Find Seasons by perimeter and order by start date

@param Perimeter $perimeter The perimeter

@return Doctrine\Common\Collections\Collection Collection of seasons
511995
public function findByPerimeter(Perimeter $perimeter)
    {
        $qb = $this->createQueryBuilder('s');
        $qb->where("s.perimeter = :perimeter")
            ->setParameter('perimeter', $perimeter)
            ->orderBy('s.startDate', 'DESC')
        ;

        return $qb->getQuery()->getResult();
    }
374154
public function byOrganizationWithYear($id)
  {
    // return $this->Period->where('organization_id', '=', $id)->with('year')->get(); -> Evitar los with

    $periods = $this->DB->connection($this->databaseConnectionName)
      ->table('ACCT_Period As p')
      ->join('ACCT_Fiscal_Year AS f', 'f.id', '=', 'p.fiscal_year_id')
      ->where('p.organization_id', '=', $id)
      ->get(array('p.id', 'p.month', 'f.year'));

    return new Collection($periods);
  }
23325
public static function getDatesForPeriod($period)
    {
        /*
         * Type of period is incorrect?
         * Nothing to do
         */
        if (!(new DatePeriod())->isCorrectType($period)) {
            return null;
        }

        $dateStart = null;
        $dateEnd = null;

        switch ($period) {
            case DatePeriod::LAST_WEEK:
                $thisWeekStart = new DateTime('this week');

                $dateStart = clone $thisWeekStart;
                $dateEnd = clone $thisWeekStart;

                $dateStart->sub(new DateInterval('P7D'));
                $dateEnd->sub(new DateInterval('P1D'));

                break;
            case DatePeriod::THIS_WEEK:
                $dateStart = new DateTime('this week');

                $dateEnd = clone $dateStart;
                $dateEnd->add(new DateInterval('P6D'));

                break;
            case DatePeriod::NEXT_WEEK:
                $dateStart = new DateTime('this week');
                $dateStart->add(new DateInterval('P7D'));

                $dateEnd = clone $dateStart;
                $dateEnd->add(new DateInterval('P6D'));

                break;
            case DatePeriod::LAST_MONTH:
                $dateStart = new DateTime('first day of last month');
                $dateEnd = new DateTime('last day of last month');

                break;
            case DatePeriod::THIS_MONTH:
                $lastMonth = self::getDatesForPeriod(DatePeriod::LAST_MONTH);
                $nextMonth = self::getDatesForPeriod(DatePeriod::NEXT_MONTH);

                if (null !== $lastMonth) {
                    $dateStart = $lastMonth->getEndDate();
                    $dateStart->add(new DateInterval('P1D'));
                }

                if (null !== $nextMonth) {
                    $dateEnd = $nextMonth->getStartDate();
                    $dateEnd->sub(new DateInterval('P1D'));
                }

                break;
            case DatePeriod::NEXT_MONTH:
                $dateStart = new DateTime('first day of next month');
                $dateEnd = new DateTime('last day of next month');

                break;
            case DatePeriod::LAST_YEAR:
            case DatePeriod::THIS_YEAR:
            case DatePeriod::NEXT_YEAR:
                $dateStart = new DateTime();
                $dateEnd = new DateTime();

                $yearPeriod = [
                    DatePeriod::LAST_YEAR,
                    DatePeriod::NEXT_YEAR,
                ];

                if (in_array($period, $yearPeriod, true)) {
                    $yearDifference = 1;

                    if (DatePeriod::LAST_YEAR === $period) {
                        $yearDifference *= -1;
                    }

                    $modifyString = sprintf('%s year', $yearDifference);
                    $dateStart->modify($modifyString);
                    $dateEnd->modify($modifyString);
                }

                $year = $dateStart->format('Y');
                $dateStart->setDate($year, 1, 1);
                $dateEnd->setDate($year, 12, 31);

                break;
        }

        /*
         * Start or end date is unknown?
         * Nothing to do
         */
        if (null === $dateStart || null === $dateEnd) {
            return null;
        }

        $dateStart->setTime(0, 0);
        $dateEnd->setTime(23, 59, 59);

        return new DatePeriod($dateStart, $dateEnd);
    }
1342096
public function laterThan($object)
    {
        if (!$this->sameTypeAs($object)) {
            throw new NotMatchTypeException($this);
        }

        return ($this->year() > $object->year()) ||
        ($this->year() >= $object->year() && $this->month() > $object->month()) ||
        ($this->year() >= $object->year() && $this->month() >= $object->month() && $this->day() > $object->day());
    }
938986
public function getByRangeUserId( $startDate, $endDate, $userId ) {

		$modelClass	= static::$modelClass;
		$modelTable	= $this->getModelTable();

		$conditions = [ "$modelTable.scheduledAt BETWEEN '$startDate' AND '$endDate'", 'userId' => $userId ];

		$query = $modelClass::queryWithUser( [ 'conditions' => $conditions ] );

		return $query->all();
	}
857830
private function sortByStartDate(Period $interval1, Period $interval2): int
    {
        return $interval1->getStartDate() <=> $interval2->getStartDate();
    }
170278
protected function getForPeriod($key, \DatePeriod $period)
    {
        $ranges = $this->getRanges($period);

        if (count($ranges) > 0) {
            if (count($ranges) == 1 && !($ranges[0] instanceof DateRange)) {
                return new DateValue($ranges[0], $this->repository->getFor($key, $ranges[0]));
            }

            $values = array();

            /** @var \Krucas\Counter\DateRange $range */
            foreach ($ranges as $range) {
                $values[] = new RangeValue(
                    $range,
                    $this->repository->getForRange($key, $range->getStartDate(), $range->getEndDate())
                );
            }

            return $values;
        }

        return null;
    }
