Exemplo n.º 1
0
 private function append_nodes(\DomNode $node, $parent)
 {
     if ($node->localName != 'node') {
         return;
     }
     $name = "";
     foreach ($node->attributes as $element) {
         /* The name of each JCR node or property becomes the value of the sv:name */
         if ($element->name != 'name') {
             continue;
         }
         $name = $element->value;
     }
     /* The hierarchy of the content repository nodes and properties is reflected in
      * the hierarchy of the corresponding XML elements. */
     $mvc_node = new midgardmvc_core_node();
     $mvc_node->name = $name;
     $mvc_node->up = $parent->id;
     $mvc_node->create();
     /* If there's duplicate, get it and reuse */
     if (midgard_connection::get_instance()->get_error() == MGD_ERR_DUPLICATE) {
         $q = new \midgard_query_select(new \midgard_query_storage('midgardmvc_core_node'));
         $group = new midgard_query_constraint_group('AND');
         $group->add_constraint(new \midgard_query_constraint(new \midgard_query_property('up'), '=', new \midgard_query_value($parent->id)));
         $group->add_constraint(new \midgard_query_constraint(new \midgard_query_property('name'), '=', new \midgard_query_value($name)));
         $q->set_constraint($group);
         $q->execute();
         $mvc_node = current($q->list_objects());
     }
     foreach ($node->childNodes as $snode) {
         $this->append_nodes($snode, $mvc_node);
     }
 }
Exemplo n.º 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);
 }
Exemplo n.º 3
0
 /**
  * Retrieves all providers
  *
  * @param array filters, possible members: deleted, creator, name, provider
  *              if multiple members used then we do a logical AND with them
  * @return array array of com_meego_devprogram_device objects
  */
 public static function get_providers(array $filters)
 {
     $providers = null;
     $storage = new midgard_query_storage('com_meego_devprogram_provider');
     $q = new midgard_query_select($storage);
     if (count($filters) > 1) {
         $qc = new midgard_query_constraint_group('AND');
     }
     foreach ($filters as $filter => $value) {
         switch ($filter) {
             case 'deleted':
                 if ($value) {
                     $q->include_deleted(true);
                 }
                 break;
             case 'creator':
                 // check if the value is a real guid
                 if (mgd_is_guid($value)) {
                     $constraint = new midgard_query_constraint(new midgard_query_property('metadata.creator'), '=', new midgard_query_value($value));
                 }
                 break;
             case 'id':
             case 'guid':
             case 'name':
             case 'primarycontactname':
             case 'primarycontactemail':
                 $constraint = new midgard_query_constraint(new midgard_query_property($filter), '=', new midgard_query_value($value));
                 break;
         }
         // set the constraint
         if (isset($constraint)) {
             count($filters) > 1 ? $qc->add_constraint($constraint) : ($qc = $constraint);
         }
     }
     if (isset($qc)) {
         $q->set_constraint($qc);
     }
     $q->add_order(new midgard_query_property('metadata.created'), SORT_DESC);
     $q->execute();
     // does not seem to work
     // @bug: $q->toggle_read_only(false);
     $objects = $q->list_objects();
     if (count($objects)) {
         foreach ($objects as $object) {
             $providers[] = self::extend_provider($object);
         }
     }
     return $providers;
 }
Exemplo n.º 4
0
 public static function get_user_vote(com_meego_planet_item $item)
 {
     midgardmvc_core::get_instance()->authorization->require_user();
     $q = new midgard_query_select(new midgard_query_storage('com_meego_planet_item_vote'));
     $qc = new midgard_query_constraint_group('AND');
     $qc->add_constraint(new midgard_query_constraint(new midgard_query_property('item'), '=', new midgard_query_value($item->id)));
     $qc->add_constraint(new midgard_query_constraint(new midgard_query_property('user'), '=', new midgard_query_value(midgardmvc_core::get_instance()->authentication->get_person()->id)));
     $q->set_constraint($qc);
     $q->execute();
     $objects = $q->list_objects();
     if (count($objects) > 0) {
         return new com_meego_planet_item_vote($objects[0]->guid);
     }
     $vote = new com_meego_planet_item_vote();
     $vote->item = $item->id;
     $vote->user = midgardmvc_core::get_instance()->authentication->get_person()->id;
     return $vote;
 }
