예제 #1
0
파일: User.php 프로젝트: chinazan/zzcrm
 protected function beforeSave(Entity $entity, array $options)
 {
     parent::beforeSave($entity, $options);
     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();
             }
         }
     }
 }
예제 #2
0
파일: Meeting.php 프로젝트: chinazan/zzcrm
 protected function beforeSave(Entity $entity, array $options)
 {
     parent::beforeSave($entity, $options);
     $parentId = $entity->get('parentId');
     $parentType = $entity->get('parentType');
     if (!empty($parentId) || !empty($parentType)) {
         $parent = $this->getEntityManager()->getEntity($parentType, $parentId);
         if (!empty($parent)) {
             if ($parent->getEntityType() == 'Account') {
                 $accountId = $parent->id;
             } else {
                 if ($parent->has('accountId')) {
                     $accountId = $parent->get('accountId');
                 }
             }
             if (!empty($accountId)) {
                 $entity->set('accountId', $accountId);
             }
         }
     }
     $assignedUserId = $entity->get('assignedUserId');
     if ($assignedUserId && $entity->has('usersIds')) {
         $usersIds = $entity->get('usersIds');
         if (!is_array($usersIds)) {
             $usersIds = array();
         }
         if (!in_array($assignedUserId, $usersIds)) {
             $usersIds[] = $assignedUserId;
             $entity->set('usersIds', $usersIds);
             $hash = $entity->get('usersNames');
             if ($hash instanceof \StdClass) {
                 $hash->{$assignedUserId} = $entity->get('assignedUserName');
                 $entity->set('usersNames', $hash);
             }
         }
         if ($entity->isNew()) {
             $currentUserId = $this->getEntityManager()->getUser()->id;
             if (in_array($currentUserId, $usersIds)) {
                 $usersColumns = $entity->get('usersColumns');
                 if (empty($usersColumns)) {
                     $usersColumns = new \StdClass();
                 }
                 if ($usersColumns instanceof \StdClass) {
                     if (!$usersColumns->{$currentUserId} instanceof \StdClass) {
                         $usersColumns->{$currentUserId} = new \StdClass();
                     }
                     if (empty($usersColumns->{$currentUserId}->status)) {
                         $usersColumns->{$currentUserId}->status = 'Accepted';
                     }
                 }
             }
         }
     }
 }
예제 #3
0
파일: Task.php 프로젝트: chinazan/zzcrm
 protected function beforeSave(Entity $entity, array $options)
 {
     parent::beforeSave($entity, $options);
     if ($entity->isFieldChanged('status')) {
         if ($entity->get('status') == 'Completed') {
             $entity->set('dateCompleted', date('Y-m-d H:i:s'));
         } else {
             $entity->set('dateCompleted', null);
         }
     }
     if ($entity->has('dateStartDate')) {
         $dateStartDate = $entity->get('dateStartDate');
         if (!empty($dateStartDate)) {
             $dateStart = $dateStartDate . ' 00:00:00';
             $dateStart = $this->convertDateTimeToDefaultTimezone($dateStart);
             $entity->set('dateStart', $dateStart);
         } else {
             $entity->set('dateStartDate', null);
         }
     }
     if ($entity->has('dateEndDate')) {
         $dateEndDate = $entity->get('dateEndDate');
         if (!empty($dateEndDate)) {
             $dateEnd = $dateEndDate . ' 00:00:00';
             $dateEnd = $this->convertDateTimeToDefaultTimezone($dateEnd);
             $entity->set('dateEnd', $dateEnd);
         } else {
             $entity->set('dateEndDate', null);
         }
     }
     $parentId = $entity->get('parentId');
     $parentType = $entity->get('parentType');
     if (!empty($parentId) || !empty($parentType)) {
         $parent = $this->getEntityManager()->getEntity($parentType, $parentId);
         if (!empty($parent)) {
             if ($parent->getEntityType() == 'Account') {
                 $accountId = $parent->id;
             } else {
                 if ($parent->has('accountId')) {
                     $accountId = $parent->get('accountId');
                 }
             }
             if (!empty($accountId)) {
                 $entity->set('accountId', $accountId);
             }
         }
     }
 }
예제 #4
0
파일: Email.php 프로젝트: chinazan/zzcrm
 protected function beforeSave(Entity $entity, array $options)
 {
     $eaRepositoty = $this->getEntityManager()->getRepository('EmailAddress');
     if ($entity->has('attachmentsIds')) {
         $attachmentsIds = $entity->get('attachmentsIds');
         if (!empty($attachmentsIds)) {
             $entity->set('hasAttachment', true);
         }
     }
     if ($entity->has('from') || $entity->has('to') || $entity->has('cc') || $entity->has('bcc') || $entity->has('replyTo')) {
         if (!$entity->has('usersIds')) {
             $entity->loadLinkMultipleField('users');
         }
         if ($entity->has('from')) {
             $from = trim($entity->get('from'));
             if (!empty($from)) {
                 $ids = $eaRepositoty->getIds(array($from));
                 if (!empty($ids)) {
                     $entity->set('fromEmailAddressId', $ids[0]);
                     $this->setUsersIdsByEmailAddressId($entity, $ids[0]);
                 }
             } else {
                 $entity->set('fromEmailAddressId', null);
             }
         }
         if ($entity->has('to')) {
             $this->prepareAddressess($entity, 'to');
         }
         if ($entity->has('cc')) {
             $this->prepareAddressess($entity, 'cc');
         }
         if ($entity->has('bcc')) {
             $this->prepareAddressess($entity, 'bcc');
         }
         if ($entity->has('replyTo')) {
             $this->prepareAddressess($entity, 'replyTo');
         }
         $usersIds = $entity->get('usersIds');
         $assignedUserId = $entity->get('assignedUserId');
         if (!empty($assignedUserId) && !in_array($assignedUserId, $usersIds)) {
             $usersIds[] = $assignedUserId;
         }
         $entity->set('usersIds', $usersIds);
     }
     parent::beforeSave($entity, $options);
     $parentId = $entity->get('parentId');
     $parentType = $entity->get('parentType');
     if (!empty($parentId) || !empty($parentType)) {
         $parent = $this->getEntityManager()->getEntity($parentType, $parentId);
         if (!empty($parent)) {
             if ($parent->getEntityType() == 'Account') {
                 $accountId = $parent->id;
             } else {
                 if ($parent->has('accountId')) {
                     $accountId = $parent->get('accountId');
                 }
             }
             if (!empty($accountId)) {
                 $account = $this->getEntityManager()->getEntity('Account', $accountId);
                 if ($account) {
                     $entity->set('accountId', $accountId);
                     $entity->set('accountName', $account->get('name'));
                 }
             }
         }
     }
 }