redirect(new moodle_url('/mod/mediagallery/view.php', array('g' => $gallery->id, 'editing' => 1))); } else { if ($data = $mform->get_data()) { if ($bulk) { $draftid = file_get_submitted_draft_itemid('content'); $files = $fs->get_area_files(context_user::instance($USER->id)->id, 'user', 'draft', $draftid, 'id DESC', false); $storedfile = reset($files); \mod_mediagallery\item::create_from_archive($gallery, $storedfile, $data); } else { $data->description = $data->description['text']; $data->galleryid = $gallery->id; if (!empty($data->id)) { $item = new \mod_mediagallery\item($data->id); $item->update($data); } else { $item = \mod_mediagallery\item::create($data); } if (!empty($data->content)) { $info = file_get_draft_area_info($data->content); file_save_draft_area_files($data->content, $context->id, 'mod_mediagallery', 'item', $item->id, $fmoptions); $storedfile = null; if ($gallery->galleryfocus != \mod_mediagallery\base::TYPE_IMAGE && $gallery->mode != 'thebox') { $draftid = file_get_submitted_draft_itemid('customthumbnail'); if ($files = $fs->get_area_files(context_user::instance($USER->id)->id, 'user', 'draft', $draftid, 'id DESC', false)) { $storedfile = reset($files); } } if ($gallery->mode != 'thebox') { $item->generate_image_by_type('lowres', false, $storedfile); $item->generate_image_by_type('thumbnail', false, $storedfile); }
public function create_item($record = null) { global $CFG, $USER; $record = (object) (array) $record; $defaults = array('caption' => '', 'userid' => $USER->id, 'tags' => ''); if (!isset($record->galleryid)) { throw new coding_exception('galleryid must be present in $record'); } foreach ($defaults as $key => $value) { if (!isset($record->{$key})) { $record->{$key} = $value; } } return \mod_mediagallery\item::create($record); }