/**
  * Gets presentations, ordered in a persistent random fashion
  *         
  * @return DataList
  */
 public function getRandomisedPresentations($category_id = null, $summit = null)
 {
     $mid = Member::currentUserID();
     if (!$summit) {
         $summit = Summit::get_active();
     }
     $priority = $this->owner->VotingList();
     if (!$priority->exists() || $priority->SummitID != $summit->ID) {
         $priority = PresentationRandomVotingList::get()->filter('SummitID', $summit->ID)->sort('RAND()')->first();
         if (!$priority) {
             return false;
         }
         $this->owner->VotingListID = $priority->ID;
         $this->owner->write();
     }
     $list = $priority->getPriorityList();
     if (!count($list)) {
         return false;
     }
     $presentations = $summit->VoteablePresentations()->sort("FIND_IN_SET(Presentation.ID, '" . implode(',', $list) . "')");
     if (!empty($category_id) && intval($category_id) > 0) {
         $presentations = $presentations->filter('CategoryID', $category_id);
     }
     return $presentations;
 }
Пример #2
0
 public function generateVotingLists()
 {
     DB::query("DELETE FROM PresentationRandomVotingList");
     $i = 0;
     while ($i < self::config()->random_voting_list_count) {
         $list = PresentationRandomVotingList::create(['SummitID' => $this->ID]);
         $list->setSequence($this->VoteablePresentations()->sort('RAND()')->column('ID'));
         $list->write();
         $i++;
     }
 }
 public function testSummitVotingListIdempotence()
 {
     $s = Summit::get_active();
     $s->generateVotingLists();
     $s->generateVotingLists();
     $this->assertEquals($s->config()->random_voting_list_count, PresentationRandomVotingList::get()->count());
     $member = $this->objFromFixture('Member', 'unclecheese');
     $member->flushCache();
     $member->getRandomisedPresentations(null, $s);
     $this->assertTrue($member->VotingList()->exists());
     $oldID = $member->VotingListID;
     $s->generateVotingLists();
     $member->flushCache();
     $member->getRandomisedPresentations(null, $s);
     $this->assertNotEquals($oldID, $member->VotingListID);
 }