Exemplo n.º 5
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;
 }
Exemplo n.º 6
0
 /**
  * A signal handler for deleting comments
  * Checks if the comment was attached to a rating object
  * If the rating object has no rating, then it will delete this object
  *
  * @param object com_meego_comments_comment object
  */
 public static function delete_rating_handler(com_meego_comments_comment $comment)
 {
     $mvc = midgardmvc_core::get_instance();
     if ($comment) {
         $storage = new midgard_query_storage('com_meego_ratings_rating');
         $q = new midgard_query_select($storage);
         $qc = new midgard_query_constraint_group('AND');
         $qc->add_constraint(new midgard_query_constraint(new midgard_query_property('comment'), '=', new midgard_query_value($comment->id)));
         $qc->add_constraint(new midgard_query_constraint(new midgard_query_property('rating'), '=', new midgard_query_value('')));
         $q->set_constraint($qc);
         $q->execute();
         $ratings = $q->list_objects();
         if (count($ratings)) {
             foreach ($ratings as $rating) {
                 $res = $rating->delete();
                 if ($res) {
                     $mvc->log(__CLASS__, 'Rating object with id: ' . $rating->id . ' has been successfuly deleted.', 'info');
                 } else {
                     $mvc->log(__CLASS__, 'Rating object with id: ' . $rating->id . ' could not be deleted.', 'info');
                 }
             }
         }
     }
 }
Exemplo n.º 7
0
 private function _get_user()
 {
     if ($this->_midgard2) {
         $storage = new midgard_query_storage('midgard_user');
         $qs = new midgard_query_select($storage);
         $group = new midgard_query_constraint_group('AND');
         $group->add_constraint(new midgard_query_constraint(new midgard_query_property('person'), '=', new midgard_query_value($this->_person->guid)));
         $group->add_constraint(new midgard_query_constraint(new midgard_query_property('authtype'), '=', new midgard_query_value($GLOBALS['midcom_config']['auth_type'])));
         $qs->set_constraint($group);
         $qs->toggle_readonly(false);
         $qs->execute();
         $result = $qs->list_objects();
         if (sizeof($result) != 1) {
             return new midgard_user();
         }
         return $result[0];
     } else {
         return $this->_person;
     }
 }
Exemplo n.º 8
0
 /**
  * Retrieves membership using various filters
  *
  * @param array filters array
  *
  * @return array an array of com_meego_devprogram_provider_membership objects
  *               extended with some handy properties
  */
 private static function get_memberships(array $filters)
 {
     $memberships = array();
     $storage = new midgard_query_storage('com_meego_devprogram_provider_membership');
     $q = new midgard_query_select($storage);
     if (count($filters) > 1 || count($filters) == 1 && !array_key_exists('status', $filters)) {
         $qc = new midgard_query_constraint_group('AND');
     }
     foreach ($filters as $filter => $value) {
         switch ($filter) {
             case 'creator':
                 // check if creator guid is valid
                 if (mgd_is_guid($value)) {
                     $constraint = new midgard_query_constraint(new midgard_query_property('metadata.creator'), '=', new midgard_query_value($value));
                 }
                 break;
             case 'provider':
             case 'person':
                 if (isset($value)) {
                     $constraint = new midgard_query_constraint(new midgard_query_property($filter), '=', new midgard_query_value($value));
                 }
                 break;
             case 'status':
                 if (isset($value)) {
                     $constraint = new midgard_query_constraint(new midgard_query_property($filter), '=', new midgard_query_value($value));
                 }
                 break;
         }
         // set the constraint
         if (is_a($qc, 'midgard_query_constraint_group')) {
             $qc->add_constraint($constraint);
         } else {
             $qc = $constraint;
         }
     }
     if (!array_key_exists('status', $filters)) {
         // if status was not set explicitly then include all but cancelled memberships
         $constraint = new midgard_query_constraint(new midgard_query_property('status'), '<', new midgard_query_value(CMD_MEMBERSHIP_CANCELLED));
         // set the constraint
         if (count($filters) >= 1) {
             if (!is_a($qc, 'midgard_query_constraint_group')) {
                 $qc = new midgard_query_constraint_group('AND');
             }
             $qc->add_constraint($constraint);
         } else {
             $qc = $constraint;
         }
     }
     $q->set_constraint($qc);
     $q->execute();
     // does not seem to work
     // @bug: $q->toggle_read_only(false);
     $objects = $q->list_objects();
     foreach ($objects as $object) {
         $memberships[] = self::extend_membership($object);
     }
     return $memberships;
 }
