getListingCondition() public method

Get a condition object for item listings.
public getListingCondition ( string $objectKey ) : Condition
$objectKey string
return Jarves\Configuration\Condition
Beispiel #1
0
 /**
  * Generates a row from the propel object using the get*() methods. Resolves *-to-many relations.
  *
  * @param      $clazz
  * @param      $row
  * @param      $selects
  * @param      $relations
  * @param      $relationFields
  * @param bool $permissionCheck
  *
  * @return array
  */
 public function populateRow($clazz, $row, $selects, $relations, $relationFields, $permissionCheck = false)
 {
     $item = new $clazz();
     $item->fromArray($row);
     $newRow = [];
     foreach ($selects as $select) {
         if (strpos($select, '.') === false) {
             $newRow[lcfirst($select)] = $item->{'get' . $select}();
         }
     }
     if (!$relations) {
         return $newRow;
     }
     foreach ($relations as $name => $relation) {
         /** @var $relation \Propel\Runtime\Map\RelationMap */
         if ($relation->getType() != RelationMap::MANY_TO_MANY && $relation->getType() != RelationMap::ONE_TO_MANY) {
             if (isset($relationFields[$name]) && is_array($relationFields[$name])) {
                 $foreignClazz = $relation->getForeignTable()->getClassName();
                 $foreignObj = new $foreignClazz();
                 $foreignRow = array();
                 $allNull = true;
                 foreach ($relationFields[$name] as $col) {
                     if ($row[$name . "." . $col] !== null) {
                         $foreignRow[$col] = $row[$name . "." . $col];
                         $allNull = false;
                     }
                 }
                 if ($allNull) {
                     $newRow[lcfirst($name)] = null;
                 } else {
                     $foreignObj->fromArray($foreignRow);
                     $foreignRow = array();
                     foreach ($relationFields[$name] as $col) {
                         $foreignRow[lcfirst($col)] = $foreignObj->{'get' . $col}();
                     }
                     $newRow[lcfirst($name)] = $foreignRow;
                 }
             }
         } else {
             //many-to-one and many-to-many, we need a extra query
             if (is_array($relationFields[$name]) && ($relationField = $this->getDefinition()->getField($name))) {
                 if (!($relationObjectName = $relationField->getObject())) {
                     $relationObjectName = $this->getDefinition()->getKey();
                     //                            if (!$relationField->getObjectDefinition() || !$relationObjectName = $relationField->getObjectDefinition()->getKey()) {
                     //                                throw new ObjectNotFoundException(sprintf('No object defined for relation `%s`.', $relationField->getId()));
                     //                            }
                 }
                 $sClazz = $relation->getRightTable()->getClassname();
                 $queryName = $sClazz . 'Query';
                 if ($relation->getType() === RelationMap::MANY_TO_MANY) {
                     $filterBy = 'filterBy' . $this->getDefinition()->getId();
                 } else {
                     $filterBy = 'filterBy' . $relation->getSymmetricalRelation()->getName();
                 }
                 $sQuery = $queryName::create()->select($relationFields[$name])->{$filterBy}($item);
                 $condition = null;
                 if ($permissionCheck) {
                     $condition = $this->acl->getListingCondition($relationObjectName);
                 }
                 $sStmt = $this->getStm($sQuery, $condition);
                 $sItems = array();
                 while ($subRow = $sStmt->fetch(\PDO::FETCH_ASSOC)) {
                     $sItem = new $sClazz();
                     $sItem->fromArray($subRow);
                     $temp = array();
                     foreach ($relationFields[$name] as $select) {
                         $temp[lcfirst($select)] = $sItem->{'get' . $select}();
                     }
                     $sItems[] = $temp;
                 }
             } else {
                 $get = 'get' . $relation->getPluralName();
                 $sItems = $item->{$get}();
             }
             if ($sItems instanceof ObjectCollection) {
                 $newRow[lcfirst($name)] = $sItems->toArray(null, null, TableMap::TYPE_CAMELNAME) ?: null;
             } else {
                 if (is_array($sItems) && $sItems) {
                     $newRow[lcfirst($name)] = $sItems;
                 } else {
                     $newRow[lcfirst($name)] = null;
                 }
             }
         }
     }
     return $newRow;
 }
Beispiel #2
0
 /**
  * @param Condition|array $filter
  * @param string $query
  * @return int
  */
 public function getCount($filter, $query = '')
 {
     $storageController = $this->objects->getStorageController($this->getObject());
     $condition = new Condition(null, $this->jarves);
     if ($filter && is_array($filter)) {
         $this->conditionOperator->applyRulesFromPk($condition, $filter, $this->getObject());
     } else {
         if ($filter instanceof Condition) {
             $condition = $filter;
         } else {
             $condition = new Condition(null, $this->jarves);
         }
     }
     if ($limit = $this->getObjectDefinition()->getLimitDataSets()) {
         $condition->mergeAnd($limit);
     }
     if ($this->getPermissionCheck() && ($aclCondition = $this->acl->getListingCondition($this->getObject()))) {
         $condition->mergeAndBegin($aclCondition);
     }
     if ($query) {
         if ($queryCondition = $this->getQueryCondition($query, $this->getItemsSelection())) {
             $condition->mergeAnd($queryCondition);
         }
     }
     return $storageController->getCount($condition);
 }