Function countResult

@author: 713uk13m <dev@nguyenanhung.com>
@time  : 2018-12-02 21:50

@param array  $wheres
@param string $selectField

@return int
541384
public function countResult($wheres = [], $selectField = '*')
    {
        if (is_array($wheres) && count($wheres) > 0) {
            foreach ($wheres as $field => $value) {
                if (is_array($value)) {
                    $this->db->where($field, $value, self::OPERATOR_IS_IN);
                } else {
                    $this->db->where($field, $value, self::OPERATOR_EQUAL_TO);
                }
            }
        } else {
            $this->db->where($this->primaryKey, $wheres, self::OPERATOR_EQUAL_TO);
        }
        $result = $this->db->get($this->table, NULL, $selectField);
        $this->debug->debug(__FUNCTION__, 'Total Item Result => ' . json_encode($result));
        if ($this->db->count > 0) {
            return (int) $this->db->count;
        }

        return 0;
    }
62869
public function getInfoWithMultipleWhere($wheres = '', $field = 'id', $selectField = NULL)
    {
        if (is_array($wheres) && count($wheres) > 0) {
            foreach ($wheres as $key => $value) {
                if (is_array($value['value'])) {
                    $this->db->where($value['field'], $value['value'], self::OPERATOR_IS_IN);
                } else {
                    $this->db->where($value['field'], $value['value'], $value['operator']);
                }
            }
        } else {
            $this->db->where($field, $wheres, self::OPERATOR_EQUAL_TO);
        }
        $result = $this->db->getOne($this->table, $selectField);
        if ($this->db->count > 0) {
            return $result;
        }

        return NULL;
    }
558904
public function count($field = '*')
    {
        if (!empty($this->options['group'])) {
            // 支持GROUP
            $options = $this->getOptions();
            $subSql  = $this->options($options)
                ->field('count(' . $field . ') AS think_count')
                ->bind($this->bind)
                ->buildSql();

            $query = $this->newQuery()->table([$subSql => '_group_count_']);

            if (!empty($options['fetch_sql'])) {
                $query->fetchSql(true);
            }

            $count = $query->aggregate('COUNT', '*');
        } else {
            $count = $this->aggregate('COUNT', $field);
        }

        return is_string($count) ? $count : (int) $count;
    }
1336298
public function total($field = '*') {
        if (!$this->countperformed || $this->whereData) {
            $this->performCount('*');
        }

        return $this->count;
    }
197689
public function count(array $query = [], string $column = null): int
    {
        return $this->getSelector()->where($query)->count();
    }
12566
public function count(array $options = null) {
        if ($this->_model instanceof Garp_Model_Db) {
            unset($options['sort']);
            $options['fields'] = 'COUNT(*)';
            try {
                $result = $this->fetch($options);
                return !empty($result[0]['COUNT(*)']) ? $result[0]['COUNT(*)'] : 0;
            } catch (Zend_Db_Statement_Exception $e) {
                /**
                 * @todo When fetching results
                 * filtered using a HABTM relationship, extra
                 * meta field are returned from the binding table.
                 * This results in an SQL error; when using COUNT()
                 * and returning results from multiple tables a
                 * GROUP BY clause is mandatory. This must be fixed in
                 * the future.
                 */
                return 1000;
            }
        } else {
            return $this->_model->count();
        }
    }
214959
public int count(String where, String[] args) {
		return db.count(getTableName(), where, args);
	}
242666
public function count($field = '')
    {
        if ($field === '') {
            $query = [];
        } else {
            $query = (array) $field;
        }
        return count($this->select($query));
    }
988982
public function count(array $locales = null,  array $filters = null)
    {
        $this->loadCustomHydrator();

        $builder = $this->createQueryBuilder('tu')
            ->select('COUNT(DISTINCT tu.id) AS number');

        $this->addTransUnitFilters($builder, $filters);
        $this->addTranslationFilter($builder, $locales, $filters);

        return (int) $builder->getQuery()->getResult(Query::HYDRATE_SINGLE_SCALAR);
    }
