Moodle release 3.4.7
[moodle.git] / blocks / community / locallib.php
blobd97507835b122d3ee02dc024206fe43f2fa3b528
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
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.
8 //
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/>.
17 /**
18 * Community library
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 {
30 /**
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) {
37 global $DB;
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);
49 } else {
50 return false;
54 /**
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) {
60 global $DB;
61 return $DB->get_records('block_community', array('userid' => $userid), 'coursename');
64 /**
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) {
71 global $DB;
72 return $DB->get_record('block_community',
73 array('courseurl' => $courseurl, 'userid' => $userid));
76 /**
77 * Delete a community course
78 * @param integer $communityid
79 * @param integer $userid
80 * @return bool true
82 public function block_community_remove_course($communityid, $userid) {
83 global $DB, $USER;
84 return $DB->delete_records('block_community',
85 array('userid' => $userid, 'id' => $communityid));