Exemplo n.º 9
0
 /**
  * Checks if a user has rated a certain package
  * @param integer package id
  * @param guid of the user
  *
  * @return boolean true: if user has rated, false otherwise
  */
 public function user_has_voted($application_id = null, $author_guid = null)
 {
     $retval = false;
     if (!$application_id) {
         // throw an exception or something..
         return null;
     }
     if (!$author_guid) {
         // ok, get the current user then
         $user = $this->get_current_user();
         if (!$user) {
             // not logged in, to bad
             return null;
         }
         $author_guid = $user->person;
     }
     // query select
     $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('id'), '=', new midgard_query_value($application_id)));
     $qc->add_constraint(new midgard_query_constraint(new midgard_query_property('commentid'), '=', new midgard_query_value(0)));
     $qc->add_constraint(new midgard_query_constraint(new midgard_query_property('authorguid'), '=', new midgard_query_value($author_guid)));
     $q->set_constraint($qc);
     $q->execute();
     $ratings = $q->list_objects();
     if (count($ratings)) {
         $retval = true;
     }
     return $retval;
 }
Exemplo n.º 10
0
 /**
  * Loads favourited items
  *
  * @param user_guid GUID of user
  * @param article_guid GUID of article object
  * @return array of db entries
  *
  */
 public static function load_favourites($user_guid = null, $article_guid = null)
 {
     if (!$user_guid) {
         return null;
     }
     $storage = new midgard_query_storage('fi_openkeidas_articles_favourite');
     if (!$article_guid) {
         $qc = new midgard_query_constraint(new midgard_query_property('metadata.creator'), '=', new midgard_query_value($user_guid));
     } else {
         $qc = new midgard_query_constraint_group('AND');
         $qc->add_constraint(new midgard_query_constraint(new midgard_query_property('metadata.creator'), '=', new midgard_query_value($user_guid)));
         $qc->add_constraint(new midgard_query_constraint(new midgard_query_property('article'), '=', new midgard_query_value($article_guid)));
     }
     $q = new midgard_query_select($storage);
     $q->set_constraint($qc);
     $q->execute();
     return $q->list_objects();
 }
Exemplo n.º 11
0
 /**
  * Loads a relation object betwenn a base category and a package category
  *
  * @param integer id of the base category
  * @param integer id of the package category
  *
  * @return object relation object
  *
  */
 private function load_relation($basecategory = null, $packagecategory = null, $includedeleted = false)
 {
     $relation = null;
     $storage = new midgard_query_storage('com_meego_package_category_relation');
     $qc = new midgard_query_constraint_group('AND');
     $qc->add_constraint(new midgard_query_constraint(new midgard_query_property('basecategory'), '=', new midgard_query_value($basecategory)));
     $qc->add_constraint(new midgard_query_constraint(new midgard_query_property('packagecategory'), '=', new midgard_query_value($packagecategory)));
     $q = new midgard_query_select($storage);
     $q->set_constraint($qc);
     $q->set_limit(1);
     if ($includedeleted) {
         $q->include_deleted(true);
     }
     $q->execute();
     $relations = $q->list_objects();
     if (is_array($relations) && count($relations)) {
         $relation = $relations[0];
     }
     return $relation;
 }
