Moved file manager to the image element

This commit is contained in:
Mark Nelson 2015-03-12 23:58:35 -07:00
parent 7739eefea1
commit 74003bf0bb
4 changed files with 37 additions and 22 deletions

View file

@ -158,9 +158,6 @@ $mform = new mod_customcert_edit_form('', array('customcertid' => $customcert->i
'course' => $course));
if ($data = $mform->get_data()) {
// Handle file uploads.
customcert_upload_imagefiles($data->customcertimage, context_course::instance($course->id)->id);
// Save any page data.
customcert_save_page_data($data);

View file

@ -62,7 +62,8 @@ $PAGE->set_heading($course->fullname);
$PAGE->set_title(get_string('editcustomcert', 'customcert', format_string($customcert->name)));
$PAGE->set_url($pageurl);
$mform = new mod_customcert_edit_element_form($pageurl, array('element' => $element, 'cmid' => $cmid, 'action' => $action));
$mform = new mod_customcert_edit_element_form($pageurl, array('element' => $element, 'course' => $course,
'cmid' => $cmid, 'action' => $action));
// Check if they cancelled.
if ($mform->is_cancelled()) {

View file

@ -41,11 +41,6 @@ class mod_customcert_edit_form extends moodleform {
*/
private $numpages = 1;
/**
* The filemanager options.
*/
private $filemanageroptions = array();
/**
* Form definition.
*/
@ -53,9 +48,6 @@ class mod_customcert_edit_form extends moodleform {
global $DB;
$this->id = $this->_customdata['customcertid'];
$this->filemanageroptions = array('maxbytes' => $this->_customdata['course']->maxbytes,
'subdirs' => 1,
'accepted_types' => 'image');
$mform =& $this->_form;
@ -71,10 +63,6 @@ class mod_customcert_edit_form extends moodleform {
$mform->addElement('submit', 'addcertpage', get_string('addcertpage', 'customcert'));
$mform->addElement('header', 'uploadimage', get_string('uploadimage', 'customcert'));
$mform->addElement('filemanager', 'customcertimage', get_string('uploadimage', 'customcert'), '', $this->filemanageroptions);
$mform->closeHeaderBefore('submitbtn');
// Add the submit buttons.
@ -99,12 +87,6 @@ class mod_customcert_edit_form extends moodleform {
$mform = $this->_form;
// Editing existing instance - copy existing files into draft area.
$draftitemid = file_get_submitted_draft_itemid('customcertimage');
file_prepare_draft_area($draftitemid, context_course::instance($this->_customdata['course']->id)->id, 'mod_customcert', 'image', 0, $this->filemanageroptions);
$element = $mform->getElement('customcertimage');
$element->setValue($draftitemid);
// Check that we are updating a current customcert.
if ($this->id) {
// Get the pages for this customcert.

View file

@ -33,6 +33,8 @@ class customcert_element_image extends customcert_element_base {
* @param mod_customcert_edit_element_form $mform the edit_form instance
*/
public function render_form_elements($mform) {
global $COURSE;
$mform->addElement('select', 'image', get_string('image', 'customcertelement_image'), self::get_images());
$mform->addElement('text', 'width', get_string('width', 'customcertelement_image'), array('size' => 10));
@ -46,6 +48,12 @@ class customcert_element_image extends customcert_element_base {
$mform->addHelpButton('height', 'height', 'customcertelement_image');
parent::render_form_element_position($mform);
$filemanageroptions = array('maxbytes' => $COURSE->maxbytes,
'subdirs' => 1,
'accepted_types' => 'image');
$mform->addElement('filemanager', 'customcertimage', get_string('uploadimage', 'customcert'), '', $filemanageroptions);
}
/**
@ -75,6 +83,21 @@ class customcert_element_image extends customcert_element_base {
return $errors;
}
/**
* Handles saving the form elements created by this element.
* Can be overridden if more functionality is needed.
*
* @param stdClass $data the form data
*/
public function save_form_elements($data) {
global $COURSE;
// Handle file uploads.
customcert_upload_imagefiles($data->customcertimage, context_course::instance($COURSE->id)->id);
parent::save_form_elements($data);
}
/**
* This will handle how form data will be saved into the data column in the
* customcert_elements table.
@ -126,12 +149,24 @@ class customcert_element_image extends customcert_element_base {
* @param mod_customcert_edit_element_form $mform the edit_form instance
*/
public function definition_after_data($mform) {
global $COURSE;
// Set the image, width and height for this element.
$imageinfo = json_decode($this->element->data);
$this->element->image = $imageinfo->pathnamehash;
$this->element->width = $imageinfo->width;
$this->element->height = $imageinfo->height;
// Editing existing instance - copy existing files into draft area.
$draftitemid = file_get_submitted_draft_itemid('customcertimage');
$filemanageroptions = array('maxbytes' => $COURSE->maxbytes,
'subdirs' => 1,
'accepted_types' => 'image');
file_prepare_draft_area($draftitemid, context_course::instance($COURSE->id)->id, 'mod_customcert', 'image', 0,
$filemanageroptions);
$element = $mform->getElement('customcertimage');
$element->setValue($draftitemid);
parent::definition_after_data($mform);
}