构建SELECT语句
@return string
511070
public function buildSelectSQL()
	{
		$where = $this->parseCondition(isset($this->operationOption['where']) ? $this->operationOption['where'] : '');
		if ('' !== $where)
		{
			$where = 'where ' . $where . ' ';
		}
		return 'select ' . $this->parseDistinct()
				. $this->parseFieldBefore()
				. $this->parseField(null,'*')
				. 'from '
				. $this->parseTable() . ' '
				. $this->parseJoin()
				. $where
				. $this->parseGroup()
				. $this->parseHaving()
				. $this->parseOrder()
				. $this->parseLimit()
				. $this->parseLock()
				;
	}
1003297
public function index()
    {
        return Admin::content(function (Content $content) {
            $content->header(trans('admin.menu'));
            $content->description(trans('admin.list'));

            $content->row(function (Row $row) {
                $row->column(6, $this->treeView()->render());

                $row->column(6, function (Column $column) {
                    $form = new \Encore\Admin\Widgets\Form();
                    $form->action(admin_base_path('auth/menu'));

                    $form->select('parent_id', trans('admin.parent_id'))->options(Menu::selectOptions());
                    $form->text('title', trans('admin.title'))->rules('required');
                    $form->icon('icon', trans('admin.icon'))->default('fa-bars')->rules('required')->help($this->iconHelp());
                    $form->text('uri', trans('admin.uri'));
                    $form->multipleSelect('roles', trans('admin.roles'))->options(Role::all()->pluck('name', 'id'));
                    $form->radio('blank', '加载方式')->options(['0' => 'pjax', '1'=>'no-pjax' ])->default('0');
                    $form->hidden('_token')->default(csrf_token());

                    $column->append((new Box(trans('admin.new'), $form))->style('success'));
                });
            });
        });
    }
1080503
public function getSelectSql()
    {
        $sql = "SELECT ";

        $sql .= $this->implodeSqlClauses($this->columns, ", ").
            " FROM `".$this->schemaName."` AS `".$this->getAlias()."`";

        foreach($this->joins as $join){
            $joinsSql = $join->getSql($this);
            if (strpos($joinsSql," ") !== false){
                $joinsSql = "(".$joinsSql.")";
            }

            $sql .= " ".$join->joinType." ".$joinsSql." AS `".$join->statement->getAlias()."` ON `".$this->getAlias()."`.`".
                $join->parentColumn."` = `".$join->statement->getAlias()."`.`".$join->childColumn."`";
        }

        if ($this->whereExpression) {
            $havingSql = $this->whereExpression->getWhereSql($this);
            if ($havingSql != "" ){
                $sql .= " WHERE ".$havingSql;
            }
        }
        
        if (count($this->groups)){
            $sql .= " GROUP BY ".$this->implodeSqlClauses($this->groups, ", ");
        }

        if ($this->whereExpression) {
            $havingSql = $this->whereExpression->getHavingSql($this);
            if ($havingSql != "" ){
                $sql .= " HAVING ".$havingSql;
            }
        }

        if (count($this->sorts)){
            $sql .= " ORDER BY ".$this->implodeSqlClauses($this->sorts, ", ");
        }

        if ($this->hasLimit()){
            $sql .= " LIMIT ".$this->limitStart.", ".$this->limitCount;
        }

        return $sql;
    }
6371
public function getValue()
    {
        $selected = [];

        // walk all options
        foreach ($this->options as $option) {
            if ($option instanceof Option) {
                if ($option->isSelected()) {
                    $selected[] = $option->getValue();
                }
            } else {
                if ($option instanceof Optgroup) {
                    $options = $option->getOptions();
                    foreach ($options as $option2) {
                        if ($option2->isSelected()) {
                            $selected[] = $option2->getValue();
                        }
                    }
                }
            }
        }

        $count = sizeof($selected);
        if ($count > 0) {
            if ($this->isMultiple()) {
                return $selected;
            } else {
                // return last selected item as value
                return $selected[$count - 1];
            }
        }

        return $this->isMultiple() ? [] : "";
    }
506220
protected function checkSelect(){
        return $this->select = is_array($this->select) ? $this->select :  [$this->select];
    }
