Example #1
0
 public function get_read(array $args)
 {
     parent::get_read($args);
     $this->data['groups'] = array();
     $this->data['is_challenger'] = $this->is_challenger();
     if ($this->data['is_challenger']) {
         $this->data['groups_url'] = midgardmvc_core::get_instance()->dispatcher->generate_url('index', array(), 'fi_openkeidas_groups');
         $this->data['update_url'] = $this->get_url_update();
         $this->data['delete_url'] = midgardmvc_core::get_instance()->dispatcher->generate_url('challenge_delete', array('challenge' => $this->object->guid), $this->request);
     }
     $activityobject = null;
     if ($this->object->activity) {
         $activityobject = fi_openkeidas_diary_activities::get($this->object->activity);
     }
     $this->object->activityobject = $activityobject;
     $this->data['challenger'] = new fi_openkeidas_groups_group($this->object->challenger);
     $mc = new midgard_collector('fi_openkeidas_diary_challenge_participant', 'challenge', $this->object->id);
     //$mc->add_constraint('metadata.isapproved', '=', true);
     $mc->set_key_property('grp');
     $mc->execute();
     $grp_ids = array_keys($mc->list_keys());
     if (count($grp_ids) == 0) {
         return;
     }
     $qb = new midgard_query_builder('fi_openkeidas_groups_group');
     $qb->add_constraint('id', 'IN', $grp_ids);
     $qb->add_order('metadata.score', 'DESC');
     $this->data['groups'] = array_map(function ($group) use($activityobject) {
         $group->url = midgardmvc_core::get_instance()->dispatcher->generate_url('group_read', array('group' => $group->guid), 'fi_openkeidas_groups');
         $group->activity = fi_openkeidas_diary_logs::group_duration_this_week($group, $activityobject);
         return $group;
     }, $qb->execute());
 }
Example #2
0
 public function get_read(array $args)
 {
     parent::get_read($args);
     $this->data['admins'] = array();
     $this->data['is_admin'] = false;
     $qb = new midgard_query_builder('fi_openkeidas_groups_group_member');
     $qb->add_constraint('grp', '=', $this->object->id);
     $qb->add_constraint('admin', '=', true);
     $qb->add_constraint('metadata.isapproved', '=', true);
     $admins = $qb->execute();
     foreach ($admins as $admin) {
         $this->data['admins'][] = new midgard_person($admin->person);
         if ($admin->person == midgardmvc_core::get_instance()->authentication->get_person()->id) {
             $this->data['is_admin'] = true;
         }
     }
     if ($this->data['is_admin']) {
         $this->data['members'] = array();
         $qb = new midgard_query_builder('fi_openkeidas_groups_group_member');
         $qb->add_constraint('grp', '=', $this->object->id);
         $qb->add_constraint('admin', '=', false);
         $members = $qb->execute();
         foreach ($members as $member) {
             $this->data['members'][] = new midgard_person($member->person);
         }
         $this->data['approve_url'] = midgardmvc_core::get_instance()->dispatcher->generate_url('group_join_approve', array('group' => $this->object->guid), $this->request);
     }
     $this->data['is_member'] = $this->is_member();
     $this->data['join_url'] = midgardmvc_core::get_instance()->dispatcher->generate_url('group_join', array('group' => $this->object->guid), $this->request);
     if (!$this->object->autocreated) {
         $this->data['leave_url'] = midgardmvc_core::get_instance()->dispatcher->generate_url('group_leave', array('group' => $this->object->guid), $this->request);
     }
     $this->data['challenges'] = array();
     $mc = new midgard_collector('fi_openkeidas_groups_group_member', 'person', midgardmvc_core::get_instance()->authentication->get_person()->id);
     $mc->add_constraint('metadata.isapproved', '=', true);
     $mc->set_key_property('grp');
     $mc->execute();
     $grp_ids = array_keys($mc->list_keys());
     if (count($grp_ids) == 0) {
         return;
     }
     $qb = new midgard_query_builder('fi_openkeidas_diary_challenge');
     $qb->add_constraint('challenger', 'IN', $grp_ids);
     $qb->add_constraint('challenger', '<>', $this->object->id);
     $qb->add_constraint('enddate', '>', new DateTime());
     $challenges = $qb->execute();
     foreach ($challenges as $challenge) {
         $qb = new midgard_query_builder('fi_openkeidas_diary_challenge_participant');
         $qb->add_constraint('challenge', '=', $challenge->id);
         $qb->add_constraint('grp', '=', $this->object->id);
         if ($qb->count() > 0) {
             continue;
         }
         $challenge->url = midgardmvc_core::get_instance()->dispatcher->generate_url('challenge_challenge', array('challenge' => $challenge->guid, 'group' => $this->object->guid), 'fi_openkeidas_diary');
         $this->data['challenges'][] = $challenge;
     }
 }
Example #3
0
 /**
  * Deletes the device
  * First it makes sure that all expired programs are deleted,
  * otherwise a device can not be deleted if it is assigned to a program
  */
 public function post_delete(array $args)
 {
     # make sure all closed (expired) programs are marked deleted
     # before attempting to delete a device
     com_meego_devprogram_progutils::delete_expired_programs();
     parent::post_delete($args);
 }
Example #4
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']);
 }
Example #5
0
 public function __construct(midgardmvc_core_request $request)
 {
     parent::__construct($request);
     $this->mvc = midgardmvc_core::get_instance();
 }
