scoredisplayform.class.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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(
  44. 'text',
  45. 'scorecolpercent',
  46. array(get_lang('Below'), get_lang('WillColorRed'), '%'),
  47. array(
  48. 'size' => 5,
  49. 'maxlength' => 5,
  50. 'input-size' => 2,
  51. )
  52. );
  53. if (api_get_setting('teachers_can_change_score_settings') != 'true') {
  54. $this->freeze('scorecolpercent');
  55. }
  56. $this->addRule('scorecolpercent', get_lang('OnlyNumbers'), 'numeric');
  57. $this->addRule(array('scorecolpercent', 'maxvalue'), get_lang('Over100'), 'compare', '<=');
  58. $this->addRule(array('scorecolpercent', 'minvalue'), get_lang('UnderMin'), 'compare', '>');
  59. }
  60. //Settings for the scoring system
  61. if ($displayscore->is_custom()) {
  62. $this->addElement('html', '<br /><b>'.get_lang('ScoringSystem').'</b>');
  63. $this->addElement('static', null, null, get_lang('ScoreInfo'));
  64. $this->setDefaults(array(
  65. 'beginscore' => '0'
  66. ));
  67. $this->addElement('text', 'beginscore', array(get_lang('Between'), null, '%'), array(
  68. 'size' => 5,
  69. 'maxlength' => 5,
  70. 'disabled' => 'disabled',
  71. 'input-size' => 2
  72. ));
  73. for ($counter = 1; $counter <= 20; $counter++) {
  74. $renderer = & $this->defaultRenderer();
  75. $elementTemplateTwoLabel =
  76. '<div id='.$counter.' style="display: '.(($counter <= $nr_items) ? 'inline' : 'none').';">
  77. <!-- BEGIN required --><span class="form_required">*</span> <!-- END required -->
  78. <label class="control-label">{label}</label>
  79. <div class="form-group">
  80. <label class="col-sm-2 control-label">
  81. </label>
  82. <div class="col-sm-1">
  83. <!-- BEGIN error --><span class="form_error">{error}</span><br />
  84. <!-- END error -->&nbsp<b>'.get_lang('And').'</b>
  85. </div>
  86. <div class="col-sm-2">
  87. {element}
  88. </div>
  89. <div class="col-sm-1">
  90. =
  91. </div>
  92. ';
  93. $elementTemplateTwoLabel2 = '
  94. <div class="col-sm-2">
  95. <!-- BEGIN error --><span class="form_error">{error}</span>
  96. <!-- END error -->
  97. {element}
  98. </div>
  99. <div class="col-sm-1">
  100. <a href="javascript:plusItem(' . ($counter + 1).')">
  101. <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>
  102. <a href="javascript:minItem(' . ($counter).')">
  103. <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>
  104. </div>
  105. </div>
  106. </div>';
  107. $scorebetw = array();
  108. $this->addElement('text', 'endscore['.$counter.']', null, array(
  109. 'size' => 5,
  110. 'maxlength' => 5,
  111. 'id' => 'txta-'.$counter,
  112. 'input-size' => 2
  113. ));
  114. $this->addElement(
  115. 'text',
  116. 'displaytext['.$counter.']',
  117. null,
  118. array(
  119. 'size' => 40,
  120. 'maxlength' => 40,
  121. 'id' => 'txtb-'.$counter,
  122. )
  123. );
  124. $renderer->setElementTemplate($elementTemplateTwoLabel, 'endscore['.$counter.']');
  125. $renderer->setElementTemplate($elementTemplateTwoLabel2, 'displaytext['.$counter.']');
  126. $this->addRule('endscore['.$counter.']', get_lang('OnlyNumbers'), 'numeric');
  127. $this->addRule(array('endscore['.$counter.']', 'maxvalue'), get_lang('Over100'), 'compare', '<=');
  128. $this->addRule(array('endscore['.$counter.']', 'minvalue'), get_lang('UnderMin'), 'compare', '>');
  129. }
  130. }
  131. if ($displayscore->is_custom()) {
  132. $this->addButtonSave(get_lang('Ok'));
  133. }
  134. }
  135. public function validate()
  136. {
  137. return parent::validate();
  138. }
  139. }