Exemplo n.º 1
0
 private function getRootNodes()
 {
     $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(0)));
     $q->execute();
     return $q->list_objects();
 }
Exemplo n.º 2
0
 /**
  * @todo: docs
  */
 public function start(midgard_object $object, array $args = null)
 {
     if (!midgardmvc_core::get_instance()->authentication->is_user()) {
         return false;
     }
     $user = midgardmvc_core::get_instance()->authentication->get_user();
     $workflow = $this->get();
     $storage = new midgard_query_storage('midgardmvc_helper_workflow_execution');
     $q = new midgard_query_select($storage);
     $q->set_constraint(new midgard_query_constraint(new midgard_query_property('metadata.creator'), '=', new midgard_query_value($user->person)));
     $q->execute();
     $execs = $q->list_objects();
     foreach ($execs as $exec) {
         $variables = unserialize($exec->variables);
         if ($variables['package_instance'] == $object->guid) {
             midgardmvc_core::get_instance()->log(__CLASS__, 'Re-use unfinished workflow execution (' . $exec->id . ')', 'info');
             return self::resume($exec->guid, $variables);
         }
     }
     $execution = new midgardmvc_helper_workflow_execution_interactive($workflow);
     $execution->setVariable('package_instance', $object->guid);
     $execution->start();
     $values = array();
     if (!$execution->hasEnded()) {
         $values['execution'] = $execution->guid;
         return $values;
     }
     return $values;
 }
Exemplo n.º 3
0
 public function execute(ezcWorkflowExecution $execution)
 {
     $qa_results_dir = "/var/qa";
     // value will be the latest score of the package
     $value = $execution->getVariable('distilled_review');
     // an integer
     // dump this value to a file in the filesystem
     $storage = new midgard_query_storage('com_meego_package_details');
     // get the detailed package object
     $q = new midgard_query_select($storage);
     $q->set_constraint(new midgard_query_constraint(new midgard_query_property('packageguid'), '=', new midgard_query_value($execution->getVariable('package_instance'))));
     $q->execute();
     $package = $q->list_objects();
     if (count($package) && $value) {
         $project_name = $package[0]->repoprojectname;
         $package_name = $package[0]->packageparent;
         $qa_results_dir = $qa_results_dir . '/' . $project_name;
         if (!is_dir($qa_results_dir)) {
             $ret = mkdir($qa_results_dir, 0755, true);
             if (!$ret) {
                 // do something
                 return;
             }
         }
         $handle = fopen($qa_results_dir . '/' . $package_name . '.txt', "wb");
         if ($handle) {
             $ret = fwrite($handle, $value);
             if (!$ret) {
                 // do something
             }
         }
         fclose($handle);
     }
     return;
 }
Exemplo n.º 4
0
 public function execute()
 {
     $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(0)));
     $q->execute();
     $root_object = current($q->list_objects());
     $this->get_nodes($root_object);
 }
Exemplo n.º 5
0
 private function getRootObjects()
 {
     // TODO: Support all MgdSchema rootlevel types
     $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(0)));
     $q->execute();
     return $q->list_objects();
 }
/**
 * Collect QA posts
 * @param guid of a specfic user
 */
function get_qas($user = null)
{
    $storage = new midgard_query_storage('midgardmvc_ui_forms_form_instance');
    $q = new midgard_query_select($storage);
    if ($user) {
        $qc = new midgard_query_constraint(new midgard_query_property('metadata.creator'), '=', new midgard_query_value($user));
        $q->set_constraint($qc);
    }
    $q->execute();
    $results = $q->list_objects();
    return $results;
}
Exemplo n.º 7
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.º 8
0
 public function get_search(array $args)
 {
     $term = '%';
     if (isset($_GET['term'])) {
         $term = "{$_GET['term']}%";
     }
     $q = new midgard_query_select(new midgard_query_storage('midgard_person'));
     $q->set_constraint(new midgard_query_constraint(new midgard_query_property('firstname'), 'LIKE', new midgard_query_value($term)));
     $q->execute();
     $this->data = array_map(function ($person) {
         return array('value' => $person->id, 'label' => $person->firstname);
     }, $q->list_objects());
 }
