作者:dispossesse
项目:espocr
public function checkIsOwner(User $user, Entity $entity)
{
if ($user->id === $entity->get('createdById')) {
return true;
}
return false;
}
作者:mehulsbhat
项目:espocr
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;
}
作者:sanduhr
项目:espocr
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;
}
作者:naushramb
项目:espocr
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;
}
作者:jdavis59
项目:appitechtur
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;
}
}
作者:mehulsbhat
项目:espocr
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);
}
}
作者:naushramb
项目:espocr
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')));
}
}
}
}
作者:lucasmatto
项目:cr
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);
}
}
}
作者:houzhenggan
项目:espocr
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);
}
作者:houzhenggan
项目:espocr
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;
}
作者:diseart
项目:espocr
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;
}
作者:naushramb
项目:espocr
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;
}
作者:naushramb
项目:espocr
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);
}
作者:naushramb
项目:espocr
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;
}
作者:naushramb
项目:espocr
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;
}
作者:naushramb
项目:espocr
public function sendInvitations(Entity $entity)
{
$invitationManager = $this->getInvitationManager();
$users = $entity->get('users');
foreach ($users as $user) {
$invitationManager->sendInvitation($entity, $user, 'users');
}
$contacts = $entity->get('contacts');
foreach ($contacts as $contact) {
$invitationManager->sendInvitation($entity, $contact, 'contacts');
}
$leads = $entity->get('leads');
foreach ($leads as $lead) {
$invitationManager->sendInvitation($entity, $lead, 'leads');
}
return true;
}
作者:naushramb
项目:espocr
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);
}
}
}
作者:houzhenggan
项目:espocr
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);
}
作者:jdavis59
项目:appitechtur
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
}
}
作者:lucasmatto
项目:cr
protected function beforeSave(Entity $entity)
{
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();
}
}
}
}