Exemplo n.º 12
0
 /**
  * Creates a role object for the package
  */
 public function createRole($package_guid, $userid, $role)
 {
     $storage = new midgard_query_storage('midgard_user');
     $q = new midgard_query_select($storage);
     $q->set_constraint(new midgard_query_constraint(new midgard_query_property('login'), '=', new midgard_query_value($userid)));
     $q->toggle_readonly(false);
     $q->execute();
     $users = $q->list_objects();
     if (count($users)) {
         $user = $users[0];
     } else {
         $user = $this->createUser($userid);
     }
     // check if this role is already set
     midgard_error::info(__CLASS__ . ' Check if role exists: (' . $package_guid . ', ' . $userid . ', ' . $role . ')');
     $storage = new midgard_query_storage('com_meego_package_role');
     $q = new midgard_query_select($storage);
     $qc = new midgard_query_constraint_group('AND');
     $qc->add_constraint(new midgard_query_constraint(new midgard_query_property('package'), '=', new midgard_query_value($package_guid)));
     $qc->add_constraint(new midgard_query_constraint(new midgard_query_property('user'), '=', new midgard_query_value($user->guid)));
     $qc->add_constraint(new midgard_query_constraint(new midgard_query_property('role'), '=', new midgard_query_value($role)));
     $q->set_constraint($qc);
     $q->execute();
     $roles = $q->list_objects();
     if (!count($roles)) {
         $role_obj = new com_meego_package_role();
         $role_obj->package = $package_guid;
         $role_obj->user = $user->guid;
         $role_obj->role = $role;
         if (!$role_obj->create()) {
             $error = midgard_connection::get_instance()->get_error_string();
             midgard_error::error(__CLASS__ . " Creating role object failed: " . $error);
         }
         midgard_error::info(__CLASS__ . " Creating role object succeeded: " . $role_obj->guid);
     } else {
         midgard_error::info(__CLASS__ . " Role object already exists: " . $roles[0]->guid);
     }
 }
