
added new endpoints PUT /api/v1/summits/{id}/metrics/enter required scopes %s/me/summits/metrics/write s/me/summits/events/enter POST /api/v1/summits/{id}/metrics/leave payload type (string:in[GENERAL,LOBBY,EVENT,SPONSOR]) source_id (int[event id or sponsor id]) required scopes %s/me/summits/events/leave %s/me/summits/metrics/write Change-Id: I46babe9d92832da02fe175f0d6cbcfd26bb037ad Signed-off-by: smarcet <smarcet@gmail.com>
77 lines
2.7 KiB
PHP
77 lines
2.7 KiB
PHP
<?php namespace App\Repositories\Summit;
|
|
/**
|
|
* Copyright 2020 OpenStack Foundation
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
**/
|
|
use App\Models\Foundation\Summit\Repositories\ISummitMetricRepository;
|
|
use App\Repositories\SilverStripeDoctrineRepository;
|
|
use models\main\Member;
|
|
use models\summit\ISummitMetricType;
|
|
use models\summit\SummitEventAttendanceMetric;
|
|
use models\summit\SummitMetric;
|
|
use models\summit\SummitSponsorMetric;
|
|
/**
|
|
* Class DoctrineSummitMetricRepository
|
|
* @package App\Repositories\Summit
|
|
*/
|
|
final class DoctrineSummitMetricRepository
|
|
extends SilverStripeDoctrineRepository
|
|
implements ISummitMetricRepository
|
|
{
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
protected function getBaseEntity()
|
|
{
|
|
return SummitMetric::class;
|
|
}
|
|
|
|
/**
|
|
* @param Member $member
|
|
* @param string $type
|
|
* @param int|null $source_id
|
|
* @return SummitMetric|null
|
|
*/
|
|
public function getNonAbandoned(Member $member, string $type, ?int $source_id = null): ?SummitMetric
|
|
{
|
|
$query = $this->getEntityManager()
|
|
->createQueryBuilder()
|
|
->select("e")
|
|
->from($this->getBaseEntity(), "e")
|
|
->where("e.type = :type");
|
|
|
|
if(!is_null($source_id) && $source_id > 0){
|
|
if($type == ISummitMetricType::Event){
|
|
$query = $query->leftJoin(SummitEventAttendanceMetric::class, 'sam', 'WITH', 'e.id = sam.id')
|
|
->join("sam.event", "evt")
|
|
->andWhere("evt.id = :source_id")
|
|
->setParameter("source_id", $source_id);
|
|
}
|
|
if($type == ISummitMetricType::Sponsor){
|
|
$query = $query->leftJoin(SummitSponsorMetric::class, 'sm', 'WITH', 'e.id = sm.id')
|
|
->join("sm.sponsor", "sp")
|
|
->andWhere("sp.id = :source_id")
|
|
->setParameter("source_id", $source_id);
|
|
}
|
|
}
|
|
|
|
return $query
|
|
->andWhere("e.outgress_date is null")
|
|
->andWhere("e.member = :member")
|
|
->setParameter("member", $member)
|
|
->setParameter("type", trim($type))
|
|
->setMaxResults(1)
|
|
->orderBy('e.ingress_date', 'DESC')
|
|
->getQuery()
|
|
->getOneOrNullResult();
|
|
}
|
|
} |