evaluation.class.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855
  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. $em = Database::getManager();
  192. $qb = $em->createQueryBuilder();
  193. $qb
  194. ->select('ge')
  195. ->from('ChamiloCoreBundle:GradebookEvaluation', 'ge');
  196. if (isset ($id)) {
  197. $qb->andWhere(
  198. $qb->expr()->eq('ge.id', $id)
  199. );
  200. }
  201. if (isset ($user_id)) {
  202. $user_id = intval($user_id);
  203. $qb->andWhere(
  204. $qb->expr()->eq('ge.userId', $user_id)
  205. );
  206. }
  207. if (isset ($course_code) && $course_code <> '-1') {
  208. $courseId = api_get_course_int_id($course_code);
  209. $qb->andWhere(
  210. $qb->expr()->eq('ge.course', $courseId)
  211. );
  212. }
  213. if (isset ($category_id)) {
  214. $category_id = intval($category_id);
  215. $qb->andWhere(
  216. $qb->expr()->eq('ge.categoryId', $category_id)
  217. );
  218. }
  219. if (isset ($visible)) {
  220. $visible = intval($visible);
  221. $qb->andWhere(
  222. $qb->expr()->eq('ge.visible', $visible)
  223. );
  224. }
  225. if (isset ($locked)) {
  226. $locked = intval($locked);
  227. $qb->andWhere(
  228. $qb->expr()->eq('ge.locked', $locked)
  229. );
  230. }
  231. $result = $qb->getQuery()->getResult();
  232. $alleval = Evaluation::createEvaluationObjectsFromEntities($result);
  233. return $alleval;
  234. }
  235. /**
  236. * Get an Evaluation array from an \Chamilo\CoreBundle\Entity\GradebookEvaluation collection
  237. * @param \Doctrine\Common\Collections\ArrayCollection|array $entities
  238. * @return array
  239. */
  240. private static function createEvaluationObjectsFromEntities($entities)
  241. {
  242. $alleval = array();
  243. foreach ($entities as $gradebookEvaluation) {
  244. $eval= new Evaluation();
  245. $eval->set_id($gradebookEvaluation->getId());
  246. $eval->set_name($gradebookEvaluation->getName());
  247. $eval->set_description($gradebookEvaluation->getDescription());
  248. $eval->set_user_id($gradebookEvaluation->getUserId());
  249. $eval->set_course_code($gradebookEvaluation->getCourse()->getCode());
  250. $eval->set_category_id($gradebookEvaluation->getCategoryId());
  251. $eval->set_date(api_get_local_time($gradebookEvaluation->getCreatedAt()));
  252. $eval->set_weight($gradebookEvaluation->getWeight());
  253. $eval->set_max($gradebookEvaluation->getMax());
  254. $eval->set_visible($gradebookEvaluation->getVisible());
  255. $eval->set_type($gradebookEvaluation->getType());
  256. $eval->set_locked($gradebookEvaluation->getLocked());
  257. $eval->setSessionId(api_get_session_id());
  258. $alleval[] = $eval;
  259. }
  260. return $alleval;
  261. }
  262. /**
  263. * @param array $result
  264. * @return array
  265. */
  266. private static function create_evaluation_objects_from_sql_result($result)
  267. {
  268. $alleval = array();
  269. if (Database::num_rows($result)) {
  270. while ($data = Database::fetch_array($result)) {
  271. $eval= new Evaluation();
  272. $eval->set_id($data['id']);
  273. $eval->set_name($data['name']);
  274. $eval->set_description($data['description']);
  275. $eval->set_user_id($data['user_id']);
  276. $eval->set_course_code($data['course_code']);
  277. $eval->set_category_id($data['category_id']);
  278. $eval->set_date(api_get_local_time($data['created_at']));
  279. $eval->set_weight($data['weight']);
  280. $eval->set_max($data['max']);
  281. $eval->set_visible($data['visible']);
  282. $eval->set_type($data['type']);
  283. $eval->set_locked($data['locked']);
  284. $eval->setSessionId(api_get_session_id());
  285. $alleval[] = $eval;
  286. }
  287. }
  288. return $alleval;
  289. }
  290. /**
  291. * Insert this evaluation into the database
  292. */
  293. public function add()
  294. {
  295. if (isset($this->name) &&
  296. isset($this->user_id) &&
  297. isset($this->weight) &&
  298. isset ($this->eval_max) &&
  299. isset($this->visible)
  300. ) {
  301. $em = Database::getManager();
  302. $createdAt = new DateTime(api_get_utc_datetime(), new DateTimeZone('UTC'));
  303. $gradebookEvaluation = new \Chamilo\CoreBundle\Entity\GradebookEvaluation();
  304. $gradebookEvaluation
  305. ->setName($this->get_name())
  306. ->setUserId($this->get_user_id())
  307. ->setWeight($this->get_weight())
  308. ->setMax($this->get_max())
  309. ->setVisible($this->is_visible())
  310. ->setCreatedAt($createdAt)
  311. ->setLocked(false);
  312. if (isset($this->description)) {
  313. $gradebookEvaluation->setDescription($this->get_description());
  314. }
  315. if (isset($this->course_code)) {
  316. $course = $em->getRepository('ChamiloCoreBundle:Course')->findOneBy([
  317. 'code' => $this->get_course_code()
  318. ]);
  319. $gradebookEvaluation->setCourse($course);
  320. }
  321. if (isset($this->category)) {
  322. $gradebookEvaluation->setCategoryId($this->get_category_id());
  323. }
  324. if (empty($this->type)) {
  325. $this->type = 'evaluation';
  326. $gradebookEvaluation->setType($this->get_type());
  327. }
  328. $em->persist($gradebookEvaluation);
  329. $em->flush();
  330. $this->set_id($gradebookEvaluation->getId());
  331. } else {
  332. die('Error in Evaluation add: required field empty');
  333. }
  334. }
  335. /**
  336. * @param int $idevaluation
  337. */
  338. public function add_evaluation_log($idevaluation)
  339. {
  340. if (!empty($idevaluation)) {
  341. $em = Database::getManager();
  342. $tbl_grade_linkeval_log = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINKEVAL_LOG);
  343. $eval = new Evaluation();
  344. $dateobject = $eval->load($idevaluation,null,null,null,null);
  345. $arreval = get_object_vars($dateobject[0]);
  346. if (!empty($arreval['id'])) {
  347. $row_old_weight = $em->find('ChamiloCoreBundle:GradebookEvaluation', $arreval['id']);
  348. $current_date = api_get_utc_datetime();
  349. $params = [
  350. 'id_linkeval_log' => $arreval['id'],
  351. 'name' => $arreval['name'],
  352. 'description' => $arreval['description'],
  353. 'created_at' => $current_date,
  354. 'weight' => $row_old_weight->getWeight(),
  355. 'visible' => $arreval['visible'],
  356. 'type' => 'evaluation',
  357. 'user_id_log' => api_get_user_id()
  358. ];
  359. Database::insert($tbl_grade_linkeval_log, $params);
  360. }
  361. }
  362. }
  363. /**
  364. * Update the properties of this evaluation in the database
  365. */
  366. public function save()
  367. {
  368. $em = Database::getManager();
  369. $gradebookEvaluation = $em->find('ChamiloCoreBundle:GradebookEvaluation', $this->id);
  370. if (!$gradebookEvaluation) {
  371. return;
  372. }
  373. $eval_log = new Evaluation();
  374. $eval_log->add_evaluation_log($this->id);
  375. $gradebookEvaluation
  376. ->setName($this->get_name())
  377. ->setUserId($this->get_user_id())
  378. ->setWeight($this->get_weight())
  379. ->setMax($this->get_max())
  380. ->setVisible($this->is_visible());
  381. if (isset($this->description)) {
  382. $gradebookEvaluation->setDescription($this->get_description());
  383. }
  384. if (isset($this->course_code)) {
  385. $course = $em->getRepository('ChamiloCoreBundle:Course')->findOneBy([
  386. 'code' => $this->get_course_code()
  387. ]);
  388. $gradebookEvaluation->setCourse($course);
  389. }
  390. if (isset($this->category)) {
  391. $gradebookEvaluation->setCategoryId($this->get_category_id());
  392. }
  393. //recorded history
  394. $em->persist($gradebookEvaluation);
  395. $em->flush();
  396. }
  397. /**
  398. * Delete this evaluation from the database
  399. */
  400. public function delete()
  401. {
  402. $em = Database::getManager();
  403. $gradebookEvaluation = $em->find('ChamiloCoreBundle:GradebookEvaluation', $this->id);
  404. $em->remove($gradebookEvaluation);
  405. $em->flush();
  406. }
  407. /**
  408. * Check if an evaluation name (with the same parent category) already exists
  409. * @param $name name to check (if not given, the name property of this object will be checked)
  410. * @param $parent parent category
  411. */
  412. public function does_name_exist($name, $parent)
  413. {
  414. if (!isset ($name)) {
  415. $name = $this->name;
  416. $parent = $this->category;
  417. }
  418. $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
  419. $sql = 'SELECT count(id) AS number'
  420. .' FROM '.$tbl_grade_evaluations
  421. ." WHERE name = '".Database::escape_string($name)."'";
  422. if (api_is_allowed_to_edit()) {
  423. $parent = Category::load($parent);
  424. $code = $parent[0]->get_course_code();
  425. $courseInfo = api_get_course_info($code);
  426. $courseId = $courseInfo['real_id'];
  427. if (isset($code) && $code != '0') {
  428. $main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  429. $sql .= ' AND user_id IN (
  430. SELECT user_id FROM '.$main_course_user_table.'
  431. WHERE
  432. c_id = '.$courseId.' AND
  433. status = '.COURSEMANAGER.'
  434. )';
  435. } else {
  436. $sql .= ' AND user_id = '.api_get_user_id();
  437. }
  438. }else {
  439. $sql .= ' AND user_id = '.api_get_user_id();
  440. }
  441. if (!isset ($parent)) {
  442. $sql.= ' AND category_id is null';
  443. } else {
  444. $sql.= ' AND category_id = '.intval($parent);
  445. }
  446. $result = Database::query($sql);
  447. $number=Database::fetch_row($result);
  448. return $number[0] != 0;
  449. }
  450. /**
  451. * Are there any results for this evaluation yet ?
  452. * The 'max' property should not be changed then.
  453. */
  454. public function has_results()
  455. {
  456. $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
  457. $sql = 'SELECT count(id) AS number
  458. FROM '.$tbl_grade_results.'
  459. WHERE evaluation_id = '.intval($this->id);
  460. $result = Database::query($sql);
  461. $number=Database::fetch_row($result);
  462. return ($number[0] != 0);
  463. }
  464. /**
  465. * Delete all results for this evaluation
  466. */
  467. public function delete_results()
  468. {
  469. $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
  470. $sql = 'DELETE FROM '.$tbl_grade_results.'
  471. WHERE evaluation_id = '.intval($this->id);
  472. Database::query($sql);
  473. }
  474. /**
  475. * Delete this evaluation and all underlying results.
  476. */
  477. public function delete_with_results()
  478. {
  479. $this->delete_results();
  480. $this->delete();
  481. }
  482. /**
  483. * Check if the given score is possible for this evaluation
  484. */
  485. public function is_valid_score($score)
  486. {
  487. return is_numeric($score) && $score >= 0 && $score <= $this->eval_max;
  488. }
  489. /**
  490. * Calculate the score of this evaluation
  491. * @param int $stud_id (default: all students who have results for this eval - then the average is returned)
  492. * @param string $type (best, average, ranking)
  493. * @return array (score, max) if student is given
  494. * array (sum of scores, number of scores) otherwise
  495. * or null if no scores available
  496. */
  497. public function calc_score($stud_id = null, $type = null)
  498. {
  499. $useSession = true;
  500. if (isset($stud_id) && empty($type)) {
  501. $key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id.'_'.$stud_id;
  502. $data = Session::read('calc_score');
  503. $results = isset($data[$key]) ? $data[$key] : null;
  504. if ($useSession == false) {
  505. $results = null;
  506. }
  507. if (empty($results)) {
  508. $results = Result::load(null, $stud_id, $this->id);
  509. Session::write('calc_score', array($key => $results));
  510. }
  511. $score = 0;
  512. /** @var Result $res */
  513. foreach ($results as $res) {
  514. $score = $res->get_score();
  515. }
  516. return array($score, $this->get_max());
  517. } else {
  518. $count = 0;
  519. $sum = 0;
  520. $bestResult = 0;
  521. $weight = 0;
  522. $sumResult = 0;
  523. $key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id;
  524. $data = Session::read('calc_score');
  525. $allResults = isset($data[$key]) ? $data[$key] : null;
  526. if ($useSession == false) {
  527. $allResults = null;
  528. }
  529. if (empty($allResults)) {
  530. $allResults = Result::load(null, null, $this->id);
  531. Session::write($key, $allResults);
  532. }
  533. $students = array();
  534. /** @var Result $res */
  535. foreach ($allResults as $res) {
  536. $score = $res->get_score();
  537. if (!empty($score) || $score == '0') {
  538. $count++;
  539. $sum += $score / $this->get_max();
  540. $sumResult += $score;
  541. if ($score > $bestResult) {
  542. $bestResult = $score;
  543. }
  544. $weight = $this->get_max();
  545. }
  546. $students[$res->get_user_id()] = $score;
  547. }
  548. if (empty($count)) {
  549. return null;
  550. }
  551. switch ($type) {
  552. case 'best':
  553. return array($bestResult, $weight);
  554. break;
  555. case 'average':
  556. return array($sumResult/$count, $weight);
  557. break;
  558. case 'ranking':
  559. $students = array();
  560. /** @var Result $res */
  561. foreach ($allResults as $res) {
  562. $score = $res->get_score();
  563. $students[$res->get_user_id()] = $score;
  564. }
  565. return AbstractLink::getCurrentUserRanking($stud_id, $students);
  566. break;
  567. default:
  568. return array($sum, $count);
  569. break;
  570. }
  571. }
  572. }
  573. /**
  574. * Generate an array of possible categories where this evaluation can be moved to.
  575. * Notice: its own parent will be included in the list: it's up to the frontend
  576. * to disable this element.
  577. * @return array 2-dimensional array - every element contains 3 subelements (id, name, level)
  578. */
  579. public function get_target_categories()
  580. {
  581. // - course independent evaluation
  582. // -> movable to root or other course independent categories
  583. // - evaluation inside a course
  584. // -> movable to root, independent categories or categories inside the course
  585. $user = (api_is_platform_admin() ? null : api_get_user_id());
  586. $targets = array();
  587. $level = 0;
  588. $root = array(0, get_lang('RootCat'), $level);
  589. $targets[] = $root;
  590. if (isset($this->course_code) && !empty($this->course_code)) {
  591. $crscats = Category::load(null,null,$this->course_code,0);
  592. foreach ($crscats as $cat) {
  593. $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1);
  594. $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id());
  595. }
  596. }
  597. $indcats = Category::load(null,$user,0,0);
  598. foreach ($indcats as $cat) {
  599. $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1);
  600. $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id());
  601. }
  602. return $targets;
  603. }
  604. /**
  605. * Internal function used by get_target_categories()
  606. * @param integer $level
  607. */
  608. private function add_target_subcategories($targets, $level, $catid)
  609. {
  610. $subcats = Category::load(null,null,null,$catid);
  611. foreach ($subcats as $cat) {
  612. $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1);
  613. $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id());
  614. }
  615. return $targets;
  616. }
  617. /**
  618. * Move this evaluation to the given category.
  619. * If this evaluation moves from inside a course to outside,
  620. * its course code is also changed.
  621. */
  622. public function move_to_cat($cat)
  623. {
  624. $this->set_category_id($cat->get_id());
  625. if ($this->get_course_code() != $cat->get_course_code()) {
  626. $this->set_course_code($cat->get_course_code());
  627. }
  628. $this->save();
  629. }
  630. /**
  631. * Retrieve evaluations where a student has results for
  632. * and return them as an array of Evaluation objects
  633. * @param int $cat_id parent category (use 'null' to retrieve them in all categories)
  634. * @param int $stud_id student id
  635. */
  636. public static function get_evaluations_with_result_for_student($cat_id = null, $stud_id)
  637. {
  638. $em = Database::getManager();
  639. $query = $em->createQuery();
  640. $dql = '
  641. SELECT ge FROM ChamiloCoreBundle:GradebookEvaluation ge
  642. WHERE gc IN (
  643. SELECT gr.evaluationId FROM ChamiloCoreBundle:GradebookResult gr
  644. WHERE gr.userId = :user AND gr.score IS NOT NULL
  645. )
  646. ';
  647. $queryParams = ['user' => intval($stud_id)];
  648. if (!api_is_allowed_to_edit()) {
  649. $dql .= 'AND ge.visible = 1 ';
  650. }
  651. if (isset($cat_id)) {
  652. $dql .= 'AND ge.categoryId = :category ';
  653. $queryParams['category'] = intval($cat_id);
  654. } else {
  655. $dql .= 'AND ge.categoryId >= 0 ';
  656. }
  657. $result = $query->setParameters($queryParams)->getResult();
  658. $alleval = Evaluation::createEvaluationObjectsFromEntities($result);
  659. return $alleval;
  660. }
  661. /**
  662. * Get a list of students that do not have a result record for this evaluation
  663. */
  664. public function get_not_subscribed_students($first_letter_user = '')
  665. {
  666. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  667. $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
  668. $sql = 'SELECT user_id,lastname,firstname,username FROM '.$tbl_user
  669. ." WHERE lastname LIKE '".Database::escape_string($first_letter_user)."%'"
  670. .' AND status = '.STUDENT
  671. .' AND user_id NOT IN'
  672. .' (SELECT user_id FROM '.$tbl_grade_results
  673. .' WHERE evaluation_id = '.intval($this->id)
  674. .' )'
  675. .' ORDER BY lastname';
  676. $result = Database::query($sql);
  677. $users = Database::store_result($result);
  678. return $users;
  679. }
  680. /**
  681. * Find evaluations by name
  682. * @param string $name_mask search string
  683. * @return array evaluation objects matching the search criterium
  684. * @todo can be written more efficiently using a new (but very complex) sql query
  685. */
  686. public function find_evaluations($name_mask,$selectcat)
  687. {
  688. $rootcat = Category::load($selectcat);
  689. $evals = $rootcat[0]->get_evaluations((api_is_allowed_to_create_course() ? null : api_get_user_id()), true);
  690. $foundevals = array();
  691. foreach ($evals as $eval) {
  692. if (!(api_strpos(api_strtolower($eval->get_name()), api_strtolower($name_mask)) === false)) {
  693. $foundevals[] = $eval;
  694. }
  695. }
  696. return $foundevals;
  697. }
  698. public function get_item_type()
  699. {
  700. return 'E';
  701. }
  702. public function get_icon_name()
  703. {
  704. return $this->has_results() ? 'evalnotempty' : 'evalempty';
  705. }
  706. /**
  707. * Locks an evaluation, only one who can unlock it is the platform administrator.
  708. * @param int locked 1 or unlocked 0
  709. *
  710. **/
  711. function lock($locked)
  712. {
  713. $em = Database::getManager();
  714. $gradebookEvaluation = $em->find('ChamiloCoreBundle:GradebookEvaluation', $this->id);
  715. if ($gradebookEvaluation) {
  716. $gradebookEvaluation->setLocked($locked);
  717. $em->persist($gradebookEvaluation);
  718. $em->flush();
  719. }
  720. }
  721. function check_lock_permissions()
  722. {
  723. if (api_is_platform_admin()) {
  724. return true;
  725. } else {
  726. if ($this->is_locked()) {
  727. api_not_allowed();
  728. }
  729. }
  730. }
  731. function delete_linked_data()
  732. {
  733. }
  734. public function getStudentList()
  735. {
  736. return $this->studentList;
  737. }
  738. public function setStudentList($list)
  739. {
  740. $this->studentList = $list;
  741. }
  742. }