scoredisplayform.class.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Class ScoreDisplayForm
  5. * Form for the score display dialog
  6. * @author Stijn Konings
  7. * @author Bert Steppé
  8. * @package chamilo.gradebook
  9. */
  10. class ScoreDisplayForm extends FormValidator
  11. {
  12. /**
  13. * @param $form_name
  14. * @param null $action
  15. */
  16. public function __construct($form_name, $action= null)
  17. {
  18. parent :: __construct($form_name, 'post', $action);
  19. $displayscore = ScoreDisplay :: instance();
  20. $customdisplays = $displayscore->get_custom_score_display_settings();
  21. $nr_items = (count($customdisplays)!='0') ? count($customdisplays) : '1';
  22. $this->setDefaults(array (
  23. 'scorecolpercent' => $displayscore->get_color_split_value()
  24. ));
  25. $this->addElement('hidden', 'maxvalue', '100');
  26. $this->addElement('hidden', 'minvalue', '0');
  27. $counter= 1;
  28. //setting the default values
  29. if(is_array($customdisplays)) {
  30. foreach ($customdisplays as $customdisplay) {
  31. $this->setDefaults(array (
  32. 'endscore[' . $counter . ']' => $customdisplay['score'],
  33. 'displaytext[' . $counter . ']' => $customdisplay['display']
  34. ));
  35. $counter++;
  36. }
  37. }
  38. $scorecol = array();
  39. //settings for the colored score
  40. $this->addElement('header', get_lang('ScoreEdit'));
  41. if ($displayscore->is_coloring_enabled()) {
  42. $this->addElement('html', '<b>' . get_lang('ScoreColor') . '</b>');
  43. $this->addElement('text', 'scorecolpercent', array(get_lang('Below'), get_lang('WillColorRed'), '%'), array(
  44. 'size' => 5,
  45. 'maxlength' => 5,
  46. 'input-size' => 2
  47. ));
  48. if (api_get_setting(
  49. 'gradebook.teachers_can_change_score_settings'
  50. ) != 'true'
  51. ) {
  52. $this->freeze('scorecolpercent');
  53. }
  54. $this->addRule('scorecolpercent', get_lang('OnlyNumbers'), 'numeric');
  55. $this->addRule(array('scorecolpercent','maxvalue'), get_lang('Over100'), 'compare', '<=');
  56. $this->addRule(array('scorecolpercent','minvalue'), get_lang('UnderMin'), 'compare', '>');
  57. }
  58. //Settings for the scoring system
  59. if ($displayscore->is_custom()) {
  60. $this->addElement('html', '<br /><b>' . get_lang('ScoringSystem') . '</b>');
  61. $this->addElement('static', null, null, get_lang('ScoreInfo'));
  62. $this->setDefaults(array(
  63. 'beginscore' => '0'
  64. ));
  65. $this->addElement('text', 'beginscore', array(get_lang('Between'), null, '%'), array(
  66. 'size' => 5,
  67. 'maxlength' => 5,
  68. 'disabled' => 'disabled',
  69. 'input-size' => 2
  70. ));
  71. for ($counter= 1; $counter <= 20; $counter++) {
  72. $renderer =& $this->defaultRenderer();
  73. $elementTemplateTwoLabel =
  74. '<div id=' . $counter . ' style="display: '.(($counter<=$nr_items)?'inline':'none').';">
  75. <!-- BEGIN required --><span class="form_required">*</span> <!-- END required -->
  76. <label class="control-label">{label}</label>
  77. <div class="form-group">
  78. <label class="col-sm-2 control-label">
  79. </label>
  80. <div class="col-sm-1">
  81. <!-- BEGIN error --><span class="form_error">{error}</span><br />
  82. <!-- END error -->&nbsp<b>'.get_lang('And').'</b>
  83. </div>
  84. <div class="col-sm-2">
  85. {element}
  86. </div>
  87. <div class="col-sm-1">
  88. =
  89. </div>
  90. ';
  91. $elementTemplateTwoLabel2 ='
  92. <div class="col-sm-2">
  93. <!-- BEGIN error --><span class="form_error">{error}</span>
  94. <!-- END error -->
  95. {element}
  96. </div>
  97. <div class="col-sm-1">
  98. <a href="javascript:plusItem(' . ($counter+1) . ')">
  99. <img style="display: '.(($counter>=$nr_items)?'inline':'none').';" id="plus-' . ($counter+1) . '" src="'.Display::returnIconPath('add.png').'" alt="'.get_lang('Add').'" title="'.get_lang('Add').'"></a>
  100. <a href="javascript:minItem(' . ($counter) . ')">
  101. <img style="display: '.(($counter>=$nr_items && $counter!=1)?'inline':'none').';" id="min-' . $counter . '" src="'.Display::returnIconPath('delete.png').'" alt="'.get_lang('Delete').'" title="'.get_lang('Delete').'"></a>
  102. </div>
  103. </div>
  104. </div>';
  105. $scorebetw = array();
  106. $this->addElement('text', 'endscore[' . $counter . ']', null, array (
  107. 'size' => 5,
  108. 'maxlength' => 5,
  109. 'id' => 'txta-'.$counter,
  110. 'input-size' => 2
  111. ));
  112. $this->addElement('text', 'displaytext[' . $counter . ']', null,array (
  113. 'size' => 40,
  114. 'maxlength' => 40,
  115. 'id' => 'txtb-'.$counter
  116. ));
  117. $renderer->setElementTemplate($elementTemplateTwoLabel, 'endscore[' . $counter . ']');
  118. $renderer->setElementTemplate($elementTemplateTwoLabel2, 'displaytext[' . $counter . ']');
  119. $this->addRule('endscore[' . $counter . ']', get_lang('OnlyNumbers'), 'numeric');
  120. $this->addRule(array ('endscore[' . $counter . ']', 'maxvalue'), get_lang('Over100'), 'compare', '<=');
  121. $this->addRule(array ('endscore[' . $counter . ']', 'minvalue'), get_lang('UnderMin'), 'compare', '>');
  122. }
  123. }
  124. if ($displayscore->is_custom()) {
  125. $this->addButtonSave(get_lang('Ok'));
  126. }
  127. }
  128. function validate() {
  129. return parent :: validate();
  130. }
  131. }