/** * @access public * @return void * @param int[] $a_ids * @desc Read from the db the comments for the supplied review item */ public function ReadCommentsForReviewItem(ReviewItem $review_item) { $s_person = $this->GetSettings()->GetTable('User'); $s_message = $this->GetSettings()->GetTable('ForumMessage'); # prepare command $s_sql = 'SELECT ' . $s_person . '.user_id, ' . $s_person . '.known_as, ' . 'location, ' . $s_person . ".date_added AS sign_up_date, " . $s_person . '.total_messages, ' . $s_message . '.id, ' . $s_message . '.message, ' . $s_message . ".date_added AS message_date " . 'FROM ' . $s_message . ' INNER JOIN ' . $s_person . ' ON ' . $s_message . '.user_id = ' . $s_person . '.user_id ' . 'WHERE ' . $s_message . '.item_id = ' . Sql::ProtectNumeric($review_item->GetId(), false, false) . ' AND item_type = ' . Sql::ProtectNumeric($review_item->GetType(), false, false); if ($this->GetReverseOrder()) { $s_sql .= ' ORDER BY sort_override DESC, ' . $s_message . '.date_added DESC'; } else { $s_sql .= ' ORDER BY sort_override, ' . $s_message . '.date_added ASC'; } # get data $result = $this->GetDataConnection()->query($s_sql); $this->Clear(); $o_topic = new ForumTopic($this->GetSettings()); while ($o_row = $result->fetch()) { $o_person = new User(); $o_person->SetId($o_row->user_id); $o_person->SetName($o_row->known_as); $o_person->SetSignUpdate($o_row->sign_up_date); $o_person->SetLocation($o_row->location); $o_person->SetTotalMessages($o_row->total_messages); $o_message = new ForumMessage($this->GetSettings(), AuthenticationManager::GetUser()); $o_message->SetId($o_row->id); $o_message->SetDate($o_row->message_date); $o_message->SetBody($o_row->message); $o_message->SetUser($o_person); $o_message->SetReviewItem($review_item); $o_topic->Add($o_message); } $this->Add($o_topic); $result->closeCursor(); }
/** * Populates the collection of business objects from raw data * * @return bool * @param MySqlRawData $result */ protected function BuildItems(MySqlRawData $result) { $this->Clear(); # use CollectionBuilder to handle duplicates $user_builder = new CollectionBuilder(); $roles = new CollectionBuilder(); $role_class_loaded = false; $user = null; while ($row = $result->fetch()) { # check whether this is a new person if (!$user_builder->IsDone($row->user_id)) { # store any exisiting person if ($user != null) { $this->Add($user); $roles->Reset(); } # create the new person $user = new User(); $user->SetId($row->user_id); $user->SetName($row->known_as); if (isset($row->name_first)) { $user->SetFirstName($row->name_first); } if (isset($row->name_last)) { $user->SetLastName($row->name_last); } if (isset($row->email)) { $user->SetEmail($row->email); } if (isset($row->gender)) { $user->SetGender($row->gender); } if (isset($row->occupation)) { $user->SetOccupation($row->occupation); } if (isset($row->interests)) { $user->SetInterests($row->interests); } if (isset($row->location)) { $user->SetLocation($row->location); } if (isset($row->sign_up_date)) { $user->SetSignUpDate($row->sign_up_date); } if (isset($row->total_messages)) { $user->SetTotalMessages($row->total_messages); } if (isset($row->disabled)) { $user->SetAccountDisabled($row->disabled); } } # Add security roles if (isset($row->role_id) and !$roles->IsDone($row->role_id)) { if (!$role_class_loaded) { require_once "authentication/role.class.php"; $role_class_loaded = true; } $role = new Role($row->role_id, $row->role); $user->Roles()->Add($role); } } # store final person if ($user != null) { $this->Add($user); } }