Announcement

Collapse
No announcement yet.

Task Reminder for Creator of task

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Task Reminder for Creator of task

    It looks like the default reminder (popup or email) only gets sent to the Assigned User. Is there a way that the Creator could also get the reminder?

    The reason - sales team have a number of tasks that they send to engineering along with a required due date. The creator (sales guy) also wants a reminder that the task needs completion on a certain day/time else they may forget as well.


  • #2
    You can customize function getSubscriberList from \Espo\Hooks\Note\Notifications and include all persons who should be notified in $userList


    Code:
    namespace Espo\Custom\Hooks\Note;
    use Espo\ORM\Entity;
    class Notifications extends \Espo\Hooks\Note\Notifications
    {
    
        protected function getSubscriberList($parentType, $parentId, $isInternal = false)
        {       
             return $userList;
        }
    }

    Comment


    • rmorgan
      rmorgan commented
      Editing a comment
      So I have created a new file with the function but its likely to take me days trying to understand the code structure in order to get the correct $userList variables. I guess what I am actually after is for Subscribers to get notified. Any more hints??

  • #3
    Well I have been playing - bearing in mind that I don't fundamentally understand the architecture of the code, my original assumption was that every N minutes (set by Admin->Send Email Reminders) some code would be processed and a reminder emailed to those 'users' that have a reminder set. Therefore I just need to intercept the code that runs every N minutes, mod it and job done....obviously not

    What I have done - is create a new file with the following -

    <?php



    namespace Espo\Custom\Hooks\Note;
    use Espo\ORM\Entity;
    class Notifications extends \Espo\Hooks\Note\Notifications
    {

    protected function getSubscriberList($parentType, $parentId, $isInternal = false)
    {

    if (!$this->getMetadata()->get(['scopes', $parentType, 'stream'])) return [];

    $pdo = $this->getEntityManager()->getPDO();


    /*NEED TO MODIFY THIS TO find followers*/
    if (!$isInternal) {
    $sql = "
    SELECT created_by_id as userId
    FROM task
    WHERE id = " . $pdo->quote($parentId);

    } else {
    $sql = "
    SELECT subscription.user_id AS userId
    FROM subscription
    JOIN user ON user.id = subscription.user_id
    WHERE
    entity_id = " . $pdo->quote($parentId) . " AND entity_type = " . $pdo->quote($parentType) . " AND
    user.type <> 'portal'
    ";
    }

    $userList = $this->getEntityManager()->getRepository('User')->where([
    'isActive' => true
    ])->select(['id', 'type'])->find([
    'customWhere' => "AND user.id IN (".$sql.")"
    ]);


    file_put_contents('espocrm_mylog2.txt','.........' );
    file_put_contents('espocrm_mylog2.txt',$sql,FILE_A PPEND);
    file_put_contents('espocrm_mylog2.txt','*-------',FILE_APPEND);
    file_put_contents('espocrm_mylog2.txt',$userList,F ILE_APPEND);
    file_put_contents('espocrm_mylog2.txt','*+++++++', FILE_APPEND);



    return $userList;
    }
    }

    I was hoping to log to a file the users but the users always appear empty. This file only seems to get executed when I create \ update a task with a notification, not at the stage when the code is run (i.e .timer based). So therefore I seem to be missing a fundamental point of something but not sure what....?

    Comment


    • #4
      What does the subscription table do?

      Comment


      • #5
        Here is what I ended up doing - not sure if its the correct way to do it but it works! Others may find it useful.


        edit the file c:\birnami\espocrm-5.5.1-0\apps\espocrm\htdocs\application\espo\modules\crm \business\reminder\emailreminder.php
        add the following line of code below




        and also add a new function following the send function -


        protected function sendtocreator(Entity $reminder)
        {

        $user = $this->getEntityManager()->getEntity('User', $reminder->get('userId'));
        $entity = $this->getEntityManager()->getEntity($reminder->get('entityType'), $reminder->get('entityId'));


        $entityid=$entity->get('id');
        $mytask = $this->getEntityManager()->getEntity('Task', $entityid);
        $creator=$mytask->get('createdBy');
        $creator_emailAddress = $creator->get('emailAddress');


        $emailAddress = $user->get('emailAddress');

        if($emailAddress==$creator_emailAddress)
        {
        //file_put_contents('espocrm_entity.txt','matching email addresses');
        return;
        }
        else{
        $user=$mytask->get('createdBy');
        $emailAddress = $creator->get('emailAddress');
        }

        //--------------
        if (empty($user) || empty($emailAddress) || empty($entity)) {
        return;
        }


        $email = $this->getEntityManager()->getEntity('Email');
        $email->set('to', $emailAddress);


        $subjectTpl = $this->getTemplateFileManager()->getTemplate('reminder', 'subject', $entity->getEntityType(), 'Crm');
        $bodyTpl = $this->getTemplateFileManager()->getTemplate('reminder', 'body', $entity->getEntityType(), 'Crm');


        $subjectTpl = str_replace(array("\n", "\r"), '', $subjectTpl);


        $data = array();


        $siteUrl = rtrim($this->getConfig()->get('siteUrl'), '/');
        $recordUrl = $siteUrl . '/#' . $entity->getEntityType() . '/view/' . $entity->id;
        $data['recordUrl'] = $recordUrl;


        $data['entityType'] = $this->getLanguage()->translate($entity->getEntityType(), 'scopeNames');
        $data['entityTypeLowerFirst'] = lcfirst($data['entityType']);


        if ($user) {
        $data['userName'] = $user->get('name');
        }


        $preferences = $this->getEntityManager()->getEntity('Preferences', $user->id);
        $timezone = $preferences->get('timeZone');
        $dateTime = clone($this->dateTime);
        if ($timezone) {
        $dateTime->setTimezone($timezone);
        }


        $htmlizer = new \Espo\Core\Htmlizer\Htmlizer($this->fileManager, $dateTime, $this->number, null);


        $subject = $htmlizer->render($entity, $subjectTpl, 'reminder-email-subject-' . $entity->getEntityType(), $data, true);
        $body = $htmlizer->render($entity, $bodyTpl, 'reminder-email-body-' . $entity->getEntityType(), $data, false);


        $email->set('subject', $subject);
        $email->set('body', $body);
        $email->set('isHtml', true);


        $emailSender = $this->mailSender;


        $emailSender->send($email);
        }


        Comment

        Working...
        X