/**
  * @param UncacherBaseDaoWorker $uncacher
  *
  * @return UncacherBaseDaoWorker
  */
 private function mergeSelf(UncacherBaseDaoWorker $uncacher)
 {
     foreach ($uncacher->getClassNameMap() as $className => $idKeys) {
         if (isset($this->classNameMap[$className])) {
             $this->classNameMap[$className] = ArrayUtils::mergeUnique($this->classNameMap[$className], $idKeys);
         } else {
             $this->classNameMap[$className] = $idKeys;
         }
     }
     return $this;
 }
 private function mergeSelf(UncacherTaggableDaoWorkerTags $uncacher)
 {
     foreach ($uncacher->getClassNameMap() as $className => $tags) {
         if (!isset($this->classNameMap[$className])) {
             $this->classNameMap[$className] = $tags;
         } else {
             //merging idkeys
             $this->classNameMap[$className] = ArrayUtils::mergeUnique($this->classNameMap[$className], $tags);
         }
     }
     return $this;
 }
 private function mergeSelf(UncacherGenericDAO $uncacher)
 {
     foreach ($uncacher->getDaoMap() as $daoClass => $daoMap) {
         if (isset($this->daoMap[$daoClass])) {
             //merge identities
             $this->daoMap[$daoClass][0] = ArrayUtils::mergeUnique($this->daoMap[$daoClass][0], $daoMap[0]);
             //merge workers uncachers
             $this->daoMap[$daoClass][1]->merge($daoMap[1]);
         } else {
             $this->daoMap[$daoClass] = $daoMap;
         }
     }
     return $this;
 }
Example #4
0
 public function importSingle($scope)
 {
     if (!BasePrimitive::import($scope) || is_array($scope[$this->name])) {
         return null;
     }
     if (isset($scope[$this->name]) && is_string($scope[$this->name])) {
         $array = explode('-', $scope[$this->name], 2);
         $range = BaseRange::lazyCreate(ArrayUtils::getArrayVar($array, 0), ArrayUtils::getArrayVar($array, 1));
         if ($range && $this->checkLimits($range)) {
             $this->value = $range;
             return true;
         }
     }
     return false;
 }
 /**
  * @return OneToManyLinkedFull
  **/
 public function sync($insert, $update = array(), $delete)
 {
     $uc = $this->container;
     $dao = $uc->getDao();
     if ($delete) {
         DBPool::getByDao($dao)->queryNull(OSQL::delete()->from($dao->getTable())->where(Expression::eq(new DBField($uc->getParentIdField()), $uc->getParentObject()->getId()))->andWhere(Expression::in($uc->getChildIdField(), ArrayUtils::getIdsArray($delete))));
         $dao->uncacheByIds(ArrayUtils::getIdsArray($delete));
     }
     if ($insert) {
         for ($i = 0, $size = count($insert); $i < $size; ++$i) {
             $dao->add($insert[$i]);
         }
     }
     if ($update) {
         for ($i = 0, $size = count($update); $i < $size; ++$i) {
             $dao->save($update[$i]);
         }
     }
     return $this;
 }
Example #6
0
 public function fetchCollections(array $collections, array $list)
 {
     Assert::isNotEmptyArray($list);
     $ids = ArrayUtils::getIdsArray($list);
     $mainId = DBField::create($this->getIdName(), $this->getTable());
     foreach ($collections as $path => $info) {
         $lazy = $info['lazy'];
         $query = OSQL::select()->get($mainId)->from($this->getTable());
         $proto = reset($list)->proto();
         $this->processPath($proto, $path, $query, $this->getTable());
         if ($criteria = $info['criteria']) {
             $query = $criteria->setDao($this)->fillSelectQuery($query);
         }
         $query->andWhere(Expression::in($mainId, $ids));
         $propertyPath = $info['propertyPath'];
         $property = $propertyPath->getFinalProperty();
         $proto = $propertyPath->getFinalProto();
         $dao = $propertyPath->getFinalDao();
         $selfName = $this->getObjectName();
         $self = new $selfName();
         $getter = 'get' . ucfirst($property->getName());
         Assert::isTrue($property->getRelationId() == MetaRelation::ONE_TO_MANY || $property->getRelationId() == MetaRelation::MANY_TO_MANY);
         $table = $dao->getJoinName($property->getColumnName());
         $id = $this->getIdName();
         $collection = [];
         if ($lazy) {
             if ($property->getRelationId() == MetaRelation::MANY_TO_MANY) {
                 $childId = $self->{$getter}()->getChildIdField();
             } else {
                 $childId = $dao->getIdName();
             }
             $alias = 'cid';
             // childId, collectionId, whatever
             $field = DBField::create($childId, $self->{$getter}()->getHelperTable());
             $query->get($field, $alias);
             if (!$property->isRequired()) {
                 $query->andWhere(Expression::notNull($field));
             }
             try {
                 $rows = $dao->getCustomList($query);
                 foreach ($rows as $row) {
                     if (!empty($row[$alias])) {
                         $collection[$row[$id]][] = $row[$alias];
                     }
                 }
             } catch (ObjectNotFoundException $e) {
                 /*_*/
             }
         } else {
             $prefix = $table . '_';
             foreach ($dao->getFields() as $field) {
                 $query->get(DBField::create($field, $table), $prefix . $field);
             }
             if (!$property->isRequired()) {
                 $query->andWhere(Expression::notNull(DBField::create($dao->getIdName(), $table)));
             }
             try {
                 // otherwise we don't know which object
                 // belongs to which collection
                 $rows = $dao->getCustomList($query);
                 foreach ($rows as $row) {
                     $collection[$row[$id]][] = $dao->makeObject($row, $prefix);
                 }
             } catch (ObjectNotFoundException $e) {
                 /*_*/
             }
         }
         $suffix = ucfirst($property->getName());
         $fillMethod = 'fill' . $suffix;
         $getMethod = 'get' . $suffix;
         Assert::isTrue(method_exists(reset($list), $fillMethod), 'can not find filler');
         Assert::isTrue(method_exists(reset($list), $getMethod), 'can not find getter');
         foreach ($list as $object) {
             if (!empty($collection[$object->getId()])) {
                 $object->{$fillMethod}($collection[$object->getId()], $lazy);
             } else {
                 $object->{$getMethod}()->mergeList([]);
             }
         }
     }
     return $list;
 }
Example #7
0
 public function scopeHref($scope, $absolute = null)
 {
     Assert::isArray($scope);
     // href scope may override navigation scope
     $actualScope = ArrayUtils::mergeRecursiveUnique($this->navigationScope, $scope);
     return $this->cleanHref($actualScope, $absolute);
 }
 public function exportValue()
 {
     if (!$this->value) {
         return null;
     }
     return ArrayUtils::getIdsArray($this->value);
 }
Example #9
0
 public function getListByIds(array $ids, $expires = Cache::EXPIRES_MEDIUM)
 {
     $mapped = $remain = [];
     foreach ($ids as $id) {
         if (isset($this->identityMap[$id])) {
             $mapped[] = $this->identityMap[$id];
         } else {
             $remain[] = $id;
         }
     }
     if ($remain) {
         $list = $this->addObjectListToMap(Cache::worker($this)->getListByIds($remain, $expires));
         $mapped = array_merge($mapped, $list);
     }
     return ArrayUtils::regularizeList($ids, $mapped);
 }