2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
20 * @package block_community
21 * @author Jerome Mouneyrac <jerome@mouneyrac.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL
23 * @copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com
28 class block_community_manager
{
31 * Add a community course
32 * @param object $course
33 * @param integer $userid
34 * @return id of course or false if already added
36 public function block_community_add_course($course, $userid) {
39 $community = $this->block_community_get_course($course->url
, $userid);
41 if (empty($community)) {
42 $community = new stdClass();
43 $community->userid
= $userid;
44 $community->coursename
= $course->name
;
45 $community->coursedescription
= $course->description
;
46 $community->courseurl
= $course->url
;
47 $community->imageurl
= $course->imageurl
;
48 return $DB->insert_record('block_community', $community);
55 * Return all community courses of a user
56 * @param integer $userid
57 * @return array of course
59 public function block_community_get_courses($userid) {
61 return $DB->get_records('block_community', array('userid' => $userid), 'coursename');
65 * Return a community courses of a user
66 * @param integer $userid
67 * @param integer $userid
68 * @return array of course
70 public function block_community_get_course($courseurl, $userid) {
72 return $DB->get_record('block_community',
73 array('courseurl' => $courseurl, 'userid' => $userid));
77 * Delete a community course
78 * @param integer $communityid
79 * @param integer $userid
82 public function block_community_remove_course($communityid, $userid) {
84 return $DB->delete_records('block_community',
85 array('userid' => $userid, 'id' => $communityid));