本文整理汇总了PHP中Espo\ORM\Entity::set方法的典型用法代码示例。如果您正苦于以下问题:PHP Entity::set方法的具体用法?PHP Entity::set怎么用?PHP Entity::set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Espo\ORM\Entity
的用法示例。
在下文中一共展示了Entity::set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: beforeSave
public function beforeSave(Entity $entity)
{
if (!$entity->has('executeTime')) {
$entity->set('executeTime', date('Y-m-d H:i:s'));
}
if (!$entity->has('attempts')) {
$attempts = $this->getConfig()->get('cron.attempts', 0);
$entity->set('attempts', $attempts);
}
}
示例2: loadUrlField
protected function loadUrlField(Entity $entity)
{
$siteUrl = $this->getConfig()->get('siteUrl');
$url = $siteUrl . '?entryPoint=portal';
if ($entity->id === $this->getConfig()->get('defaultPortalId')) {
$entity->set('isDefault', true);
} else {
$url .= '&id=' . $entity->id;
}
$entity->set('url', $url);
}
示例3: beforeSave
protected function beforeSave(Entity $entity)
{
$eaRepositoty = $this->getEntityManager()->getRepository('EmailAddress');
$from = trim($entity->get('from'));
if (!empty($from)) {
$ids = $eaRepositoty->getIds(array($from));
if (!empty($ids)) {
$entity->set('fromEmailAddressId', $ids[0]);
}
} else {
$entity->set('fromEmailAddressId', null);
}
$this->prepareAddressess($entity, 'to');
$this->prepareAddressess($entity, 'cc');
$this->prepareAddressess($entity, 'bcc');
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);
}
}
} else {
// TODO find account by from address
}
}
示例4: storeEntity
protected function storeEntity(Entity $entity)
{
$assignedUserId = $entity->get('assignedUserId');
if ($assignedUserId && $entity->has('usersIds')) {
$usersIds = $entity->get('usersIds');
if (!is_array($usersIds)) {
$usersIds = array();
}
if (!in_array($assignedUserId, $usersIds)) {
$usersIds[] = $assignedUserId;
$entity->set('usersIds', $usersIds);
$hash = $entity->get('usersNames');
if ($hash instanceof \stdClass) {
$hash->assignedUserId = $entity->get('assignedUserName');
$entity->set('usersNames', $hash);
}
}
}
return parent::storeEntity($entity);
}
示例5: loadUserColumnFields
public function loadUserColumnFields(Entity $entity)
{
$pdo = $this->getEntityManager()->getPDO();
$sql = "\n SELECT is_read AS 'isRead', is_important AS 'isImportant' FROM email_user\n WHERE\n deleted = 0 AND\n user_id = " . $pdo->quote($this->getUser()->id) . " AND\n email_id = " . $pdo->quote($entity->id) . "\n ";
$sth = $pdo->prepare($sql);
$sth->execute();
if ($row = $sth->fetch(\PDO::FETCH_ASSOC)) {
$isRead = !empty($row['isRead']) ? true : false;
$isImportant = !empty($row['isImportant']) ? true : false;
$entity->set('isRead', $isRead);
$entity->set('isImportant', $isImportant);
} else {
$entity->set('isRead', null);
$entity->clear('isImportant');
}
}
示例6: loadPhoneNumberField
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));
}
}
示例7: save
public function save(Entity $entity, array $options = array())
{
$nowString = date('Y-m-d H:i:s', time());
$restoreData = array();
if ($entity->isNew()) {
if (!$entity->has('id')) {
$entity->set('id', Util::generateId());
}
if ($entity->hasField('createdAt')) {
$entity->set('createdAt', $nowString);
}
if ($entity->hasField('modifiedAt')) {
$entity->set('modifiedAt', $nowString);
}
if ($entity->hasField('createdById')) {
$entity->set('createdById', $this->entityManager->getUser()->id);
}
if ($entity->has('modifiedById')) {
$restoreData['modifiedById'] = $entity->get('modifiedById');
}
if ($entity->has('modifiedAt')) {
$restoreData['modifiedAt'] = $entity->get('modifiedAt');
}
$entity->clear('modifiedById');
} else {
if (empty($options['silent'])) {
if ($entity->hasField('modifiedAt')) {
$entity->set('modifiedAt', $nowString);
}
if ($entity->hasField('modifiedById')) {
$entity->set('modifiedById', $this->entityManager->getUser()->id);
}
}
if ($entity->has('createdById')) {
$restoreData['createdById'] = $entity->get('createdById');
}
if ($entity->has('createdAt')) {
$restoreData['createdAt'] = $entity->get('createdAt');
}
$entity->clear('createdById');
$entity->clear('createdAt');
}
$this->restoreData = $restoreData;
$result = parent::save($entity, $options);
return $result;
}
示例8: parseValue
protected function parseValue(Entity $entity, $field, $value, $params = array())
{
$decimalMark = '.';
if (!empty($params['decimalMark'])) {
$decimalMark = $params['decimalMark'];
}
$defaultCurrency = 'USD';
if (!empty($params['defaultCurrency'])) {
$defaultCurrency = $params['defaultCurrency'];
}
$dateFormat = 'Y-m-d';
if (!empty($params['dateFormat'])) {
if (!empty($this->dateFormatsMap[$params['dateFormat']])) {
$dateFormat = $this->dateFormatsMap[$params['dateFormat']];
}
}
$timeFormat = 'H:i';
if (!empty($params['timeFormat'])) {
if (!empty($this->timeFormatsMap[$params['timeFormat']])) {
$timeFormat = $this->timeFormatsMap[$params['timeFormat']];
}
}
$fieldDefs = $entity->getFields();
if (!empty($fieldDefs[$field])) {
$type = $fieldDefs[$field]['type'];
switch ($type) {
case Entity::DATE:
$dt = \DateTime::createFromFormat($dateFormat, $value);
if ($dt) {
return $dt->format('Y-m-d');
}
break;
case Entity::DATETIME:
$dt = \DateTime::createFromFormat($dateFormat . ' ' . $timeFormat, $value);
if ($dt) {
return $dt->format('Y-m-d H:i');
}
break;
case Entity::FLOAT:
$currencyField = $field . 'Currency';
if ($entity->hasField($currencyField)) {
if (!$entity->has($currencyField)) {
$entity->set($currencyField, $defaultCurrency);
}
}
$a = explode($decimalMark, $value);
$a[0] = preg_replace('/[^A-Za-z0-9\\-]/', '', $a[0]);
if (count($a) > 1) {
return $a[0] . '.' . $a[1];
} else {
return $a[0];
}
break;
}
}
return $value;
}
示例9: fetchAutoFollowEntityTypeList
protected function fetchAutoFollowEntityTypeList(Entity $entity)
{
$id = $entity->id;
$autoFollowEntityTypeList = [];
$pdo = $this->getEntityManger()->getPDO();
$sql = "\n SELECT `entity_type` AS 'entityType' FROM `autofollow`\n WHERE `user_id` = " . $pdo->quote($id) . "\n ORDER BY `entity_type`\n ";
$sth = $pdo->prepare($sql);
$sth->execute();
$rows = $sth->fetchAll();
foreach ($rows as $row) {
$autoFollowEntityTypeList[] = $row['entityType'];
}
$this->data[$id]['autoFollowEntityTypeList'] = $autoFollowEntityTypeList;
$entity->set('autoFollowEntityTypeList', $autoFollowEntityTypeList);
}
示例10: sendQueueItem
protected function sendQueueItem(Entity $queueItem, Entity $massEmail, Entity $emailTemplate, $attachmetList = [], $campaign = null, $isTest = false)
{
$target = $this->getEntityManager()->getEntity($queueItem->get('targetType'), $queueItem->get('targetId'));
if (!$target || !$target->id || !$target->get('emailAddress')) {
$queueItem->set('status', 'Failed');
$this->getEntityManager()->saveEntity($queueItem);
return;
}
$emailAddress = $target->get('emailAddress');
if (!$emailAddress) {
$queueItem->set('status', 'Failed');
$this->getEntityManager()->saveEntity($queueItem);
return false;
}
$emailAddressRecord = $this->getEntityManager()->getRepository('EmailAddress')->getByAddress($emailAddress);
if ($emailAddressRecord) {
if ($emailAddressRecord->get('invalid') || $emailAddressRecord->get('optOut')) {
$queueItem->set('status', 'Failed');
$this->getEntityManager()->saveEntity($queueItem);
return false;
}
}
$trackingUrlList = [];
if ($campaign) {
$trackingUrlList = $campaign->get('trackingUrls');
}
$email = $this->getPreparedEmail($queueItem, $massEmail, $emailTemplate, $target, $trackingUrlList);
$params = array();
if ($massEmail->get('fromName')) {
$params['fromName'] = $massEmail->get('fromName');
}
if ($massEmail->get('replyToName')) {
$params['replyToName'] = $massEmail->get('replyToName');
}
try {
$attemptCount = $queueItem->get('attemptCount');
$attemptCount++;
$queueItem->set('attemptCount', $attemptCount);
$message = new \Zend\Mail\Message();
$header = new \Espo\Core\Mail\Mail\Header\XQueueItemId();
$header->setId($queueItem->id);
$message->getHeaders()->addHeader($header);
$this->getMailSender()->useGlobal()->send($email, $params, $message, $attachmetList);
$emailObject = $emailTemplate;
if ($massEmail->get('storeSentEmails')) {
$this->getEntityManager()->saveEntity($email);
$emailObject = $email;
}
$queueItem->set('emailAddress', $target->get('emailAddress'));
$queueItem->set('status', 'Sent');
$queueItem->set('sentAt', date('Y-m-d H:i:s'));
$this->getEntityManager()->saveEntity($queueItem);
if ($campaign) {
$this->getCampaignService()->logSent($campaign->id, $queueItem->id, $target, $emailObject, $target->get('emailAddress'));
}
} catch (\Exception $e) {
if ($queueItem->get('attemptCount') >= self::MAX_ATTEMPT_COUNT) {
$queueItem->set('status', 'Failed');
}
$this->getEntityManager()->saveEntity($queueItem);
$GLOBALS['log']->error('MassEmail#sendQueueItem: [' . $e->getCode() . '] ' . $e->getMessage());
return false;
}
return true;
}
示例11: findParent
protected function findParent(Entity $email, $emailAddress)
{
$contact = $this->getEntityManager()->getRepository('Contact')->where(array('emailAddress' => $emailAddress))->findOne();
if ($contact) {
if (!$this->getConfig()->get('b2cMode')) {
if ($contact->get('accountId')) {
$email->set('parentType', 'Account');
$email->set('parentId', $contact->get('accountId'));
return true;
}
} else {
$email->set('parentType', 'Contact');
$email->set('parentId', $contact->id);
return true;
}
} else {
$account = $this->getEntityManager()->getRepository('Account')->where(array('emailAddress' => $emailAddress))->findOne();
if ($account) {
$email->set('parentType', 'Account');
$email->set('parentId', $account->id);
return true;
} else {
$lead = $this->getEntityManager()->getRepository('Lead')->where(array('emailAddress' => $emailAddress))->findOne();
if ($lead) {
$email->set('parentType', 'Lead');
$email->set('parentId', $lead->id);
return true;
}
}
}
}
示例12: save
public function save(Entity $entity)
{
$nowString = date('Y-m-d H:i:s', time());
$restoreData = array();
if ($entity->isNew()) {
if (!$entity->has('id')) {
$entity->set('id', uniqid());
}
if ($entity->hasField('createdAt')) {
$entity->set('createdAt', $nowString);
}
if ($entity->hasField('createdById')) {
$entity->set('createdById', $this->entityManager->getUser()->id);
}
if ($entity->has('modifiedById')) {
$restoreData['modifiedById'] = $entity->get('modifiedById');
}
if ($entity->has('modifiedAt')) {
$restoreData['modifiedAt'] = $entity->get('modifiedAt');
}
$entity->clear('modifiedById');
$entity->clear('modifiedAt');
} else {
if ($entity->hasField('modifiedAt')) {
$entity->set('modifiedAt', $nowString);
}
if ($entity->hasField('modifiedById')) {
$entity->set('modifiedById', $this->entityManager->getUser()->id);
}
if ($entity->has('createdById')) {
$restoreData['createdById'] = $entity->get('createdById');
}
if ($entity->has('createdAt')) {
$restoreData['createdAt'] = $entity->get('createdAt');
}
$entity->clear('createdById');
$entity->clear('createdAt');
}
$result = parent::save($entity);
$entity->set($restoreData);
$this->handleEmailAddressSave($entity);
$this->handlePhoneNumberSave($entity);
$this->handleSpecifiedRelations($entity);
return $result;
}
示例13: loadNameHash
public function loadNameHash(Entity $entity)
{
$addressList = array();
if ($entity->get('from')) {
$addressList[] = $entity->get('from');
}
$arr = explode(';', $entity->get('to'));
foreach ($arr as $address) {
if (!in_array($address, $addressList)) {
$addressList[] = $address;
}
}
$arr = explode(';', $entity->get('cc'));
foreach ($arr as $address) {
if (!in_array($address, $addressList)) {
$addressList[] = $address;
}
}
$nameHash = array();
$typeHash = array();
$idHash = array();
foreach ($addressList as $address) {
$p = $this->getEntityManager()->getRepository('EmailAddress')->getEntityByAddress($address);
if ($p) {
$nameHash[$address] = $p->get('name');
$typeHash[$address] = $p->getEntityName();
$idHash[$address] = $p->id;
}
}
$entity->set('nameHash', $nameHash);
$entity->set('typeHash', $typeHash);
$entity->set('idHash', $idHash);
}
示例14: beforeSave
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'));
}
}
}
}
}
示例15: loadAssignedUserName
protected function loadAssignedUserName(Entity $entity)
{
$user = $this->getEntityManager()->getEntity('User', $entity->get('assignedUserId'));
if ($user) {
$entity->set('assignedUserName', $user->get('name'));
}
}