. // // // /////////////////////////////////////////////////////////////////////////// /** * Block community renderer. * @package blocks * @subpackage community * @copyright 2010 Moodle Pty Ltd (http://moodle.com) * @author Jerome Mouneyrac * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class block_community_renderer extends plugin_renderer_base { /** * Display a list of courses * @param array $courses * @param boolean $withwriteaccess * @return string */ public function course_list($courses, $huburl) { global $OUTPUT, $CFG; $renderedhtml = ''; $table = new html_table(); $table->head = array(get_string('coursename', 'block_community'), get_string('coursedesc', 'block_community'), get_string('courselang', 'block_community'), get_string('operation', 'block_community')); $table->align = array('left', 'left', 'center', 'center'); $table->size = array('25%', '40%', '5%', '%5'); if (empty($courses)) { $renderedhtml .= get_string('nocourse', 'block_community'); } else { $table->width = '100%'; $table->data = array(); $table->attributes['class'] = 'sitedirectory'; // iterate through sites and add to the display table foreach ($courses as $course) { if (is_array($course)) { $course = (object) $course; } //create site name with link if (!empty($course->courseurl)) { $courseurl = new moodle_url($course->courseurl); } else { $courseurl = new moodle_url($course->demourl); } $courseatag = html_writer::tag('a', $course->fullname, array('href' => $courseurl)); $coursenamehtml = html_writer::tag('span', $courseatag, array()); //create description to display $course->subject = get_string($course->subject, 'edufields'); $course->audience = get_string('audience'.$course->audience, 'hub'); $course->educationallevel = get_string('edulevel'.$course->educationallevel, 'hub'); if (!empty($course->contributornames)) { $course->contributorname = get_string('contributors', 'block_community', $course->contributorname); } if (!empty($course->coverage)) { $course->coverage = get_string('coverage', 'block_community', $course->coverage); } $deschtml = $course->description; //the description /// courses and sites number display under the description, in smaller $deschtml .= html_writer::empty_tag('br'); $additionaldesc = get_string('additionalcoursedesc', 'block_community', $course); $deschtml .= html_writer::tag('span', $additionaldesc, array('class' => 'additionaldesc')); //retrieve language string //construct languages array if (!empty($course->language)) { $languages = get_string_manager()->get_list_of_languages(); $language = $languages[$course->language]; } else { $language= ''; } if ($course->enrollable) { //Add link TODO make it a button and send by post $addurl = new moodle_url("/blocks/community/communitycourse.php", array('sesskey' => sesskey(), 'add' => 1, 'confirmed' => 1, 'coursefullname' => $course->fullname, 'courseurl' => $courseurl, 'coursedescription' => $course->description)); $addlinkhtml = html_writer::tag('a', get_string('add'), array('href' => $addurl)); } else { // Add link TODO make it a button and send by post $addurl = new moodle_url("/blocks/community/communitycourse.php", array('sesskey' => sesskey(), 'download' => 1, 'confirmed' => 1, 'courseid' => $course->id, 'huburl' => $huburl)); $addlinkhtml = html_writer::tag('a', get_string('download', 'block_community'), array('href' => $addurl)); } // add a row to the table $cells = array($coursenamehtml, $deschtml, $language, $addlinkhtml); $row = new html_table_row($cells); $table->data[] = $row; } $renderedhtml .= html_writer::table($table); } return $renderedhtml; } }