Example #1
0
 /**
  * @todo: docs
  */
 public function get_comments(array $args)
 {
     if ($args['type'] != 1) {
         throw new midgardmvc_exception_notfound("Only CONTENT type supported");
     }
     $cnt = 0;
     $package = new com_meego_package();
     $ocs = new com_meego_ocs_OCSWriter();
     try {
         $package->get_by_id((int) $args['contentid1']);
     } catch (midgard_error_exception $e) {
         $error = true;
         $this->mvc->log(__CLASS__, 'Probably missing package with id:  ' . $args['contentid1'] . '.', 'warning');
         $ocs->writeError('Package not found', 101);
         $ocs->endDocument();
         self::output_xml($ocs);
     }
     $storage = new midgard_query_storage('com_meego_package_ratings');
     $q = new midgard_query_select($storage);
     $qc = new midgard_query_constraint_group('AND');
     $qc->add_constraint(new midgard_query_constraint(new midgard_query_property('authorguid'), '<>', new midgard_query_value('')));
     $qc->add_constraint(new midgard_query_constraint(new midgard_query_property('name'), '=', new midgard_query_value($package->name)));
     $q->set_constraint($qc);
     $q->add_order(new midgard_query_property('posted', $storage), SORT_ASC);
     // First run a query of the whole set to get results count
     $q->execute();
     $cnt = $q->get_results_count();
     list($limit, $offset) = $this->limit_and_offset_from_query();
     $q->set_limit($limit);
     $q->set_offset($offset);
     $q->execute();
     $comments = $q->list_objects();
     foreach ($comments as $comment) {
         if ($comment->commentid == 0 && !$this->mvc->configuration->show_ratings_without_comments) {
             // skip the rating if it has no comment and the configuration excludes such ratings
             --$cnt;
         }
     }
     $ocs->writeMeta($cnt);
     $ocs->startElement('data');
     // todo: again this loop..  a bit redundant, but works for now
     foreach ($comments as $comment) {
         if ($comment->commentid == 0 && !$this->mvc->configuration->show_ratings_without_comments) {
             // skip the rating if it has no comment and the configuration excludes such ratings
             continue;
         }
         $this->comment_to_ocs($comment, $ocs);
     }
     $ocs->endElement();
     $ocs->endDocument();
     self::output_xml($ocs);
 }
Example #2
0
 /**
  * Returns "dependencies", ie. various UXes (User Experiences)
  *
  * @param array HTTP GET args
  */
 public function get_dependencies(array $args)
 {
     $q = new midgard_query_select(new midgard_query_storage('com_meego_ux'));
     $q->execute();
     $total = $q->get_results_count();
     $query = $this->request->get_query();
     if (array_key_exists('pagesize', $query) && strlen($query['pagesize'])) {
         $this->pagesize = $query['pagesize'];
     }
     $q->set_limit($this->pagesize);
     $page = 0;
     if (array_key_exists('page', $query) && strlen($query['page'])) {
         $page = $query['page'];
     }
     $offset = $page * $this->pagesize;
     $q->set_offset($offset);
     if ($offset > $total) {
         $offset = $total - $this->pagesize;
     }
     // 2nd execute to limit pagesize
     $q->execute();
     $ocs = new com_meego_ocs_OCSWriter();
     $ocs->writeMeta($total, $this->pagesize);
     $ocs->writeDependencies($q->list_objects());
     $ocs->endDocument();
     self::output_xml($ocs);
 }