Exemplo n.º 13
0
 /**
  * The main method to return list of packages
  *
  * @param array HTTP GET arguments
  */
 public function get_data(array $args)
 {
     $constraints = array();
     $query = $this->request->get_query();
     $storage = new midgard_query_storage('com_meego_package_details');
     $q = new midgard_query_select($storage);
     $qc = new midgard_query_constraint_group('OR');
     // filter all hidden packages
     $qc->add_constraint(new midgard_query_constraint(new midgard_query_property('packagehidden'), '=', new midgard_query_value(1)));
     // filter packages by their names
     foreach ($this->mvc->configuration->sql_package_filters as $filter) {
         $qc->add_constraint(new midgard_query_constraint(new midgard_query_property('packagename'), 'LIKE', new midgard_query_value($filter)));
         $qc->add_constraint(new midgard_query_constraint(new midgard_query_property('packagetitle'), 'LIKE', new midgard_query_value($filter)));
     }
     $q->set_constraint($qc);
     $q->execute();
     $filtered = array();
     foreach ($q->list_objects() as $package) {
         $filtered[] = $package->packageid;
     }
     if (count($filtered)) {
         $constraints[] = new midgard_query_constraint(new midgard_query_property('packageid'), 'NOT IN', new midgard_query_value($filtered));
     }
     if (count($query)) {
         if (array_key_exists('search', $query) && strlen($query['search'])) {
             $cnstr1 = new midgard_query_constraint(new midgard_query_property('packagename'), 'LIKE', new midgard_query_value('%' . $query['search'] . '%'));
             $cnstr2 = new midgard_query_constraint(new midgard_query_property('packagetitle'), 'LIKE', new midgard_query_value('%' . $query['search'] . '%'));
             $group_constraint = new midgard_query_constraint_group("OR", $cnstr1, $cnstr2);
             $constraints[] = $group_constraint;
         }
         if (array_key_exists('categories', $query) && strlen($query['categories'])) {
             $constraints[] = new midgard_query_constraint(new midgard_query_property('basecategory'), 'IN', new midgard_query_value(explode('x', $query['categories'])));
         }
         if (array_key_exists('license', $query) && strlen($query['license'])) {
             $constraints[] = new midgard_query_constraint(new midgard_query_property('packagelicenseid'), 'IN', new midgard_query_value(explode(',', $query['license'])));
         }
         if (array_key_exists('distribution', $query) && strlen($query['distribution'])) {
             $constraints[] = new midgard_query_constraint(new midgard_query_property('repoosversionid'), 'IN', new midgard_query_value(explode(',', $query['distribution'])));
         }
         if (array_key_exists('dependency', $query) && strlen($query['dependency'])) {
             $constraints[] = new midgard_query_constraint(new midgard_query_property('repoosuxid'), 'IN', new midgard_query_value(explode(',', $query['dependency'])));
         }
         if (array_key_exists('sortmode', $query) && strlen($query['sortmode'])) {
             switch ($query['sortmode']) {
                 case 'new':
                     $q->add_order(new midgard_query_property('packagecreated'), SORT_DESC);
                     break;
                 case 'high':
                     $q->add_order(new midgard_query_property('statscachedratingvalue'), SORT_DESC);
                     //sort by name too
                     $q->add_order(new midgard_query_property('packagetitle'), SORT_ASC);
                     break;
                 case 'down':
                     //sort by name too
                     $q->add_order(new midgard_query_property('statscachedratingvalue'), SORT_ASC);
                 case 'alpha':
                 default:
                     $q->add_order(new midgard_query_property('packagetitle'), SORT_ASC);
                     break;
             }
         }
     }
     if (isset($args['id'])) {
         $constraints[] = new midgard_query_constraint(new midgard_query_property('packageid'), '=', new midgard_query_value($args['id']));
     }
     $qc = null;
     if (count($constraints) > 1) {
         $qc = new midgard_query_constraint_group('AND');
         foreach ($constraints as $constraint) {
             $qc->add_constraint($constraint);
         }
     } else {
         if (isset($constraints[0])) {
             $qc = $constraints[0];
         }
     }
     if (is_object($qc)) {
         $q->set_constraint($qc);
     }
     // 1st execute to get the total number of records
     // required by OCS
     $q->execute();
     $total = $q->get_results_count();
     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();
     if ($total > 0) {
         $packageids = array();
         $localpackages = array();
         $packages = $q->list_objects();
         $done = array();
         foreach ($packages as $package) {
             if (in_array($package->packageid, $packageids)) {
                 // mimic distinct (Midgard Ratatoskr does not support it on SQL level)
                 --$total;
                 continue;
             }
             // set a special flag if the package is from a testing repository
             $package->testing = false;
             foreach ($this->mvc->configuration->top_projects as $top_project) {
                 if ($top_project['staging'] == $package->repoprojectname) {
                     $package->testing = true;
                 }
             }
             $package->comments_count = 0;
             // get number of comments
             $comments_qs = new midgard_query_storage('com_meego_comments_comment');
             $comments_q = new midgard_query_select($comments_qs);
             $comments_q->set_constraint(new midgard_query_constraint(new midgard_query_property('to'), '=', new midgard_query_value($package->packageguid)));
             $comments_q->execute();
             $package->comments_count = $comments_q->get_results_count();
             // get attachments
             $origpackage = new com_meego_package($package->packageguid);
             $package->attachments = $origpackage->list_attachments();
             unset($origpackage);
             // get the voters (who rated the package)
             $package->ratings = '';
             $ratings = com_meego_packages_controllers_application::prepare_ratings($package->packagename, true);
             if (count($ratings['ratings'])) {
                 foreach ($ratings['ratings'] as $rating) {
                     $ratings_[] = array('user' => $rating->user, 'version' => $rating->version, 'rate' => $rating->rating, 'date' => $rating->date);
                 }
                 $package->ratings = serialize($ratings_);
             }
             // some attributes returned only if an exact package is queried
             if (isset($args['id'])) {
                 // generate the URL of the package instance
                 $path = midgardmvc_core::get_instance()->dispatcher->generate_url('package_instance', array('package' => $package->packagename, 'version' => $package->packageversion, 'project' => $package->repoprojectname, 'repository' => $package->reponame, 'arch' => $package->repoarch), '/');
                 $package->commentsurl = com_meego_ocs_controllers_providers::generate_url($path);
                 // get the roles
                 $package->roles = null;
                 $roles = com_meego_packages_controllers_application::get_roles($package->packageguid);
                 if (count($roles)) {
                     $package->roles = serialize($roles);
                 }
                 // get the forms
                 $package->qa = null;
                 $forms = com_meego_packages_utils::get_stripped_forms_for_package($package);
                 if (count($forms)) {
                     $package->qa = serialize($forms);
                 }
             }
             if ($package->packagename != '') {
                 //get history
                 $args = array('os' => $package->repoos, 'version' => $package->repoosversion, 'ux' => $package->repoosux, 'packagename' => $package->packagename);
                 if (!isset($done[$package->packagename])) {
                     $packagehistory = com_meego_packages_controllers_application::get_lightweight_history($args);
                     if (count($packagehistory)) {
                         $package->history = serialize($packagehistory);
                         $done[$package->packagename] = $package->history;
                         //die;
                     }
                 } else {
                     // just copy the history
                     $package->history = $done[$package->packagename];
                 }
             }
             $localpackages[] = $package;
             $packageids[] = $package->packageid;
         }
         // write the xml content
         $ocs->writeMeta($total, $this->pagesize);
         $ocs->writeContent(array_values($localpackages));
         unset($done, $packageids, $localpackages);
     } else {
         // item not found
         $ocs->writeMeta($total, $this->pagesize, 'content not found', 'failed', 101);
         $ocs->writeEmptyData();
     }
     $ocs->endDocument();
     self::output_xml($ocs);
 }
