Skip to content

Commit

Permalink
community block MDL-24292 add 'give me more' link to course search re…
Browse files Browse the repository at this point in the history
…sult
  • Loading branch information
mouneyrac committed Sep 21, 2010
1 parent 413f6cc commit c48ab36
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 30 deletions.
67 changes: 47 additions & 20 deletions blocks/community/communitycourse.php
Expand Up @@ -120,36 +120,50 @@
'notifysuccess');
}

//forms
$hubselectorform = new community_hub_search_form('',
array('search' => $search, 'courseid' => $courseid));
$fromform = $hubselectorform->get_data();
$courses = null;
//Get form default/current values
$fromformdata['coverage'] = optional_param('coverage', 'all', PARAM_TEXT);
$fromformdata['licence'] = optional_param('licence', 'all', PARAM_ALPHANUMEXT);
$fromformdata['subject'] = optional_param('subject', 'all', PARAM_ALPHANUMEXT);
$fromformdata['audience'] = optional_param('audience', 'all', PARAM_ALPHANUMEXT);
$fromformdata['language'] = optional_param('language', 'all', PARAM_ALPHANUMEXT);
$fromformdata['educationallevel'] = optional_param('educationallevel', 'all', PARAM_ALPHANUMEXT);
$fromformdata['downloadable'] = optional_param('downloadable', 0, PARAM_ALPHANUM);
$fromformdata['orderby'] = optional_param('orderby', 'newest', PARAM_ALPHA);
$fromformdata['huburl'] = optional_param('huburl', HUB_MOODLEORGHUBURL, PARAM_URL);
$fromformdata['search'] = $search;
$fromformdata['courseid'] = $courseid;
$hubselectorform = new community_hub_search_form('', $fromformdata);
$hubselectorform->set_data($fromformdata);

