get count

@param array $criteria
@param bool  $withTrash
@return int
339176
final public static function count(array $criteria = [], bool $withTrash = false)
    {
        $criteria = self::criteriaWithSoftDelete($criteria, $withTrash);
        return static::getRepository()
            ->count($criteria);
    }
958328
public function count($criteria=null)
	{
		$query=new CJoinQuery($this,$criteria);
		// ensure only one big join statement is used
		$this->_finder->baseLimited=false;
		$this->_finder->joinAll=true;
		$this->buildQuery($query);

		$query->limit=$query->offset=-1;

		if(!empty($criteria->group) || !empty($criteria->having))
		{
			$query->orders = array();
			$command=$query->createCommand($this->_builder);
			$sql=$command->getText();
			$sql="SELECT COUNT(*) FROM ({$sql}) sq";
			$command->setText($sql);
			$command->params=$query->params;
			return $command->queryScalar();
		}
		else
		{
			$select=is_array($criteria->select) ? implode(',',$criteria->select) : $criteria->select;
			if($select!=='*' && preg_match('/^count\s*\(/i',trim($select)))
				$query->selects=array($select);
			elseif(is_string($this->_table->primaryKey))
			{
				$prefix=$this->getColumnPrefix();
				$schema=$this->_builder->getSchema();
				$column=$prefix.$schema->quoteColumnName($this->_table->primaryKey);
				$query->selects=array("COUNT(DISTINCT $column)");
			}
			else
				$query->selects=array("COUNT(*)");

			$query->orders=$query->groups=$query->havings=array();
			$command=$query->createCommand($this->_builder);
			return $command->queryScalar();
		}
	}
415923
public function GetCount($Wheres = '', $ForceNoAnnouncements = FALSE) {
      if (is_array($Wheres) && count($Wheres) == 0)
         $Wheres = '';
      
      // Check permission and limit to categories as necessary
      if ($this->Watching)
         $Perms = CategoryModel::CategoryWatch();
      else
         $Perms = self::CategoryPermissions();
      
      if (!$Wheres || (count($Wheres) == 1 && isset($Wheres['d.CategoryID']))) {
         // Grab the counts from the faster category cache.
         if (isset($Wheres['d.CategoryID'])) {
            $CategoryIDs = (array)$Wheres['d.CategoryID'];
            if ($Perms === FALSE)
               $CategoryIDs = array();
            elseif (is_array($Perms))
               $CategoryIDs = array_intersect($CategoryIDs, $Perms);
            
            if (count($CategoryIDs) == 0) {
               return 0;
            } else {
               $Perms = $CategoryIDs;
            }
         }
         
         $Categories = CategoryModel::Categories();
         $Count = 0;
         
         foreach ($Categories as $Cat) {
            if (is_array($Perms) && !in_array($Cat['CategoryID'], $Perms))
               continue;
            $Count += (int)$Cat['CountDiscussions'];
         }
         return $Count;
      }
      
      if ($Perms !== TRUE) {
         $this->SQL->WhereIn('c.CategoryID', $Perms);
      }
      
      $this->EventArguments['Wheres'] = &$Wheres;
		$this->FireEvent('BeforeGetCount'); // @see 'BeforeGet' for consistency in count vs. results
         
      $this->SQL
         ->Select('d.DiscussionID', 'count', 'CountDiscussions')
         ->From('Discussion d')
         ->Join('Category c', 'd.CategoryID = c.CategoryID')
         ->Join('UserDiscussion w', 'd.DiscussionID = w.DiscussionID and w.UserID = '.Gdn::Session()->UserID, 'left')
         ->Where($Wheres);
      
      $Result = $this->SQL
         ->Get()
         ->FirstRow()
         ->CountDiscussions;
      
      return $Result;
   }
574000
public function with_count($value)
    {
        $with_counts = explode(',', $value);
        $model = $this->builder->getModel();
        $with_counts = collect($with_counts)->filter(function ($with_count) use($model) {
            if (str_contains($with_count, '.')) return ($model->{explode('.', $with_count)[0]}() instanceof Relation);
            return ($model->{$with_count}() instanceof Relation);
        })->toArray();
        return $this->builder->when(count($with_counts), function (Builder $query) use($with_counts) {
            if (is_null($query->getQuery()->columns)) $query->select([ '*' => $query->qualifyColumn('*') ]);
            $query->withCount($with_counts);
        });
    }
1123358
public function GetCountSQL($criteria)
	{
		$sql = "select count(1) as counter ";
	
		$sql .= $this->GetTableJoinSQL($criteria);
	
		$sql .= $criteria->GetJoin();
	
		$sql .= $this->GetWhereSQL($criteria);
		
		$criteria->Reset();
	
		return $sql;
	}