570569
public function selectAll() {
        // Build Select Command
        $sql_query = 'SELECT ' . $this->_distinct .
                     '* FROM ' . $this->_table;

        if (count($this->_joins)) {
            $sql_query .= implode($this->_joins, ' ');
        }
        
        // Where statements
        if (count($this->_where)) {
            $sql_query .= ' WHERE ';
            $sql_query .= implode($this->_where, ' AND ');
            
            // or statements
            if (count($this->_or)) {
                $sql_query .= ' OR ';
                $sql_query .= implode($this->_or, ' AND ');
            }
        }
        
        // Alias
        if ($this->_alias) {
            $sql_query .= ' AS ' . $this->_alias;
        }
        
        // Union
        if (count($this->_union)) {
            $sql_query .= ' UNION ' . implode($this->_union, ' UNION ');
        }
        
        // Union All
        if (count($this->_union_all)) {
            $sql_query .= ' UNION ALL ' . implode($this->_union_all, ' UNION ALL ');
        }
        
        // Group By
        if (strlen($this->_group_by)) {
            $sql_query .= $this->_group_by;
        }
        
        // Order By
        if (strlen($this->_order)) {
            $sql_query .= $this->_order;
        }
        
        // Limit
        if (strlen($this->_limit)) {
            $sql_query .= $this->_limit;
        }
        
        // Set the query
        $this->_sql_query = $sql_query;
        
        return $this;
    }
795486
protected function buildSELECT()
    {
        return 'SELECT'
        . $this->buildFlags()
        . $this->buildCols()
        . $this->buildFrom()
        . $this->buildWhere()
        . $this->buildGroupBy()
        . $this->buildHaving()
        . $this->buildOrderBy()
        . $this->buildLimit()
        . $this->buildForUpdate();
    }
1153301
public function getSelect()
    {
        $ret = parent::getSelect();
        $categoryDirectory = $this->getItemDirectory()->getComponent();

        $refData = Kwc_Directories_Category_Detail_List_Component::getTableReferenceData(
            Kwc_Abstract::getSetting(get_class($categoryDirectory), 'categoryToItemModelName'),
            'Category'
        );

        $ret->join($refData['tableName'],
            "{$refData['refTableName']}.{$refData['refItemColumn']} = "
                ."{$refData['tableName']}.{$refData['itemColumn']}", array()
        );

        $refDataItem = Kwc_Directories_Category_Detail_List_Component::getTableReferenceData(
            Kwc_Abstract::getSetting(get_class($categoryDirectory), 'categoryToItemModelName'),
            'Item'
        );

        $ret->where(
            $refDataItem['tableName'].'.'.$refDataItem['itemColumn'].' = ?',
            $this->_getItemDetail()->row->id
        );

        return $ret;
    }
1037663
protected function translateSelect()
    {
        // normal or distinct selection?
        $build = ($this->attr('distinct') ? 'select distinct' : 'select') . ' ';

        // build the selected fields 
        $fields = $this->attr('fields');

        if (!empty($fields)) 
        {
            foreach ($fields as $key => $field) 
            {
                list($column, $alias) = $field;

                if (!is_null($alias)) 
                {
                    $build .= $this->escape($column) . ' as ' . $this->escape($alias);
                }
                else 
                {
                    $build .= $this->escape($column);
                }

                $build .= ', ';
            }

            $build = substr($build, 0, -2);
        } 
        else 
        {
            $build .= '*';
        }

        // append the table
        $build .= ' from ' . $this->escapeTable();

        // build the join statements
        if ($this->attr('joins'))
        {
            $build .= $this->translateJoins();
        }

        // build the where statements
        if ($wheres = $this->attr('wheres'))
        {
            $build .= $this->translateWhere($wheres);
        }

        // build the groups
        if ($this->attr('groups'))
        {
            $build .= $this->translateGroupBy();
        }

        // build the order statement
        if ($this->attr('orders'))
        {
            $build .= $this->translateOrderBy();
        }
    
        // build offset and limit
        if ($this->attr('limit') || $this->attr('offset'))
        {
            $build .= $this->translateLimitWithOffset();
        }

        return $build;
    }