//Retrieve courses by web service
if (!empty($fromform)) {
$courses = null;
if (optional_param('executesearch', 0, PARAM_INTEGER) and confirm_sesskey()) {
$downloadable = optional_param('downloadable', false, PARAM_INTEGER);

$options = new stdClass();
if (!empty($fromform->coverage)) {
$options->coverage = $fromform->coverage;
if (!empty($fromformdata['coverage'])) {
$options->coverage = $fromformdata['coverage'];
}
if ($fromform->licence != 'all') {
$options->licenceshortname = $fromform->licence;
if ($fromformdata['licence'] != 'all') {
$options->licenceshortname = $fromformdata['licence'];
}
if ($fromform->subject != 'all') {
$options->subject = $fromform->subject;
if ($fromformdata['subject'] != 'all') {
$options->subject = $fromformdata['subject'];
}
if ($fromform->audience != 'all') {
$options->audience = $fromform->audience;
if ($fromformdata['audience'] != 'all') {
$options->audience = $fromformdata['audience'];
}
if ($fromform->educationallevel != 'all') {
$options->educationallevel = $fromform->educationallevel;
if ($fromformdata['educationallevel'] != 'all') {
$options->educationallevel = $fromformdata['educationallevel'];
}
if ($fromform->language != 'all') {
$options->language = $fromform->language;
if ($fromformdata['language'] != 'all') {
$options->language = $fromformdata['language'];
}

$options->orderby = $fromform->orderby;
$options->orderby = $fromformdata['orderby'];

//the range of course requested
$options->givememore = optional_param('givememore', 0, PARAM_INTEGER);

//check if the selected hub is from the registered list (in this case we use the private token)
$token = 'publichub';
Expand All @@ -168,7 +182,9 @@
require_once($CFG->dirroot . "/webservice/xmlrpc/lib.php");
$xmlrpcclient = new webservice_xmlrpc_client($serverurl, $token);
try {
$courses = $xmlrpcclient->call($function, $params);
$result = $xmlrpcclient->call($function, $params);
$courses = $result['courses'];
$coursetotal = $result['coursetotal'];
} catch (Exception $e) {
$errormessage = $OUTPUT->notification(
get_string('errorcourselisting', 'block_community', $e->getMessage()));
Expand Down Expand Up @@ -199,4 +215,15 @@
array(array('commentids' => $courseids)));

echo highlight($search, $renderer->course_list($courses, $huburl, $courseid));

//display givememore/Next link if more course can be displayed
if (!empty($courses)) {
if (($options->givememore + count($courses)) < $coursetotal) {
$fromformdata['givememore'] = count($courses) + $options->givememore;
$fromformdata['executesearch'] = true;
$fromformdata['sesskey'] = sesskey();
echo $renderer->next_button($fromformdata);
}
}

echo $OUTPUT->footer();
64 changes: 56 additions & 8 deletions blocks/community/forms.php
Expand Up @@ -40,11 +40,60 @@ 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 = 'all';
}
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';
Expand Down Expand Up @@ -130,7 +179,7 @@ public function definition() {
if (empty($firsthub)) {
$mform->addElement('radio', 'huburl', get_string('selecthub', 'block_community'),
$hubdescription, $hub['url']);
$mform->setDefault('huburl', HUB_MOODLEORGHUBURL);
$mform->setDefault('huburl', $huburl);
$firsthub = true;
} else {
$mform->addElement('radio', 'huburl', '', $hubdescription, $hub['url']);
Expand All @@ -155,7 +204,7 @@ public function definition() {
$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', 'all');
$mform->setDefault('audience', $audience);
unset($options);
$mform->addHelpButton('audience', 'audience', 'block_community');

Expand All @@ -170,7 +219,7 @@ public function definition() {
$options[HUB_EDULEVEL_OTHER] = get_string('edulevelother', 'hub');
$mform->addElement('select', 'educationallevel',
get_string('educationallevel', 'block_community'), $options);
$mform->setDefault('educationallevel', 'all');
$mform->setDefault('educationallevel', $educationallevel);
unset($options);
$mform->addHelpButton('educationallevel', 'educationallevel', 'block_community');

Expand All @@ -187,7 +236,7 @@ public function definition() {
$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', 'all');
$mform->setDefault('subject', $subject);
unset($options);
$mform->addHelpButton('subject', 'subject', 'block_community');
$this->init_javascript_enhancement('subject', 'smartselect',
Expand All @@ -202,16 +251,15 @@ public function definition() {
$options[$license->shortname] = get_string($license->shortname, 'license');
}
$mform->addElement('select', 'licence', get_string('licence', 'block_community'), $options);
$mform->setDefault('licence', 'cc');
unset($options);
$mform->addHelpButton('licence', 'licence', 'block_community');
$mform->setDefault('licence', 'all');
$mform->setDefault('licence', $licence);

$languages = get_string_manager()->get_list_of_languages();
textlib_get_instance()->asort($languages);
$languages = array_merge(array('all' => get_string('any')), $languages);
$mform->addElement('select', 'language', get_string('language'), $languages);
$mform->setDefault('language', 'all');
$mform->setDefault('language', $language);
$mform->addHelpButton('language', 'language', 'block_community');

$mform->addElement('radio', 'orderby', get_string('orderby', 'block_community'),
Expand All @@ -222,7 +270,7 @@ public function definition() {
get_string('orderbyname', 'block_community'), 'fullname');
$mform->addElement('radio', 'orderby', null,
get_string('orderbypublisher', 'block_community'), 'publisher');
$mform->setDefault('orderby', 'newest');
$mform->setDefault('orderby', $orderby);
$mform->setType('orderby', PARAM_ALPHA);

$mform->addElement('text', 'search', get_string('keywords', 'block_community'));
Expand Down
1 change: 1 addition & 0 deletions blocks/community/lang/en/block_community.php
Expand Up @@ -71,6 +71,7 @@
$string['licence_help'] = 'You can search for courses that are licensed in a particular way.';
$string['moredetails'] = 'More details';
$string['mycommunities'] = 'My communities:';
$string['next'] = 'Next >>>';
$string['nocomments'] = 'No comments';
$string['nocourse'] = 'No courses found';
$string['noratings'] = 'No ratings';
Expand Down
11 changes: 11 additions & 0 deletions blocks/community/renderer.php
Expand Up @@ -45,6 +45,17 @@ public function restore_confirmation_box($filename, $context) {
$formrestore, $formsearch);
}

/**
* The 'Next'/'more course result' link for a courses search
* @param array $data - the form parameter to execute the search on more result
* @return string html code
*/
public function next_button($data) {
$nextlink = html_writer::tag('a', get_string('next', 'block_community'),
array('href' => new moodle_url('', $data)));
return html_writer::tag('div', $nextlink, array( 'class' => 'nextlink'));
}

/**
* Display a list of courses
* @param array $courses
Expand Down
1 change: 1 addition & 0 deletions blocks/community/styles.css
Expand Up @@ -151,3 +151,4 @@
}
#page-blocks-community-communitycourse .hubrateandcomment { font-size: 80%;}
#page-blocks-community-communitycourse .hubcourseoutcomes {}
#page-blocks-community-communitycourse .nextlink {text-align: center;margin-top: 6px;}
3 changes: 2 additions & 1 deletion course/publish/forms.php
Expand Up @@ -125,7 +125,8 @@ public function definition() {
require_once($CFG->dirroot . "/webservice/xmlrpc/lib.php");
$xmlrpcclient = new webservice_xmlrpc_client($serverurl, $registeredhub->token);
try {
$publishedcourses = $xmlrpcclient->call($function, $params);
$result = $xmlrpcclient->call($function, $params);
$publishedcourses = $result['courses'];
} catch (Exception $e) {
$error = $OUTPUT->notification(get_string('errorcourseinfo', 'hub', $e->getMessage()));
$mform->addElement('static', 'errorhub', '', $error);
Expand Down
3 changes: 2 additions & 1 deletion course/publish/index.php
Expand Up @@ -74,7 +74,8 @@
$serverurl = $hub->huburl."/local/hub/webservice/webservices.php";
require_once($CFG->dirroot."/webservice/xmlrpc/lib.php");
$xmlrpcclient = new webservice_xmlrpc_client($serverurl, $hub->token);
$sitecourses = $xmlrpcclient->call($function, $params);
$result = $xmlrpcclient->call($function, $params);
$sitecourses = $result['courses'];

//update status for all these course
foreach ($sitecourses as $sitecourse) {
Expand Down

0 comments on commit c48ab36

Please sign in to comment.