Saving a visible user log - php

For an application, I need to save user logs that come in different formats, like account changes among application specific changes. The over goal is to have a twitter like news feed about their account and global sent messages.
The problem is I'm not sure how to save this information. For an example, say the user has submitted a support ticket. I would want a message on their feed to display: "Ticket "I need help" has been submitted to the Help Desk" Where the title would be a link to the their ticket.
Would it be wise to save the entire link in the message? I personally don't want to, because the title of the ticket could change or the location could be changed as well. I have thought about saving the ticket id along with the message in its own column, but then what about other message that don't use ticket id and instead another id? Would I create a new column that way?
Let me know if more information is needed. Thanks for all the help!

just do a templating approach
+--------------+
+ event +
+--------------+
+ id +
+ user_id +
+ type +
+ custom_id +
+--------------+
id is your key autoincrement
user_id: your user key
type is a type for example send_message, created_ticket whatever your application need to log
custom_id is just a number if type is send_message maybe the message id, if created_ticket the ticket id, what ever id you need to identify the ressource
you can use the custom_id and type to fetch the link title.

Related

Yii2: how to use mysql LEFT() function along with time stamp in Yii2

I need to create Client ID for my page in which client ID should be made of first 4 letters of company name + current time stamp in it.
e.g SAMS1016
(SAMSUNG= SAMS + time(10:16)=1016)
Also, I need this to be auto generate, when user enter client information in form, he will enter only company name and other details Client ID field should be hidden. When user submits the form, it should take company name from company_name field and generate Client id with time stamp.
How to achieve this?
you are looking for somethings like this :
select concat( left('YOUR_COMPANY',4) , DATE_FORMAT(NOW(), '%h%m ') ) from your_table;

Best way to create an anonymous mode for logged in users?

I'm working on a Web App similar to a discussion board and I want to give logged in users the ability to switch to an anonymous mode in which their username is not displayed but replaced by an ID when they post or reply to a topic. So the question is what is the best way to generate this ID given that :
A user has the same ID in the same topic.
The ID for the same user is different from a topic to another.
I'm in a LAMP environment so if you can suggest any PHP function to generate the ID or a way to store it in MySQL database that will be great.
Thanks !
All you really need is to:
be able to create an id, which in your case should probably be globally unique
associate that id with your regular user's id
be able to track that a unique id belongs to a topic
You can do this easily with one extra table:
table anonymous_ids
-------------------
user_id INT (references your user id)
anonymous_id VARCHAR, UNIQUE index
topic_id INT (references your threads/topic id)
When a user replies in a topic, you check whether there's already an anonymous id for him in this topic:
SELECT anonymous_id
FROM anonymous_ids
WHERE user_id = {userId}
AND topic_id = {topicId}
If there is no such id yet, you create it. That's the basic gist of it.

Cassandra - Recommended approach to storing user display name on the post (and what happens if display name changes)

I have a website where people can post messages and I store them in this form:
post_id : {user_display_name, title, body}
for example:
234567 : {
user_display_name : "John Doe",
title : "Title here now",
body : "Body of the post here"
}
My problem now is, what happens if John Doe decides he's gonna change his name to John Lorem? In a relational database, I would just have a user id that points to user information so that if he changes his name, changes will reflect everywhere.
How can I achieve this in a NoSQL database?
Because I don't think it is practical to lookup John Doe in the whole keyspace and change it to John Lorem.
Thank you
If you maintain a Column Family for post's by user you should pull all the post's for that user and change their display name.
Similarly in RDBMS without index (aka relation ship) you will end up accessing full table to change display name.
However, you can write Map-Reduce to identify post for user and change their display names and for future you can maintain a column_family with.
ROW -> USERID (or) USERID_YYYYMM (to avoid hot-spots)
COLUMN Name -> Reverse(TimeStamp):PostId
This column family will also help you quickly fetch latest Postid's by userid.
Personally I find it sometimes still makes sense to store data that may change using IDs as you would in a relational model. Considering the extra lookup to get the name for ID is really cheap, this tends to be more reasonable than running through your entire CF to make the change.

Setting up a MySQL table to track user link clicks

