public function afterSave(Entity $entity, array $options) { parent::afterSave($entity, $options); if ($entity->has('targetListId')) { $this->relate($entity, 'targetLists', $entity->get('targetListId')); } }
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(); } } } }
public function afterRemove(Entity $entity, $options) { parent::afterRemove($entity, $options); $pdo = $this->getEntityManager()->getPDO(); $query = $this->getEntityManager()->getQuery(); $pathsTableName = $query->toDb($entity->getEntityType() . 'Path'); $sql = "DELETE FROM `" . $pathsTableName . "` WHERE descendor_id = " . $pdo->quote($entity->id) . ""; $pdo->query($sql); }
public function get($id = null) { $entity = parent::get($id); if (empty($entity) && !empty($id)) { $entity = $this->get(); $entity->id = $id; } return $entity; }
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; }
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); } } }
protected function afterRemove(Entity $entity, array $options = array()) { if ($entity->get('fileId')) { $attachment = $this->getEntityManager()->getEntity('Attachment', $entity->get('fileId')); if ($attachment) { $this->getEntityManager()->removeEntity($attachment); } } $pdo = $this->getEntityManager()->getPDO(); $sql = "DELETE FROM import_entity WHERE import_id = :importId"; $sth = $pdo->prepare($sql); $sth->bindValue(':importId', $entity->id); $sth->execute(); parent::afterRemove($entity, $options); }
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); } } } }
protected function getNewEntity() { $entity = parent::getNewEntity(); $entity->set('name', uniqid()); return $entity; }
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); } } } } }
public function afterSave(Entity $entity, array $options) { $result = parent::afterSave($entity, $options); $this->handleAfterSaveContacts($entity, $options); return $result; }
protected function afterRemove(Entity $entity, array $options = array()) { parent::afterRemove($entity, $options); $this->getFileManager()->removeFile('data/upload/' . $entity->id); }