public function save(Entity $entity) { $result = parent::save($entity); $accountIdChanged = $entity->has('accountId') && $entity->get('accountId') != $entity->getFetched('accountId'); $titleChanged = $entity->has('title') && $entity->get('title') != $entity->getFetched('title'); if ($accountIdChanged) { $accountId = $entity->get('accountId'); if (empty($accountId)) { $this->unrelate($entity, 'accounts', $entity->getFetched('accountId')); return $result; } } if ($titleChanged) { if (empty($accountId)) { $accountId = $entity->getFetched('accountId'); if (empty($accountId)) { return $result; } } } if ($accountIdChanged || $titleChanged) { $pdo = $this->getEntityManager()->getPDO(); $sql = "\n\t\t\t\tSELECT id, role FROM account_contact\n\t\t\t\tWHERE \n\t\t\t\t\taccount_id = " . $pdo->quote($accountId) . " AND\n\t\t\t\t\tcontact_id = " . $pdo->quote($entity->id) . " AND\n\t\t\t\t\tdeleted = 0\t\t\t\t\t\n\t\t\t"; $sth = $pdo->prepare($sql); if ($row = $sth->fetch()) { if ($titleChanged && $entity->get('title') != $row['role']) { $this->updateRelation($entity, 'accounts', $accountId, array('role' => $entity->get('title'))); } } else { $this->relate($entity, 'accounts', $accountId, array('role' => $entity->get('title'))); } } return $result; }
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 afterSave(Entity $entity, array $options) { parent::afterSave($entity, $options); if ($entity->has('targetListId')) { $this->relate($entity, 'targetLists', $entity->get('targetListId')); } }
protected function beforeRemove(Entity $entity) { parent::beforeRemove($entity); $attachments = $entity->get('attachments'); foreach ($attachments as $attachment) { $this->getEntityManager()->removeEntity($attachment); } }
public function handleSelectParams(&$params) { parent::handleSelectParams($params); if (empty($params['customJoin'])) { $params['customJoin'] = ''; } $params['customJoin'] .= " \n\t\t\tLEFT JOIN currency ON currency.id = lead.opportunity_amount_currency\n\t\t"; }
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; }
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)) { $accountId = null; if ($parent->getEntityType() == 'Account') { $accountId = $parent->id; } else { if ($parent->get('accountId')) { $accountId = $parent->get('accountId'); } else { if ($parent->getEntityType() == 'Lead') { if ($parent->get('status') == 'Converted') { if ($parent->get('createdAccountId')) { $accountId = $parent->get('createdAccountId'); } } } } } if (!empty($accountId)) { $entity->set('accountId', $accountId); } } } }
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->has('isDefault')) { if ($entity->get('isDefault')) { $this->getConfig()->set('defaultPortalId', $entity->id); } else { $this->getConfig()->set('defaultPortalId', null); } $this->getConfig()->save(); } }
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->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(); } } } if ($entity->has('isAdmin') && $entity->get('isAdmin')) { $entity->set('isPortalUser', false); $entity->set('portalRolesIds', []); $entity->set('portalRolesNames', (object) []); $entity->set('portalsIds', []); $entity->set('portalsNames', (object) []); } if ($entity->has('isPortalUser') && $entity->get('isPortalUser')) { $entity->set('isAdmin', false); $entity->set('rolesIds', []); $entity->set('rolesNames', (object) []); $entity->set('teamsIds', []); $entity->set('teamsNames', (object) []); $entity->set('defaultTeamId', null); $entity->set('defaultTeamName', null); } }
protected function beforeSave(Entity $entity) { parent::beforeSave($entity); $parentId = $entity->get('parentId'); $parentType = $entity->get('parentType'); if (!empty($parentId) || !empty($parentType)) { $parent = $this->getEntityManager()->getEntity($parentType, $parentId); if (!empty($parent)) { if ($parent->getEntityName() == 'Account') { $accountId = $parent->id; } else { if ($parent->has('accountId')) { $accountId = $parent->get('accountId'); } } if (!empty($accountId)) { $entity->set('accountId', $accountId); } } } }
public function afterSave(Entity $entity, array $options) { $result = parent::afterSave($entity, $options); $this->handleAfterSaveContacts($entity, $options); return $result; }
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); } } } } }
protected function afterRemove(Entity $entity) { parent::afterRemove($entity); $this->getFileManager()->removeFile('data/upload/' . $entity->id); }
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() || $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()) { parent::afterRemove($entity, $options); $this->getFileManager()->removeFile('data/upload/' . $entity->id); }