skill.lib.php 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Class SkillProfile
  5. * @package chamilo.library
  6. */
  7. class SkillProfile extends Model
  8. {
  9. public $columns = array('id', 'name', 'description');
  10. /**
  11. * Constructor
  12. */
  13. public function __construct()
  14. {
  15. $this->table = Database::get_main_table(TABLE_MAIN_SKILL_PROFILE);
  16. $this->table_rel_profile = Database::get_main_table(TABLE_MAIN_SKILL_REL_PROFILE);
  17. }
  18. /**
  19. * @return array
  20. */
  21. public function get_profiles()
  22. {
  23. $sql = "SELECT * FROM $this->table p
  24. INNER JOIN $this->table_rel_profile sp
  25. ON(p.id = sp.profile_id) ";
  26. $result = Database::query($sql);
  27. $profiles = Database::store_result($result, 'ASSOC');
  28. return $profiles;
  29. }
  30. /**
  31. * This function is for editing profile info from profile_id.
  32. * @param int $profileId
  33. * @param string $name
  34. * @param string $description
  35. */
  36. public function updateProfileInfo($profileId, $name, $description)
  37. {
  38. $profileId = intval($profileId);
  39. $sql = "UPDATE $this->table SET
  40. name = '$name',
  41. description = '$description'
  42. WHERE id = $profileId ";
  43. $result = Database::query($sql);
  44. return $result;
  45. }
  46. /**
  47. * Call the save method of the parent class and the SkillRelProfile object
  48. * @param array Params
  49. * @param bool Whether to show the query in parent save() method
  50. * @return mixed Profile ID or false if incomplete params
  51. */
  52. public function save($params, $show_query = false)
  53. {
  54. if (!empty($params)) {
  55. $profile_id = parent::save($params, $show_query);
  56. if ($profile_id) {
  57. $skill_rel_profile = new SkillRelProfile();
  58. if (isset($params['skills'])) {
  59. foreach ($params['skills'] as $skill_id) {
  60. $attributes = array('skill_id' => $skill_id, 'profile_id' => $profile_id);
  61. $skill_rel_profile->save($attributes);
  62. }
  63. }
  64. return $profile_id;
  65. }
  66. }
  67. return false;
  68. }
  69. /**
  70. * Delete a skill profile
  71. * @param int $id The skill profile id
  72. * @return boolean Whether delete a skill profile
  73. */
  74. public function delete($id)
  75. {
  76. Database::delete(
  77. $this->table_rel_profile,
  78. array(
  79. 'profile_id' => $id
  80. )
  81. );
  82. return parent::delete($id);
  83. }
  84. }
  85. /**
  86. * Class SkillRelProfile
  87. */
  88. class SkillRelProfile extends Model
  89. {
  90. public $columns = array('id', 'skill_id', 'profile_id');
  91. /**
  92. * Constructor
  93. */
  94. public function __construct()
  95. {
  96. $this->table = Database::get_main_table(TABLE_MAIN_SKILL_REL_PROFILE);
  97. $this->tableProfile = Database::get_main_table(TABLE_MAIN_SKILL_PROFILE);
  98. }
  99. /**
  100. * @param int $profileId
  101. * @return array
  102. */
  103. public function get_skills_by_profile($profileId)
  104. {
  105. $profileId = intval($profileId);
  106. $skills = $this->get_all(array('where' => array('profile_id = ? ' => $profileId)));
  107. $return = array();
  108. if (!empty($skills)) {
  109. foreach ($skills as $skill_data) {
  110. $return[] = $skill_data['skill_id'];
  111. }
  112. }
  113. return $return;
  114. }
  115. /**
  116. * This function is for getting profile info from profile_id.
  117. * @param int $profileId
  118. */
  119. public function getProfileInfo($profileId)
  120. {
  121. $sql = "SELECT * FROM $this->table p
  122. INNER JOIN $this->tableProfile pr
  123. ON (pr.id = p.profile_id)
  124. WHERE p.profile_id = ".intval($profileId);
  125. $result = Database::query($sql);
  126. $profileData = Database::fetch_array($result, 'ASSOC');
  127. return $profileData;
  128. }
  129. }
  130. /**
  131. * Class SkillRelSkill
  132. */
  133. class SkillRelSkill extends Model
  134. {
  135. public $columns = array('skill_id', 'parent_id', 'relation_type', 'level');
  136. /**
  137. * Constructor
  138. */
  139. public function __construct()
  140. {
  141. $this->table = Database::get_main_table(TABLE_MAIN_SKILL_REL_SKILL);
  142. }
  143. /**
  144. * Gets an element
  145. * @param int $id
  146. * @return array
  147. */
  148. public function get_skill_info($id)
  149. {
  150. if (empty($id)) {
  151. return array();
  152. }
  153. $result = Database::select(
  154. '*',
  155. $this->table,
  156. array('where' => array('skill_id = ?' => intval($id))),
  157. 'first'
  158. );
  159. return $result;
  160. }
  161. public function get_skill_parents($skill_id, $add_child_info = true)
  162. {
  163. $skill_id = intval($skill_id);
  164. $sql = 'SELECT child.* FROM '.$this->table.' child
  165. LEFT JOIN '.$this->table.' parent
  166. ON child.parent_id = parent.skill_id
  167. WHERE child.skill_id = '.$skill_id.' ';
  168. $result = Database::query($sql);
  169. $skill = Database::store_result($result, 'ASSOC');
  170. $skill = isset($skill[0]) ? $skill[0] : null;
  171. $parents = array();
  172. if (!empty($skill)) {
  173. if ($skill['parent_id'] != null) {
  174. $parents = self::get_skill_parents($skill['parent_id']);
  175. }
  176. if ($add_child_info) {
  177. $parents[] = $skill;
  178. }
  179. }
  180. return $parents;
  181. }
  182. /**
  183. * @param int $skill_id
  184. * @return array
  185. */
  186. public function get_direct_parents($skill_id)
  187. {
  188. $skill_id = intval($skill_id);
  189. $sql = 'SELECT parent_id as skill_id FROM '.$this->table.'
  190. WHERE skill_id = '.$skill_id.' ';
  191. $result = Database::query($sql);
  192. $skill = Database::store_result($result, 'ASSOC');
  193. $skill = isset($skill[0]) ? $skill[0] : null;
  194. $parents = array();
  195. if (!empty($skill)) {
  196. $parents[] = $skill;
  197. }
  198. return $parents;
  199. }
  200. /**
  201. * @param int $skill_id
  202. * @param bool $load_user_data
  203. * @param bool $user_id
  204. * @return array
  205. */
  206. public function get_children($skill_id, $load_user_data = false, $user_id = false)
  207. {
  208. $skills = $this->find('all', array('where' => array('parent_id = ? ' => $skill_id)));
  209. $skill_obj = new Skill();
  210. $skill_rel_user = new SkillRelUser();
  211. if ($load_user_data) {
  212. $passed_skills = $skill_rel_user->get_user_skills($user_id);
  213. $done_skills = array();
  214. foreach ($passed_skills as $done_skill) {
  215. $done_skills[] = $done_skill['skill_id'];
  216. }
  217. }
  218. if (!empty($skills)) {
  219. foreach ($skills as &$skill) {
  220. $skill['data'] = $skill_obj->get($skill['skill_id']);
  221. if (isset($skill['data']) && !empty($skill['data'])) {
  222. if (!empty($done_skills)) {
  223. $skill['data']['passed'] = 0;
  224. if (in_array($skill['skill_id'], $done_skills)) {
  225. $skill['data']['passed'] = 1;
  226. }
  227. }
  228. } else {
  229. $skill = null;
  230. }
  231. }
  232. }
  233. return $skills;
  234. }
  235. /**
  236. * @param array $params
  237. * @return bool
  238. */
  239. public function update_by_skill($params)
  240. {
  241. $result = Database::update($this->table, $params, array('skill_id = ? ' => $params['skill_id']));
  242. if ($result) {
  243. return true;
  244. }
  245. return false;
  246. }
  247. /**
  248. * @param int $skill_id
  249. * @param int $parent_id
  250. * @return bool
  251. */
  252. public function relation_exists($skill_id, $parent_id)
  253. {
  254. $result = $this->find(
  255. 'all',
  256. array('where' => array('skill_id = ? AND parent_id = ?' => array($skill_id, $parent_id)))
  257. );
  258. if (!empty($result)) {
  259. return true;
  260. }
  261. return false;
  262. }
  263. }
  264. /**
  265. * Class SkillRelGradebook
  266. */
  267. class SkillRelGradebook extends Model
  268. {
  269. public $columns = array('id', 'gradebook_id', 'skill_id');
  270. public function __construct()
  271. {
  272. $this->table = Database::get_main_table(TABLE_MAIN_SKILL_REL_GRADEBOOK);
  273. }
  274. /**
  275. * @param int $gradebook_id
  276. * @param int $skill_id
  277. * @return bool
  278. */
  279. public function exists_gradebook_skill($gradebook_id, $skill_id)
  280. {
  281. $result = $this->find(
  282. 'all',
  283. array('where' => array('gradebook_id = ? AND skill_id = ?' => array($gradebook_id, $skill_id)))
  284. );
  285. if (!empty($result)) {
  286. return true;
  287. }
  288. return false;
  289. }
  290. /**
  291. * Gets an element
  292. */
  293. public function get_skill_info($skill_id, $gradebook_id)
  294. {
  295. if (empty($skill_id)) {
  296. return array();
  297. }
  298. $result = Database::select(
  299. '*',
  300. $this->table,
  301. array('where' => array('skill_id = ? AND gradebook_id = ? ' => array($skill_id, $gradebook_id))),
  302. 'first'
  303. );
  304. return $result;
  305. }
  306. /**
  307. * @param int $skill_id
  308. * @param array $gradebook_list
  309. */
  310. public function update_gradebooks_by_skill($skill_id, $gradebook_list)
  311. {
  312. $original_gradebook_list = $this->find(
  313. 'all',
  314. array('where' => array('skill_id = ?' => array($skill_id)))
  315. );
  316. $gradebooks_to_remove = array();
  317. $gradebooks_to_add = array();
  318. $original_gradebook_list_ids = array();
  319. if (!empty($original_gradebook_list)) {
  320. foreach ($original_gradebook_list as $gradebook) {
  321. if (!in_array($gradebook['gradebook_id'], $gradebook_list)) {
  322. $gradebooks_to_remove[] = $gradebook['id'];
  323. }
  324. }
  325. foreach ($original_gradebook_list as $gradebook_item) {
  326. $original_gradebook_list_ids[] = $gradebook_item['gradebook_id'];
  327. }
  328. }
  329. if (!empty($gradebook_list)) {
  330. foreach ($gradebook_list as $gradebook_id) {
  331. if (!in_array($gradebook_id, $original_gradebook_list_ids)) {
  332. $gradebooks_to_add[] = $gradebook_id;
  333. }
  334. }
  335. }
  336. if (!empty($gradebooks_to_remove)) {
  337. foreach ($gradebooks_to_remove as $id) {
  338. $this->delete($id);
  339. }
  340. }
  341. if (!empty($gradebooks_to_add)) {
  342. foreach ($gradebooks_to_add as $gradebook_id) {
  343. $attributes = array('skill_id' => $skill_id, 'gradebook_id' => $gradebook_id);
  344. $this->save($attributes);
  345. }
  346. }
  347. }
  348. /**
  349. * @param array $params
  350. * @return bool|void
  351. */
  352. public function update_by_skill($params)
  353. {
  354. $skill_info = $this->exists_gradebook_skill($params['gradebook_id'], $params['skill_id']);
  355. if ($skill_info) {
  356. return;
  357. } else {
  358. $result = $this->save($params);
  359. }
  360. if ($result) {
  361. return true;
  362. }
  363. return false;
  364. }
  365. }
  366. /**
  367. * Class SkillRelUser
  368. */
  369. class SkillRelUser extends Model
  370. {
  371. public $columns = array('id', 'user_id', 'skill_id', 'acquired_skill_at', 'assigned_by', 'course_id', 'session_id');
  372. /**
  373. * Constructor
  374. */
  375. public function __construct()
  376. {
  377. $this->table = Database::get_main_table(TABLE_MAIN_SKILL_REL_USER);
  378. }
  379. /**
  380. * @param array $skill_list
  381. * @return array
  382. */
  383. public function get_user_by_skills($skill_list)
  384. {
  385. $users = array();
  386. if (!empty($skill_list)) {
  387. $skill_list = array_map('intval', $skill_list);
  388. $skill_list = implode("', '", $skill_list);
  389. $sql = "SELECT user_id FROM {$this->table}
  390. WHERE skill_id IN ('$skill_list') ";
  391. $result = Database::query($sql);
  392. $users = Database::store_result($result, 'ASSOC');
  393. }
  394. return $users;
  395. }
  396. /**
  397. * Get the achieved skills for the user
  398. * @param int $userId
  399. * @param int $courseId Optional. The course id
  400. * @param int $sessionId Optional. The session id
  401. * @return array The skill list. Otherwise return false
  402. */
  403. public function get_user_skills($userId, $courseId = 0, $sessionId = 0)
  404. {
  405. if (empty($userId)) {
  406. return array();
  407. }
  408. $courseId = intval($courseId);
  409. $sessionId = intval($sessionId);
  410. $whereConditions = array(
  411. 'user_id = ? ' => intval($userId)
  412. );
  413. if ($courseId > 0) {
  414. $whereConditions['AND course_id = ? '] = $courseId;
  415. $whereConditions['AND session_id = ?'] = $sessionId;
  416. }
  417. $result = Database::select(
  418. 'skill_id',
  419. $this->table,
  420. array(
  421. 'where' => $whereConditions
  422. ),
  423. 'all'
  424. );
  425. return $result;
  426. }
  427. /**
  428. * Get the relation data between user and skill
  429. * @param int $userId The user id
  430. * @param int $skillId The skill id
  431. * @param int $courseId The course id
  432. * @param int $sessionId Optional. The session id
  433. * @return array The relation data. Otherwise return false
  434. */
  435. public function getByUserAndSkill($userId, $skillId, $courseId, $sessionId = 0)
  436. {
  437. $where = array(
  438. 'user_id = ? AND skill_id = ? AND course_id = ? AND session_id = ?' => array(
  439. intval($userId),
  440. intval($skillId),
  441. intval($courseId),
  442. intval($sessionId)
  443. )
  444. );
  445. return Database::select('*', $this->table, array(
  446. 'where' => $where
  447. ), 'first');
  448. }
  449. }
  450. /**
  451. * Class Skill
  452. */
  453. class Skill extends Model
  454. {
  455. public $columns = array('id', 'name', 'description', 'access_url_id', 'short_code', 'icon', 'criteria');
  456. public $required = array('name');
  457. /** Array of colours by depth, for the coffee wheel. Each depth has 4 col */
  458. /*var $colours = array(
  459. 0 => array('#f9f0ab', '#ecc099', '#e098b0', '#ebe378'),
  460. 1 => array('#d5dda1', '#4a5072', '#8dae43', '#72659d'),
  461. 2 => array('#b28647', '#2e6093', '#393e64', '#1e8323'),
  462. 3 => array('#9f6652', '#9f6652', '#9f6652', '#9f6652'),
  463. 4 => array('#af643c', '#af643c', '#af643c', '#af643c'),
  464. 5 => array('#72659d', '#72659d', '#72659d', '#72659d'),
  465. 6 => array('#8a6e9e', '#8a6e9e', '#8a6e9e', '#8a6e9e'),
  466. 7 => array('#92538c', '#92538c', '#92538c', '#92538c'),
  467. 8 => array('#2e6093', '#2e6093', '#2e6093', '#2e6093'),
  468. 9 => array('#3a5988', '#3a5988', '#3a5988', '#3a5988'),
  469. 10 => array('#393e64', '#393e64', '#393e64', '#393e64'),
  470. );*/
  471. public function __construct()
  472. {
  473. $this->table = Database::get_main_table(TABLE_MAIN_SKILL);
  474. $this->table_user = Database::get_main_table(TABLE_MAIN_USER);
  475. $this->table_skill_rel_gradebook = Database::get_main_table(TABLE_MAIN_SKILL_REL_GRADEBOOK);
  476. $this->table_skill_rel_user = Database::get_main_table(TABLE_MAIN_SKILL_REL_USER);
  477. $this->table_course = Database::get_main_table(TABLE_MAIN_COURSE);
  478. $this->table_skill_rel_skill = Database::get_main_table(TABLE_MAIN_SKILL_REL_SKILL);
  479. $this->table_gradebook = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
  480. $this->sessionTable = Database::get_main_table(TABLE_MAIN_SESSION);
  481. }
  482. /**
  483. * Gets an element
  484. * @param int $id
  485. *
  486. * @return array|mixed
  487. */
  488. public function get($id)
  489. {
  490. $result = parent::get($id);
  491. $result['web_icon_path'] = api_get_path(WEB_UPLOAD_PATH).'badges/'.$result['icon'];
  492. return $result;
  493. }
  494. /**
  495. * @param int $id
  496. * @return array
  497. */
  498. public function get_skill_info($id)
  499. {
  500. $skill_rel_skill = new SkillRelSkill();
  501. $skill_info = $this->get($id);
  502. if (!empty($skill_info)) {
  503. $skill_info['extra'] = $skill_rel_skill->get_skill_info($id);
  504. $skill_info['gradebooks'] = self::get_gradebooks_by_skill($id);
  505. }
  506. return $skill_info;
  507. }
  508. /**
  509. * @param array $skill_list
  510. * @return array
  511. */
  512. public function get_skills_info($skill_list)
  513. {
  514. $skill_list = array_map('intval', $skill_list);
  515. $skill_list = implode("', '", $skill_list);
  516. $sql = "SELECT * FROM {$this->table} WHERE id IN ('$skill_list') ";
  517. $result = Database::query($sql);
  518. $users = Database::store_result($result, 'ASSOC');
  519. foreach ($users as &$user) {
  520. if (!$user['icon']) {
  521. continue;
  522. }
  523. $user['icon_small'] = sprintf("badges/%s-small.png", sha1($user['name']));
  524. }
  525. return $users;
  526. }
  527. /**
  528. * @param bool $load_user_data
  529. * @param bool $user_id
  530. * @param int $id
  531. * @param int $parent_id
  532. * @return array
  533. */
  534. public function get_all($load_user_data = false, $user_id = false, $id = null, $parent_id = null)
  535. {
  536. $id_condition = '';
  537. if (!empty($id)) {
  538. $id = intval($id);
  539. $id_condition = " WHERE s.id = $id";
  540. }
  541. if (!empty($parent_id)) {
  542. $parent_id = intval($parent_id);
  543. if (empty($id_condition)) {
  544. $id_condition = " WHERE ss.parent_id = $parent_id";
  545. } else {
  546. $id_condition = " AND ss.parent_id = $parent_id";
  547. }
  548. }
  549. $sql = "SELECT
  550. s.id,
  551. s.name,
  552. s.description,
  553. ss.parent_id,
  554. ss.relation_type,
  555. s.icon,
  556. s.short_code,
  557. s.status
  558. FROM {$this->table} s
  559. INNER JOIN {$this->table_skill_rel_skill} ss
  560. ON (s.id = ss.skill_id) $id_condition
  561. ORDER BY ss.id, ss.parent_id";
  562. $result = Database::query($sql);
  563. $skills = array();
  564. $webPath = api_get_path(WEB_UPLOAD_PATH);
  565. if (Database::num_rows($result)) {
  566. while ($row = Database::fetch_array($result, 'ASSOC')) {
  567. $skill_rel_skill = new SkillRelSkill();
  568. $parents = $skill_rel_skill->get_skill_parents($row['id']);
  569. $row['level'] = count($parents) - 1;
  570. $row['gradebooks'] = self::get_gradebooks_by_skill($row['id']);
  571. $row['web_icon_path'] = $webPath.'badges/'.$row['icon'];
  572. $skills[$row['id']] = $row;
  573. }
  574. }
  575. // Load all children of the parent_id
  576. if (!empty($skills) && !empty($parent_id)) {
  577. foreach ($skills as $skill) {
  578. $children = self::get_all($load_user_data, $user_id, $id, $skill['id']);
  579. if (!empty($children)) {
  580. //$skills = array_merge($skills, $children);
  581. $skills = $skills + $children;
  582. }
  583. }
  584. }
  585. return $skills;
  586. }
  587. /**
  588. * @param int $skill_id
  589. * @return array|resource
  590. */
  591. public function get_gradebooks_by_skill($skill_id)
  592. {
  593. $skill_id = intval($skill_id);
  594. $sql = "SELECT g.* FROM {$this->table_gradebook} g
  595. INNER JOIN {$this->table_skill_rel_gradebook} sg
  596. ON g.id = sg.gradebook_id
  597. WHERE sg.skill_id = $skill_id";
  598. $result = Database::query($sql);
  599. $result = Database::store_result($result, 'ASSOC');
  600. return $result;
  601. }
  602. /**
  603. * Get one level childrens
  604. *
  605. * @param int $skill_id
  606. * @param bool $load_user_data
  607. * @return array
  608. */
  609. public function get_children($skill_id, $load_user_data = false)
  610. {
  611. $skill_rel_skill = new SkillRelSkill();
  612. if ($load_user_data) {
  613. $user_id = api_get_user_id();
  614. $skills = $skill_rel_skill->get_children($skill_id, true, $user_id);
  615. } else {
  616. $skills = $skill_rel_skill->get_children($skill_id);
  617. }
  618. return $skills;
  619. }
  620. /**
  621. * Get all children of the current node (recursive)
  622. * @param int $skillId
  623. * @return array
  624. */
  625. public function get_all_children($skillId)
  626. {
  627. $skill_rel_skill = new SkillRelSkill();
  628. $children = $skill_rel_skill->get_children($skillId);
  629. foreach ($children as $child) {
  630. $subChildren = $this->get_all_children($child['skill_id']);
  631. }
  632. if (!empty($subChildren)) {
  633. $children = array_merge($children, $subChildren);
  634. }
  635. return $children;
  636. }
  637. /**
  638. * Gets all parents from from the wanted skill
  639. */
  640. public function get_parents($skill_id)
  641. {
  642. $skill_rel_skill = new SkillRelSkill();
  643. $skills = $skill_rel_skill->get_skill_parents($skill_id, true);
  644. foreach ($skills as &$skill) {
  645. $skill['data'] = self::get($skill['skill_id']);
  646. }
  647. return $skills;
  648. }
  649. /**
  650. * All direct parents
  651. */
  652. public function get_direct_parents($skill_id)
  653. {
  654. $skill_rel_skill = new SkillRelSkill();
  655. $skills = $skill_rel_skill->get_direct_parents($skill_id, true);
  656. foreach($skills as &$skill) {
  657. $skill['data'] = self::get($skill['skill_id']);
  658. $skill_info2 = $skill_rel_skill->get_skill_info($skill['skill_id']);
  659. $skill['data']['parent_id'] = $skill_info2['parent_id'];
  660. }
  661. return $skills;
  662. }
  663. /**
  664. * Adds a new skill
  665. * @param array $params
  666. * @return bool|null
  667. */
  668. public function add($params)
  669. {
  670. if (!isset($params['parent_id'])) {
  671. $params['parent_id'] = 1;
  672. }
  673. if (!is_array($params['parent_id'])) {
  674. $params['parent_id'] = array($params['parent_id']);
  675. }
  676. $skill_rel_skill = new SkillRelSkill();
  677. $skill_rel_gradebook = new SkillRelGradebook();
  678. //Saving name, description
  679. $skill_id = $this->save($params);
  680. if ($skill_id) {
  681. //Saving skill_rel_skill (parent_id, relation_type)
  682. foreach ($params['parent_id'] as $parent_id) {
  683. $relation_exists = $skill_rel_skill->relation_exists($skill_id, $parent_id);
  684. if (!$relation_exists) {
  685. $attributes = array(
  686. 'skill_id' => $skill_id,
  687. 'parent_id' => $parent_id,
  688. 'relation_type' => (isset($params['relation_type'])?$params['relation_type']:0),
  689. //'level' => $params['level'],
  690. );
  691. $skill_rel_skill->save($attributes);
  692. }
  693. }
  694. if (!empty($params['gradebook_id'])) {
  695. foreach ($params['gradebook_id'] as $gradebook_id) {
  696. $attributes = array();
  697. $attributes['gradebook_id'] = $gradebook_id;
  698. $attributes['skill_id'] = $skill_id;
  699. $skill_rel_gradebook->save($attributes);
  700. }
  701. }
  702. return $skill_id;
  703. }
  704. return null;
  705. }
  706. /**
  707. * @param int $user_id
  708. * @param int $gradebook_id
  709. * @param int $courseId
  710. * @param int $sessionId
  711. */
  712. public function add_skill_to_user($user_id, $gradebook_id, $courseId = 0, $sessionId = 0)
  713. {
  714. $skill_gradebook = new SkillRelGradebook();
  715. $skill_rel_user = new SkillRelUser();
  716. $skill_gradebooks = $skill_gradebook->get_all(array('where' => array('gradebook_id = ?' => $gradebook_id)));
  717. if (!empty($skill_gradebooks)) {
  718. foreach ($skill_gradebooks as $skill_gradebook) {
  719. $user_has_skill = $this->user_has_skill($user_id, $skill_gradebook['skill_id'], $courseId, $sessionId);
  720. if (!$user_has_skill) {
  721. $params = array(
  722. 'user_id' => $user_id,
  723. 'skill_id' => $skill_gradebook['skill_id'],
  724. 'acquired_skill_at' => api_get_utc_datetime(),
  725. 'course_id' => intval($courseId),
  726. 'session_id' => intval($sessionId)
  727. );
  728. $skill_rel_user->save($params);
  729. }
  730. }
  731. }
  732. }
  733. /* Deletes a skill */
  734. public function delete($skill_id)
  735. {
  736. /*$params = array('skill_id' => $skill_id);
  737. $skill_rel_skill = new SkillRelSkill();
  738. $skills = $skill_rel_skill->get_all(array('where'=>array('skill_id = ?' =>$skill_id)));
  739. $skill_rel_profile = new SkillRelProfile();
  740. $skill_rel_gradebook = new SkillRelGradebook();
  741. $skill_rel_user = new SkillRelUser();
  742. $this->delete($skill_id);
  743. $skill_rel_gradebook->delete($params);*/
  744. }
  745. /**
  746. * @param array $params
  747. * @return null
  748. */
  749. public function edit($params)
  750. {
  751. if (!isset($params['parent_id'])) {
  752. $params['parent_id'] = 1;
  753. }
  754. $skill_rel_skill = new SkillRelSkill();
  755. $skill_rel_gradebook = new SkillRelGradebook();
  756. //Saving name, description
  757. $this->update($params);
  758. $skill_id = $params['id'];
  759. if ($skill_id) {
  760. //Saving skill_rel_skill (parent_id, relation_type)
  761. if (!is_array($params['parent_id'])) {
  762. $params['parent_id'] = array($params['parent_id']);
  763. }
  764. foreach ($params['parent_id'] as $parent_id) {
  765. $relation_exists = $skill_rel_skill->relation_exists($skill_id, $parent_id);
  766. if (!$relation_exists) {
  767. $attributes = array(
  768. 'skill_id' => $skill_id,
  769. 'parent_id' => $parent_id,
  770. 'relation_type' => $params['relation_type'],
  771. //'level' => $params['level'],
  772. );
  773. $skill_rel_skill->update_by_skill($attributes);
  774. }
  775. }
  776. $skill_rel_gradebook->update_gradebooks_by_skill($skill_id, $params['gradebook_id']);
  777. return $skill_id;
  778. }
  779. return null;
  780. }
  781. /**
  782. * Get user's skills
  783. *
  784. * @param int $userId User's id
  785. * @param bool $get_skill_data
  786. */
  787. public function get_user_skills($user_id, $get_skill_data = false)
  788. {
  789. $user_id = intval($user_id);
  790. $sql = 'SELECT DISTINCT s.id, s.name, s.icon
  791. FROM '.$this->table_skill_rel_user.' u
  792. INNER JOIN '.$this->table.' s
  793. ON u.skill_id = s.id
  794. WHERE user_id = '.$user_id;
  795. $result = Database::query($sql);
  796. $skills = Database::store_result($result, 'ASSOC');
  797. $uploadPath = api_get_path(WEB_UPLOAD_PATH);
  798. $clean_skill = array();
  799. if (!empty($skills)) {
  800. foreach ($skills as $skill) {
  801. if ($get_skill_data) {
  802. $iconThumb = null;
  803. $iconPath = null;
  804. if (!empty($skill['icon'])) {
  805. $iconThumb = sprintf(
  806. "badges/%s-small.png",
  807. sha1($skill['name'])
  808. );
  809. $iconPath = sprintf(
  810. "badges/%s.png",
  811. sha1($skill['name'])
  812. );
  813. }
  814. $clean_skill[$skill['id']] = array_merge(
  815. $skill,
  816. array(
  817. 'web_icon_thumb_path' => $uploadPath.$iconThumb,
  818. 'web_icon_path' => $uploadPath.$iconPath
  819. )
  820. );
  821. } else {
  822. $clean_skill[$skill['id']] = $skill['id'];
  823. }
  824. }
  825. }
  826. return $clean_skill;
  827. }
  828. /**
  829. * @param int $user_id
  830. * @param int $skill_id
  831. * @param bool $return_flat_array
  832. * @param bool $add_root
  833. * @return array|null
  834. */
  835. public function get_skills_tree($user_id = null, $skill_id = null, $return_flat_array = false, $add_root = false)
  836. {
  837. if ($skill_id == 1) {
  838. $skill_id = 0;
  839. }
  840. if (isset($user_id) && !empty($user_id)) {
  841. $skills = $this->get_all(true, $user_id, null, $skill_id);
  842. } else {
  843. $skills = $this->get_all(false, false, null, $skill_id);
  844. }
  845. $original_skill = $this->list = $skills;
  846. // Show 1 item
  847. if (!empty($skill_id)) {
  848. if ($add_root) {
  849. if (!empty($skill_id)) {
  850. // Default root node
  851. $skills[1] = array(
  852. 'id' => '1',
  853. 'name' => get_lang('Root'),
  854. 'parent_id' => '0'
  855. );
  856. $skill_info = $this->get_skill_info($skill_id);
  857. // 2nd node
  858. $skills[$skill_id] = $skill_info;
  859. // Uncomment code below to hide the searched skill
  860. $skills[$skill_id]['data']['parent_id'] = $skill_info['extra']['parent_id'];
  861. $skills[$skill_id]['parent_id'] = 1;
  862. }
  863. }
  864. }
  865. $refs = array();
  866. $skills_tree = null;
  867. // Create references for all nodes
  868. $flat_array = array();
  869. $family = array();
  870. if (!empty($skills)) {
  871. foreach ($skills as &$skill) {
  872. if ($skill['parent_id'] == 0) {
  873. $skill['parent_id'] = 'root';
  874. }
  875. // because except main keys (id, name, children) others keys
  876. // are not saved while in the space tree
  877. $skill['data'] = array('parent_id' => $skill['parent_id']);
  878. // If a short code was defined, send the short code to replace
  879. // skill name (to shorten the text in the wheel)
  880. if (
  881. !empty($skill['short_code']) &&
  882. api_get_setting('show_full_skill_name_on_skill_wheel') === 'false'
  883. ) {
  884. $skill['data']['short_code'] = $skill['short_code'];
  885. }
  886. $skill['data']['name'] = $skill['name'];
  887. // In order to paint all members of a family with the same color
  888. if (empty($skill_id)) {
  889. if ($skill['parent_id'] == 1) {
  890. $family[$skill['id']] = $this->get_all_children($skill['id']);
  891. }
  892. } else {
  893. if ($skill['parent_id'] == $skill_id) {
  894. $family[$skill['id']] = $this->get_all_children($skill['id']);
  895. }
  896. /*if ($skill_id == $skill['id']) {
  897. $skill['parent_id'] = 1;
  898. }*/
  899. }
  900. if (!isset($skill['data']['real_parent_id'])) {
  901. $skill['data']['real_parent_id'] = $skill['parent_id'];
  902. }
  903. // User achieved the skill (depends in the gradebook with certification)
  904. $skill['data']['achieved'] = false;
  905. if ($user_id) {
  906. $skill['data']['achieved'] = $this->user_has_skill($user_id, $skill['id']);
  907. }
  908. // Check if the skill has related gradebooks
  909. $skill['data']['skill_has_gradebook'] = false;
  910. if (isset($skill['gradebooks']) && !empty($skill['gradebooks'])) {
  911. $skill['data']['skill_has_gradebook'] = true;
  912. }
  913. $refs[$skill['id']] = &$skill;
  914. $flat_array[$skill['id']] = &$skill;
  915. }
  916. // Checking family value
  917. $family_id = 1;
  918. $new_family_array = array();
  919. foreach ($family as $main_family_id => $family_items) {
  920. if (!empty($family_items)) {
  921. foreach ($family_items as $item) {
  922. $new_family_array[$item['skill_id']] = $family_id;
  923. }
  924. }
  925. $new_family_array[$main_family_id] = $family_id;
  926. $family_id++;
  927. }
  928. if (empty($original_skill)) {
  929. $refs['root']['children'][0] = $skills[1];
  930. $skills[$skill_id]['data']['family_id'] = 1;
  931. $refs['root']['children'][0]['children'][0] = $skills[$skill_id];
  932. $flat_array[$skill_id] = $skills[$skill_id];
  933. } else {
  934. // Moving node to the children index of their parents
  935. foreach ($skills as $my_skill_id => &$skill) {
  936. if (isset($new_family_array[$skill['id']])) {
  937. $skill['data']['family_id'] = $new_family_array[$skill['id']];
  938. }
  939. $refs[$skill['parent_id']]['children'][] = &$skill;
  940. $flat_array[$my_skill_id] = $skill;
  941. }
  942. }
  943. $skills_tree = array(
  944. 'name' => get_lang('SkillRootName'),
  945. 'id' => 'root',
  946. 'children' => $refs['root']['children'],
  947. 'data' => array()
  948. );
  949. }
  950. if ($return_flat_array) {
  951. return $flat_array;
  952. }
  953. unset($skills);
  954. return $skills_tree;
  955. }
  956. /**
  957. * Get skills tree as a simplified JSON structure
  958. * @param int user id
  959. * @param int skill id
  960. * @param bool return a flat array or not
  961. * @param int depth of the skills
  962. *
  963. */
  964. public function get_skills_tree_json($user_id = null, $skill_id = null, $return_flat_array = false, $main_depth = 2)
  965. {
  966. $tree = $this->get_skills_tree($user_id, $skill_id, $return_flat_array, true);
  967. $simple_tree = array();
  968. if (!empty($tree['children'])) {
  969. foreach ($tree['children'] as $element) {
  970. $simple_tree[] = array(
  971. 'name' => $element['name'],
  972. 'children' => $this->get_skill_json($element['children'], 1, $main_depth)
  973. );
  974. }
  975. }
  976. return json_encode($simple_tree[0]['children']);
  977. }
  978. /**
  979. * Get JSON element
  980. * @param array $subtree
  981. * @param int $depth
  982. * @param int $max_depth
  983. * @return array|null
  984. */
  985. public function get_skill_json($subtree, $depth = 1, $max_depth = 2)
  986. {
  987. $simple_sub_tree = array();
  988. if (is_array($subtree)) {
  989. $counter = 1;
  990. foreach ($subtree as $elem) {
  991. $tmp = array();
  992. $tmp['name'] = $elem['name'];
  993. $tmp['id'] = $elem['id'];
  994. $tmp['isSearched'] = self::isSearched($elem['id']);
  995. if (isset($elem['children']) && is_array($elem['children'])) {
  996. $tmp['children'] = $this->get_skill_json($elem['children'], $depth + 1, $max_depth);
  997. } else {
  998. //$tmp['colour'] = $this->colours[$depth][rand(0,3)];
  999. }
  1000. if ($depth > $max_depth) {
  1001. continue;
  1002. }
  1003. $tmp['depth'] = $depth;
  1004. $tmp['counter'] = $counter;
  1005. $counter++;
  1006. if (isset($elem['data']) && is_array($elem['data'])) {
  1007. foreach ($elem['data'] as $key => $item) {
  1008. $tmp[$key] = $item;
  1009. }
  1010. }
  1011. $simple_sub_tree[] = $tmp;
  1012. }
  1013. return $simple_sub_tree;
  1014. }
  1015. return null;
  1016. }
  1017. /**
  1018. * @param int $user_id
  1019. * @return bool
  1020. */
  1021. public function get_user_skill_ranking($user_id)
  1022. {
  1023. $user_id = intval($user_id);
  1024. $sql = "SELECT count(skill_id) count FROM {$this->table} s
  1025. INNER JOIN {$this->table_skill_rel_user} su
  1026. ON (s.id = su.skill_id)
  1027. WHERE user_id = $user_id";
  1028. $result = Database::query($sql);
  1029. if (Database::num_rows($result)) {
  1030. $result = Database::fetch_row($result);
  1031. return $result[0];
  1032. }
  1033. return false;
  1034. }
  1035. /**
  1036. * @param $start
  1037. * @param $limit
  1038. * @param $sidx
  1039. * @param $sord
  1040. * @param $where_condition
  1041. * @return array
  1042. */
  1043. public function get_user_list_skill_ranking($start, $limit, $sidx, $sord, $where_condition)
  1044. {
  1045. $start = intval($start);
  1046. $limit = intval($limit);
  1047. /* ORDER BY $sidx $sord */
  1048. $sql = "SELECT *, @rownum:=@rownum+1 rank FROM (
  1049. SELECT u.user_id, firstname, lastname, count(username) skills_acquired
  1050. FROM {$this->table} s INNER JOIN {$this->table_skill_rel_user} su ON (s.id = su.skill_id)
  1051. INNER JOIN {$this->table_user} u ON u.user_id = su.user_id, (SELECT @rownum:=0) r
  1052. WHERE 1=1 $where_condition
  1053. GROUP BY username
  1054. ORDER BY skills_acquired desc
  1055. LIMIT $start , $limit) AS T1, (SELECT @rownum:=0) r";
  1056. $result = Database::query($sql);
  1057. if (Database::num_rows($result)) {
  1058. return Database::store_result($result, 'ASSOC');
  1059. }
  1060. return array();
  1061. }
  1062. /**
  1063. * @return int
  1064. */
  1065. public function get_user_list_skill_ranking_count()
  1066. {
  1067. $sql = "SELECT count(*) FROM (
  1068. SELECT count(distinct 1)
  1069. FROM {$this->table} s
  1070. INNER JOIN {$this->table_skill_rel_user} su
  1071. ON (s.id = su.skill_id)
  1072. INNER JOIN {$this->table_user} u
  1073. ON u.user_id = su.user_id
  1074. GROUP BY username
  1075. ) as T1";
  1076. $result = Database::query($sql);
  1077. if (Database::num_rows($result)) {
  1078. $result = Database::fetch_row($result);
  1079. return $result[0];
  1080. }
  1081. return 0;
  1082. }
  1083. /**
  1084. * @param string $course_code
  1085. * @return int
  1086. */
  1087. public function get_count_skills_by_course($course_code)
  1088. {
  1089. $sql = "SELECT count(skill_id) as count
  1090. FROM {$this->table_gradebook} g
  1091. INNER JOIN {$this->table_skill_rel_gradebook} sg
  1092. ON g.id = sg.gradebook_id
  1093. WHERE course_code = '$course_code'";
  1094. $result = Database::query($sql);
  1095. if (Database::num_rows($result)) {
  1096. $result = Database::fetch_row($result);
  1097. return $result[0];
  1098. }
  1099. return 0;
  1100. }
  1101. /**
  1102. * @param int $skill_id
  1103. * @return array
  1104. */
  1105. public function get_courses_by_skill($skill_id)
  1106. {
  1107. $skill_id = intval($skill_id);
  1108. $sql = "SELECT c.title, c.code
  1109. FROM {$this->table_gradebook} g
  1110. INNER JOIN {$this->table_skill_rel_gradebook} sg
  1111. ON g.id = sg.gradebook_id
  1112. INNER JOIN {$this->table_course} c
  1113. ON c.code = g.course_code
  1114. WHERE sg.skill_id = $skill_id
  1115. AND (g.session_id IS NULL OR g.session_id = 0)";
  1116. $result = Database::query($sql);
  1117. return Database::store_result($result, 'ASSOC');
  1118. }
  1119. /**
  1120. * Check if the user has the skill
  1121. * @param int $userId The user id
  1122. * @param int $skillId The skill id
  1123. * @param int $courseId Optional. The course id
  1124. * @param int $sessionId Optional. The session id
  1125. * @return boolean Whether the user has the skill return true. Otherwise return false
  1126. */
  1127. public function user_has_skill($userId, $skillId, $courseId = 0, $sessionId = 0)
  1128. {
  1129. $courseId = intval($courseId);
  1130. $sessionId = intval($sessionId);
  1131. $whereConditions = array(
  1132. 'user_id = ? ' => intval($userId),
  1133. 'AND skill_id = ? ' => intval($skillId)
  1134. );
  1135. if ($courseId > 0) {
  1136. $whereConditions['AND course_id = ? '] = $courseId;
  1137. $whereConditions['AND session_id = ? '] = $sessionId;
  1138. }
  1139. $result = Database::select(
  1140. 'COUNT(1) AS qty',
  1141. $this->table_skill_rel_user, array(
  1142. 'where' => $whereConditions
  1143. ),
  1144. 'first'
  1145. );
  1146. if ($result != false) {
  1147. if ($result['qty'] > 0) {
  1148. return true;
  1149. }
  1150. }
  1151. return false;
  1152. }
  1153. /**
  1154. * Check if a skill is searched
  1155. * @param int $id The skill id
  1156. * @return boolean Whether el skill is searched return true. Otherwise return false
  1157. */
  1158. public static function isSearched($id)
  1159. {
  1160. $id = intval($id);
  1161. if (empty($id)) {
  1162. return false;
  1163. }
  1164. $skillRelProfileTable = Database::get_main_table(TABLE_MAIN_SKILL_REL_PROFILE);
  1165. $result = Database::select(
  1166. 'COUNT( DISTINCT `skill_id`) AS qty',
  1167. $skillRelProfileTable,
  1168. array(
  1169. 'where' => array(
  1170. 'skill_id = ?' => $id
  1171. )
  1172. ),
  1173. 'first'
  1174. );
  1175. if ($result === false) {
  1176. return false;
  1177. }
  1178. if ($result['qty'] > 0) {
  1179. return true;
  1180. }
  1181. return false;
  1182. }
  1183. /**
  1184. * Get the achieved skills by course
  1185. * @param int $courseId The course id
  1186. * @return array The skills list
  1187. */
  1188. public function listAchievedByCourse($courseId)
  1189. {
  1190. $courseId = intval($courseId);
  1191. if ($courseId == 0) {
  1192. return array();
  1193. }
  1194. $list = array();
  1195. $sql = "SELECT
  1196. course.id c_id,
  1197. course.title c_name,
  1198. course.directory c_directory,
  1199. user.user_id,
  1200. user.lastname,
  1201. user.firstname,
  1202. user.username,
  1203. skill.id skill_id,
  1204. skill.name skill_name,
  1205. sru.acquired_skill_at
  1206. FROM {$this->table_skill_rel_user} AS sru
  1207. INNER JOIN {$this->table_course}
  1208. ON sru.course_id = course.id
  1209. INNER JOIN {$this->table_user}
  1210. ON sru.user_id = user.user_id
  1211. INNER JOIN {$this->table}
  1212. ON sru.skill_id = skill.id
  1213. WHERE course.id = $courseId";
  1214. $result = Database::query($sql);
  1215. while ($row = Database::fetch_assoc($result)) {
  1216. $list[] = $row;
  1217. }
  1218. return $list;
  1219. }
  1220. /**
  1221. * Get the users list who achieved a skill
  1222. * @param int $skillId The skill id
  1223. *
  1224. * @return array The users list
  1225. */
  1226. public function listUsersWhoAchieved($skillId)
  1227. {
  1228. $skillId = intval($skillId);
  1229. if ($skillId == 0) {
  1230. return array();
  1231. }
  1232. $list = array();
  1233. $sql = "SELECT
  1234. course.id c_id,
  1235. course.title c_name,
  1236. course.directory c_directory,
  1237. user.user_id,
  1238. user.lastname,
  1239. user.firstname,
  1240. user.username,
  1241. skill.id skill_id,
  1242. skill.name skill_name,
  1243. sru.acquired_skill_at
  1244. FROM {$this->table_skill_rel_user} AS sru
  1245. INNER JOIN {$this->table_course}
  1246. ON sru.course_id = course.id
  1247. INNER JOIN {$this->table_user}
  1248. ON sru.user_id = user.user_id
  1249. INNER JOIN {$this->table}
  1250. ON sru.skill_id = skill.id
  1251. WHERE skill.id = $skillId ";
  1252. $result = Database::query($sql);
  1253. while ($row = Database::fetch_assoc($result)) {
  1254. $list[] = $row;
  1255. }
  1256. return $list;
  1257. }
  1258. /**
  1259. * Get the session list where the user can achieve a skill
  1260. * @param int $skillId The skill id
  1261. * @return array
  1262. */
  1263. public function getSessionsBySkill($skillId)
  1264. {
  1265. $skillId = intval($skillId);
  1266. $sql = "SELECT s.id, s.name
  1267. FROM {$this->table_gradebook} g
  1268. INNER JOIN {$this->table_skill_rel_gradebook} sg ON g.id = sg.gradebook_id
  1269. INNER JOIN {$this->sessionTable} s ON g.session_id = s.id
  1270. WHERE sg.skill_id = $skillId
  1271. AND g.session_id > 0";
  1272. $result = Database::query($sql);
  1273. return Database::store_result($result, 'ASSOC');
  1274. }
  1275. }