Hello! Help to understand how best to cause the desired class.
I will simplify the statement of the issue to a few modules on the site... for example, there are modules:
review, posts, users.
Each module can have its own set of features (like comments and posts, subscribe to user, etc.). Take for example just like.
Huskies I have put on the principle: the object type and its ID is sent to a single file on the server
like.php. So putting like to post
333, file
like.php gets the value of a:
type == post and
id == 333Next, for each type of object has its own classes, which are responsible for generating the notification object in the DB. ie Setting
like post 333, file
like.php should create an object of class
LikePost and call the method
createNotify passing the desired parameters. Here's how I do it now:
// this file like.php //......... switch($object_type){ // check object type and call a method of creating a notification of the desired class case 'post': /* * because the file is in like.php knows only the type and ID of the object * it is already inside a class is called LikePost model (in this case post) * and get the author ID of the post to write it together with the notice as * recipient of the notification */ LikePost::createNotification($auth->user_id, $object_id); break; case 'comment': // the same meaning when type == post LikeComment::createNotification($auth->user_id, $object_id); break; case 'news': // the same meaning when type == post LikeNews::createNotification($auth->user_id, $object_id); break; //..... etc. } //.........
Everything works, it works, but the code is very scattered, it turns out that if an object can subscribe, like, comment, share. In each such file as
like.phpI need to build such tests. And when you add on the site of a new object type to remember to add all this for each such file, moreover, changing the name of the object type, I will need every tick of a file search for it and rename it.
As far as I know is not the right approach, but the other I can not think of, so please explain how actually beautiful it is?