public function findWithCount(Query $query, array $options) { $query->select(['count' => $query->func()->count('Users.id')]); $query->matching('Users'); $query->group(['UserRoles.id']); return $query; }
/** * {@inheritdoc} */ public function apply($fromAlias, $fromIdentifier, $resourcePrefix, array $requesterIdentifiers, $mask, array $orX = []) { $this->query->join(['table' => $this->getAclSchema()->getPermissionsTableName(), 'alias' => 'acl_p', 'type' => 'LEFT', 'conditions' => $this->query->newExpr()->eq('acl_p.resource', $this->query->func()->concat([':acl_resource_prefix' => 'literal', $fromAlias . '.' . $fromIdentifier => 'literal']))]); $orX[] = $this->query->newExpr()->and_([$this->query->newExpr()->in('acl_p.requester', $requesterIdentifiers, 'string'), $this->query->newExpr(':acl_mask = (acl_p.mask & :acl_mask)')]); $this->query->andWhere($this->query->newExpr()->or_($orX)); $this->query->bind(':acl_resource_prefix', $resourcePrefix); $this->query->bind(':acl_mask', $mask, 'integer'); return $this->query; }
public function findMeetingsThisMonth(Query $query, $options = []) { $defaultOptions = ['results' => 5]; $options = array_merge($defaultOptions, $options); // override defaultoptions $dateFrom = new DateTime('first day of this month'); $query->hydrate(false)->select(['Users.name', 'totalMeetings' => $query->func()->count('Meetings.id')])->matching('Meetings')->where(['Meetings.date >=' => $dateFrom->format('Y-m-d')])->group(['Users.name'])->orderDesc('totalMeetings')->limit($options['results']); return $query; }
public function findAveragePerYear(Query $query, $options = []) { $year = $query->func()->year(['Salaries.from_date' => 'literal']); return $query->select(['year' => $year])->find('average')->group([$year]); }
public function findWorldLifeExpectancy(Query $query) { return $query->select(['avg' => $query->func()->avg('life_expectancy')]); }
public function findFemaleRatio(Query $query, $options = []) { $allManagers = $this->find()->select($query->func()->count('*')); return $query->find('female')->select(['female_ratio' => $query->newExpr($query->func()->count('*'))->add($allManagers)->type('/')]); }
public function findAverageLifeExpectancy(Query $query) { return $query->select(['average_exp' => $query->func()->avg('life_expectancy')]); }
public function findVencido(Query $query, array $options) { return $query->find('pago')->where(['vencimento <' => $query->func()->now()]); }