I'm using yii framework and I want to make an activity logging for every action that user do in my web. All of their activity will be saved to a table in database.
The things that will be recorded are:
user ID
table name (inserted, deleted, edited item)
time_action
activity (what did they do. ex: created project_name)
Please help. Thanks in advance.
I'm not sure what you are trying to do but is it like when a user deletes some item; then entry should be logged in database for that user?
If yes, then you can create a common class and a static method in it like,
yourCommonClass::setActivityLog(user_id,activity_msg,time);
and put this code in every action that you have written. ex. actionUpdate, actionDelete.
you can get the user_id from Yii::app()->user->id
put you custom activity message like "User #user_id created new item" etc.
time you can get it while saving into database.
By the way, create a table and model for the same like ActivityLog. ;)
This is what I did in my project.
Related
I try to make a website with multiple users of the same role on Wordpress. That may be "Informational system of hotel rooms". Every user should have an access to login page and the page for registration. But after the process of logging in the user should get own private page. In this page the subscriber should get the opportunity to review and edit the database table. But there's no exception of the fact that despite the whole list of database tables is the same by own quantity and structure of each of them, the data stored in those tables should be unique.
The uniqueness of data witnesses that I need to create a private page for every user, save for administrator. It must be private page, not post, because I'll use php snippet and html code for displaying the table with unique data.
So the question is: What kind of plugin should I use to make a whole page for one user only?
I know you can save sessions actions of user in a file (logs) or database. But this file (or line in database) is rewrited in every action that user make, for example:
If user start in login and then go to home, later go to about; this file is rewrite to from: home > to about.
I know it is not the complete quote generated in log/db. Is it possible to storage the first action (from login to home) and the second (from home to about)? How can I do it?
Thanks
I've been using Laravel Audits and it's pretty cool, give it a try.
It tracks pretty much everything you need, and shows you what was created and the old and new values when something is edited. but downfall is it does not track changes pivot tables
Check it out here: Laravel Audits
Maybe have a look at https://github.com/spatie/laravel-activitylog which allows you to specify your own logging requirements.
Laravel requests allow to get a lot of informations.
You can create a table in your database and a middleware which get the request anytime a route is called and store informations like the route called, the user id or even his referer in the table.
Check it out for more info about requests
So I'm new to Laravel and trying to make a permissions system for the users on my application. Here is my approach:
1) Place a column in users table with the name 'permissions'
2) Create a table of permissions with columns id and page-name
Here's how it will work:
Each page will be assigned an ID. For example, the page Manage Accounts has id 1 and the page Manage Customers has the id 2 in the permissions table.
In order to give user full access to Manage Accounts and view only access to Manage Customers, I will make the following entry in the permissions column for the user 1.1111,2.1000
Now when the user will land on the Manage Accounts page, I will get the page id for the current page from the permissions table, i.e. 1. I will then convert the string value from the users.permissions column in the following format: array('1' => '1111', '2' => '1000');. Now I can get the user permissions saved against the ID of the page by $permissions['1'];.
I will then have a function to parse the 4 digits and get boolean values for the following in the exact order:
$canView = true;
$canAdd = true;
$canEdit = true;
$canDelete = true;
Now inside my page, I can easily put checks and display items accordingly.
Questions
1) So first question. Is this a good approach? Or are there better ways for going about this? I like this approach because I only have to add one more table in the database and it will only have as many entries as there are pages on my application, which aren't many. And it also means that I will only have to access the database once and I can then keep on using the values in the variable.
2) Should I create a separate class for permissions? I'm new so I don't completely understand the Eloquent class. But is that something I should be using for this? Or should I just add the functions that I need to create to the users class?
3) Where should I store the values of $canView, $CanEdit etc. Should I place them in the class for permissions and create an object for it? Or should I just use the Users class and access them using Auth::? I do not want to use Session, I don't think it to be safe.
4) Can I somehow have the permissions autoload every time a page is opened? I was looking into beforeFilter, and thinking of creating adding it to the constructor of each controller. Is that a good idea?
Thank you so much for your time and help.
Cheers
Why reinventing the wheel? take a look to https://github.com/Zizaco/entrust
I have users table in my database lay out like this :
id
username
firstname
lastname
email
photo
As of now, since I am an Admin user so I have Admin right, and I can Create, Update, and Delete.
I want to allow all my users to have the same right as me later on.
Before I release this feature, I want to keep track on who edit what - so things doesn't get lost, and it's good to keep the history of things.
What is best practice for this feature ?
I know that I have do some programming logic in my update function in my Controller function.
I know that I have to create a logs table on my database to store
user_id : who make a change
created_at : when the change was made
old_data: string
new_data: string
For someone, that had any experiences with this feature, can you PLEASE give me some advice ?
I really appreciate your concern. Thank You.
I think best approach to this problem is each action that a user takes that you want to log should also fire an event.
Event::fire('some.event', array(Auth::user()));
Then you can register listeners for each event and log appropriately.
Event::listen('some.event', function($user)
{
// create new item in logs table here.
});
This is a follow-up to a previous question: Should sub-objects be fetched in the Model or the Model Mapper?
Let's say a User can have one or more PhoneNumber objects. According to the answer in the above question, these sub-objects will be fetched upon instantiation of the User. If I were to delete a PhoneNumber from the User's phoneNumbers property (an array of PhoneNumbers), or modify one of the PhoneNumber objects, where should this change be propagated?
Should I manually delete/update the sub-objects in the database, or should the User do that automatically on save? Thank you,
Let's see If I got it the right way.
The user is logged and it's on his profile page. On this page the user clicks a link "delete this phone number".
On the page where the action is performed it will executed DELETE FROM phones ETC.
Now after this is performed when you will load the User, the constructor will load the phonenumber etc and considering you performed the DELETE sql early the current user object will not have, of course, the just deleted phonenumber.
This is at least what happens in my MVC framework.