Feature group events
Added group events, this kind of event types are only visible to members that belongs to one of the groups listed on the event. Change-Id: I9e7ba8ed10540b136997c054f7ace2c518bae184
This commit is contained in:
parent
4d1b9a6496
commit
b364505b55
@ -57,13 +57,17 @@ final class OAuth2SummitMembersApiController extends OAuth2ProtectedController
|
||||
$current_member = $this->repository->getById($current_member_id);
|
||||
if (is_null($current_member)) return $this->error404();
|
||||
|
||||
$fields = Request::input('fields', null);
|
||||
$relations = Request::input('relations', null);
|
||||
|
||||
|
||||
return $this->ok
|
||||
(
|
||||
SerializerRegistry::getInstance()->getSerializer($current_member)->serialize
|
||||
(
|
||||
Request::input('expand', ''),
|
||||
[],
|
||||
[],
|
||||
is_null($fields) ? [] : explode(',', $fields),
|
||||
is_null($relations) ? [] : explode(',', $relations),
|
||||
['summit' => $summit]
|
||||
)
|
||||
);
|
||||
|
@ -23,6 +23,12 @@ final class GroupSerializer extends SilverStripeSerializer
|
||||
(
|
||||
'Title' => 'title:json_string',
|
||||
'Description' => 'description:json_string',
|
||||
'Code' => 'code:json_string',
|
||||
);
|
||||
|
||||
protected static $allowed_relations = array
|
||||
(
|
||||
'members',
|
||||
);
|
||||
|
||||
/**
|
||||
@ -36,13 +42,19 @@ final class GroupSerializer extends SilverStripeSerializer
|
||||
{
|
||||
$group = $this->object;
|
||||
if(! $group instanceof Group) return [];
|
||||
$values = parent::serialize($expand, $fields, $relations, $params);
|
||||
$members = [];
|
||||
$values = parent::serialize($expand, $fields, $relations, $params);
|
||||
|
||||
foreach($group->getMembers() as $member){
|
||||
$members[] = SerializerRegistry::getInstance()->getSerializer($member)->serialize();
|
||||
if(!count($relations)) $relations = $this->getAllowedRelations();
|
||||
|
||||
if(in_array('members', $relations)) {
|
||||
$members = [];
|
||||
|
||||
foreach ($group->getMembers() as $member) {
|
||||
$members[] = SerializerRegistry::getInstance()->getSerializer($member)->serialize();
|
||||
}
|
||||
$values['members'] = $members;
|
||||
}
|
||||
$values['members'] = $members;
|
||||
|
||||
return $values;
|
||||
}
|
||||
}
|
@ -13,6 +13,7 @@
|
||||
**/
|
||||
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use models\main\Member;
|
||||
|
||||
/**
|
||||
* Class MemberSerializer
|
||||
@ -20,8 +21,8 @@ use Illuminate\Support\Facades\Config;
|
||||
*/
|
||||
final class MemberSerializer extends SilverStripeSerializer
|
||||
{
|
||||
protected static $array_mappings = array
|
||||
(
|
||||
protected static $array_mappings = [
|
||||
|
||||
'FirstName' => 'first_name:json_string',
|
||||
'LastName' => 'last_name:json_string',
|
||||
'Gender' => 'gender:json_string',
|
||||
@ -29,8 +30,23 @@ final class MemberSerializer extends SilverStripeSerializer
|
||||
'LinkedInProfile' => 'linked_in:json_string',
|
||||
'IrcHandle' => 'irc:json_string',
|
||||
'TwitterHandle' => 'twitter:json_string',
|
||||
);
|
||||
];
|
||||
|
||||
protected static $allowed_relations = [
|
||||
|
||||
'groups',
|
||||
'groups_events',
|
||||
'feedback'
|
||||
];
|
||||
|
||||
private static $expand_group_events = [
|
||||
'type',
|
||||
'location',
|
||||
'sponsors',
|
||||
'track',
|
||||
'track_groups',
|
||||
'groups',
|
||||
];
|
||||
|
||||
/**
|
||||
* @param null $expand
|
||||
@ -42,11 +58,20 @@ final class MemberSerializer extends SilverStripeSerializer
|
||||
public function serialize($expand = null, array $fields = array(), array $relations = array(), array $params = array())
|
||||
{
|
||||
$member = $this->object;
|
||||
$values = parent::serialize($expand, $fields, $relations, $params);
|
||||
$values['pic'] = Config::get("server.assets_base_url", 'https://www.openstack.org/'). 'profile_images/members/'. $member->getId();
|
||||
$summit = isset($params['summit'])? $params['summit'] :null;
|
||||
$speaker = !is_null($summit)? $summit->getSpeakerByMember($member): null;
|
||||
$attendee = !is_null($summit)? $summit->getAttendeeByMember($member): null;
|
||||
if(!$member instanceof Member) return [];
|
||||
|
||||
if(!count($relations)) $relations = $this->getAllowedRelations();
|
||||
|
||||
$values = parent::serialize($expand, $fields, $relations, $params);
|
||||
$values['pic'] = Config::get("server.assets_base_url", 'https://www.openstack.org/'). 'profile_images/members/'. $member->getId();
|
||||
$summit = isset($params['summit'])? $params['summit'] :null;
|
||||
|
||||
$speaker = !is_null($summit)? $summit->getSpeakerByMember($member): null;
|
||||
$attendee = !is_null($summit)? $summit->getAttendeeByMember($member): null;
|
||||
$groups_events = !is_null($summit)? $summit->getGroupEventsFor($member): null;
|
||||
|
||||
if(in_array('groups', $relations))
|
||||
$values['groups'] = $member->getGroupsIds();
|
||||
|
||||
if(!is_null($speaker))
|
||||
$values['speaker_id'] = $speaker->getId();
|
||||
@ -54,6 +79,16 @@ final class MemberSerializer extends SilverStripeSerializer
|
||||
if(!is_null($attendee))
|
||||
$values['attendee_id'] = $attendee->getId();
|
||||
|
||||
if(!is_null($groups_events) && in_array('groups_events', $relations)){
|
||||
$res = [];
|
||||
foreach ($groups_events as $group_event){
|
||||
$res[] = SerializerRegistry::getInstance()
|
||||
->getSerializer($group_event)
|
||||
->serialize(implode(',', self::$expand_group_events));
|
||||
}
|
||||
$values['groups_events'] = $res;
|
||||
}
|
||||
|
||||
if (!empty($expand)) {
|
||||
$exp_expand = explode(',', $expand);
|
||||
foreach ($exp_expand as $relation) {
|
||||
@ -63,7 +98,7 @@ final class MemberSerializer extends SilverStripeSerializer
|
||||
if (!is_null($attendee))
|
||||
{
|
||||
unset($values['attendee_id']);
|
||||
$values['attendee'] = SerializerRegistry::getInstance()->getSerializer($attendee)->serialize(null,[],['none']);
|
||||
$values['attendee'] = SerializerRegistry::getInstance()->getSerializer($attendee)->serialize($expand,[],['none']);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -71,18 +106,29 @@ final class MemberSerializer extends SilverStripeSerializer
|
||||
if (!is_null($speaker))
|
||||
{
|
||||
unset($values['speaker_id']);
|
||||
$values['speaker'] = SerializerRegistry::getInstance()->getSerializer($speaker)->serialize(null,[],['none']);
|
||||
$values['speaker'] = SerializerRegistry::getInstance()->getSerializer($speaker)->serialize($expand,[],['none']);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'feedback': {
|
||||
if(!in_array('feedback', $relations)) break;
|
||||
$feedback = array();
|
||||
foreach ($member->getFeedbackBySummit($summit) as $f) {
|
||||
array_push($feedback, SerializerRegistry::getInstance()->getSerializer($f)->serialize());
|
||||
$feedback[] = SerializerRegistry::getInstance()->getSerializer($f)->serialize();
|
||||
}
|
||||
$values['feedback'] = $feedback;
|
||||
}
|
||||
break;
|
||||
case 'groups': {
|
||||
if(!in_array('groups', $relations)) break;
|
||||
$groups = [];
|
||||
unset($values['groups']);
|
||||
foreach ($member->getGroups() as $g) {
|
||||
$groups[] = SerializerRegistry::getInstance()->getSerializer($g)->serialize(null, [], ['none']);
|
||||
}
|
||||
$values['groups'] = $groups;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -42,6 +42,24 @@ final class PresentationCategorySerializer extends SilverStripeSerializer
|
||||
$groups[] = intval($group->getId());
|
||||
}
|
||||
$values['track_groups'] = $groups;
|
||||
|
||||
if (!empty($expand)) {
|
||||
$exp_expand = explode(',', $expand);
|
||||
foreach ($exp_expand as $relation) {
|
||||
switch (trim($relation)) {
|
||||
case 'track_groups': {
|
||||
$groups = array();
|
||||
unset($values['track_groups']);
|
||||
foreach ($category->getGroups() as $g) {
|
||||
$groups[] = SerializerRegistry::getInstance()->getSerializer($g)->serialize(null, [], ['none']);
|
||||
}
|
||||
$values['track_groups'] = $groups;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
}
|
@ -91,7 +91,7 @@ class PresentationSpeakerSerializer extends SilverStripeSerializer
|
||||
$values['presentations'] = $presentations;
|
||||
|
||||
$moderated_presentations = [];
|
||||
foreach ($speaker->getModeratedPresentation($summit_id, $published) as $p) {
|
||||
foreach ($speaker->getModeratedPresentations($summit_id, $published) as $p) {
|
||||
$moderated_presentations[] = SerializerRegistry::getInstance()->getSerializer($p)->serialize();
|
||||
}
|
||||
$values['moderated_presentations'] = $presentations;
|
||||
|
@ -63,6 +63,7 @@ final class SerializerRegistry
|
||||
$this->registry['PresentationCategoryGroup'] = PresentationCategoryGroupSerializer::class;
|
||||
$this->registry['Tag'] = TagSerializer::class;
|
||||
$this->registry['SummitEvent'] = SummitEventSerializer::class;
|
||||
$this->registry['SummitGroupEvent'] = SummitGroupEventSerializer::class;
|
||||
$this->registry['SummitEventMetricsSnapshot'] = SummitEventMetricsSnapshotSerializer::class;
|
||||
$this->registry['Presentation'] = PresentationSerializer::class;
|
||||
$this->registry['PresentationVideo'] = PresentationVideoSerializer::class;
|
||||
|
@ -79,7 +79,6 @@ class SummitEventSerializer extends SilverStripeSerializer
|
||||
|
||||
if(!count($relations)) $relations = $this->getAllowedRelations();
|
||||
|
||||
|
||||
$values = parent::serialize($expand, $fields, $relations, $params);
|
||||
|
||||
if(in_array('sponsors', $relations))
|
||||
@ -120,6 +119,15 @@ class SummitEventSerializer extends SilverStripeSerializer
|
||||
$values['sponsors'] = $sponsors;
|
||||
}
|
||||
break;
|
||||
case 'track': {
|
||||
unset($values['track_id']);
|
||||
$values['track'] = SerializerRegistry::getInstance()->getSerializer($event->getCategory())->serialize($expand);
|
||||
}
|
||||
case 'type': {
|
||||
unset($values['type_id']);
|
||||
$values['type'] = SerializerRegistry::getInstance()->getSerializer($event->getType())->serialize($expand);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
58
app/ModelSerializers/SummitGroupEventSerializer.php
Normal file
58
app/ModelSerializers/SummitGroupEventSerializer.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php namespace ModelSerializers;
|
||||
/**
|
||||
* Copyright 2017 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 models\summit\SummitGroupEvent;
|
||||
|
||||
/**
|
||||
* Class SummitGroupEventSerializer
|
||||
* @package ModelSerializers
|
||||
*/
|
||||
class SummitGroupEventSerializer extends SummitEventSerializer
|
||||
{
|
||||
|
||||
/**
|
||||
* @param null $expand
|
||||
* @param array $fields
|
||||
* @param array $relations
|
||||
* @param array $params
|
||||
* @return array
|
||||
*/
|
||||
public function serialize($expand = null, array $fields = array(), array $relations = array(), array $params = array() )
|
||||
{
|
||||
$values = parent::serialize($expand, $fields, $relations, $params);
|
||||
|
||||
$event = $this->object;
|
||||
if(!$event instanceof SummitGroupEvent) return [];
|
||||
|
||||
$values['groups'] = $event->getGroupsIds();
|
||||
|
||||
if (!empty($expand)) {
|
||||
$exp_expand = explode(',', $expand);
|
||||
foreach ($exp_expand as $relation) {
|
||||
switch (trim($relation)) {
|
||||
case 'groups': {
|
||||
$groups = array();
|
||||
unset($values['groups']);
|
||||
foreach ($event->getGroups() as $g) {
|
||||
$groups[] = SerializerRegistry::getInstance()->getSerializer($g)->serialize(null, [], ['none']);
|
||||
}
|
||||
$values['groups'] = $groups;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
}
|
@ -24,6 +24,10 @@ use models\utils\SilverstripeBaseModel;
|
||||
*/
|
||||
class Group extends SilverstripeBaseModel
|
||||
{
|
||||
const AdminGroupCode = 'administrators';
|
||||
const CommunityMembersCode = 'community-members';
|
||||
const FoundationMembersCode = 'foundation-members';
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct();
|
||||
$this->members = new ArrayCollection();
|
||||
|
@ -13,7 +13,9 @@
|
||||
**/
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
use models\summit\Summit;
|
||||
use models\summit\SummitEvent;
|
||||
use models\summit\SummitEventFeedback;
|
||||
use models\utils\SilverstripeBaseModel;
|
||||
use Doctrine\ORM\Mapping AS ORM;
|
||||
@ -208,4 +210,55 @@ class Member extends SilverstripeBaseModel
|
||||
->setParameter('owner_id', $this->getId())
|
||||
->getQuery()->getResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SummitEvent $event
|
||||
* @return SummitEventFeedback[]
|
||||
*/
|
||||
public function getFeedbackByEvent(SummitEvent $event){
|
||||
return $this->createQueryBuilder()
|
||||
->select('distinct f')
|
||||
->from('models\summit\SummitEventFeedback','f')
|
||||
->join('f.event','e')
|
||||
->join('f.owner','o')
|
||||
->join('e.summit','s')
|
||||
->where('e.id = :event_id and o.id = :owner_id')
|
||||
->setParameter('event_id', $event->getId())
|
||||
->setParameter('owner_id', $this->getId())
|
||||
->getQuery()->getResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isAdmin(){
|
||||
|
||||
$admin_group = $this->groups->filter(function($entity){
|
||||
return $entity->getCode() == Group::AdminGroupCode;
|
||||
});
|
||||
|
||||
return !is_null($admin_group) && $admin_group != false && $admin_group->count() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int[]
|
||||
*/
|
||||
public function getGroupsIds(){
|
||||
$ids = [];
|
||||
foreach ($this->getGroups() as $g){
|
||||
$ids[] = intval($g->getId());
|
||||
}
|
||||
return $ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getGroupsCodes(){
|
||||
$codes = [];
|
||||
foreach ($this->getGroups() as $g){
|
||||
$codes[] = $g->getCode();
|
||||
}
|
||||
return $codes;
|
||||
}
|
||||
}
|
@ -12,6 +12,7 @@
|
||||
* limitations under the License.
|
||||
**/
|
||||
|
||||
use models\main\Member;
|
||||
use models\summit\SummitEntityEvent;
|
||||
use ModelSerializers\SerializerRegistry;
|
||||
|
||||
@ -26,9 +27,9 @@ final class SummitEntityEventProcessContext
|
||||
private $update_operations = array();
|
||||
private $summit_events_operations = array();
|
||||
/**
|
||||
* @var int
|
||||
* @var Member
|
||||
*/
|
||||
private $current_member_id;
|
||||
private $current_member;
|
||||
/**
|
||||
* @var EntityEventList
|
||||
*/
|
||||
@ -36,17 +37,24 @@ final class SummitEntityEventProcessContext
|
||||
|
||||
/**
|
||||
* SummitEntityEventProcessContext constructor.
|
||||
* @param int|null $current_member_id
|
||||
* @param Member|null $current_member
|
||||
*/
|
||||
public function __construct($current_member_id){
|
||||
$this->list = new EntityEventList();
|
||||
$this->current_member_id = $current_member_id;
|
||||
public function __construct($current_member = null){
|
||||
$this->list = new EntityEventList();
|
||||
$this->current_member = $current_member;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Member|null
|
||||
*/
|
||||
public function getCurrentMember(){ return $this->current_member; }
|
||||
|
||||
/**
|
||||
* @return int|null
|
||||
*/
|
||||
public function getCurrentMemberId(){ return $this->current_member_id; }
|
||||
public function getCurrentMemberId(){
|
||||
return !is_null($this->current_member) ? $this->current_member->getId() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SummitEntityEvent $entity_event
|
||||
|
@ -58,6 +58,14 @@ final class EntityEventTypeFactory
|
||||
return new SummitEventEntityEventDeleteType($e, $ctx);
|
||||
}
|
||||
break;
|
||||
case 'SummitGroupEvent':
|
||||
{
|
||||
if ($e->getType() === 'UPDATE' || $e->getType() === "INSERT")
|
||||
return new SummitGroupEventEntityEventInsertOrUpdateType($e, $ctx);
|
||||
|
||||
return new SummitEventEntityEventDeleteType($e, $ctx);;
|
||||
}
|
||||
break;
|
||||
case 'MySchedule':
|
||||
{
|
||||
return new MyScheduleEntityEventType($e, $ctx);
|
||||
|
@ -12,7 +12,7 @@
|
||||
* limitations under the License.
|
||||
**/
|
||||
use models\utils\IEntity;
|
||||
|
||||
use models\summit\SummitEvent;
|
||||
/**
|
||||
* Class SummitEventEntityEventType
|
||||
* @package Models\foundation\summit\EntityEvents
|
||||
@ -23,9 +23,16 @@ abstract class SummitEventEntityEventType extends EntityEventType
|
||||
* @return IEntity|null
|
||||
*/
|
||||
protected function registerEntity(){
|
||||
$entity = $this->entity_event->getSummit()->getScheduleEvent($this->entity_event->getEntityId());
|
||||
$entity = $this->getEntity();
|
||||
if(!is_null($entity))
|
||||
$this->entity_event->registerEntity($entity);
|
||||
$this->entity_event->registerEntity($entity);
|
||||
return $entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return SummitEvent|null
|
||||
*/
|
||||
protected function getEntity(){
|
||||
return $this->entity_event->getSummit()->getScheduleEvent($this->entity_event->getEntityId());
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
<?php namespace Models\foundation\summit\EntityEvents;
|
||||
|
||||
/**
|
||||
* Copyright 2017 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 models\summit\Summit;
|
||||
use models\summit\SummitGroupEvent;
|
||||
|
||||
/**
|
||||
* Class SummitGroupEventEntityEventInsertOrUpdateType
|
||||
* @package Models\foundation\summit\EntityEvents
|
||||
*/
|
||||
final class SummitGroupEventEntityEventInsertOrUpdateType extends SummitEventEntityEventType
|
||||
{
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function process()
|
||||
{
|
||||
$metadata = $this->entity_event->getMetadata();
|
||||
$published_old = isset($metadata['pub_old']) ? (bool)intval($metadata['pub_old']) : false;
|
||||
$published_current = isset($metadata['pub_new']) ? (bool)intval($metadata['pub_new']) : false;
|
||||
|
||||
// the event was not published at the moment of UPDATE .. then skip it!
|
||||
if (!$published_old && !$published_current) return;
|
||||
$entity = $this->getEntity();
|
||||
|
||||
if (!$entity instanceof SummitGroupEvent) return;
|
||||
|
||||
$current_member = $this->process_ctx->getCurrentMember();
|
||||
|
||||
if (is_null($current_member)) return;
|
||||
|
||||
if (!Summit::allowToSee($entity, $current_member)) return;
|
||||
|
||||
if (!is_null($entity)) // if event exists its bc its published
|
||||
{
|
||||
$this->registerEntity();
|
||||
$this->entity_event->setType
|
||||
(
|
||||
$published_current && isset($metadata['pub_old']) && !$published_old ?
|
||||
'INSERT' :
|
||||
$this->entity_event->getType()
|
||||
);
|
||||
|
||||
$this->process_ctx->registerEntityEvent($this->entity_event);
|
||||
$this->process_ctx->registerSummitEventOp($this->entity_event);
|
||||
return;
|
||||
}
|
||||
// if does not exists on schedule delete it
|
||||
$this->entity_event->setType('DELETE');
|
||||
$chain = new SummitEventEntityEventDeleteType($this->entity_event, $this->process_ctx);
|
||||
return $chain->process();
|
||||
}
|
||||
}
|
30
app/Models/Foundation/Summit/Events/ISummitEventType.php
Normal file
30
app/Models/Foundation/Summit/Events/ISummitEventType.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php namespace models\summit;
|
||||
/**
|
||||
* Copyright 2017 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.
|
||||
**/
|
||||
|
||||
/**
|
||||
* Interface ISummitEventType
|
||||
* @package models\summit
|
||||
*/
|
||||
interface ISummitEventType
|
||||
{
|
||||
// default types
|
||||
|
||||
const HandonLabs = 'Hand-on Labs';
|
||||
|
||||
const Lunch_Breaks = 'Lunch & Breaks';
|
||||
|
||||
const EveningEvents = 'Evening Events';
|
||||
|
||||
const GroupsEvents = 'Groups Events';
|
||||
}
|
@ -34,7 +34,7 @@ use Cocur\Slugify\Slugify;
|
||||
* @ORM\Table(name="SummitEvent")
|
||||
* @ORM\InheritanceType("JOINED")
|
||||
* @ORM\DiscriminatorColumn(name="ClassName", type="string")
|
||||
* @ORM\DiscriminatorMap({"SummitEvent" = "SummitEvent", "Presentation" = "Presentation"})
|
||||
* @ORM\DiscriminatorMap({"SummitEvent" = "SummitEvent", "Presentation" = "Presentation", "SummitGroupEvent" = "SummitGroupEvent"})
|
||||
* @ORM\Entity(repositoryClass="repositories\summit\DoctrineSummitEventRepository")
|
||||
* @ORM\HasLifecycleCallbacks
|
||||
* Class SummitEvent
|
||||
|
@ -119,4 +119,13 @@ class SummitEventType extends SilverstripeBaseModel
|
||||
$this->blackout_times = $blackout_times;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
* @return bool
|
||||
*/
|
||||
static public function isPrivate($type){
|
||||
$private_types = [ISummitEventType::GroupsEvents];
|
||||
return in_array($type, $private_types);
|
||||
}
|
||||
|
||||
}
|
72
app/Models/Foundation/Summit/Events/SummitGroupEvent.php
Normal file
72
app/Models/Foundation/Summit/Events/SummitGroupEvent.php
Normal file
@ -0,0 +1,72 @@
|
||||
<?php namespace models\summit;
|
||||
/**
|
||||
* Copyright 2017 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\ORM\Mapping AS ORM;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use models\main\Group;
|
||||
|
||||
/**
|
||||
* Class SummitGroupEvent
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="SummitGroupEvent")
|
||||
* @package models\summit
|
||||
*/
|
||||
class SummitGroupEvent extends SummitEvent
|
||||
{
|
||||
/**
|
||||
* @ORM\ManyToMany(targetEntity="models\main\Group")
|
||||
* @ORM\JoinTable(name="SummitGroupEvent_Groups",
|
||||
* joinColumns={
|
||||
* @ORM\JoinColumn(name="`SummitGroupEventID`", referencedColumnName="ID")
|
||||
* },
|
||||
* inverseJoinColumns={
|
||||
* @ORM\JoinColumn(name="GroupID", referencedColumnName="ID")
|
||||
* }
|
||||
* )
|
||||
*/
|
||||
private $groups;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->groups = new ArrayCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Group[]
|
||||
*/
|
||||
public function getGroups()
|
||||
{
|
||||
return $this->groups;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayCollection $groups
|
||||
*/
|
||||
public function setGroups($groups)
|
||||
{
|
||||
$this->groups = $groups;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int[]
|
||||
*/
|
||||
public function getGroupsIds(){
|
||||
$ids = [];
|
||||
foreach ($this->getGroups() as $g){
|
||||
$ids[] = intval($g->getId());
|
||||
}
|
||||
return $ids;
|
||||
}
|
||||
|
||||
}
|
@ -890,4 +890,61 @@ SQL;
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SummitEvent $summit_event
|
||||
* @param Member|null $member
|
||||
* @return bool
|
||||
*/
|
||||
static public function allowToSee(SummitEvent $summit_event, Member $member = null)
|
||||
{
|
||||
|
||||
if (SummitEventType::isPrivate($summit_event->getType()->getType())) {
|
||||
if (is_null($member))
|
||||
return false;
|
||||
|
||||
if ($member->isAdmin()) return true;
|
||||
|
||||
// i am logged, check if i have permissions
|
||||
if ($summit_event instanceof SummitGroupEvent) {
|
||||
|
||||
$member_groups_code = [];
|
||||
$event_groups_code = [];
|
||||
|
||||
foreach ($member->getGroups() as $member_group) {
|
||||
$member_groups_code[] = $member_group->getCode();
|
||||
}
|
||||
|
||||
foreach ($summit_event->getGroups() as $event_group) {
|
||||
$event_groups_code[] = $event_group->getCode();
|
||||
}
|
||||
|
||||
return count(array_intersect($event_groups_code, $member_groups_code)) > 0;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Member $member
|
||||
* @return SummitGroupEvent[]
|
||||
*/
|
||||
public function getGroupEventsFor(Member $member){
|
||||
$builder = $this->createQueryBuilder()
|
||||
->select('distinct eg')
|
||||
->from('models\summit\SummitGroupEvent','eg')
|
||||
->join('eg.groups','g')
|
||||
->join('eg.summit','s')
|
||||
->where("s.id = :summit_id and eg.published = 1")
|
||||
->setParameter('summit_id', $this->getId());
|
||||
|
||||
if(!$member->isAdmin()){
|
||||
$groups_ids = $member->getGroupsIds();
|
||||
$groups_ids = implode(",", $groups_ids);
|
||||
$builder->andWhere("g.id in ({$groups_ids})");
|
||||
}
|
||||
|
||||
return $builder->getQuery()->getResult();
|
||||
}
|
||||
|
||||
}
|
@ -31,6 +31,10 @@ use Doctrine\ORM\Query\Expr\Join;
|
||||
final class DoctrineSummitEventRepository extends SilverStripeDoctrineRepository implements ISummitEventRepository
|
||||
{
|
||||
|
||||
private static $forbidded_classes = [
|
||||
'models\\summit\\SummitGroupEvent'
|
||||
];
|
||||
|
||||
/**
|
||||
* @param SummitEvent $event
|
||||
* @return SummitEvent[]
|
||||
@ -47,6 +51,7 @@ final class DoctrineSummitEventRepository extends SilverStripeDoctrineRepository
|
||||
->join('e.summit', 's', Join::WITH, " s.id = :summit_id")
|
||||
->where('e.published = 1')
|
||||
->andWhere('e.start_date < :end_date')
|
||||
->andWhere("not e INSTANCE OF ('" . implode("','", self::$forbidded_classes) . "')")
|
||||
->andWhere('e.end_date > :start_date')
|
||||
->setParameter('summit_id', $summit->getId())
|
||||
->setParameter('start_date', $start_date)
|
||||
@ -62,7 +67,10 @@ final class DoctrineSummitEventRepository extends SilverStripeDoctrineRepository
|
||||
*/
|
||||
public function getAllByPage(PagingInfo $paging_info, Filter $filter = null, Order $order = null)
|
||||
{
|
||||
$class = count($filter->getFilter('speaker')) > 0? \models\summit\Presentation::class : \models\summit\SummitEvent::class;
|
||||
$class = count($filter->getFilter('speaker')) > 0?
|
||||
\models\summit\Presentation::class :
|
||||
\models\summit\SummitEvent::class;
|
||||
|
||||
$query = $this->getEntityManager()->createQueryBuilder()
|
||||
->select("e")
|
||||
->from($class, "e");
|
||||
@ -131,6 +139,7 @@ final class DoctrineSummitEventRepository extends SilverStripeDoctrineRepository
|
||||
}
|
||||
|
||||
$query= $query
|
||||
->andWhere("not e INSTANCE OF ('" . implode("','", self::$forbidded_classes) . "')")
|
||||
->setFirstResult($paging_info->getOffset())
|
||||
->setMaxResults($paging_info->getPerPage());
|
||||
|
||||
|
@ -151,6 +151,8 @@ final class SummitService implements ISummitService
|
||||
if (is_null($event)) {
|
||||
throw new EntityNotFoundException('event not found on summit!');
|
||||
}
|
||||
if(!Summit::allowToSee($event, $attendee->getMember()))
|
||||
throw new EntityNotFoundException('event not found on summit!');
|
||||
$attendee->add2Schedule($event);
|
||||
});
|
||||
Event::fire(new MyScheduleAdd($attendee, $event_id));
|
||||
@ -174,7 +176,10 @@ final class SummitService implements ISummitService
|
||||
{
|
||||
$this->tx_service->transaction(function () use ($summit, $attendee, $event_id) {
|
||||
$event = $summit->getScheduleEvent($event_id);
|
||||
if (is_null($event)) throw new EntityNotFoundException('event not found on summit!');
|
||||
if (is_null($event))
|
||||
throw new EntityNotFoundException('event not found on summit!');
|
||||
if(!Summit::allowToSee($event, $attendee->getMember()))
|
||||
throw new EntityNotFoundException('event not found on summit!');
|
||||
$attendee->checkIn($event);
|
||||
});
|
||||
}
|
||||
@ -190,7 +195,8 @@ final class SummitService implements ISummitService
|
||||
{
|
||||
$this->tx_service->transaction(function () use ($summit, $attendee, $event_id) {
|
||||
$event = $summit->getScheduleEvent($event_id);
|
||||
if (is_null($event)) throw new EntityNotFoundException('event not found on summit!');
|
||||
if (is_null($event))
|
||||
throw new EntityNotFoundException('event not found on summit!');
|
||||
$attendee->removeFromSchedule($event);
|
||||
});
|
||||
|
||||
@ -227,7 +233,17 @@ final class SummitService implements ISummitService
|
||||
$member = $this->member_repository->getById($member_id);
|
||||
}
|
||||
|
||||
if (is_null($member)) throw new EntityNotFoundException();
|
||||
if (is_null($member))
|
||||
throw new EntityNotFoundException('member not found!.');
|
||||
|
||||
if(!Summit::allowToSee($event, $member))
|
||||
throw new EntityNotFoundException('event not found on summit!.');
|
||||
|
||||
// check older feedback
|
||||
$older_feedback = $member->getFeedbackByEvent($event);
|
||||
|
||||
if(count($older_feedback) > 0 )
|
||||
throw new ValidationException(sprintf("you already sent feedback for event id %s!.", $event->getIdentifier()));
|
||||
|
||||
$newFeedback = new SummitEventFeedback();
|
||||
$newFeedback->setRate(intval($feedback['rate']));
|
||||
@ -253,7 +269,8 @@ final class SummitService implements ISummitService
|
||||
|
||||
$global_last_id = $this->entity_events_repository->getLastEntityEventId($summit);
|
||||
$from_id = !is_null($from_id) ? intval($from_id) : null;
|
||||
$ctx = new SummitEntityEventProcessContext($member_id);
|
||||
$member = !is_null($member_id) && $member_id > 0 ? $this->member_repository->getById($member_id): null;
|
||||
$ctx = new SummitEntityEventProcessContext($member);
|
||||
|
||||
do {
|
||||
|
||||
|
@ -270,9 +270,9 @@ final class OAuth2SummitApiTest extends ProtectedApiTest
|
||||
{
|
||||
$params = array
|
||||
(
|
||||
'id' => $summit_id,
|
||||
'id' => $summit_id,
|
||||
'attendee_id' => 'me',
|
||||
'event_id' => $event_id
|
||||
'event_id' => $event_id
|
||||
);
|
||||
|
||||
$headers = array("HTTP_Authorization" => " Bearer " . $this->access_token);
|
||||
@ -695,15 +695,15 @@ final class OAuth2SummitApiTest extends ProtectedApiTest
|
||||
$this->assertTrue(!is_null($events));
|
||||
}
|
||||
|
||||
public function testCurrentSummitEventsByEventTypeExpandLocation()
|
||||
public function testCurrentSummitEventsByEventTypeExpandLocation($summit_id = 7)
|
||||
{
|
||||
$params = array
|
||||
(
|
||||
'id' => 'current',
|
||||
'id' => $summit_id,
|
||||
'expand' => 'feedback,location',
|
||||
'filter' => array
|
||||
(
|
||||
'event_type_id==4',
|
||||
'event_type_id==91',
|
||||
)
|
||||
);
|
||||
|
||||
@ -1249,9 +1249,9 @@ final class OAuth2SummitApiTest extends ProtectedApiTest
|
||||
{
|
||||
$params = array
|
||||
(
|
||||
'id' => 6,
|
||||
'id' => 7,
|
||||
'from_date' => 1471565531,
|
||||
'limit' => 100
|
||||
'limit' => 100
|
||||
);
|
||||
|
||||
$headers = array
|
||||
@ -1278,13 +1278,13 @@ final class OAuth2SummitApiTest extends ProtectedApiTest
|
||||
$this->assertTrue(!is_null($events));
|
||||
}
|
||||
|
||||
public function testGetEntityEventsFromCurrentSummitGreaterThanGivenID()
|
||||
public function testGetEntityEventsFromCurrentSummitGreaterThanGivenID($summit_id = 7, $last_event_id = 665707)
|
||||
{
|
||||
$params = array
|
||||
(
|
||||
'id' => 6,
|
||||
'last_event_id' => 32500,
|
||||
'limit' => 100
|
||||
'id' => $summit_id,
|
||||
'last_event_id' => $last_event_id,
|
||||
'limit' => 100
|
||||
);
|
||||
|
||||
$headers = array
|
||||
@ -1312,7 +1312,7 @@ final class OAuth2SummitApiTest extends ProtectedApiTest
|
||||
|
||||
$params = array
|
||||
(
|
||||
'id' => 6,
|
||||
'id' => 6,
|
||||
'last_event_id' => 32795
|
||||
);
|
||||
|
||||
@ -1775,11 +1775,11 @@ final class OAuth2SummitApiTest extends ProtectedApiTest
|
||||
$this->assertTrue(!is_null($attendee));
|
||||
}
|
||||
|
||||
public function testCurrentSummitLocationEventsWithFilter()
|
||||
public function testCurrentSummitLocationEventsWithFilter($summit_id = 7)
|
||||
{
|
||||
$params = array
|
||||
(
|
||||
'id' => 6,
|
||||
'id' => $summit_id,
|
||||
'page' => 1,
|
||||
'per_page' => 50,
|
||||
'location_id' => 52,
|
||||
@ -2000,11 +2000,11 @@ final class OAuth2SummitApiTest extends ProtectedApiTest
|
||||
public function testGetMyMemberFromCurrentSummit()
|
||||
{
|
||||
|
||||
$params = array
|
||||
(
|
||||
'expand' => 'attendee,speaker,feedback',
|
||||
'id' => 6,
|
||||
);
|
||||
$params = [
|
||||
|
||||
'expand' => 'attendee,speaker,feedback,groups, presentations',
|
||||
'id' => 7,
|
||||
];
|
||||
|
||||
$headers = array("HTTP_Authorization" => " Bearer " . $this->access_token);
|
||||
$response = $this->action(
|
||||
|
@ -30,7 +30,7 @@ class AccessTokenServiceStub implements IAccessTokenService
|
||||
*/
|
||||
public function get($token_value)
|
||||
{
|
||||
$url = Config::get('app.url');
|
||||
$url = Config::get('app.url');
|
||||
$parts = @parse_url($url);
|
||||
$realm = $parts['host'];
|
||||
|
||||
@ -55,7 +55,7 @@ class AccessTokenServiceStub implements IAccessTokenService
|
||||
$url . '/teams/write',
|
||||
);
|
||||
|
||||
return AccessToken::createFromParams('123456789', implode(' ', $scopes), '1', $realm, '1','13867', 3600, 'WEB_APPLICATION', '', '');
|
||||
return AccessToken::createFromParams('123456789', implode(' ', $scopes), '1', $realm, '1','11624', 3600, 'WEB_APPLICATION', '', '');
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user