/** * Sets $this->data['stars'] with an HTML snippet showing the stars */ public function get_stars($rating) { parent::get_stars($rating); $this->data['stars'] .= ' (' . $this->data['numberofratings'] . ')'; }
/** * Gathers ratings and appends them to data * * @param guid of the package * @return array of ratings together with their comments */ public function prepare_ratings($package_guid) { $retval = array(); $storage = new midgard_query_storage('com_meego_package_ratings'); $q = new midgard_query_select($storage); $q->set_constraint(new midgard_query_constraint(new midgard_query_property('guid'), '=', new midgard_query_value($package_guid))); $q->add_order(new midgard_query_property('posted', $storage), SORT_DESC); $q->execute(); $ratings = $q->list_objects(); foreach ($ratings as $rating) { $rating->stars = ''; if ($rating->rating || $rating->commentid) { // add a new property containing the stars to the rating object $rating->stars = com_meego_ratings_controllers_rating::draw_stars($rating->rating); // pimp the posted date $rating->date = gmdate('Y-m-d H:i e', strtotime($rating->posted)); // avatar part $rating->avatar = false; if ($rating->authorguid) { $username = null; // get the midgard user name from rating->authorguid $user = com_meego_packages_utils::get_user_by_person_guid($rating->authorguid); if ($user) { $username = $user->login; if ($username && $username != 'admin') { // get avatar and url to user profile page only if the user is not the midgard admin try { $rating->avatar = com_meego_packages_utils::get_avatar($username); $rating->avatarurl = $this->mvc->configuration->user_profile_prefix . $username; } catch (Exception $e) { // no avatar } } } } } array_push($retval, $rating); } unset($ratings); return $retval; }
/** * Gathers ratings and appends them to data * * @param string title of the application * @param boolean flag to override show_ratings_without_comments configuration * * @return array of ratings together with their comments */ public function prepare_ratings($application_name = null, $flag = false) { // the array to be returned // the comment flag is set to tru when the 1st comment found // this will help the template to display some headinhs only if needed $retval = array('ratings' => array(), 'comment' => false); // relocate url after editing or deleting a comment by admins $relocate = 'relocate=' . $this->mvc->context->get_request(0)->get_path(); $this->isadmin = false; $this->isuser = $this->mvc->authentication->is_user(); if ($this->isuser) { $this->isadmin = $this->mvc->authentication->get_user()->is_admin(); } $storage = new midgard_query_storage('com_meego_package_ratings'); $q = new midgard_query_select($storage); $q->set_constraint(new midgard_query_constraint(new midgard_query_property('name'), '=', new midgard_query_value($application_name))); $q->add_order(new midgard_query_property('posted', $storage), SORT_DESC); $q->execute(); $ratings = $q->list_objects(); if (count($ratings)) { foreach ($ratings as $rating) { $rating->show = true; if (!$rating->commentid && !$this->mvc->configuration->show_ratings_without_comments && !$flag) { $rating->show = false; array_push($retval, $rating); continue; } $rating->stars = ''; if ($rating->rating || $rating->commentid) { if ($rating->commentid) { $retval['comment'] = true; if ($this->isadmin) { try { $_comment = new com_meego_comments_comment($rating->commentid); } catch (Exception $e) { // the comment object was probably deleted, not a big deal } if (isset($_comment)) { $rating->edit_comment_url = $this->mvc->dispatcher->generate_url('comment_update', array('comment' => $_comment->guid), 'com_meego_comments'); $rating->edit_comment_url .= '?' . $relocate; $rating->delete_comment_url = $this->mvc->dispatcher->generate_url('comment_delete', array('comment' => $_comment->guid), 'com_meego_comments'); $rating->delete_comment_url .= '?' . $relocate; unset($_comment); } } } if ($rating->rating) { // add a new property containing the stars to the rating object $rating->stars = com_meego_ratings_controllers_rating::draw_stars($rating->rating); } // pimp the posted date $rating->date = gmdate('Y-m-d H:i e', strtotime($rating->posted)); // avatar part $rating->avatar = false; if ($rating->authorguid) { $rating->user = '******'; $username = null; // get the midgard user name from rating->authorguid $user = com_meego_packages_utils::get_user_by_person_guid($rating->authorguid); if ($user && $user->login != 'admin') { // get avatar and url to user profile page only if the user is not the midgard admin try { $rating->user = $user->login; $rating->avatar = com_meego_packages_utils::get_avatar($user->login); $rating->avatarurl = $this->mvc->configuration->user_profile_prefix . $user->login; } catch (Exception $e) { // no avatar } } } } array_push($retval['ratings'], $rating); } unset($ratings); } return $retval; }