Pimcore\Model\Listing\AbstractListing::getCondition PHP Method

getCondition() public method

public getCondition ( ) : string
return string
    public function getCondition()
    {
        $conditionString = '';
        $conditionParams = $this->getConditionParams();
        $db = \Pimcore\Db::get();
        if (!empty($conditionParams)) {
            $params = [];
            $i = 0;
            foreach ($conditionParams as $key => $value) {
                if (!$this->condition && $i == 0) {
                    $conditionString .= $key . ' ';
                } else {
                    $conditionString .= ' ' . $value['concatenator'] . ' ' . $key . ' ';
                }
                // If there is not a placeholder, ignore value!
                if (!$value['ignore-value']) {
                    if (is_array($value['value'])) {
                        foreach ($value['value'] as $k => $v) {
                            if ($db->supportsParameters("named")) {
                                $params[$k] = $v;
                            } else {
                                $params[] = $v;
                            }
                        }
                    } else {
                        $params[] = $value['value'];
                    }
                }
                $i++;
            }
            $this->setConditionVariables($params);
        }
        $condition = $this->condition . $conditionString;
        return $condition;
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Returns the SQL condition value.
  *
  * @return string
  */
 public function getCondition()
 {
     $condition = parent::getCondition();
     if ($condition) {
         if (Document::doHideUnpublished() && !$this->getUnpublished()) {
             $condition = " (" . $condition . ") AND published = 1";
         }
     } elseif (Document::doHideUnpublished() && !$this->getUnpublished()) {
         $condition = "published = 1";
     }
     return $condition;
 }