course_home.lib.php 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CourseBundle\Entity\CLpCategory;
  4. use Chamilo\CourseBundle\Entity\CTool;
  5. /**
  6. * Class CourseHome.
  7. */
  8. class CourseHome
  9. {
  10. /**
  11. * Gets the tools of a certain category. Returns an array expected
  12. * by show_tools_category().
  13. *
  14. * @param string $course_tool_category contains the category of tools to
  15. * display: "toolauthoring", "toolinteraction", "tooladmin", "tooladminplatform", "toolplugin"
  16. * @param int $courseId Optional
  17. * @param int $sessionId Optional
  18. *
  19. * @return array
  20. */
  21. public static function get_tools_category(
  22. $course_tool_category,
  23. $courseId = 0,
  24. $sessionId = 0
  25. ) {
  26. $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST);
  27. $is_platform_admin = api_is_platform_admin();
  28. $all_tools_list = [];
  29. // Condition for the session
  30. $sessionId = $sessionId ?: api_get_session_id();
  31. $course_id = $courseId ?: api_get_course_int_id();
  32. $courseInfo = api_get_course_info_by_id($course_id);
  33. $userId = api_get_user_id();
  34. $user = api_get_user_entity($userId);
  35. $condition_session = api_get_session_condition(
  36. $sessionId,
  37. true,
  38. true,
  39. 't.session_id'
  40. );
  41. $lpTable = Database::get_course_table(TABLE_LP_MAIN);
  42. $tblLpCategory = Database::get_course_table(TABLE_LP_CATEGORY);
  43. $studentView = api_is_student_view_active();
  44. $orderBy = ' ORDER BY id ';
  45. switch ($course_tool_category) {
  46. case TOOL_STUDENT_VIEW:
  47. $conditions = ' WHERE visibility = 1 AND
  48. (category = "authoring" OR category = "interaction" OR category = "plugin") AND
  49. t.name <> "notebookteacher" ';
  50. if ((api_is_coach() || api_is_course_tutor() || api_is_platform_admin()) && !$studentView) {
  51. $conditions = ' WHERE (
  52. visibility = 1 AND (
  53. category = "authoring" OR
  54. category = "interaction" OR
  55. category = "plugin"
  56. ) OR (t.name = "'.TOOL_TRACKING.'")
  57. )';
  58. }
  59. // Add order if there are LPs
  60. $sql = "SELECT t.* FROM $course_tool_table t
  61. LEFT JOIN $lpTable l
  62. ON (t.c_id = l.c_id AND link LIKE concat('%/lp_controller.php?action=view&lp_id=', l.id, '&%'))
  63. LEFT JOIN $tblLpCategory lc
  64. ON (t.c_id = lc.c_id AND l.category_id = lc.iid)
  65. $conditions AND
  66. t.c_id = $course_id $condition_session
  67. ORDER BY
  68. CASE WHEN l.category_id IS NULL THEN 0 ELSE 1 END,
  69. CASE WHEN l.display_order IS NULL THEN 0 ELSE 1 END,
  70. lc.position,
  71. l.display_order,
  72. t.id";
  73. $orderBy = '';
  74. break;
  75. case TOOL_AUTHORING:
  76. $sql = "SELECT t.* FROM $course_tool_table t
  77. LEFT JOIN $lpTable l
  78. ON (t.c_id = l.c_id AND link LIKE concat('%/lp_controller.php?action=view&lp_id=', l.id, '&%'))
  79. LEFT JOIN $tblLpCategory lc
  80. ON (t.c_id = lc.c_id AND l.category_id = lc.iid)
  81. WHERE
  82. category = 'authoring' AND t.c_id = $course_id $condition_session
  83. ORDER BY
  84. CASE WHEN l.category_id IS NULL THEN 0 ELSE 1 END,
  85. CASE WHEN l.display_order IS NULL THEN 0 ELSE 1 END,
  86. lc.position,
  87. l.display_order,
  88. t.id";
  89. $orderBy = '';
  90. break;
  91. case TOOL_INTERACTION:
  92. $sql = "SELECT * FROM $course_tool_table t
  93. WHERE category = 'interaction' AND c_id = $course_id $condition_session
  94. ";
  95. break;
  96. case TOOL_ADMIN_VISIBLE:
  97. $sql = "SELECT * FROM $course_tool_table t
  98. WHERE category = 'admin' AND visibility ='1' AND c_id = $course_id $condition_session
  99. ";
  100. break;
  101. case TOOL_ADMIN_PLATFORM:
  102. $sql = "SELECT * FROM $course_tool_table t
  103. WHERE category = 'admin' AND c_id = $course_id $condition_session
  104. ";
  105. break;
  106. case TOOL_DRH:
  107. $sql = "SELECT * FROM $course_tool_table t
  108. WHERE t.name IN ('tracking') AND c_id = $course_id $condition_session
  109. ";
  110. break;
  111. case TOOL_COURSE_PLUGIN:
  112. //Other queries recover id, name, link, image, visibility, admin, address, added_tool, target, category and session_id
  113. // but plugins are not present in the tool table, only globally and inside the course_settings table once configured
  114. $sql = "SELECT * FROM $course_tool_table t
  115. WHERE category = 'plugin' AND name <> 'courseblock' AND c_id = $course_id $condition_session
  116. ";
  117. break;
  118. }
  119. $sql .= $orderBy;
  120. $result = Database::query($sql);
  121. $tools = [];
  122. while ($row = Database::fetch_assoc($result)) {
  123. $tools[] = $row;
  124. }
  125. // Get the list of hidden tools - this might imply performance slowdowns
  126. // if the course homepage is loaded many times, so the list of hidden
  127. // tools might benefit from a shared memory storage later on
  128. $list = api_get_settings('Tools', 'list', api_get_current_access_url_id());
  129. $hide_list = [];
  130. $check = false;
  131. foreach ($list as $line) {
  132. // Admin can see all tools even if the course_hide_tools configuration is set
  133. if ($is_platform_admin) {
  134. continue;
  135. }
  136. if ($line['variable'] == 'course_hide_tools' && $line['selected_value'] == 'true') {
  137. $hide_list[] = $line['subkey'];
  138. $check = true;
  139. }
  140. }
  141. $allowEditionInSession = api_get_configuration_value('allow_edit_tool_visibility_in_session');
  142. // If exists same tool (by name) from session in base course then avoid it. Allow them pass in other cases
  143. $tools = array_filter($tools, function (array $toolToFilter) use ($sessionId, $tools) {
  144. if (!empty($toolToFilter['session_id'])) {
  145. foreach ($tools as $originalTool) {
  146. if ($toolToFilter['name'] == $originalTool['name'] && empty($originalTool['session_id'])) {
  147. return false;
  148. }
  149. }
  150. }
  151. return true;
  152. });
  153. foreach ($tools as $temp_row) {
  154. $add = false;
  155. if ($check) {
  156. if (!in_array($temp_row['name'], $hide_list)) {
  157. $add = true;
  158. }
  159. } else {
  160. $add = true;
  161. }
  162. if ($allowEditionInSession && !empty($sessionId)) {
  163. // Checking if exist row in session
  164. $criteria = [
  165. 'course' => $course_id,
  166. 'name' => $temp_row['name'],
  167. 'sessionId' => $sessionId,
  168. ];
  169. /** @var CTool $toolObj */
  170. $toolObj = Database::getManager()->getRepository('ChamiloCourseBundle:CTool')->findOneBy($criteria);
  171. if ($toolObj) {
  172. if (api_is_allowed_to_edit() == false && $toolObj->getVisibility() == false) {
  173. continue;
  174. }
  175. }
  176. }
  177. switch ($temp_row['image']) {
  178. case 'scormbuilder.gif':
  179. $lpId = self::getPublishedLpIdFromLink($temp_row['link']);
  180. $lp = new learnpath(
  181. api_get_course_id(),
  182. $lpId,
  183. $userId
  184. );
  185. $path = $lp->get_preview_image_path(ICON_SIZE_BIG);
  186. if (api_is_allowed_to_edit(null, true)) {
  187. $add = true;
  188. } else {
  189. $add = learnpath::is_lp_visible_for_student(
  190. $lpId,
  191. $userId,
  192. $courseInfo,
  193. $sessionId
  194. );
  195. }
  196. if ($path) {
  197. $temp_row['custom_image'] = $path;
  198. }
  199. break;
  200. case 'lp_category.gif':
  201. $lpCategory = self::getPublishedLpCategoryFromLink(
  202. $temp_row['link']
  203. );
  204. $add = learnpath::categoryIsVisibleForStudent(
  205. $lpCategory,
  206. $user
  207. );
  208. break;
  209. }
  210. if ($add) {
  211. $all_tools_list[] = $temp_row;
  212. }
  213. }
  214. // Grabbing all the links that have the property on_homepage set to 1
  215. $course_link_table = Database::get_course_table(TABLE_LINK);
  216. $course_item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
  217. $condition_session = api_get_session_condition(
  218. $sessionId,
  219. true,
  220. true,
  221. 'tip.session_id'
  222. );
  223. switch ($course_tool_category) {
  224. case TOOL_AUTHORING:
  225. $sql_links = "SELECT tl.*, tip.visibility
  226. FROM $course_link_table tl
  227. LEFT JOIN $course_item_property_table tip
  228. ON tip.tool='link' AND tip.ref=tl.id
  229. WHERE
  230. tl.c_id = $course_id AND
  231. tip.c_id = $course_id AND
  232. tl.on_homepage='1' $condition_session";
  233. break;
  234. case TOOL_INTERACTION:
  235. $sql_links = null;
  236. /*
  237. $sql_links = "SELECT tl.*, tip.visibility
  238. FROM $course_link_table tl
  239. LEFT JOIN $course_item_property_table tip ON tip.tool='link' AND tip.ref=tl.id
  240. WHERE tl.on_homepage='1' ";
  241. */
  242. break;
  243. case TOOL_STUDENT_VIEW:
  244. $sql_links = "SELECT tl.*, tip.visibility
  245. FROM $course_link_table tl
  246. LEFT JOIN $course_item_property_table tip
  247. ON tip.tool='link' AND tip.ref=tl.id
  248. WHERE
  249. tl.c_id = $course_id AND
  250. tip.c_id = $course_id AND
  251. tl.on_homepage ='1' $condition_session";
  252. break;
  253. case TOOL_ADMIN:
  254. $sql_links = "SELECT tl.*, tip.visibility
  255. FROM $course_link_table tl
  256. LEFT JOIN $course_item_property_table tip
  257. ON tip.tool='link' AND tip.ref=tl.id
  258. WHERE
  259. tl.c_id = $course_id AND
  260. tip.c_id = $course_id AND
  261. tl.on_homepage='1' $condition_session";
  262. break;
  263. default:
  264. $sql_links = null;
  265. break;
  266. }
  267. // Edited by Kevin Van Den Haute (kevin@develop-it.be) for integrating Smartblogs
  268. if ($sql_links != null) {
  269. $result_links = Database::query($sql_links);
  270. if (Database::num_rows($result_links) > 0) {
  271. while ($links_row = Database::fetch_array($result_links, 'ASSOC')) {
  272. $properties = [];
  273. $properties['name'] = $links_row['title'];
  274. $properties['session_id'] = $links_row['session_id'];
  275. $properties['link'] = $links_row['url'];
  276. $properties['visibility'] = $links_row['visibility'];
  277. $properties['image'] = $links_row['visibility'] == '0' ? 'file_html.png' : 'file_html.png';
  278. $properties['adminlink'] = api_get_path(WEB_CODE_PATH).'link/link.php?action=editlink&id='.$links_row['id'];
  279. $properties['target'] = $links_row['target'];
  280. $tmp_all_tools_list[] = $properties;
  281. }
  282. }
  283. }
  284. if (isset($tmp_all_tools_list)) {
  285. $tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
  286. foreach ($tmp_all_tools_list as $tool) {
  287. if ($tool['image'] == 'blog.gif') {
  288. // Get blog id
  289. $blog_id = substr($tool['link'], strrpos($tool['link'], '=') + 1, strlen($tool['link']));
  290. // Get blog members
  291. if ($is_platform_admin) {
  292. $sql = "SELECT * FROM $tbl_blogs_rel_user blogs_rel_user
  293. WHERE blog_id = ".$blog_id;
  294. } else {
  295. $sql = "SELECT * FROM $tbl_blogs_rel_user blogs_rel_user
  296. WHERE blog_id = ".$blog_id." AND user_id = ".$userId;
  297. }
  298. $result = Database::query($sql);
  299. if (Database::num_rows($result) > 0) {
  300. $all_tools_list[] = $tool;
  301. }
  302. } else {
  303. $all_tools_list[] = $tool;
  304. }
  305. }
  306. }
  307. $list = self::filterPluginTools($all_tools_list, $course_tool_category);
  308. return $list;
  309. }
  310. /**
  311. * Displays the tools of a certain category.
  312. *
  313. * @param array $all_tools_list List of tools as returned by get_tools_category()
  314. *
  315. * @return array
  316. */
  317. public static function show_tools_category($all_tools_list)
  318. {
  319. $_user = api_get_user_info();
  320. $theme = api_get_setting('homepage_view');
  321. if ($theme === 'vertical_activity') {
  322. //ordering by get_lang name
  323. $order_tool_list = [];
  324. if (is_array($all_tools_list) && count($all_tools_list) > 0) {
  325. foreach ($all_tools_list as $key => $new_tool) {
  326. $tool_name = self::translate_tool_name($new_tool);
  327. $order_tool_list[$key] = $tool_name;
  328. }
  329. natsort($order_tool_list);
  330. $my_temp_tool_array = [];
  331. foreach ($order_tool_list as $key => $new_tool) {
  332. $my_temp_tool_array[] = $all_tools_list[$key];
  333. }
  334. $all_tools_list = $my_temp_tool_array;
  335. } else {
  336. $all_tools_list = [];
  337. }
  338. }
  339. $web_code_path = api_get_path(WEB_CODE_PATH);
  340. $session_id = api_get_session_id();
  341. $is_platform_admin = api_is_platform_admin();
  342. $allowEditionInSession = api_get_configuration_value('allow_edit_tool_visibility_in_session');
  343. if ($session_id == 0) {
  344. $is_allowed_to_edit = api_is_allowed_to_edit(null, true) && api_is_course_admin();
  345. } else {
  346. $is_allowed_to_edit = api_is_allowed_to_edit(null, true) && !api_is_coach();
  347. if ($allowEditionInSession) {
  348. $is_allowed_to_edit = api_is_allowed_to_edit(null, true) && api_is_coach($session_id, api_get_course_int_id());
  349. }
  350. }
  351. $items = [];
  352. $app_plugin = new AppPlugin();
  353. if (isset($all_tools_list)) {
  354. $lnk = '';
  355. foreach ($all_tools_list as &$tool) {
  356. $item = [];
  357. $studentview = false;
  358. $tool['original_link'] = $tool['link'];
  359. if ($tool['image'] === 'scormbuilder.gif') {
  360. // Check if the published learnpath is visible for student
  361. $lpId = self::getPublishedLpIdFromLink($tool['link']);
  362. if (api_is_allowed_to_edit(null, true)) {
  363. $studentview = true;
  364. }
  365. if (!api_is_allowed_to_edit(null, true) &&
  366. !learnpath::is_lp_visible_for_student(
  367. $lpId,
  368. api_get_user_id(),
  369. api_get_course_info(),
  370. api_get_session_id()
  371. )
  372. ) {
  373. continue;
  374. }
  375. }
  376. if ($session_id != 0 && in_array($tool['name'], ['course_setting'])) {
  377. continue;
  378. }
  379. // This part displays the links to hide or remove a tool.
  380. // These links are only visible by the course manager.
  381. unset($lnk);
  382. $item['extra'] = null;
  383. $toolAdmin = isset($tool['admin']) ? $tool['admin'] : '';
  384. if ($is_allowed_to_edit) {
  385. if (empty($session_id)) {
  386. if (isset($tool['id'])) {
  387. if ($tool['visibility'] == '1' && $toolAdmin != '1') {
  388. $link['name'] = Display::return_icon(
  389. 'visible.png',
  390. get_lang('Deactivate'),
  391. ['id' => 'linktool_'.$tool['iid']],
  392. ICON_SIZE_SMALL,
  393. false
  394. );
  395. $link['cmd'] = 'hide=yes';
  396. $lnk[] = $link;
  397. }
  398. if ($tool['visibility'] == '0' && $toolAdmin != '1') {
  399. $link['name'] = Display::return_icon(
  400. 'invisible.png',
  401. get_lang('Activate'),
  402. ['id' => 'linktool_'.$tool['iid']],
  403. ICON_SIZE_SMALL,
  404. false
  405. );
  406. $link['cmd'] = 'restore=yes';
  407. $lnk[] = $link;
  408. }
  409. }
  410. } elseif ($allowEditionInSession) {
  411. $criteria = [
  412. 'course' => api_get_course_int_id(),
  413. 'name' => $tool['name'],
  414. 'sessionId' => $session_id,
  415. ];
  416. /** @var CTool $tool */
  417. $toolObj = Database::getManager()->getRepository('ChamiloCourseBundle:CTool')->findOneBy($criteria);
  418. if ($toolObj) {
  419. $visibility = (int) $toolObj->getVisibility();
  420. switch ($visibility) {
  421. case '0':
  422. $info = pathinfo($tool['image']);
  423. $basename = basename($tool['image'], '.'.$info['extension']);
  424. $tool['image'] = $basename.'_na.'.$info['extension'];
  425. $link['name'] = Display::return_icon(
  426. 'invisible.png',
  427. get_lang('Activate'),
  428. ['id' => 'linktool_'.$tool['iid']],
  429. ICON_SIZE_SMALL,
  430. false
  431. );
  432. $link['cmd'] = 'restore=yes';
  433. $lnk[] = $link;
  434. break;
  435. case '1':
  436. $link['name'] = Display::return_icon(
  437. 'visible.png',
  438. get_lang('Deactivate'),
  439. ['id' => 'linktool_'.$tool['iid']],
  440. ICON_SIZE_SMALL,
  441. false
  442. );
  443. $link['cmd'] = 'hide=yes';
  444. $lnk[] = $link;
  445. break;
  446. }
  447. } else {
  448. $link['name'] = Display::return_icon(
  449. 'visible.png',
  450. get_lang('Deactivate'),
  451. ['id' => 'linktool_'.$tool['iid']],
  452. ICON_SIZE_SMALL,
  453. false
  454. );
  455. $link['cmd'] = 'hide=yes';
  456. $lnk[] = $link;
  457. }
  458. }
  459. if (!empty($tool['adminlink'])) {
  460. $item['extra'] = '<a href="'.$tool['adminlink'].'">'.
  461. Display::return_icon('edit.gif', get_lang('Edit')).
  462. '</a>';
  463. }
  464. }
  465. // Both checks are necessary as is_platform_admin doesn't take student view into account
  466. if ($is_platform_admin && $is_allowed_to_edit) {
  467. if ($toolAdmin != '1') {
  468. $link['cmd'] = 'hide=yes';
  469. }
  470. }
  471. $item['visibility'] = '';
  472. if (isset($lnk) && is_array($lnk)) {
  473. foreach ($lnk as $this_link) {
  474. if (empty($tool['adminlink'])) {
  475. $item['visibility'] .=
  476. '<a class="make_visible_and_invisible" href="'.api_get_self().'?'.api_get_cidreq().'&id='.$tool['iid'].'&'.$this_link['cmd'].'">'.
  477. $this_link['name'].'</a>';
  478. }
  479. }
  480. }
  481. // NOTE : Table contains only the image file name, not full path
  482. if (stripos($tool['link'], 'http://') === false &&
  483. stripos($tool['link'], 'https://') === false &&
  484. stripos($tool['link'], 'ftp://') === false
  485. ) {
  486. $tool['link'] = $web_code_path.$tool['link'];
  487. }
  488. $class = '';
  489. if ($tool['visibility'] == '0' && $toolAdmin != '1') {
  490. $class = 'text-muted';
  491. $info = pathinfo($tool['image']);
  492. $basename = basename($tool['image'], '.'.$info['extension']);
  493. $tool['image'] = $basename.'_na.'.$info['extension'];
  494. }
  495. $qm_or_amp = strpos($tool['link'], '?') === false ? '?' : '&';
  496. // If it's a link, we don't add the cidReq
  497. if ($tool['image'] === 'file_html.png' || $tool['image'] === 'file_html_na.png') {
  498. $tool['link'] = $tool['link'];
  499. } else {
  500. $tool['link'] = $tool['link'].$qm_or_amp.api_get_cidreq();
  501. }
  502. $toolIid = isset($tool['iid']) ? $tool['iid'] : null;
  503. //@todo this visio stuff should be removed
  504. if (strpos($tool['name'], 'visio_') !== false) {
  505. $tool_link_params = [
  506. 'id' => 'tooldesc_'.$toolIid,
  507. 'href' => '"javascript: void(0);"',
  508. 'class' => $class,
  509. 'onclick' => 'javascript: window.open(\''.$tool['link'].'\',\'window_visio'.api_get_course_id().'\',config=\'height=\'+730+\', width=\'+1020+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')',
  510. 'target' => $tool['target'],
  511. ];
  512. } elseif (strpos($tool['name'], 'chat') !== false &&
  513. api_get_course_setting('allow_open_chat_window')
  514. ) {
  515. $tool_link_params = [
  516. 'id' => 'tooldesc_'.$toolIid,
  517. 'class' => $class,
  518. 'href' => 'javascript: void(0);',
  519. 'onclick' => 'javascript: window.open(\''.$tool['link'].'\',\'window_chat'.api_get_course_id().'\',config=\'height=\'+600+\', width=\'+825+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')', //Chat Open Windows
  520. 'target' => $tool['target'],
  521. ];
  522. } else {
  523. $tool_link_params = [
  524. 'id' => 'tooldesc_'.$toolIid,
  525. 'href' => $tool['link'],
  526. 'class' => $class,
  527. 'target' => $tool['target'],
  528. ];
  529. }
  530. $tool_name = self::translate_tool_name($tool);
  531. // Including Courses Plugins
  532. // Creating title and the link
  533. if (isset($tool['category']) && $tool['category'] == 'plugin') {
  534. $plugin_info = $app_plugin->getPluginInfo($tool['name']);
  535. if (isset($plugin_info) && isset($plugin_info['title'])) {
  536. $tool_name = $plugin_info['title'];
  537. }
  538. if (!file_exists(api_get_path(SYS_CODE_PATH).'img/'.$tool['image']) &&
  539. !file_exists(api_get_path(SYS_CODE_PATH).'img/icons/64/'.$tool['image'])) {
  540. $tool['image'] = 'plugins.png';
  541. }
  542. $tool_link_params['href'] = api_get_path(WEB_PLUGIN_PATH)
  543. .$tool['original_link'].$qm_or_amp.api_get_cidreq();
  544. }
  545. // Use in the course home
  546. $icon = Display::return_icon(
  547. $tool['image'],
  548. $tool_name,
  549. ['class' => 'tool-icon', 'id' => 'toolimage_'.$toolIid],
  550. ICON_SIZE_BIG,
  551. false
  552. );
  553. // Used in the top bar
  554. $iconMedium = Display::return_icon(
  555. $tool['image'],
  556. $tool_name,
  557. ['class' => 'tool-icon', 'id' => 'toolimage_'.$toolIid],
  558. ICON_SIZE_MEDIUM,
  559. false
  560. );
  561. // Used for vertical navigation
  562. $iconSmall = Display::return_icon(
  563. $tool['image'],
  564. $tool_name,
  565. ['class' => 'tool-img', 'id' => 'toolimage_'.$toolIid],
  566. ICON_SIZE_SMALL,
  567. false
  568. );
  569. /*if (!empty($tool['custom_icon'])) {
  570. $image = self::getCustomWebIconPath().$tool['custom_icon'];
  571. $icon = Display::img(
  572. $image,
  573. $tool['description'],
  574. array(
  575. 'class' => 'tool-icon',
  576. 'id' => 'toolimage_'.$tool['id']
  577. )
  578. );
  579. }*/
  580. // Validation when belongs to a session
  581. $session_img = api_get_session_image(
  582. $tool['session_id'],
  583. !empty($_user['status']) ? $_user['status'] : ''
  584. );
  585. if ($studentview) {
  586. $tool_link_params['href'] .= '&isStudentView=true';
  587. }
  588. $item['url_params'] = $tool_link_params;
  589. $item['icon'] = Display::url($icon, $tool_link_params['href'], $tool_link_params);
  590. $item['only_icon'] = $icon;
  591. $item['only_icon_medium'] = $iconMedium;
  592. $item['only_icon_small'] = $iconSmall;
  593. $item['only_href'] = $tool_link_params['href'];
  594. $item['tool'] = $tool;
  595. $item['name'] = $tool_name;
  596. $tool_link_params['id'] = 'is'.$tool_link_params['id'];
  597. $item['link'] = Display::url(
  598. $tool_name.$session_img,
  599. $tool_link_params['href'],
  600. $tool_link_params
  601. );
  602. $items[] = $item;
  603. }
  604. }
  605. foreach ($items as &$item) {
  606. $originalImage = self::getToolIcon($item, ICON_SIZE_BIG);
  607. $item['tool']['only_icon_medium'] = self::getToolIcon($item, ICON_SIZE_MEDIUM, false);
  608. $item['tool']['only_icon_small'] = self::getToolIcon($item, ICON_SIZE_SMALL, false);
  609. if ($theme === 'activity_big') {
  610. $item['tool']['image'] = Display::url(
  611. $originalImage,
  612. $item['url_params']['href'],
  613. $item['url_params']
  614. );
  615. }
  616. }
  617. return $items;
  618. }
  619. /**
  620. * Shows the general data for a particular meeting.
  621. *
  622. * @param int $id_session
  623. *
  624. * @return string session data
  625. */
  626. public static function show_session_data($id_session)
  627. {
  628. $sessionInfo = api_get_session_info($id_session);
  629. if (empty($sessionInfo)) {
  630. return '';
  631. }
  632. $table = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
  633. $sql = 'SELECT name FROM '.$table.'
  634. WHERE id = "'.intval($sessionInfo['session_category_id']).'"';
  635. $rs_category = Database::query($sql);
  636. $session_category = '';
  637. if (Database::num_rows($rs_category) > 0) {
  638. $rows_session_category = Database::store_result($rs_category);
  639. $rows_session_category = $rows_session_category[0];
  640. $session_category = $rows_session_category['name'];
  641. }
  642. $coachInfo = api_get_user_info($sessionInfo['id_coach']);
  643. $output = '';
  644. if (!empty($session_category)) {
  645. $output .= '<tr><td>'.get_lang('Sessions categories').': '.'<b>'.$session_category.'</b></td></tr>';
  646. }
  647. $dateInfo = SessionManager::parseSessionDates($sessionInfo);
  648. $msgDate = $dateInfo['access'];
  649. $output .= '<tr>
  650. <td style="width:50%">'.get_lang('Session name').': '.'<b>'.$sessionInfo['name'].'</b></td>
  651. <td>'.get_lang('General coach').': '.'<b>'.$coachInfo['complete_name'].'</b></td></tr>';
  652. $output .= '<tr>
  653. <td>'.get_lang('Identifier of session').': '.
  654. Display::return_icon('star.png', ' ', ['align' => 'absmiddle']).'
  655. </td>
  656. <td>'.get_lang('Date').': '.'<b>'.$msgDate.'</b>
  657. </td>
  658. </tr>';
  659. return $output;
  660. }
  661. /**
  662. * Retrieves the name-field within a tool-record and translates it on necessity.
  663. *
  664. * @param array $tool the input record
  665. *
  666. * @return string returns the name of the corresponding tool
  667. */
  668. public static function translate_tool_name(&$tool)
  669. {
  670. static $already_translated_icons = [
  671. 'file_html.gif',
  672. 'file_html_na.gif',
  673. 'file_html.png',
  674. 'file_html_na.png',
  675. 'scormbuilder.gif',
  676. 'scormbuilder_na.gif',
  677. 'blog.gif',
  678. 'blog_na.gif',
  679. 'external.gif',
  680. 'external_na.gif',
  681. ];
  682. $toolName = Security::remove_XSS(stripslashes(strip_tags($tool['name'])));
  683. if (isset($tool['image']) && in_array($tool['image'], $already_translated_icons)) {
  684. return $toolName;
  685. }
  686. $toolName = api_underscore_to_camel_case($toolName);
  687. if (isset($tool['category']) && 'plugin' !== $tool['category'] &&
  688. isset($GLOBALS['Tool'.$toolName])
  689. ) {
  690. return get_lang('Tool'.$toolName);
  691. }
  692. return $toolName;
  693. }
  694. /**
  695. * Get published learning path id from link inside course home.
  696. *
  697. * @param string Link to published lp
  698. *
  699. * @return int Learning path id
  700. */
  701. public static function getPublishedLpIdFromLink($link)
  702. {
  703. $lpId = 0;
  704. $param = strstr($link, 'lp_id=');
  705. if (!empty($param)) {
  706. $paramList = explode('=', $param);
  707. if (isset($paramList[1])) {
  708. $lpId = (int) $paramList[1];
  709. }
  710. }
  711. return $lpId;
  712. }
  713. /**
  714. * Get published learning path category from link inside course home.
  715. *
  716. * @param string $link
  717. *
  718. * @return CLpCategory
  719. */
  720. public static function getPublishedLpCategoryFromLink($link)
  721. {
  722. $query = parse_url($link, PHP_URL_QUERY);
  723. parse_str($query, $params);
  724. $id = isset($params['id']) ? (int) $params['id'] : 0;
  725. $em = Database::getManager();
  726. /** @var CLpCategory $category */
  727. $category = $em->find('ChamiloCourseBundle:CLpCategory', $id);
  728. return $category;
  729. }
  730. /**
  731. * Show a navigation menu.
  732. */
  733. public static function show_navigation_menu()
  734. {
  735. $blocks = self::getUserBlocks();
  736. $class = null;
  737. $idLearn = null;
  738. $item = null;
  739. $marginLeft = 160;
  740. $html = '<div id="toolnav">';
  741. $html .= '<ul id="toolnavbox">';
  742. $showOnlyText = api_get_setting('show_navigation_menu') === 'text';
  743. $showOnlyIcons = api_get_setting('show_navigation_menu') === 'icons';
  744. foreach ($blocks as $block) {
  745. $blockItems = $block['content'];
  746. foreach ($blockItems as $item) {
  747. $html .= '<li>';
  748. if ($showOnlyText) {
  749. $class = 'text';
  750. $marginLeft = 170;
  751. $show = $item['name'];
  752. } elseif ($showOnlyIcons) {
  753. $class = 'icons';
  754. $marginLeft = 25;
  755. $show = $item['tool']['only_icon_small'];
  756. } else {
  757. $class = 'icons-text';
  758. $show = $item['name'].$item['tool']['only_icon_small'];
  759. }
  760. $item['url_params']['class'] = 'btn btn-default text-left '.$class;
  761. $html .= Display::url(
  762. $show,
  763. $item['only_href'],
  764. $item['url_params']
  765. );
  766. $html .= '</li>';
  767. }
  768. }
  769. $html .= '</ul>';
  770. $html .= '<script>$(function() {
  771. $("#toolnavbox a").stop().animate({"margin-left":"-'.$marginLeft.'px"},1000);
  772. $("#toolnavbox > li").hover(
  773. function () {
  774. $("a",$(this)).stop().animate({"margin-left":"-2px"},200);
  775. $("span",$(this)).css("display","block");
  776. },
  777. function () {
  778. $("a",$(this)).stop().animate({"margin-left":"-'.$marginLeft.'px"},200);
  779. $("span",$(this)).css("display","initial");
  780. }
  781. );
  782. });</script>';
  783. $html .= '</div>';
  784. return $html;
  785. }
  786. /**
  787. * Show a toolbar with shortcuts to the course tool.
  788. *
  789. * @param int $orientation
  790. *
  791. * @return string
  792. */
  793. public static function show_navigation_tool_shortcuts($orientation = SHORTCUTS_HORIZONTAL)
  794. {
  795. $origin = api_get_origin();
  796. $courseInfo = api_get_course_info();
  797. if ($origin === 'learnpath') {
  798. return '';
  799. }
  800. $blocks = self::getUserBlocks();
  801. $html = '';
  802. if (!empty($blocks)) {
  803. $styleId = 'toolshortcuts_vertical';
  804. if ($orientation == SHORTCUTS_HORIZONTAL) {
  805. $styleId = 'toolshortcuts_horizontal';
  806. }
  807. $html .= '<div id="'.$styleId.'">';
  808. $html .= Display::url(
  809. Display::return_icon('home.png', get_lang('Course home'), '', ICON_SIZE_MEDIUM),
  810. $courseInfo['course_public_url'],
  811. ['class' => 'items-icon']
  812. );
  813. foreach ($blocks as $block) {
  814. $blockItems = $block['content'];
  815. foreach ($blockItems as $item) {
  816. $item['url_params']['id'] = '';
  817. $item['url_params']['class'] = 'items-icon';
  818. $html .= Display::url(
  819. $item['tool']['only_icon_medium'],
  820. $item['only_href'],
  821. $item['url_params']
  822. );
  823. if ($orientation == SHORTCUTS_VERTICAL) {
  824. $html .= '<br />';
  825. }
  826. }
  827. }
  828. $html .= '</div>';
  829. }
  830. return $html;
  831. }
  832. /**
  833. * List course homepage tools from authoring and interaction sections.
  834. *
  835. * @param int $courseId The course ID (guessed from context if not provided)
  836. * @param int $sessionId The session ID (guessed from context if not provided)
  837. *
  838. * @return array List of all tools data from the c_tools table
  839. */
  840. public static function toolsIconsAction($courseId = null, $sessionId = null)
  841. {
  842. if (empty($courseId)) {
  843. $courseId = api_get_course_int_id();
  844. } else {
  845. $courseId = intval($courseId);
  846. }
  847. if (empty($sessionId)) {
  848. $sessionId = api_get_session_id();
  849. } else {
  850. $sessionId = intval($sessionId);
  851. }
  852. if (empty($courseId)) {
  853. // We shouldn't get here, but for some reason api_get_course_int_id()
  854. // doesn't seem to get the course from the context, sometimes
  855. return [];
  856. }
  857. $table = Database::get_course_table(TABLE_TOOL_LIST);
  858. $sql = "SELECT * FROM $table
  859. WHERE category in ('authoring','interaction')
  860. AND c_id = $courseId
  861. AND session_id = $sessionId
  862. ORDER BY id";
  863. $result = Database::query($sql);
  864. $data = Database::store_result($result, 'ASSOC');
  865. return $data;
  866. }
  867. /**
  868. * @param int $editIcon
  869. *
  870. * @return array
  871. */
  872. public static function getTool($editIcon)
  873. {
  874. $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST);
  875. $editIcon = intval($editIcon);
  876. $sql = "SELECT * FROM $course_tool_table
  877. WHERE iid = $editIcon";
  878. $result = Database::query($sql);
  879. $tool = Database::fetch_assoc($result, 'ASSOC');
  880. return $tool;
  881. }
  882. /**
  883. * @return string
  884. */
  885. public static function getCustomSysIconPath()
  886. {
  887. // Check if directory exists or create it if it doesn't
  888. $dir = api_get_path(SYS_COURSE_PATH).api_get_course_path().'/upload/course_home_icons/';
  889. if (!is_dir($dir)) {
  890. mkdir($dir, api_get_permissions_for_new_directories(), true);
  891. }
  892. return $dir;
  893. }
  894. /**
  895. * @return string
  896. */
  897. public static function getCustomWebIconPath()
  898. {
  899. // Check if directory exists or create it if it doesn't
  900. $dir = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/upload/course_home_icons/';
  901. return $dir;
  902. }
  903. /**
  904. * @param string $icon
  905. *
  906. * @return string
  907. */
  908. public static function getDisableIcon($icon)
  909. {
  910. $fileInfo = pathinfo($icon);
  911. return $fileInfo['filename'].'_na.'.$fileInfo['extension'];
  912. }
  913. /**
  914. * @param int $id
  915. * @param array $values
  916. */
  917. public static function updateTool($id, $values)
  918. {
  919. $table = Database::get_course_table(TABLE_TOOL_LIST);
  920. $params = [
  921. 'name' => $values['name'],
  922. 'link' => $values['link'],
  923. 'target' => $values['target'],
  924. 'visibility' => $values['visibility'],
  925. 'description' => $values['description'],
  926. ];
  927. if (isset($_FILES['icon']['size']) && $_FILES['icon']['size'] !== 0) {
  928. $dir = self::getCustomSysIconPath();
  929. // Resize image if it is larger than 64px
  930. $temp = new Image($_FILES['icon']['tmp_name']);
  931. $picture_infos = $temp->get_image_info();
  932. if ($picture_infos['width'] > 64) {
  933. $thumbwidth = 64;
  934. } else {
  935. $thumbwidth = $picture_infos['width'];
  936. }
  937. if ($picture_infos['height'] > 64) {
  938. $new_height = 64;
  939. } else {
  940. $new_height = $picture_infos['height'];
  941. }
  942. $temp->resize($thumbwidth, $new_height, 0);
  943. //copy the image to the course upload folder
  944. $path = $dir.$_FILES['icon']['name'];
  945. $result = $temp->send_image($path);
  946. $temp = new Image($path);
  947. $r = $temp->convert2bw();
  948. $ext = pathinfo($path, PATHINFO_EXTENSION);
  949. $bwPath = substr($path, 0, -(strlen($ext) + 1)).'_na.'.$ext;
  950. if ($r === false) {
  951. error_log('Conversion to B&W of '.$path.' failed in '.__FILE__.' at line '.__LINE__);
  952. } else {
  953. $temp->send_image($bwPath);
  954. $iconName = $_FILES['icon']['name'];
  955. $params['custom_icon'] = $iconName;
  956. }
  957. }
  958. Database::update(
  959. $table,
  960. $params,
  961. [' iid = ?' => [$id]]
  962. );
  963. }
  964. /**
  965. * @param int $id
  966. */
  967. public static function deleteIcon($id)
  968. {
  969. $table = Database::get_course_table(TABLE_TOOL_LIST);
  970. $tool = self::getTool($id);
  971. if ($tool && !empty($tool['custom_icon'])) {
  972. $file = self::getCustomSysIconPath().$tool['custom_icon'];
  973. $fileInfo = pathinfo($file);
  974. $fileGray = $fileInfo['filename'].'_na.'.$fileInfo['extension'];
  975. $fileGray = self::getCustomSysIconPath().$fileGray;
  976. if (file_exists($file) && is_file($file)) {
  977. if (Security::check_abs_path($file, self::getCustomSysIconPath())) {
  978. unlink($file);
  979. }
  980. }
  981. if (file_exists($fileGray) && is_file($fileGray)) {
  982. if (Security::check_abs_path($fileGray, self::getCustomSysIconPath())) {
  983. unlink($fileGray);
  984. }
  985. }
  986. $params = [
  987. 'custom_icon' => '',
  988. ];
  989. Database::update(
  990. $table,
  991. $params,
  992. [' iid = ?' => [$id]]
  993. );
  994. }
  995. }
  996. /**
  997. * @return array
  998. */
  999. public static function getCourseAdminBlocks()
  1000. {
  1001. $blocks = [];
  1002. $my_list = self::get_tools_category(TOOL_AUTHORING);
  1003. $blocks[] = [
  1004. 'title' => get_lang('Authoring'),
  1005. 'class' => 'course-tools-author',
  1006. 'content' => self::show_tools_category($my_list),
  1007. ];
  1008. $list1 = self::get_tools_category(TOOL_INTERACTION);
  1009. $list2 = self::get_tools_category(TOOL_COURSE_PLUGIN);
  1010. $my_list = array_merge($list1, $list2);
  1011. $blocks[] = [
  1012. 'title' => get_lang('Interaction'),
  1013. 'class' => 'course-tools-interaction',
  1014. 'content' => self::show_tools_category($my_list),
  1015. ];
  1016. $my_list = self::get_tools_category(TOOL_ADMIN_PLATFORM);
  1017. $blocks[] = [
  1018. 'title' => get_lang('Administration'),
  1019. 'class' => 'course-tools-administration',
  1020. 'content' => self::show_tools_category($my_list),
  1021. ];
  1022. return $blocks;
  1023. }
  1024. /**
  1025. * @return array
  1026. */
  1027. public static function getCoachBlocks()
  1028. {
  1029. $blocks = [];
  1030. $my_list = self::get_tools_category(TOOL_STUDENT_VIEW);
  1031. $blocks[] = [
  1032. 'content' => self::show_tools_category($my_list),
  1033. ];
  1034. $sessionsCopy = api_get_setting('allow_session_course_copy_for_teachers');
  1035. if ($sessionsCopy === 'true') {
  1036. // Adding only maintenance for coaches.
  1037. $myList = self::get_tools_category(TOOL_ADMIN_PLATFORM);
  1038. $onlyMaintenanceList = [];
  1039. foreach ($myList as $item) {
  1040. if ($item['name'] === 'course_maintenance') {
  1041. $item['link'] = 'course_info/maintenance_coach.php';
  1042. $onlyMaintenanceList[] = $item;
  1043. }
  1044. }
  1045. $blocks[] = [
  1046. 'title' => get_lang('Administration'),
  1047. 'content' => self::show_tools_category($onlyMaintenanceList),
  1048. ];
  1049. }
  1050. return $blocks;
  1051. }
  1052. /**
  1053. * @return array
  1054. */
  1055. public static function getStudentBlocks()
  1056. {
  1057. $blocks = [];
  1058. $tools = self::get_tools_category(TOOL_STUDENT_VIEW);
  1059. $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
  1060. api_get_user_id(),
  1061. api_get_course_info()
  1062. );
  1063. // Force user icon for DRH
  1064. if ($isDrhOfCourse) {
  1065. $addUserTool = true;
  1066. foreach ($tools as $tool) {
  1067. if ($tool['name'] === 'user') {
  1068. $addUserTool = false;
  1069. break;
  1070. }
  1071. }
  1072. if ($addUserTool) {
  1073. $tools[] = [
  1074. 'c_id' => api_get_course_int_id(),
  1075. 'name' => 'user',
  1076. 'link' => 'user/user.php',
  1077. 'image' => 'members.gif',
  1078. 'visibility' => '1',
  1079. 'admin' => '0',
  1080. 'address' => 'squaregrey.gif',
  1081. 'added_tool' => '0',
  1082. 'target' => '_self',
  1083. 'category' => 'interaction',
  1084. 'session_id' => api_get_session_id(),
  1085. ];
  1086. }
  1087. }
  1088. if (count($tools) > 0) {
  1089. $blocks[] = ['content' => self::show_tools_category($tools)];
  1090. }
  1091. if ($isDrhOfCourse) {
  1092. $drhTool = self::get_tools_category(TOOL_DRH);
  1093. $blocks[] = ['content' => self::show_tools_category($drhTool)];
  1094. }
  1095. return $blocks;
  1096. }
  1097. /**
  1098. * @return array
  1099. */
  1100. public static function getUserBlocks()
  1101. {
  1102. $sessionId = api_get_session_id();
  1103. // Start of tools for CourseAdmins (teachers/tutors)
  1104. if ($sessionId === 0 && api_is_course_admin() && api_is_allowed_to_edit(null, true)) {
  1105. $blocks = self::getCourseAdminBlocks();
  1106. } elseif (api_is_coach()) {
  1107. $blocks = self::getCoachBlocks();
  1108. } else {
  1109. $blocks = self::getStudentBlocks();
  1110. }
  1111. return $blocks;
  1112. }
  1113. /**
  1114. * Filter tool icons. Only show if $patronKey is = :teacher
  1115. * Example dataIcons[i]['name']: parameter titleIcons1:teacher || titleIcons2 || titleIcons3:teacher.
  1116. *
  1117. * @param array $dataIcons array Reference to icons
  1118. * @param string $courseToolCategory Current tools category
  1119. *
  1120. * @return array
  1121. */
  1122. private static function filterPluginTools($dataIcons, $courseToolCategory)
  1123. {
  1124. $patronKey = ':teacher';
  1125. if ($courseToolCategory == TOOL_STUDENT_VIEW) {
  1126. //Fix only coach can see external pages - see #8236 - icpna
  1127. if (api_is_coach()) {
  1128. foreach ($dataIcons as $index => $array) {
  1129. if (isset($array['name'])) {
  1130. $dataIcons[$index]['name'] = str_replace($patronKey, '', $array['name']);
  1131. }
  1132. }
  1133. return $dataIcons;
  1134. }
  1135. $flagOrder = false;
  1136. foreach ($dataIcons as $index => $array) {
  1137. if (!isset($array['name'])) {
  1138. continue;
  1139. }
  1140. $pos = strpos($array['name'], $patronKey);
  1141. if ($pos !== false) {
  1142. unset($dataIcons[$index]);
  1143. $flagOrder = true;
  1144. }
  1145. }
  1146. if ($flagOrder) {
  1147. return array_values($dataIcons);
  1148. }
  1149. return $dataIcons;
  1150. }
  1151. // clean patronKey of name icons
  1152. foreach ($dataIcons as $index => $array) {
  1153. if (isset($array['name'])) {
  1154. $dataIcons[$index]['name'] = str_replace($patronKey, '', $array['name']);
  1155. }
  1156. }
  1157. return $dataIcons;
  1158. }
  1159. /**
  1160. * Find the tool icon when homepage_view is activity_big.
  1161. *
  1162. * @param array $item
  1163. * @param int $iconSize
  1164. * @param bool $generateId
  1165. *
  1166. * @return string
  1167. */
  1168. private static function getToolIcon(array $item, $iconSize, $generateId = true)
  1169. {
  1170. $image = str_replace('.gif', '.png', $item['tool']['image']);
  1171. $toolIid = isset($item['tool']['iid']) ? $item['tool']['iid'] : null;
  1172. if (isset($item['tool']['custom_image'])) {
  1173. return Display::img(
  1174. $item['tool']['custom_image'],
  1175. $item['name'],
  1176. ['id' => 'toolimage_'.$toolIid]
  1177. );
  1178. }
  1179. if (isset($item['tool']['custom_icon']) && !empty($item['tool']['custom_icon'])) {
  1180. $customIcon = $item['tool']['custom_icon'];
  1181. if ($item['tool']['visibility'] == '0') {
  1182. $customIcon = self::getDisableIcon($item['tool']['custom_icon']);
  1183. }
  1184. return Display::img(
  1185. self::getCustomWebIconPath().$customIcon,
  1186. $item['name'],
  1187. ['id' => 'toolimage_'.$toolIid]
  1188. );
  1189. }
  1190. $id = '';
  1191. if ($generateId) {
  1192. $id = 'toolimage_'.$toolIid;
  1193. }
  1194. return Display::return_icon(
  1195. $image,
  1196. $item['name'],
  1197. ['id' => $id],
  1198. $iconSize,
  1199. false
  1200. );
  1201. }
  1202. }