436366
public function checkExists($whereValue = '', $whereField = 'id', $select = '*')
    {
        if (is_array($whereValue) && count($whereValue) > 0) {
            foreach ($whereValue as $column => $column_value) {
                if (is_array($column_value)) {
                    $this->db->where($column, $column_value, self::OPERATOR_IS_IN);
                } else {
                    $this->db->where($column, $column_value, self::OPERATOR_EQUAL_TO);
                }
            }
        } else {
            $this->db->where($whereField, $whereValue, self::OPERATOR_EQUAL_TO);
        }
        $this->db->get($this->table, NULL, $select);

        return (int) $this->db->count;
    }
169075
public function getDistinctResultByColumn($selectField = '', $whereValue = [])
    {
        if (!is_array($selectField)) {
            $selectField = [$selectField];
        }
        $this->connection();
        $db = DB::table($this->table);
        if (is_array($whereValue) && count($whereValue) > 0) {
            foreach ($whereValue as $column => $column_value) {
                if (is_array($column_value)) {
                    $db->whereIn($column, $column_value);
                } else {
                    $db->where($column, self::OPERATOR_EQUAL_TO, $column_value);
                }
            }
        } else {
            if (!empty($whereValue)) {
                if (is_array($whereValue)) {
                    $db->whereIn($selectField, $whereValue);
                } else {
                    $db->where($selectField, self::OPERATOR_EQUAL_TO, $whereValue);
                }
            }
        }
        $db->distinct();
        $this->debug->debug(__FUNCTION__, 'SQL Queries: ' . $db->toSql());
        $result = $db->get($selectField);
        $this->debug->debug(__FUNCTION__, 'Result from DB => ' . json_encode($result));

        return $result;
    }
334627
public function count($filter=NULL, array $options=NULL, $ttl=60) {
		$has=$this->hasCond;
		$count=$this->filteredFind($filter,$options,$ttl,true);
		$this->hasCond=$has;
		return $count;
	}
