コード例 #1
0
ファイル: Stream.php プロジェクト: naushrambo/espocrm
 public function noteEmailSent(Entity $entity, Entity $email)
 {
     $entityType = $entity->getEntityType();
     $note = $this->getEntityManager()->getEntity('Note');
     $note->set('type', 'EmailSent');
     $note->set('parentId', $entity->id);
     $note->set('parentType', $entityType);
     if ($email->get('accountId')) {
         $note->set('superParentId', $email->get('accountId'));
         $note->set('superParentType', 'Account');
     }
     $withContent = in_array($entityType, $this->emailsWithContentEntityList);
     if ($withContent) {
         $note->set('post', $email->getBodyPlain());
     }
     $data = array();
     $data['emailId'] = $email->id;
     $data['emailName'] = $email->get('name');
     if ($withContent) {
         $data['attachmentsIds'] = $email->get('attachmentsIds');
     }
     $user = $this->getUser();
     if ($user->id != 'system') {
         $person = $user;
     } else {
         $from = $email->get('from');
         if ($from) {
             $person = $this->getEntityManager()->getRepository('EmailAddress')->getEntityByAddress($from);
         }
     }
     if ($person) {
         $data['personEntityType'] = $person->getEntityName();
         $data['personEntityName'] = $person->get('name');
         $data['personEntityId'] = $person->id;
     }
     $note->set('data', $data);
     $this->getEntityManager()->saveEntity($note);
 }