scoredisplayform.class.php 4.9 KB

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