/** * 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 and shows the list of application for a certain program (cmd-list-application) * * Access: only owners of the program can list the applications * * @param array args (not used) */ public function get_applications_for_program(array $args) { $this->load_object($args); // admin of the program or belongs to the same provider 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->provider->id)) { $this->data['index_url'] = com_meego_devprogram_utils::get_url('index', array()); $this->data['applications'] = com_meego_devprogram_apputils::get_applications_by_program($this->object->id); } else { // nice try, redirect to standard read page $this->relocate_to_read(); } }
/** * Prepares the application page * * @param array args */ public function get_create(array $args) { if (!strlen($args['program_name'])) { $url = com_meego_devprogram_utils::get_url('index', $args); $this->mvc->head->relocate($url); } // require login $redirect = com_meego_devprogram_utils::get_url('my_application_create', $args); $user = com_meego_devprogram_utils::require_login($redirect); // @todo: sanity check $programs = com_meego_devprogram_progutils::get_programs(array('name' => $args['program_name'])); $program = $programs[0]; if (!is_object($program)) { throw new InvalidArgumentException("Program: {$args['program_name']} con not be found"); } $this->data['program'] = $program; // check if the user has applied for the program and // display a warning if yes // in case of multiple applications we only refer to the 1st $this->data['myapps'] = com_meego_devprogram_apputils::get_applications_of_current_user($program->id); $now = new DateTime(); if ($program->duedate >= $now && (!count($this->data['myapps']) || $program->multiple)) { // we move on if user has not applied or // the program accepts multiple entries from the same person parent::get_create($args); } // load the text limiter js files $this->mvc->head->add_jsfile(MIDGARDMVC_STATIC_URL . '/' . $this->component . '/js/textLimit.js'); $this->mvc->head->add_jsfile(MIDGARDMVC_STATIC_URL . '/' . $this->component . '/js/limiter_for_applications.js'); }