73729
public function getOption()
	{
		$option = $this->operationOption;
		// 清空连贯配置
		$this->operationOption = array ();
		if (! isset($option['table']))
		{
			// 未设置表明则为模型表名
			$option['table'] = $this->tableName();
		}
		$this->isSelectBefore = true;
		return $option;
	}
831857
public function select()
    {
        $fields = !empty($this->fields) ? $this->fields : ["*"];
        if (empty($this->fields)) {
            $fields = isset($this->infosMergeds['fields']) ?
                implode(", ", $this->infosMergeds['fields']) :
                "*";
        }

        $this->sql = new PhiberQueryWriter("select", [
            "table" => $this->table,
            "fields" => $fields,
            "where" => isset($this->infosMergeds['where']) ?
                $this->infosMergeds['where'] :
                null,
            "limit" => isset($this->infosMergeds['limit']) ?
                $this->infosMergeds['limit'] :
                null,
            "offset" => isset($this->infosMergeds['offset']) ?
                $this->infosMergeds['offset'] :
                null,
            "orderby" => isset($this->infosMergeds['orderby']) ?
                $this->infosMergeds['orderby'] :
                null,
            "join" => isset($this->joins) ?
                $this->joins :
                null
        ]);

        $result = [];
        if ($this->phiberConfig->verifyExecuteQueries()) {
            $this->PDO = $this->PDO->prepare($this->sql);
            if (isset($this->infosMergeds['fields_and_values'])) {

                while (current($this->infosMergeds['fields_and_values'])) {
                    $this->PDO->bindValue(
                        "condition_" . key($this->infosMergeds['fields_and_values']),
                        $this->infosMergeds['fields_and_values'][key($this->infosMergeds['fields_and_values'])]);
                    next($this->infosMergeds['fields_and_values']);
                }
            }
            $this->PDO->execute();

            $result = $this->PDO->fetchAll((PDO::FETCH_ASSOC));

            $this->rowCount = $this->PDO->rowCount();
        }

        return $result;
    }
636501
public function getSelect()
    {
        $select = $this->db->select();

        $fields['answered'] = new \Zend_Db_Expr("SUM(
            CASE
            WHEN grc_success = 1 AND gto_completion_time IS NOT NULL
            THEN 1 ELSE 0 END
            )");
        $fields['missed']   = new \Zend_Db_Expr('SUM(
            CASE
            WHEN grc_success = 1 AND
                 gto_completion_time IS NULL AND
                 gto_valid_until < CURRENT_TIMESTAMP AND
                 (gto_valid_from IS NOT NULL AND gto_valid_from <= CURRENT_TIMESTAMP)
            THEN 1 ELSE 0 END
            )');
        $fields['open']   = new \Zend_Db_Expr('SUM(
            CASE
            WHEN grc_success = 1 AND gto_completion_time IS NULL AND
                gto_valid_from <= CURRENT_TIMESTAMP AND
                (gto_valid_until >= CURRENT_TIMESTAMP OR gto_valid_until IS NULL)
            THEN 1 ELSE 0 END
            )');
        $fields['total'] = new \Zend_Db_Expr('SUM(
            CASE
            WHEN grc_success = 1 AND (
                    gto_completion_time IS NOT NULL OR
                    (gto_valid_from IS NOT NULL AND gto_valid_from <= CURRENT_TIMESTAMP)
                )
            THEN 1 ELSE 0 END
            )');
        /*
        $fields['future'] = new \Zend_Db_Expr('SUM(
            CASE
            WHEN grc_success = 1 AND gto_completion_time IS NULL AND gto_valid_from > CURRENT_TIMESTAMP
            THEN 1 ELSE 0 END
            )');
        $fields['unknown'] = new \Zend_Db_Expr('SUM(
            CASE
            WHEN grc_success = 1 AND gto_completion_time IS NULL AND gto_valid_from IS NULL
            THEN 1 ELSE 0 END
            )');
        $fields['is']      = new \Zend_Db_Expr("'='");
        $fields['success'] = new \Zend_Db_Expr('SUM(
            CASE
            WHEN grc_success = 1
            THEN 1 ELSE 0 END
            )');
        $fields['removed'] = new \Zend_Db_Expr('SUM(
            CASE
            WHEN grc_success = 0
            THEN 1 ELSE 0 END
            )');
        // */

        $fields['filler'] = new \Zend_Db_Expr('COALESCE(gems__track_fields.gtf_field_name, gems__groups.ggp_name)');

        $select = $this->db->select();
        $select->from('gems__tokens', $fields)
                ->joinInner('gems__reception_codes', 'gto_reception_code = grc_id_reception_code', array())
                ->joinInner('gems__rounds', 'gto_id_round = gro_id_round',
                        array('gro_round_description', 'gro_id_survey'))
                ->joinInner('gems__surveys', 'gro_id_survey = gsu_id_survey',
                        array('gsu_survey_name'))
                ->joinInner('gems__groups', 'gsu_id_primary_group =  ggp_id_group', array())
                ->joinLeft('gems__track_fields', 'gto_id_relationfield = gtf_id_field AND gtf_field_type = "relation"', array())
                ->group(array('gro_id_order', 'gro_round_description', 'gsu_survey_name', 'filler'));

        $filter = $this->getSearchFilter();
        if (array_key_exists('fillerfilter', $filter)) {
            $select->having('filler = ?', $filter['fillerfilter']);
        }

        return $select;
    }
