/**
* Content bank constructor
*
- * @param stdClass $content A contentbanck_content record.
+ * @param stdClass $record A contentbank_content record.
* @throws coding_exception If content type is not right.
*/
- public function __construct(stdClass $content) {
+ public function __construct(stdClass $record) {
// Content type should exist and be linked to plugin classname.
- $classname = $content->contenttype.'\\content';
+ $classname = $record->contenttype.'\\content';
if (get_class($this) != $classname) {
- throw new coding_exception(get_string('contenttypenotfound', 'error', $content->contenttype));
+ throw new coding_exception(get_string('contenttypenotfound', 'error', $record->contenttype));
}
- $typeclass = $content->contenttype.'\\contenttype';
+ $typeclass = $record->contenttype.'\\contenttype';
if (!class_exists($typeclass)) {
- throw new coding_exception(get_string('contenttypenotfound', 'error', $content->contenttype));
+ throw new coding_exception(get_string('contenttypenotfound', 'error', $record->contenttype));
}
// A record with the id must exist in 'contenbank_content' table.
// To improve performance, we are only checking the id is set, but no querying the database.
- if (!isset($content->id)) {
+ if (!isset($record->id)) {
throw new coding_exception(get_string('invalidcontentid', 'error'));
}
- $this->content = $content;
+ $this->content = $record;
}
/**
/**
* Fills content_bank table with appropiate information.
*
- * @param stdClass $content An optional content record compatible object (default null)
- * @return content Object with content bank information.
+ * @param stdClass $record An optional content record compatible object (default null)
+ * @return content Object with content bank information.
*/
- public function create_content(\stdClass $content = null): ?content {
+ public function create_content(\stdClass $record = null): ?content {
global $USER, $DB;
- $record = new \stdClass();
- $record->contenttype = $this->get_contenttype_name();
- $record->contextid = $this->context->id;
- $record->name = $content->name ?? '';
- $record->usercreated = $content->usercreated ?? $USER->id;
- $record->timecreated = time();
- $record->usermodified = $record->usercreated;
- $record->timemodified = $record->timecreated;
- $record->configdata = $content->configdata ?? '';
- $record->id = $DB->insert_record('contentbank_content', $record);
- if ($record->id) {
- $classname = '\\'.$record->contenttype.'\\content';
- return new $classname($record);
+ $entry = new \stdClass();
+ $entry->contenttype = $this->get_contenttype_name();
+ $entry->contextid = $this->context->id;
+ $entry->name = $record->name ?? '';
+ $entry->usercreated = $record->usercreated ?? $USER->id;
+ $entry->timecreated = time();
+ $entry->usermodified = $entry->usercreated;
+ $entry->timemodified = $entry->timecreated;
+ $entry->configdata = $record->configdata ?? '';
+ $entry->id = $DB->insert_record('contentbank_content', $entry);
+ if ($entry->id) {
+ $classname = '\\'.$entry->contenttype.'\\content';
+ return new $classname($entry);
}
return null;
}
/**
* Returns the URL where the content will be visualized.
*
- * @param stdClass $record Th content to be displayed.
- * @return string URL where to visualize the given content.
+ * @param stdClass $record The content to be displayed.
+ * @return string URL where to visualize the given content.
*/
public function get_view_url(\stdClass $record): string {
return new moodle_url('/contentbank/view.php', ['id' => $record->id]);
/**
* Returns the HTML content to add to view.php visualizer.
*
- * @param stdClass $record Th content to be displayed.
- * @return string HTML code to include in view.php.
+ * @param stdClass $record The content to be displayed.
+ * @return string HTML code to include in view.php.
*/
public function get_view_content(\stdClass $record): string {
// Main contenttype class can visualize the content, but plugins could overwrite visualization.