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(); }
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'); }
/** * @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; }
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; }
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); }
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; }
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()); }
/** * 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; }
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]; }
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()); } }
/** * @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); }
/** * 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; }
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; }
/** * Prepares the data to be returned */ private function prepare_data() { $storage = new midgard_query_storage('net_nemein_party_registration'); $q = new midgard_query_select($storage); $q->execute(); $registrations = $q->list_objects(); $this->data['guests'] = array(); if (count($registrations)) { $this->data['guests']['header'][] = 'firstname'; $this->data['guests']['header'][] = 'lastname'; $this->data['guests']['header'][] = 'email'; $this->data['guests']['header'][] = 'attending'; $this->data['guests']['header'][] = 'avec'; $this->data['guests']['header'][] = 'avec_firstname'; $this->data['guests']['header'][] = 'avec_lastname'; $this->data['guests']['header'][] = 'registered'; foreach ($registrations as $registration) { $avec_firstname = ''; $avec_lastname = ''; if ($registration->parent) { $parent = new net_nemein_party_registration($registration->parent); if (is_object($parent)) { $guest = $parent; $avec_firstname = $registration->firstname; $avec_lastname = $registration->lastname; } unset($parent); } else { $guest = $registration; } $this->data['guests'][$guest->guid]['firstname'] = $guest->firstname; $this->data['guests'][$guest->guid]['lastname'] = $guest->lastname; $this->data['guests'][$guest->guid]['email'] = $guest->email; $this->data['guests'][$guest->guid]['attending'] = $guest->attending ? 'yes' : 'no'; $this->data['guests'][$guest->guid]['avec'] = $guest->avec ? 'yes' : 'no'; $this->data['guests'][$guest->guid]['avec_firstname'] = $avec_firstname; $this->data['guests'][$guest->guid]['avec_lastname'] = $avec_lastname; $this->data['guests'][$guest->guid]['registered'] = $guest->metadata->created->format('Y-m-d H:i:s'); } } }
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; } }
public function get_list(array $args) { $this->data['title'] = sprintf('%s: Aggregated feeds', $node = $this->request->get_node()->get_object()->title); midgardmvc_core::get_instance()->head->set_title($this->data['title']); $q = new midgard_query_select(new midgard_query_storage('com_meego_planet_feed')); $q->execute(); $request = $this->request; $this->data['feeds'] = array_map(function ($feed) use($request) { $feed->editurl = ''; $feed->deleteurl = ''; if (midgardmvc_core::get_instance()->authentication->is_user() && midgardmvc_core::get_instance()->authentication->get_user()->is_admin()) { $feed->editurl = midgardmvc_core::get_instance()->dispatcher->generate_url('feed_update', array('feed' => $feed->guid), $request); $feed->deleteurl = midgardmvc_core::get_instance()->dispatcher->generate_url('feed_delete', array('feed' => $feed->guid), $request); } return $feed; }, $q->list_objects()); $this->data['addurl'] = ''; if (midgardmvc_core::get_instance()->authentication->is_user() && midgardmvc_core::get_instance()->authentication->get_user()->is_admin()) { $this->data['addurl'] = midgardmvc_core::get_instance()->dispatcher->generate_url('feed_create', array(), $this->request); } midgardmvc_core::get_instance()->head->enable_jquery(); midgardmvc_core::get_instance()->head->enable_jquery_ui(); midgardmvc_core::get_instance()->head->add_jsfile(MIDGARDMVC_STATIC_URL . '/com_meego_planet/feeds.js'); }
/** * 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'); } } } } }
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; } }
/** * 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; }
/** * 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; }
/** * 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']); }
/** * 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']); }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }
public static function page_by_args(midgard_query_select $q, array $args) { $q->set_limit(20); }
/** * 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; }
/** * 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; }