Example #6
0
 /**
  * Prepares the delete page
  */
 public function get_delete(array $args)
 {
     parent::get_delete($args);
     $this->data['index_url'] = com_meego_devprogram_utils::get_url('index', array());
     $this->data['can_not_delete'] = false;
     $this->data['delete_question'] = $this->mvc->i18n->get('question_program_delete', null, array('program_name' => $this->data['program']->title));
 }
Example #7
0
 public function __construct(midgardmvc_core_request $request)
 {
     parent::__construct($request);
     $this->mvc = midgardmvc_core::get_instance();
     $this->mvc->i18n->set_translation_domain($this->component);
 }
 /**
  * Prepares the update
  */
 public function get_update(array $args)
 {
     $this->load_object($args);
     if (com_meego_devprogram_utils::is_current_user_creator_or_admin($this->object) || com_meego_devprogram_membutils::is_current_user_member_of_provider($this->object->id)) {
         // if creator
         // or admin
         // or good enough member
         parent::get_update($args);
     } else {
         $redirect = com_meego_devprogram_utils::get_url('provider_read', array('provider_name' => $args['provider_name']));
         // redirect to the read page
         $this->mvc->head->relocate($redirect);
     }
 }
 /**
  * Prepares the delete page
  */
 public function get_delete(array $args)
 {
     $this->data['can_not_delete'] = true;
     $this->load_object($args);
     $redirect = com_meego_devprogram_utils::get_url('my_membership_delete', array('membership_guid' => $this->object->guid));
     $user = com_meego_devprogram_utils::require_login($redirect);
     $this->data['person'] = $user->person;
     if (com_meego_devprogram_utils::is_current_user_creator_or_admin($this->object)) {
         parent::get_delete($args);
         $this->data['index_url'] = com_meego_devprogram_utils::get_url('index', array());
         $this->data['can_not_delete'] = false;
         $this->data['delete_question'] = $this->mvc->i18n->get('question_membership_delete', null, array('provider_name' => $this->data['provider']->title));
     } else {
         // nice try...
         $this->mvc->head->relocate(com_meego_devprogram_utils::get_url('index', array()));
     }
 }
Example #10
0
 public function get_read(array $args)
 {
     parent::get_read($args);
     $this->data['class'] = "button row-2 fav";
     $this->data['favs'] = fi_openkeidas_articles_controllers_favourite::count_favourites($this->object->guid);
     // check if the item has already been favourited by this user
     $user_guid = '';
     $results = array();
     if (midgardmvc_core::get_instance()->authentication->is_user()) {
         $user_guid = midgardmvc_core::get_instance()->authentication->get_person()->guid;
         $results = fi_openkeidas_articles_controllers_favourite::load_favourites($user_guid, $this->object->guid);
     }
     $results = fi_openkeidas_articles_controllers_favourite::load_favourites($user_guid, $this->object->guid);
     if (count($results)) {
         // show unfavouriting button
         $this->data['caption'] = midgardmvc_core::get_instance()->i18n->get('unselect', 'fi_openkeidas_articles');
         $this->data['class'] .= " dislike";
         $this->data['url'] = midgardmvc_core::get_instance()->dispatcher->generate_url('item_dislike', array(), $this->request);
     } else {
         // show favouriting button
         $this->data['caption'] = midgardmvc_core::get_instance()->i18n->get('select', 'fi_openkeidas_articles');
         $this->data['class'] .= " like";
         $this->data['url'] = midgardmvc_core::get_instance()->dispatcher->generate_url('item_like', array(), $this->request);
     }
     midgardmvc_core::get_instance()->head->add_jsfile(MIDGARDMVC_STATIC_URL . '/fi_openkeidas_articles/js/buttons.js');
     $this->data['show_title'] = false;
     $this->data['allow_comments'] = false;
     $this->data['allow_favorites'] = midgardmvc_core::get_instance()->authentication->is_user();
     $this->data['articleguid'] = '';
     $this->data['comments'] = array();
     $this->data['postaction'] = '';
     $this->data['relocate'] = '';
     $today = new DateTime('now');
     $today = $today->getTimestamp();
     $start = midgardmvc_core::get_instance()->configuration->commenting_timeframe['start'];
     $end = midgardmvc_core::get_instance()->configuration->commenting_timeframe['end'];
     // check if current date is within the configured time frame
     if ($today >= $start && $today <= $end) {
         // check if current path is enabled for commenting
         foreach (midgardmvc_core::get_instance()->configuration->commenting_paths as $path => $info) {
             $result = substr_compare($this->request->get_path(), $path, 0, strlen($path));
             #echo $this->request->get_path() . ' vs ' . $path . ', result: ' . $result . "\n";
             #ob_flush();
             if ($result == 0) {
                 $this->data['allow_comments'] = true;
             }
         }
         // populate data for the template in case commenting is allowed
         if ($this->data['allow_comments']) {
             $this->data['articleguid'] = $this->object->guid;
             // get comments
             $this->data['comments'] = $this->get_comments($this->data['articleguid']);
             // set the form's action
             $this->data['postaction'] = midgardmvc_core::get_instance()->dispatcher->generate_url('article_comment_create', array('articleguid' => $this->data['articleguid']), 'fi_openkeidas_website');
         }
         // show the "Comments" title only if there are comments,
         // or commenting is allowed
         if (count($this->data['comments']) || $this->data['allow_comments']) {
             $this->data['show_title'] = true;
         }
         // if post successful then relocate here
         $this->data['relocate'] = $this->request->get_path();
     }
     #echo 'path: ' . $this->request->get_path() . ', today: ' . $today . ', start: ' . $start . ', end: ' . $end . "\n";
     #ob_flush();
 }