本文整理汇总了PHP中Espo\ORM\Entity类的典型用法代码示例。如果您正苦于以下问题:PHP Entity类的具体用法?PHP Entity怎么用?PHP Entity使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Entity类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkIsOwner
public function checkIsOwner(User $user, Entity $entity)
{
if ($user->id === $entity->get('createdById')) {
return true;
}
return false;
}
示例2: sendInvitations
public function sendInvitations(Entity $entity)
{
$invitationManager = $this->getInvitationManager();
$emailHash = array();
$users = $entity->get('users');
foreach ($users as $user) {
if ($user->get('emailAddress') && !array_key_exists($user->get('emailAddress'), $emailHash)) {
$invitationManager->sendInvitation($entity, $user, 'users');
$emailHash[$user->get('emailAddress')] = true;
}
}
$contacts = $entity->get('contacts');
foreach ($contacts as $contact) {
if ($contact->get('emailAddress') && !array_key_exists($contact->get('emailAddress'), $emailHash)) {
$invitationManager->sendInvitation($entity, $contact, 'contacts');
$emailHash[$user->get('emailAddress')] = true;
}
}
$leads = $entity->get('leads');
foreach ($leads as $lead) {
if ($lead->get('emailAddress') && !array_key_exists($lead->get('emailAddress'), $emailHash)) {
$invitationManager->sendInvitation($entity, $lead, 'leads');
$emailHash[$user->get('emailAddress')] = true;
}
}
return true;
}
示例3: getDuplicateWhereClause
protected function getDuplicateWhereClause(Entity $entity)
{
$data = array('OR' => array(array('firstName' => $entity->get('firstName'), 'lastName' => $entity->get('lastName'))));
if ($entity->get('emailAddress')) {
$data['OR'][] = array('emailAddress' => $entity->get('emailAddress'));
}
return $data;
}
示例4: getDataFromEntity
protected function getDataFromEntity(Entity $entity)
{
$data = $entity->toArray();
$fieldDefs = $entity->getFields();
$fieldList = array_keys($fieldDefs);
foreach ($fieldList as $field) {
$type = null;
if (!empty($fieldDefs[$field]['type'])) {
$type = $fieldDefs[$field]['type'];
}
if ($type == Entity::DATETIME) {
if (!empty($data[$field])) {
$data[$field] = $this->dateTime->convertSystemDateTime($data[$field]);
}
} else {
if ($type == Entity::DATE) {
if (!empty($data[$field])) {
$data[$field] = $this->dateTime->convertSystemDate($data[$field]);
}
} else {
if ($type == Entity::JSON_ARRAY) {
if (!empty($data[$field])) {
$list = $data[$field];
$newList = [];
foreach ($list as $item) {
$v = $item;
if ($item instanceof \StdClass) {
$v = get_object_vars($v);
}
foreach ($v as $k => $w) {
$v[$k] = $this->format($v[$k]);
}
$newList[] = $v;
}
$data[$field] = $newList;
}
} else {
if ($type == Entity::JSON_OBJECT) {
if (!empty($data[$field])) {
$value = $data[$field];
if ($value instanceof \StdClass) {
$data[$field] = get_object_vars($value);
}
foreach ($data[$field] as $k => $w) {
$data[$field][$k] = $this->format($data[$field][$k]);
}
}
}
}
}
}
if (array_key_exists($field, $data)) {
$data[$field] = $this->format($data[$field]);
}
}
return $data;
}
示例5: save
public function save(Entity $entity)
{
if ($entity->id) {
$this->data[$entity->id] = $entity->toArray();
$fileName = $this->getFilePath($entity->id);
$this->getFileManager()->putContents($fileName, json_encode($this->data[$entity->id]));
return $entity;
}
}
示例6: 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);
}
}
示例7: handleAfterSaveAccounts
protected function handleAfterSaveAccounts(Entity $entity, array $options)
{
$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;
}
}
if ($titleChanged) {
if (empty($accountId)) {
$accountId = $entity->getFetched('accountId');
if (empty($accountId)) {
return;
}
}
}
if ($accountIdChanged || $titleChanged) {
$pdo = $this->getEntityManager()->getPDO();
$sql = "\n SELECT id, role FROM account_contact\n WHERE\n account_id = " . $pdo->quote($accountId) . " AND\n contact_id = " . $pdo->quote($entity->id) . " AND\n deleted = 0\n ";
$sth = $pdo->prepare($sql);
$sth->execute();
if ($row = $sth->fetch()) {
if ($titleChanged && $entity->get('title') != $row['role']) {
$this->updateRelation($entity, 'accounts', $accountId, array('role' => $entity->get('title')));
}
} else {
if ($accountIdChanged) {
$this->relate($entity, 'accounts', $accountId, array('role' => $entity->get('title')));
}
}
}
}
示例8: afterSave
public function afterSave(Entity $entity)
{
if ($this->getConfig()->get('assignmentEmailNotifications') && in_array($entity->getEntityName(), $this->getConfig()->get('assignmentEmailNotificationsEntityList', array()))) {
$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);
}
}
}
示例9: 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);
}
示例10: save
public function save(Entity $entity, array $options = array())
{
$isNew = $entity->isNew();
$result = parent::save($entity, $options);
if ($isNew) {
if (!empty($entity->id) && $entity->has('contents')) {
$contents = $entity->get('contents');
$this->getFileManager()->putContents('data/upload/' . $entity->id, $contents);
}
}
return $result;
}
示例11: checkIsOwner
public function checkIsOwner(User $user, Entity $entity)
{
if ($user->id === $entity->get('assignedUserId')) {
return true;
}
if ($user->id === $entity->get('createdById')) {
return true;
}
if ($entity->hasLinkMultipleId('assignedUsers', $user->id)) {
return true;
}
return false;
}
示例12: checkInTeam
public function checkInTeam(User $user, Entity $entity)
{
if ($entity->has('campaignId')) {
$campaignId = $entity->get('campaignId');
if (!$campaignId) {
return;
}
$campaign = $this->getEntityManager()->getEntity('Campaign', $campaignId);
if ($campaign && $this->getAclManager()->getImplementation('Campaign')->checkInTeam($user, $campaign)) {
return true;
}
}
return;
}
示例13: afterRemove
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);
}
示例14: checkIsOwner
public function checkIsOwner(User $user, Entity $entity)
{
if ($entity->has('parentId') && $entity->has('parentType')) {
$parentType = $entity->get('parentType');
$parentId = $entity->get('parentId');
if (!$parentType || !$parentId) {
return;
}
$parent = $this->getEntityManager()->getEntity($parentType, $parentId);
if ($parent && $parent->has('assignedUserId') && $parent->get('assignedUserId') === $user->id) {
return true;
}
}
return;
}
示例15: getEntityReminders
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;
}