PageRenderTime 48ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/appLms/lib/lib.preassessment.php

https://github.com/wanadli75/cocalms
PHP | 683 lines | 372 code | 106 blank | 205 comment | 59 complexity | aa9dbc3fa5d2f8eb3233f1005f190ac8 MD5 | raw file
Possible License(s): GPL-2.0, CC-BY-3.0
  1. <?php defined("IN_FORMA") or die('Direct access is forbidden.');
  2. /* ======================================================================== \
  3. | FORMA - The E-Learning Suite |
  4. | |
  5. | Copyright (c) 2013 (Forma) |
  6. | http://www.formalms.org |
  7. | License http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt |
  8. | |
  9. | from docebo 4.0.5 CE 2008-2012 (c) docebo |
  10. | License http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt |
  11. \ ======================================================================== */
  12. /**
  13. * @package DoceoLms
  14. * @subpackage course management
  15. * @category library
  16. * @author Fabio Pirovano
  17. * @version $Id:$
  18. * @since 3.5
  19. *
  20. * ( editor = Eclipse 3.2.0[phpeclipse,subclipse,WTP], tabwidth = 4 )
  21. */
  22. define("RULE_ID", 0);
  23. define("RULE_ID_ASSESS", 1);
  24. define("RULE_TYPE", 2);
  25. define("RULE_SETTING", 3);
  26. define("RULE_EFFECT", 4);
  27. define("RULE_CASUALTIES", 5);
  28. define("USER_ASSES_ID", 0);
  29. define("USER_ASSES_ID_USER", 1);
  30. define("USER_ASSES_TYPE", 2);
  31. define("USER_ASSES_TYPE_ADMIN", 'admin');
  32. define("USER_ASSES_TYPE_USER", 'user');
  33. define("RULE_DEFAULT", 0);
  34. define("RULE_LESSER", 1);
  35. define("RULE_BETWEEN", 2);
  36. define("RULE_GREATER", 3);
  37. /**
  38. * manage the totality of preassessment
  39. */
  40. class AssessmentList {
  41. var $user_field = array(
  42. USER_ASSES_ID => 'id_assessment',
  43. USER_ASSES_ID_USER => 'id_user',
  44. USER_ASSES_TYPE => 'type_of'
  45. );
  46. function tableUserAssessment() { return $GLOBALS['prefix_lms'].'_assessment_user'; }
  47. function courseType() { return 'assessment'; }
  48. function fetch_row($re) { return sql_fetch_row($re); }
  49. function fetch_array($re) { return mysql_fetch_array($re); }
  50. function num_rows($re) { return mysql_num_rows($re); }
  51. function _query($query) { $re = sql_query($query); return $re; }
  52. function AssessmentList() {
  53. require_once($GLOBALS['where_lms'].'/lib/lib.course.php');
  54. $this->man_course = new Man_Course();
  55. ksort($this->user_field);
  56. reset($this->user_field);
  57. }
  58. /**
  59. * return the list of assessment created (note: an assessment is a course)
  60. * @return array array( id_course => int, name => string, code => string )
  61. */
  62. function getAllAssessment() {
  63. return $this->man_course->getAllCourses(false, $this->courseType());
  64. }
  65. function getAssessment($id_assessment) {
  66. return $this->man_course->getCourseInfo($id_assessment);
  67. }
  68. function saveAssessment($id_assessment, $assessment_data) {
  69. if($id_assessment == 0) {
  70. // create the course
  71. $course_info = array(
  72. 'code' => $assessment_data['code'],
  73. 'name' => $assessment_data['name'],
  74. 'description' => $assessment_data['description'],
  75. 'lang_code' => getLanguage(),
  76. 'course_type' => $this->courseType(),
  77. 'show_rules' => 2,
  78. 'status' => 2,
  79. 'direct_play' => 1
  80. );
  81. $id_course = $this->man_course->addCourse($course_info);
  82. if($id_course == false) return false;
  83. $level_idst =& DoceboCourse::createCourseLevel($id_course);
  84. if($level_idst == false) return false;
  85. $id_main = $this->man_course->addMainToCourse($id_course, Lang::t('_PREASSESSMENT_MENU', 'preassessment', 'framework'));
  86. if($id_main == false) return false;
  87. $re = true;
  88. $perm = array();
  89. $perm['7'] = array('view');
  90. $perm['6'] = array('view');
  91. $perm['3'] = array('view');
  92. $re &= $this->man_course->addModuleToCourse($id_course, $level_idst, $id_main, false, 'organization', 'organization', $perm );
  93. $perm = array();
  94. $perm['7'] = array('view', 'home', 'lesson', 'public');
  95. $perm['6'] = array('view', 'home', 'lesson', 'public');
  96. $re &= $this->man_course->addModuleToCourse($id_course, $level_idst, $id_main, false, 'storage', 'display', $perm);
  97. $perm = array();
  98. $perm['7'] = array('view', 'mod');
  99. $perm['6'] = array('view', 'mod');
  100. $re &= $this->man_course->addModuleToCourse($id_course, $level_idst, $id_main, false, 'coursereport', 'coursereport', $perm );
  101. //after creating the assessment course, create directly the test LO
  102. if ($re) {
  103. $query = "INSERT INTO %lms_test ( author, title, description ) VALUES "
  104. ."( '".Docebo::user()->getIdSt()."', '".$assessment_data['name']."', '' )";
  105. if (!sql_query($query)) {
  106. //...
  107. return false;
  108. }
  109. $id_test = sql_insert_id();
  110. if ($id_test) {
  111. require_once(_lms_.'/modules/organization/orglib.php');
  112. $odb= new OrgDirDb($id_course);
  113. $odb->addItem(0, $assessment_data['name'], 'test', $id_test, '0', '0', getLogUserId(), '1.0', '_DIFFICULT_MEDIUM', '', '', '', '', date('Y-m-d H:i:s'));
  114. } else {
  115. //...
  116. return false;
  117. }
  118. }
  119. return $re;
  120. } else {
  121. // modify the course
  122. $course_info = array(
  123. 'code' => $assessment_data['code'],
  124. 'name' => $assessment_data['name'],
  125. 'description' => $assessment_data['description']
  126. );
  127. return $this->man_course->saveCourse($id_assessment, $course_info);
  128. }
  129. }
  130. function deleteAssessment($id_assessment) {
  131. //$rules = new AssessmentRule();
  132. if(!$this->deleteAssessmentUser($id_assessment)) return false;
  133. //if(!$rules->deleteRules($id_assessment)) return false;
  134. if(!$this->man_course->deleteCourse($id_assessment)) return false;
  135. return true;
  136. }
  137. function getAssessmentAdministrator($id_assessment) {
  138. $users = array();
  139. $query = "
  140. SELECT ".implode($this->user_field, ',')."
  141. FROM ".$this->tableUserAssessment()."
  142. WHERE ".$this->user_field[USER_ASSES_TYPE]." = '".USER_ASSES_TYPE_ADMIN."'";
  143. if($id_assessment !== false) $query .= " AND ".$this->user_field[USER_ASSES_ID]." = '".$id_assessment."'";
  144. $re = $this->_query($query);
  145. while($row = $this->fetch_row($re)) {
  146. $users[] = $row[USER_ASSES_ID_USER];
  147. }
  148. return $users;
  149. }
  150. function getAssessmentUser($id_assessment) {
  151. $users = array();
  152. $query = "
  153. SELECT ".implode($this->user_field, ',')."
  154. FROM ".$this->tableUserAssessment()."
  155. WHERE ".$this->user_field[USER_ASSES_TYPE]." = '".USER_ASSES_TYPE_USER."'";
  156. if($id_assessment !== false) $query .= " AND ".$this->user_field[USER_ASSES_ID]." = '".$id_assessment."'";
  157. $re = $this->_query($query);
  158. while($row = $this->fetch_row($re)) {
  159. $users[] = $row[USER_ASSES_ID_USER];
  160. }
  161. return $users;
  162. }
  163. /**
  164. * add some user to an assessment
  165. * @param int $id_assessment the id of the assessment
  166. * @param int $user_type is the identifier of the type of the user, use the constant USER_ASSES_TYPE_ADMIN, USER_ASSES_TYPE_USER
  167. * @param array $user_list the list of user that must be assigned to the assesment.
  168. */
  169. function addAssessmentUser($id_assessment, $user_type, $user_list) {
  170. $op_result = true;
  171. if(empty($user_list)) return true;
  172. $query = "
  173. SELECT ".implode($this->user_field, ',')."
  174. FROM ".$this->tableUserAssessment()."
  175. WHERE ".$this->user_field[USER_ASSES_ID]." = '".$id_assessment."'
  176. AND ".$this->user_field[USER_ASSES_ID_USER]." IN ( ".implode($user_list, ',')." ) ";
  177. $re_query = $this->_query($query);
  178. $user_assigned = array();
  179. while($row = sql_fetch_row($re_query)) {
  180. $user_assigned[$row[USER_ASSES_ID_USER]] = $row[USER_ASSES_TYPE];
  181. }
  182. reset($user_list);
  183. while(list(, $id_user) = each($user_list)) {
  184. if(isset($user_assigned[$id_user])) {
  185. if($user_assigned[$id_user] != $user_type) {
  186. // modify the user level
  187. $upd_query = "
  188. UPDATE ".$this->tableUserAssessment()."
  189. SET ".$this->user_field[USER_ASSES_TYPE]." = '".$user_type."'
  190. WHERE ".$this->user_field[USER_ASSES_ID]." = '".$this->user_field[USER_ASSES_TYPE]."'
  191. AND ".$this->user_field[USER_ASSES_ID_USER]." = '".$id_user."'";
  192. $op_result &= $this->_query($upd_query);
  193. }
  194. // all right
  195. } else {
  196. // add the user
  197. $upd_query = "
  198. INSERT INTO ".$this->tableUserAssessment()."
  199. ( ".$this->user_field[USER_ASSES_ID].",
  200. ".$this->user_field[USER_ASSES_ID_USER].",
  201. ".$this->user_field[USER_ASSES_TYPE]." ) VALUES
  202. ( '".$id_assessment."',
  203. '".$id_user."',
  204. '".$user_type."' )";
  205. $op_result &= $this->_query($upd_query);
  206. }
  207. }
  208. return $op_result;
  209. }
  210. /**
  211. * assign a group of user to a preassessment, you can specify if the users are administrator or not
  212. * @param int $id_assessment the id of the assessment
  213. * @param int $user_type is the identifier of the type of the user, use the constant USER_ASSES_TYPE_ADMIN, USER_ASSES_TYPE_USER
  214. * @param array $user_list the list of user that must be assigned to the assesment.If a user is not in this list, but is actually
  215. * assigned to the ass. the function will remove the user
  216. */
  217. function updateAssessmentUser($id_assessment, $user_type, $user_list) {
  218. require_once(_lms_.'/lib/lib.course.php');
  219. require_once(_lms_.'/admin/models/SubscriptionAlms.php');
  220. $docebo_course = new DoceboCourse($id_assessment);
  221. $acl_man = Docebo::user()->getAclManager();
  222. $subsciption_model = new SubscriptionAlms($id_assessment, 0, 0);
  223. $level_idst = $docebo_course->getCourseLevel($id_assessment);
  224. if (count($level_idst) == 0 || $level_idst[1] == '')
  225. $level_idst = $docebo_course->createCourseLevel($id_assessment);
  226. $level = 3;
  227. if($user_type !== 'user')
  228. $level = 6;
  229. $op_result = true;
  230. $query = "
  231. SELECT ".implode($this->user_field, ',')."
  232. FROM ".$this->tableUserAssessment()."
  233. WHERE ".$this->user_field[USER_ASSES_ID]." = '".$id_assessment."'
  234. AND ".$this->user_field[USER_ASSES_TYPE]." = '".$user_type."'";
  235. $re_query = $this->_query($query);
  236. while($row = $this->fetch_row($re_query)) {
  237. if(isset($user_list[$row[USER_ASSES_ID_USER]]))
  238. {
  239. unset($user_list[$row[USER_ASSES_ID_USER]]);
  240. }
  241. else
  242. {
  243. $del_query = "
  244. DELETE FROM ".$this->tableUserAssessment()."
  245. WHERE ".$this->user_field[USER_ASSES_ID]." = '$id_assessment'
  246. AND ".$this->user_field[USER_ASSES_ID_USER]." = '".$row[USER_ASSES_ID_USER]."'";
  247. $op_result &= $this->_query($del_query);
  248. $acl_man->removeFromGroup($level_idst[$level], $row[USER_ASSES_ID_USER]);
  249. $subsciption_model->delUser($row[USER_ASSES_ID_USER]);
  250. }
  251. } // end while
  252. reset($user_list);
  253. while(list(, $id_user) = each($user_list)) {
  254. $upd_query = "
  255. INSERT INTO ".$this->tableUserAssessment()."
  256. ( ".$this->user_field[USER_ASSES_ID].",
  257. ".$this->user_field[USER_ASSES_ID_USER].",
  258. ".$this->user_field[USER_ASSES_TYPE]." ) VALUES
  259. ( '".$id_assessment."',
  260. '".$id_user."',
  261. '".$user_type."' )";
  262. $op_result &= $this->_query($upd_query);
  263. $acl_man->addToGroup($level_idst[$level], $id_user);
  264. $subsciption_model->subscribeUser($id_user, $level, false);
  265. }
  266. return $op_result;
  267. }
  268. /**
  269. * remove users assigned at the assesment
  270. * @param int $id_assessment the id of the assessment
  271. * @param array $user_list the list of user to remove
  272. */
  273. function deleteAssessmentUser($id_assessment, $user_list = false) {
  274. $query = "
  275. DELETE FROM ".$this->tableUserAssessment()."
  276. WHERE ".$this->user_field[USER_ASSES_ID]." = '$id_assessment'";
  277. if($user_list !== false) $query .= " AND ".$this->user_field[USER_ASSES_ID_USER]." IN ( ".implode(',', $user_list)." )";
  278. return $this->_query($query);
  279. }
  280. function getUserAssessmentSubsription($all_user_idst) {
  281. $assess = array('course_list' => array(), 'level_number' => array());
  282. if(!is_array($all_user_idst) || count($all_user_idst) == 0) return $assess;
  283. $query = "
  284. SELECT ".implode($this->user_field, ',')."
  285. FROM ".$this->tableUserAssessment()."
  286. WHERE ".$this->user_field[USER_ASSES_ID_USER]." IN ( ".implode(',', $all_user_idst)." ) ";
  287. $re = $this->_query($query);
  288. while($row = $this->fetch_row($re)) {
  289. $assess['course_list'][$row[USER_ASSES_ID]] = $row[USER_ASSES_ID];
  290. $new_lvl = ( $row[USER_ASSES_TYPE] == USER_ASSES_TYPE_ADMIN ? 6 : 3 );
  291. if(!isset($assess['level_number'][$row[USER_ASSES_ID]]) || $assess['level_number'][$row[USER_ASSES_ID]] < $new_lvl) {
  292. $assess['level_number'][$row[USER_ASSES_ID]] = $new_lvl;
  293. }
  294. }
  295. return $assess;
  296. }
  297. }
  298. class AssessmentRule {
  299. var $rules_field = array(
  300. RULE_ID => 'id_rule',
  301. RULE_ID_ASSESS => 'id_assessment',
  302. RULE_TYPE => 'rule_type',
  303. RULE_SETTING => 'rule_setting',
  304. RULE_EFFECT => 'rule_effect',
  305. RULE_CASUALTIES => 'rule_casualities'
  306. );
  307. /* function tableAssessmentRules() { return $GLOBALS['prefix_lms'].'_assessment_rules'; } */
  308. function fetch_row($re) { if($re === false) return false; return sql_fetch_row($re); }
  309. function fetch_array($re) { if($re === false) return false; return mysql_fetch_array($re); }
  310. function num_rows($re) { if($re === false) return 0; return mysql_num_rows($re); }
  311. function _query($query) { $re = sql_query($query); return $re; }
  312. /* function AssessmentRule() {
  313. ksort($this->rules_field);
  314. reset($this->rules_field);
  315. }
  316. function getAllRule($arr_assessment = false) {
  317. if(empty($arr_assessment)) return false;
  318. if(($arr_assessment !== false) && !is_array($arr_assessment)) $arr_assessment = array($arr_assessment);
  319. $query = "
  320. SELECT ".implode($this->rules_field, ',')."
  321. FROM ".$this->tableAssessmentRules()."
  322. WHERE 1 ";
  323. if($arr_assessment !== false) {
  324. $query .= " AND ".$this->rules_field[RULE_ID_ASSESS]."
  325. IN (".implode($arr_assessment, ',').")";
  326. }
  327. $query .= " ORDER BY ".$this->rules_field[RULE_TYPE]." ";
  328. return $this->_query($query);
  329. }
  330. function getRule($id_rule) {
  331. $query = "
  332. SELECT ".implode($this->rules_field, ',')."
  333. FROM ".$this->tableAssessmentRules()."
  334. WHERE ".$this->rules_field[RULE_ID]." = '".$id_rule."'";
  335. return $this->fetch_row($this->_query($query));
  336. }
  337. function resolveRuleTypePhrase(&$lang, $rule) {
  338. $cont = array();
  339. $rule_values = $this->parseRuleSetting($rule[RULE_TYPE], $rule[RULE_SETTING]);
  340. switch($rule[RULE_TYPE]) {
  341. case RULE_DEFAULT : return $lang->def('_RULE_DEFAULT');break;
  342. case RULE_GREATER : return str_replace('[score]', $rule_values[0], $lang->def('_RULE_GREATER'));break;
  343. case RULE_LESSER : return str_replace('[score]', $rule_values[0], $lang->def('_RULE_LESSER'));break;
  344. case RULE_BETWEEN : return str_replace(array('[score_1]', '[score_2]'), $rule_values, $lang->def('_RULE_BETWEEN'));break;
  345. }
  346. return '';
  347. }
  348. function parseRuleSetting($rule_type, $rule) {
  349. // format example : ";12" "12;23" "23"
  350. $rule_parsed = array();
  351. $rule_piece = explode(';', $rule);
  352. switch($rule_type) {
  353. case RULE_DEFAULT : return array();
  354. case RULE_GREATER : { return array($rule_piece[0]); };break;
  355. case RULE_LESSER : { return array($rule_piece[0]); };break;
  356. case RULE_BETWEEN : { return array($rule_piece[0], $rule_piece[1]); };break;
  357. }
  358. return array();
  359. }
  360. function compressRule($rule_type, $arr_rules) {
  361. return implode(';', $arr_rules);
  362. } */
  363. function parseEffects($effects_string) {
  364. $effects = array('course' => array(), 'coursepath' => array());
  365. $eff_piece = explode('|', $effects_string);
  366. if(isset($eff_piece[0]) && $eff_piece[0] != '') {
  367. $temp = explode(';', $eff_piece[0]);
  368. while(list(, $id) = each($temp)) $effects['course'][$id] = $id;
  369. }
  370. if(isset($eff_piece[1]) && $eff_piece[1] != '') {
  371. $temp = explode(';', $eff_piece[1]);
  372. while(list(, $id) = each($temp)) $effects['coursepath'][$id] = $id;
  373. }
  374. return $effects;
  375. }
  376. /* function setEffects($id_rule, $effects_course, $effects_coursepath) {
  377. $effects = '';
  378. if(is_array($effects_course)) $effects .= implode(';', $effects_course);
  379. $effects .= '|';
  380. if(is_array($effects_coursepath)) $effects .= implode(';', $effects_coursepath);
  381. $query = "
  382. UPDATE ".$this->tableAssessmentRules()."
  383. SET ".$this->rules_field[RULE_EFFECT]." = '".$effects."'
  384. WHERE ".$this->rules_field[RULE_ID]." = '".$id_rule."'";
  385. return $this->_query($query);
  386. } */
  387. /* function saveRule($id_rule, $rule_data) {
  388. if($id_rule == 0) {
  389. $query = "INSERT INTO ".$this->tableAssessmentRules()."
  390. ( ".$this->rules_field[RULE_ID].",
  391. ".$this->rules_field[RULE_ID_ASSESS].",
  392. ".$this->rules_field[RULE_TYPE].",
  393. ".$this->rules_field[RULE_SETTING].",
  394. ".$this->rules_field[RULE_EFFECT].",
  395. ".$this->rules_field[RULE_CASUALTIES]." ) VALUES
  396. ( NULL,
  397. '".$rule_data['id_assessment']."',
  398. '".$rule_data['rule_type']."',
  399. '".$rule_data['rule_setting']."',
  400. '',
  401. '0' )";
  402. if(!$re = $this->_query($query)) return false;
  403. return mysql_insert_id();
  404. } else {
  405. $query = "
  406. UPDATE ".$this->tableAssessmentRules()."
  407. SET ".$this->rules_field[RULE_ID_ASSESS] ." = '".$rule_data['id_assessment']."'
  408. ,".$this->rules_field[RULE_TYPE] ." = '".$rule_data['rule_type']."'
  409. ,".$this->rules_field[RULE_SETTING] ." = '".$rule_data['rule_setting']."' ";
  410. if(isset($rule_data['rule_effect']))
  411. $query .= ",".$this->rules_field[RULE_EFFECT]." = '".$rule_data['rule_effect']."' ";
  412. if(isset($rule_data['rule_casualties']))
  413. $query .= ",".$this->rules_field[RULE_CASUALTIES]." = '".$rule_data['rule_casualties']."' ";
  414. $query .= " WHERE ".$this->rules_field[RULE_ID]." = '".$id_rule."'";
  415. if(!$re = $this->_query($query)) return false;
  416. return $id_rule;
  417. }
  418. }
  419. function deleteRule($id_rule) {
  420. $query = "
  421. DELETE FROM ".$this->tableAssessmentRules()."
  422. WHERE ".$this->rules_field[RULE_ID]." = '".$id_rule."'";
  423. return $this->_query($query);
  424. }
  425. function deleteRules($id_assessment, $arr_rules = false) {
  426. $query = "
  427. DELETE FROM ".$this->tableAssessmentRules()."
  428. WHERE ".$this->rules_field[RULE_ID_ASSESS]." = '".$id_assessment."' ";
  429. if($arr_rules !== false) $query .= " AND ".$this->rules_field[RULE_ID]." IN ( ".implode(',', $arr_rules)." )";
  430. return $this->_query($query);
  431. }
  432. function scoreMatchRule() {
  433. } */
  434. function getRelatedEffectForAssessments($arr_assessment) {
  435. $effects_parsed = array('course' => array(), 'coursepath' => array());
  436. $rules = $this->getAllRule($arr_assessment);
  437. while($rule = $this->fetch_row($rules)) {
  438. $effects = $this->parseEffects($rule[RULE_EFFECT]);
  439. $effects_parsed['course'] = array_unique(array_merge($effects_parsed['course'], $effects['course']));
  440. $effects_parsed['coursepath'] = array_unique(array_merge($effects_parsed['coursepath'], $effects['coursepath']));
  441. }
  442. return $effects_parsed;
  443. }
  444. /**
  445. * return a complete list of all the course and coursepath related to a list of assessment and the course and
  446. * coursepath that match the user result for a specific assessment recoverd from the assessment rules and effect.
  447. * @param array $arr_assessment an array of assessment
  448. * @param array $result_in_assessment an array with the user result
  449. *
  450. * @return array array( 'parsed' => array('course' => , 'coursepath' => ),
  451. * 'to_apply' => array('course' => , 'coursepath' => ),
  452. * 'not_done' => array('course' => , 'coursepath' => ) )
  453. */
  454. function getCompleteEffectListForAssessmentWithUserResult($arr_assessment, $result_in_assessment) {
  455. $effects_parsed = array('course' => array(), 'coursepath' => array());
  456. $effects_to_apply = array('course' => array(), 'coursepath' => array());
  457. $effects_not = array('course' => array(), 'coursepath' => array());
  458. $rule_match = array();
  459. $rules = $this->getAllRule($arr_assessment);
  460. while($rule = $this->fetch_row($rules)) {
  461. $descr = $this->parseRuleSetting($rule[RULE_TYPE],$rule[RULE_SETTING]);
  462. $effects = $this->parseEffects($rule[RULE_EFFECT]);
  463. $effects_parsed['course'] = array_unique(array_merge($effects_parsed['course'], $effects['course']));
  464. $effects_parsed['coursepath'] = array_unique(array_merge($effects_parsed['coursepath'], $effects['coursepath']));
  465. if(isset($result_in_assessment[$rule[RULE_ID_ASSESS]])) {
  466. $score = $result_in_assessment[$rule[RULE_ID_ASSESS]];
  467. switch($rule[RULE_TYPE]) {
  468. case RULE_GREATER : {
  469. if($descr[0] <= $score) {
  470. $rule_match[$rule[RULE_ID_ASSESS]] = true;
  471. $effects_to_apply['course'] = array_unique(array_merge($effects_to_apply['course'], $effects['course']));
  472. $effects_to_apply['coursepath'] = array_unique(array_merge($effects_to_apply['coursepath'], $effects['coursepath']));
  473. }
  474. };break;
  475. case RULE_LESSER : {
  476. if($score < $descr[0]) {
  477. $rule_match[$rule[RULE_ID_ASSESS]] = true;
  478. $effects_to_apply['course'] = array_unique(array_merge($effects_to_apply['course'], $effects['course']));
  479. $effects_to_apply['coursepath'] = array_unique(array_merge($effects_to_apply['coursepath'], $effects['coursepath']));
  480. }
  481. };break;
  482. case RULE_BETWEEN : {
  483. if($descr[0] <= $score && $score < $descr[1]) {
  484. $rule_match[$rule[RULE_ID_ASSESS]] = true;
  485. $effects_to_apply['course'] = array_unique(array_merge($effects_to_apply['course'], $effects['course']));
  486. $effects_to_apply['coursepath'] = array_unique(array_merge($effects_to_apply['coursepath'], $effects['coursepath']));
  487. }
  488. };break;
  489. case RULE_DEFAULT : {
  490. $default_effects[$rule[RULE_ID_ASSESS]] = $effects;
  491. };break;
  492. } // end switch
  493. } else {
  494. $effects_not['course'] = array_unique(array_merge($effects_not['course'], $effects['course']));
  495. $effects_not['coursepath'] = array_unique(array_merge($effects_not['coursepath'], $effects['coursepath']));
  496. }
  497. } // end while
  498. // no rule matched ----------------------------------------------------------------------
  499. foreach($arr_assessment as $id_ass) {
  500. if(isset($result_in_assessment[$id_ass])) {
  501. // if the assessment is done
  502. if(isset($default_effects[$id_ass]) && !isset($rule_match[$id_ass])) {
  503. // but no rules find a match
  504. $effects_to_apply['course'] = array_unique(array_merge($effects_to_apply['course'], $default_effects[$id_ass]['course']));
  505. $effects_to_apply['coursepath'] = array_unique(array_merge($effects_to_apply['coursepath'], $default_effects[$id_ass]['coursepath']));
  506. }
  507. }
  508. }
  509. return array('parsed' => $effects_parsed, 'to_apply' => $effects_to_apply, 'not_done' => $effects_not);
  510. }
  511. function getEffectForScore($id_assessment, $score) {
  512. $rule_match = false;
  513. $default_effects = false;
  514. $effects_to_apply = array('course' => array(), 'coursepath' => array());
  515. $rules = $this->getAllRule($id_assessment);
  516. while($rule = $this->fetch_row($rules)) {
  517. $descr = $this->parseRuleSetting($rule[RULE_TYPE],$rule[RULE_SETTING]);
  518. $effects = $this->parseEffects($rule[RULE_EFFECT]);
  519. switch($rule[RULE_TYPE]) {
  520. case RULE_GREATER : {
  521. if($descr[0] <= $score) {
  522. $rule_match = true;
  523. $effects_to_apply['course'] = array_unique(array_merge($effects_to_apply['course'], $effects['course']));
  524. $effects_to_apply['coursepath'] = array_unique(array_merge($effects_to_apply['coursepath'], $effects['coursepath']));
  525. }
  526. };break;
  527. case RULE_LESSER : {
  528. if($score < $descr[0]) {
  529. $rule_match = true;
  530. $effects_to_apply['course'] = array_unique(array_merge($effects_to_apply['course'], $effects['course']));
  531. $effects_to_apply['coursepath'] = array_unique(array_merge($effects_to_apply['coursepath'], $effects['coursepath']));
  532. }
  533. };break;
  534. case RULE_BETWEEN : {
  535. if($descr[0] <= $score && $score < $descr[1]) {
  536. $rule_match = true;
  537. $effects_to_apply['course'] = array_unique(array_merge($effects_to_apply['course'], $effects['course']));
  538. $effects_to_apply['coursepath'] = array_unique(array_merge($effects_to_apply['coursepath'], $effects['coursepath']));
  539. }
  540. };break;
  541. case RULE_DEFAULT : {
  542. $default_effects = $effects;
  543. };break;
  544. }
  545. }
  546. // no rule matched
  547. if($default_effects !== false && $rule_match === false) { $effects_to_apply = $default_effects; }
  548. return $effects_to_apply;
  549. }
  550. } // end class AssessmentRule
  551. ?>