Beispiel #1
0
 /**
  * Gets the menu for the given id.
  *
  * @param int $menuId
  *
  * @return \Ilch\Layout\Helper\Menu\Model
  */
 public function getMenu($menuId)
 {
     $menu = new \Ilch\Layout\Helper\Menu\Model($this->layout);
     $menuRow = $this->db->select(array('id', 'title'))->from('menu')->where(array('id' => $menuId))->execute()->fetchAssoc();
     $menu->setId($menuRow['id']);
     $menu->setTitle($menuRow['title']);
     return $menu;
 }
Beispiel #2
0
 /**
  * Loads the config from the database.
  */
 public function loadConfigFromDatabase()
 {
     $configs = $this->db->select(array('key', 'value'))->from('config')->where(array('autoload' => 1))->execute()->fetchRows();
     foreach ($configs as $config) {
         $this->configData[$config['key']]['value'] = $config['value'];
         $this->configData[$config['key']]['autoload'] = 1;
     }
 }
 /**
  * Create Expression for Comparison
  *
  * @param string|integer $key
  * @param mixed $value
  * @return Expression\Comparison
  * @throws \InvalidArgumentException
  */
 protected function createComparisonExpression($key, $value)
 {
     $singleComparisonOperators = ['=', '<=', '=>', '<', '>', '!=', '<>'];
     // expect comparison of 2 fields -> don't escape (f.e. join conditions)
     if (is_int($key)) {
         $conditionParts = explode(' ', $value);
         if (count($conditionParts) != 3 || !in_array($conditionParts[1], $singleComparisonOperators)) {
             throw new \InvalidArgumentException('Invalid comparison expression');
         }
         $left = $this->db->quote($conditionParts[0]);
         $operator = $conditionParts[1];
         $right = $this->db->quote($conditionParts[2]);
     } else {
         // string key -> comparison with value(s)
         $keyParts = explode(' ', $key);
         $left = $this->db->quote(array_shift($keyParts));
         if (!empty($keyParts)) {
             $operator = implode(' ', $keyParts);
         } else {
             $operator = '=';
         }
         if (is_array($value)) {
             if ($operator === '=') {
                 $operator = 'IN';
             } elseif (in_array($operator, ['!=', '<>'])) {
                 $operator = 'NOT IN';
             }
             if (!in_array($operator, ['IN', 'NOT IN'])) {
                 throw new \InvalidArgumentException('invalid operator for multiple value comparison');
             }
             $right = '(' . implode(', ', $this->db->escapeArray($value, true)) . ')';
         } else {
             if (!in_array($operator, $singleComparisonOperators)) {
                 throw new \InvalidArgumentException('invalid operator for single value comparison');
             }
             $right = $this->db->escape($value, true);
         }
     }
     return new Expression\Comparison($left, $operator, $right);
 }
Beispiel #4
0
 /**
  * Für eine Select Query, die mit useFoundRows aufgerufen wurde, kann so die FOUND_ROWS() aufgerufen werden
  * @return integer
  */
 public function getFoundRows()
 {
     return (int) $this->db->queryCell('SELECT FOUND_ROWS()');
 }