Exemple #1
0
 /**
  * Returns an array of posted forms that belong to the given package.
  * Each element of the array is appended with submitter info as well
  * as some css styling helper (odd or even row), and a local url where
  * the form can be viewed by admins.
  *
  * @param guid GUID of the package
  * @param integer number of the page
  *                Items shown on one page is configurable;
  *                see: defaults.yml
  *
  * @return array of com_meego_package_forms_posted objects
  */
 public function get_posted_forms($package_guid = null, $page = 1)
 {
     $cnt = 0;
     $retval = array();
     $retval['forms'] = null;
     $retval['previous_page'] = 1;
     $retval['next_page'] = 1;
     // @todo: maybe do a GUID check here?
     if (!$package_guid) {
         return $retval;
     }
     $posts = self::get_all_forms($package_guid);
     if (is_array($posts) && count($posts)) {
         $total = count($posts);
         $limit = $this->mvc->configuration->rows_per_page * $this->mvc->configuration->items_per_row;
         $paged_posts = com_meego_packages_pager::page($limit, $page, $posts);
         $retval['total'] = $total;
         $retval['items_shown'] = $paged_posts['items_shown'];
         $retval['previous_page'] = $paged_posts['previous_page'];
         $retval['next_page'] = $paged_posts['next_page'];
         foreach ($paged_posts['content'] as $post) {
             ++$cnt % 2 == 0 ? $post->rawclass = 'even' : ($post->rawclass = 'odd');
             $post->localurl = $this->mvc->dispatcher->generate_url('package_posted_form_instance', array('forminstance' => $post->forminstanceguid), $this->request);
             $post->submitter = "n/a";
             // get the login name for the submitter
             $user = com_meego_packages_utils::get_user_by_person_guid($post->submitterguid);
             if ($user) {
                 $post->submitter = $user->login;
             }
             if (!isset($retval['forms'][$post->formtitle]['title'])) {
                 $retval['forms'][$post->formtitle]['title'] = $post->formtitle;
             }
             $retval['forms'][$post->formtitle]['posts'][$post->forminstanceguid] = $post;
         }
     }
     return $retval;
 }
 /**
  * retreives a form instance
  */
 public function get_posted_form_instance(array $args)
 {
     $forminstance = new midgardmvc_ui_forms_form_instance($args['forminstance']);
     $form = new midgardmvc_ui_forms_form($forminstance->form);
     // get user info
     $currentuser = com_meego_packages_utils::get_current_user();
     $formcreator = com_meego_packages_utils::get_user_by_person_guid($forminstance->metadata->creator);
     $form_to_return = midgardmvc_ui_forms_load::load_form(midgardmvc_ui_forms_generator::get_by_guid($form->guid), $forminstance);
     $form_to_return->set_readonly(true);
     if ($currentuser) {
         if ($forminstance->metadata->creator == $currentuser->person) {
             $form_to_return->set_readonly(false);
         }
     }
     $login = '******';
     if ($formcreator) {
         $login = $formcreator->login;
     }
     $this->data['title'] = $form->title . " submitted by " . $login;
     $this->data['form'] = $form_to_return;
     unset($form_to_return);
 }
 /**
  * Retrieves all ratings belonging to the object having the guid: $this->data['to'].
  *
  * Passes all ratings to the view ($this->data['ratings']).
  * Calculates the average rating and passes that to the view too ($this->data['average']).
  * Sets the rated flag ($this->data['rated']) to show if object was ever rated or not.
  * Sets the can_post flag ($this->data['can_post']), so that the view can determine
  * whether to show a POST form or not.
  *
  * @param array arguments
  */
 public function get_ratings(array $args)
 {
     $this->get_average($args);
     if (midgardmvc_core::get_instance()->authentication->is_user()) {
         $this->data['can_post'] = true;
     } else {
         $this->data['can_post'] = false;
     }
     // @todo: can't add elements to head from here.. why?
     // Enable jQuery in case it is not enabled yet
     midgardmvc_core::get_instance()->head->enable_jquery();
     // Add rating CSS
     $css = array('href' => MIDGARDMVC_STATIC_URL . '/com_meego_ratings/js/jquery.rating/jquery.rating.css', 'rel' => 'stylesheet');
     midgardmvc_core::get_instance()->head->add_link($css);
     // Add rating js
     midgardmvc_core::get_instance()->head->add_jsfile(MIDGARDMVC_STATIC_URL . '/com_meego_ratings/js/jquery.rating/jquery.rating.pack.js', true);
     $this->data['to'] = midgard_object_class::get_object_by_guid($args['to']);
     $storage = new midgard_query_storage('com_meego_ratings_rating_author');
     $q = new midgard_query_select($storage);
     $q->set_constraint(new midgard_query_constraint(new midgard_query_property('to'), '=', new midgard_query_value($this->data['to']->guid)));
     $q->add_order(new midgard_query_property('posted'), SORT_DESC);
     $q->execute();
     $ratings = $q->list_objects();
     $this->data['ratings'] = array();
     if (count($ratings)) {
         $this->data['rated'] = true;
         foreach ($ratings as $rating) {
             $rating->stars = '';
             // get comment if available
             if ($rating->ratingcomment) {
                 $comment = new com_meego_comments_comment($rating->ratingcomment);
                 $rating->ratingcommentcontent = $comment->content;
             }
             // add a new property containing the stars to the rating object
             $rating->stars = $this->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) {
                 // 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->avatar = com_meego_packages_utils::get_avatar($user->login);
                         $rating->avatarurl = midgardmvc_core::get_instance()->configuration->user_profile_prefix . $user->login;
                     } catch (Exception $e) {
                         // no avatar
                     }
                 }
             }
             array_push($this->data['ratings'], $rating);
         }
     }
 }
