public function definition() { global $CFG; $mform =& $this->_form; $share = $this->_customdata['share']; $mform->addElement('header', 'site', get_string('selecthub', 'hub')); $mform->addElement('static', 'info', '', get_string('selecthubinfo', 'hub') . html_writer::empty_tag('br')); $registrationmanager = new registration_manager(); $registeredhubs = $registrationmanager->get_registered_on_hubs(); //Public hub list $options = array(); foreach ($registeredhubs as $hub) { $hubname = $hub->hubname; $mform->addElement('hidden', clean_param($hub->huburl, PARAM_ALPHANUMEXT), $hubname); if (empty($hubname)) { $hubname = $hub->huburl; } $mform->addElement('radio', 'huburl', null, ' ' . $hubname, $hub->huburl); if ($hub->huburl == HUB_MOODLEORGHUBURL) { $mform->setDefault('huburl', $hub->huburl); } } $mform->addElement('hidden', 'id', $this->_customdata['id']); if ($share) { $buttonlabel = get_string('shareonhub', 'hub'); $mform->addElement('hidden', 'share', true); } else { $buttonlabel = get_string('advertiseonhub', 'hub'); $mform->addElement('hidden', 'advertise', true); } $this->add_action_buttons(false, $buttonlabel); }
public function definition() { global $CFG, $USER, $OUTPUT; $strrequired = get_string('required'); $mform =& $this->_form; //set default value $search = $this->_customdata['search']; if (isset($this->_customdata['coverage'])) { $coverage = $this->_customdata['coverage']; } else { $coverage = 'all'; } if (isset($this->_customdata['licence'])) { $licence = $this->_customdata['licence']; } else { $licence = 'all'; } if (isset($this->_customdata['subject'])) { $subject = $this->_customdata['subject']; } else { $subject = 'all'; } if (isset($this->_customdata['audience'])) { $audience = $this->_customdata['audience']; } else { $audience = 'all'; } if (isset($this->_customdata['language'])) { $language = $this->_customdata['language']; } else { $language = current_language(); } if (isset($this->_customdata['educationallevel'])) { $educationallevel = $this->_customdata['educationallevel']; } else { $educationallevel = 'all'; } if (isset($this->_customdata['downloadable'])) { $downloadable = $this->_customdata['downloadable']; } else { $downloadable = 0; } if (isset($this->_customdata['orderby'])) { $orderby = $this->_customdata['orderby']; } else { $orderby = 'newest'; } if (isset($this->_customdata['huburl'])) { $huburl = $this->_customdata['huburl']; } else { $huburl = HUB_MOODLEORGHUBURL; } $mform->addElement('header', 'site', get_string('search', 'block_community')); //add the course id (of the context) $mform->addElement('hidden', 'courseid', $this->_customdata['courseid']); $mform->addElement('hidden', 'executesearch', 1); //retrieve the hub list on the hub directory by web service $function = 'hubdirectory_get_hubs'; $params = array(); $serverurl = HUB_HUBDIRECTORYURL . "/local/hubdirectory/webservice/webservices.php"; require_once $CFG->dirroot . "/webservice/xmlrpc/lib.php"; $xmlrpcclient = new webservice_xmlrpc_client($serverurl, 'publichubdirectory'); try { $hubs = $xmlrpcclient->call($function, $params); } catch (Exception $e) { $hubs = array(); $error = $OUTPUT->notification(get_string('errorhublisting', 'block_community', $e->getMessage())); $mform->addElement('static', 'errorhub', '', $error); } //display list of registered on hub $registrationmanager = new registration_manager(); $registeredhubs = $registrationmanager->get_registered_on_hubs(); //retrieve some additional hubs that we will add to //the hub list got from the hub directory $additionalhubs = array(); foreach ($registeredhubs as $registeredhub) { $inthepubliclist = false; foreach ($hubs as $hub) { if ($hub['url'] == $registeredhub->huburl) { $inthepubliclist = true; $hub['registeredon'] = true; } } if (!$inthepubliclist) { $additionalhub = array(); $additionalhub['name'] = $registeredhub->hubname; $additionalhub['url'] = $registeredhub->huburl; $additionalhubs[] = $additionalhub; } } if (!empty($additionalhubs)) { $hubs = array_merge($hubs, $additionalhubs); } if (!empty($hubs)) { //TODO: sort hubs by trusted/prioritize //Public hub list $options = array(); $firsthub = false; foreach ($hubs as $hub) { if (array_key_exists('id', $hub)) { $params = array('hubid' => $hub['id'], 'filetype' => HUB_HUBSCREENSHOT_FILE_TYPE); $imgurl = new moodle_url(HUB_HUBDIRECTORYURL . "/local/hubdirectory/webservice/download.php", $params); $ascreenshothtml = html_writer::empty_tag('img', array('src' => $imgurl, 'alt' => $hub['name'])); $hubdescription = html_writer::tag('a', $hub['name'], array('class' => 'hublink clearfix', 'href' => $hub['url'], 'onclick' => 'this.target="_blank"')); $hubdescription .= html_writer::tag('span', $ascreenshothtml, array('class' => 'hubscreenshot')); $hubdescriptiontext = html_writer::tag('span', format_text($hub['description'], FORMAT_PLAIN), array('class' => 'hubdescription')); if (isset($hub['enrollablecourses'])) { //check needed to avoid warnings for Moodle version < 2011081700 $additionaldesc = get_string('enrollablecourses', 'block_community') . ': ' . $hub['enrollablecourses'] . ' - ' . get_string('downloadablecourses', 'block_community') . ': ' . $hub['downloadablecourses']; $hubdescriptiontext .= html_writer::tag('span', $additionaldesc, array('class' => 'hubadditionaldesc')); } if ($hub['trusted']) { $hubtrusted = get_string('hubtrusted', 'block_community'); $hubdescriptiontext .= html_writer::tag('span', $hubtrusted . ' ' . $OUTPUT->doc_link('trusted_hubs'), array('class' => 'trusted')); } $hubdescriptiontext = html_writer::tag('span', $hubdescriptiontext, array('class' => 'hubdescriptiontext')); $hubdescription = html_writer::tag('span', $hubdescription . $hubdescriptiontext, array('class' => $hub['trusted'] ? 'hubtrusted' : 'hubnottrusted')); } else { $hubdescription = html_writer::tag('a', $hub['name'], array('class' => 'hublink hubtrusted', 'href' => $hub['url'])); } if (empty($firsthub)) { $mform->addElement('radio', 'huburl', get_string('selecthub', 'block_community'), $hubdescription, $hub['url']); $mform->setDefault('huburl', $huburl); $firsthub = true; } else { $mform->addElement('radio', 'huburl', '', $hubdescription, $hub['url']); } } //display enrol/download select box if the USER has the download capability on the course if (has_capability('moodle/community:download', context_course::instance($this->_customdata['courseid']))) { $options = array(0 => get_string('enrollable', 'block_community'), 1 => get_string('downloadable', 'block_community')); $mform->addElement('select', 'downloadable', get_string('enroldownload', 'block_community'), $options); $mform->addHelpButton('downloadable', 'enroldownload', 'block_community'); } else { $mform->addElement('hidden', 'downloadable', 0); } $options = array(); $options['all'] = get_string('any'); $options[HUB_AUDIENCE_EDUCATORS] = get_string('audienceeducators', 'hub'); $options[HUB_AUDIENCE_STUDENTS] = get_string('audiencestudents', 'hub'); $options[HUB_AUDIENCE_ADMINS] = get_string('audienceadmins', 'hub'); $mform->addElement('select', 'audience', get_string('audience', 'block_community'), $options); $mform->setDefault('audience', $audience); unset($options); $mform->addHelpButton('audience', 'audience', 'block_community'); $options = array(); $options['all'] = get_string('any'); $options[HUB_EDULEVEL_PRIMARY] = get_string('edulevelprimary', 'hub'); $options[HUB_EDULEVEL_SECONDARY] = get_string('edulevelsecondary', 'hub'); $options[HUB_EDULEVEL_TERTIARY] = get_string('eduleveltertiary', 'hub'); $options[HUB_EDULEVEL_GOVERNMENT] = get_string('edulevelgovernment', 'hub'); $options[HUB_EDULEVEL_ASSOCIATION] = get_string('edulevelassociation', 'hub'); $options[HUB_EDULEVEL_CORPORATE] = get_string('edulevelcorporate', 'hub'); $options[HUB_EDULEVEL_OTHER] = get_string('edulevelother', 'hub'); $mform->addElement('select', 'educationallevel', get_string('educationallevel', 'block_community'), $options); $mform->setDefault('educationallevel', $educationallevel); unset($options); $mform->addHelpButton('educationallevel', 'educationallevel', 'block_community'); $publicationmanager = new course_publish_manager(); $options = $publicationmanager->get_sorted_subjects(); foreach ($options as $key => &$option) { $keylength = strlen($key); if ($keylength == 10) { $option = " " . $option; } else { if ($keylength == 12) { $option = " " . $option; } } } $options = array_merge(array('all' => get_string('any')), $options); $mform->addElement('select', 'subject', get_string('subject', 'block_community'), $options, array('id' => 'communitysubject')); $mform->setDefault('subject', $subject); unset($options); $mform->addHelpButton('subject', 'subject', 'block_community'); $this->init_javascript_enhancement('subject', 'smartselect', array('selectablecategories' => true, 'mode' => 'compact')); require_once $CFG->libdir . "/licenselib.php"; $licensemanager = new license_manager(); $licences = $licensemanager->get_licenses(); $options = array(); $options['all'] = get_string('any'); foreach ($licences as $license) { $options[$license->shortname] = get_string($license->shortname, 'license'); } $mform->addElement('select', 'licence', get_string('licence', 'block_community'), $options); unset($options); $mform->addHelpButton('licence', 'licence', 'block_community'); $mform->setDefault('licence', $licence); $languages = get_string_manager()->get_list_of_languages(); collatorlib::asort($languages); $languages = array_merge(array('all' => get_string('any')), $languages); $mform->addElement('select', 'language', get_string('language'), $languages); $mform->setDefault('language', $language); $mform->addHelpButton('language', 'language', 'block_community'); $mform->addElement('radio', 'orderby', get_string('orderby', 'block_community'), get_string('orderbynewest', 'block_community'), 'newest'); $mform->addElement('radio', 'orderby', null, get_string('orderbyeldest', 'block_community'), 'eldest'); $mform->addElement('radio', 'orderby', null, get_string('orderbyname', 'block_community'), 'fullname'); $mform->addElement('radio', 'orderby', null, get_string('orderbypublisher', 'block_community'), 'publisher'); $mform->addElement('radio', 'orderby', null, get_string('orderbyratingaverage', 'block_community'), 'ratingaverage'); $mform->setDefault('orderby', $orderby); $mform->setType('orderby', PARAM_ALPHA); $mform->addElement('text', 'search', get_string('keywords', 'block_community')); $mform->addHelpButton('search', 'keywords', 'block_community'); $mform->addElement('submit', 'submitbutton', get_string('search', 'block_community')); } }
if (!empty($publication)) { $publication->status = $sitecourse['privacy']; $publication->timechecked = time(); $publicationmanager->update_publication($publication); } else { $msgparams = new stdClass(); $msgparams->id = $sitecourse['id']; $msgparams->hubname = html_writer::tag('a', $hub->hubname, array('href' => $hub->huburl)); $confirmmessage .= $OUTPUT->notification(get_string('detectednotexistingpublication', 'hub', $msgparams)); } } } } //if the site os registered on no hub display an error page $registrationmanager = new registration_manager(); $registeredhubs = $registrationmanager->get_registered_on_hubs(); if (empty($registeredhubs)) { echo $OUTPUT->header(); echo $OUTPUT->heading(get_string('publishon', 'hub'), 3, 'main'); echo $OUTPUT->box(get_string('notregisteredonhub', 'hub')); echo $OUTPUT->footer(); die; } $renderer = $PAGE->get_renderer('core', 'publish'); /// UNPUBLISH $cancel = optional_param('cancel', 0, PARAM_BOOL); if (!empty($cancel) and confirm_sesskey()) { $confirm = optional_param('confirm', 0, PARAM_BOOL); $hubcourseid = optional_param('hubcourseid', 0, PARAM_INT); $publicationid = optional_param('publicationid', 0, PARAM_INT); $timepublished = optional_param('timepublished', 0, PARAM_INT);
public function definition() { global $CFG, $USER, $OUTPUT; $strrequired = get_string('required'); $mform =& $this->_form; //set default value $search = $this->_customdata['search']; if (isset($this->_customdata['coverage'])) { $coverage = $this->_customdata['coverage']; } else { $coverage = 'all'; } if (isset($this->_customdata['licence'])) { $licence = $this->_customdata['licence']; } else { $licence = 'all'; } if (isset($this->_customdata['subject'])) { $subject = $this->_customdata['subject']; } else { $subject = 'all'; } if (isset($this->_customdata['audience'])) { $audience = $this->_customdata['audience']; } else { $audience = 'all'; } if (isset($this->_customdata['language'])) { $language = $this->_customdata['language']; } else { $language = current_language(); } if (isset($this->_customdata['educationallevel'])) { $educationallevel = $this->_customdata['educationallevel']; } else { $educationallevel = 'all'; } if (isset($this->_customdata['downloadable'])) { $downloadable = $this->_customdata['downloadable']; } else { $downloadable = 1; } if (isset($this->_customdata['orderby'])) { $orderby = $this->_customdata['orderby']; } else { $orderby = 'newest'; } if (isset($this->_customdata['huburl'])) { $huburl = $this->_customdata['huburl']; } else { $huburl = HUB_MOODLEORGHUBURL; } $mform->addElement('header', 'site', get_string('search', 'block_community')); //add the course id (of the context) $mform->addElement('hidden', 'courseid', $this->_customdata['courseid']); $mform->setType('courseid', PARAM_INT); $mform->addElement('hidden', 'executesearch', 1); $mform->setType('executesearch', PARAM_INT); //retrieve the hub list on the hub directory by web service $function = 'hubdirectory_get_hubs'; $params = array(); $serverurl = HUB_HUBDIRECTORYURL . "/local/hubdirectory/webservice/webservices.php"; require_once $CFG->dirroot . "/webservice/xmlrpc/lib.php"; $xmlrpcclient = new webservice_xmlrpc_client($serverurl, 'publichubdirectory'); try { $hubs = $xmlrpcclient->call($function, $params); } catch (Exception $e) { $hubs = array(); $error = $OUTPUT->notification(get_string('errorhublisting', 'block_community', $e->getMessage())); $mform->addElement('static', 'errorhub', '', $error); } //display list of registered on hub $registrationmanager = new registration_manager(); $registeredhubs = $registrationmanager->get_registered_on_hubs(); //retrieve some additional hubs that we will add to //the hub list got from the hub directory $additionalhubs = array(); foreach ($registeredhubs as $registeredhub) { $inthepubliclist = false; foreach ($hubs as $hub) { if ($hub['url'] == $registeredhub->huburl) { $inthepubliclist = true; $hub['registeredon'] = true; } } if (!$inthepubliclist) { $additionalhub = array(); $additionalhub['name'] = $registeredhub->hubname; $additionalhub['url'] = $registeredhub->huburl; $additionalhubs[] = $additionalhub; } } if (!empty($additionalhubs)) { $hubs = array_merge($hubs, $additionalhubs); } if (!empty($hubs)) { $htmlhubs = array(); foreach ($hubs as $hub) { // Name can come from hub directory - need some cleaning. $hubname = clean_text($hub['name'], PARAM_TEXT); $smalllogohtml = ''; if (array_key_exists('id', $hub)) { // Retrieve hub logo + generate small logo. $params = array('hubid' => $hub['id'], 'filetype' => HUB_HUBSCREENSHOT_FILE_TYPE); $imgurl = new moodle_url(HUB_HUBDIRECTORYURL . "/local/hubdirectory/webservice/download.php", $params); $imgsize = getimagesize($imgurl->out(false)); if ($imgsize[0] > 1) { $ascreenshothtml = html_writer::empty_tag('img', array('src' => $imgurl, 'alt' => $hubname)); $smalllogohtml = html_writer::empty_tag('img', array('src' => $imgurl, 'alt' => $hubname, 'height' => 30, 'width' => 40)); } else { $ascreenshothtml = ''; } $hubimage = html_writer::tag('div', $ascreenshothtml, array('class' => 'hubimage')); // Statistics + trusted info. $hubstats = ''; if (isset($hub['enrollablecourses'])) { //check needed to avoid warnings for Moodle version < 2011081700 $additionaldesc = get_string('enrollablecourses', 'block_community') . ': ' . $hub['enrollablecourses'] . ' - ' . get_string('downloadablecourses', 'block_community') . ': ' . $hub['downloadablecourses']; $hubstats .= html_writer::tag('div', $additionaldesc); } if ($hub['trusted']) { $hubtrusted = get_string('hubtrusted', 'block_community'); $hubstats .= $OUTPUT->doc_link('trusted_hubs') . html_writer::tag('div', $hubtrusted); } $hubstats = html_writer::tag('div', $hubstats, array('class' => 'hubstats')); // hub name link + hub description. $hubnamelink = html_writer::link($hub['url'], html_writer::tag('h2', $hubname), array('class' => 'hubtitlelink')); // The description can come from the hub directory - need to clean. $hubdescription = clean_param($hub['description'], PARAM_TEXT); $hubdescriptiontext = html_writer::tag('div', format_text($hubdescription, FORMAT_PLAIN), array('class' => 'hubdescription')); $hubtext = html_writer::tag('div', $hubdescriptiontext . $hubstats, array('class' => 'hubtext')); $hubimgandtext = html_writer::tag('div', $hubimage . $hubtext, array('class' => 'hubimgandtext')); $hubfulldesc = html_writer::tag('div', $hubnamelink . $hubimgandtext, array('class' => 'hubmainhmtl')); } else { $hubfulldesc = html_writer::link($hub['url'], $hubname); } // Add hub to the hub items. $hubinfo = new stdClass(); $hubinfo->mainhtml = $hubfulldesc; $hubinfo->rowhtml = html_writer::tag('div', $smalllogohtml, array('class' => 'hubsmalllogo')) . $hubname; $hubitems[$hub['url']] = $hubinfo; } // Hub listing form element. $mform->addElement('listing', 'huburl', '', '', array('items' => $hubitems, 'showall' => get_string('showall', 'block_community'), 'hideall' => get_string('hideall', 'block_community'))); $mform->setDefault('huburl', $huburl); //display enrol/download select box if the USER has the download capability on the course if (has_capability('moodle/community:download', context_course::instance($this->_customdata['courseid']))) { $options = array(0 => get_string('enrollable', 'block_community'), 1 => get_string('downloadable', 'block_community')); $mform->addElement('select', 'downloadable', get_string('enroldownload', 'block_community'), $options); $mform->addHelpButton('downloadable', 'enroldownload', 'block_community'); $mform->setDefault('downloadable', $downloadable); } else { $mform->addElement('hidden', 'downloadable', 0); } $mform->setType('downloadable', PARAM_INT); $options = array(); $options['all'] = get_string('any'); $options[HUB_AUDIENCE_EDUCATORS] = get_string('audienceeducators', 'hub'); $options[HUB_AUDIENCE_STUDENTS] = get_string('audiencestudents', 'hub'); $options[HUB_AUDIENCE_ADMINS] = get_string('audienceadmins', 'hub'); $mform->addElement('select', 'audience', get_string('audience', 'block_community'), $options); $mform->setDefault('audience', $audience); unset($options); $mform->addHelpButton('audience', 'audience', 'block_community'); $options = array(); $options['all'] = get_string('any'); $options[HUB_EDULEVEL_PRIMARY] = get_string('edulevelprimary', 'hub'); $options[HUB_EDULEVEL_SECONDARY] = get_string('edulevelsecondary', 'hub'); $options[HUB_EDULEVEL_TERTIARY] = get_string('eduleveltertiary', 'hub'); $options[HUB_EDULEVEL_GOVERNMENT] = get_string('edulevelgovernment', 'hub'); $options[HUB_EDULEVEL_ASSOCIATION] = get_string('edulevelassociation', 'hub'); $options[HUB_EDULEVEL_CORPORATE] = get_string('edulevelcorporate', 'hub'); $options[HUB_EDULEVEL_OTHER] = get_string('edulevelother', 'hub'); $mform->addElement('select', 'educationallevel', get_string('educationallevel', 'block_community'), $options); $mform->setDefault('educationallevel', $educationallevel); unset($options); $mform->addHelpButton('educationallevel', 'educationallevel', 'block_community'); $publicationmanager = new course_publish_manager(); $options = $publicationmanager->get_sorted_subjects(); $mform->addElement('searchableselector', 'subject', get_string('subject', 'block_community'), $options, array('id' => 'communitysubject')); $mform->setDefault('subject', $subject); unset($options); $mform->addHelpButton('subject', 'subject', 'block_community'); require_once $CFG->libdir . "/licenselib.php"; $licensemanager = new license_manager(); $licences = $licensemanager->get_licenses(); $options = array(); $options['all'] = get_string('any'); foreach ($licences as $license) { $options[$license->shortname] = get_string($license->shortname, 'license'); } $mform->addElement('select', 'licence', get_string('licence', 'block_community'), $options); unset($options); $mform->addHelpButton('licence', 'licence', 'block_community'); $mform->setDefault('licence', $licence); $languages = get_string_manager()->get_list_of_languages(); core_collator::asort($languages); $languages = array_merge(array('all' => get_string('any')), $languages); $mform->addElement('select', 'language', get_string('language'), $languages); $mform->setDefault('language', $language); $mform->addHelpButton('language', 'language', 'block_community'); $mform->addElement('select', 'orderby', get_string('orderby', 'block_community'), array('newest' => get_string('orderbynewest', 'block_community'), 'eldest' => get_string('orderbyeldest', 'block_community'), 'fullname' => get_string('orderbyname', 'block_community'), 'publisher' => get_string('orderbypublisher', 'block_community'), 'ratingaverage' => get_string('orderbyratingaverage', 'block_community'))); $mform->setDefault('orderby', $orderby); $mform->addHelpButton('orderby', 'orderby', 'block_community'); $mform->setType('orderby', PARAM_ALPHA); $mform->setAdvanced('audience'); $mform->setAdvanced('educationallevel'); $mform->setAdvanced('subject'); $mform->setAdvanced('licence'); $mform->setAdvanced('language'); $mform->setAdvanced('orderby'); $mform->addElement('text', 'search', get_string('keywords', 'block_community'), array('size' => 30)); $mform->addHelpButton('search', 'keywords', 'block_community'); $mform->setType('search', PARAM_NOTAGS); $mform->addElement('submit', 'submitbutton', get_string('search', 'block_community')); } }