Files
meetletacbfree/classes/local/instance.php
T

99 lines
3.1 KiB
PHP

<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Activity instance helpers.
*
* @package mod_meetletacbfree
* @copyright 2026 MeetLet
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_meetletacbfree\local;
use cm_info;
use context_module;
use moodle_exception;
use stdClass;
defined('MOODLE_INTERNAL') || die();
/**
* Load and resolve MeetLet instances.
*/
class instance {
/** @var stdClass */
public $record;
/** @var stdClass */
public $course;
/** @var cm_info|stdClass */
public $cm;
/** @var context_module */
public $context;
/** @var int */
public $groupid = 0;
/** @var stdClass|null */
public $meetingmap;
public static function get_from_cmid(int $cmid, int $groupid = 0): self {
list($course, $cm) = get_course_and_cm_from_cmid($cmid, 'meetletacbfree');
return self::from_cm($cm, $course, $groupid);
}
public static function get_from_instanceid(int $instanceid, int $groupid = 0): self {
list($course, $cm) = get_course_and_cm_from_instance($instanceid, 'meetletacbfree');
return self::from_cm($cm, $course, $groupid);
}
protected static function from_cm($cm, $course, int $groupid): self {
global $DB;
$inst = new self();
$inst->cm = $cm;
$inst->course = $course;
$inst->context = context_module::instance($cm->id);
$inst->record = $DB->get_record('meetletacbfree', ['id' => $cm->instance], '*', MUST_EXIST);
$inst->groupid = $groupid;
$inst->meetingmap = $DB->get_record('meetletacbfree_meetings', [
'instanceid' => $inst->record->id,
'groupid' => $groupid,
]);
if (!$inst->meetingmap && $groupid !== 0) {
// Fallback to no-group mapping.
$inst->meetingmap = $DB->get_record('meetletacbfree_meetings', [
'instanceid' => $inst->record->id,
'groupid' => 0,
]);
}
return $inst;
}
public function meetingscoid(): int {
return (int)($this->meetingmap->meetingscoid ?? 0);
}
public function require_meeting(): int {
$scoid = $this->meetingscoid();
if (!$scoid) {
throw new moodle_exception('nomeeting', 'meetletacbfree');
}
return $scoid;
}
public function auto_offline_enabled(): bool {
return config::auto_offline_enabled($this->record);
}
}