Example #1
0
 /**
  * getListQuery
  *
  * @param Query $query
  *
  * @return  Query
  */
 protected function getListQuery(Query $query)
 {
     $queryHelper = $this->getQueryHelper();
     $queryHelper->addTable('post', 'posts')->addTable('author', 'authors', 'post.author = author.id')->addTable('user', 'users', 'user.id = author.user')->addTable('blog', 'blogs', 'post.blog = blog.id');
     $query->select($queryHelper->getSelectFields())->where($query->format('%n = %q', 'blog.id', $this['blog.id']))->where($query->format('%n = %q', 'type', $this['post.type']));
     $query = $queryHelper->registerQueryTables($query);
     if ($this['list.search']) {
         $search[] = $query->format('%n LIKE %q', 'title', '%' . $this['list.search'] . '%');
         $search[] = $query->format('%n LIKE %q', 'alias', '%' . $this['list.search'] . '%');
         $query->where(new QueryElement('()', $search, ' OR '));
     }
     if ($this['list.ordering']) {
         $query->order($this['list.ordering']);
     }
     return $query;
 }
Example #2
0
 /**
  * Method to test format().
  *
  * @return void
  *
  * @covers Windwalker\Query\Query::format
  */
 public function testFormat()
 {
     $result = $this->instance->format('SELECT %n FROM %n WHERE %n = %a', 'foo', '#__bar', 'id', 10);
     $sql = 'SELECT ' . $this->instance->qn('foo') . ' FROM ' . $this->instance->qn('#__bar') . ' WHERE ' . $this->instance->qn('id') . ' = 10';
     $this->assertEquals($sql, $result);
     $result = $this->instance->format('SELECT %n FROM %n WHERE %n = %t OR %3$n = %Z', 'id', '#__foo', 'date');
     $sql = 'SELECT ' . $this->instance->qn('id') . ' FROM ' . $this->instance->qn('#__foo') . ' WHERE ' . $this->instance->qn('date') . ' = ' . $this->instance->expression('current_timestamp') . ' OR ' . $this->instance->qn('date') . ' = ' . $this->instance->nullDate(true);
     $this->assertEquals($sql, $result);
 }
 /**
  * getListQuery
  *
  * @param Query $query
  *
  * @return  Query
  */
 protected function getListQuery(Query $query)
 {
     $queryHelper = $this->getQueryHelper();
     $queryHelper->addTable('cat', 'categories')->addTable('blog', 'blogs', 'blog.id = cat.blog');
     $query->select($queryHelper->getSelectFields())->where($query->format('%n = %q', 'blog.id', $this['blog.id']));
     $query = $queryHelper->registerQueryTables($query);
     if ($this['list.search']) {
         $search[] = $query->format('%n LIKE %q', 'title', '%' . $this['list.search'] . '%');
         $search[] = $query->format('%n LIKE %q', 'alias', '%' . $this['list.search'] . '%');
         $query->where(new QueryElement('()', $search, ' OR '));
     }
     return $query;
 }
Example #4
0
 /**
  * getListQuery
  *
  * @param Query $query
  *
  * @return  Query
  */
 protected function getListQuery(Query $query)
 {
     $queryHelper = $this->getQueryHelper();
     $queryHelper->addTable('author', 'authors')->addTable('user', 'users', 'user.id = author.user')->addTable('blog', 'blogs', 'blog.id = author.blog');
     $query->select($queryHelper->getSelectFields());
     if ($this['blog.id']) {
         $query->where($query->format('%n = %q', 'blog.id', $this['blog.id']));
     }
     if ($this['find.query']) {
         $q = '%' . $this['find.query'] . '%';
         $conditions[] = $query->format('%n LIKE %q', 'user.username', $q);
         $conditions[] = $query->format('%n LIKE %q', 'user.fullname', $q);
         $conditions[] = $query->format('%n LIKE %q', 'user.email', $q);
         $conditions[] = $query->format('%n LIKE %q', 'author.name', $q);
         $query->where(new QueryElement('()', $conditions, ' OR '));
     }
     $query = $queryHelper->registerQueryTables($query);
     if ($this['list.search']) {
         $search[] = $query->format('%n LIKE %q', 'title', '%' . $this['list.search'] . '%');
         $search[] = $query->format('%n LIKE %q', 'alias', '%' . $this['list.search'] . '%');
         $query->where(new QueryElement('()', $search, ' OR '));
     }
     return $query;
 }
Example #5
0
 /**
  * buildConditions
  *
  * @param Query $query
  * @param array         $conditions
  *
  * @return  Query
  */
 public static function buildWheres(Query $query, array $conditions)
 {
     foreach ($conditions as $key => $value) {
         // NULL
         if ($value === null) {
             $query->where($query->format('%n = NULL', $key));
         } elseif ($value instanceof Compare) {
             $query->where((string) static::buildCompare($key, $value, $query));
         } elseif (is_numeric($key)) {
             $query->where($query->format('%n = %a', $key, $value));
         } elseif (is_array($value) || is_object($value)) {
             $value = array_map(array($query, 'quote'), (array) $value);
             $query->where($query->quoteName($key) . new QueryElement('IN ()', $value, ','));
         } else {
             $query->where($query->format('%n = %q', $key, $value));
         }
     }
     return $query;
 }