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); } } }
public function afterSave(Entity $entity, array $options = []) { if (!empty($options['silent']) || !empty($options['noNotifications'])) { return; } if ($this->getConfig()->get('assignmentEmailNotifications') && $entity->has('assignedUserId') && in_array($entity->getEntityType(), $this->getConfig()->get('assignmentEmailNotificationsEntityList', []))) { $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); } } }
public function getEntityReminders(Entity $entity) { $pdo = $this->getEntityManager()->getPDO(); $reminders = array(); $sql = "\n SELECT id, `seconds`, `type`\n FROM `reminder`\n WHERE\n `entity_type` = " . $pdo->quote($entity->getEntityType()) . " AND\n `entity_id` = " . $pdo->quote($entity->id) . " AND\n `deleted` = 0\n ORDER BY `seconds` ASC\n "; $sth = $pdo->prepare($sql); $sth->execute(); $rows = $sth->fetchAll(\PDO::FETCH_ASSOC); foreach ($rows as $row) { $o = new \StdClass(); $o->seconds = intval($row['seconds']); $o->type = $row['type']; $reminders[] = $o; } return $reminders; }
protected function afterUnrelateCases(Entity $entity, $foreign) { $case = null; if ($foreign instanceof Entity) { $case = $foreign; } else { if (is_string($foreign)) { $case = $this->getEntityManager()->getEntity('Case', $foreign); } } if (!$case) { return; } $note = $this->getEntityManager()->getRepository('Note')->where(array('type' => 'Relate', 'parentId' => $case->id, 'parentType' => 'Case', 'relatedId' => $entity->id, 'relatedType' => $entity->getEntityType()))->findOne(); if (!$note) { return; } $this->getEntityManager()->removeEntity($note); }
public function prepareEntityForOutput(Entity $entity) { foreach ($this->internalAttributeList as $field) { $entity->clear($field); } foreach ($this->getAcl()->getScopeForbiddenAttributeList($entity->getEntityType(), 'read') as $attribute) { $entity->clear($attribute); } }
public function logClicked($campaignId, $queueItemId = null, Entity $target, Entity $trackingUrl, $actionDate = null) { $this->logOpened($campaignId, $queueItemId, $target); if ($queueItemId && $this->getEntityManager()->getRepository('CampaignLogRecord')->where(array('queueItemId' => $queueItemId, 'action' => 'Clicked', 'objectId' => $trackingUrl->id, 'objectType' => $trackingUrl->getEntityType()))->findOne()) { return; } if (empty($actionDate)) { $actionDate = date('Y-m-d H:i:s'); } $logRecord = $this->getEntityManager()->getEntity('CampaignLogRecord'); $logRecord->set(array('campaignId' => $campaignId, 'actionDate' => $actionDate, 'parentId' => $target->id, 'parentType' => $target->getEntityType(), 'action' => 'Clicked', 'objectId' => $trackingUrl->id, 'objectType' => $trackingUrl->getEntityType(), 'queueItemId' => $queueItemId)); $this->getEntityManager()->saveEntity($logRecord); }
public function fetchFromMailServer(Entity $emailAccount) { if ($emailAccount->get('status') != 'Active') { throw new Error(); } $importer = new \Espo\Core\Mail\Importer($this->getEntityManager(), $this->getFileManager(), $this->getConfig()); $maxSize = $this->getConfig()->get('emailMessageMaxSize'); $user = $this->getEntityManager()->getEntity('User', $emailAccount->get('assignedUserId')); if (!$user) { throw new Error(); } $userId = $user->id; $teamId = $user->get('defaultTeamId'); $teamIds = array(); if (!empty($teamId)) { $teamIds[] = $teamId; } $filterCollection = $this->getEntityManager()->getRepository('EmailFilter')->where(['OR' => [['parentType' => $emailAccount->getEntityType(), 'parentId' => $emailAccount->id], ['parentId' => null]]])->find(); $fetchData = json_decode($emailAccount->get('fetchData'), true); if (empty($fetchData)) { $fetchData = array(); } if (!array_key_exists('lastUID', $fetchData)) { $fetchData['lastUID'] = array(); } if (!array_key_exists('lastUID', $fetchData)) { $fetchData['lastDate'] = array(); } $storage = $this->getStorage($emailAccount); $monitoredFolders = $emailAccount->get('monitoredFolders'); if (empty($monitoredFolders)) { throw new Error(); } $portionLimit = $this->getConfig()->get('personalEmailMaxPortionSize', self::PORTION_LIMIT); $monitoredFoldersArr = explode(',', $monitoredFolders); foreach ($monitoredFoldersArr as $folder) { $folder = mb_convert_encoding(trim($folder), 'UTF7-IMAP', 'UTF-8'); try { $storage->selectFolder($folder); } catch (\Exception $e) { $GLOBALS['log']->error('EmailAccount ' . $emailAccount->id . ' (Select Folder) [' . $e->getCode() . '] ' . $e->getMessage()); continue; } $lastUID = 0; $lastDate = 0; if (!empty($fetchData['lastUID'][$folder])) { $lastUID = $fetchData['lastUID'][$folder]; } if (!empty($fetchData['lastDate'][$folder])) { $lastDate = $fetchData['lastDate'][$folder]; } if (!empty($lastUID)) { $ids = $storage->getIdsFromUID($lastUID); } else { $dt = new \DateTime($emailAccount->get('fetchSince')); if ($dt) { $ids = $storage->getIdsFromDate($dt->format('d-M-Y')); } else { return false; } } if (count($ids) == 1 && !empty($lastUID)) { if ($storage->getUniqueId($ids[0]) == $lastUID) { continue; } } $k = 0; foreach ($ids as $i => $id) { if ($k == count($ids) - 1) { $lastUID = $storage->getUniqueId($id); } if ($maxSize) { if ($storage->getSize($id) > $maxSize * 1024 * 1024) { $k++; continue; } } $message = null; $email = null; try { $message = $storage->getMessage($id); if ($message && $emailAccount->get('keepFetchedEmailsUnread')) { $flags = $message->getFlags(); } try { $email = $importer->importMessage($message, $userId, $teamIds, $filterCollection); } catch (\Exception $e) { $GLOBALS['log']->error('EmailAccount ' . $emailAccount->id . ' (Import Message): [' . $e->getCode() . '] ' . $e->getMessage()); } if ($emailAccount->get('keepFetchedEmailsUnread')) { if (is_array($flags) && empty($flags[Storage::FLAG_SEEN])) { $storage->setFlags($id, $flags); } } } catch (\Exception $e) { $GLOBALS['log']->error('EmailAccount ' . $emailAccount->id . ' (Get Message): [' . $e->getCode() . '] ' . $e->getMessage()); } if (!empty($email)) { $this->noteAboutEmail($email); } if ($k == count($ids) - 1) { $lastUID = $storage->getUniqueId($id); if ($message && isset($message->date)) { $dt = new \DateTime($message->date); if ($dt) { $dateSent = $dt->setTimezone(new \DateTimeZone('UTC'))->format('Y-m-d H:i:s'); $lastDate = $dateSent; } } } if ($k == $portionLimit - 1) { $lastUID = $storage->getUniqueId($id); break; } $k++; } $fetchData['lastUID'][$folder] = $lastUID; $fetchData['lastDate'][$folder] = $lastDate; $emailAccount->set('fetchData', json_encode($fetchData)); $this->getEntityManager()->saveEntity($emailAccount, array('silent' => true)); } $storage->close(); return true; }
protected function parseText($type, Entity $entity, $text) { $fieldList = array_keys($entity->getFields()); foreach ($fieldList as $field) { $value = $entity->get($field); if (is_object($value)) { continue; } $fieldType = $this->getMetadata()->get('entityDefs.' . $entity->getEntityType() . '.fields.' . $field . '.type'); if ($fieldType === 'enum') { $value = $this->getLanguage()->translateOption($value, $field, $entity->getEntityType()); } else { if ($entity->fields[$field]['type'] == 'date') { $value = $this->getDateTime()->convertSystemDateToGlobal($value); } else { if ($entity->fields[$field]['type'] == 'datetime') { $value = $this->getDateTime()->convertSystemDateTimeToGlobal($value); } } } $text = str_replace('{' . $type . '.' . $field . '}', $value, $text); } return $text; }
public function checkEntity(User $user, Entity $entity, $action) { $scope = $entity->getEntityType(); $data = $this->getTable($user)->getScopeData($scope); $impl = $this->getImplementation($scope); $methodName = 'checkEntity' . ucfirst($action); if (method_exists($impl, $methodName)) { return $impl->{$methodName}($user, $entity, $data); } return $impl->checkEntity($user, $entity, $data, $action); }
public function checkEntity(User $user, Entity $entity, $action) { if ($user->isAdmin()) { return true; } $data = $this->getTable($user)->getScopeData($entity->getEntityType()); return $this->getImplementation($entity->getEntityType())->checkEntity($user, $entity, $data, $action); }
public function fetchFromMailServer(Entity $emailAccount) { if ($emailAccount->get('status') != 'Active') { throw new Error(); } $importer = new \Espo\Core\Mail\Importer($this->getEntityManager(), $this->getFileManager(), $this->getConfig()); $maxSize = $this->getConfig()->get('emailMessageMaxSize'); $teamId = $emailAccount->get('teamId'); $userId = $this->getUser()->id; if ($emailAccount->get('assignToUserId')) { $userId = $emailAccount->get('assignToUserId'); } $teamIds = array(); if (!empty($teamId)) { $teamIds[] = $teamId; } $filterCollection = $this->getEntityManager()->getRepository('EmailFilter')->where(['OR' => [['parentType' => $emailAccount->getEntityType(), 'parentId' => $emailAccount->id], ['parentId' => null]]])->find(); $fetchData = json_decode($emailAccount->get('fetchData'), true); if (empty($fetchData)) { $fetchData = array(); } if (!array_key_exists('lastUID', $fetchData)) { $fetchData['lastUID'] = array(); } if (!array_key_exists('lastUID', $fetchData)) { $fetchData['lastDate'] = array(); } $imapParams = array('host' => $emailAccount->get('host'), 'port' => $emailAccount->get('port'), 'user' => $emailAccount->get('username'), 'password' => $this->getCrypt()->decrypt($emailAccount->get('password'))); if ($emailAccount->get('ssl')) { $imapParams['ssl'] = 'SSL'; } $storage = new \Espo\Core\Mail\Mail\Storage\Imap($imapParams); $monitoredFolders = $emailAccount->get('monitoredFolders'); if (empty($monitoredFolders)) { $monitoredFolders = 'INBOX'; } $monitoredFoldersArr = explode(',', $monitoredFolders); foreach ($monitoredFoldersArr as $folder) { $folder = mb_convert_encoding(trim($folder), 'UTF7-IMAP', 'UTF-8'); try { $storage->selectFolder($folder); } catch (\Exception $e) { $GLOBALS['log']->error('InboundEmail ' . $emailAccount->id . ' (Select Folder) [' . $e->getCode() . '] ' . $e->getMessage()); continue; } $lastUID = 0; $lastDate = 0; if (!empty($fetchData['lastUID'][$folder])) { $lastUID = $fetchData['lastUID'][$folder]; } if (!empty($fetchData['lastDate'][$folder])) { $lastDate = $fetchData['lastDate'][$folder]; } $ids = $storage->getIdsFromUID($lastUID); if (count($ids) == 1 && !empty($lastUID)) { if ($storage->getUniqueId($ids[0]) == $lastUID) { continue; } } $k = 0; foreach ($ids as $i => $id) { $toSkip = false; if ($k == count($ids) - 1) { $lastUID = $storage->getUniqueId($id); } if ($maxSize) { if ($storage->getSize($id) > $maxSize * 1024 * 1024) { $k++; continue; } } $message = null; $email = null; try { $message = $storage->getMessage($id); if ($message && isset($message->from)) { $fromString = $message->from; if (preg_match('/MAILER-DAEMON|POSTMASTER/i', $fromString)) { $toSkip = true; try { $this->processBouncedMessage($message); } catch (\Exception $e) { $GLOBALS['log']->error('InboundEmail ' . $emailAccount->id . ' (Process Bounced Message: [' . $e->getCode() . '] ' . $e->getMessage()); } } } if (!$toSkip) { try { $email = $importer->importMessage($message, $userId, $teamIds, $filterCollection); } catch (\Exception $e) { $GLOBALS['log']->error('InboundEmail ' . $emailAccount->id . ' (Import Message): [' . $e->getCode() . '] ' . $e->getMessage()); } } } catch (\Exception $e) { $GLOBALS['log']->error('InboundEmail ' . $emailAccount->id . ' (Get Message): [' . $e->getCode() . '] ' . $e->getMessage()); } if (!empty($email)) { if (!$emailAccount->get('createCase')) { $this->noteAboutEmail($email); } if ($emailAccount->get('createCase')) { $this->createCase($emailAccount, $email); } else { if ($emailAccount->get('reply')) { $user = $this->getEntityManager()->getEntity('User', $userId); $this->autoReply($emailAccount, $email, $user); } } } if ($k == count($ids) - 1) { if ($message && isset($message->date)) { $dt = new \DateTime($message->date); if ($dt) { $dateSent = $dt->setTimezone(new \DateTimeZone('UTC'))->format('Y-m-d H:i:s'); $lastDate = $dateSent; } } } if ($k == self::PORTION_LIMIT - 1) { $lastUID = $storage->getUniqueId($id); break; } $k++; } $fetchData['lastUID'][$folder] = $lastUID; $fetchData['lastDate'][$folder] = $lastDate; $emailAccount->set('fetchData', json_encode($fetchData)); $this->getEntityManager()->saveEntity($emailAccount, array('silent' => true)); } return true; }
public function beforeRemove(Entity $entity, array $options = array()) { if (!empty($options['silent']) && !empty($options['noNotifications'])) { return; } $entityType = $entity->getEntityType(); if ($this->checkHasStream($entityType)) { $followersData = $this->getStreamService()->getEntityFollowers($entity); foreach ($followersData['idList'] as $userId) { if ($userId === $this->getUser()->id) { continue; } $notification = $this->getEntityManager()->getEntity('Notification'); $notification->set(array('userId' => $userId, 'type' => 'EntityRemoved', 'data' => array('entityType' => $entity->getEntityType(), 'entityId' => $entity->id, 'entityName' => $entity->get('name'), 'userId' => $this->getUser()->id, 'userName' => $this->getUser()->get('name')))); $this->getEntityManager()->saveEntity($notification); } } }
protected function handleSpecifiedRelations(Entity $entity) { $relationTypeList = [$entity::HAS_MANY, $entity::MANY_MANY, $entity::HAS_CHILDREN]; foreach ($entity->getRelations() as $name => $defs) { if (in_array($defs['type'], $relationTypeList)) { $fieldName = $name . 'Ids'; $columnsFieldsName = $name . 'Columns'; if ($entity->has($fieldName) || $entity->has($columnsFieldsName)) { if ($this->getMetadata()->get("entityDefs." . $entity->getEntityType() . ".fields.{$name}.noSave")) { continue; } if ($entity->has($fieldName)) { $specifiedIds = $entity->get($fieldName); } else { $specifiedIds = array(); foreach ($entity->get($columnsFieldsName) as $id => $d) { $specifiedIds[] = $id; } } if (is_array($specifiedIds)) { $toRemoveIds = array(); $existingIds = array(); $toUpdateIds = array(); $existingColumnsData = new \stdClass(); $defs = array(); $columns = $this->getMetadata()->get("entityDefs." . $entity->getEntityType() . ".fields.{$name}.columns"); if (!empty($columns)) { $columnData = $entity->get($columnsFieldsName); $defs['additionalColumns'] = $columns; } $foreignCollection = $entity->get($name, $defs); if ($foreignCollection) { foreach ($foreignCollection as $foreignEntity) { $existingIds[] = $foreignEntity->id; if (!empty($columns)) { $data = new \stdClass(); foreach ($columns as $columnName => $columnField) { $foreignId = $foreignEntity->id; $data->{$columnName} = $foreignEntity->get($columnField); } $existingColumnsData->{$foreignId} = $data; $entity->setFetched($columnsFieldsName, $existingColumnsData); } } } if ($entity->has($fieldName)) { $entity->setFetched($fieldName, $existingIds); } if ($entity->has($columnsFieldsName) && !empty($columns)) { $entity->setFetched($columnsFieldsName, $existingColumnsData); } foreach ($existingIds as $id) { if (!in_array($id, $specifiedIds)) { $toRemoveIds[] = $id; } else { if (!empty($columns)) { foreach ($columns as $columnName => $columnField) { if ($columnData->{$id}->{$columnName} != $existingColumnsData->{$id}->{$columnName}) { $toUpdateIds[] = $id; } } } } } foreach ($specifiedIds as $id) { if (!in_array($id, $existingIds)) { $data = null; if (!empty($columns) && isset($columnData->{$id})) { $data = $columnData->{$id}; } $this->relate($entity, $name, $id, $data); } } foreach ($toRemoveIds as $id) { $this->unrelate($entity, $name, $id); } if (!empty($columns)) { foreach ($toUpdateIds as $id) { $data = $columnData->{$id}; $this->updateRelation($entity, $name, $id, $data); } } } } } else { if ($defs['type'] === $entity::HAS_ONE) { if (empty($defs['entity']) || empty($defs['foreignKey'])) { return; } if ($this->getMetadata()->get("entityDefs." . $entity->getEntityType() . ".fields.{$name}.noSave")) { continue; } $foreignEntityType = $defs['entity']; $foreignKey = $defs['foreignKey']; $idFieldName = $name . 'Id'; $nameFieldName = $name . 'Name'; if (!$entity->has($idFieldName)) { return; } $where = array(); $where[$foreignKey] = $entity->id; $previousForeignEntity = $this->getEntityManager()->getRepository($foreignEntityType)->where($where)->findOne(); if ($previousForeignEntity) { $entity->setFetched($idFieldName, $previousForeignEntity->id); if ($previousForeignEntity->id !== $entity->get($idFieldName)) { $previousForeignEntity->set($foreignKey, null); $this->getEntityManager()->saveEntity($previousForeignEntity); } } else { $entity->setFetched($idFieldName, null); } if ($entity->get($idFieldName)) { $newForeignEntity = $this->getEntityManager()->getEntity($foreignEntityType, $entity->get($idFieldName)); if ($newForeignEntity) { $newForeignEntity->set($foreignKey, $entity->id); $this->getEntityManager()->saveEntity($newForeignEntity); } else { $entity->set($idFieldName, null); } } } } } }
public function afterSave(Entity $entity, array $options = array()) { $entityName = $entity->getEntityType(); if ($this->checkHasStream($entity)) { if ($entity->isNew()) { $userIdList = []; $assignedUserId = $entity->get('assignedUserId'); $createdById = $entity->get('createdById'); if ($this->getConfig()->get('followCreatedEntities') && !empty($createdById)) { $userIdList[] = $createdById; } if (!empty($assignedUserId) && !in_array($assignedUserId, $userIdList)) { $userIdList[] = $assignedUserId; } if (!empty($userIdList)) { $this->getStreamService()->followEntityMass($entity, $userIdList); } if (empty($options['noStream']) && empty($options['silent'])) { $this->getStreamService()->noteCreate($entity); } if (in_array($this->getUser()->id, $userIdList)) { $entity->set('isFollowed', true); } $autofollowUserIdList = $this->getAutofollowUserIdList($entity, $userIdList); foreach ($autofollowUserIdList as $i => $userId) { if (in_array($userId, $userIdList)) { unset($autofollowUserIdList[$i]); } } $autofollowUserIdList = array_values($autofollowUserIdList); if (!empty($autofollowUserIdList)) { $job = $this->getEntityManager()->getEntity('Job'); $job->set(array('serviceName' => 'Stream', 'method' => 'afterRecordCreatedJob', 'data' => array('userIdList' => $autofollowUserIdList, 'entityType' => $entity->getEntityType(), 'entityId' => $entity->id))); $this->getEntityManager()->saveEntity($job); } } else { if (empty($options['noStream']) && empty($options['silent'])) { if ($entity->isFieldChanged('assignedUserId')) { $assignedUserId = $entity->get('assignedUserId'); if (!empty($assignedUserId)) { $this->getStreamService()->followEntity($entity, $assignedUserId); $this->getStreamService()->noteAssign($entity); if ($this->getUser()->id === $assignedUserId) { $entity->set('isFollowed', true); } } } $this->getStreamService()->handleAudited($entity); $statusFields = $this->getStatusFields(); if (array_key_exists($entityName, $this->statusFields)) { $field = $this->statusFields[$entityName]; $value = $entity->get($field); if (!empty($value) && $value != $entity->getFetched($field)) { $this->getStreamService()->noteStatus($entity, $field); } } } } } if ($entity->isNew() && empty($options['noStream']) && empty($options['silent']) && $this->getMetadata()->get("scopes.{$entityName}.tab")) { $this->handleCreateRelated($entity); } }
public function getEntityFollowers(Entity $entity, $offset = 0, $limit = false) { $query = $this->getEntityManager()->getQuery(); $pdo = $this->getEntityManager()->getPDO(); if (!$limit) { $limit = 200; } $sql = $query->createSelectQuery('User', array('select' => ['id', 'name'], 'customJoin' => "\n JOIN subscription AS `subscription` ON\n subscription.user_id = user.id AND\n subscription.entity_id = " . $query->quote($entity->id) . " AND\n subscription.entity_type = " . $query->quote($entity->getEntityType()) . "\n ", 'offset' => $offset, 'limit' => $limit, 'whereClause' => array('isActive' => true), 'orderBy' => [['LIST:id:' . $this->getUser()->id, 'DESC'], ['name']])); $sth = $pdo->prepare($sql); $sth->execute(); $data = array('idList' => [], 'nameMap' => new \StdClass()); while ($row = $sth->fetch(\PDO::FETCH_ASSOC)) { $id = $row['id']; $data['idList'][] = $id; $data['nameMap']->{$id} = $row['name']; } return $data; }
protected function handleSpecifiedRelations(Entity $entity) { $relationTypes = array($entity::HAS_MANY, $entity::MANY_MANY, $entity::HAS_CHILDREN); foreach ($entity->getRelations() as $name => $defs) { if (in_array($defs['type'], $relationTypes)) { $fieldName = $name . 'Ids'; $columnsFieldsName = $name . 'Columns'; if ($entity->has($fieldName) || $entity->has($columnsFieldsName)) { if ($this->getMetadata()->get("entityDefs." . $entity->getEntityType() . ".fields.{$name}.noSave")) { continue; } if ($entity->has($fieldName)) { $specifiedIds = $entity->get($fieldName); } else { $specifiedIds = array(); foreach ($entity->get($columnsFieldsName) as $id => $d) { $specifiedIds[] = $id; } } if (is_array($specifiedIds)) { $toRemoveIds = array(); $existingIds = array(); $toUpdateIds = array(); $existingColumnsData = new \stdClass(); $defs = array(); $columns = $this->getMetadata()->get("entityDefs." . $entity->getEntityType() . ".fields.{$name}.columns"); if (!empty($columns)) { $columnData = $entity->get($columnsFieldsName); $defs['additionalColumns'] = $columns; } $foreignCollection = $entity->get($name, $defs); if ($foreignCollection) { foreach ($foreignCollection as $foreignEntity) { $existingIds[] = $foreignEntity->id; if (!empty($columns)) { $data = new \stdClass(); foreach ($columns as $columnName => $columnField) { $foreignId = $foreignEntity->id; $data->{$columnName} = $foreignEntity->get($columnField); } $existingColumnsData->{$foreignId} = $data; $entity->setFetched($columnsFieldsName, $existingColumnsData); } } } if ($entity->has($fieldName)) { $entity->setFetched($fieldName, $existingIds); } if ($entity->has($columnsFieldsName) && !empty($columns)) { $entity->setFetched($columnsFieldsName, $existingColumnsData); } foreach ($existingIds as $id) { if (!in_array($id, $specifiedIds)) { $toRemoveIds[] = $id; } else { if (!empty($columns)) { foreach ($columns as $columnName => $columnField) { if ($columnData->{$id}->{$columnName} != $existingColumnsData->{$id}->{$columnName}) { $toUpdateIds[] = $id; } } } } } foreach ($specifiedIds as $id) { if (!in_array($id, $existingIds)) { $data = null; if (!empty($columns) && isset($columnData->{$id})) { $data = $columnData->{$id}; } $this->relate($entity, $name, $id, $data); } } foreach ($toRemoveIds as $id) { $this->unrelate($entity, $name, $id); } if (!empty($columns)) { foreach ($toUpdateIds as $id) { $data = $columnData->{$id}; $this->updateRelation($entity, $name, $id, $data); } } } } } } }
protected function loadPhoneNumberField(Entity $entity) { $fieldDefs = $this->getMetadata()->get('entityDefs.' . $entity->getEntityType() . '.fields', array()); if (!empty($fieldDefs['phoneNumber']) && $fieldDefs['phoneNumber']['type'] == 'phone') { $dataFieldName = 'phoneNumberData'; $entity->set($dataFieldName, $this->getEntityManager()->getRepository('PhoneNumber')->getPhoneNumberData($entity)); } }
public function checkIsOwnContact(User $user, Entity $entity) { $contactId = $user->get('contactId'); if ($contactId) { if ($entity->hasAttribute('contactId')) { if ($entity->get('contactId') === $contactId) { return true; } } if ($entity->hasRelation('contacts')) { $repository = $this->getEntityManager()->getRepository($entity->getEntityType()); if ($repository->isRelated($entity, 'contacts', $contactId)) { return true; } } if ($entity->hasAttribute('parentId') && $entity->hasRelation('parent')) { if ($entity->get('parentType') === 'Contact') { if ($entity->get('parentId') === $contactId) { return true; } } } } return false; }