This is a followup to a question I posted a few days ago.
basically, I have a site with six links. In order to access the site, users must log in using LDAP authentication. When they do this, I grab some of their account credentials (username, firstname, lastname), and store it in a PHP $_SESSION variable.
That works; the user can log in, and the session data is being stored successfully.
Now, I want to set up a way to track which links have been clicked by what users. Basically just store a time stamp in the database of when they clicked the link. I want to be able to see who has (or has not) clicked each link, and when.
Can I do this in a single table / would that be a bad idea? I was thinking setting up the table like this:
TABLE (each bullet indicative of a column)
auto-incrementing ID
user account name: abc1234
user account first name: John
link 1: Last Accessed 5/2/2012 at 4:15PM
link 2: NULL
link 3: NULL
link 4: Last Accessed 5/1/2012 at 2:20PM
link 5: NULL
link 6: NULL
basically the above would say that "John" had only clicked the first and 4th links. The rest are null because he has never accessed them. If he were to click #1 again, it would overwrite with the more recent date/time.
Can I do this in a single table? or will that create complications? I feel like the thing I will have the hardest time with is checking to see if the user is already in the database before adding the info (ie so that if John logs in a second time, a whole new row isn't created for him)
Thanks for any help!
That would be a bad idea. What if you wanted to have a seventh link? What if the user format would change?
This solution requires 3 tables:
Users - contains user data (And a user ID).
Links - contains link data (And a link ID).
Clicks - many-to-many relationship between users and links.
That third table would look like this:
user_id | link_id | timestamp
-----------------------------
1 | 2 | ...
2 | 2 | ...
1 | 3 | ...
............
why not just have
increment_ID
Account_ID
Link_URL
Timestamp
Then just insert a new record for each click. You also don't need to manage links since you'll store the entire URL path

Want to create a facebook likenews and updates

I'm wokring on a simple social network site and I would like to build a simple news update feed. Feed not in the actual sense but you know like those little reports you get on facebook eg when someone posts a picture you get a simple report saying in your main page that - so and so added a picture, or so and so added a comment. Stuff like that one liners.
However I want to build something similar. I was thinking of running a union based query on all my tables but that is INSANELY impractical. Another idea I had was to create a news feed table which would have fields like:
Who - Action - ON WHAT
Where 'WHo' - refers to the user ID of the individual who did something
Action refers to the action ie.. adding a comment
WHAT refers to like if the action was done ON something like a comment passed on an article.
However I'm not so sure if this is a good idea... I want a simple solution - any ideas would be much appreciated.
I think this sort of depends on what sort of actions you are expecting to be performed on your items. I'm no expert, but I think the approach I would take is to keep each action distinct.
Let's assume that you have news items to display in your feed, and users can vote on them (or even just 'Like' them a la Facebook) or add a comment about the item.
I'd likely set up my database as such:
NewsItems
---------
NewsId
UserId (if this is like Facebook where it's someone posting their item)
Body
Timestamp
Votes
-----
VoteId
NewsId
UserId
VoteType (or possibly VoteValue with values +1 and -1 or something)
Timestamp
Comments
--------
CommentId
NewsId
Body
Timestamp
Using this, you can retrieve the last n items that a user posted from the NewsItems table, and as you display each, you can use it's NewsId to determine it's current vote count from the Votes table, and also use NewsId to retrieve a chronological listing of all comments made on the item.
I suppose you could also replace the Body field in NewsItems with two other fields, like NewsType and TypeId. The former tells you which table to use to lookup an action (since you probably don't want picture BLOBs and status update text in the same field/table. The second gives you the key to lookup in that table.
Just my two cents. Hope it helps.
thats a tricky and not so easy thing to do.
I worked for a start up social network and it was something they wanted as well.
I dont think i still have the code laying around but if i recall correctly i went about it something like this
DB:
USERS
id : guid "a unique identifier for this user"
"other user info"
ACTIONS
when : unix_timestamp
who : guid "the user who made the actions guid"
type : set('image','news') "replace with a list of the type of things you want to track"
what : url "not like a web address but the guid of the thing that was made"
FRIENDS
id1 : guid "one of the 'friends' guid's
id2 : guid "the other persons guid
PHOTOS
id : guid "a unique identifier for the image"
url : varchar(255) "where is the image stored (file name directory etc)
who : guid "the user who posted the photos guid"
"other info you want to keep track of"
NEWS (think status update)
id : guid "a unique identifier for this statu update"
who : guid "the guid of the person who posted this"
when : unix_timestamp "timestamp of when it was posted
what : text "the contents"
using the above structure i would have my code make an entry into the ACTIONS table anytime a user posted a photo or a status update. then when their friend logged on it would go through the ACTIONS table pulling out all the actions of anyone it found was friends (via the FRIENDS table)
the TYPE field is used to differentiate what table to use when linking the IDs of the actions. so if the person posted an image when it writes the action to the screen it can set the link up to point to whatever script your using to display images. etc etc
ill see if i can find the code, if i can ill post it (company went under and i retain ownership of the code)
If my explanation isnt clear ill take some more time later to better document the process and code.

Categories