Builds a SQL statement from the given criteria object and resets the Criteria

@param Criteria $criteria
@return string fully formed SQL statement
10601
public function GetSQL($criteria)
	{
		// start building the sql statement
		$sql = "select " . $this->GetColumnNames() . "";

		$sql .= $this->GetTableJoinSQL($criteria);		

		$sql .= $criteria->GetJoin();
				
		$sql .= $this->GetWhereSQL($criteria);
		
		$sql .= $criteria->GetOrder();
		
		$criteria->Reset();
		
		return $sql;
	}
697668
public function getDatabaseSeriesData(Criteria $criteria)
    {
        $dbData = [];

        $res = $this->database->query("SELECT {$criteria->getValueField()} AS value,
calendar.week AS week,
calendar.month AS month,
calendar.year AS year,
{$this->getSeries($criteria->getSeries())}
{$criteria->getTableName()}.id
FROM {$criteria->getTableName()}
INNER JOIN calendar ON date({$criteria->getTableName()}.{$criteria->getTimeField()}) = calendar.date
    AND calendar.date >= '{$criteria->getStartDate()}'
	AND calendar.date <= '{$criteria->getEndDate()}'
    {$criteria->getJoin()}
WHERE
    {$criteria->getTableName()}.{$criteria->getTimeField()} >= '{$criteria->getStartDate()}' 
AND {$criteria->getTableName()}.{$criteria->getTimeField()} <= '{$criteria->getEndDate()}'
	{$criteria->getWhere()}
GROUP BY calendar.year,calendar.month,calendar.week" . $this->getGroupBy($criteria->getGroupBy()) . '
		');

        foreach ($res as $row) {
            $value = 0;
            if ($row->id != null) {
                $value = $row['value'];
            }
            $date = new \DateTime();
            $date->setISODate($row->year, $row->week);
            if (isset($row->name)) {
                $dbData[$row->name][$date->format('Y-m-d')] = $value;
            } else {
                $dbData[' '][$date->format('Y-m-d')] = $value;
            }
        }
        return $dbData;
    }
514576
public function prepareCriteria($criteria)
    {
        if (is_null($criteria)) {
            $criteria = array();
        }

        if (array_key_exists('$id', $criteria)) {
            $criteria['id'] = $criteria['$id'];
            unset($criteria['$id']);
        }

        return $criteria ? : array();
    }
390202
public function buildCriteria()
    {
        $criteria = new Criteria(DealerI18nTableMap::DATABASE_NAME);

        if ($this->isColumnModified(DealerI18nTableMap::ID)) $criteria->add(DealerI18nTableMap::ID, $this->id);
        if ($this->isColumnModified(DealerI18nTableMap::LOCALE)) $criteria->add(DealerI18nTableMap::LOCALE, $this->locale);
        if ($this->isColumnModified(DealerI18nTableMap::TITLE)) $criteria->add(DealerI18nTableMap::TITLE, $this->title);
        if ($this->isColumnModified(DealerI18nTableMap::DESCRIPTION)) $criteria->add(DealerI18nTableMap::DESCRIPTION, $this->description);
        if ($this->isColumnModified(DealerI18nTableMap::ACCESS)) $criteria->add(DealerI18nTableMap::ACCESS, $this->access);

        return $criteria;
    }
68062
public function query(Criteria $criteria=null, $alias=null)
    {
        $query = new Query($this->_connection);

        if($alias) {
            $query->from('`'.$this->_tableName."` AS `".$alias."`");
        } else {
            $query->from('`'.$this->_tableName.'`');
        }

        // add optional where clause
        if($criteria) $query->where($criteria->toSql());

        return $query;
    }
777686
public function buildCriteria()
    {
        $criteria = new Criteria(UserPeer::DATABASE_NAME);

        if ($this->isColumnModified(UserPeer::ID)) $criteria->add(UserPeer::ID, $this->id);
        if ($this->isColumnModified(UserPeer::USERNAME)) $criteria->add(UserPeer::USERNAME, $this->username);
        if ($this->isColumnModified(UserPeer::PASSWORD)) $criteria->add(UserPeer::PASSWORD, $this->password);
        if ($this->isColumnModified(UserPeer::SALT)) $criteria->add(UserPeer::SALT, $this->salt);
        if ($this->isColumnModified(UserPeer::FIRSTNAME)) $criteria->add(UserPeer::FIRSTNAME, $this->firstname);
        if ($this->isColumnModified(UserPeer::LASTNAME)) $criteria->add(UserPeer::LASTNAME, $this->lastname);
        if ($this->isColumnModified(UserPeer::EMAIL)) $criteria->add(UserPeer::EMAIL, $this->email);
        if ($this->isColumnModified(UserPeer::PHONE)) $criteria->add(UserPeer::PHONE, $this->phone);
        if ($this->isColumnModified(UserPeer::MEMO)) $criteria->add(UserPeer::MEMO, $this->memo);
        if ($this->isColumnModified(UserPeer::ACTIVATED)) $criteria->add(UserPeer::ACTIVATED, $this->activated);
        if ($this->isColumnModified(UserPeer::LAST_LOGIN)) $criteria->add(UserPeer::LAST_LOGIN, $this->last_login);
        if ($this->isColumnModified(UserPeer::NOTIFICATION_CHANGE)) $criteria->add(UserPeer::NOTIFICATION_CHANGE, $this->notification_change);
        if ($this->isColumnModified(UserPeer::NOTIFICATION_ERROR)) $criteria->add(UserPeer::NOTIFICATION_ERROR, $this->notification_error);

        return $criteria;
    }
859591
public function buildCriteria()
    {
        $criteria = new Criteria(UserRolePeer::DATABASE_NAME);

        if ($this->isColumnModified(UserRolePeer::USER_ID)) $criteria->add(UserRolePeer::USER_ID, $this->user_id);
        if ($this->isColumnModified(UserRolePeer::ROLE_ID)) $criteria->add(UserRolePeer::ROLE_ID, $this->role_id);

        return $criteria;
    }
1116665
public function findOneOrNullBy(array $criteria)
    {

        $query = $this->createQueryBuilder($criteria);

        $object = $this->getOneOrNullResultFromQueryBuilder($query);

        return $object;
    }
894972
public function matching(Criteria $criteria)
    {
        if ($this->isDirty) {
            $this->initialize();
        }

        if ($this->initialized) {
            return $this->collection->matching($criteria);
        }

        if ($this->association instanceof ManyToManyAssociationMetadata) {
            $persister = $this->em->getUnitOfWork()->getCollectionPersister($this->association);

            return new ArrayCollection($persister->loadCriteria($this, $criteria));
        }

        $builder         = Criteria::expr();
        $ownerExpression = $builder->eq($this->backRefFieldName, $this->owner);
        $expression      = $criteria->getWhereExpression();
        $expression      = $expression ? $builder->andX($expression, $ownerExpression) : $ownerExpression;

        $criteria = clone $criteria;
        $criteria->where($expression);

        $persister = $this->em->getUnitOfWork()->getEntityPersister($this->association->getTargetEntity());

        return $this->association->getFetchMode() === FetchMode::EXTRA_LAZY
            ? new LazyCriteriaCollection($persister, $criteria)
            : new ArrayCollection($persister->loadCriteria($criteria));
    }
942320
public function buildCriteria()
    {
        $criteria = new Criteria(DealerContactI18nTableMap::DATABASE_NAME);

        if ($this->isColumnModified(DealerContactI18nTableMap::ID)) $criteria->add(DealerContactI18nTableMap::ID, $this->id);
        if ($this->isColumnModified(DealerContactI18nTableMap::LOCALE)) $criteria->add(DealerContactI18nTableMap::LOCALE, $this->locale);
        if ($this->isColumnModified(DealerContactI18nTableMap::LABEL)) $criteria->add(DealerContactI18nTableMap::LABEL, $this->label);

        return $criteria;
    }
711008
public function buildCriteria()
    {
        $criteria = new Criteria(UserTableMap::DATABASE_NAME);

        if ($this->isColumnModified(UserTableMap::COL_ID)) {
            $criteria->add(UserTableMap::COL_ID, $this->id);
        }
        if ($this->isColumnModified(UserTableMap::COL_USERNAME)) {
            $criteria->add(UserTableMap::COL_USERNAME, $this->username);
        }
        if ($this->isColumnModified(UserTableMap::COL_PASSWORD)) {
            $criteria->add(UserTableMap::COL_PASSWORD, $this->password);
        }
        if ($this->isColumnModified(UserTableMap::COL_FIRST_NAME)) {
            $criteria->add(UserTableMap::COL_FIRST_NAME, $this->first_name);
        }
        if ($this->isColumnModified(UserTableMap::COL_LAST_NAME)) {
            $criteria->add(UserTableMap::COL_LAST_NAME, $this->last_name);
        }
        if ($this->isColumnModified(UserTableMap::COL_CREATE_DATE)) {
            $criteria->add(UserTableMap::COL_CREATE_DATE, $this->create_date);
        }
        if ($this->isColumnModified(UserTableMap::COL_UPDATE_DATE)) {
            $criteria->add(UserTableMap::COL_UPDATE_DATE, $this->update_date);
        }
        if ($this->isColumnModified(UserTableMap::COL_STATUS)) {
            $criteria->add(UserTableMap::COL_STATUS, $this->status);
        }

        return $criteria;
    }
356473
public function query($criteria=null)
    {
        $query = new \Pheasant\Query\Query($this->_connection);
        $query->from($this->_name);

        if(!is_null($criteria))
            $query->where($criteria);

        return $query;
    }
1282964
public function getPlainSelectedColumns(Criteria $criteria)
    {
        $selected = [];
        foreach ($criteria->getSelectColumns() as $columnName) {
            if (false === strpos($columnName, '(')) {
                $selected[] = $columnName;
            }
        }

        foreach ($criteria->getAsColumns() as $alias => $col) {
            if (false === strpos($col, '(') && !in_array($col, $selected)) {
                $selected[] = $col;
            }
        }

        return $selected;
    }
414114
private static function getPrimaryKey(Criteria $criteria)
    {
        // Assume all the keys are for the same table.
        $keys = $criteria->keys();
        $key = $keys[0];
        $table = $criteria->getTableName($key);

        $pk = null;

        if (!empty($table)) {

            $dbMap = Propel::getDatabaseMap($criteria->getDbName());

            $pks = $dbMap->getTable($table)->getPrimaryKeys();
            if (!empty($pks)) {
                $pk = array_shift($pks);
            }
        }

        return $pk;
    }
705717
private function createCriteriaQueryBuilder(Criteria $criteria, $prefix)
    {
        $qb = $this->createQueryBuilder($prefix);

        if ($criteria->count()) {
            $composite = $this->applyCriteriaToQueryBuilder($criteria, $qb, $prefix);

            if ($composite->count()) {
                $qb->where($composite);
            }
        }

        return $qb;
    }
812814
public function buildCriteria()
    {
        $criteria = new Criteria(LoginLogTableMap::DATABASE_NAME);

        if ($this->isColumnModified(LoginLogTableMap::COL_ID)) {
            $criteria->add(LoginLogTableMap::COL_ID, $this->id);
        }
        if ($this->isColumnModified(LoginLogTableMap::COL_TYPE)) {
            $criteria->add(LoginLogTableMap::COL_TYPE, $this->type);
        }
        if ($this->isColumnModified(LoginLogTableMap::COL_DATE_TIME)) {
            $criteria->add(LoginLogTableMap::COL_DATE_TIME, $this->date_time);
        }
        if ($this->isColumnModified(LoginLogTableMap::COL_USER_ID)) {
            $criteria->add(LoginLogTableMap::COL_USER_ID, $this->user_id);
        }
        if ($this->isColumnModified(LoginLogTableMap::COL_USERNAME)) {
            $criteria->add(LoginLogTableMap::COL_USERNAME, $this->username);
        }
        if ($this->isColumnModified(LoginLogTableMap::COL_SESSION_ID)) {
            $criteria->add(LoginLogTableMap::COL_SESSION_ID, $this->session_id);
        }
        if ($this->isColumnModified(LoginLogTableMap::COL_CLIENT_ADDRESS)) {
            $criteria->add(LoginLogTableMap::COL_CLIENT_ADDRESS, $this->client_address);
        }
        if ($this->isColumnModified(LoginLogTableMap::COL_CLIENT_IP)) {
            $criteria->add(LoginLogTableMap::COL_CLIENT_IP, $this->client_ip);
        }
        if ($this->isColumnModified(LoginLogTableMap::COL_CLIENT_AGENT)) {
            $criteria->add(LoginLogTableMap::COL_CLIENT_AGENT, $this->client_agent);
        }
        if ($this->isColumnModified(LoginLogTableMap::COL_CLIENT_PLATFORM)) {
            $criteria->add(LoginLogTableMap::COL_CLIENT_PLATFORM, $this->client_platform);
        }

        return $criteria;
    }
567339
protected function normalizeCriteria($criteria) {
		if ($criteria === null) {
			return;
		}
		
		if ($criteria instanceof Criteria) {
			return $criteria->getInnerCriteria()->getParams();
		}
		
		if ($criteria instanceof PhalconCriteria) {
			return $criteria->getParams();
		}
		
		if (is_array($criteria) || is_string($criteria) || is_int($criteria)) {
			return $criteria;
		}
		
		throw new InvalidCriteria('Invalid type of the criteria: "' . gettype($criteria) . '"');
	}