promotion.lib.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This class provides methods for the promotion management.
  5. * Include/require it in your code to use its features.
  6. * @package chamilo.library
  7. */
  8. require_once 'model.lib.php';
  9. require_once 'career.lib.php';
  10. define ('PROMOTION_STATUS_ACTIVE', 1);
  11. define ('PROMOTION_STATUS_INACTIVE',0);
  12. class Promotion extends Model {
  13. var $table;
  14. var $columns = array('id','name','description','career_id','status','created_at','updated_at');
  15. public function __construct() {
  16. $this->table = Database::get_main_table(TABLE_PROMOTION);
  17. }
  18. /**
  19. * Gets all promotions by career id
  20. * @param int career id
  21. * @return array results
  22. */
  23. public function get_all_promotions_by_career_id($career_id) {
  24. return Database::select('*', $this->table, array('where'=>array('career_id = ?'=>$career_id)));
  25. }
  26. public function get_status_list() {
  27. return array(PROMOTION_STATUS_ACTIVE => get_lang('Active'), PROMOTION_STATUS_INACTIVE => get_lang('Inactive'));
  28. }
  29. /**
  30. * Displays the title + grid
  31. * @return string html code
  32. */
  33. function display() {
  34. // action links
  35. echo '<div class="actions" style="margin-bottom:20px">';
  36. echo '<a href="career_dashboard.php">'.Display::return_icon('back.png',get_lang('Back')).get_lang('Back').'</a>';
  37. echo '<a href="'.api_get_self().'?action=add">'.Display::return_icon('filenew.gif',get_lang('Add')).get_lang('Add').'</a>';
  38. echo '</div>';
  39. echo Display::grid_html('promotions');
  40. }
  41. /**
  42. * Update all session status by promotion
  43. * @param int promotion id
  44. * @param int status (1, 0)
  45. */
  46. public function update_all_sessions_status_by_promotion_id($promotion_id, $status) {
  47. require_once api_get_path(LIBRARY_PATH).'sessionmanager.lib.php';
  48. $session_list = SessionManager::get_all_sessions_by_promotion($promotion_id);
  49. if (!empty($session_list)) {
  50. foreach($session_list as $item) {
  51. SessionManager::set_session_status($item['id'], $status);
  52. }
  53. }
  54. }
  55. /**
  56. * Returns a Form validator Obj
  57. * @todo the form should be auto generated
  58. * @param string url
  59. * @param string header name
  60. * @return obj form validator obj
  61. */
  62. function return_form($url, $action = 'add') {
  63. $form = new FormValidator('promotion', 'post', $url);
  64. // Settting the form elements
  65. $header = get_lang('Add');
  66. if ($action == 'edit') {
  67. $header = get_lang('Modify');
  68. }
  69. $form->addElement('header', '', $header);
  70. $form->addElement('hidden', 'id', intval($_GET['id']));
  71. $form->addElement('text', 'name', get_lang('Name'), array('size' => '100','id' => 'name'));
  72. $form->addElement('html_editor', 'description', get_lang('Description'), true, array('ToolbarSet'=>'Forum','Height'=>'150'));
  73. $career = new Career();
  74. $careers = $career->get_all();
  75. $career_list = array();
  76. foreach($careers as $item) {
  77. $career_list[$item['id']] = $item['name'];
  78. }
  79. $form->addElement('select', 'career_id', get_lang('Career'), $career_list);
  80. $status_list = $this->get_status_list();
  81. $form->addElement('select', 'status', get_lang('Status'), $status_list);
  82. if ($action == 'edit') {
  83. $form->addElement('text', 'created_at', get_lang('CreatedAt'));
  84. $form->freeze('created_at');
  85. }
  86. $form->addElement('style_submit_button', 'submit', get_lang('Modify'), 'class="save"');
  87. // Setting the defaults
  88. $defaults = $this->get($_GET['id']);
  89. $defaults['created_at'] = api_convert_and_format_date($defaults['created_at']);
  90. $defaults['updated_at'] = api_convert_and_format_date($defaults['updated_at']);
  91. $form->setDefaults($defaults);
  92. // Setting the rules
  93. $form->addRule('name', '<div class="required">'.get_lang('ThisFieldIsRequired'), 'required');
  94. return $form;
  95. }
  96. }