renderer.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. <?php
  2. ///////////////////////////////////////////////////////////////////////////
  3. // //
  4. // This file is part of Moodle - http://moodle.org/ //
  5. // Moodle - Modular Object-Oriented Dynamic Learning Environment //
  6. // //
  7. // Moodle is free software: you can redistribute it and/or modify //
  8. // it under the terms of the GNU General Public License as published by //
  9. // the Free Software Foundation, either version 3 of the License, or //
  10. // (at your option) any later version. //
  11. // //
  12. // Moodle is distributed in the hope that it will be useful, //
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of //
  14. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
  15. // GNU General Public License for more details. //
  16. // //
  17. // You should have received a copy of the GNU General Public License //
  18. // along with Moodle. If not, see <http://www.gnu.org/licenses/>. //
  19. // //
  20. ///////////////////////////////////////////////////////////////////////////
  21. /**
  22. * Block community renderer.
  23. * @package block_community
  24. * @copyright 2010 Moodle Pty Ltd (http://moodle.com)
  25. * @author Jerome Mouneyrac
  26. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  27. */
  28. class block_community_renderer extends plugin_renderer_base {
  29. public function restore_confirmation_box($filename, $context) {
  30. $restoreurl = new moodle_url('/backup/restore.php',
  31. array('filename' => $filename . ".mbz", 'contextid' => $context->id));
  32. $searchurl = new moodle_url('/blocks/community/communitycourse.php',
  33. array('add' => 1, 'courseid' => $context->instanceid,
  34. 'cancelrestore' => 1, 'sesskey' => sesskey(),
  35. 'filename' => $filename));
  36. $formrestore = new single_button($restoreurl,
  37. get_string('dorestore', 'block_community'));
  38. $formsearch = new single_button($searchurl,
  39. get_string('donotrestore', 'block_community'));
  40. return $this->output->confirm(get_string('restorecourseinfo', 'block_community'),
  41. $formrestore, $formsearch);
  42. }
  43. /**
  44. * Display remove community success message and a button to be redirected to te referer page
  45. * @param moodle_url $url the page to be redirected to
  46. * @return string html
  47. */
  48. public function remove_success(moodle_url $url) {
  49. $html = $this->output->notification(get_string('communityremoved', 'hub'),
  50. 'notifysuccess');
  51. $continuebutton = new single_button($url,
  52. get_string('continue', 'block_community'));
  53. $html .= html_writer::tag('div', $this->output->render($continuebutton),
  54. array('class' => 'continuebutton'));
  55. return $html;
  56. }
  57. /**
  58. * Display add community course success message and a button to be redirected to te referer page
  59. * @param moodle_url $url the page to be redirected to
  60. * @return string html
  61. */
  62. public function save_link_success(moodle_url $url) {
  63. $html = $this->output->notification(get_string('addedtoblock', 'block_community'),
  64. 'notifysuccess');
  65. $continuebutton = new single_button($url,
  66. get_string('continue', 'block_community'));
  67. $html .= html_writer::tag('div', $this->output->render($continuebutton),
  68. array('class' => 'continuebutton'));
  69. return $html;
  70. }
  71. /**
  72. * The 'Next'/'more course result' link for a courses search
  73. * @param array $data - the form parameter to execute the search on more result
  74. * @return string html code
  75. */
  76. public function next_button($data) {
  77. $nextlink = html_writer::tag('a', get_string('next', 'block_community'),
  78. array('href' => new moodle_url('', $data)));
  79. return html_writer::tag('div', $nextlink, array( 'class' => 'nextlink'));
  80. }
  81. /**
  82. * Display a list of courses
  83. * @param array $courses
  84. * @param boolean $withwriteaccess
  85. * @param int $contextcourseid context course id
  86. * @return string
  87. */
  88. public function course_list($courses, $huburl, $contextcourseid) {
  89. global $CFG;
  90. $renderedhtml = '';
  91. if (empty($courses)) {
  92. if (isset($courses)) {
  93. $renderedhtml .= get_string('nocourse', 'block_community');
  94. }
  95. } else {
  96. $courseiteration = 0;
  97. foreach ($courses as $course) {
  98. $course = (object) $course;
  99. $courseiteration = $courseiteration + 1;
  100. //create visit link html
  101. if (!empty($course->courseurl)) {
  102. $courseurl = new moodle_url($course->courseurl);
  103. $linktext = get_string('visitsite', 'block_community');
  104. } else {
  105. $courseurl = new moodle_url($course->demourl);
  106. $linktext = get_string('visitdemo', 'block_community');
  107. }
  108. $visitlinkhtml = html_writer::tag('a', $linktext,
  109. array('href' => $courseurl, 'class' => 'hubcoursedownload',
  110. 'onclick' => 'this.target="_blank"'));
  111. //create title html
  112. $coursename = html_writer::tag('h3', $course->fullname,
  113. array('class' => 'hubcoursetitle'));
  114. $coursenamehtml = html_writer::tag('div', $coursename,
  115. array('class' => 'hubcoursetitlepanel'));
  116. // create screenshots html
  117. $screenshothtml = '';
  118. if (!empty($course->screenshots)) {
  119. $baseurl = new moodle_url($huburl . '/local/hub/webservice/download.php',
  120. array('courseid' => $course->id,
  121. 'filetype' => HUB_SCREENSHOT_FILE_TYPE));
  122. $screenshothtml = html_writer::empty_tag('img',
  123. array('src' => $baseurl, 'alt' => $course->fullname));
  124. }
  125. $coursescreenshot = html_writer::tag('div', $screenshothtml,
  126. array('class' => 'coursescreenshot',
  127. 'id' => 'image-' . $course->id));
  128. //create description html
  129. $deschtml = html_writer::tag('div', $course->description,
  130. array('class' => 'hubcoursedescription'));
  131. //create users related information html
  132. $courseuserinfo = get_string('userinfo', 'block_community', $course);
  133. if ($course->contributornames) {
  134. $courseuserinfo .= ' - ' . get_string('contributors', 'block_community',
  135. $course->contributornames);
  136. }
  137. $courseuserinfohtml = html_writer::tag('div', $courseuserinfo,
  138. array('class' => 'hubcourseuserinfo'));
  139. //create course content related information html
  140. $course->subject = get_string($course->subject, 'edufields');
  141. $course->audience = get_string('audience' . $course->audience, 'hub');
  142. $course->educationallevel = get_string('edulevel' . $course->educationallevel, 'hub');
  143. $coursecontentinfo = '';
  144. if (empty($course->coverage)) {
  145. $course->coverage = '';
  146. } else {
  147. $coursecontentinfo .= get_string('coverage', 'block_community', $course->coverage);
  148. $coursecontentinfo .= ' - ';
  149. }
  150. $coursecontentinfo .= get_string('contentinfo', 'block_community', $course);
  151. $coursecontentinfohtml = html_writer::tag('div', $coursecontentinfo,
  152. array('class' => 'hubcoursecontentinfo'));
  153. ///create course file related information html
  154. //language
  155. if (!empty($course->language)) {
  156. $languages = get_string_manager()->get_list_of_languages();
  157. $course->lang = $languages[$course->language];
  158. } else {
  159. $course->lang = '';
  160. }
  161. //licence
  162. require_once($CFG->libdir . "/licenselib.php");
  163. $licensemanager = new license_manager();
  164. $licenses = $licensemanager->get_licenses();
  165. foreach ($licenses as $license) {
  166. if ($license->shortname == $course->licenceshortname) {
  167. $course->license = $license->fullname;
  168. }
  169. }
  170. $course->timeupdated = userdate($course->timemodified);
  171. $coursefileinfo = get_string('fileinfo', 'block_community', $course);
  172. $coursefileinfohtml = html_writer::tag('div', $coursefileinfo,
  173. array('class' => 'hubcoursefileinfo'));
  174. //Create course content html
  175. $blocks = core_component::get_plugin_list('block');
  176. $activities = core_component::get_plugin_list('mod');
  177. if (!empty($course->contents)) {
  178. $activitieshtml = '';
  179. $blockhtml = '';
  180. foreach ($course->contents as $content) {
  181. $content = (object) $content;
  182. if ($content->moduletype == 'block') {
  183. if (!empty($blockhtml)) {
  184. $blockhtml .= ' - ';
  185. }
  186. if (array_key_exists($content->modulename, $blocks)) {
  187. $blockname = get_string('pluginname', 'block_' . $content->modulename);
  188. } else {
  189. $blockname = $content->modulename;
  190. }
  191. $blockhtml .= $blockname . " (" . $content->contentcount . ")";
  192. } else {
  193. if (!empty($activitieshtml)) {
  194. $activitieshtml .= ' - ';
  195. }
  196. if (array_key_exists($content->modulename, $activities)) {
  197. $activityname = get_string('modulename', $content->modulename);
  198. } else {
  199. $activityname = $content->modulename;
  200. }
  201. $activitieshtml .= $activityname . " (" . $content->contentcount . ")";
  202. }
  203. }
  204. $blocksandactivities = html_writer::tag('div',
  205. get_string('activities', 'block_community') . " : " . $activitieshtml);
  206. //Uncomment following lines to display blocks information
  207. // $blocksandactivities .= html_writer::tag('span',
  208. // get_string('blocks', 'block_community') . " : " . $blockhtml);
  209. }
  210. //Create outcomes html
  211. $outcomes= '';
  212. if (!empty($course->outcomes)) {
  213. foreach ($course->outcomes as $outcome) {
  214. if (!empty($outcomes)) {
  215. $outcomes .= ', ';
  216. }
  217. $outcomes .= $outcome['fullname'];
  218. }
  219. $outcomes = get_string('outcomes', 'block_community',
  220. $outcomes);
  221. }
  222. $outcomeshtml = html_writer::tag('div', $outcomes, array('class' => 'hubcourseoutcomes'));
  223. //create additional information html
  224. $additionaldesc = $courseuserinfohtml . $coursecontentinfohtml
  225. . $coursefileinfohtml . $blocksandactivities . $outcomeshtml;
  226. $additionaldeschtml = html_writer::tag('div', $additionaldesc,
  227. array('class' => 'additionaldesc'));
  228. //Create add button html
  229. $addbuttonhtml = "";
  230. if ($course->enrollable) {
  231. $params = array('sesskey' => sesskey(), 'add' => 1, 'confirmed' => 1,
  232. 'coursefullname' => $course->fullname, 'courseurl' => $courseurl,
  233. 'coursedescription' => $course->description,
  234. 'courseid' => $contextcourseid);
  235. $addurl = new moodle_url("/blocks/community/communitycourse.php", $params);
  236. $addbuttonhtml = html_writer::tag('a',
  237. get_string('addtocommunityblock', 'block_community'),
  238. array('href' => $addurl, 'class' => 'centeredbutton, hubcoursedownload'));
  239. }
  240. //create download button html
  241. $downloadbuttonhtml = "";
  242. if (!$course->enrollable) {
  243. $params = array('sesskey' => sesskey(), 'download' => 1, 'confirmed' => 1,
  244. 'remotemoodleurl' => $CFG->wwwroot, 'courseid' => $contextcourseid,
  245. 'downloadcourseid' => $course->id, 'huburl' => $huburl,
  246. 'coursefullname' => $course->fullname, 'backupsize' => $course->backupsize);
  247. $downloadurl = new moodle_url("/blocks/community/communitycourse.php", $params);
  248. $downloadbuttonhtml = html_writer::tag('a', get_string('install', 'block_community'),
  249. array('href' => $downloadurl, 'class' => 'centeredbutton, hubcoursedownload'));
  250. }
  251. //Create rating html
  252. $rating = html_writer::tag('div', get_string('noratings', 'block_community'),
  253. array('class' => 'norating'));
  254. if (!empty($course->rating)) {
  255. $course->rating = (object) $course->rating;
  256. if ($course->rating->count > 0) {
  257. //calculate size of the rating star
  258. $starimagesize = 20; //in px
  259. $numberofstars = 5;
  260. $size = ($course->rating->aggregate / $course->rating->scaleid)
  261. * $numberofstars * $starimagesize;
  262. $rating = html_writer::tag('li', '',
  263. array('class' => 'current-rating',
  264. 'style' => 'width:' . $size . 'px;'));
  265. $rating = html_writer::tag('ul', $rating,
  266. array('class' => 'star-rating clearfix'));
  267. $rating .= html_writer::tag('div', ' (' . $course->rating->count . ')',
  268. array('class' => 'ratingcount clearfix'));
  269. }
  270. }
  271. //Create comments html
  272. $coursecomments = html_writer::tag('div', get_string('nocomments', 'block_community'),
  273. array('class' => 'nocomments'));
  274. $commentcount = 0;
  275. if (!empty($course->comments)) {
  276. //display only if there is some comment if there is some comment
  277. $commentcount = count($course->comments);
  278. $coursecomments = html_writer::tag('div',
  279. get_string('comments', 'block_community', $commentcount),
  280. array('class' => 'commenttitle'));
  281. foreach ($course->comments as $comment) {
  282. $commentator = html_writer::tag('div',
  283. $comment['commentator'],
  284. array('class' => 'hubcommentator'));
  285. $commentdate = html_writer::tag('div',
  286. ' - ' . userdate($comment['date'], '%e/%m/%y'),
  287. array('class' => 'hubcommentdate clearfix'));
  288. $commenttext = html_writer::tag('div',
  289. $comment['comment'],
  290. array('class' => 'hubcommenttext'));
  291. $coursecomments .= html_writer::tag('div',
  292. $commentator . $commentdate . $commenttext,
  293. array('class' => 'hubcomment'));
  294. }
  295. $coursecommenticon = html_writer::tag('div',
  296. get_string('comments', 'block_community', $commentcount),
  297. array('class' => 'hubcoursecomments',
  298. 'id' => 'comments-' . $course->id));
  299. $coursecomments = $coursecommenticon . html_writer::tag('div',
  300. $coursecomments,
  301. array('class' => 'yui3-overlay-loading',
  302. 'id' => 'commentoverlay-' . $course->id));
  303. }
  304. //link rate and comment
  305. $rateandcomment = html_writer::tag('div',
  306. html_writer::tag('a', get_string('rateandcomment', 'block_community'),
  307. array('href' => new moodle_url($huburl,
  308. array('courseid' => $course->id, 'mustbelogged' => true)),
  309. 'onclick' => 'this.target="_blank"')),
  310. array('class' => 'hubrateandcomment'));
  311. //the main DIV tags
  312. $buttonsdiv = html_writer::tag('div',
  313. $addbuttonhtml . $downloadbuttonhtml . $visitlinkhtml,
  314. array('class' => 'courseoperations'));
  315. $screenshotbuttonsdiv = html_writer::tag('div',
  316. $coursescreenshot . $buttonsdiv,
  317. array('class' => 'courselinks'));
  318. $coursedescdiv = html_writer::tag('div',
  319. $deschtml . $additionaldeschtml
  320. . $rating . $coursecomments . $rateandcomment,
  321. array('class' => 'coursedescription'));
  322. $coursehtml =
  323. $coursenamehtml . html_writer::tag('div',
  324. $coursedescdiv . $screenshotbuttonsdiv,
  325. array('class' => 'hubcourseinfo clearfix'));
  326. $renderedhtml .=html_writer::tag('div', $coursehtml,
  327. array('class' => 'fullhubcourse clearfix'));
  328. }
  329. $renderedhtml = html_writer::tag('div', $renderedhtml,
  330. array('class' => 'hubcourseresult'));
  331. }
  332. return $renderedhtml;
  333. }
  334. }