808282
public function countRel($key, $alias=null, $filter=null, $option=null) {
		if (!$alias)
			$alias = 'count_'.$key;
		$filter_bak = null;
		if ($filter || $option) {
			$filter_bak = isset($this->relFilter[$key]) ? $this->relFilter[$key] : false;
			$this->filter($key,$filter,$option);
		}
		if (isset($this->fieldConf[$key])){
			// one-to-one, one-to-many
			if ($this->fieldConf[$key]['relType'] == 'belongs-to-one') {
				if ($this->dbsType == 'sql') {
					$this->mapper->set($alias,'count('.$this->db->quotekey($key).')');
					$this->grp_stack=(!$this->grp_stack)?$key:$this->grp_stack.','.$key;
					if ($this->whitelist && !in_array($alias,$this->whitelist))
						$this->whitelist[] = $alias;
				} elseif ($this->dbsType == 'mongo')
					$this->_mongo_addGroup(array(
						'keys'=>array($key=>1),
						'reduce' => 'prev.'.$alias.'++;',
						"initial" => array($alias => 0)
					));
				else
					trigger_error('Cannot add direct relational counter.',E_USER_ERROR);
			} elseif($this->fieldConf[$key]['relType'] == 'has-many') {
				$relConf=$this->fieldConf[$key]['has-many'];
				if ($relConf['hasRel']=='has-many') {
					// many-to-many
					if ($this->dbsType == 'sql') {
						$mmTable = $this->mmTable($relConf,$key);
						$filter = array($mmTable.'.'.$relConf['relField']
							.' = '.$this->table.'.'.$this->primary);
						$from = $this->db->quotekey($mmTable);
						if (array_key_exists($key, $this->relFilter) &&
							!empty($this->relFilter[$key][0])) {
							$options=array();
							$from = $this->db->quotekey($mmTable).' '.
								$this->_sql_left_join($key,$mmTable,$relConf['relPK'],$relConf['relTable']);
							$relFilter = $this->relFilter[$key];
							$this->_sql_mergeRelCondition($relFilter,$relConf['relTable'],
								$filter,$options);
						}
						$filter = $this->queryParser->prepareFilter($filter,
							$this->dbsType, $this->db, $this->fieldConf);
						$crit = array_shift($filter);
						if (count($filter)>0)
							$this->preBinds=array_merge($this->preBinds,$filter);
						$this->mapper->set($alias,
							'(select count('.$this->db->quotekey($mmTable.'.'.$relConf['relField']).')'.
							' from '.$from.' where '.$crit.
							' group by '.$this->db->quotekey($mmTable.'.'.$relConf['relField']).')');
						if ($this->whitelist && !in_array($alias,$this->whitelist))
							$this->whitelist[] = $alias;
					} else {
						// count rel
						$this->countFields[]=$key;
					}
				} elseif($this->fieldConf[$key]['has-many']['hasRel']=='belongs-to-one') {
					// many-to-one
					if ($this->dbsType == 'sql') {
						$fConf=$relConf[0]::resolveConfiguration();
						$fTable=$fConf['table'];
						$fAlias=$fTable.'__count';
						$rKey=$relConf[1];
						$crit = $fAlias.'.'.$rKey.' = '.$this->table.'.'.$relConf['relField'];
						$filter = $this->mergeWithRelFilter($key,array($crit));
						$filter[0] = $this->queryParser->sql_prependTableToFields($filter[0],$fAlias);
						$filter = $this->queryParser->prepareFilter($filter,
							$this->dbsType, $this->db, $this->fieldConf);
						$crit = array_shift($filter);
						if (count($filter)>0)
							$this->preBinds=array_merge($this->preBinds,$filter);
						$this->mapper->set($alias,
							'(select count('.$this->db->quotekey($fAlias.'.'.$fConf['primary']).') from '.
							$this->db->quotekey($fTable).' AS '.$this->db->quotekey($fAlias).' where '.
							$crit.' group by '.$this->db->quotekey($fAlias.'.'.$rKey).')');
						if ($this->whitelist && !in_array($alias,$this->whitelist))
							$this->whitelist[] = $alias;
					} else {
						// count rel
						$this->countFields[]=$key;
					}
				}
			}
		}
		if ($filter_bak!==null) {
			if ($filter_bak)
				$this->relFilter[$key] = $filter_bak;
			else
				$this->clearFilter($key);
		}
	}
419066
public function count($field = '*')
    {
        $field = $this->distinct ? "DISTINCT {$field}" : $field;
        return intval($this->select(new Raw("COUNT({$field}) as `aggregation`"))->first(1)->aggregation);
    }
911577
public function getDistinctResult($selectField = '*')
    {
        try {
            $result = $this->db->setQueryOption(['DISTINCT'])->get($this->table, NULL, $selectField);
            $this->debug->debug(__FUNCTION__, 'Result from DB => ' . json_encode($result));

            return $result;
        }
        catch (\Exception $e) {
            $this->debug->error(__FUNCTION__, $e->getFile() . ' - Line: ' . $e->getLine() . ' - Message: ' . $e->getMessage());

            return NULL;
        }
    }
1294570
public function count(string $table, $where = null, array $whereParams = null, string $op = null): ?int
    {
        $query = $this->prepare('SELECT count(*) AS count FROM %n %v', [$table,
            $this->where($where, $whereParams, $op)]);

        $result = (object) $this->get($query);

        return isset($result->count) ? intval($result->count) : null;
    }
584038
public static function countWhere (string $column, array $operatorValue, string $joinOperator="AND") : int
	{
		$joinOperator 	= static::validateOperator($joinOperator, "AND");
		$expression 	= static::generateValue($column, $operatorValue, $joinOperator);
		$sqlQuery  		= "SELECT COUNT(*) as count FROM ".static::$tableName." WHERE {$column} {$expression}";
		$resultSet 		= Database::getInstance()->query($sqlQuery);
		$row 			= Database::fetchAssoc($resultSet);
		return (int) array_shift($row);
	}