Example #1
0
 /** @return DibiDataSource */
 public final function getDataSource()
 {
     if ($this->dataSource === NULL) {
         list($sorting, $limit, $offset) = $this->process();
         FindByHelper::dibiProcess($this, $this->getMapper(), $this->getConventional(), $this->where, $this->findBy, $this->tableAlias);
         static $dsClass;
         if ($dsClass === NULL) {
             // @codeCoverageIgnoreStart
             $dsClass = 'DibiDataSource';
             if (class_exists('DibiDataSourceX')) {
                 $dsClass = 'DibiDataSourceX';
             }
         }
         // @codeCoverageIgnoreEnd
         $ds = new $dsClass($this->sql, $this->getConnection());
         foreach ($this->where as $where) {
             $ds->where($where);
         }
         foreach ($sorting as $tmp) {
             list($key, $direction) = $tmp;
             $ds->orderBy($key, $direction);
         }
         if ($limit !== NULL or $offset) {
             $ds->applyLimit($limit, $offset);
         }
         $this->dataSource = $ds;
     }
     return $this->dataSource;
 }
 /**
  * Vola automaticky findBy* a getBy*
  * <code>
  * 	$collection->findByAuthor(3);
  * 	// stejne jako
  * 	$collection->findBy(array('author' => 3));
  *
  * 	$collection->findByAuthorAndCategory(3, 'foo');
  * 	// stejne jako
  * 	$collection->findBy(array('author' => 3, 'category' => 'foo'));
  * </code>
  * @see self::findBy();
  * @see self::getBy();
  * @param string
  * @param array
  * @throws MemberAccessException
  * @return ArrayCollection|IEntity|NULL
  */
 public final function __call($name, $args)
 {
     if (!method_exists($this, $name) and FindByHelper::parse($name, $args)) {
         return $this->{$name}($args);
     }
     return parent::__call($name, $args);
 }
Example #3
0
    /**
     * Returns sql query
     * @return string
     */
    public final function __toString()
    {
        list($sorting, $limit, $offset) = $this->process();
        $orderBy = array();
        end($sorting);
        $end = key($sorting);
        foreach ($sorting as $i => $tmp) {
            list($key, $direction) = $tmp;
            $orderBy[] = '%by' . ($end === $i ? '' : ', ');
            $orderBy[] = array($key => $direction);
        }
        FindByHelper::dibiProcess($this, $this->getMapper(), $this->getConventional(), $this->where, $this->findBy, $this->tableAlias);
        $join = array();
        foreach ($this->join as $tmp) {
            $join = array_merge($join, $tmp);
        }
        return $this->connectionTranslate('
			SELECT [e.*]
			FROM %n', $this->tableName, ' as e
			%ex', $join, '
			%ex', $this->where ? array('WHERE %and', $this->where) : NULL, '
			' . ($join ? 'GROUP BY [e.id]' : '') . '
			%ex', $orderBy ? array('ORDER BY %sql', $orderBy) : NULL, '
			%ofs %lmt', $offset, $limit);
    }