Fix on calculation of remaining_selections attribute

Change-Id: Ib09fd9c1468ec1f355d8f0314410bfebafda1938
Signed-off-by: smarcet <smarcet@gmail.com>
This commit is contained in:
smarcet 2021-04-26 19:37:13 -03:00
parent a13ff76ff4
commit 45ad467787
6 changed files with 60 additions and 18 deletions

View File

@ -1429,13 +1429,8 @@ class Presentation extends SummitEvent
* @throws ValidationException
*/
public function getRemainingSelectionsForMember(Member $member):int{
$criteria = Criteria::create();
$criteria->where(Criteria::expr()->eq('member', $member));
$criteria->andWhere(Criteria::expr()->eq('collection', SummitSelectedPresentation::CollectionSelected));
$res = $this->selected_presentations->matching($criteria)->first();
if($res === false ) return 0;
$list = $res->getList();
if(is_null($list) || !$list instanceof SummitSelectedPresentationList) return 0;
$list = $this->category->getSelectionListByTypeAndOwner(SummitSelectedPresentationList::Individual, $member);
if(is_null($list) || !$list instanceof SummitSelectedPresentationList) return $this->category->getTrackChairAvailableSlots();
return $list->getAvailableSlots();
}

View File

@ -38,14 +38,14 @@ class PresentationTrackChairView extends SilverstripeBaseModel
/**
* @ORM\ManyToOne(targetEntity="models\main\Member")
* @ORM\JoinColumn(name="TrackChairID", referencedColumnName="ID", onDelete="SET NULL")
* @ORM\JoinColumn(name="TrackChairID", referencedColumnName="ID", onDelete="CASCADE")
* @var Member
*/
private $viewer;
/**
* @ORM\ManyToOne(targetEntity="models\summit\Presentation", inversedBy="track_chair_views")
* @ORM\JoinColumn(name="PresentationID", referencedColumnName="ID", onDelete="SET NULL")
* @ORM\JoinColumn(name="PresentationID", referencedColumnName="ID", onDelete="CASCADE")
* @var Presentation
*/
private $presentation;

View File

@ -348,8 +348,7 @@ class SummitSelectedPresentationList extends SilverstripeBaseModel
* @throws ValidationException
*/
public function getAvailableSlots():int{
$selection_count = $this->
getSelectedPresentationsByCollection
$selection_count = $this->getSelectedPresentationsByCollection
(
SummitSelectedPresentation::CollectionSelected
)->count();
@ -359,9 +358,9 @@ class SummitSelectedPresentationList extends SilverstripeBaseModel
/**
* @return mixed
*/
public function getMaxPresentations()
public function getMaxPresentations():int
{
return $this->category->getSessionCount() + $this->category->getAlternateCount();
return $this->category->getTrackChairAvailableSlots();
}
public function getMaxAlternates()

View File

@ -94,7 +94,7 @@ class SummitTrackChair extends SilverstripeBaseModel
$track->removeFromTrackChairs($this);
$this->categories->removeElement($track);
$list = $track->getSelectionListByTypeAndOwner(SummitSelectedPresentationList::Individual, $track, $this->member);
$list = $track->getSelectionListByTypeAndOwner(SummitSelectedPresentationList::Individual, $this->member);
// if we remove the track , then we need to remove the selection lists
if(!is_null($list)){
$track->removeSelectionList($list);

View File

@ -92,7 +92,7 @@ final class SummitSelectedPresentationListService
throw new AuthzException("Current user is not allowed to perform this operation.");
}
$selection_list = $category->getSelectionListByTypeAndOwner(SummitSelectedPresentationList::Group, $category);
$selection_list = $category->getSelectionListByTypeAndOwner(SummitSelectedPresentationList::Group);
if (is_null($selection_list)) throw new EntityNotFoundException("list not found.");
return $selection_list;
@ -145,7 +145,7 @@ final class SummitSelectedPresentationListService
$member = $this->member_repository->getById(intval($owner_id));
if (is_null($member)) throw new EntityNotFoundException("member not found.");
$selection_list = $category->getSelectionListByTypeAndOwner(SummitSelectedPresentationList::Individual, $category, $member);
$selection_list = $category->getSelectionListByTypeAndOwner(SummitSelectedPresentationList::Individual, $member);
if (is_null($selection_list)) throw new EntityNotFoundException("list not found.");
return $selection_list;
@ -339,7 +339,7 @@ final class SummitSelectedPresentationListService
if(!$authz)
throw new AuthzException("User is not authorized to perform this action");
$selection_list = $category->getSelectionListByTypeAndOwner(SummitSelectedPresentationList::Individual, $category, $current_member);
$selection_list = $category->getSelectionListByTypeAndOwner(SummitSelectedPresentationList::Individual, $current_member);
if (is_null($selection_list))
throw new EntityNotFoundException(sprintf("Individual List not found for member %s and category %s", $current_member->getId(), $category->getId()));
@ -443,7 +443,7 @@ final class SummitSelectedPresentationListService
throw new AuthzException("Current user is not allowed to perform this operation.");
}
$selection_list = $category->getSelectionListByTypeAndOwner(SummitSelectedPresentationList::Individual, $category, $current_member);
$selection_list = $category->getSelectionListByTypeAndOwner(SummitSelectedPresentationList::Individual, $current_member);
if (is_null($selection_list))
throw new EntityNotFoundException(sprintf("Individual List not found for member %s and category %s", $current_member->getId(), $category->getId()));

View File

@ -0,0 +1,48 @@
<?php namespace Database\Migrations\Model;
/**
* Copyright 2021 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 Doctrine\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema as Schema;
use LaravelDoctrine\Migrations\Schema\Builder;
use LaravelDoctrine\Migrations\Schema\Table;
/**
* Class Version20210426223306
* @package Database\Migrations\Model
*/
final class Version20210426223306 extends AbstractMigration
{
/**
* @param Schema $schema
*/
public function up(Schema $schema):void
{
$builder = new Builder($schema);
if($schema->hasTable("PresentationTrackChairView")) {
$builder->table('PresentationTrackChairView', function (Table $table) {
// FK
$table->foreign("Member", "TrackChairID", "ID", ["onDelete" => "CASCADE"]);
$table->foreign("Presentation", "PresentationID", "ID", ["onDelete" => "CASCADE"]);
});
}
}
/**
* @param Schema $schema
*/
public function down(Schema $schema):void
{
}
}