Exemplo n.º 14
0
 /**
  * Retrieves all open workflows for the specified OS / UX combo
  * Returns repository titles, form titles and URLs to browse the repos
  *
  * @return array
  */
 public function get_open_workflows_for_osux($os = null, $version = null, $ux = null)
 {
     $retval = null;
     if ($os && $version && $ux) {
         $dt = new midgard_datetime();
         $now = $dt->__toString();
         $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('formstart'), '<=', new midgard_query_value($now)));
         $qc->add_constraint(new midgard_query_constraint(new midgard_query_property('formend'), '>', new midgard_query_value($now)));
         $qc->add_constraint(new midgard_query_constraint(new midgard_query_property('repoos'), '=', new midgard_query_value($os)));
         $qc->add_constraint(new midgard_query_constraint(new midgard_query_property('repoosversion'), '=', new midgard_query_value($version)));
         $qc1 = new midgard_query_constraint_group('OR');
         $qc1->add_constraint(new midgard_query_constraint(new midgard_query_property('repoux'), '=', new midgard_query_value($ux)));
         $qc1->add_constraint(new midgard_query_constraint(new midgard_query_property('repoux'), '=', new midgard_query_value('')));
         $qc->add_constraint($qc1);
         $q->set_constraint($qc);
         $q->execute();
         $forms = $q->list_objects();
         $retval = self::append_forms($forms);
     }
     return $retval;
 }
Exemplo n.º 15
0
 /**
  * Get a lightweight history of an app
  *
  * @param array of args (os, version, ux, basecategory, packagename)
  */
 public function get_lightweight_history(array $args)
 {
     $ux = null;
     $history = array();
     if ($args['ux'] != '') {
         $ux = $args['ux'];
     }
     // collect all ids of this app having the same os and ux
     $storage = new midgard_query_storage('com_meego_package_details');
     $q = new midgard_query_select($storage);
     $qc = new midgard_query_constraint_group('AND');
     $qc->add_constraint(new midgard_query_constraint(new midgard_query_property('packagename'), '=', new midgard_query_value($args['packagename'])));
     $qc->add_constraint(new midgard_query_constraint(new midgard_query_property('repoos'), '=', new midgard_query_value($args['os'])));
     if ($ux) {
         $qc->add_constraint(new midgard_query_constraint(new midgard_query_property('repoosux'), '=', new midgard_query_value($ux)));
     }
     $q->set_constraint($qc);
     $q->add_order(new midgard_query_property('packageid', $storage), SORT_ASC);
     $q->execute();
     $packages = $q->list_objects();
     foreach ($packages as $package) {
         if (end($history) != $package->packageid) {
             $history[] = $package->packageid;
         }
     }
     return $history;
 }
