scoredisplayform.class.php 6.2 KB

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