User Activity log - laravel

I have two database tables users and activity_log with dummy records as below:
Table users
id name
1 Michael
2 Joseph
Table activity_log
id user_id activity
1 --- 1 ---------- you received $30 from Joseph
2 --- 1 ---------- you withdrew $20
My problem is that, I don't want to hard-code the name Joseph in the activity since the user might change his name in the future. I want when user 2 changes his name from Joseph, user 1 activity log will be updated accordingly with the new name.
As an example, I need activity log similar to that of Facebook where for example Michael can see in his activity log 'you liked Joseph's photo'. If Joseph changes his name to Jose, Michael will see in his activity log 'you liked Jose's photo'. How can I achieve that?
Thank you in advance.

You can just save the user_id into the activity_log table and then reference it when rendering the message.
activity_log should contain id, owner_id, target_id, and activity_type.
Then you can create a function in the Activity model that'll render proper message accordingly to your requirements.

Related

How to use login ID session variable in Oracle BI publisher report

I am thinking of setting user filter on report. So user can only see data related to him.
It is supposed to login to Oracle bi publisher, then open report, and the related data will show up.
Is there a way to extract login id as parameter in a data model?
Database is from DB2
There are user information stored in system variables that you can include in your data model. The folowing query would give you the user info that you can refference in your report:
select
:xdo_user_name as USER_ID,
:xdo_user_roles as USER_ROLES,
:xdo_user_report_oracle_lang as REPORT_LANGUAGE,
:xdo_user_report_locale as REPORT_LOCALE,
:xdo_user_ui_oracle_lang as UI_LANGUAGE,
:xdo_user_ui_locale as UI_LOCALE
from dual
More about it at: https://docs.oracle.com/middleware/12212/bip/BIPDM/GUID-2A6E4B9B-ABCD-4CF0-A458-59B89F2443A1.htm#BIPDM223
Regards...

Auditing from a trigger in oracle

I am working with a big database and it had many generators of data basically have alot of data being inserted and updated per day. I have a trigger that updates each row every time there is an update or insert and i use the following code to input the person's name from the apex application (the user from apex)
NVL(v('APP_USER'),USER)
My problem comes when there is heavy data entry, for example 500,000 records are being generated by one person (John) and when john generated this data, each row is audited but as john generated more than one person who are users in the apex application shows up in the audit.
So scenario is that john clicks a button to generate data and in the audit fields, more than one users name show up (Mary, John, Peter)
Does anybody have any idea why this is happening?
the entire code, it is very generic
TRIGGER trg_tableA before insert or update
on tableA REFERENCING OLD AS OLD NEW AS NEW
FOR EACH ROW
begin
:new.insert_date:=sysdate;
:new.inserted_by:= nvl(V('APP_USER'),USER);
:new.modified_date:=sysdate;
:new.modified_by:= nvl(V('APP_USER'),USER);
end trg_tableA;
Thank you in advance
As per this link Use v('APP_USER') as default value for column in Oracle Apex There are other options than V('APP_USER'). Since Apex 5, the APP_USER is stored in the sys_context and that is a lot more performant than the V() function. It is available as SYS_CONTEXT('APEX$SESSION','APP_USER').
Please try the below and see if your issue is getting resolved.
TRIGGER trg_tableA before insert or update
on tableA REFERENCING OLD AS OLD NEW AS NEW
FOR EACH ROW
begin
:new.insert_date:=sysdate;
:new.inserted_by:= nvl(sys_context('APEX$SESSION','APP_USER'),user);
:new.modified_date:=sysdate;
:new.modified_by:= nvl(sys_context('APEX$SESSION','APP_USER'),user);
end trg_tableA;

Comparing a Table column to the connected user in Oracle