687793
public function subTotal($format = true, $withDiscount = true)
    {
        $total = 0;

        if ($this->count() != 0) {
            foreach ($this->getItems() as $item) {
                $total += $item->subTotal(false, $withDiscount);
            }
        }

        if ($total < 0) {
            $total = 0;
        }

        return $this->formatMoney($total, null, null, $format);
    }
982538
public function count($match = null, $exact = false)
    {
        if (!is_null($match)) {
            $keys = $this->index->getKeys();

            if ($exact) {
                $match = "^{$match}$";
            }

            $matches = array_filter($keys, function($key) use ($match) {
                return preg_match("/{$match}/i", $key);
            });

            return sizeof($matches);
        }

        return $this->index->count();
    }
1103614
public function getCount( $collection, $column, $value, $excludeId = null, $idColumn = null, array $extra = [] )
	{
		$query = $this->table( $collection )->where( $column, '=', $value );

		if ( !is_null( $excludeId ) && $excludeId != 'NULL' )
		{
			$query->where( $idColumn ?: 'id', '<>', $excludeId );
		}

		foreach ( $extra as $key => $extraValue )
		{
			$this->addWhere( $query, $key, $extraValue );
		}

		return $query->count();
	}
695883
public function countEmailsByCriteria($criteria, $count = false)
    {
        $mails = $this->driver->getEmailsBy($criteria, $count);

        return count($mails);
    }
900224
public function countPositions(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null)
    {
        $partial = $this->collPositionsPartial && !$this->isNew();
        if (null === $this->collPositions || null !== $criteria || $partial) {
            if ($this->isNew() && null === $this->collPositions) {
                return 0;
            }

            if ($partial && !$criteria) {
                return count($this->getPositions());
            }

            $query = ChildPositionQuery::create(null, $criteria);
            if ($distinct) {
                $query->distinct();
            }

            return $query
                ->filterBySport($this)
                ->count($con);
        }

        return count($this->collPositions);
    }
1039863
public function count($with_deleted = null)
    {
        if (false === $this->has_table()) return false;

        if ($this->count === 0) {
            $with_deleted !== null or $with_deleted = (! $this->is_destructive);

            if (false === $with_deleted) {
                $db = $this->db->where($this->deletion_key, 0);
            }

            $this->count = $db->count_all_results($this->table);
        }

        return $this->count;
    }
131276
public function count($beanType,$addSQL = '',$params = array()) {
		$sql = "SELECT count(*) FROM {$this->safeTable($beanType)} ";
		if ($addSQL!='') $addSQL = ' WHERE '.$addSQL; 
		return (int) $this->adapter->getCell($sql.$addSQL,$params);
	}
962852
public function countRemoteHistoryContaos(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
    {
        $partial = $this->collRemoteHistoryContaosPartial && !$this->isNew();
        if (null === $this->collRemoteHistoryContaos || null !== $criteria || $partial) {
            if ($this->isNew() && null === $this->collRemoteHistoryContaos) {
                return 0;
            }

            if ($partial && !$criteria) {
                return count($this->getRemoteHistoryContaos());
            }
            $query = RemoteHistoryContaoQuery::create(null, $criteria);
            if ($distinct) {
                $query->distinct();
            }

            return $query
                ->filterByRemoteApp($this)
                ->count($con);
        }

        return count($this->collRemoteHistoryContaos);
    }
701930
public function countChildren(Criteria $criteria = null, ConnectionInterface $con = null)
    {
        if (null === $this->collNestedSetChildren || null !== $criteria) {
            if ($this->isLeaf() || ($this->isNew() && null === $this->collNestedSetChildren)) {
                return 0;
            } else {
                return ChildCategoryQuery::create(null, $criteria)
                    ->childrenOf($this)
                    ->count($con);
            }
        } else {
            return count($this->collNestedSetChildren);
        }
    }
521885
protected function loadCount(IRowCriteria $criteria = null) : int
    {
        if ($criteria) {
            return $this->objectSource->countMatching($this->criteriaMapper->mapCriteria($criteria));
        } else {
            return $this->objectSource->count();
        }
    }
1060601
public function findOneWhere($criteria, $returnType = Table::RETURN_MODEL) {
        $this->limit(1);
        $result = $this->findWhere($criteria, $returnType);
        if (is_array($result)) {
            $result = array_values($result);
            return ($returnType === Table::RETURN_JSON) ? json_encode($result[0])
                        : $result[0];
        }
        else if (is_object($result)) {
            return $result->first();
        }
    }
149864
public static function count($criteria = array())
    {
        self::processCriteriaWithType($criteria);
        $count = self::connection()->count(self::collectionName(), $criteria);
        return $count;
    }