Fix on moderators
Fix on moderator serialization and queries Change-Id: Iaf765be43a02101da6395bd655a4299907251e66
This commit is contained in:
parent
c34ef254b7
commit
f7a6f04891
@ -11,6 +11,8 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
**/
|
**/
|
||||||
|
use models\summit\Presentation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class PresentationSerializer
|
* Class PresentationSerializer
|
||||||
* @package ModelSerializers
|
* @package ModelSerializers
|
||||||
@ -54,10 +56,12 @@ class PresentationSerializer extends SummitEventSerializer
|
|||||||
{
|
{
|
||||||
if(!count($relations)) $relations = $this->getAllowedRelations();
|
if(!count($relations)) $relations = $this->getAllowedRelations();
|
||||||
|
|
||||||
$values = parent::serialize($expand, $fields, $relations, $params);
|
|
||||||
|
|
||||||
$presentation = $this->object;
|
$presentation = $this->object;
|
||||||
|
|
||||||
|
if(!$presentation instanceof Presentation) return [];
|
||||||
|
|
||||||
|
$values = parent::serialize($expand, $fields, $relations, $params);
|
||||||
|
|
||||||
if(in_array('speakers', $relations)) {
|
if(in_array('speakers', $relations)) {
|
||||||
$values['speakers'] = $presentation->getSpeakerIds();
|
$values['speakers'] = $presentation->getSpeakerIds();
|
||||||
}
|
}
|
||||||
@ -104,6 +108,9 @@ class PresentationSerializer extends SummitEventSerializer
|
|||||||
$speakers[] = SerializerRegistry::getInstance()->getSerializer($s)->serialize();
|
$speakers[] = SerializerRegistry::getInstance()->getSerializer($s)->serialize();
|
||||||
}
|
}
|
||||||
$values['speakers'] = $speakers;
|
$values['speakers'] = $speakers;
|
||||||
|
if(isset($values['moderator_speaker_id']) && intval($values['moderator_speaker_id']) > 0 ){
|
||||||
|
$values['moderator'] = SerializerRegistry::getInstance()->getSerializer($presentation->getModerator())->serialize();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,8 @@
|
|||||||
**/
|
**/
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Config;
|
use Illuminate\Support\Facades\Config;
|
||||||
|
use models\summit\Presentation;
|
||||||
|
use models\summit\PresentationSpeaker;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class PresentationSpeakerSerializer
|
* Class PresentationSpeakerSerializer
|
||||||
@ -44,13 +46,18 @@ class PresentationSpeakerSerializer extends SilverStripeSerializer
|
|||||||
*/
|
*/
|
||||||
public function serialize($expand = null, array $fields = array(), array $relations = array(), array $params = array() )
|
public function serialize($expand = null, array $fields = array(), array $relations = array(), array $params = array() )
|
||||||
{
|
{
|
||||||
if(!count($relations)) $relations = $this->getAllowedRelations();
|
if(!count($relations)) $relations = $this->getAllowedRelations();
|
||||||
$values = parent::serialize($expand, $fields, $relations, $params);
|
|
||||||
$speaker = $this->object;
|
$speaker = $this->object;
|
||||||
$summit_id = isset($params['summit_id'])? intval($params['summit_id']):null;
|
if(!$speaker instanceof PresentationSpeaker) return [];
|
||||||
$published = isset($params['published'])? intval($params['published']):true;
|
|
||||||
$values['presentations'] = $speaker->getPresentationIds($summit_id, $published);
|
$values = parent::serialize($expand, $fields, $relations, $params);
|
||||||
$values['pic'] = Config::get("server.assets_base_url", 'https://www.openstack.org/') . 'profile_images/speakers/' . $speaker->getId();
|
|
||||||
|
$summit_id = isset($params['summit_id'])? intval($params['summit_id']):null;
|
||||||
|
$published = isset($params['published'])? intval($params['published']):true;
|
||||||
|
$values['presentations'] = $speaker->getPresentationIds($summit_id, $published);
|
||||||
|
$values['moderated_presentations'] = $speaker->getModeratedPresentationIds($summit_id, $published);
|
||||||
|
$values['pic'] = Config::get("server.assets_base_url", 'https://www.openstack.org/') . 'profile_images/speakers/' . $speaker->getId();
|
||||||
|
|
||||||
if (in_array('member', $relations) && $speaker->hasMember())
|
if (in_array('member', $relations) && $speaker->hasMember())
|
||||||
{
|
{
|
||||||
@ -77,11 +84,17 @@ class PresentationSpeakerSerializer extends SilverStripeSerializer
|
|||||||
foreach (explode(',', $expand) as $relation) {
|
foreach (explode(',', $expand) as $relation) {
|
||||||
switch (trim($relation)) {
|
switch (trim($relation)) {
|
||||||
case 'presentations': {
|
case 'presentations': {
|
||||||
$presentations = array();
|
$presentations = [];
|
||||||
foreach ($speaker->getPresentations() as $p) {
|
foreach ($speaker->getPresentations($summit_id, $published) as $p) {
|
||||||
$presentations[] = SerializerRegistry::getInstance()->getSerializer($p)->serialize();
|
$presentations[] = SerializerRegistry::getInstance()->getSerializer($p)->serialize();
|
||||||
}
|
}
|
||||||
$values['presentations'] = $presentations;
|
$values['presentations'] = $presentations;
|
||||||
|
|
||||||
|
$moderated_presentations = [];
|
||||||
|
foreach ($speaker->getModeratedPresentation($summit_id, $published) as $p) {
|
||||||
|
$moderated_presentations[] = SerializerRegistry::getInstance()->getSerializer($p)->serialize();
|
||||||
|
}
|
||||||
|
$values['moderated_presentations'] = $presentations;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -168,10 +168,16 @@ class PresentationSpeaker extends SilverstripeBaseModel
|
|||||||
*/
|
*/
|
||||||
private $presentations;
|
private $presentations;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\OneToMany(targetEntity="Presentation", mappedBy="moderator", cascade={"persist"})
|
||||||
|
*/
|
||||||
|
private $moderated_presentations;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this->presentations = new ArrayCollection;
|
$this->presentations = new ArrayCollection;
|
||||||
|
$this->moderated_presentations = new ArrayCollection;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -197,6 +203,22 @@ class PresentationSpeaker extends SilverstripeBaseModel
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param null|int $summit_id
|
||||||
|
* @param bool|true $published_ones
|
||||||
|
* @return Presentation[]
|
||||||
|
*/
|
||||||
|
public function moderated_presentations($summit_id, $published_ones = true)
|
||||||
|
{
|
||||||
|
|
||||||
|
return $this->moderated_presentations
|
||||||
|
->filter(function($p) use($published_ones, $summit_id){
|
||||||
|
$res = $published_ones? $p->isPublished(): true;
|
||||||
|
$res &= is_null($summit_id)? true : $p->getSummit()->getId() == $summit_id;
|
||||||
|
return $res;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $presentation_id
|
* @param int $presentation_id
|
||||||
* @return Presentation
|
* @return Presentation
|
||||||
@ -205,6 +227,7 @@ class PresentationSpeaker extends SilverstripeBaseModel
|
|||||||
{
|
{
|
||||||
return $this->presentations->get($presentation_id);
|
return $this->presentations->get($presentation_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param null $summit_id
|
* @param null $summit_id
|
||||||
* @param bool|true $published_ones
|
* @param bool|true $published_ones
|
||||||
@ -217,6 +240,43 @@ class PresentationSpeaker extends SilverstripeBaseModel
|
|||||||
})->toArray();
|
})->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param null $summit_id
|
||||||
|
* @param bool|true $published_ones
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getPresentations($summit_id, $published_ones = true)
|
||||||
|
{
|
||||||
|
return $this->presentations($summit_id, $published_ones)->map(function($entity) {
|
||||||
|
return $entity;
|
||||||
|
})->toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param null $summit_id
|
||||||
|
* @param bool|true $published_ones
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getModeratedPresentationIds($summit_id, $published_ones = true)
|
||||||
|
{
|
||||||
|
return $this->moderated_presentations($summit_id, $published_ones)->map(function($entity) {
|
||||||
|
return $entity->getId();
|
||||||
|
})->toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param null $summit_id
|
||||||
|
* @param bool|true $published_ones
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getModeratedPresentations($summit_id, $published_ones = true)
|
||||||
|
{
|
||||||
|
return $this->moderated_presentations($summit_id, $published_ones)->map(function($entity) {
|
||||||
|
return $entity;
|
||||||
|
})->toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\ManyToOne(targetEntity="models\main\File")
|
* @ORM\ManyToOne(targetEntity="models\main\File")
|
||||||
|
@ -673,25 +673,13 @@ class Summit extends SilverstripeBaseModel
|
|||||||
*/
|
*/
|
||||||
private function buildModeratorsQuery()
|
private function buildModeratorsQuery()
|
||||||
{
|
{
|
||||||
$query = <<<SQL
|
return $this->createQueryBuilder()
|
||||||
SELECT DISTINCT p0_.FirstName , p0_.LastName,
|
->select('distinct ps')
|
||||||
p0_.Title , p0_.Bio , p0_.IRCHandle,
|
->from('models\summit\PresentationSpeaker','ps')
|
||||||
p0_.TwitterName ,
|
->join('ps.moderated_presentations','p')
|
||||||
p0_.ID , p0_.Created, p0_.LastEdited,
|
->join('p.summit','s')
|
||||||
p0_.PhotoID,
|
->where("s.id = :summit_id and p.published = 1")
|
||||||
p0_.MemberID
|
->setParameter('summit_id', $this->getId());
|
||||||
FROM PresentationSpeaker p0_
|
|
||||||
|
|
||||||
WHERE p0_.ID IN (
|
|
||||||
SELECT Presentation.ModeratorID FROM Presentation INNER JOIN SummitEvent ON SummitEvent.ID = Presentation.ID
|
|
||||||
WHERE SummitID = {$this->getId()} AND Published = 1
|
|
||||||
)
|
|
||||||
SQL;
|
|
||||||
$rsm = new ResultSetMappingBuilder($this->getEM());
|
|
||||||
$rsm->addRootEntityFromClassMetadata(\models\summit\PresentationSpeaker::class, 's', []);
|
|
||||||
// build rsm here
|
|
||||||
$native_query = $this->getEM()->createNativeQuery($query, $rsm);
|
|
||||||
return $native_query;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -712,7 +700,7 @@ SQL;
|
|||||||
*/
|
*/
|
||||||
public function getSpeakers(){
|
public function getSpeakers(){
|
||||||
// moderators
|
// moderators
|
||||||
$moderators = $this->buildModeratorsQuery()->getResult();
|
$moderators = $this->buildModeratorsQuery()->getQuery()->getResult();
|
||||||
// get moderators ids to exclude from speakers
|
// get moderators ids to exclude from speakers
|
||||||
$moderators_ids = array();
|
$moderators_ids = array();
|
||||||
foreach($moderators as $m){
|
foreach($moderators as $m){
|
||||||
|
@ -686,8 +686,9 @@ final class OAuth2SummitApiTest extends ProtectedApiTest
|
|||||||
public function testGetEvent(){
|
public function testGetEvent(){
|
||||||
$params = array
|
$params = array
|
||||||
(
|
(
|
||||||
'id' => 6,
|
'id' => 7,
|
||||||
'event_id' => 6838,
|
'event_id' => 15303,
|
||||||
|
'expand' => 'speakers',
|
||||||
);
|
);
|
||||||
|
|
||||||
$headers = array
|
$headers = array
|
||||||
|
Loading…
x
Reference in New Issue
Block a user