evaluation.class.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812
  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 = self::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. .','.api_float_val($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. return false;
  308. //die('Error in Evaluation add: required field empty');
  309. }
  310. }
  311. /**
  312. * @param int $idevaluation
  313. */
  314. public function add_evaluation_log($idevaluation)
  315. {
  316. if (!empty($idevaluation)) {
  317. $tbl_grade_evaluations = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
  318. $tbl_grade_linkeval_log = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINKEVAL_LOG);
  319. $eval = new Evaluation();
  320. $dateobject = $eval->load($idevaluation, null, null, null, null);
  321. $arreval = get_object_vars($dateobject[0]);
  322. if (!empty($arreval['id'])) {
  323. $sql = 'SELECT weight from '.$tbl_grade_evaluations.'
  324. WHERE id='.$arreval['id'];
  325. $rs = Database::query($sql);
  326. $row_old_weight = Database::fetch_array($rs, 'ASSOC');
  327. $current_date = api_get_utc_datetime();
  328. $params = [
  329. 'id_linkeval_log' => $arreval['id'],
  330. 'name' => $arreval['name'],
  331. 'description' => $arreval['description'],
  332. 'created_at' => $current_date,
  333. 'weight' => $row_old_weight['weight'],
  334. 'visible' => $arreval['visible'],
  335. 'type' => 'evaluation',
  336. 'user_id_log' => api_get_user_id()
  337. ];
  338. Database::insert($tbl_grade_linkeval_log, $params);
  339. }
  340. }
  341. }
  342. /**
  343. * Update the properties of this evaluation in the database
  344. */
  345. public function save()
  346. {
  347. $tbl_grade_evaluations = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
  348. $sql = 'UPDATE '.$tbl_grade_evaluations
  349. ." SET name = '".Database::escape_string($this->get_name())."'"
  350. .', description = ';
  351. if (isset($this->description)) {
  352. $sql .= "'".Database::escape_string($this->get_description())."'";
  353. } else {
  354. $sql .= 'null';
  355. }
  356. $sql .= ', user_id = '.intval($this->get_user_id())
  357. .', course_code = ';
  358. if (isset($this->course_code)) {
  359. $sql .= "'".Database::escape_string($this->get_course_code())."'";
  360. } else {
  361. $sql .= 'null';
  362. }
  363. $sql .= ', category_id = ';
  364. if (isset($this->category)) {
  365. $sql .= intval($this->get_category_id());
  366. } else {
  367. $sql .= 'null';
  368. }
  369. $sql .= ', weight = "'.Database::escape_string($this->get_weight()).'" '
  370. .', max = '.intval($this->get_max())
  371. .', visible = '.intval($this->is_visible())
  372. .' WHERE id = '.intval($this->id);
  373. //recorded history
  374. $eval_log = new Evaluation();
  375. $eval_log->add_evaluation_log($this->id);
  376. Database::query($sql);
  377. }
  378. /**
  379. * Delete this evaluation from the database
  380. */
  381. public function delete()
  382. {
  383. $tbl_grade_evaluations = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
  384. $sql = 'DELETE FROM '.$tbl_grade_evaluations.' WHERE id = '.intval($this->id);
  385. Database::query($sql);
  386. }
  387. /**
  388. * Check if an evaluation name (with the same parent category) already exists
  389. * @param $name name to check (if not given, the name property of this object will be checked)
  390. * @param $parent parent category
  391. * @return bool
  392. */
  393. public function does_name_exist($name, $parent)
  394. {
  395. if (!isset($name)) {
  396. $name = $this->name;
  397. $parent = $this->category;
  398. }
  399. $tbl_grade_evaluations = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
  400. $sql = 'SELECT count(id) AS number'
  401. .' FROM '.$tbl_grade_evaluations
  402. ." WHERE name = '".Database::escape_string($name)."'";
  403. if (api_is_allowed_to_edit()) {
  404. $parent = Category::load($parent);
  405. $code = $parent[0]->get_course_code();
  406. $courseInfo = api_get_course_info($code);
  407. $courseId = $courseInfo['real_id'];
  408. if (isset($code) && $code != '0') {
  409. $main_course_user_table = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  410. $sql .= ' AND user_id IN (
  411. SELECT user_id FROM '.$main_course_user_table.'
  412. WHERE
  413. c_id = '.$courseId.' AND
  414. status = '.COURSEMANAGER.'
  415. )';
  416. } else {
  417. $sql .= ' AND user_id = '.api_get_user_id();
  418. }
  419. } else {
  420. $sql .= ' AND user_id = '.api_get_user_id();
  421. }
  422. if (!isset($parent)) {
  423. $sql .= ' AND category_id is null';
  424. } else {
  425. $sql .= ' AND category_id = '.intval($parent);
  426. }
  427. $result = Database::query($sql);
  428. $number = Database::fetch_row($result);
  429. return $number[0] != 0;
  430. }
  431. /**
  432. * Are there any results for this evaluation yet ?
  433. * The 'max' property should not be changed then.
  434. * @return bool
  435. */
  436. public function has_results()
  437. {
  438. $table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
  439. $sql = 'SELECT count(id) AS number
  440. FROM '.$table.'
  441. WHERE evaluation_id = '.intval($this->id);
  442. $result = Database::query($sql);
  443. $number = Database::fetch_row($result);
  444. return $number[0] != 0;
  445. }
  446. /**
  447. * Delete all results for this evaluation
  448. */
  449. public function delete_results()
  450. {
  451. $table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
  452. $sql = 'DELETE FROM '.$table.'
  453. WHERE evaluation_id = '.intval($this->id);
  454. Database::query($sql);
  455. }
  456. /**
  457. * Delete this evaluation and all underlying results.
  458. */
  459. public function delete_with_results()
  460. {
  461. $this->delete_results();
  462. $this->delete();
  463. }
  464. /**
  465. * Check if the given score is possible for this evaluation
  466. */
  467. public function is_valid_score($score)
  468. {
  469. return is_numeric($score) && $score >= 0 && $score <= $this->eval_max;
  470. }
  471. /**
  472. * Calculate the score of this evaluation
  473. * @param int $stud_id (default: all students who have results for this eval - then the average is returned)
  474. * @param string $type (best, average, ranking)
  475. * @return array (score, max) if student is given
  476. * array (sum of scores, number of scores) otherwise
  477. * or null if no scores available
  478. */
  479. public function calc_score($stud_id = null, $type = null)
  480. {
  481. $useSession = true;
  482. if (isset($stud_id) && empty($type)) {
  483. $key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id.'_'.$stud_id;
  484. $data = Session::read('calc_score');
  485. $results = isset($data[$key]) ? $data[$key] : null;
  486. if ($useSession == false) {
  487. $results = null;
  488. }
  489. if (empty($results)) {
  490. $results = Result::load(null, $stud_id, $this->id);
  491. Session::write('calc_score', array($key => $results));
  492. }
  493. $score = 0;
  494. /** @var Result $res */
  495. foreach ($results as $res) {
  496. $score = $res->get_score();
  497. }
  498. return array($score, $this->get_max());
  499. } else {
  500. $count = 0;
  501. $sum = 0;
  502. $bestResult = 0;
  503. $weight = 0;
  504. $sumResult = 0;
  505. $key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id;
  506. $data = Session::read('calc_score');
  507. $allResults = isset($data[$key]) ? $data[$key] : null;
  508. if ($useSession == false) {
  509. $allResults = null;
  510. }
  511. if (empty($allResults)) {
  512. $allResults = Result::load(null, null, $this->id);
  513. Session::write($key, $allResults);
  514. }
  515. $students = array();
  516. /** @var Result $res */
  517. foreach ($allResults as $res) {
  518. $score = $res->get_score();
  519. if (!empty($score) || $score == '0') {
  520. $count++;
  521. $sum += $score / $this->get_max();
  522. $sumResult += $score;
  523. if ($score > $bestResult) {
  524. $bestResult = $score;
  525. }
  526. $weight = $this->get_max();
  527. }
  528. $students[$res->get_user_id()] = $score;
  529. }
  530. if (empty($count)) {
  531. return null;
  532. }
  533. switch ($type) {
  534. case 'best':
  535. return array($bestResult, $weight);
  536. break;
  537. case 'average':
  538. return array($sumResult / $count, $weight);
  539. break;
  540. case 'ranking':
  541. $students = array();
  542. /** @var Result $res */
  543. foreach ($allResults as $res) {
  544. $score = $res->get_score();
  545. $students[$res->get_user_id()] = $score;
  546. }
  547. return AbstractLink::getCurrentUserRanking($stud_id, $students);
  548. break;
  549. default:
  550. return array($sum, $count);
  551. break;
  552. }
  553. }
  554. }
  555. /**
  556. * Generate an array of possible categories where this evaluation can be moved to.
  557. * Notice: its own parent will be included in the list: it's up to the frontend
  558. * to disable this element.
  559. * @return array 2-dimensional array - every element contains 3 subelements (id, name, level)
  560. */
  561. public function get_target_categories()
  562. {
  563. // - course independent evaluation
  564. // -> movable to root or other course independent categories
  565. // - evaluation inside a course
  566. // -> movable to root, independent categories or categories inside the course
  567. $user = (api_is_platform_admin() ? null : api_get_user_id());
  568. $targets = array();
  569. $level = 0;
  570. $root = array(0, get_lang('RootCat'), $level);
  571. $targets[] = $root;
  572. if (isset($this->course_code) && !empty($this->course_code)) {
  573. $crscats = Category::load(null, null, $this->course_code, 0);
  574. foreach ($crscats as $cat) {
  575. $targets[] = array($cat->get_id(), $cat->get_name(), $level + 1);
  576. $targets = $this->add_target_subcategories($targets, $level + 1, $cat->get_id());
  577. }
  578. }
  579. $indcats = Category::load(null, $user, 0, 0);
  580. foreach ($indcats as $cat) {
  581. $targets[] = array($cat->get_id(), $cat->get_name(), $level + 1);
  582. $targets = $this->add_target_subcategories($targets, $level + 1, $cat->get_id());
  583. }
  584. return $targets;
  585. }
  586. /**
  587. * Internal function used by get_target_categories()
  588. * @param integer $level
  589. *
  590. * @return array
  591. */
  592. private function add_target_subcategories($targets, $level, $catid)
  593. {
  594. $subcats = Category::load(null, null, null, $catid);
  595. foreach ($subcats as $cat) {
  596. $targets[] = array($cat->get_id(), $cat->get_name(), $level + 1);
  597. $targets = $this->add_target_subcategories($targets, $level + 1, $cat->get_id());
  598. }
  599. return $targets;
  600. }
  601. /**
  602. * Move this evaluation to the given category.
  603. * If this evaluation moves from inside a course to outside,
  604. * its course code is also changed.
  605. */
  606. public function move_to_cat($cat)
  607. {
  608. $this->set_category_id($cat->get_id());
  609. if ($this->get_course_code() != $cat->get_course_code()) {
  610. $this->set_course_code($cat->get_course_code());
  611. }
  612. $this->save();
  613. }
  614. /**
  615. * Retrieve evaluations where a student has results for
  616. * and return them as an array of Evaluation objects
  617. * @param int $cat_id parent category (use 'null' to retrieve them in all categories)
  618. * @param int $stud_id student id
  619. */
  620. public static function get_evaluations_with_result_for_student($cat_id = null, $stud_id)
  621. {
  622. $tbl_grade_evaluations = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
  623. $tbl_grade_results = Database::get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
  624. $sql = 'SELECT * FROM '.$tbl_grade_evaluations.'
  625. WHERE id IN (
  626. SELECT evaluation_id FROM '.$tbl_grade_results.'
  627. WHERE user_id = '.intval($stud_id).' AND score IS NOT NULL
  628. )';
  629. if (!api_is_allowed_to_edit()) {
  630. $sql .= ' AND visible = 1';
  631. }
  632. if (isset($cat_id)) {
  633. $sql .= ' AND category_id = '.intval($cat_id);
  634. } else {
  635. $sql .= ' AND category_id >= 0';
  636. }
  637. $result = Database::query($sql);
  638. $alleval = self::create_evaluation_objects_from_sql_result($result);
  639. return $alleval;
  640. }
  641. /**
  642. * Get a list of students that do not have a result record for this evaluation
  643. */
  644. public function get_not_subscribed_students($first_letter_user = '')
  645. {
  646. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  647. $tbl_grade_results = Database::get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
  648. $sql = 'SELECT user_id,lastname,firstname,username FROM '.$tbl_user
  649. ." WHERE lastname LIKE '".Database::escape_string($first_letter_user)."%'"
  650. .' AND status = '.STUDENT
  651. .' AND user_id NOT IN'
  652. .' (SELECT user_id FROM '.$tbl_grade_results
  653. .' WHERE evaluation_id = '.intval($this->id)
  654. .' )'
  655. .' ORDER BY lastname';
  656. $result = Database::query($sql);
  657. $users = Database::store_result($result);
  658. return $users;
  659. }
  660. /**
  661. * Find evaluations by name
  662. * @param string $name_mask search string
  663. * @return array evaluation objects matching the search criterium
  664. * @todo can be written more efficiently using a new (but very complex) sql query
  665. */
  666. public function find_evaluations($name_mask, $selectcat)
  667. {
  668. $rootcat = Category::load($selectcat);
  669. $evals = $rootcat[0]->get_evaluations((api_is_allowed_to_create_course() ? null : api_get_user_id()), true);
  670. $foundevals = array();
  671. foreach ($evals as $eval) {
  672. if (!(api_strpos(api_strtolower($eval->get_name()), api_strtolower($name_mask)) === false)) {
  673. $foundevals[] = $eval;
  674. }
  675. }
  676. return $foundevals;
  677. }
  678. public function get_item_type()
  679. {
  680. return 'E';
  681. }
  682. public function get_icon_name()
  683. {
  684. return $this->has_results() ? 'evalnotempty' : 'evalempty';
  685. }
  686. /**
  687. * Locks an evaluation, only one who can unlock it is the platform administrator.
  688. * @param int locked 1 or unlocked 0
  689. *
  690. **/
  691. function lock($locked)
  692. {
  693. $table_evaluation = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
  694. $sql = "UPDATE $table_evaluation SET locked = '".intval($locked)."' WHERE id='".intval($this->id)."'";
  695. Database::query($sql);
  696. }
  697. function check_lock_permissions()
  698. {
  699. if (api_is_platform_admin()) {
  700. return true;
  701. } else {
  702. if ($this->is_locked()) {
  703. api_not_allowed();
  704. }
  705. }
  706. }
  707. function delete_linked_data()
  708. {
  709. }
  710. public function getStudentList()
  711. {
  712. return $this->studentList;
  713. }
  714. public function setStudentList($list)
  715. {
  716. $this->studentList = $list;
  717. }
  718. }