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

public addAnd ( array | Condition $condition = null )
$condition array | Condition
Пример #1
0
 public function testConditionToSql()
 {
     $condition = new Condition();
     $condition2 = new Condition();
     $condition2->addAnd(['title', '=', 'TestNode tree']);
     $condition->addAnd($condition2);
     $condition->addOr(['1', '=', '1']);
     $params = [];
     $sql = $this->getConditionOperator()->standardConditionToSql($condition, $params, 'jarves/node');
     $expectedArray = [[['title', '=', 'TestNode tree']], 'OR', ['1', '=', '1']];
     $this->assertEquals($expectedArray, $condition->toArray());
     $this->assertEquals([':p1' => 'TestNode tree'], $params);
     $this->assertEquals(' system_node.title = :p1  OR 1= 1', $sql);
 }
Пример #2
0
 /**
  * Propel uses for his nested-set objects `lft` and `rgt` fields.
  * So we include with this condition all entries 'inside' the entry
  * defined through $condition.
  *
  * @param Condition $condition
  * @return Condition
  */
 public function getNestedSubCondition(Condition $condition)
 {
     $result = new Condition(null, $this->jarves);
     $sub = new ConditionSubSelect(null, $this->jarves);
     $sub->select('sub.lft');
     $sub->addSelfJoin('sub', 'sub.lft BETWEEN %table%.lft+1 AND %table%.rgt-1');
     $sub->setRules($condition->getRules());
     $subCondition = new Condition();
     $subCondition->addAnd(['lft', 'IN', $sub]);
     $result->addAnd($subCondition);
     return $result;
 }
Пример #3
0
 /**
  * Get a condition object for item listings.
  *
  * @param  string $objectKey
  *
  * @return 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;
 }