886467
public function get()
    {
        $q = "SELECT " . $this->fields . " FROM `" . $this->table . "` " . $this->join;
        if ($this->condition) {
            $q .= " WHERE {$this->condition}";
        }
        if ($this->group) {
            $q .= " GROUP BY {$this->group}";
            if ($this->having) {
                $q .= " HAVING {$this->having}";
            }
        }
        if ($this->order) {
            $q .= " ORDER BY {$this->order}";
        }
        if ($this->limit) {
            $q .= " LIMIT {$this->limit}";
        }
        if ($this->offset) {
            $q .= " OFFSET {$this->offset}";
        }
        if ($this->procedure) {
            $q .= " PROCEDURE {$this->procedure}";
        }
        if ($this->into) {
            $q .= " INTO {$this->into}";
        }
        if ($this->for_update) {
            $q .= " FOR UPDATE";
        }
        if ($this->lock_in_share_mode) {
            $q .= " LOCK IN SHARE MODE";
        }
        return $this->connection->queryAssoc($q, $this->params);
    }
274260
public function getquery()
      {
            $query = \Grace\Req\Environment::getInstance()->all()['query'];
            $_p = array();
            $_query = explode('&', $query);
            foreach($_query as $k=>$value){
                  //存在=号
                  $p = explode('=', $value);
                  if(!empty($p[0])){
                        $_p[$p[0]] = isset($p[1])?$p[1]:'';
                  }
            }
            return $_p;       //获得通过querystring 分析出来的参数
      }
955944
public function selectPage()
    {
        if ($this->pageTotal <= 1) {
            return '';
        }

        $page = (int)$this->getOption('page', 1);
        $select = ' <select class="page-num-input" style="max-height: 400px"
        onchange="javascript:location.href=\'' . $this->getUrl() . '\'+this.value;">';

        for ($i = 1; $i <= $this->pageTotal; $i++) {
            $select .= ($page === $i) ?
                '<option value="' . $i . '" selected="selected"">' . $i . '</option>' :
                '<option value="' . $i . '" >' . $i . '</option>';
        }

        $select .= '</select> ';

        $this->html['select'] = $select;

        return $this;
    }
446785
public function getQuery()
    {
        $sql = $this->prepareSelectString();
        $sql .= $this->prepareJoinString();
        $sql .= $this->prepareWhereString();
        $sql .= $this->prepareGroupByString();
        $sql .= $this->prepareHavingString();
        $sql .= $this->prepareOrderByString();
        $sql .= $this->prepareLimitString();

        return $sql;
    }
673556
final public function select($column = '*')
    {
        if ($column == '*') {
            $this->_sql['select'][] = $column;
            return $this;
        }
        //处理字段名
        if (!is_array($column) && strpos($column, '(') === false) {
            $column = explode(',', $column);
        }
        $column = is_array($column) ? $column : [$column];

        $column = array_map([$this, 'formatColumn'], $column);
        $this->_sql['select'] = array_merge($this->_sql['select'], $column);
        return $this;
    }