Jarves\ACL::getListingCondition PHP Метод

getListingCondition() публичный Метод

Get a condition object for item listings.
public getListingCondition ( string $objectKey ) : Condition
$objectKey string
Результат Jarves\Configuration\Condition
    public function getListingCondition($objectKey)
    {
        $objectKey = Objects::normalizeObjectKey($objectKey);
        $obj = $this->objects->getStorageController($objectKey);
        $rules = self::getRules($objectKey, static::MODE_LISTING);
        if (count($rules) === 0) {
            return null;
        }
        if ($this->getCaching()) {
            $cacheKey = md5($objectKey);
            $cached = $this->cacher->getDistributedCache('core/acl/listing/' . $cacheKey);
            if (null !== $cached) {
                return $cached;
            }
        }
        $condition = '';
        $primaryList = $this->objects->getPrimaryList($objectKey);
        $primaryKey = current($primaryList);
        $denyList = array();
        $conditionObject = new Condition(null, $this->jarves);
        foreach ($rules as $rule) {
            if ($rule['constraint_type'] === ACL::CONSTRAINT_EXACT) {
                //todo $rule['constraint_code'] can be a (urlencoded) composite pk
                //todo constraint_code is always urlencoded;
                $condition = Condition::create(array($primaryKey, '=', Tools::urlDecode($rule['constraint_code'])), $this->jarves);
            }
            if ($rule['constraint_type'] === ACL::CONSTRAINT_CONDITION) {
                $condition = Condition::create($rule['constraint_code'], $this->jarves);
            }
            if ($rule['constraint_type'] === ACL::CONSTRAINT_ALL) {
                $condition = array('1', '=', '1');
            } elseif ($rule['sub']) {
                $subCondition = $obj->getNestedSubCondition($condition);
                if ($subCondition) {
                    $condition = array($condition, 'OR', $subCondition);
                }
            }
            if ($rule['access'] === 1) {
                if ($denyList) {
                    $condition = array($condition, 'AND NOT', $denyList);
                    $conditionObject->addOr($condition);
                    //                    $conditionObject->add('AND NOT', $denyList);
                } else {
                    $conditionObject->addOr($condition);
                }
            }
            if ($rule['access'] !== 1) {
                if ($denyList) {
                    $denyList[] = 'AND NOT';
                }
                $denyList[] = $condition;
            }
        }
        if (!$conditionObject->hasRules()) {
            $conditionObject->addAnd(array('1', '!=', '1'));
        }
        if ($this->getCaching()) {
            $cacheKey = md5($objectKey);
            $this->cacher->setDistributedCache('core/acl/listing/' . $cacheKey, $conditionObject);
        }
        return $conditionObject;
    }

Usage Example

Пример #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;
 }
All Usage Examples Of Jarves\ACL::getListingCondition