From 13b8dfce57f333b792604406b0057fd8ff708ea5 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Mon, 16 Dec 2013 16:14:57 +0100 Subject: [PATCH] Minor - format code. --- main/inc/lib/notification.lib.php | 6 +- main/inc/lib/promotion.lib.php | 183 ++++++++++++++++-------------- main/inc/lib/timeline.lib.php | 165 ++++++++++++++++----------- 3 files changed, 195 insertions(+), 159 deletions(-) diff --git a/main/inc/lib/notification.lib.php b/main/inc/lib/notification.lib.php index 3d7e1ec255..dda42100ca 100644 --- a/main/inc/lib/notification.lib.php +++ b/main/inc/lib/notification.lib.php @@ -140,7 +140,7 @@ class Notification extends Model } $user_info = api_get_user_info($user_id); - //Extra field was deleted or removed? Use the default status + // Extra field was deleted or removed? Use the default status. if (empty($setting_info)) { $user_setting = $default_status; } else { @@ -172,7 +172,7 @@ class Notification extends Model } } $params['sent_at'] = api_get_utc_datetime(); - //Saving the notification to be sent some day + // Saving the notification to be sent some day. default: $params['dest_user_id'] = $user_id; $params['dest_mail'] = $user_info['mail']; @@ -190,7 +190,7 @@ class Notification extends Model * Formats the content in order to add the welcome message, the notification preference, etc * @param string the content * @param array result of api_get_user_info() or GroupPortalManager:get_group_data() - * @param string + * @return string * */ public function format_content($content, $sender_info) { diff --git a/main/inc/lib/promotion.lib.php b/main/inc/lib/promotion.lib.php index 345d1ea845..39abfa9be8 100644 --- a/main/inc/lib/promotion.lib.php +++ b/main/inc/lib/promotion.lib.php @@ -13,28 +13,29 @@ require_once 'career.lib.php'; require_once 'fckeditor/fckeditor.php'; define ('PROMOTION_STATUS_ACTIVE', 1); -define ('PROMOTION_STATUS_INACTIVE',0); +define ('PROMOTION_STATUS_INACTIVE', 0); /** * @package chamilo.library */ -class Promotion extends Model { - - var $table; - var $columns = array('id','name','description','career_id','status','created_at','updated_at'); - - public function __construct() { +class Promotion extends Model +{ + public $table; + public $columns = array('id','name','description','career_id','status','created_at','updated_at'); + + public function __construct() + { $this->table = Database::get_main_table(TABLE_PROMOTION); } - + /** * Get the count of elements */ - public function get_count() { - $row = Database::select('count(*) as count', $this->table, array(),'first'); + public function get_count() + { + $row = Database::select('count(*) as count', $this->table, array(), 'first'); return $row['count']; } - - + /** * Copies the promotion to a new one * @param integer Promotion ID @@ -42,54 +43,55 @@ class Promotion extends Model { * @param boolean Whether or not to copy the sessions inside * @return integer New promotion ID on success, false on failure */ - public function copy($id, $career_id = null, $copy_sessions = false) { + public function copy($id, $career_id = null, $copy_sessions = false) + { $pid = false; - $promotion = $this->get($id); - if (!empty($promotion)) { - $new = array(); - foreach ($promotion as $key => $val) { - switch ($key) { - case 'id': - case 'updated_at': - break; - case 'name': - $val .= ' '.get_lang('CopyLabelSuffix'); - $new[$key] = $val; - break; - case 'created_at': - $val = api_get_utc_datetime(); - $new[$key] = $val; - break; - case 'career_id': - if (!empty($career_id)) { - $val = (int)$career_id; - } - $new[$key] = $val; - default: - $new[$key] = $val; - break; - } - } - + $promotion = $this->get($id); + if (!empty($promotion)) { + $new = array(); + foreach ($promotion as $key => $val) { + switch ($key) { + case 'id': + case 'updated_at': + break; + case 'name': + $val .= ' '.get_lang('CopyLabelSuffix'); + $new[$key] = $val; + break; + case 'created_at': + $val = api_get_utc_datetime(); + $new[$key] = $val; + break; + case 'career_id': + if (!empty($career_id)) { + $val = (int)$career_id; + } + $new[$key] = $val; + default: + $new[$key] = $val; + break; + } + } + if ($copy_sessions) { /** * When copying a session we do: * 1. Copy a new session from the source * 2. Copy all courses from the session (no user data, no user list) * 3. Create the promotion - */ + */ $session_list = SessionManager::get_all_sessions_by_promotion($id); - + if (!empty($session_list)) { - $pid = $this->save($new); + $pid = $this->save($new); if (!empty($pid)) { $new_session_list = array(); - + foreach($session_list as $item) { - $sid = SessionManager::copy_session($item['id'], true, false, false, true); + $sid = SessionManager::copy_session($item['id'], true, false, false, true); $new_session_list[] = $sid; } - + if (!empty($new_session_list)) { SessionManager::suscribe_sessions_to_promotion($pid, $new_session_list); } @@ -101,20 +103,26 @@ class Promotion extends Model { } return $pid; } - + /** * Gets all promotions by career id * @param int career id + * @param bool $order * @return array results */ - public function get_all_promotions_by_career_id($career_id, $order = false) { + public function get_all_promotions_by_career_id($career_id, $order = false) + { return Database::select('*', $this->table, array('where'=>array('career_id = ?'=>$career_id),'order' =>$order)); } - - public function get_status_list() { + + /** + * @return array + */ + public function get_status_list() + { return array(PROMOTION_STATUS_ACTIVE => get_lang('Active'), PROMOTION_STATUS_INACTIVE => get_lang('Inactive')); - } - + } + /** * Displays the title + grid * @return string html code @@ -123,44 +131,45 @@ class Promotion extends Model { // action links echo '
'; echo ''.Display::return_icon('back.png',get_lang('Back'),'','32').''; - echo ''.Display::return_icon('new_promotion.png',get_lang('Add'),'','32').''; - echo ''.Display::return_icon('new_session.png',get_lang('AddSession'),'','32').''; + echo ''.Display::return_icon('new_promotion.png',get_lang('Add'),'','32').''; + echo ''.Display::return_icon('new_session.png',get_lang('AddSession'),'','32').''; echo '
'; - echo Display::grid_html('promotions'); + echo Display::grid_html('promotions'); } - + /** * Update all session status by promotion * @param int promotion id * @param int status (1, 0) */ - public function update_all_sessions_status_by_promotion_id($promotion_id, $status) { - $session_list = SessionManager::get_all_sessions_by_promotion($promotion_id); + public function update_all_sessions_status_by_promotion_id($promotion_id, $status) + { + $session_list = SessionManager::get_all_sessions_by_promotion($promotion_id); if (!empty($session_list)) { foreach($session_list as $item) { - SessionManager::set_session_status($item['id'], $status); + SessionManager::set_session_status($item['id'], $status); } } } - - + + /** * Returns a Form validator Obj * @todo the form should be auto generated * @param string url * @param string header name - * @return obj form validator obj + * @return obj form validator obj */ - - function return_form($url, $action = 'add') { - + + function return_form($url, $action = 'add') + { $oFCKeditor = new FCKeditor('description') ; $oFCKeditor->ToolbarSet = 'careers'; $oFCKeditor->Width = '100%'; $oFCKeditor->Height = '200'; $oFCKeditor->Value = ''; - $oFCKeditor->CreateHtml(); - + $oFCKeditor->CreateHtml(); + $form = new FormValidator('promotion', 'post', $url); // Settting the form elements $header = get_lang('Add'); @@ -168,31 +177,31 @@ class Promotion extends Model { $header = get_lang('Modify'); } $id = isset($_GET['id']) ? intval($_GET['id']) : ''; - + $form->addElement('header', '', $header); $form->addElement('hidden', 'id', $id); - $form->addElement('text', 'name', get_lang('Name'), array('size' => '70','id' => 'name')); - $form->add_html_editor('description', get_lang('Description'), false, false, array('ToolbarSet' => 'careers','Width' => '100%', 'Height' => '250')); + $form->addElement('text', 'name', get_lang('Name'), array('size' => '70','id' => 'name')); + $form->add_html_editor('description', get_lang('Description'), false, false, array('ToolbarSet' => 'careers','Width' => '100%', 'Height' => '250')); $career = new Career(); $careers = $career->get_all(); - $career_list = array(); - foreach($careers as $item) { + $career_list = array(); + foreach($careers as $item) { $career_list[$item['id']] = $item['name']; } $form->addElement('select', 'career_id', get_lang('Career'), $career_list); - - $status_list = $this->get_status_list(); + + $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'); - } + } if ($action == 'edit') { $form->addElement('style_submit_button', 'submit', get_lang('Modify'), 'class="save"'); } else { $form->addElement('style_submit_button', 'submit', get_lang('Add'), 'class="save"'); } - + // Setting the defaults $defaults = $this->get($id); if (!empty($defaults['created_at'])) { @@ -200,31 +209,31 @@ class Promotion extends Model { } if (!empty($defaults['updated_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; } - - public function save($params, $show_query = false) { + + public function save($params, $show_query = false) + { $id = parent::save($params, $show_query); if (!empty($id)) { event_system(LOG_PROMOTION_CREATE, LOG_PROMOTION_ID, $id, api_get_utc_datetime(), api_get_user_id()); } - return $id; + return $id; } - - public function delete($id) { + + public function delete($id) + { if (parent::delete($id)) { SessionManager::clear_session_ref_promotion($id); event_system(LOG_PROMOTION_DELETE, LOG_PROMOTION_ID, $id, api_get_utc_datetime(), api_get_user_id()); } else { return false; - } + } } - - } diff --git a/main/inc/lib/timeline.lib.php b/main/inc/lib/timeline.lib.php index 16af420164..89c78ea751 100644 --- a/main/inc/lib/timeline.lib.php +++ b/main/inc/lib/timeline.lib.php @@ -10,85 +10,97 @@ */ define('TIMELINE_STATUS_ACTIVE', '1'); define('TIMELINE_STATUS_INACTIVE', '2'); + /** * Timeline model class definition */ -class Timeline extends Model { - var $table; - var $columns = array('headline', 'type', 'start_date', 'end_date', 'text', 'media', 'media_credit', 'media_caption', 'title_slide', 'parent_id', 'status','c_id'); - var $is_course_model = true; - - public function __construct() { +class Timeline extends Model +{ + public $table; + public $columns = array('headline', 'type', 'start_date', 'end_date', 'text', 'media', 'media_credit', 'media_caption', 'title_slide', 'parent_id', 'status','c_id'); + public $is_course_model = true; + + public function __construct() + { $this->table = Database::get_course_table(TABLE_TIMELINE); - } - + } + /** * Get the count of elements */ - public function get_count() { + public function get_count() + { $course_id = api_get_course_int_id(); $row = Database::select('count(*) as count', $this->table, array('where' => array('parent_id = ? AND c_id = ?' => array('0', $course_id))), 'first'); return $row['count']; - } - - public function get_all($where_conditions = array()) { + } + + /** + * @param array $where_conditions + * @return array + */ + public function get_all($where_conditions = array()) + { return Database::select('*',$this->table, array('where'=>$where_conditions,'order' =>'headline ASC')); } - + /** * Displays the title + grid */ - public function listing() { + public function listing() + { // action links - $html .= '
'; - //$html .= ''.Display::return_icon('back.png',get_lang('Back'),'','32').''; - $html .= ''.Display::return_icon('add.png', get_lang('Add'),'','32').''; + $html = ''; - $html .= Display::grid_html('timelines'); + $html .= Display::grid_html('timelines'); return $html; } - - public function get_status_list() { + + public function get_status_list() + { return array(TIMELINE_STATUS_ACTIVE => get_lang('Active'), TIMELINE_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 + * @return obj form validator obj */ - public function return_form($url, $action) { + public function return_form($url, $action) + { $form = new FormValidator('timeline', 'post', $url); // Setting the form elements - $header = get_lang('Add'); + $header = get_lang('Add'); if ($action == 'edit') { $header = get_lang('Modify'); - } + } $form->addElement('header', $header); $id = isset($_GET['id']) ? intval($_GET['id']) : ''; $form->addElement('hidden', 'id', $id); - + $form->addElement('text', 'headline', get_lang('Name'), array('size' => '70')); - //$form->add_html_editor('description', get_lang('Description'), false, false, array('ToolbarSet' => 'careers','Width' => '100%', 'Height' => '250')); - $status_list = $this->get_status_list(); + //$form->add_html_editor('description', get_lang('Description'), false, false, array('ToolbarSet' => 'careers','Width' => '100%', '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'); - } + } if ($action == 'edit') { $form->addElement('style_submit_button', 'submit', get_lang('Modify'), 'class="save"'); } else { $form->addElement('style_submit_button', 'submit', get_lang('Add'), 'class="save"'); } - + $form->addRule('headline', get_lang('ThisFieldIsRequired'), 'required'); - + // Setting the defaults $defaults = $this->get($id); - + /*if (!empty($defaults['created_at'])) { $defaults['created_at'] = api_convert_and_format_date($defaults['created_at']); } @@ -96,27 +108,33 @@ class Timeline extends Model { $defaults['updated_at'] = api_convert_and_format_date($defaults['updated_at']); }*/ $form->setDefaults($defaults); - + // Setting the rules - $form->addRule('headline', get_lang('ThisFieldIsRequired'), 'required'); - return $form; + $form->addRule('headline', get_lang('ThisFieldIsRequired'), 'required'); + return $form; } - - public function return_item_form($url, $action) { - + + /** + * @param $url + * @param $action + * @return FormValidator + */ + public function return_item_form($url, $action) + { + $form = new FormValidator('item_form', 'post', $url); // Settting the form elements - $header = get_lang('Add'); + $header = get_lang('Add'); if ($action == 'edit') { $header = get_lang('Modify'); - } + } $form->addElement('header', $header); $id = isset($_GET['id']) ? intval($_GET['id']) : ''; $parent_id = isset($_GET['parent_id']) ? intval($_GET['parent_id']) : ''; - $form->addElement('hidden', 'parent_id', $parent_id); + $form->addElement('hidden', 'parent_id', $parent_id); $form->addElement('hidden', 'id', $id); $form->addElement('text', 'headline', get_lang('Name'), array('class' => 'span4')); - + //@todo fix this $form->addElement('text', 'start_date', get_lang('StartDate'), array('size' => '70')); $form->addElement('text', 'end_date', get_lang('EndDate'), array('size' => '70')); @@ -125,13 +143,13 @@ class Timeline extends Model { $form->addElement('text', 'media_caption', get_lang('TimelineItemMediaCaption'), array('size' => '70')); $form->addElement('text', 'media_credit', get_lang('TimelineItemMediaCredit'), array('size' => '70')); $form->addElement('text', 'title_slide', get_lang('TimelineItemTitleSlide'), array('size' => '70')); - + $form->addRule('headline', get_lang('ThisFieldIsRequired'), 'required'); $form->addRule('start_date', get_lang('ThisFieldIsRequired'), 'required'); - - - //$form->add_html_editor('description', get_lang('Description'), false, false, array('ToolbarSet' => 'careers','Width' => '100%', 'Height' => '250')); - + + + //$form->add_html_editor('description', get_lang('Description'), false, false, array('ToolbarSet' => 'careers','Width' => '100%', 'Height' => '250')); + if ($action == 'edit') { // Setting the defaults $defaults = $this->get($id); @@ -139,7 +157,7 @@ class Timeline extends Model { } else { $form->addElement('style_submit_button', 'submit', get_lang('Add'), 'class="save"'); } - + /*if (!empty($defaults['created_at'])) { $defaults['created_at'] = api_convert_and_format_date($defaults['created_at']); } @@ -147,22 +165,31 @@ class Timeline extends Model { $defaults['updated_at'] = api_convert_and_format_date($defaults['updated_at']); }*/ $form->setDefaults($defaults); - + // Setting the rules - $form->addRule('headline', get_lang('ThisFieldIsRequired'), 'required'); - return $form; - + $form->addRule('headline', get_lang('ThisFieldIsRequired'), 'required'); + return $form; + } - - public function save_item($params) { - $params['c_id'] = api_get_course_int_id(); + + /** + * @param array $params + * @return bool + */ + public function save_item($params) + { + $params['c_id'] = api_get_course_int_id(); $id = parent::save($params); if (!empty($id)) { //event_system(LOG_CAREER_CREATE, LOG_CAREER_ID, $id, api_get_utc_datetime(), api_get_user_id()); } - return $id; + return $id; } - + + /** + * @param array $params + * @return bool + */ public function save($params) { $params['c_id'] = api_get_course_int_id(); $params['parent_id'] = '0'; @@ -173,25 +200,25 @@ class Timeline extends Model { } return $id; } - + public function delete($id) { parent::delete($id); //event_system(LOG_CAREER_DELETE, LOG_CAREER_ID, $id, api_get_utc_datetime(), api_get_user_id()); } - + public function get_url($id) { return api_get_path(WEB_AJAX_PATH).'timeline.ajax.php?a=get_timeline_content&id='.intval($id); } - + public function get_timeline_content($id) { $timeline = array(); $course_id = api_get_course_int_id(); - $timeline['timeline'] = $this->process_item($this->get($id)); - $items = $this->process_items($this->get_all(array('parent_id = ? AND c_id = ? ' =>array($id, $course_id)))); + $timeline['timeline'] = $this->process_item($this->get($id)); + $items = $this->process_items($this->get_all(array('parent_id = ? AND c_id = ? ' =>array($id, $course_id)))); $timeline['timeline']['date'] = $items; return $timeline; } - + function process_items($items) { foreach ($items as &$item) { $item = $this->process_item($item); @@ -208,15 +235,15 @@ class Timeline extends Model { if (!empty($item['end_date'])) { $item['endDate'] = $item['end_date']; } else { - unset($item['endDate']); + unset($item['endDate']); } unset($item['end_date']); // Assets $item['asset'] = array( 'media' => $item['media'], - 'credit' => $item['media_credit'], - 'caption' => $item['media_caption'], + 'credit' => $item['media_credit'], + 'caption' => $item['media_caption'], ); - + //Cleaning items unset($item['id']); if (empty($item['type'])) { @@ -227,8 +254,8 @@ class Timeline extends Model { unset($item['media_caption']); unset($item['status']); unset($item['title_slide']); - unset($item['parent_id']); + unset($item['parent_id']); unset($item['c_id']); - return $item; + return $item; } }