evalform.class.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Class EvalForm.
  5. *
  6. * Extends FormValidator with add&edit forms for evaluations
  7. *
  8. * @author Stijn Konings
  9. *
  10. * @package chamilo.gradebook
  11. */
  12. class EvalForm extends FormValidator
  13. {
  14. const TYPE_ADD = 1;
  15. const TYPE_EDIT = 2;
  16. const TYPE_MOVE = 3;
  17. const TYPE_RESULT_ADD = 4;
  18. const TYPE_RESULT_EDIT = 5;
  19. const TYPE_ALL_RESULTS_EDIT = 6;
  20. const TYPE_ADD_USERS_TO_EVAL = 7;
  21. protected $evaluation_object;
  22. private $result_object;
  23. private $extra;
  24. /**
  25. * Builds a form containing form items based on a given parameter.
  26. *
  27. * @param int $form_type 1=add, 2=edit,3=move,4=result_add
  28. * @param Evaluation $evaluation_object the category object
  29. * @param obj $result_object the result object
  30. * @param string $form_name
  31. * @param string $method
  32. * @param string $action
  33. */
  34. public function __construct(
  35. $form_type,
  36. $evaluation_object,
  37. $result_object,
  38. $form_name,
  39. $method = 'post',
  40. $action = null,
  41. $extra1 = null,
  42. $extra2 = null
  43. ) {
  44. parent::__construct($form_name, $method, $action);
  45. if (isset($evaluation_object)) {
  46. $this->evaluation_object = $evaluation_object;
  47. }
  48. if (isset($result_object)) {
  49. $this->result_object = $result_object;
  50. }
  51. if (isset($extra1)) {
  52. $this->extra = $extra1;
  53. }
  54. switch ($form_type) {
  55. case self::TYPE_EDIT:
  56. $this->build_editing_form();
  57. break;
  58. case self::TYPE_ADD:
  59. $this->build_add_form();
  60. break;
  61. case self::TYPE_MOVE:
  62. $this->build_editing_form();
  63. break;
  64. case self::TYPE_RESULT_ADD:
  65. $this->build_result_add_form();
  66. break;
  67. case self::TYPE_RESULT_EDIT:
  68. $this->build_result_edit_form();
  69. break;
  70. case self::TYPE_ALL_RESULTS_EDIT:
  71. $this->build_all_results_edit_form();
  72. break;
  73. case self::TYPE_ADD_USERS_TO_EVAL:
  74. $this->build_add_user_to_eval();
  75. break;
  76. }
  77. $this->setDefaults();
  78. }
  79. public function display()
  80. {
  81. parent::display();
  82. }
  83. public function setDefaults($defaults = [], $filter = null)
  84. {
  85. parent::setDefaults($defaults, $filter);
  86. }
  87. public function sort_by_user($item1, $item2)
  88. {
  89. $user1 = $item1['user'];
  90. $user2 = $item2['user'];
  91. if (api_sort_by_first_name()) {
  92. $result = api_strcmp($user1['firstname'], $user2['firstname']);
  93. if ($result == 0) {
  94. return api_strcmp($user1['lastname'], $user2['lastname']);
  95. }
  96. } else {
  97. $result = api_strcmp($user1['lastname'], $user2['lastname']);
  98. if ($result == 0) {
  99. return api_strcmp($user1['firstname'], $user2['firstname']);
  100. }
  101. }
  102. return $result;
  103. }
  104. /**
  105. * This form will build a form to add users to an evaluation.
  106. */
  107. protected function build_add_user_to_eval()
  108. {
  109. $this->addElement('header', get_lang('Choose users for this evaluation'));
  110. $select = $this->addElement(
  111. 'select',
  112. 'firstLetterUser',
  113. get_lang('First letter'),
  114. null,
  115. [
  116. 'onchange' => 'document.add_users_to_evaluation.submit()',
  117. ]
  118. );
  119. $select->addOption('', '');
  120. for ($i = 65; $i <= 90; $i++) {
  121. $letter = chr($i);
  122. if (isset($this->extra) && $this->extra == $letter) {
  123. $select->addOption($letter, $letter, 'selected');
  124. } else {
  125. $select->addOption($letter, $letter);
  126. }
  127. }
  128. $select = $this->addElement(
  129. 'select',
  130. 'add_users',
  131. null,
  132. null,
  133. [
  134. 'multiple' => 'multiple',
  135. 'size' => '15',
  136. 'style' => 'width:250px',
  137. ]
  138. );
  139. foreach ($this->evaluation_object->get_not_subscribed_students() as $user) {
  140. if ((!isset($this->extra)) || empty($this->extra) || api_strtoupper(api_substr($user[1], 0, 1)) == $this->extra
  141. ) {
  142. $select->addoption($user[1].' '.$user[2].' ('.$user[3].')', $user[0]);
  143. }
  144. }
  145. $this->addButtonCreate(get_lang('Add users to evaluation'), 'submit_button');
  146. }
  147. /**
  148. * This function builds a form to edit all results in an evaluation.
  149. */
  150. protected function build_all_results_edit_form()
  151. {
  152. //extra field for check on maxvalue
  153. $this->addElement('header', get_lang('Grade learners'));
  154. $renderer = &$this->defaultRenderer();
  155. // set new form template
  156. $form_template = '<form{attributes}>
  157. <table class="data_table" border="0" cellpadding="5" cellspacing="5">{content}
  158. </table>
  159. </form>';
  160. $renderer->setFormTemplate($form_template);
  161. if (api_is_western_name_order()) {
  162. $renderer->setHeaderTemplate(
  163. '<tr>
  164. <th>'.get_lang('Code').'</th>
  165. <th>'.get_lang('Username').'</th>
  166. <th>'.get_lang('First name').'</th>
  167. <th>'.get_lang('Last name').'</th>
  168. <th>'.get_lang('Grade activity').'</th>
  169. </tr>'
  170. );
  171. } else {
  172. $renderer->setHeaderTemplate(
  173. '<tr>
  174. <th>'.get_lang('Code').'</th>
  175. <th>'.get_lang('Username').'</th>
  176. <th>'.get_lang('Last name').'</th>
  177. <th>'.get_lang('First name').'</th>
  178. <th>'.get_lang('Grade activity').'</th>
  179. </tr>'
  180. );
  181. }
  182. $template_submit = '<tr>
  183. <td colspan="4" ></td>
  184. <td>
  185. {element}
  186. <!-- BEGIN error --><br /><span style="color: #ff0000;font-size:10px">{error}</span><!-- END error -->
  187. </td>
  188. </tr>';
  189. $results_and_users = [];
  190. foreach ($this->result_object as $result) {
  191. $user = api_get_user_info($result->get_user_id());
  192. $results_and_users[] = ['result' => $result, 'user' => $user];
  193. }
  194. usort($results_and_users, ['EvalForm', 'sort_by_user']);
  195. $defaults = [];
  196. $model = ExerciseLib::getCourseScoreModel();
  197. foreach ($results_and_users as $result_and_user) {
  198. $user = $result_and_user['user'];
  199. $result = $result_and_user['result'];
  200. $renderer = &$this->defaultRenderer();
  201. if (api_is_western_name_order()) {
  202. $user_info = '<td align="left" >'.$user['firstname'].'</td>';
  203. $user_info .= '<td align="left" >'.$user['lastname'].'</td>';
  204. } else {
  205. $user_info = '<td align="left" >'.$user['lastname'].'</td>';
  206. $user_info .= '<td align="left" >'.$user['firstname'].'</td>';
  207. }
  208. $template = '<tr>
  209. <td align="left" >'.$user['official_code'].'</td>
  210. <td align="left" >'.$user['username'].'</td>
  211. '.$user_info.'
  212. <td align="left">{element} / '.$this->evaluation_object->get_max().'
  213. <!-- BEGIN error --><br /><span style="color: #ff0000;font-size:10px">{error}</span><!-- END error -->
  214. </td>
  215. </tr>';
  216. if (empty($model)) {
  217. $this->addFloat(
  218. 'score['.$result->get_id().']',
  219. $this->build_stud_label($user['user_id'], $user['username'], $user['lastname'], $user['firstname']),
  220. false,
  221. [
  222. 'maxlength' => 5,
  223. ],
  224. false,
  225. 0,
  226. $this->evaluation_object->get_max()
  227. );
  228. $defaults['score['.$result->get_id().']'] = $result->get_score();
  229. } else {
  230. $questionWeighting = $this->evaluation_object->get_max();
  231. $select = $this->addSelect(
  232. 'score['.$result->get_id().']',
  233. get_lang('Score'),
  234. [],
  235. ['disable_js' => true, 'id' => 'score_'.$result->get_id()]
  236. );
  237. foreach ($model['score_list'] as $item) {
  238. $i = api_number_format($item['score_to_qualify'] / 100 * $questionWeighting, 2);
  239. $modelStyle = ExerciseLib::getModelStyle($item, $i);
  240. $attributes = ['class' => $item['css_class']];
  241. if ($result->get_score() == $i) {
  242. $attributes['selected'] = 'selected';
  243. }
  244. $select->addOption($modelStyle, $i, $attributes);
  245. }
  246. $select->updateSelectWithSelectedOption($this);
  247. $template = '<tr>
  248. <td align="left" >'.$user['official_code'].'</td>
  249. <td align="left" >'.$user['username'].'</td>
  250. '.$user_info.'
  251. <td align="left">{element} <!-- BEGIN error --><br /><span style="color: #ff0000;font-size:10px">{error}</span><!-- END error -->
  252. </td>
  253. </tr>';
  254. }
  255. $renderer->setElementTemplate($template, 'score['.$result->get_id().']');
  256. }
  257. if (empty($model)) {
  258. $this->setDefaults($defaults);
  259. }
  260. $this->addButtonSave(get_lang('Grade learners'));
  261. $renderer->setElementTemplate($template_submit, 'submit');
  262. }
  263. /**
  264. * This function builds a form to move an item to another category.
  265. */
  266. protected function build_move_form()
  267. {
  268. $renderer = &$this->defaultRenderer();
  269. $renderer->setCustomElementTemplate('<span>{element}</span> ');
  270. $this->addElement('static', null, null, '"'.$this->evaluation_object->get_name().'" ');
  271. $this->addElement('static', null, null, get_lang('Move to').' : ');
  272. $select = $this->addElement('select', 'move_cat', null, null);
  273. $line = '';
  274. foreach ($this->evaluation_object->get_target_categories() as $cat) {
  275. for ($i = 0; $i < $cat[2]; $i++) {
  276. $line .= '&mdash;';
  277. }
  278. $select->addoption($line.' '.$cat[1], $cat[0]);
  279. $line = '';
  280. }
  281. $this->addButtonSave(get_lang('Validate'), 'submit');
  282. }
  283. /**
  284. * Builds a result form containing inputs for all students with a given course_code.
  285. */
  286. protected function build_result_add_form()
  287. {
  288. $renderer = &$this->defaultRenderer();
  289. $renderer->setFormTemplate(
  290. '<form{attributes}>
  291. <table class="data_table">
  292. {content}
  293. </table>
  294. </form>'
  295. );
  296. $users = GradebookUtils::get_users_in_course($this->evaluation_object->get_course_code());
  297. $nr_users = 0;
  298. //extra field for check on maxvalue
  299. $this->addElement('hidden', 'maxvalue', $this->evaluation_object->get_max());
  300. $this->addElement('hidden', 'minvalue', 0);
  301. $this->addElement('header', get_lang('Grade learners'));
  302. if (api_is_western_name_order()) {
  303. $renderer->setHeaderTemplate(
  304. '<tr>
  305. <th>'.get_lang('Code').'</th>
  306. <th>'.get_lang('Username').'</th>
  307. <th>'.get_lang('First name').'</th>
  308. <th>'.get_lang('Last name').'</th>
  309. <th>'.get_lang('Grade activity').'</th>
  310. </tr>'
  311. );
  312. } else {
  313. $renderer->setHeaderTemplate(
  314. '<tr>
  315. <th>'.get_lang('Code').'</th>
  316. <th>'.get_lang('Username').'</th>
  317. <th>'.get_lang('Last name').'</th>
  318. <th>'.get_lang('First name').'</th>
  319. <th>'.get_lang('Grade activity').'</th>
  320. </tr>'
  321. );
  322. }
  323. $firstUser = true;
  324. foreach ($users as $user) {
  325. $element_name = 'score['.$user[0].']';
  326. $scoreColumnProperties = ['maxlength' => 5];
  327. if ($firstUser) {
  328. $scoreColumnProperties['autofocus'] = '';
  329. $firstUser = false;
  330. }
  331. //user_id, user.username, lastname, firstname
  332. $this->addFloat(
  333. $element_name,
  334. $this->build_stud_label($user[0], $user[1], $user[2], $user[3]),
  335. false,
  336. $scoreColumnProperties,
  337. false,
  338. 0,
  339. $this->evaluation_object->get_max()
  340. );
  341. if (api_is_western_name_order()) {
  342. $user_info = '<td align="left" >'.$user[3].'</td>';
  343. $user_info .= '<td align="left" >'.$user[2].'</td>';
  344. } else {
  345. $user_info = '<td align="left" >'.$user[2].'</td>';
  346. $user_info .= '<td align="left" >'.$user[3].'</td>';
  347. }
  348. $nr_users++;
  349. $template = '<tr>
  350. <td align="left" >'.$user[4].'</td>
  351. <td align="left" >'.$user[1].'</td>
  352. '.$user_info.'
  353. <td align="left">{element} / '.$this->evaluation_object->get_max().'
  354. <!-- BEGIN error --><br /><span style="color: #ff0000;font-size:10px">{error}</span><!-- END error -->
  355. </td>
  356. </tr>';
  357. $renderer->setElementTemplate($template, $element_name);
  358. }
  359. $this->addElement('hidden', 'nr_users', $nr_users);
  360. $this->addElement('hidden', 'evaluation_id', $this->result_object->get_evaluation_id());
  361. $this->addButtonSave(get_lang('Grade learners'), 'submit');
  362. $template_submit = '<tr>
  363. <td colspan="4" ></td>
  364. <td >
  365. {element}
  366. <!-- BEGIN error --><br /><span style="color: #ff0000;font-size:10px">{error}</span><!-- END error -->
  367. </td>
  368. </tr>';
  369. $renderer->setElementTemplate($template_submit, 'submit');
  370. }
  371. /**
  372. * Builds a form to edit a result.
  373. */
  374. protected function build_result_edit_form()
  375. {
  376. $userInfo = api_get_user_info($this->result_object->get_user_id());
  377. $this->addHeader(get_lang('User').': '.$userInfo['complete_name']);
  378. $model = ExerciseLib::getCourseScoreModel();
  379. if (empty($model)) {
  380. $this->addFloat(
  381. 'score',
  382. [
  383. get_lang('Score'),
  384. null,
  385. '/ '.$this->evaluation_object->get_max(),
  386. ],
  387. false,
  388. [
  389. 'size' => '4',
  390. 'maxlength' => '5',
  391. ],
  392. false,
  393. 0,
  394. $this->evaluation_object->get_max()
  395. );
  396. $this->setDefaults(
  397. [
  398. 'score' => $this->result_object->get_score(),
  399. 'maximum' => $this->evaluation_object->get_max(),
  400. ]
  401. );
  402. } else {
  403. $questionWeighting = $this->evaluation_object->get_max();
  404. $select = $this->addSelect('score', get_lang('Score'), [], ['disable_js' => true]);
  405. foreach ($model['score_list'] as $item) {
  406. $i = api_number_format($item['score_to_qualify'] / 100 * $questionWeighting, 2);
  407. $model = ExerciseLib::getModelStyle($item, $i);
  408. $attributes = ['class' => $item['css_class']];
  409. if ($this->result_object->get_score() == $i) {
  410. $attributes['selected'] = 'selected';
  411. }
  412. $select->addOption($model, $i, $attributes);
  413. }
  414. $select->updateSelectWithSelectedOption($this);
  415. }
  416. $allowMultipleAttempts = api_get_configuration_value('gradebook_multiple_evaluation_attempts');
  417. if ($allowMultipleAttempts) {
  418. $this->addTextarea('comment', get_lang('Comment'));
  419. }
  420. $this->addButtonSave(get_lang('Edit'));
  421. $this->addElement('hidden', 'hid_user_id', $this->result_object->get_user_id());
  422. }
  423. /**
  424. * Builds a form to add an evaluation.
  425. */
  426. protected function build_add_form()
  427. {
  428. $this->setDefaults(
  429. [
  430. 'hid_user_id' => $this->evaluation_object->get_user_id(),
  431. 'hid_category_id' => $this->evaluation_object->get_category_id(),
  432. 'hid_course_code' => $this->evaluation_object->get_course_code(),
  433. 'created_at' => api_get_utc_datetime(),
  434. ]
  435. );
  436. $this->build_basic_form();
  437. if ($this->evaluation_object->get_course_code() == null) {
  438. $this->addElement('checkbox', 'adduser', null, get_lang('Add users to evaluation'));
  439. } else {
  440. $this->addElement('checkbox', 'addresult', null, get_lang('Grade learners'));
  441. }
  442. $this->addButtonCreate(get_lang('Add this classroom activity to the assessment'), 'submit');
  443. }
  444. /**
  445. * Builds a form to edit an evaluation.
  446. */
  447. protected function build_editing_form()
  448. {
  449. $parent_cat = Category::load($this->evaluation_object->get_category_id());
  450. //@TODO $weight_mask is replaced?
  451. if ($parent_cat[0]->get_parent_id() == 0) {
  452. $weight_mask = $this->evaluation_object->get_weight();
  453. } else {
  454. $cat = Category::load($parent_cat[0]->get_parent_id());
  455. $global_weight = $cat[0]->get_weight();
  456. $weight_mask = $global_weight * $this->evaluation_object->get_weight() / $parent_cat[0]->get_weight();
  457. }
  458. $weight = $weight_mask = $this->evaluation_object->get_weight();
  459. $this->setDefaults([
  460. 'hid_id' => $this->evaluation_object->get_id(),
  461. 'name' => $this->evaluation_object->get_name(),
  462. 'description' => $this->evaluation_object->get_description(),
  463. 'hid_user_id' => $this->evaluation_object->get_user_id(),
  464. 'hid_course_code' => $this->evaluation_object->get_course_code(),
  465. 'hid_category_id' => $this->evaluation_object->get_category_id(),
  466. 'created_at' => api_get_utc_datetime($this->evaluation_object->get_date()),
  467. 'weight' => $weight,
  468. 'weight_mask' => $weight_mask,
  469. 'max' => $this->evaluation_object->get_max(),
  470. 'visible' => $this->evaluation_object->is_visible(),
  471. ]);
  472. $id_current = isset($this->id) ? $this->id : null;
  473. $this->addElement('hidden', 'hid_id', $id_current);
  474. $this->build_basic_form(1);
  475. $this->addButtonSave(get_lang('Save assessment'), 'submit');
  476. }
  477. /**
  478. * Builds a basic form that is used in add and edit.
  479. *
  480. * @param int $edit
  481. */
  482. private function build_basic_form($edit = 0)
  483. {
  484. $form_title = get_lang('Add classroom activity');
  485. if (!empty($_GET['editeval']) && $_GET['editeval'] == 1) {
  486. $form_title = get_lang('Edit evaluation');
  487. }
  488. $this->addHeader($form_title);
  489. $this->addElement('hidden', 'hid_user_id');
  490. $this->addElement('hidden', 'hid_course_code');
  491. $this->addText(
  492. 'name',
  493. get_lang('Assessment'),
  494. true,
  495. [
  496. 'maxlength' => '50',
  497. 'id' => 'evaluation_title',
  498. ]
  499. );
  500. $cat_id = $this->evaluation_object->get_category_id();
  501. $session_id = api_get_session_id();
  502. $course_code = api_get_course_id();
  503. $all_categories = Category:: load(
  504. null,
  505. null,
  506. $course_code,
  507. null,
  508. null,
  509. $session_id,
  510. false
  511. );
  512. if (count($all_categories) == 1) {
  513. $this->addElement('hidden', 'hid_category_id', $cat_id);
  514. } else {
  515. $select_gradebook = $this->addElement(
  516. 'select',
  517. 'hid_category_id',
  518. get_lang('Select assessment'),
  519. [],
  520. ['id' => 'hid_category_id']
  521. );
  522. $this->addRule('hid_category_id', get_lang('Required field'), 'nonzero');
  523. $default_weight = 0;
  524. if (!empty($all_categories)) {
  525. foreach ($all_categories as $my_cat) {
  526. if ($my_cat->get_course_code() == api_get_course_id()) {
  527. $grade_model_id = $my_cat->get_grade_model_id();
  528. if (empty($grade_model_id)) {
  529. if ($my_cat->get_parent_id() == 0) {
  530. $default_weight = $my_cat->get_weight();
  531. $select_gradebook->addoption(get_lang('Default'), $my_cat->get_id());
  532. $cats_added[] = $my_cat->get_id();
  533. } else {
  534. $select_gradebook->addoption($my_cat->get_name(), $my_cat->get_id());
  535. $cats_added[] = $my_cat->get_id();
  536. }
  537. } else {
  538. $select_gradebook->addoption(get_lang('Select'), 0);
  539. }
  540. if ($this->evaluation_object->get_category_id() == $my_cat->get_id()) {
  541. $default_weight = $my_cat->get_weight();
  542. }
  543. }
  544. }
  545. }
  546. }
  547. $this->addFloat(
  548. 'weight_mask',
  549. [
  550. get_lang('Weight'),
  551. null,
  552. ' [0 .. <span id="max_weight">'.$all_categories[0]->get_weight().'</span>] ',
  553. ],
  554. true,
  555. [
  556. 'size' => '4',
  557. 'maxlength' => '5',
  558. ]
  559. );
  560. $model = ExerciseLib::getCourseScoreModel();
  561. if ($edit) {
  562. if (empty($model)) {
  563. if (!$this->evaluation_object->has_results()) {
  564. $this->addText(
  565. 'max',
  566. get_lang('Maximum score'),
  567. true,
  568. [
  569. 'maxlength' => '5',
  570. ]
  571. );
  572. } else {
  573. $this->addText(
  574. 'max',
  575. [get_lang('Maximum score'), get_lang('Cannot change the score')],
  576. false,
  577. [
  578. 'maxlength' => '5',
  579. 'disabled' => 'disabled',
  580. ]
  581. );
  582. }
  583. } else {
  584. $class = '';
  585. foreach ($model['score_list'] as $item) {
  586. $class = $item['css_class'];
  587. }
  588. $this->addText(
  589. 'max',
  590. get_lang('Maximum score'),
  591. false,
  592. [
  593. 'maxlength' => '5',
  594. 'class' => $class,
  595. 'disabled' => 'disabled',
  596. ]
  597. );
  598. $defaults['max'] = $item['max'];
  599. $this->setDefaults($defaults);
  600. }
  601. } else {
  602. if (empty($model)) {
  603. $this->addText(
  604. 'max',
  605. get_lang('Maximum score'),
  606. true,
  607. [
  608. 'maxlength' => '5',
  609. ]
  610. );
  611. $default_max = api_get_setting('gradebook_default_weight');
  612. $defaults['max'] = isset($default_max) ? $default_max : 100;
  613. $this->setDefaults($defaults);
  614. } else {
  615. $class = '';
  616. foreach ($model['score_list'] as $item) {
  617. $class = $item['css_class'];
  618. }
  619. $this->addText(
  620. 'max',
  621. get_lang('Maximum score'),
  622. false,
  623. [
  624. 'maxlength' => '5',
  625. 'class' => $class,
  626. 'disabled' => 'disabled',
  627. ]
  628. );
  629. $defaults['max'] = $item['max'];
  630. $this->setDefaults($defaults);
  631. }
  632. }
  633. $this->addElement('textarea', 'description', get_lang('Description'));
  634. $this->addRule('hid_category_id', get_lang('Required field'), 'required');
  635. $this->addElement('checkbox', 'visible', null, get_lang('Visible'));
  636. $this->addRule('max', get_lang('Only numbers'), 'numeric');
  637. $this->addRule(
  638. 'max',
  639. get_lang('Negative value'),
  640. 'compare',
  641. '>=',
  642. 'server',
  643. false,
  644. false,
  645. 0
  646. );
  647. $setting = api_get_setting('tool_visible_by_default_at_creation');
  648. $visibility_default = 1;
  649. if (isset($setting['gradebook']) && $setting['gradebook'] == 'false') {
  650. $visibility_default = 0;
  651. }
  652. $this->setDefaults(['visible' => $visibility_default]);
  653. }
  654. /**
  655. * @param $id
  656. * @param $username
  657. * @param $lastname
  658. * @param $firstname
  659. *
  660. * @return string
  661. */
  662. private function build_stud_label($id, $username, $lastname, $firstname)
  663. {
  664. $opendocurl_start = '';
  665. $opendocurl_end = '';
  666. // evaluation's origin is a link
  667. if ($this->evaluation_object->get_category_id() < 0) {
  668. $link = LinkFactory::get_evaluation_link($this->evaluation_object->get_id());
  669. $doc_url = $link->get_view_url($id);
  670. if ($doc_url != null) {
  671. $opendocurl_start .= '<a href="'.$doc_url.'" target="_blank">';
  672. $opendocurl_end = '</a>';
  673. }
  674. }
  675. return $opendocurl_start.api_get_person_name($firstname, $lastname).' ('.$username.')'.$opendocurl_end;
  676. }
  677. }