Loading

Send email to people deassigned from a task - code inside :)

General Discussion around Collabtive

Send email to people deassigned from a task - code inside :)

Postby BaneD » 14.01.2016, 11:45

I noticed that I got email only when I was assigned to the task, but not when I was taken from it. I think that this is very important, at least for people like myself since I have often went to sleep thinking of my to-do list and how I would do something. Knowing that I should no longer think about something makes more room to think about something else and not have any time wasted..so I made some changes to the code to know if I am removed from the task as well :)

This mod is a bit more complex than the previous two I added since it requires 2 points of edit, but in the end it is worth it - at least for me :)

Code: Select all
//To activate this, we need to add the first part on line 212 under edit section - elseif ($action == "edit") {
// First part of the code is added at the top - before the task is attempted to be edited

//Since we are only sending an email if the email notify setting is ON, there is no point in doing all this if no email should be sent..
if($settings["mailnotify"])
{
  //Lets get the people that are currently assigned to the task
  $currentTask = $task->getTask($tid);

  $currentUsers = $currentTask['users'];

  $deassigned = null;

  //Lets check if anyone is assigned to the project - if no one, there is no need to make any checks, we just send an email to all those that were assigned to it.
  if(empty($assigned))
  {
    $deassigned = $currentUsers;
  }
  else
  {

    $maxI = count($currentUsers);
    $maxJ = count($assigned);

    for($i = 0; $i < $maxI; $i++, $matched = false)
    {
      for($j = 0; $j < $maxJ; $j++)
      {
   if( $currentUsers[$i]['ID'] == $assigned[$j] )
   {
     $matched = true;
     break;
   }
      }
      if( !$matched )
      {
   $deassigned[] = $currentUsers[$i];
      }
    }
  }
}


This is added to the managetask.php file at the line 212 right after the segment start code: elseif ($action == "edit") {

Now we move to the second part..

Code: Select all
// the second one is there only if the edit was made.
// The second part of the code is added after the task has been created and before the emails are sent about assigned tasks..this is usually line 214, with the first part, it is approximately line 250.

if($settings["mailnotify"])
{
  if( $deassigned !== null )
  {
    foreach($deassigned as $deassignee)
    {
      if (!empty($deassignee['email']))
      {
     // send email
     $userlang = readLangfile($deassignee['locale']);

     //Quick and temporary patch so that language files are not modified
     $userlang["taskdeassignedsubject"] = "You were deassigned from a task";
     $userlang["taskdeassignedtext"] = "You were deassigned from a task:";

     $subject = $userlang["taskdeassignedsubject"] . ' (' . $userlang['by'] .' '. $username . ')';
     $mailcontent = $userlang["hello"] . ",<br /><br/>" .
           $userlang["taskdeassignedtext"] .
           "<h3><a href = \"" . $url . "managetask.php?action=showtask&id=$id&tid=$tid\">$title</a></h3>".
           $text;

     $themail = new emailer($settings);
     $themail->send_mail($deassignee['email'], $subject , $mailcontent);
      }
    }
  }
}


There are 2 new language strings included in this code. I have again placed them within the code instead of editing language file since that allows quick preview of the functionality, but it is quite simple to add the same into your own language file.
taskdeassignedsubject = "You were deassigned from a task";
taskdeassignedtext = "You were deassigned from a task:";

Now I tend to remove $text from the email since otherwise it would mean that all the info is available in my email and is not something that I like, but the code above is made following the default Collabtive coding as much as possible.

Well, I hope it is useful to someone :)
BaneD
 
Posts: 16
Joined: 13.01.2016, 20:26

Re: Send email to people deassigned from a task - code insid

Postby onda » 04.03.2016, 14:10

Thanks for the code: I wonder if you can help I'm trying to elaborate the notification on managetracker.php which sends a notification to "admin" when a report is submited, any ideas how I can include the "task" #title etc?
if ($settings["mailnotify"]) {
$usr = (object) new user();
$user = 1;
$user = $usr->getProfile($user);

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


// send email
$themail = new emailer($settings);

$themail->send_mail($user["email"], $langfile["messagewasaddedsubject"]."Från > ". $username,". $proj["name"] ."
);
}
onda
 
Posts: 95
Joined: 26.11.2012, 16:16

Re: Send email to people deassigned from a task - code insid

Postby BaneD » 07.03.2016, 23:36

Hi :)

I checked my own version (2.1.1) and I did not see the file 'managetracker.php', so I can not tell you any specifics, but in general what you would need is the task ID. If you have it - usually it is passed over as "tid" or "id" depending on the page - and as mentioned it seems that I do not have it so I can not check the same - you would be able to use the following code.

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


Then just inspect the $currentTask to see the values that you are after.

For example, based on what you have mentioned (and few other details):

Code: Select all
$taskTitle = $currentTask['title'];
$taskDescription = $currentTask['text'];
$taskList = $currentTask['list'];
$taskStatus = $currentTask['status'];
$daysLeft = $currentTask['daysleft'];


Under users you could get the details about the people that are assigned to the project.

If by some chance the $task is not already declared you can do that by using this code:

Code: Select all
$task = new task();


- so in case you need to use the new task, you need to add it above the previous code for it to be available.

Hope this helps :)

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


Return to General

Who is online

Users browsing this forum: No registered users

cron