Hi, this is my first thread here, as I always find a solution to my problems by searching in the forum, and I have to say this have a very good support, so that why I didn't post much.
I have a MOD installed in my site, made by a friend and maintained by other friend and I, is really complex, based on and somewhat integrated with SimplePortal.
This mod create Post(and publish it in the portal) in one or another board depend on the settings selected, and with only 2 or 3 things entered in a textareas the mod generate the post with a predefined template. It saves all the things in it's own db table and also allow the admin to delete the post and delete the db entry.
This all work well but what I want is to remove from this posts the "Delete" and "Modify" link, as the Moderators, Admins and the user who create the post possibly edit from there the post to fix some errror like a typo or update the info in the post, as this way only update the post and not the mod db. The mod has it's own way to handle edits and deletions.
In the test site I managed to do something that works but I'm afraid that in the mains site uses a lot of resources by the way I do it.
The way I do it:
In the Subs-AManager.php(my mod subs file) I have a function that does the db query of the post_id that the AManager create, so I get all the id's in one array.
In Display.template.php just in the While loop that get all the messages I call that fucntion this way
if (in_array($message['id'], getAManagerPosts())){
$message['can_modify'] = false;
$message['can_remove'] = false;
}
This way I overwrite the settings of the post and only that post created by the AManager can't be edited or deleted the normal way, so this way I force all to use the AManager form to keep the things in order(the db updated).
As I said, this way in probably not the best, as every post call the function and query through the whole post db, so I want to ask a way to simplify this, maybe store the array in the db and instead of looking through the post table just look into this value, updated only when a new post is created by the AManager.
Thanks in advance.
Is the generated post always a new topic?
If so, you can just perform that query once in Display.php (maybe add a join to the existing query or maybe perform a small, much faster, new query) and like this identify the post (first post in topic) like you're doing with just one query per page.
Also note that code wouldn't be accepted, eg, as a customization in our modsite, as you're using computation in a template file. Not an issue per se, it works, it's just not recommended.
Finally: by doing it only in Display (be it Sources or template) only deals with showing the button or not. It is still possible to bypass that.
The proper way to do it, really, would be:
- add a column to smf_messages, eg "outside_post", tinyint, default value 0
- each time your mod adds a post, sets this column to 1
- in Display.php, you fetch this column additionally
- in the following while loop, you establish the modify/remove permission conditionally to this field
- in Post.php, when checking if an edit is allowed, also check this field
Hope I was clear ;)
Good luck!
Yes, the post is always a new topic. I'm looking at that, less query as possible.
I know that is still possible to bypass that, if the group allowed to use the mod know how SMF works, but thats why I need to remove the buttons, they don't know much about forums and mods, so I want to keep it simple. If they can't see the button to edit the post then they go to the mod page and edit from there.
I will try that new column in smf_messages, just need to be sure that I understand it right:
-New column, default value 0 to always allow edit/delete normal post under normal circumstances.
-When my mod add a post, in $msgOptions array goes one more field, eg: 'AManager' => 1.
-in Display.php, only neet to fetch the new field in the $messages_request?
-not sure what while loop it is, but I see the output array where can_modify and can_remove were set. Maybe here is where I fetch the conditional?
-doing the last is not enough?
Need to clone the main site again and do this to test(to be sure that is clean). Hope work better than my actual "fix".
It works.
What I done:
-New column in smf_messages, default value 0.
-When my mod create a new post(or edit one) set this to 1.
-In Display.php in the $messages_request just add my field m.AManager next to m.approved.
-Also in Display.php, when "can_modify" and "can_remove" are set, I add at the end "&& (!$message['Amanager'])".
Doing this in the same query for the message check the permissions and all the Posts made by mu MOD don't show Edit or Delete buttons. Better performance in just the normal 17~20 queries than the 57 of my way...
Thanks for the help.
Great! :)