evaluation.class.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. * Class Evaluation
  6. * @package chamilo.gradebook
  7. */
  8. class Evaluation implements GradebookItem
  9. {
  10. private $id;
  11. private $name;
  12. private $description;
  13. private $user_id;
  14. private $course_code;
  15. /** @var Category */
  16. private $category;
  17. private $created_at;
  18. private $weight;
  19. private $eval_max;
  20. private $visible;
  21. private $sessionId;
  22. public $studentList;
  23. /**
  24. * Construct
  25. */
  26. public function __construct()
  27. {
  28. }
  29. /**
  30. * @return Category
  31. */
  32. public function getCategory()
  33. {
  34. return $this->category;
  35. }
  36. /**
  37. * @param Category $category
  38. */
  39. public function setCategory($category)
  40. {
  41. $this->category = $category;
  42. }
  43. /**
  44. * @return int
  45. */
  46. public function get_category_id()
  47. {
  48. return $this->category->get_id();
  49. }
  50. /**
  51. * @param int $category_id
  52. */
  53. public function set_category_id($category_id)
  54. {
  55. $categories = Category::load($category_id);
  56. if (isset($categories[0])) {
  57. $this->setCategory($categories[0]);
  58. }
  59. }
  60. /**
  61. * @return int
  62. */
  63. public function get_id()
  64. {
  65. return $this->id;
  66. }
  67. /**
  68. * @return string
  69. */
  70. public function get_name()
  71. {
  72. return $this->name;
  73. }
  74. /**
  75. * @return string
  76. */
  77. public function get_description()
  78. {
  79. return $this->description;
  80. }
  81. public function get_user_id()
  82. {
  83. return $this->user_id;
  84. }
  85. public function get_course_code()
  86. {
  87. return $this->course_code;
  88. }
  89. /**
  90. * @return int
  91. */
  92. public function getSessionId()
  93. {
  94. return $this->sessionId;
  95. }
  96. /**
  97. * @param int $sessionId
  98. */
  99. public function setSessionId($sessionId)
  100. {
  101. $this->sessionId = intval($sessionId);
  102. }
  103. public function get_date()
  104. {
  105. return $this->created_at;
  106. }
  107. public function get_weight()
  108. {
  109. return $this->weight;
  110. }
  111. public function get_max()
  112. {
  113. return $this->eval_max;
  114. }
  115. public function get_type()
  116. {
  117. return $this->type;
  118. }
  119. public function is_visible()
  120. {
  121. return $this->visible;
  122. }
  123. public function get_locked()
  124. {
  125. return $this->locked;
  126. }
  127. public function is_locked()
  128. {
  129. return isset($this->locked) && $this->locked == 1 ? true : false;
  130. }
  131. public function set_id($id)
  132. {
  133. $this->id = $id;
  134. }
  135. public function set_name($name)
  136. {
  137. $this->name = $name;
  138. }
  139. public function set_description($description)
  140. {
  141. $this->description = $description;
  142. }
  143. public function set_user_id($user_id)
  144. {
  145. $this->user_id = $user_id;
  146. }
  147. public function set_course_code($course_code)
  148. {
  149. $this->course_code = $course_code;
  150. }
  151. public function set_date($date)
  152. {
  153. $this->created_at = $date;
  154. }
  155. public function set_weight($weight)
  156. {
  157. $this->weight = $weight;
  158. }
  159. public function set_max($max)
  160. {
  161. $this->eval_max = $max;
  162. }
  163. public function set_visible($visible)
  164. {
  165. $this->visible = $visible;
  166. }
  167. public function set_type($type)
  168. {
  169. $this->type = $type;
  170. }
  171. public function set_locked($locked)
  172. {
  173. $this->locked = $locked;
  174. }
  175. /**
  176. * Retrieve evaluations and return them as an array of Evaluation objects
  177. * @param int $id evaluation id
  178. * @param int $user_id user id (evaluation owner)
  179. * @param string $course_code course code
  180. * @param int $category_id parent category
  181. * @param integer $visible visible
  182. */
  183. public static function load(
  184. $id = null,
  185. $user_id = null,
  186. $course_code = null,
  187. $category_id = null,
  188. $visible = null,
  189. $locked = null
  190. ) {
  191. $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
  192. $sql = 'SELECT * FROM '.$tbl_grade_evaluations;
  193. $paramcount = 0;
  194. if (isset ($id)) {
  195. $sql.= ' WHERE id = '.intval($id);
  196. $paramcount ++;
  197. }
  198. if (isset ($user_id)) {
  199. if ($paramcount != 0) $sql .= ' AND';
  200. else $sql .= ' WHERE';
  201. $sql .= ' user_id = '.intval($user_id);
  202. $paramcount ++;
  203. }
  204. if (isset ($course_code) && $course_code <> '-1') {
  205. if ($paramcount != 0) $sql .= ' AND';
  206. else $sql .= ' WHERE';
  207. $sql .= " course_code = '".Database::escape_string($course_code)."'";
  208. $paramcount ++;
  209. }
  210. if (isset ($category_id)) {
  211. if ($paramcount != 0) $sql .= ' AND';
  212. else $sql .= ' WHERE';
  213. $sql .= ' category_id = '.intval($category_id);
  214. $paramcount ++;
  215. }
  216. if (isset ($visible)) {
  217. if ($paramcount != 0) $sql .= ' AND';
  218. else $sql .= ' WHERE';
  219. $sql .= ' visible = '.intval($visible);
  220. $paramcount ++;
  221. }
  222. if (isset ($locked)) {
  223. if ($paramcount != 0) $sql .= ' AND';
  224. else $sql .= ' WHERE';
  225. $sql .= ' locked = '.intval($locked);
  226. }
  227. $result = Database::query($sql);
  228. $alleval = Evaluation::create_evaluation_objects_from_sql_result($result);
  229. return $alleval;
  230. }
  231. /**
  232. * @param array $result
  233. * @return array
  234. */
  235. private static function create_evaluation_objects_from_sql_result($result)
  236. {
  237. $alleval = array();
  238. if (Database::num_rows($result)) {
  239. while ($data = Database::fetch_array($result)) {
  240. $eval= new Evaluation();
  241. $eval->set_id($data['id']);
  242. $eval->set_name($data['name']);
  243. $eval->set_description($data['description']);
  244. $eval->set_user_id($data['user_id']);
  245. $eval->set_course_code($data['course_code']);
  246. $eval->set_category_id($data['category_id']);
  247. $eval->set_date(api_get_local_time($data['created_at']));
  248. $eval->set_weight($data['weight']);
  249. $eval->set_max($data['max']);
  250. $eval->set_visible($data['visible']);
  251. $eval->set_type($data['type']);
  252. $eval->set_locked($data['locked']);
  253. $eval->setSessionId(api_get_session_id());
  254. $alleval[] = $eval;
  255. }
  256. }
  257. return $alleval;
  258. }
  259. /**
  260. * Insert this evaluation into the database
  261. */
  262. public function add()
  263. {
  264. if (isset($this->name) &&
  265. isset($this->user_id) &&
  266. isset($this->weight) &&
  267. isset ($this->eval_max) &&
  268. isset($this->visible)
  269. ) {
  270. $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
  271. $sql = 'INSERT INTO '.$tbl_grade_evaluations
  272. .' (name, user_id, weight, max, visible';
  273. if (isset($this->description)) {
  274. $sql .= ',description';
  275. }
  276. if (isset($this->course_code)) {
  277. $sql .= ', course_code';
  278. }
  279. if (isset($this->category)) {
  280. $sql .= ', category_id';
  281. }
  282. $sql .= ', created_at';
  283. $sql .= ',type';
  284. $sql .= ") VALUES ('".Database::escape_string($this->get_name())."'"
  285. .','.intval($this->get_user_id())
  286. .','.floatval($this->get_weight())
  287. .','.intval($this->get_max())
  288. .','.intval($this->is_visible());
  289. if (isset($this->description)) {
  290. $sql .= ",'".Database::escape_string($this->get_description())."'";
  291. }
  292. if (isset($this->course_code)) {
  293. $sql .= ",'".Database::escape_string($this->get_course_code())."'";
  294. }
  295. if (isset($this->category)) {
  296. $sql .= ','.intval($this->get_category_id());
  297. }
  298. if (empty($this->type)) {
  299. $this->type = 'evaluation';
  300. }
  301. $sql .= ", '".api_get_utc_datetime()."'";
  302. $sql .= ',\''.Database::escape_string($this->type).'\'';
  303. $sql .= ")";
  304. Database::query($sql);
  305. $this->set_id(Database::insert_id());
  306. } else {
  307. die('Error in Evaluation add: required field empty');
  308. }
  309. }
  310. /**
  311. * @param int $idevaluation
  312. */
  313. public function add_evaluation_log($idevaluation)
  314. {
  315. if (!empty($idevaluation)) {
  316. $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
  317. $tbl_grade_linkeval_log = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINKEVAL_LOG);
  318. $eval = new Evaluation();
  319. $dateobject = $eval->load($idevaluation,null,null,null,null);
  320. $arreval = get_object_vars($dateobject[0]);
  321. if (!empty($arreval['id'])) {
  322. $sql = 'SELECT weight from '.$tbl_grade_evaluations.'
  323. WHERE id='.$arreval['id'];
  324. $rs = Database::query($sql);
  325. $row_old_weight = Database::fetch_array($rs, 'ASSOC');
  326. $current_date = api_get_utc_datetime();
  327. $params = [
  328. 'id_linkeval_log' => $arreval['id'],
  329. 'name' => $arreval['name'],
  330. 'description' => $arreval['description'],
  331. 'created_at' => $current_date,
  332. 'weight' => $row_old_weight['weight'],
  333. 'visible' => $arreval['visible'],
  334. 'type' => 'evaluation',
  335. 'user_id_log' => api_get_user_id()
  336. ];
  337. Database::insert($tbl_grade_linkeval_log, $params);
  338. }
  339. }
  340. }
  341. /**
  342. * Update the properties of this evaluation in the database
  343. */
  344. public function save()
  345. {
  346. $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
  347. $sql = 'UPDATE '.$tbl_grade_evaluations
  348. ." SET name = '".Database::escape_string($this->get_name())."'"
  349. .', description = ';
  350. if (isset($this->description)) {
  351. $sql .= "'".Database::escape_string($this->get_description())."'";
  352. }else {
  353. $sql .= 'null';
  354. }
  355. $sql .= ', user_id = '.intval($this->get_user_id())
  356. .', course_code = ';
  357. if (isset($this->course_code)) {
  358. $sql .= "'".Database::escape_string($this->get_course_code())."'";
  359. } else {
  360. $sql .= 'null';
  361. }
  362. $sql .= ', category_id = ';
  363. if (isset($this->category)) {
  364. $sql .= intval($this->get_category_id());
  365. } else {
  366. $sql .= 'null';
  367. }
  368. $sql .= ', weight = "'.Database::escape_string($this->get_weight()).'" '
  369. .', max = '.intval($this->get_max())
  370. .', visible = '.intval($this->is_visible())
  371. .' WHERE id = '.intval($this->id);
  372. //recorded history
  373. $eval_log = new Evaluation();
  374. $eval_log->add_evaluation_log($this->id);
  375. Database::query($sql);
  376. }
  377. /**
  378. * Delete this evaluation from the database
  379. */
  380. public function delete()
  381. {
  382. $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
  383. $sql = 'DELETE FROM '.$tbl_grade_evaluations.' WHERE id = '.intval($this->id);
  384. Database::query($sql);
  385. }
  386. /**
  387. * Check if an evaluation name (with the same parent category) already exists
  388. * @param $name name to check (if not given, the name property of this object will be checked)
  389. * @param $parent parent category
  390. */
  391. public function does_name_exist($name, $parent)
  392. {
  393. if (!isset ($name)) {
  394. $name = $this->name;
  395. $parent = $this->category;
  396. }
  397. $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
  398. $sql = 'SELECT count(id) AS number'
  399. .' FROM '.$tbl_grade_evaluations
  400. ." WHERE name = '".Database::escape_string($name)."'";
  401. if (api_is_allowed_to_edit()) {
  402. $parent = Category::load($parent);
  403. $code = $parent[0]->get_course_code();
  404. $courseInfo = api_get_course_info($code);
  405. $courseId = $courseInfo['real_id'];
  406. if (isset($code) && $code != '0') {
  407. $main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  408. $sql .= ' AND user_id IN (
  409. SELECT user_id FROM '.$main_course_user_table.'
  410. WHERE
  411. c_id = '.$courseId.' AND
  412. status = '.COURSEMANAGER.'
  413. )';
  414. } else {
  415. $sql .= ' AND user_id = '.api_get_user_id();
  416. }
  417. }else {
  418. $sql .= ' AND user_id = '.api_get_user_id();
  419. }
  420. if (!isset ($parent)) {
  421. $sql.= ' AND category_id is null';
  422. } else {
  423. $sql.= ' AND category_id = '.intval($parent);
  424. }
  425. $result = Database::query($sql);
  426. $number=Database::fetch_row($result);
  427. return $number[0] != 0;
  428. }
  429. /**
  430. * Are there any results for this evaluation yet ?
  431. * The 'max' property should not be changed then.
  432. */
  433. public function has_results()
  434. {
  435. $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
  436. $sql = 'SELECT count(id) AS number
  437. FROM '.$tbl_grade_results.'
  438. WHERE evaluation_id = '.intval($this->id);
  439. $result = Database::query($sql);
  440. $number=Database::fetch_row($result);
  441. return ($number[0] != 0);
  442. }
  443. /**
  444. * Delete all results for this evaluation
  445. */
  446. public function delete_results()
  447. {
  448. $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
  449. $sql = 'DELETE FROM '.$tbl_grade_results.'
  450. WHERE evaluation_id = '.intval($this->id);
  451. Database::query($sql);
  452. }
  453. /**
  454. * Delete this evaluation and all underlying results.
  455. */
  456. public function delete_with_results()
  457. {
  458. $this->delete_results();
  459. $this->delete();
  460. }
  461. /**
  462. * Check if the given score is possible for this evaluation
  463. */
  464. public function is_valid_score($score)
  465. {
  466. return is_numeric($score) && $score >= 0 && $score <= $this->eval_max;
  467. }
  468. /**
  469. * Calculate the score of this evaluation
  470. * @param int $stud_id (default: all students who have results for this eval - then the average is returned)
  471. * @param string $type (best, average, ranking)
  472. * @return array (score, max) if student is given
  473. * array (sum of scores, number of scores) otherwise
  474. * or null if no scores available
  475. */
  476. public function calc_score($stud_id = null, $type = null)
  477. {
  478. $useSession = true;
  479. if (isset($stud_id) && empty($type)) {
  480. $key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id.'_'.$stud_id;
  481. $data = Session::read('calc_score');
  482. $results = isset($data[$key]) ? $data[$key] : null;
  483. if ($useSession == false) {
  484. $results = null;
  485. }
  486. if (empty($results)) {
  487. $results = Result::load(null, $stud_id, $this->id);
  488. Session::write('calc_score', array($key => $results));
  489. }
  490. $score = 0;
  491. /** @var Result $res */
  492. foreach ($results as $res) {
  493. $score = $res->get_score();
  494. }
  495. return array($score, $this->get_max());
  496. } else {
  497. $count = 0;
  498. $sum = 0;
  499. $bestResult = 0;
  500. $weight = 0;
  501. $sumResult = 0;
  502. $key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id;
  503. $data = Session::read('calc_score');
  504. $allResults = isset($data[$key]) ? $data[$key] : null;
  505. if ($useSession == false) {
  506. $allResults = null;
  507. }
  508. if (empty($allResults)) {
  509. $allResults = Result::load(null, null, $this->id);
  510. Session::write($key, $allResults);
  511. }
  512. $students = array();
  513. /** @var Result $res */
  514. foreach ($allResults as $res) {
  515. $score = $res->get_score();
  516. if (!empty($score) || $score == '0') {
  517. $count++;
  518. $sum += $score / $this->get_max();
  519. $sumResult += $score;
  520. if ($score > $bestResult) {
  521. $bestResult = $score;
  522. }
  523. $weight = $this->get_max();
  524. }
  525. $students[$res->get_user_id()] = $score;
  526. }
  527. if (empty($count)) {
  528. return null;
  529. }
  530. switch ($type) {
  531. case 'best':
  532. return array($bestResult, $weight);
  533. break;
  534. case 'average':
  535. return array($sumResult/$count, $weight);
  536. break;
  537. case 'ranking':
  538. $students = array();
  539. /** @var Result $res */
  540. foreach ($allResults as $res) {
  541. $score = $res->get_score();
  542. $students[$res->get_user_id()] = $score;
  543. }
  544. return AbstractLink::getCurrentUserRanking($stud_id, $students);
  545. break;
  546. default:
  547. return array($sum, $count);
  548. break;
  549. }
  550. }
  551. }
  552. /**
  553. * Generate an array of possible categories where this evaluation can be moved to.
  554. * Notice: its own parent will be included in the list: it's up to the frontend
  555. * to disable this element.
  556. * @return array 2-dimensional array - every element contains 3 subelements (id, name, level)
  557. */
  558. public function get_target_categories()
  559. {
  560. // - course independent evaluation
  561. // -> movable to root or other course independent categories
  562. // - evaluation inside a course
  563. // -> movable to root, independent categories or categories inside the course
  564. $user = (api_is_platform_admin() ? null : api_get_user_id());
  565. $targets = array();
  566. $level = 0;
  567. $root = array(0, get_lang('RootCat'), $level);
  568. $targets[] = $root;
  569. if (isset($this->course_code) && !empty($this->course_code)) {
  570. $crscats = Category::load(null,null,$this->course_code,0);
  571. foreach ($crscats as $cat) {
  572. $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1);
  573. $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id());
  574. }
  575. }
  576. $indcats = Category::load(null,$user,0,0);
  577. foreach ($indcats as $cat) {
  578. $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1);
  579. $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id());
  580. }
  581. return $targets;
  582. }
  583. /**
  584. * Internal function used by get_target_categories()
  585. * @param integer $level
  586. */
  587. private function add_target_subcategories($targets, $level, $catid)
  588. {
  589. $subcats = Category::load(null,null,null,$catid);
  590. foreach ($subcats as $cat) {
  591. $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1);
  592. $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id());
  593. }
  594. return $targets;
  595. }
  596. /**
  597. * Move this evaluation to the given category.
  598. * If this evaluation moves from inside a course to outside,
  599. * its course code is also changed.
  600. */
  601. public function move_to_cat($cat)
  602. {
  603. $this->set_category_id($cat->get_id());
  604. if ($this->get_course_code() != $cat->get_course_code()) {
  605. $this->set_course_code($cat->get_course_code());
  606. }
  607. $this->save();
  608. }
  609. /**
  610. * Retrieve evaluations where a student has results for
  611. * and return them as an array of Evaluation objects
  612. * @param int $cat_id parent category (use 'null' to retrieve them in all categories)
  613. * @param int $stud_id student id
  614. */
  615. public static function get_evaluations_with_result_for_student($cat_id = null, $stud_id)
  616. {
  617. $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
  618. $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
  619. $sql = 'SELECT * FROM '.$tbl_grade_evaluations.'
  620. WHERE id IN (
  621. SELECT evaluation_id FROM '.$tbl_grade_results.'
  622. WHERE user_id = '.intval($stud_id).' AND score IS NOT NULL
  623. )';
  624. if (!api_is_allowed_to_edit()) {
  625. $sql .= ' AND visible = 1';
  626. }
  627. if (isset($cat_id)) {
  628. $sql .= ' AND category_id = '.intval($cat_id);
  629. } else {
  630. $sql .= ' AND category_id >= 0';
  631. }
  632. $result = Database::query($sql);
  633. $alleval = Evaluation::create_evaluation_objects_from_sql_result($result);
  634. return $alleval;
  635. }
  636. /**
  637. * Get a list of students that do not have a result record for this evaluation
  638. */
  639. public function get_not_subscribed_students($first_letter_user = '')
  640. {
  641. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  642. $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
  643. $sql = 'SELECT user_id,lastname,firstname,username FROM '.$tbl_user
  644. ." WHERE lastname LIKE '".Database::escape_string($first_letter_user)."%'"
  645. .' AND status = '.STUDENT
  646. .' AND user_id NOT IN'
  647. .' (SELECT user_id FROM '.$tbl_grade_results
  648. .' WHERE evaluation_id = '.intval($this->id)
  649. .' )'
  650. .' ORDER BY lastname';
  651. $result = Database::query($sql);
  652. $users = Database::store_result($result);
  653. return $users;
  654. }
  655. /**
  656. * Find evaluations by name
  657. * @param string $name_mask search string
  658. * @return array evaluation objects matching the search criterium
  659. * @todo can be written more efficiently using a new (but very complex) sql query
  660. */
  661. public function find_evaluations($name_mask,$selectcat)
  662. {
  663. $rootcat = Category::load($selectcat);
  664. $evals = $rootcat[0]->get_evaluations((api_is_allowed_to_create_course() ? null : api_get_user_id()), true);
  665. $foundevals = array();
  666. foreach ($evals as $eval) {
  667. if (!(api_strpos(api_strtolower($eval->get_name()), api_strtolower($name_mask)) === false)) {
  668. $foundevals[] = $eval;
  669. }
  670. }
  671. return $foundevals;
  672. }
  673. public function get_item_type()
  674. {
  675. return 'E';
  676. }
  677. public function get_icon_name()
  678. {
  679. return $this->has_results() ? 'evalnotempty' : 'evalempty';
  680. }
  681. /**
  682. * Locks an evaluation, only one who can unlock it is the platform administrator.
  683. * @param int locked 1 or unlocked 0
  684. *
  685. **/
  686. function lock($locked)
  687. {
  688. $table_evaluation = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
  689. $sql = "UPDATE $table_evaluation SET locked = '".intval($locked)."' WHERE id='".intval($this->id)."'";
  690. Database::query($sql);
  691. }
  692. function check_lock_permissions()
  693. {
  694. if (api_is_platform_admin()) {
  695. return true;
  696. } else {
  697. if ($this->is_locked()) {
  698. api_not_allowed();
  699. }
  700. }
  701. }
  702. function delete_linked_data()
  703. {
  704. }
  705. public function getStudentList()
  706. {
  707. return $this->studentList;
  708. }
  709. public function setStudentList($list)
  710. {
  711. $this->studentList = $list;
  712. }
  713. }