Exemplo n.º 9
0
 private static function get_item_by_url($url)
 {
     if (!filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED)) {
         throw new InvalidArgumentException("Argument must be a valid URL");
     }
     $q = new midgard_query_select(new midgard_query_storage('com_meego_planet_item'));
     $q->set_constraint(new midgard_query_constraint(new midgard_query_property('url'), '=', new midgard_query_value($url)));
     $q->execute();
     if ($q->resultscount == 0) {
         throw new midgardmvc_exception_notfound("Item {$url} not found");
     }
     $objects = $q->list_objects();
     return $objects[0];
 }
Exemplo n.º 10
0
 private static function get_item_by_url($url)
 {
     $q = new midgard_query_select(new midgard_query_storage('com_meego_planet_item'));
     $q->add_order(new midgard_query_property('metadata.score'), SORT_DESC);
     $q->set_constraint(new midgard_query_constraint(new midgard_query_property('url'), '=', new midgard_query_value($url)));
     $q->execute();
     if ($q->resultscount == 0) {
         // New item
         $item = new com_meego_planet_item();
         $item->url = $url;
         return $item;
     }
     $list_of_items = $q->list_objects();
     return $list_of_items[0];
 }
Exemplo n.º 11
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());
     }
 }
Exemplo n.º 12
0
 /**
  * Just return all DB objects
  */
 public function get_all_forms($package_guid = null)
 {
     $retval = array();
     $storage = new midgard_query_storage('com_meego_package_forms_posted');
     $q = new midgard_query_select($storage);
     $q->set_constraint(new midgard_query_constraint(new midgard_query_property('packageguid'), '=', new midgard_query_value($package_guid)));
     // using set_limit and set_offset would work here, but let's try our universal pager
     //$q->set_limit($limit);
     //$q->set_offset($page * $limit);
     $q->execute();
     $forms = $q->list_objects();
     foreach ($forms as $form) {
         // don't return duplicates
         $retval[$form->forminstanceguid] = $form;
     }
     return $retval;
 }
Exemplo n.º 13
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.º 14
0
 /**
  * Retrieves all devices
  *
  * @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_devices(array $filters)
 {
     $devices = array();
     $storage = new midgard_query_storage('com_meego_devprogram_device');
     $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 'provider':
                 $constraint = new midgard_query_constraint(new midgard_query_property($filter), '=', new midgard_query_value($value));
                 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) {
             $devices[] = self::extend_device($object);
         }
     }
     return $devices;
 }
Exemplo n.º 15
0
 public function get_comments(array $args)
 {
     $this->data['to'] = midgard_object_class::get_object_by_guid($args['to']);
     if (!$this->data['to']) {
         throw new midgardmvc_exception_notfound("Comment target not found");
     }
     $this->data['comments'] = array();
     $storage = new midgard_query_storage('com_meego_comments_comment_author');
     $q = new midgard_query_select($storage);
     $q->set_constraint(new midgard_query_constraint(new midgard_query_property('to', $storage), '=', new midgard_query_value($this->data['to']->guid)));
     $q->add_order(new midgard_query_property('posted', $storage), SORT_ASC);
     $q->execute();
     $comments = $q->list_objects();
     foreach ($comments as $comment) {
         $this->data['comments'][$comment->commentid] = $comment;
     }
     if (midgardmvc_core::get_instance()->authentication->is_user()) {
         $this->data['can_post'] = true;
     } else {
         $this->data['can_post'] = false;
     }
 }
Exemplo n.º 16
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.º 17
0
 /**
  * Loads all relations that belong to a base category
  * @param integer id of the base category
  * @return array of relation objects
  */
 public function load_relations_for_basecategory($basecategory_id = null, $includedeleted = false)
 {
     $relations = array();
     if ($basecategory_id) {
         $storage = new midgard_query_storage('com_meego_package_category_relation');
         $q = new midgard_query_select($storage);
         $qc = new midgard_query_constraint(new midgard_query_property('basecategory'), '=', new midgard_query_value($basecategory_id));
         $q->set_constraint($qc);
         if ($includedeleted) {
             $q->include_deleted(true);
         }
         $q->execute();
         $relations = $q->list_objects();
     }
     return $relations;
 }
Exemplo n.º 18
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.º 19
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;
 }
