|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00004 // // 00005 // This file is part of Moodle - http://moodle.org/ // 00006 // Moodle - Modular Object-Oriented Dynamic Learning Environment // 00007 // // 00008 // Moodle is free software: you can redistribute it and/or modify // 00009 // it under the terms of the GNU General Public License as published by // 00010 // the Free Software Foundation, either version 3 of the License, or // 00011 // (at your option) any later version. // 00012 // // 00013 // Moodle is distributed in the hope that it will be useful, // 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of // 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 00016 // GNU General Public License for more details. // 00017 // // 00018 // You should have received a copy of the GNU General Public License // 00019 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. // 00020 // // 00022 00031 class block_community_renderer extends plugin_renderer_base { 00032 00033 public function restore_confirmation_box($filename, $context) { 00034 $restoreurl = new moodle_url('/backup/restore.php', 00035 array('filename' => $filename . ".mbz", 'contextid' => $context->id)); 00036 $searchurl = new moodle_url('/blocks/community/communitycourse.php', 00037 array('add' => 1, 'courseid' => $context->instanceid, 00038 'cancelrestore' => 1, 'sesskey' => sesskey(), 00039 'filename' => $filename)); 00040 $formrestore = new single_button($restoreurl, 00041 get_string('dorestore', 'block_community')); 00042 $formsearch = new single_button($searchurl, 00043 get_string('donotrestore', 'block_community')); 00044 return $this->output->confirm(get_string('restorecourseinfo', 'block_community'), 00045 $formrestore, $formsearch); 00046 } 00047 00053 public function remove_success(moodle_url $url) { 00054 $html = $this->output->notification(get_string('communityremoved', 'hub'), 00055 'notifysuccess'); 00056 $continuebutton = new single_button($url, 00057 get_string('continue', 'block_community')); 00058 $html .= html_writer::tag('div', $this->output->render($continuebutton), 00059 array('class' => 'continuebutton')); 00060 return $html; 00061 } 00062 00068 public function save_link_success(moodle_url $url) { 00069 $html = $this->output->notification(get_string('addedtoblock', 'block_community'), 00070 'notifysuccess'); 00071 $continuebutton = new single_button($url, 00072 get_string('continue', 'block_community')); 00073 $html .= html_writer::tag('div', $this->output->render($continuebutton), 00074 array('class' => 'continuebutton')); 00075 return $html; 00076 } 00077 00083 public function next_button($data) { 00084 $nextlink = html_writer::tag('a', get_string('next', 'block_community'), 00085 array('href' => new moodle_url('', $data))); 00086 return html_writer::tag('div', $nextlink, array( 'class' => 'nextlink')); 00087 } 00088 00096 public function course_list($courses, $huburl, $contextcourseid) { 00097 global $CFG; 00098 00099 $renderedhtml = ''; 00100 00101 if (empty($courses)) { 00102 if (isset($courses)) { 00103 $renderedhtml .= get_string('nocourse', 'block_community'); 00104 } 00105 } else { 00106 $courseiteration = 0; 00107 foreach ($courses as $course) { 00108 $course = (object) $course; 00109 $courseiteration = $courseiteration + 1; 00110 00111 //create visit link html 00112 if (!empty($course->courseurl)) { 00113 $courseurl = new moodle_url($course->courseurl); 00114 $linktext = get_string('visitsite', 'block_community'); 00115 } else { 00116 $courseurl = new moodle_url($course->demourl); 00117 $linktext = get_string('visitdemo', 'block_community'); 00118 } 00119 00120 $visitlinkhtml = html_writer::tag('a', $linktext, 00121 array('href' => $courseurl, 'class' => 'hubcoursedownload', 00122 'onclick' => 'this.target="_blank"')); 00123 00124 //create title html 00125 $coursename = html_writer::tag('h3', $course->fullname, 00126 array('class' => 'hubcoursetitle')); 00127 $coursenamehtml = html_writer::tag('div', $coursename, 00128 array('class' => 'hubcoursetitlepanel')); 00129 00130 // create screenshots html 00131 $screenshothtml = ''; 00132 if (!empty($course->screenshots)) { 00133 $baseurl = new moodle_url($huburl . '/local/hub/webservice/download.php', 00134 array('courseid' => $course->id, 00135 'filetype' => HUB_SCREENSHOT_FILE_TYPE)); 00136 $screenshothtml = html_writer::empty_tag('img', 00137 array('src' => $baseurl, 'alt' => $course->fullname)); 00138 } 00139 $coursescreenshot = html_writer::tag('div', $screenshothtml, 00140 array('class' => 'coursescreenshot', 00141 'id' => 'image-' . $course->id)); 00142 00143 //create description html 00144 $deschtml = html_writer::tag('div', $course->description, 00145 array('class' => 'hubcoursedescription')); 00146 00147 //create users related information html 00148 $courseuserinfo = get_string('userinfo', 'block_community', $course); 00149 if ($course->contributornames) { 00150 $courseuserinfo .= ' - ' . get_string('contributors', 'block_community', 00151 $course->contributornames); 00152 } 00153 $courseuserinfohtml = html_writer::tag('div', $courseuserinfo, 00154 array('class' => 'hubcourseuserinfo')); 00155 00156 //create course content related information html 00157 $course->subject = get_string($course->subject, 'edufields'); 00158 $course->audience = get_string('audience' . $course->audience, 'hub'); 00159 $course->educationallevel = get_string('edulevel' . $course->educationallevel, 'hub'); 00160 $coursecontentinfo = ''; 00161 if (empty($course->coverage)) { 00162 $course->coverage = ''; 00163 } else { 00164 $coursecontentinfo .= get_string('coverage', 'block_community', $course->coverage); 00165 $coursecontentinfo .= ' - '; 00166 } 00167 $coursecontentinfo .= get_string('contentinfo', 'block_community', $course); 00168 $coursecontentinfohtml = html_writer::tag('div', $coursecontentinfo, 00169 array('class' => 'hubcoursecontentinfo')); 00170 00172 //language 00173 if (!empty($course->language)) { 00174 $languages = get_string_manager()->get_list_of_languages(); 00175 $course->lang = $languages[$course->language]; 00176 } else { 00177 $course->lang = ''; 00178 } 00179 //licence 00180 require_once($CFG->libdir . "/licenselib.php"); 00181 $licensemanager = new license_manager(); 00182 $licenses = $licensemanager->get_licenses(); 00183 foreach ($licenses as $license) { 00184 if ($license->shortname == $course->licenceshortname) { 00185 $course->license = $license->fullname; 00186 } 00187 } 00188 $course->timeupdated = userdate($course->timemodified); 00189 $coursefileinfo = get_string('fileinfo', 'block_community', $course); 00190 $coursefileinfohtml = html_writer::tag('div', $coursefileinfo, 00191 array('class' => 'hubcoursefileinfo')); 00192 00193 00194 00195 //Create course content html 00196 $blocks = get_plugin_list('block'); 00197 $activities = get_plugin_list('mod'); 00198 if (!empty($course->contents)) { 00199 $activitieshtml = ''; 00200 $blockhtml = ''; 00201 foreach ($course->contents as $content) { 00202 $content = (object) $content; 00203 if ($content->moduletype == 'block') { 00204 if (!empty($blockhtml)) { 00205 $blockhtml .= ' - '; 00206 } 00207 if (array_key_exists($content->modulename, $blocks)) { 00208 $blockname = get_string('pluginname', 'block_' . $content->modulename); 00209 } else { 00210 $blockname = $content->modulename; 00211 } 00212 $blockhtml .= $blockname . " (" . $content->contentcount . ")"; 00213 } else { 00214 if (!empty($activitieshtml)) { 00215 $activitieshtml .= ' - '; 00216 } 00217 if (array_key_exists($content->modulename, $activities)) { 00218 $activityname = get_string('modulename', $content->modulename); 00219 } else { 00220 $activityname = $content->modulename; 00221 } 00222 $activitieshtml .= $activityname . " (" . $content->contentcount . ")"; 00223 } 00224 } 00225 00226 $blocksandactivities = html_writer::tag('div', 00227 get_string('activities', 'block_community') . " : " . $activitieshtml); 00228 00229 //Uncomment following lines to display blocks information 00230 // $blocksandactivities .= html_writer::tag('span', 00231 // get_string('blocks', 'block_community') . " : " . $blockhtml); 00232 } 00233 00234 //Create outcomes html 00235 $outcomes= ''; 00236 if (!empty($course->outcomes)) { 00237 foreach ($course->outcomes as $outcome) { 00238 if (!empty($outcomes)) { 00239 $outcomes .= ', '; 00240 } 00241 $outcomes .= $outcome['fullname']; 00242 } 00243 $outcomes = get_string('outcomes', 'block_community', 00244 $outcomes); 00245 } 00246 $outcomeshtml = html_writer::tag('div', $outcomes, array('class' => 'hubcourseoutcomes')); 00247 00248 //create additional information html 00249 $additionaldesc = $courseuserinfohtml . $coursecontentinfohtml 00250 . $coursefileinfohtml . $blocksandactivities . $outcomeshtml; 00251 $additionaldeschtml = html_writer::tag('div', $additionaldesc, 00252 array('class' => 'additionaldesc')); 00253 00254 //Create add button html 00255 $addbuttonhtml = ""; 00256 if ($course->enrollable) { 00257 $params = array('sesskey' => sesskey(), 'add' => 1, 'confirmed' => 1, 00258 'coursefullname' => $course->fullname, 'courseurl' => $courseurl, 00259 'coursedescription' => $course->description, 00260 'courseid' => $contextcourseid); 00261 $addurl = new moodle_url("/blocks/community/communitycourse.php", $params); 00262 $addbuttonhtml = html_writer::tag('a', 00263 get_string('addtocommunityblock', 'block_community'), 00264 array('href' => $addurl, 'class' => 'centeredbutton, hubcoursedownload')); 00265 } 00266 00267 //create download button html 00268 $downloadbuttonhtml = ""; 00269 if (!$course->enrollable) { 00270 $params = array('sesskey' => sesskey(), 'download' => 1, 'confirmed' => 1, 00271 'remotemoodleurl' => $CFG->wwwroot, 'courseid' => $contextcourseid, 00272 'downloadcourseid' => $course->id, 'huburl' => $huburl, 00273 'coursefullname' => $course->fullname, 'backupsize' => $course->backupsize); 00274 $downloadurl = new moodle_url("/blocks/community/communitycourse.php", $params); 00275 $downloadbuttonhtml = html_writer::tag('a', get_string('download', 'block_community'), 00276 array('href' => $downloadurl, 'class' => 'centeredbutton, hubcoursedownload')); 00277 } 00278 00279 //Create rating html 00280 $rating = html_writer::tag('div', get_string('noratings', 'block_community'), 00281 array('class' => 'norating')); 00282 if (!empty($course->rating)) { 00283 $course->rating = (object) $course->rating; 00284 if ($course->rating->count > 0) { 00285 00286 //calculate size of the rating star 00287 $starimagesize = 20; //in px 00288 $numberofstars = 5; 00289 $size = ($course->rating->aggregate / $course->rating->scaleid) 00290 * $numberofstars * $starimagesize; 00291 $rating = html_writer::tag('li', '', 00292 array('class' => 'current-rating', 00293 'style' => 'width:' . $size . 'px;')); 00294 00295 $rating = html_writer::tag('ul', $rating, 00296 array('class' => 'star-rating clearfix')); 00297 $rating .= html_writer::tag('div', ' (' . $course->rating->count . ')', 00298 array('class' => 'ratingcount clearfix')); 00299 } 00300 } 00301 00302 00303 //Create comments html 00304 $coursecomments = html_writer::tag('div', get_string('nocomments', 'block_community'), 00305 array('class' => 'nocomments')); 00306 $commentcount = 0; 00307 if (!empty($course->comments)) { 00308 //display only if there is some comment if there is some comment 00309 $commentcount = count($course->comments); 00310 $coursecomments = html_writer::tag('div', 00311 get_string('comments', 'block_community', $commentcount), 00312 array('class' => 'commenttitle')); 00313 00314 foreach ($course->comments as $comment) { 00315 $commentator = html_writer::tag('div', 00316 $comment['commentator'], 00317 array('class' => 'hubcommentator')); 00318 $commentdate = html_writer::tag('div', 00319 ' - ' . userdate($comment['date'], '%e/%m/%y'), 00320 array('class' => 'hubcommentdate clearfix')); 00321 00322 $commenttext = html_writer::tag('div', 00323 $comment['comment'], 00324 array('class' => 'hubcommenttext')); 00325 00326 $coursecomments .= html_writer::tag('div', 00327 $commentator . $commentdate . $commenttext, 00328 array('class' => 'hubcomment')); 00329 } 00330 $coursecommenticon = html_writer::tag('div', 00331 get_string('comments', 'block_community', $commentcount), 00332 array('class' => 'hubcoursecomments', 00333 'id' => 'comments-' . $course->id)); 00334 $coursecomments = $coursecommenticon . html_writer::tag('div', 00335 $coursecomments, 00336 array('class' => 'yui3-overlay-loading', 00337 'id' => 'commentoverlay-' . $course->id)); 00338 } 00339 00340 //link rate and comment 00341 $rateandcomment = html_writer::tag('div', 00342 html_writer::tag('a', get_string('rateandcomment', 'block_community'), 00343 array('href' => new moodle_url($huburl, 00344 array('courseid' => $course->id, 'mustbelogged' => true)), 00345 'onclick' => 'this.target="_blank"')), 00346 array('class' => 'hubrateandcomment')); 00347 00348 //the main DIV tags 00349 $buttonsdiv = html_writer::tag('div', 00350 $addbuttonhtml . $downloadbuttonhtml . $visitlinkhtml, 00351 array('class' => 'courseoperations')); 00352 $screenshotbuttonsdiv = html_writer::tag('div', 00353 $coursescreenshot . $buttonsdiv, 00354 array('class' => 'courselinks')); 00355 00356 $coursedescdiv = html_writer::tag('div', 00357 $deschtml . $additionaldeschtml 00358 . $rating . $coursecomments . $rateandcomment, 00359 array('class' => 'coursedescription')); 00360 $coursehtml = 00361 $coursenamehtml . html_writer::tag('div', 00362 $coursedescdiv . $screenshotbuttonsdiv, 00363 array('class' => 'hubcourseinfo clearfix')); 00364 00365 $renderedhtml .=html_writer::tag('div', $coursehtml, 00366 array('class' => 'fullhubcourse clearfix')); 00367 } 00368 00369 $renderedhtml = html_writer::tag('div', $renderedhtml, 00370 array('class' => 'hubcourseresult')); 00371 } 00372 00373 return $renderedhtml; 00374 } 00375 00376 }