Beispiel #1
0
 public function get_avatar(array $args)
 {
     $storage = new midgard_query_storage('midgard_user');
     $q = new midgard_query_select($storage);
     $cnstr1 = new midgard_query_constraint(new midgard_query_property('username', $storage), 'LIKE', new midgard_query_value('%' . $args['username'] . '%'));
     $q->execute();
     $cnt = $q->get_results_count();
     if ($cnt > 0) {
         $user = $q->list_objects();
         if ($user[0]) {
             $attachments = $user[0]->list_attachments();
             //Check if attachement exists
             if (count($attachments) == 0) {
                 //fetch avatar from meego.com
                 $employeenumber = $user[0]->get_person()->get_parameter('midgardmvc_core_services_authentication_ldap', 'employeenumber');
                 $attachment = $user[0]->create_attachment('meego:avatar', 'meego:avatar', 'image/png');
                 midgardmvc_helper_attachmentserver::copy_file_to_attachment('http://meego.com/sites/all/files/imagecache/user_pics/user_pics/picture-' . $employeenumber . '.png', $attachment);
                 $attachments[0] = $attachment;
             }
             if (count($attachments) > 0) {
                 //serve attachment
                 $this->serve_attachement($attachments[0]);
                 return;
             }
         }
     }
     //redirect to default avatar
     midgardmvc_core::get_instance()->head->relocate('http://meego.com/sites/all/themes/meego/images/peep_skate.png');
 }
Beispiel #2
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);
 }
Beispiel #3
0
 private function populateChildren()
 {
     if (!is_null($this->children)) {
         return;
     }
     $q = new \midgard_query_select(new \midgard_query_storage('midgardmvc_core_node'));
     $q->set_constraint(new \midgard_query_constraint(new \midgard_query_property('up'), '=', new \midgard_query_value($this->object->id)));
     $q->execute();
     if ($q->get_results_count() == 0) {
         return;
     }
     $children = $q->list_objects();
     foreach ($children as $child) {
         $this->children[$child->name] = new Node($child, $this, $this->getSession());
     }
 }
Beispiel #4
0
 public function can_handle(midgard_object $object)
 {
     if (!$object instanceof com_meego_package) {
         return false;
     }
     // Check that the package's repository has a form
     $repository = new com_meego_repository($object->repository);
     if (!midgardmvc_ui_forms_generator::has_object_forms($repository)) {
         return false;
     }
     // Check if the form is assigned to this repository
     $storage = new midgard_query_storage('com_meego_package_repository_form');
     $q = new midgard_query_select($storage);
     $qc = new midgard_query_constraint_group('AND');
     $qc->add_constraint(new midgard_query_constraint(new midgard_query_property('formtitle'), '=', new midgard_query_value($this->workflow['label'])));
     $qc->add_constraint(new midgard_query_constraint(new midgard_query_property('repoguid'), '=', new midgard_query_value($repository->guid)));
     $q->set_constraint($qc);
     $res = $q->execute();
     if (!$q->get_results_count()) {
         return false;
     }
     if (!midgardmvc_core::get_instance()->authentication->is_user()) {
         return true;
     }
     // safety net
     try {
         $user = midgardmvc_core::get_instance()->authentication->get_person();
     } catch (midgard_error_exception $e) {
         // if the person object is gone we will have an exception here
         return false;
     }
     //Hasn't reviewed yet
     $storage = new midgard_query_storage('midgardmvc_ui_forms_form_instance');
     $q = new midgard_query_select($storage);
     $qc = new midgard_query_constraint_group('AND');
     $qc->add_constraint(new midgard_query_constraint(new midgard_query_property('relatedobject'), '=', new midgard_query_value($object->guid)));
     $qc->add_constraint(new midgard_query_constraint(new midgard_query_property('metadata.creator'), '=', new midgard_query_value($user->guid)));
     $q->set_constraint($qc);
     $res = $q->execute();
     if ($q->get_results_count() != 0) {
         return false;
     }
     return true;
 }
Beispiel #5
0
 /**
  * Returns the number of packages available within the given category
  * @param integer id of the category
  * @return integer number of packages
  */
 public function number_of_packages($category_id)
 {
     $retval = 0;
     $storage = new midgard_query_storage('com_meego_package');
     $q = new midgard_query_select($storage);
     $qc = new midgard_query_constraint(new midgard_query_property('category'), '=', new midgard_query_value($category_id));
     $q->set_constraint($qc);
     $q->execute();
     $retval = $q->get_results_count();
     return $retval;
 }
Beispiel #6
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);
 }
 public static function count_favourites($article_guid)
 {
     $storage = new midgard_query_storage('fi_openkeidas_articles_favourite');
     $qc = new midgard_query_constraint(new midgard_query_property('article', $storage), '=', new midgard_query_value($article_guid));
     $q = new midgard_query_select($storage);
     $q->set_constraint($qc);
     $q->execute();
     return $q->get_results_count();
 }
 /**
  * Checks is the given OS is valid
  *
  * @param string name of the OS
  * @param string version of the OS
  * @return boolean true if OS exists, false otherwise
  */
 public function os_exists($os = '', $os_version = '')
 {
     $retval = false;
     $storage = new midgard_query_storage('com_meego_os');
     $q = new midgard_query_select($storage);
     $qc = new midgard_query_constraint_group('AND');
     $qc->add_constraint(new midgard_query_constraint(new midgard_query_property('name'), '=', new midgard_query_value($os)));
     $qc->add_constraint(new midgard_query_constraint(new midgard_query_property('version'), '=', new midgard_query_value($os_version)));
     $q->set_constraint($qc);
     $q->execute();
     if ($q->get_results_count()) {
         $retval = true;
     }
     return $retval;
 }