public function afterSave(Entity $entity)
 {
     if ($this->getConfig()->get('assignmentEmailNotifications') && in_array($entity->getEntityName(), $this->getConfig()->get('assignmentEmailNotificationsEntityList', array()))) {
         $userId = $entity->get('assignedUserId');
         if (!empty($userId) && $userId != $this->getUser()->id && $entity->isFieldChanged('assignedUserId')) {
             $job = $this->getEntityManager()->getEntity('Job');
             $job->set(array('serviceName' => 'EmailNotification', 'method' => 'notifyAboutAssignmentJob', 'data' => json_encode(array('userId' => $userId, 'assignerUserId' => $this->getUser()->id, 'entityId' => $entity->id, 'entityType' => $entity->getEntityName())), 'executeTime' => date('Y-m-d H:i:s')));
             $this->getEntityManager()->saveEntity($job);
         }
     }
 }
Beispiel #2
0
 public function process(Entity $entity)
 {
     if ($entity->has('assignedUserId') && $entity->get('assignedUserId')) {
         $assignedUserId = $entity->get('assignedUserId');
         if ($assignedUserId != $this->getUser()->id && $entity->isFieldChanged('assignedUserId')) {
             $notification = $this->getEntityManager()->getEntity('Notification');
             $notification->set(array('type' => 'Assign', 'userId' => $assignedUserId, 'data' => array('entityType' => $entity->getEntityType(), 'entityId' => $entity->id, 'entityName' => $entity->get('name'), 'isNew' => $entity->isNew(), 'userId' => $this->getUser()->id, 'userName' => $this->getUser()->get('name'))));
             $this->getEntityManager()->saveEntity($notification);
         }
     }
 }
Beispiel #3
0
 protected function beforeSave(Entity $entity)
 {
     if ($entity->isNew()) {
         $userName = $entity->get('userName');
         if (empty($userName)) {
             throw new Error();
         }
         $user = $this->where(array('userName' => $userName))->findOne();
         if ($user) {
             throw new Error();
         }
     } else {
         if ($entity->isFieldChanged('userName')) {
             $userName = $entity->get('userName');
             if (empty($userName)) {
                 throw new Error();
             }
             $user = $this->where(array('userName' => $userName, 'id!=' => $entity->id))->findOne();
             if ($user) {
                 throw new Error();
             }
         }
     }
 }
Beispiel #4
0
 public function isPermittedAssignedUser(Entity $entity)
 {
     if (!$entity->hasField('assignedUserId')) {
         return true;
     }
     $assignedUserId = $entity->get('assignedUserId');
     if (empty($assignedUserId)) {
         return true;
     }
     $assignmentPermission = $this->getAcl()->get('assignmentPermission');
     if (empty($assignmentPermission) || $assignmentPermission === true || !in_array($assignmentPermission, ['team', 'no'])) {
         return true;
     }
     $toProcess = false;
     if (!$entity->isNew()) {
         if ($entity->isFieldChanged('assignedUserId')) {
             $toProcess = true;
         }
     } else {
         $toProcess = true;
     }
     if ($toProcess) {
         if ($assignmentPermission == 'no') {
             if ($this->getUser()->id != $assignedUserId) {
                 return false;
             }
         } else {
             if ($assignmentPermission == 'team') {
                 $teamIds = $this->getUser()->get('teamsIds');
                 if (!$this->getEntityManager()->getRepository('User')->checkBelongsToAnyOfTeams($assignedUserId, $teamIds)) {
                     return false;
                 }
             }
         }
     }
     return true;
 }