/** * Adds some handy properties to provider object * * @param object com_meego_devprogram_provider object * @return object extended com_meego_devprogram_provider object */ private function extend_provider($object = null) { // q->toggle_readonly(false) does not work so we need a new object $provider = new com_meego_devprogram_provider($object->guid); $provider->read_url = com_meego_devprogram_utils::get_url('provider_read', array('provider_name' => $provider->name)); $provider->update_url = com_meego_devprogram_utils::get_url('provider_update', array('provider_name' => $provider->name)); $provider->delete_url = com_meego_devprogram_utils::get_url('provider_delete', array('provider_name' => $provider->name)); $provider->join_url = com_meego_devprogram_utils::get_url('my_membership_create', array('provider_name' => $provider->name)); // if current user is owner then we can add more goodies $user = com_meego_devprogram_utils::get_current_user(); $provider->number_of_members = false; $mvc = midgardmvc_core::get_instance(); // set the can join flag to true by default $provider->can_join = true; // set management fflag to false by default $provider->can_manage = false; // can current user manage the provider if (com_meego_devprogram_utils::is_current_user_creator_or_admin($object) || com_meego_devprogram_membutils::is_current_user_member_of_provider($object->id)) { $provider->can_manage = true; $provider->can_join = false; // set the url for the membership list page $provider->list_memberships_url = com_meego_devprogram_utils::get_url('provider_members', array('provider_name' => $provider->name)); // set the approved number of members (all but the cancelled ones) of this provider $provider->number_of_members = count(com_meego_devprogram_membutils::get_memberships_by_provider($provider->id)); // set the number of pending membership requests $provider->number_of_members = count(com_meego_devprogram_membutils::get_memberships_by_provider($provider->id)); } // can the provider be deleted; ie. check if provider has devices that belong to open programs $provider->can_not_delete = com_meego_devprogram_provutils::has_provider_devices($object->id); return $provider; }
/** * Adds some handy properties to device object * * @param object com_meego_devprogram_device object * @return object extended com_meego_devprogram_device object */ private function extend_device($object = null) { // q->toggle_readonly(false) does not work so we need a new object $device = new com_meego_devprogram_device($object->guid); $device->read_url = com_meego_devprogram_utils::get_url('device_read', array('device_name' => $device->name)); $device->update_url = com_meego_devprogram_utils::get_url('device_update', array('device_name' => $device->name)); $device->delete_url = com_meego_devprogram_utils::get_url('device_delete', array('device_name' => $device->name)); $mvc = midgardmvc_core::get_instance(); // set the pretty name of the device platform $device->prettyplatform = $mvc->configuration->platforms[$device->platform]; // set the provider of the device $device->providerobject = new com_meego_devprogram_provider($device->provider); return $device; }
/** * Adds some handy properties to program object * * @param object com_meego_devprogram_program object * @return object extended com_meego_devprogram_program object */ private static function extend_program($object = null) { // q->toggle_readonly(false) does not work so we need a new object $program = new com_meego_devprogram_program($object->guid); // set some urls, they can come handy $program->open_programs_url = com_meego_devprogram_utils::get_url('open_programs', array()); $program->read_url = com_meego_devprogram_utils::get_url('program_read', array('program_name' => $program->name)); $program->update_url = com_meego_devprogram_utils::get_url('program_update', array('program_name' => $program->name)); $program->delete_url = com_meego_devprogram_utils::get_url('program_delete', array('program_name' => $program->name)); $program->apply_url = com_meego_devprogram_utils::get_url('my_application_create', array('program_name' => $program->name)); // reformat the duedate value so that templates and controllers don't have to bother $program->deadline = date('Y-m-d', strtotime($program->duedate)); // create a placeholder for applications to this program by the curent user $program->myapps = array(); // if current user is owner then we can add more goodies $user = com_meego_devprogram_utils::get_current_user(); if (is_object($user)) { $program->read_my_url = com_meego_devprogram_utils::get_url('my_program_read', array('program_name' => $program->name)); $program->list_apps_url = com_meego_devprogram_utils::get_url('program_applications', array('program_name' => $program->name)); // set the number of apps (all but the cancelled ones) under this program $program->number_of_applications = com_meego_devprogram_apputils::get_count_applications_by_program($program->id); // gather all apps of this user to this program //$program->myapps = com_meego_devprogram_apputils::get_applications_of_current_user($object->id); } // get the provider of the device and set a new property to the program $devices = com_meego_devprogram_devutils::get_devices(array('id' => $program->device)); $providers = com_meego_devprogram_provutils::get_providers(array('guid' => $devices[0]->providerobject->guid)); $program->provider = $providers[0]; // by default everybody can apply $program->can_apply = true; // current date and time $now = new DateTime(); if ($object->duedate < $now) { // set the flag so we can show a user friendly status box $program->closed = true; } if (com_meego_devprogram_utils::is_current_user_creator($object) || count($program->myapps) && !$object->multiple || $object->duedate < $now) { // owners of a program or admins should not apply for that program // or // if user applied then we disable further applications // unless the program accepts multiple entries from the same person $program->can_apply = false; } return $program; }
/** * 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'] = com_meego_devprogram_progutils::any_open_program_uses_device($this->object->id); $this->data['delete_question'] = $this->mvc->i18n->get('question_device_delete', null, array('device_name' => $this->object->title)); }
/** * 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)); }
/** * Retrieves all but cancelled memberships of the currently loged in user * * @param integer optional parameter to specify a concrete provider * @param integer optional parameter to specify a status of membership * * @return array an array of com_meego_devprogram_provider_membership objects * null if user is not logged in */ public static function get_memberships_of_current_user($provider_id = null, $status = null) { $user = com_meego_devprogram_utils::get_current_user(); if ($user) { $filters = array('person' => $user->person, 'provider' => $provider_id, 'status' => $status); return self::get_memberships($filters); } }
/** * 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 and shows the application approval page * * Access: only owners of the programs can judge applications * * @param array args */ public function get_judge(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->data['provider']->id))) { // not creator of the membership // not owner of the provider // not an administrator // nice try, but sorry, get back to index $this->mvc->head->relocate(com_meego_devprogram_utils::get_url('index', array())); } // we remove the toolbar on the judge form $this->data['membership']->can_manage = false; $this->load_judge_form(); $this->data['form'] = $this->form; unset($this->data['object']); }
/** * Retrieves all but cancelled applications of the currently loged in user * * @param integer optional parameter to specify a concrete program * @return array an array of com_meego_devprogram_application objects * null if user is not logged in */ public static function get_applications_of_current_user($program_id = null) { $user = com_meego_devprogram_utils::get_current_user(); if ($user) { $filters = array('creator' => $user->person, 'program' => $program_id); return self::get_applications($filters); } }