예제 #1
0
 public function afterSave(Entity $entity, $options)
 {
     parent::afterSave($entity, $options);
     $pdo = $this->getEntityManager()->getPDO();
     $query = $this->getEntityManager()->getQuery();
     $parentId = $entity->get('parentId');
     $pathsTableName = $query->toDb($entity->getEntityType() . 'Path');
     if ($entity->isNew()) {
         if ($parentId) {
             $sql = "\n\t\t\t\t\tINSERT INTO `" . $pathsTableName . "` (ascendor_id, descendor_id)\n\t\t\t\t\t\tSELECT ascendor_id, " . $pdo->quote($entity->id) . "\n\t\t\t\t\t\tFROM `" . $pathsTableName . "`\n\t\t\t\t\t\tWHERE descendor_id = " . $pdo->quote($parentId) . "\n\t\t\t\t\t\tUNION ALL\n\t\t\t\t\t\tSELECT " . $pdo->quote($entity->id) . ", " . $pdo->quote($entity->id) . "\n\t\t\t\t";
         } else {
             $sql = "\n\t\t\t\t\tINSERT INTO `" . $pathsTableName . "` (ascendor_id, descendor_id)\n\t\t\t\t\tVALUES\n\t\t\t\t\t(" . $pdo->quote($entity->id) . ", " . $pdo->quote($entity->id) . ")\n\t\t\t\t";
         }
         $pdo->query($sql);
     } else {
         if ($entity->isFieldChanged('parentId')) {
             $sql = "\n\t\t\t\t\tDELETE a FROM `" . $pathsTableName . "` AS a\n\t\t\t\t\tJOIN `" . $pathsTableName . "` AS d ON a.descendor_id = d.descendor_id\n\t\t\t\t\tLEFT JOIN `" . $pathsTableName . "` AS x ON x.ascendor_id = d.ascendor_id AND x.descendor_id = a.ascendor_id\n\t\t\t\t\tWHERE d.ascendor_id = " . $pdo->quote($entity->id) . " AND x.ascendor_id IS NULL\n\t\t\t\t";
             $pdo->query($sql);
             if (!empty($parentId)) {
                 $sql = "\n\t\t\t\t\t\tINSERT INTO `" . $pathsTableName . "` (ascendor_id, descendor_id)\n\t\t\t\t\t\t\tSELECT supertree.ascendor_id, subtree.descendor_id\n\t\t\t\t\t\t\tFROM `" . $pathsTableName . "` AS supertree\n\t\t\t\t\t\t\tJOIN `" . $pathsTableName . "` AS subtree\n\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\tsubtree.ascendor_id = " . $pdo->quote($entity->id) . " AND\n\t\t\t\t\t\t\t\tsupertree.descendor_id = " . $pdo->quote($parentId) . "\n\t\t\t\t\t";
                 $pdo->query($sql);
             }
         }
     }
 }
예제 #2
0
파일: Lead.php 프로젝트: chinazan/zzcrm
 public function afterSave(Entity $entity, array $options)
 {
     parent::afterSave($entity, $options);
     if ($entity->has('targetListId')) {
         $this->relate($entity, 'targetLists', $entity->get('targetListId'));
     }
 }
예제 #3
0
파일: Contact.php 프로젝트: chinazan/zzcrm
 public function afterSave(Entity $entity, array $options)
 {
     $result = parent::afterSave($entity, $options);
     $this->handleAfterSaveAccounts($entity, $options);
     if ($entity->has('targetListId') && $entity->isNew()) {
         $this->relate($entity, 'targetLists', $entity->get('targetListId'));
     }
     return $result;
 }
예제 #4
0
파일: Meeting.php 프로젝트: chinazan/zzcrm
 protected function afterSave(Entity $entity, array $options)
 {
     parent::afterSave($entity, $options);
     if ($entity->isNew() || $entity->isFieldChanged('assignedUserId') || $entity->isFieldChanged('dateStart') || $entity->has('reminders')) {
         $pdo = $this->getEntityManager()->getPDO();
         $reminderTypeList = $this->getMetadata()->get('entityDefs.Reminder.fields.type.options');
         if (!$entity->has('reminders')) {
             $reminders = $this->getEntityReminders($entity);
         } else {
             $reminders = $entity->get('reminders');
         }
         if (!$entity->isNew()) {
             $sql = "\n                    DELETE FROM `reminder`\n                    WHERE\n                        entity_id = " . $pdo->quote($entity->id) . " AND\n                        entity_type = " . $pdo->quote($entity->getEntityName()) . " AND\n                        deleted = 0\n                ";
             $pdo->query($sql);
         }
         if (empty($reminders) || !is_array($reminders)) {
             return;
         }
         $entityType = $entity->getEntityName();
         $dateStart = $entity->get('dateStart');
         $assignedUserId = $entity->get('assignedUserId');
         if (!$dateStart || !$assignedUserId) {
             $e = $this->get($entity->id);
             if ($e) {
                 $dateStart = $e->get('dateStart');
                 $assignedUserId = $e->get('assignedUserId');
             }
         }
         if (!$dateStart || !$assignedUserId) {
             return;
         }
         $dateStartObj = new \DateTime($dateStart);
         if (!$dateStartObj) {
             return;
         }
         foreach ($reminders as $item) {
             $remindAt = clone $dateStartObj;
             $seconds = intval($item->seconds);
             $type = $item->type;
             if (!in_array($type, $reminderTypeList)) {
                 continue;
             }
             $remindAt->sub(new \DateInterval('PT' . $seconds . 'S'));
             $id = uniqid();
             $sql = "\n                    INSERT\n                    INTO `reminder`\n                    (id, entity_id, entity_type, `type`, user_id, remind_at, start_at, `seconds`)\n                    VALUES (\n                        " . $pdo->quote($id) . ",\n                        " . $pdo->quote($entity->id) . ",\n                        " . $pdo->quote($entityType) . ",\n                        " . $pdo->quote($type) . ",\n                        " . $pdo->quote($assignedUserId) . ",\n                        " . $pdo->quote($remindAt->format('Y-m-d H:i:s')) . ",\n                        " . $pdo->quote($dateStart) . ",\n                        " . $pdo->quote($seconds) . "\n                    )\n                ";
             $pdo->query($sql);
         }
     }
 }
예제 #5
0
파일: Email.php 프로젝트: chinazan/zzcrm
 protected function afterSave(Entity $entity, array $options)
 {
     parent::afterSave($entity, $options);
     if (!$entity->isNew()) {
         if ($entity->get('parentType') && $entity->get('parentId') && $entity->isFieldChanged('parentId')) {
             $replyList = $this->findRelated($entity, 'replies');
             foreach ($replyList as $reply) {
                 if ($reply->id === $entity->id) {
                     continue;
                 }
                 if (!$reply->get('parentId')) {
                     $reply->set(array('parentId' => $entity->get('parentId'), 'parentType' => $entity->get('parentType')));
                     $this->getEntityManager()->saveEntity($reply);
                 }
             }
         }
     }
 }
예제 #6
0
파일: CaseObj.php 프로젝트: chinazan/zzcrm
 public function afterSave(Entity $entity, array $options)
 {
     $result = parent::afterSave($entity, $options);
     $this->handleAfterSaveContacts($entity, $options);
     return $result;
 }