PageRenderTime 50ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/mod/folder/mod_form.php

https://bitbucket.org/synergylearning/campusconnect
PHP | 103 lines | 57 code | 15 blank | 31 comment | 8 complexity | cb9dfb419e05fa8568830f13a33dee93 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, LGPL-2.1, Apache-2.0, BSD-3-Clause, AGPL-3.0
  1. <?php
  2. // This file is part of Moodle - http://moodle.org/
  3. //
  4. // Moodle is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // Moodle is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * Folder configuration form
  18. *
  19. * @package mod
  20. * @subpackage folder
  21. * @copyright 2009 Petr Skoda {@link http://skodak.org}
  22. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23. */
  24. defined('MOODLE_INTERNAL') || die();
  25. require_once ($CFG->dirroot.'/course/moodleform_mod.php');
  26. class mod_folder_mod_form extends moodleform_mod {
  27. function definition() {
  28. global $CFG;
  29. $mform = $this->_form;
  30. $config = get_config('folder');
  31. //-------------------------------------------------------
  32. $mform->addElement('header', 'general', get_string('general', 'form'));
  33. $mform->addElement('text', 'name', get_string('name'), array('size'=>'48'));
  34. if (!empty($CFG->formatstringstriptags)) {
  35. $mform->setType('name', PARAM_TEXT);
  36. } else {
  37. $mform->setType('name', PARAM_CLEANHTML);
  38. }
  39. $mform->addRule('name', null, 'required', null, 'client');
  40. $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
  41. $this->add_intro_editor($config->requiremodintro);
  42. //-------------------------------------------------------
  43. $mform->addElement('header', 'content', get_string('contentheader', 'folder'));
  44. $mform->addElement('filemanager', 'files', get_string('files'), null, array('subdirs'=>1, 'accepted_types'=>'*'));
  45. $mform->addElement('select', 'display', get_string('display', 'mod_folder'),
  46. array(FOLDER_DISPLAY_PAGE => get_string('displaypage', 'mod_folder'),
  47. FOLDER_DISPLAY_INLINE => get_string('displayinline', 'mod_folder')));
  48. $mform->addHelpButton('display', 'display', 'mod_folder');
  49. if (!$this->courseformat->has_view_page()) {
  50. $mform->setConstant('display', FOLDER_DISPLAY_PAGE);
  51. $mform->hardFreeze('display');
  52. }
  53. $mform->setExpanded('content');
  54. // Adding option to show sub-folders expanded or collapsed by default.
  55. $mform->addElement('advcheckbox', 'showexpanded', get_string('showexpanded', 'folder'));
  56. $mform->addHelpButton('showexpanded', 'showexpanded', 'mod_folder');
  57. $mform->setDefault('showexpanded', $config->showexpanded);
  58. //-------------------------------------------------------
  59. $this->standard_coursemodule_elements();
  60. //-------------------------------------------------------
  61. $this->add_action_buttons();
  62. //-------------------------------------------------------
  63. $mform->addElement('hidden', 'revision');
  64. $mform->setType('revision', PARAM_INT);
  65. $mform->setDefault('revision', 1);
  66. }
  67. function data_preprocessing(&$default_values) {
  68. if ($this->current->instance) {
  69. // editing existing instance - copy existing files into draft area
  70. $draftitemid = file_get_submitted_draft_itemid('files');
  71. file_prepare_draft_area($draftitemid, $this->context->id, 'mod_folder', 'content', 0, array('subdirs'=>true));
  72. $default_values['files'] = $draftitemid;
  73. }
  74. }
  75. function validation($data, $files) {
  76. $errors = parent::validation($data, $files);
  77. // Completion: Automatic on-view completion can not work together with
  78. // "display inline" option
  79. if (empty($errors['completion']) &&
  80. array_key_exists('completion', $data) &&
  81. $data['completion'] == COMPLETION_TRACKING_AUTOMATIC &&
  82. !empty($data['completionview']) &&
  83. $data['display'] == FOLDER_DISPLAY_INLINE) {
  84. $errors['completion'] = get_string('noautocompletioninline', 'mod_folder');
  85. }
  86. return $errors;
  87. }
  88. }