. /** * Activity instance helpers. * * @package mod_meetletacbmarketplace * @copyright 2026 MeetLet * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace mod_meetletacbmarketplace\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, 'meetletacbmarketplace'); 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, 'meetletacbmarketplace'); 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('meetletacbmarketplace', ['id' => $cm->instance], '*', MUST_EXIST); $inst->groupid = $groupid; $inst->meetingmap = $DB->get_record('meetlet_marketplace_meetings', [ 'instanceid' => $inst->record->id, 'groupid' => $groupid, ]); if (!$inst->meetingmap && $groupid !== 0) { // Fallback to no-group mapping. $inst->meetingmap = $DB->get_record('meetlet_marketplace_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', 'meetletacbmarketplace'); } return $scoid; } public function auto_offline_enabled(): bool { return config::auto_offline_enabled($this->record); } }