im in needed of help, im doing some exercises with a a oracle database and do not know how to do this:
I have a table called users that have information of the users that connect to the DB, what i want is a procedure where to show the information of a specific row where the connected user is compared to the user in the table.
i do not how to compared a data in a table to the connected user, more like i dont know how "work" or what limitations have the "user" parameter to be implemented this way
Sorry if my petition its a little confusing english is not my main language.
EX: i have a user in the table users, that have a serial id, username,password,name, surname1 and surname2 and i want the procedure to show me the information of this user in particular, but i do want that if for example im connected with "pedro" user to the db this procedure show me the info about the user pedro and if i change the user connected to another like Paul the information of the select change to Paul.
One option might be to use the USER function.
SQL> connect scott/tiger#orcl
Connected.
SQL> select user from dual;
USER
------------------------------
SCOTT
SQL>
Therefore you'd
select serial id,
username,
password,
name,
surname1,
surname2
from users
where username = user;
You can find the currently connected user with
select sys_context('USERENV','CURRENT_USER') from dual;

View restriction not working

I need to create views depending on users on a oracle database
For that, using System I use the following querys:
CREATE OR REPLACE VIEW PROT_VIEW AS SELECT USER_ID, ORDER_DATE, ORDER_DESC
FROM PROT
WHERE USER_ID=USER;
the tables and the values of them are as follows:
CREATE TABLE PROT(
USER_ID VARCHAR2(10),
ORDER_DATE DATE,
ORDER_DESC VARCHAR2(60));
INSERT INTO PROT VALUES ('ADM',SYSDATE+4,'FOUR DAYS LATER');
INSERT INTO PROT VALUES ('ADM',SYSDATE+5,'FIVE DAYS LATER');
INSERT INTO PROT VALUES ('STUD1',SYSDATE+6,'SIX DAYS LATER');
INSERT INTO PROT VALUES ('STUD2',SYSDATE+7,'SEVEN DAYS LATER') ;
After this I have 3 different users (adm,stud1 and stud2) and when I log them on I should be getting 3 different results (one for each user) from each select I do (depending on the user logged).
The problem is, no matter what which user I have logged in (system,adm,stud1,stud2) I get empty tables.
I would like to know what i'm doing wrong and what can I do to solve this problem
Thank you in advance for anyone who's willing to help
update: i've been messing around and the problem is that i cant connect to those users. i've granted create session with system to those users and tried to connect to them but I'm stuck on system
Nice way to accomplish this task is to use public synonym in my opinion.
After creating your view (prot_view) on system schema, create a public synonym with the same name as view :
create or replace public synonym prot_view for prot_view;
and issue :
grant select on prot_view to public;
to be able to get desired result from every schema without prefixing with system schema name :
select * from prot_view;
"the problem is that i cant connect to those users"
user is a pseduo-column which returns the name of the account you're currently connected as. You're logged in as SYSTEM so that's the value of user, and that's why your view returns no rows. So, contrary to your question title, the view restriction is working.
Which means the the real question is, why can't you connect as those other users? You have SYSTEM so you have the necessary privileges to straighten out the accounts by changing the passwords to something you know or granting create session, or whatever.

SSRS: Not sure how to create matrix with 2 pivots

I have data like so:
NAME TITLE SALARY HIREDATE
-------------------------------
HANK BOSS 100 1/1/2016
JOHN JERK 100 1/1/2015
MIKE PUNK 200 1/1/2014
We want to show this data as such:
NAME HANK JOHN MIKE
-------------------------------
TITLE BOSS JERK PUNK
SALARY 100 100 200
HIREDATE 1/1/16 1/1/15 1/1/14
This is how my client needs to see the data, unfortunately.
How can this be done with SSRS (sql 2012)?
I tried to create a Matrix, I was able to get the names as columns on top.
But when I tried to do the rest of it, no luck.
Thanks!
You can use a matrix with column groups to pivot your data, you will need the settings of your matrix look similar to this:
Just add NAME in the Column Groups pane, then right click the first row and select Insert Row - inside the group, do that three times each for TITLE, SALARY and HIREDATE.
For SALARY use =SUM(Fields!SALARY.Value). Also you may want to hide the last empty row, so select the entire row, right click it and go to Row Visibility, select Hide.
You will get:
Let me know if this helps.

Resources