1044426
public function notGroupStart(): QueryBuilderInterface
	{
		$conj = empty($this->state->getQueryMap()) ? ' WHERE ' : ' AND ';

		$this->state->appendMap($conj, ' NOT (', 'group_start');

		return $this;
	}
1329174
public function containsPeriod(PeriodInterface $period)
    {
        return $this->contains($period->getBegin()) && $this->contains($period->getEnd());
    }
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));
    }
1103496
public function getParticipationsByRangeDate($startDate = '', $endDate = '')
    {
        $em = $this->getServiceManager()->get('doctrine.entitymanager.orm_default');

        $startDateTime = \DateTime::createFromFormat('d/m/Y', $startDate);
        $endDateTime = \DateTime::createFromFormat('d/m/Y', $endDate);

        if ($startDate != '' && $endDate != '') {
            $dateRange = "(e.created_at >='" . $startDateTime->format('Y-m-d') . " 0:0:0' AND e.created_at <= '" . $endDateTime->format('Y-m-d') . " 0:0:0')";
        } elseif ($startDate == '' && $endDate != '') {
            $dateRange = "e.created_at <= '" . $endDateTime->format('Y-m-d') . " 0:0:0'";
        } elseif ($startDate != '' && $endDate == '') {
            $dateRange = "e.created_at >='" . $startDateTime->format('Y-m-d') . " 0:0:0'";
        } else {
            $dateRange = "e.created_at IS NOT NULL";
        }

        $query = $em->createQuery('
            SELECT COUNT(e.id) FROM PlaygroundGame\Entity\Entry e
			WHERE ' . $dateRange . '
            AND e.active=0
		');
        $count = $query->getSingleScalarResult();
        return $count;
    }
280625
public function indexByZoneType()
    {
        $zoneCollection = array();
        foreach ($this as $zone) {
            $zoneCollection[$zone->getZoneType()->getName()] = $zone;
        }

        return new self($zoneCollection);
    }
1165716
public function getInterests($dimensions)
    {
        $dates = $this->getStartEndDate();

        $data = LaravelAnalytics::performQuery($dates['start'], $dates['end'], 'ga:sessions', [
            'dimensions'  => $dimensions,
            'sort'        => '-ga:sessions',
            'max-results' => 30
        ]);

        if (is_null($data->rows)) {
            return [];
        }

        return $data->rows;
    }
874968
protected function buildQuery(array $constraints, array $restrictions = null)
    {
        /** @var \Doctrine\ORM\QueryBuilder $queryBuilder */
        $queryBuilder = $this->logRepository
            ->createQueryBuilder('l')->orderBy('l.dateLog');

        foreach ($restrictions as $key => $restriction) {
            $queryBuilder
                ->andWhere(sprintf('l.%s = :%s', $key, $key))
                ->setParameter($key, $restriction);
        }

        foreach ($constraints as $constraint) {
            $queryBuilder = $constraint->getQuery($queryBuilder);
        }

        return $queryBuilder;
    }
725096
def do_march(self):
        
        x, y = self.find_start_point()
        perimeter = self.walk_perimeter(x, y)
        return perimeter
498285
private function getInstancesIdsFromExternalsCoveragesIds(\Traversable $perimeters)
    {
        $userPerimeterNavitiaIds = array();
        $instances = $this->getInstances();

        foreach ($perimeters as $perimeter) {
            $userPerimeterNavitiaId = array_search($perimeter->getExternalCoverageId(), $instances);
            if ($userPerimeterNavitiaId) {
                $userPerimeterNavitiaIds[] = array_search($perimeter->getExternalCoverageId(), $instances);
            } else {
                throw new NotFoundHttpException("Coverage not found: " . $perimeter->getExternalCoverageId() . " in tyr api (" . $this->tyrUrl . ") ");
            }
        }
        return $userPerimeterNavitiaIds;
    }
85365
public function getFacetsByCriteria(Criteria $criteria)
    {
        $query = new Query();
        $query->setSize(0);

        $filter = $this->createFilterFromCriteria($criteria);

        $priorityFacet = new Facet\Terms('priorities');
        $priorityFacet->setField('priority');
        if ($filter->getFilters()) {
            $priorityFacet->setFilter($filter);
        }
        $query->addFacet($priorityFacet);

        $typeFacet = new Facet\Terms('types');
        $typeFacet->setField('type');
        if ($filter->getFilters()) {
            $typeFacet->setFilter($filter);
        }
        $query->addFacet($typeFacet);

        $channelFacet = new Facet\Terms('channels');
        $channelFacet->setField('channel');
        if ($filter->getFilters()) {
            $channelFacet->setFilter($filter);
        }
        $query->addFacet($channelFacet);

        $roleFacet = new Facet\Terms('roles');
        $roleFacet->setField('role');
        if ($filter->getFilters()) {
            $roleFacet->setFilter($filter);
        }
        $query->addFacet($roleFacet);

        $resultSet = $this->getType()->search($query);
        $facets = $resultSet->getFacets();

        $filterSets = [
            'priorities' => array_column($facets['priorities']['terms'], 'term'),
            'types' => array_column($facets['types']['terms'], 'term'),
            'channels' => array_column($facets['channels']['terms'], 'term'),
            'roles' => array_column($facets['roles']['terms'], 'term'),
        ];

        return $filterSets;
    }