Community block MDL-19314 add prefix block_community_ to class and functions of block community
This commit is contained in:
@@ -24,8 +24,6 @@
|
||||
* The community block
|
||||
*/
|
||||
|
||||
require_once($CFG->dirroot . '/blocks/community/locallib.php');
|
||||
|
||||
class block_community extends block_list {
|
||||
function init() {
|
||||
$this->title = get_string('pluginname', 'block_community');
|
||||
@@ -55,8 +53,9 @@ class block_community extends block_list {
|
||||
'class' => 'icon', 'alt' => get_string('addcourse', 'block_community')));
|
||||
$this->content->icons[] = $icon;
|
||||
|
||||
$community = new community();
|
||||
$courses = $community->get_community_courses($USER->id);
|
||||
require_once($CFG->dirroot . '/blocks/community/locallib.php');
|
||||
$communitymanager = new block_community_manager();
|
||||
$courses = $communitymanager->block_community_get_courses($USER->id);
|
||||
if ($courses) {
|
||||
$this->content->items[] = html_writer::empty_tag('hr');
|
||||
$this->content->icons[] = '';
|
||||
|
||||
@@ -53,7 +53,7 @@ if (empty($usercansearch)) {
|
||||
die();
|
||||
}
|
||||
|
||||
$community = new community();
|
||||
$communitymanager = new block_community_manager();
|
||||
|
||||
/// Check if the page has been called with trust argument
|
||||
$add = optional_param('add', -1, PARAM_INTEGER);
|
||||
@@ -64,7 +64,7 @@ if ($add != -1 and $confirm and confirm_sesskey()) {
|
||||
$course->description = optional_param('coursedescription', '', PARAM_TEXT);
|
||||
$course->url = optional_param('courseurl', '', PARAM_URL);
|
||||
$course->imageurl = optional_param('courseimageurl', '', PARAM_URL);
|
||||
$community->add_community_course($course, $USER->id);
|
||||
$communitymanager->block_community_add_course($course, $USER->id);
|
||||
$notificationmessage = $OUTPUT->notification(get_string('addedtoblock', 'hub'),
|
||||
'notifysuccess');
|
||||
}
|
||||
@@ -79,7 +79,7 @@ if ($usercandownload and $download != -1 and !empty($courseid) and confirm_sessk
|
||||
$course->fullname = $coursefullname;
|
||||
$course->id = $courseid;
|
||||
$course->huburl = $huburl;
|
||||
$community->download_community_course_backup($course);
|
||||
$communitymanager->block_community_download_course_backup($course);
|
||||
$filename = 'backup_'.$course->fullname."_".$course->id.".zip";
|
||||
$notificationmessage = $OUTPUT->notification(get_string('downloadconfirmed', 'hub', $filename),
|
||||
'notifysuccess');
|
||||
@@ -89,7 +89,7 @@ if ($usercandownload and $download != -1 and !empty($courseid) and confirm_sessk
|
||||
$remove = optional_param('remove', '', PARAM_INTEGER);
|
||||
$communityid = optional_param('communityid', '', PARAM_INTEGER);
|
||||
if ($remove != -1 and !empty($communityid) and confirm_sesskey()) {
|
||||
$community->remove_community_course($communityid, $USER->id);
|
||||
$communitymanager->block_community_remove_course($communityid, $USER->id);
|
||||
$notificationmessage = $OUTPUT->notification(get_string('communityremoved', 'hub'),
|
||||
'notifysuccess');
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
* Community library
|
||||
*/
|
||||
|
||||
class community {
|
||||
class block_community_manager {
|
||||
|
||||
///////////////////////////
|
||||
/// DB Facade functions //
|
||||
@@ -36,10 +36,10 @@ class community {
|
||||
* @param integer $userid
|
||||
* @return id of course or false if already added
|
||||
*/
|
||||
public function add_community_course($course, $userid) {
|
||||
public function block_community_add_course($course, $userid) {
|
||||
global $DB;
|
||||
|
||||
$community = $this->get_community_course($course->url, $userid);
|
||||
$community = $this->block_community_get_course($course->url, $userid);
|
||||
|
||||
if (empty($community)) {
|
||||
$community->userid = $userid;
|
||||
@@ -58,7 +58,7 @@ class community {
|
||||
* @param integer $userid
|
||||
* @return array of course
|
||||
*/
|
||||
public function get_community_courses($userid) {
|
||||
public function block_community_get_courses($userid) {
|
||||
global $DB;
|
||||
return $DB->get_records('block_community', array('userid' => $userid), 'coursename');
|
||||
}
|
||||
@@ -69,7 +69,7 @@ class community {
|
||||
* @param integer $userid
|
||||
* @return array of course
|
||||
*/
|
||||
public function get_community_course($courseurl, $userid) {
|
||||
public function block_community_get_course($courseurl, $userid) {
|
||||
global $DB;
|
||||
return $DB->get_record('block_community', array('courseurl' => $courseurl, 'userid' => $userid));
|
||||
}
|
||||
@@ -79,7 +79,7 @@ class community {
|
||||
* @param integer $courseid
|
||||
* @param string $huburl
|
||||
*/
|
||||
public function download_community_course_backup($course) {
|
||||
public function block_community_download_course_backup($course) {
|
||||
global $CFG, $USER;
|
||||
require_once($CFG->dirroot. "/lib/filelib.php");
|
||||
require_once($CFG->dirroot. "/lib/hublib.php");
|
||||
@@ -121,31 +121,9 @@ class community {
|
||||
* @param integer $userid
|
||||
* @return bool true
|
||||
*/
|
||||
public function remove_community_course($communityid, $userid) {
|
||||
public function block_community_remove_course($communityid, $userid) {
|
||||
global $DB, $USER;
|
||||
return $DB->delete_records('block_community', array('userid' => $userid, 'id' => $communityid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Decide where to save the file, can be
|
||||
* reused by sub class
|
||||
* @param string filename
|
||||
*/
|
||||
public function prepare_file($filename) {
|
||||
global $CFG;
|
||||
if (!file_exists($CFG->dataroot.'/temp/download')) {
|
||||
mkdir($CFG->dataroot.'/temp/download/', 0777, true);
|
||||
}
|
||||
if (is_dir($CFG->dataroot.'/temp/download')) {
|
||||
$dir = $CFG->dataroot.'/temp/download/';
|
||||
}
|
||||
if (empty($filename)) {
|
||||
$filename = uniqid('repo').'_'.time().'.tmp';
|
||||
}
|
||||
if (file_exists($dir.$filename)) {
|
||||
$filename = uniqid('m').$filename;
|
||||
}
|
||||
return $dir.$filename;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user