/**
  * @param string $email_verification_token
  * @return Member|null
  */
 public function getByEmailVerificationToken($email_verification_token)
 {
     $member = Member::get()->filter('EmailVerifiedTokenHash', MemberDecorator::HashConfirmationToken($email_verification_token))->first();
     if (!is_null($member)) {
         UnitOfWork::getInstance()->scheduleForUpdate($member);
     }
     return $member;
 }
 /**
  * @param QueryObject $query
  * @param int $offset
  * @param int $limit
  * @return array
  */
 public function getAll(QueryObject $query, $offset = 0, $limit = 10)
 {
     $filter = (string) $query;
     $current_member = Member::currentUser();
     $do = null;
     if ($current_member && !$current_member->isMarketPlaceSuperAdmin()) {
         //if current user is super admin get all
         //if not , get just related companies
         $companies = $current_member->getManagedMarketPlaceCompaniesByType($this->getMarketPlaceTypeGroup());
         if (count($companies)) {
             $company_filter = ' CompanyID IN ( ';
             foreach ($companies as $company) {
                 $company_filter .= $company->getIdentifier() . ',';
             }
             $company_filter = trim($company_filter, ',');
             $company_filter .= ' ) ';
             if (!empty($filter)) {
                 $company_filter = ' AND ' . $company_filter;
             }
             $filter = $filter . $company_filter;
         }
     }
     $inner_joins = $query->getAlias(QueryAlias::INNER);
     $left_joins = $query->getAlias(QueryAlias::LEFT);
     //build query for data object
     $class = $this->entity_class;
     $do = $class::get()->where($filter)->sort($query->getOrder())->limit($limit, $offset);
     foreach ($inner_joins as $table => $on) {
         $do = $do->innerJoin($table, $on);
     }
     foreach ($left_joins as $table => $on) {
         $do = $do->leftJoin($table, $on);
     }
     if (is_null($do)) {
         return array(array(), 0);
     }
     $res = $do->toArray();
     foreach ($res as $entity) {
         UnitOfWork::getInstance()->scheduleForUpdate($entity);
     }
     return array($res, (int) $do->count());
 }
Ejemplo n.º 3
0
 /**
  * @param string $owner
  * @param RelationList $component_set
  * @param QueryObject $query
  * @param string $type
  * @param              $association_name
  */
 public function __construct($owner, RelationList $component_set, QueryObject $query, $type = '1-to-many', $association_name)
 {
     $this->owner = $owner;
     $this->type = $type;
     $this->association_name = $association_name;
     $this->component_set = $component_set;
     foreach ($this->component_set->toArray() as $item) {
         $class_name = get_class($item);
         $id = $item->getIdentifier();
         $item_from_cache = UnitOfWork::getInstance()->getFromCache($class_name, $id);
         if (!is_null($item_from_cache) && count($item_from_cache->toMap()) == count($item->toMap())) {
             $item = $item_from_cache;
         } else {
             UnitOfWork::getInstance()->setToCache($item);
         }
         $this->snapshot[spl_object_hash($item)] = $item;
     }
     foreach ($this->snapshot as $key => $item) {
         $this->items[$key] = $item;
     }
     $this->query = $query;
     UnitOfWork::getInstance()->loadCollection($this);
 }
 /**
  * @param DataObject $entity
  * @param             $association_name
  * @param null $inversed_by
  * @param QueryObject $target_query
  * @return bool|Many2OneAssociation
  * @throws Exception
  */
 public function getMany2OneAssociation(DataObject $entity, $association_name, $inversed_by = null, QueryObject $target_query = null)
 {
     $class_name = $entity->has_one($association_name);
     if (!$class_name) {
         throw new Exception(sprintf("entity %s has not an many-to-one association called %s", get_class($entity), $association_name));
     }
     $old = UnitOfWork::getInstance()->getMany2OneAssociation($entity, $association_name);
     if ($old) {
         return $old;
     }
     return new Many2OneAssociation($entity, $association_name, $inversed_by, $target_query);
 }
 /**
  * @param $entity
  * @throws Exception
  */
 protected function markEntity($entity)
 {
     if (!is_null($entity) && $entity instanceof IEntity) {
         UnitOfWork::getInstance()->setToCache($entity);
         UnitOfWork::getInstance()->scheduleForUpdate($entity);
     }
 }
Ejemplo n.º 6
0
 public function __construct($object)
 {
     $this->object = $object;
     $this->unitOfWork = UnitOfWork::getInstance();
 }
 /**
  * @return DataObject
  */
 public function getTarget()
 {
     $target = $this->target;
     if ($target instanceof IEntity) {
         UnitOfWork::getInstance()->scheduleForUpdate($target);
     }
     return $target;
 }
Ejemplo n.º 8
0
 /**
  * @return ICandidate|null
  */
 public function getCurrentCandidate()
 {
     $res = null;
     $election = ElectionSystem::get()->first();
     if ($election && $election->CurrentElectionID != 0) {
         $current_election = $election->CurrentElection();
         if (!is_null($current_election)) {
             $candidate = Candidate::get()->filter(array('MemberID' => $this->getIdentifier(), 'ElectionID' => $current_election->ID))->first();
             $res = $candidate;
             if (!is_null($candidate)) {
                 UnitOfWork::getInstance()->setToCache($candidate);
                 UnitOfWork::getInstance()->scheduleForUpdate($candidate);
             }
         }
     }
     return $res;
 }
 /**
  * @param Closure $callback
  * @return null
  * @throws EntityValidationException
  * @throws Exception
  */
 public function transaction(Closure $callback)
 {
     $result = null;
     try {
         $this->beginTransaction();
         $r = new ReflectionFunction($callback);
         // reload on UOW entities that could not being on the update context
         foreach ($r->getStaticVariables() as $var) {
             if ($var instanceof IEntity && $var->getIdentifier() > 0) {
                 UnitOfWork::getInstance()->scheduleForUpdate($var);
             }
         }
         $result = $callback($this);
         $this->commit();
     } catch (ValidationException $ex1) {
         $this->rollBack();
         throw new EntityValidationException($ex1->getMessage());
     } catch (Exception $ex) {
         $this->rollBack();
         throw $ex;
     }
     return $result;
 }
Ejemplo n.º 10
0
 public function getBy(QueryObject $query)
 {
     $class = $this->entity_class;
     $query->setBaseEntity(new $class());
     $filter = (string) $query;
     $do = $class::get()->where($filter);
     $joins = $query->getAlias();
     foreach ($joins as $table => $clause) {
         $do = $do->innerJoin($table, $clause);
     }
     if (count($query->getOrder())) {
         $do = $do->sort($query->getOrder());
     }
     if (is_null($do)) {
         return false;
     }
     $entity = $do->first();
     if (!is_null($entity) && $entity instanceof IEntity) {
         UnitOfWork::getInstance()->setToCache($entity);
         UnitOfWork::getInstance()->scheduleForUpdate($entity);
     }
     return $entity;
 }
 /**
  * @return IInteropProgramVersion
  */
 public function getProgramVersion()
 {
     $program_version = $this->ProgramVersion();
     UnitOfWork::getInstance()->scheduleForUpdate($program_version);
     return $program_version;
 }