protected function loadLinkMultipleFields(Entity $entity) { $fieldDefs = $this->getMetadata()->get('entityDefs.' . $entity->getEntityType() . '.fields', array()); foreach ($fieldDefs as $field => $defs) { if (isset($defs['type']) && in_array($defs['type'], ['linkMultiple', 'attachmentMultiple']) && empty($defs['noLoad'])) { $columns = null; if (!empty($defs['columns'])) { $columns = $defs['columns']; } $entity->loadLinkMultipleField($field, $columns); } } }
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')); } } } } }
public function checkInTeam(User $user, Entity $entity) { $userTeamIds = $user->get('teamsIds'); if (!$entity->hasRelation('teams') || !$entity->hasField('teamsIds')) { return false; } if (!$entity->has('teamsIds')) { $entity->loadLinkMultipleField('teams'); } $teamIds = $entity->get('teamsIds'); if (empty($teamIds)) { return false; } foreach ($userTeamIds as $id) { if (in_array($id, $teamIds)) { return true; } } return false; }
public function loadBccField(Entity $entity) { $entity->loadLinkMultipleField('bccEmailAddresses'); $names = $entity->get('bccEmailAddressesNames'); if (!empty($names)) { $arr = array(); foreach ($names as $id => $address) { $arr[] = $address; } $entity->set('bcc', implode(';', $arr)); } }