. /** * Community library * * @package block_community * @author Jerome Mouneyrac * @license http://www.gnu.org/copyleft/gpl.html GNU GPL * @copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com * * */ class block_community_manager { /** * Add a community course * @param object $course * @param integer $userid * @return id of course or false if already added */ public function block_community_add_course($course, $userid) { global $DB; $community = $this->block_community_get_course($course->url, $userid); if (empty($community)) { $community = new stdClass(); $community->userid = $userid; $community->coursename = $course->name; $community->coursedescription = $course->description; $community->courseurl = $course->url; $community->imageurl = $course->imageurl; return $DB->insert_record('block_community', $community); } else { return false; } } /** * Return all community courses of a user * @param integer $userid * @return array of course */ public function block_community_get_courses($userid) { global $DB; return $DB->get_records('block_community', array('userid' => $userid), 'coursename'); } /** * Return a community courses of a user * @param integer $userid * @param integer $userid * @return array of course */ public function block_community_get_course($courseurl, $userid) { global $DB; return $DB->get_record('block_community', array('courseurl' => $courseurl, 'userid' => $userid)); } /** * Delete a community course * @param integer $communityid * @param integer $userid * @return bool true */ public function block_community_remove_course($communityid, $userid) { global $DB, $USER; return $DB->delete_records('block_community', array('userid' => $userid, 'id' => $communityid)); } }