table = Database::get_main_table(TABLE_CAREER); } public function get_all($where_conditions = array()) { return Database::select('*',$this->table, array('where'=>$where_conditions,'order' =>'name ASC')); } /** * Update all promotion status by career * @param int career id * @param int status (1 or 0) */ public function update_all_promotion_status_by_career_id($career_id, $status) { $promotion = new Promotion(); $promotion_list = $promotion->get_all_promotions_by_career_id($career_id); if (!empty($promotion_list)) { foreach($promotion_list as $item) { $params['id'] = $item['id']; $params['status'] = $status; $promotion->update($params); $promotion->update_all_sessions_status_by_promotion_id($params['id'], $status); } } } /** * Displays the title + grid */ public function display() { // action links echo '
'; echo ''.Display::return_icon('back.png',get_lang('Back')).get_lang('Back').''; echo ''.Display::return_icon('filenew.gif',get_lang('Add')).get_lang('Add').''; echo '
'; echo Display::grid_html('careers'); } public function get_status_list() { return array(CAREER_STATUS_ACTIVE => get_lang('Active'), CAREER_STATUS_INACTIVE => get_lang('Inactive')); } /** * Returns a Form validator Obj * @todo the form should be auto generated * @param string url * @param string action add, edit * @return obj form validator obj */ public function return_form($url, $action) { $form = new FormValidator('career', 'post', $url); // Settting the form elements $header = get_lang('add'); if ($action == 'edit') { $header = get_lang('Modify'); } $form->addElement('header', '', $header); $form->addElement('hidden', 'id',intval($_GET['id'])); $form->addElement('text', 'name', get_lang('Name'), array('size' => '70')); $form->add_html_editor('description', get_lang('Description'), false, false, array('Width' => '95%', 'Height' => '250')); $status_list = $this->get_status_list(); $form->addElement('select', 'status', get_lang('Status'), $status_list); if ($action == 'edit') { $form->addElement('text', 'created_at', get_lang('CreatedAt')); $form->freeze('created_at'); } $form->addElement('style_submit_button', 'submit', get_lang('Modify'), 'class="save"'); // Setting the defaults $defaults = $this->get($_GET['id']); $defaults['created_at'] = api_convert_and_format_date($defaults['created_at']); $defaults['updated_at'] = api_convert_and_format_date($defaults['updated_at']); $form->setDefaults($defaults); // Setting the rules $form->addRule('name', '
'.get_lang('ThisFieldIsRequired'), 'required'); return $form; } /** * Copies the career to a new one * @param integer Career ID * @return integer New career ID on success, false on failure */ public function copy($id) { $career = $this->get($id); $new = array(); foreach ($career as $key => $val) { switch ($key) { case 'id': case 'updated_at': break; case 'name': $val .= ' '.get_lang('Copy'); $new[$key] = $val; break; case 'created_at': $val = api_get_utc_datetime(); $new[$key] = $val; break; default: $new[$key] = $val; break; } } $cid = $this->save($new); //Now also copy each session of the promotion as a new session and register it inside the promotion $promotion = new Promotion(); $promo_list = $promotion->get_all_promotions_by_career_id($id); if (!empty($promo_list)) { foreach($promo_list as $item) { $pid = $promotion->copy($item['id'], $cid); } } return $cid; } }