Exemple #4
0
 /**
  * @todo: docs
  */
 private function comment_to_ocs(com_meego_package_ratings $rating, com_meego_ocs_OCSWriter $ocs)
 {
     $ocs->startElement('comment');
     $ocs->writeElement('id', $rating->commentid);
     $ocs->writeElement('subject', $rating->version . ':' . $rating->title);
     $ocs->writeElement('text', $rating->comment);
     // todo: no support of subcomments yet
     $userid = '';
     $user = com_meego_packages_utils::get_user_by_person_guid($rating->authorguid);
     if ($user) {
         $userid = $user->login;
     }
     $ocs->writeElement('user', $userid);
     $ocs->writeElement('date', $rating->posted->format('c'));
     $ocs->writeElement('score', $rating->rating);
     $ocs->endElement();
 }
Exemple #5
0
 /**
  * Creates an account
  */
 private function create_account(array $ldapuser, array $tokens)
 {
     $user = null;
     $person = null;
     midgardmvc_core::get_instance()->authorization->enter_sudo('midgardmvc_core');
     $transaction = new midgard_transaction();
     $transaction->begin();
     $persons = $this->get_persons($ldapuser);
     if (count($persons) == 0) {
         $person = $this->create_person($ldapuser, $tokens);
     } else {
         // we have multiple persons with the same firstname and lastname
         // let's see the corresponding midgard_user object and its login field
         foreach ($persons as $person) {
             $user = com_meego_packages_utils::get_user_by_person_guid($person->guid);
             if ($user->login == $tokens['login']) {
                 break;
             } else {
                 $user = null;
                 $person = null;
             }
         }
     }
     if (!$user) {
         if (!$person) {
             $person = $this->create_person($ldapuser, $tokens);
         }
         if ($person) {
             $user = new midgard_user();
             $user->login = $tokens['login'];
             $user->password = '';
             $user->usertype = 1;
             $user->authtype = 'LDAP';
             $user->active = true;
             $user->set_person($person);
             if (!$user->create()) {
                 midgardmvc_core::get_instance()->log(__CLASS__, "Creating midgard_user for LDAP user failed: " . midgard_connection::get_instance()->get_error_string(), 'warning');
                 $transaction->rollback();
                 midgardmvc_core::get_instance()->authorization->leave_sudo();
                 return false;
             }
         }
     }
     midgardmvc_core::get_instance()->authorization->leave_sudo();
     if (!$transaction->commit()) {
         return false;
     }
     return true;
 }
 /**
  * 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;
 }