Exemplo n.º 20
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.º 21
0
 /**
  * Sets the average rating of the package
  * Sets the flag showing if the package was ever rated or not
  * Sets $this->data['stars'] that can be directly put to pages showing
  * the stars
  */
 public function get_average(array $args)
 {
     $this->data['to'] = midgard_object_class::get_object_by_guid($args['to']);
     if (!$this->data['to']) {
         throw new midgardmvc_exception_notfound("rating target not found");
     }
     parent::get_read($args);
     $this->data['ratings'] = array();
     $this->data['average'] = 0;
     $this->data['rated'] = false;
     $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();
     $sum = 0;
     // only contains ratings where rating is not 0
     $num_of_valid_ratings = 0;
     if (count($ratings)) {
         $this->data['rated'] = true;
         foreach ($ratings as $rating) {
             $rating->stars = '';
             if ($rating->ratingcomment) {
                 $comment = new com_meego_comments_comment($rating->ratingcomment);
                 $rating->ratingcommentcontent = $comment->content;
             }
             if ($rating->rating || $rating->ratingcomment) {
                 // 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));
                 $sum += $rating->rating;
                 if ($rating->rating) {
                     // count only non zero ratings
                     ++$num_of_valid_ratings;
                 }
             }
             array_push($this->data['ratings'], $rating);
         }
         if ($num_of_valid_ratings) {
             $this->data['average'] = round($sum / $num_of_valid_ratings, 1);
         }
     }
     $this->get_stars($this->data['average']);
 }
Exemplo n.º 22
0
 /**
  * Sets the average rating of the package
  * Sets $this->data['stars'] that can be directly put to pages showing
  * the stars
  */
 public function get_average(array $args)
 {
     try {
         $this->data['to'] = midgard_object_class::get_object_by_guid($args['to']);
     } catch (midgard_error_exception $e) {
         midgardmvc_core::get_instance()->log(__CLASS__, 'Package with guid: ' . $args['to'] . ' not found. ' . $e->getMessage(), 'error');
         return false;
     }
     $this->data['repository'] = new com_meego_repository($this->data['to']->repository);
     com_meego_ratings_controllers_rating::get_read($args);
     $storage = new midgard_query_storage('com_meego_package_statistics_calculated');
     $q = new midgard_query_select($storage);
     $q->set_constraint(new midgard_query_constraint(new midgard_query_property('packageguid'), '=', new midgard_query_value($this->data['to']->guid)));
     $q->execute();
     $cache = $q->list_objects();
     $this->data['average'] = 0;
     $this->data['numberofratings'] = 0;
     $this->data['numberofcomments'] = 0;
     $this->data['rated'] = false;
     //load data from cache
     if (count($cache) > 0) {
         $this->data['average'] = $cache[0]->ratingvalue;
         $this->data['numberofratings'] = $cache[0]->ratings;
         $this->data['numberofcomments'] = $cache[0]->comments;
         $this->data['rated'] = true;
     }
     com_meego_ratings_caching_controllers_rating::get_stars($this->data['average']);
 }
Exemplo n.º 23
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.º 24
0
 /**
  * Retrieves all comments from the database
  * @param guid object f which the comments should be gathered
  * @return array of comment objects
  */
 private function get_comments($guid = null)
 {
     $storage = new midgard_query_storage('com_meego_comments_comment_author');
     $q = new midgard_query_select($storage);
     $q->set_constraint(new midgard_query_constraint(new midgard_query_property('to'), '=', new midgard_query_value($guid)));
     $q->add_order(new midgard_query_property('posted', $storage), SORT_DESC);
     $q->execute();
     $comments = $q->list_objects();
     $retval = array();
     foreach ($comments as $comment) {
         $object = $comment;
         $string = preg_replace_callback('|\\\\(\\d{3})|', function ($matches) {
             return chr(octdec($matches[1]));
         }, $comment->content);
         $object->fixed_content = $string;
         $retval[] = $object;
     }
     return $retval;
 }
Exemplo n.º 25
0
 /**
  * Returns the link of the avatar image that can be used in e.g. img src
  *
  * @param string user name
  * @return string url
  */
 public function get_avatar($username = null)
 {
     $retval = midgardmvc_core::get_instance()->configuration->default_avatar;
     if ($username) {
         midgardmvc_core::get_instance()->authorization->enter_sudo('midgardmvc_core');
         // determine the person guid
         $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($username)));
         $q->execute();
         $q->toggle_readonly(false);
         $users = $q->list_objects();
         midgardmvc_core::get_instance()->authorization->leave_sudo();
         if (count($users)) {
             $user = $users[0];
         }
         $account = midgardmvc_account_injector::get_account($user->person);
         if ($account->guid) {
             $retval = $account->avatarurl;
         }
     }
     return $retval;
 }
Exemplo n.º 26
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.º 27
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.º 28
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.º 29
0
 /**
  * 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;
 }
Exemplo n.º 30
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;
 }