Exemple #1
0
 protected function loadEntity(array $data)
 {
     if ($status = parent::loadEntity($data)) {
         // get latest post timestamp (if any)
         $query = "SELECT UNIX_TIMESTAMP(MAX( p.create_time )) AS ts\nFROM groups AS g, forums_threads AS t, forums_posts AS p\nWHERE g.id = " . $this->id . "\nAND g.id = t.IdGroup\nAND t.last_postid = p.id";
         if ($result = $this->dao->query($query)) {
             $timestamp = $result->fetch(PDB::FETCH_OBJ);
             $this->latestPost = $timestamp->ts;
         } else {
             $this->latestPost = 0;
         }
     }
     return $status;
 }
Exemple #2
0
 /**
  * overloads RoxEntityBase::loadEntity to load related data
  *
  * @param array $data
  *
  * @access protected
  * @return bool
  */
 protected function loadEntity(array $data)
 {
     if ($status = parent::loadEntity($data)) {
         $query = "SELECT * FROM blog_data WHERE blog_id = {$this->getPKValue()}";
         if ($result = $this->dao->query($query)) {
             $block = $result->fetch(PDB::FETCH_ASSOC);
             foreach ($block as $key => $value) {
                 if ($key != 'blog_id') {
                     $this->{$key} = $value;
                 }
             }
         }
     }
     return $status;
 }
 /**
  * overloads RoxEntityBase::loadEntity to load related data
  *
  * @param array $data
  *
  * @access protected
  * @return bool
  */
 protected function loadEntity(array $data)
 {
     if ($status = parent::loadEntity($data)) {
         $entityFactory = new RoxEntityFactory();
         $this->creator = $entityFactory->create('Member', $this->createdBy);
         if ($this->modifiedBy) {
             $this->modifier = $entityFactory->create('Member', $this->modifiedBy);
         }
         if ($this->deletedBy) {
             $this->deleter = $entityFactory->create('Member', $this->deletedBy);
         }
         if ($this->mutuallyExclusiveWith) {
             if ($this->mutuallyExclusiveWith == 'None') {
                 $this->mutuallyExclusive = array();
             } else {
                 $this->mutuallyExclusive = explode(',', $this->mutuallyExclusiveWith);
             }
         } else {
             $this->mutuallyExclusive = 'All';
         }
         // fetch rank votes for this option
         $query = "\n                SELECT\n                    SUM(vote) as sumVotes\n                FROM\n                    suggestions_option_ranks\n                WHERE\n                    optionid = " . $this->id . "\n                GROUP BY\n                    optionid\n                ";
         $this->rankVotes = 0;
         $sql = $this->dao->query($query);
         if ($sql) {
             $row = $sql->fetch(PDB::FETCH_OBJ);
             if ($row) {
                 $this->rankVotes = $row->sumVotes;
             }
         }
         // if member already ranked on this option get that as well
         $member = $this->getLoggedInMember();
         if ($member) {
             $hash = hash_hmac('sha256', $member->id, $this->id);
             $query = "SELECT vote FROM suggestions_option_ranks WHERE optionid = " . $this->id . " AND memberHash = '" . $hash . "'";
             $sql = $this->dao->query($query);
             if ($sql) {
                 $row = $sql->fetch(PDB::FETCH_OBJ);
                 if ($row) {
                     $this->vote = $row->vote;
                 }
             }
         }
     }
     return $status;
 }
 /**
  * overloads RoxEntityBase::loadEntity to load related data
  *
  * @param array $data
  *
  * @access protected
  * @return bool
  */
 protected function loadEntity(array $data)
 {
     if ($status = parent::loadEntity($data)) {
         // split date and time for start and end
         $startdatetime = strtotime($this->dateTimeStart);
         $this->dateStart = date('d.m.Y', $startdatetime);
         $this->timeStart = date('H:i', $startdatetime);
         $enddatetime = strtotime($this->dateTimeEnd);
         $this->dateEnd = date('d.m.Y', $enddatetime);
         $this->timeEnd = date('H:i', $enddatetime);
         // get organizers
         $query = "\n                SELECT\n                    a.*,\n                    m.Username\n                FROM\n                    activitiesattendees AS a,\n                    members AS m\n                WHERE\n                    a.activityId = {$this->getPKValue()}\n                    AND a.organizer = 1\n                    AND a.attendeeId = m.Id\n                    AND m.Status IN ('Active', 'OutOfRemind')\n                ORDER BY\n                    a.status, m.Username\n                ";
         if ($result = $this->dao->query($query)) {
             $organizers = array();
             while ($organizer = $result->fetch(PDB::FETCH_OBJ)) {
                 $organizers[$organizer->attendeeId] = $organizer;
             }
             $this->organizers = $organizers;
         }
         // get attendees
         $query = "\n                SELECT\n                    a.*,\n                    m.Username\n                FROM\n                    activitiesattendees AS a,\n                    members AS m\n                WHERE\n                    a.activityId = {$this->getPKValue()}\n                    AND a.attendeeId = m.Id\n                    AND m.Status IN ('Active', 'OutOfRemind')\n                ORDER BY\n                    a.status, m.Username\n                ";
         if ($result = $this->dao->query($query)) {
             $attendees = array();
             while ($attendee = $result->fetch(PDB::FETCH_OBJ)) {
                 $attendees[$attendee->attendeeId] = $attendee;
             }
             $this->attendees = $attendees;
         }
         // location details
         $entityFactory = new RoxEntityFactory();
         $this->location = $entityFactory->create('Geo', $this->locationId);
         // get counts for yes, maybe and no attendees
         $this->attendeesYes = $this->getAttendeesCountByStatus(1);
         $this->attendeesMaybe = $this->getAttendeesCountByStatus(2);
         $this->attendeesNo = $this->getAttendeesCountByStatus(3);
     }
     return $status;
 }
 /**
  * overloads RoxEntityBase::loadEntity to load related data
  *
  * @param array $data
  *
  * @access protected
  * @return bool
  */
 protected function loadEntity(array $data)
 {
     if ($status = parent::loadEntity($data)) {
     }
     return $status;
 }
 /**
  * overloads RoxEntityBase::loadEntity to load related data
  *
  * @param array $data
  *
  * @access protected
  * @return bool
  */
 protected function loadEntity(array $data)
 {
     if ($status = parent::loadEntity($data)) {
         $entityFactory = new RoxEntityFactory();
         $this->creator = $entityFactory->create('Member', $this->createdby);
         if ($this->modifiedby) {
             $this->modifier = $entityFactory->create('Member', $this->modifiedby);
         }
         // Get options count for this suggestion (visible to all members)
         $query = 'SELECT COUNT(id) as cnt FROM suggestions_options WHERE suggestionId = ' . $this->id . ' AND deleted IS NULL';
         $sql = $this->dao->query($query);
         $row = $sql->fetch(PDB::FETCH_OBJ);
         $this->optionsVisibleCount = $row->cnt;
         // Load options for this suggestion
         $optionsWhere = "";
         $optionsFactory = $entityFactory->create('SuggestionOption');
         switch ($this->state) {
             case SuggestionsModel::SUGGESTIONS_VOTING:
                 $optionsWhere = " AND deleted IS NULL";
                 $optionsFactory->sql_order = "RAND()";
                 break;
             case SuggestionsModel::SUGGESTIONS_RANKING:
                 $optionsFactory->sql_order = "`orderHint` DESC";
                 $optionsWhere = " AND deleted IS NULL";
                 break;
             case SuggestionsModel::SUGGESTIONS_REJECTED:
                 $optionsFactory->sql_order = "`orderHint` DESC";
                 $optionsWhere = " AND deleted IS NULL";
                 break;
             case SuggestionsModel::SUGGESTIONS_IMPLEMENTED:
                 $optionsFactory->sql_order = "rank DESC, `modified` DESC";
                 $optionsWhere = " AND deleted IS NULL";
                 break;
             case SuggestionsModel::SUGGESTIONS_IMPLEMENTING:
                 $optionsFactory->sql_order = "rank DESC, `modified` DESC";
                 $optionsWhere = " AND deleted IS NULL";
                 break;
             default:
                 $optionsFactory->sql_order = "`deleted` ASC, `id` ASC";
                 break;
         }
         $this->options = $optionsFactory->FindByWhereMany('suggestionId = ' . $this->id . $optionsWhere);
         $this->exclusionsSet = false;
         foreach ($this->options as $option) {
             $this->exclusionsSet |= $option->mutuallyExclusive != 'All';
         }
         // Get number of discussion items (if thread ID != null)
         $this->posts = 0;
         if ($this->threadId) {
             $query = "SELECT COUNT(*) as count FROM forums_posts WHERE threadid = " . $this->threadId . " AND PostDeleted = 'NotDeleted'";
             $sql = $this->dao->query($query);
             if ($sql) {
                 $row = $sql->fetch(PDB::FETCH_OBJ);
                 $this->posts = $row->count;
             }
         }
         // Get number of votes
         $query = "SELECT COUNT(DISTINCT memberHash) AS count FROM suggestions_votes WHERE suggestionId = " . $this->id;
         $sql = $this->dao->query($query);
         if ($sql) {
             $row = $sql->fetch(PDB::FETCH_OBJ);
             $this->voteCount = $row->count;
         }
         // if member already voted on this suggestion get votes as well
         $member = $this->getLoggedInMember();
         if ($member) {
             $hash = hash_hmac('sha256', $member->id, $this->salt);
             $query = "SELECT * FROM suggestions_votes WHERE suggestionId = " . $this->id . " AND memberHash = '" . $hash . "' ORDER BY rank DESC";
             $sql = $this->dao->query($query);
             if ($sql) {
                 $memberVotes = array();
                 while ($row = $sql->fetch(PDB::FETCH_OBJ)) {
                     $memberVotes[$row->optionId] = $row;
                 }
                 $this->memberVotes = $memberVotes;
             }
         }
         $this->ranks = $this->getRanks();
         // check if state should be updated
         $laststatechanged = strtotime($this->laststatechanged);
         switch ($this->state) {
             case SuggestionsModel::SUGGESTIONS_DISCUSSION:
                 // in discussion for more than 10 days?
                 if (time() - $laststatechanged > SuggestionsModel::DURATION_DISCUSSION) {
                     $this->state = SuggestionsModel::SUGGESTIONS_ADD_OPTIONS;
                     $this->update(true);
                 }
                 break;
             case SuggestionsModel::SUGGESTIONS_ADD_OPTIONS:
                 // post voting starts in five days?
                 $elapsed = time() - $laststatechanged;
                 if ($elapsed > SuggestionsModel::DURATION_ADDOPTIONS - SuggestionsModel::DURATION_VOTING_STARTS) {
                     $flags = $this->flags;
                     if (!$flags || ($flags & 1) != 1) {
                         $this->postVotingStartsMessage();
                         if (!$flags) {
                             $this->flags = 1;
                         } else {
                             $this->flags = $this->flags | 1;
                         }
                         $this->update();
                     }
                 }
                 // in addoptions for more than 20 days?
                 if (time() - $laststatechanged > SuggestionsModel::DURATION_ADDOPTIONS) {
                     if (count($this->options)) {
                         $this->state = SuggestionsModel::SUGGESTIONS_VOTING;
                     } else {
                         // no options added -> rejected
                         $this->state = SuggestionsModel::SUGGESTIONS_REJECTED;
                     }
                     $this->update(true);
                 }
                 break;
             case SuggestionsModel::SUGGESTIONS_VOTING:
                 // post voting starts in five days?
                 $elapsed = time() - $laststatechanged;
                 if ($elapsed > SuggestionsModel::DURATION_VOTING - SuggestionsModel::DURATION_VOTING_STARTS) {
                     $flags = $this->flags;
                     if (!$flags || ($flags & 2) != 2) {
                         $this->postVotingEndsMessage();
                         if (!$flags) {
                             $this->flags = 2;
                         } else {
                             $this->flags = $this->flags | 2;
                         }
                         $this->update();
                     }
                 }
                 // voting open for more than 30 days?
                 if (time() - $laststatechanged > SuggestionsModel::DURATION_VOTING) {
                     $this->state = SuggestionsModel::SUGGESTIONS_RANKING;
                     $this->update(true);
                 }
                 break;
         }
         // set next state change date (only needed for open suggestions)
         switch ($this->state) {
             case SuggestionsModel::SUGGESTIONS_DISCUSSION:
                 $this->nextstatechange = date('Y-m-d', strtotime($this->laststatechanged) + SuggestionsModel::DURATION_DISCUSSION);
                 break;
             case SuggestionsModel::SUGGESTIONS_ADD_OPTIONS:
                 $this->nextstatechange = date('Y-m-d', strtotime($this->laststatechanged) + SuggestionsModel::DURATION_ADDOPTIONS);
                 break;
             case SuggestionsModel::SUGGESTIONS_VOTING:
                 $this->nextstatechange = date('Y-m-d', strtotime($this->laststatechanged) + SuggestionsModel::DURATION_VOTING);
                 break;
         }
     }
     return $status;
 }