Added capabilities
[moodle.git] / mod / workshop / locallib.php
CommitLineData
de811c0c
DM
1<?php
2
3// This file is part of Moodle - http://moodle.org/
4//
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17
18
19/**
20 * Library of internal functions for module workshop
21 *
22 * All the workshop specific functions, needed to implement the module
23 * logic, should go to here.
24 *
25 * @package mod-workshop
26 * @copyright 2009 David Mudrak <david.mudrak@gmail.com>
27 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 */
29
30defined('MOODLE_INTERNAL') || die();
31
0968b1a3
DM
32function workshop_strategy_instance($workshop) {
33 /** static variable to hold the singleton */
34 static $instance = null;
35
36 if (is_null($instance)) {
37 $strategylib = dirname(__FILE__) . '/grading/' . $workshop->strategy . '/strategy.php';
38 if (is_readable($strategylib)) {
39 require_once($strategylib);
40 } else {
41 throw new moodle_exception('missingstrategy', 'workshop');
42 }
43 $classname = 'workshop_' . $workshop->strategy . '_strategy';
44 $instance = new $classname($workshop);
45 }
46
47 return $instance;
48}
49
50
de811c0c
DM
51/**
52 * Return the user's submission record in the given workshop
53 *
54 * Example submissions are not returned. This is intended to return a submission for given
55 * student.
56 *
57 * @param int $workshopid Workshop id
58 * @param int $userid Owner id
59 * @return mixed A fieldset object containing the first matching record or false if not found
60 */
61function workshop_get_user_submission($workshopid, $userid) {
62 global $DB;
63
64 return $DB->get_record('workshop_submissions', array('workshopid' => $workshopid, 'userid' => $userid, 'example' => 0));
65}
66
67