Exemplo n.º 16
0
 /**
  * Retrieves programs using various filters
  *
  * @param array filters, possible members: name, creator, status
  *              if multiple members used then we do a logical AND with them
  * @return object com_meego_devprogram_program object
  */
 public static function get_programs(array $filters)
 {
     $programs = array();
     $storage = new midgard_query_storage('com_meego_devprogram_program');
     $q = new midgard_query_select($storage);
     if (count($filters) > 1) {
         $qc = new midgard_query_constraint_group('AND');
     }
     foreach ($filters as $filter => $value) {
         switch ($filter) {
             case 'deleted':
                 if ($value) {
                     $q->include_deleted(true);
                 }
                 break;
             case 'creator':
                 // check if the value is a real guid
                 if (mgd_is_guid($value)) {
                     $constraint = new midgard_query_constraint(new midgard_query_property('metadata.creator'), '=', new midgard_query_value($value));
                 }
                 break;
             case 'id':
             case 'name':
             case 'device':
                 $constraint = new midgard_query_constraint(new midgard_query_property($filter), '=', new midgard_query_value($value));
                 break;
             case 'status':
                 // current date and time
                 $now = date("Y-m-d H:i:s");
                 switch ($value) {
                     case CMD_PROGRAM_CLOSED:
                         $type = '<';
                         break;
                     case CMD_PROGRAM_OPEN:
                     default:
                         $type = '>';
                 }
                 $constraint = new midgard_query_constraint(new midgard_query_property('duedate'), $type, new midgard_query_value($now));
                 break;
             case 'daysleft':
                 // duedate < now + value
                 $now = new DateTime();
                 $limit = $now->add(new DateInterval('P' . $value . 'D'));
                 $constraint = new midgard_query_constraint(new midgard_query_property('duedate'), '<', new midgard_query_value($limit->format('Y-m-d')));
                 break;
         }
         // set the constraint
         count($filters) > 1 ? $qc->add_constraint($constraint) : ($qc = $constraint);
     }
     $q->set_constraint($qc);
     $q->add_order(new midgard_query_property('metadata.created'), SORT_DESC);
     $q->execute();
     // does not seem to work
     // @bug: $q->toggle_read_only(false);
     $objects = $q->list_objects();
     if (count($objects)) {
         foreach ($objects as $object) {
             $programs[] = self::extend_program($object);
         }
     }
     return $programs;
 }
Exemplo n.º 17
0
 /**
  * Returns all person object that match the given ldapuser details
  */
 private function get_persons($ldapuser = null, $person_guid = null)
 {
     $retval = false;
     if (is_array($ldapuser) && array_key_exists('firstname', $ldapuser) && array_key_exists('lastname', $ldapuser)) {
         $storage = new midgard_query_storage('midgard_person');
         $q = new midgard_query_select($storage);
         $qc = new midgard_query_constraint_group('AND');
         $qc->add_constraint(new midgard_query_constraint(new midgard_query_property('firstname'), '=', new midgard_query_value($ldapuser['firstname'])));
         $qc->add_constraint(new midgard_query_constraint(new midgard_query_property('lastname'), '=', new midgard_query_value($ldapuser['lastname'])));
         if ($person_guid) {
             $qc->add_constraint(new midgard_query_constraint(new midgard_query_property('guid'), '=', new midgard_query_value($person_guid)));
         }
         $q->set_constraint($qc);
         $q->execute();
         //$q->toggle_readonly(false);
         $retval = $q->list_objects();
     }
     return $retval;
 }
Exemplo n.º 18
0
 /**
  * Renders an overview of a package identified by its name
  * The page will display all ratings and comments of all variants of the given package
  *
  * It will also show the links to the detailed pages of each individual package variants
  *
  * No commenting or rating is enabled on this page. Those can be done on the variant pages.
  *
  * @param array args
  *
  */
 public function get_package_overview(array $args)
 {
     $this->data['packages'] = false;
     $this->data['categorytree'] = rawurldecode($args['categorytree']);
     $this->data['packagename'] = rawurldecode($args['packagename']);
     $category = $this->determine_category_by_tree($this->data['categorytree']);
     if (isset($category) && $category != 0) {
         $storage = new midgard_query_storage('com_meego_package_details');
         $q = new midgard_query_select($storage);
         $qc = new midgard_query_constraint_group('AND');
         $qc->add_constraint(new midgard_query_constraint(new midgard_query_property('packagecategory'), '=', new midgard_query_value($category)));
         $qc->add_constraint(new midgard_query_constraint(new midgard_query_property('packagename'), '=', new midgard_query_value($this->data['packagename'])));
         $q->set_constraint($qc);
         $q->add_order(new midgard_query_property('packagename', $storage), SORT_ASC);
         $q->execute();
         $packages = $q->list_objects();
         $this->set_data($packages);
         // collect all ratings and comments
         $this->data['packages'][$this->data['packagename']]['ratings'] = array();
         // placeholder for variant ratings
         $local_ratings = array();
         foreach ($this->data['packages'][$this->data['packagename']]['providers'] as $provider) {
             foreach ($provider['variants'] as $variant) {
                 $local_ratings = array_merge(self::prepare_ratings($variant->packageguid), $local_ratings);
             }
         }
         // set ratings to the template
         $this->data['packages'][$this->data['packagename']]['ratings'] = $local_ratings;
     }
 }
Exemplo n.º 19
0
 /**
  * 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;
 }