Loading

Task Comments plugin mod - notify if being tagged [code]

General Discussion around Collabtive

Task Comments plugin mod - notify if being tagged [code]

Postby BaneD » 14.01.2016, 12:11

Collabtive is great for many reasons, but comments on a task is a must have for any project management. Looking into the missing feature and noticing it being already coded and available for purchase I decided to purchase the same since I am limited with time to learn everything needed quickly about Collabtive. I did notice that the plugin however did not have something that I thought would be possible - tagging someone within a comment.

When is this needed? Well if you are working on a project that involves a lot of people it can come to the point where you want to ask someone if they can confirm something or check something out without much effort - like sending an email manually and similar. It is also useful if you need system administrator to set some service in a specific manner or get back to you if something is available - like the designs from designer, etc.

For that I made the simple mod that checks if someone was tagged and sends them an email if so.

This is accomplished with a @name.

Basically once a comment is made and it includes @bane I will get an email no matter if I am assigned to the task or not. If I am, I will only get the standard email, but if I am not, I will quickly get the you were mentioned email and I can check it out :)

Well, this is the code to do it - but since this is a mod for the plugin, you need to have the plugin before you can actually use this - and I will only show my code, not the code of the entire plugin:

Code: Select all
//Lets send an email to everyone that was tagged (and not included in the list above)
// We do it by adding the following code to line 58 by adding the new line right after the closing bracket of foreach segment, this way we are still within the emailnotify block - at its end.

            //First lets see if there is anyone tagged in comments, so that we do not go through everything if not

            $projectMembers = $project->getProjectMembers($thetask['project']);
            $taggedUsers = null;

            //Lets go through all project users
            foreach($projectMembers as $key => $memberData)
            {
               $userTagged = false;

               //We can set this any way we like, for example a plus could (Collabtive removes it from the comments, so in comments it is a no) or @ could be used to mark the name that was mentioned / tagged
               if( stripos($text, '@' . $memberData['name']) )
               {
                 $userTagged = true;
               }

               //OK, user is tagged, lets check if they were already sent an email or not
               if($userTagged && !in_array( $memberData['name'], $assigned ) )
               {
                  //we have a hit :)
                  //Lets send an email..
                  $themail->send_mail(
                            $memberData['email'],
                            'You were tagged in a comment (by ' . $username  . ')',
                            'It seems that you were tagged in a comment made by <b>' . $username . '</b> on following task: "' .
                            $thetask['title'] . '". <br/><br/>' .
                            'You can see it on the following link: <a href="' . $url . 'managetask.php?action=showtask&id=' . $thetask['project'] . '&tid=' . $tid . '">' . $url . 'managetask.php?action=showtask&id=' . $thetask['project'] . '&tid=' . $tid . '</a><br/>'
                        );
               }
            }


Now here I am showing my own setup - so there are no language file strings. As you can see the subject would be easy to add into the language file, while the text is a bit more complex, so I leave it up to you if you find the best wording :)

I also use the same text in the URL and the keyword of the same, you could replace it with the $title $thetask['title'] instead if you wish.

PS: the change is made in managecomments.php file

Also Google style tagging with a + is not working properly - it seems that the + gets scraped from the text by some reason, but did not have a chance to look into it much so far.

I hope the code helps someone :)
BaneD
 
Posts: 16
Joined: 13.01.2016, 20:26

Re: Task Comments plugin mod - notify if being tagged [code]

Postby onda » 09.03.2016, 16:40

Thanks I'll keep your posted, as so far can't manage to call the fields, this should be simple, given as "tname" is already declared
onda
 
Posts: 95
Joined: 26.11.2012, 16:16

Re: Task Comments plugin mod - notify if being tagged [code]

Postby BaneD » 11.03.2016, 17:01

Hi :)

I am not completely sure what you mean, but I just want to mention that it requires the Comments for tasks plugin to be be purchased first - once you do and add it to your system adding the change above to the managecomments.php file will send you the email as well.

I have however only tested this on the 2.1.1 version of Collabtive and the same version of the plugin (per changelog).

If nothing happens and you do not get the email, I could only suggest checking the error logs to see if there are any errors shown there.

Cheers,
Bane
BaneD
 
Posts: 16
Joined: 13.01.2016, 20:26

Re: Task Comments plugin mod - notify if being tagged [code]

Postby onda » 11.03.2016, 17:24

This is a different area, I've added the "notify" to managetimetracker.php so when a report is made, a notification is sent to "admin", what I'm trying to do is call the fields of the task itself, namely #title, which has been declared as #ttname. As you can see I've created >
Code: Select all
if ($settings["mailnotify"]) {
            $usr = (object) new user();
            $user = 1;
            $user = $usr->getProfile($user);

            $pro = new project();
            $proj = $pro->getProject($tproject);


Which sends to user and calls the project fields, I just need to call the "task" name
onda
 
Posts: 95
Joined: 26.11.2012, 16:16

Re: Task Comments plugin mod - notify if being tagged [code]

Postby BaneD » 15.03.2016, 02:22

Hi :)

Sorry for a bit of delay.

OK, I see. This is not exactly connected to the original feature, but still the same principle should work.

Looking at the top of the managetimetracker.php file I saw $task being declared.

This is the code:
Code: Select all
$task = getArrayVal($_POST, "ttask");


I would suggest using the code mentioned here (with slight modification of variable names):

Code: Select all
$mytask = new task();
$currentTask = $mytask->getTask($task);

//This should allow you to get the details:
$taskTitle = $currentTask['title'];
$taskDescription = $currentTask['text'];
$taskList = $currentTask['list'];
$taskStatus = $currentTask['status'];
$daysLeft = $currentTask['daysleft'];


Regards,
Bane
BaneD
 
Posts: 16
Joined: 13.01.2016, 20:26

Re: Task Comments plugin mod - notify if being tagged [code]

Postby onda » 15.03.2016, 12:56

Thanks
just added the
Code: Select all
$mytask = new task();
            $currentTask = $mytask->getTask($task);

Then called it in the mail with
Code: Select all
 .$currentTask["title"].

Great
onda
 
Posts: 95
Joined: 26.11.2012, 16:16

Re: Task Comments plugin mod - notify if being tagged [code]

Postby BaneD » 15.03.2016, 16:31

Great to hear that you got it all set up :)

Cheers,
Bane
BaneD
 
Posts: 16
Joined: 13.01.2016, 20:26


Return to General

Who is online

Users browsing this forum: No registered users

cron