Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/grade/grading/manage.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00031 require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
00032 require_once($CFG->dirroot.'/grade/grading/lib.php');
00033 
00034 // identify gradable area by its id
00035 $areaid     = optional_param('areaid', null, PARAM_INT);
00036 // alternatively the context, component and areaname must be provided
00037 $contextid  = optional_param('contextid', null, PARAM_INT);
00038 $component  = optional_param('component', null, PARAM_COMPONENT);
00039 $area       = optional_param('area', null, PARAM_AREA);
00040 // keep the caller's URL so that we know where to send the user finally
00041 $returnurl  = optional_param('returnurl', null, PARAM_LOCALURL);
00042 // active method selector
00043 $setmethod  = optional_param('setmethod', null, PARAM_PLUGIN);
00044 // publish the given form definition as a new template in the forms bank
00045 $shareform  = optional_param('shareform', null, PARAM_INT);
00046 // delete the given form definition
00047 $deleteform = optional_param('deleteform', null, PARAM_INT);
00048 // consider the required action as confirmed
00049 $confirmed  = optional_param('confirmed', false, PARAM_BOOL);
00050 // a message to display, typically a previous action's result
00051 $message    = optional_param('message', null, PARAM_NOTAGS);
00052 
00053 if (!is_null($areaid)) {
00054     // get manager by id
00055     $manager = get_grading_manager($areaid);
00056 } else {
00057     // get manager by context and component
00058     if (is_null($contextid) or is_null($component) or is_null($area)) {
00059         throw new coding_exception('The caller script must identify the gradable area.');
00060     }
00061     $context = get_context_instance_by_id($contextid, MUST_EXIST);
00062     $manager = get_grading_manager($context, $component, $area);
00063 }
00064 
00065 if ($manager->get_context()->contextlevel < CONTEXT_COURSE) {
00066     throw new coding_exception('Unsupported gradable area context level');
00067 }
00068 
00069 // get the currently active method
00070 $method = $manager->get_active_method();
00071 
00072 list($context, $course, $cm) = get_context_info_array($manager->get_context()->id);
00073 
00074 require_login($course, true, $cm);
00075 require_capability('moodle/grade:managegradingforms', $context);
00076 
00077 if (!empty($returnurl)) {
00078     $returnurl = new moodle_url($returnurl);
00079 } else {
00080     $returnurl = null;
00081 }
00082 
00083 $PAGE->set_url($manager->get_management_url($returnurl));
00084 navigation_node::override_active_url($manager->get_management_url());
00085 $PAGE->set_title(get_string('gradingmanagement', 'core_grading'));
00086 $PAGE->set_heading(get_string('gradingmanagement', 'core_grading'));
00087 $output = $PAGE->get_renderer('core_grading');
00088 
00089 // process the eventual change of the active grading method
00090 if (!empty($setmethod)) {
00091     require_sesskey();
00092     if ($setmethod == 'none') {
00093         // here we expect that noone would actually want to call their plugin as 'none'
00094         $setmethod = null;
00095     }
00096     $manager->set_active_method($setmethod);
00097     redirect($PAGE->url);
00098 }
00099 
00100 // publish the form as a template
00101 if (!empty($shareform)) {
00102     require_capability('moodle/grade:sharegradingforms', context_system::instance());
00103     $controller = $manager->get_controller($method);
00104     $definition = $controller->get_definition();
00105     if (!$confirmed) {
00106         // let the user confirm they understand what they are doing (haha ;-)
00107         echo $output->header();
00108         echo $output->confirm(get_string('manageactionshareconfirm', 'core_grading', s($definition->name)),
00109             new moodle_url($PAGE->url, array('shareform' => $shareform, 'confirmed' => 1)),
00110             $PAGE->url);
00111         echo $output->footer();
00112         die();
00113     } else {
00114         require_sesskey();
00115         $newareaid = $manager->create_shared_area($method);
00116         $targetarea = get_grading_manager($newareaid);
00117         $targetcontroller = $targetarea->get_controller($method);
00118         $targetcontroller->update_definition($controller->get_definition_copy($targetcontroller));
00119         $DB->set_field('grading_definitions', 'timecopied', time(), array('id' => $definition->id));
00120         redirect(new moodle_url($PAGE->url, array('message' => get_string('manageactionsharedone', 'core_grading'))));
00121     }
00122 }
00123 
00124 // delete the form definition
00125 if (!empty($deleteform)) {
00126     $controller = $manager->get_controller($method);
00127     $definition = $controller->get_definition();
00128     if (!$confirmed) {
00129         // let the user confirm they understand the consequences (also known as WTF-effect)
00130         echo $output->header();
00131         echo $output->confirm(markdown_to_html(get_string('manageactiondeleteconfirm', 'core_grading', array(
00132             'formname'  => s($definition->name),
00133             'component' => $manager->get_component_title(),
00134             'area'      => $manager->get_area_title()))),
00135             new moodle_url($PAGE->url, array('deleteform' => $deleteform, 'confirmed' => 1)), $PAGE->url);
00136         echo $output->footer();
00137         die();
00138     } else {
00139         require_sesskey();
00140         $controller->delete_definition();
00141         redirect(new moodle_url($PAGE->url, array('message' => get_string('manageactiondeletedone', 'core_grading'))));
00142     }
00143 }
00144 
00145 echo $output->header();
00146 
00147 if (!empty($message)) {
00148     echo $output->management_message($message);
00149 }
00150 
00151 echo $output->heading(get_string('gradingmanagementtitle', 'core_grading', array(
00152     'component' => $manager->get_component_title(), 'area' => $manager->get_area_title())));
00153 
00154 // display the active grading method information and selector
00155 echo $output->management_method_selector($manager, $PAGE->url);
00156 
00157 // get the currently active method's controller
00158 if (!empty($method)) {
00159     $controller = $manager->get_controller($method);
00160     // display relevant actions
00161     echo $output->container_start('actions');
00162     if ($controller->is_form_defined()) {
00163         $definition = $controller->get_definition();
00164         // icon to edit the form definition
00165         echo $output->management_action_icon($controller->get_editor_url($returnurl),
00166             get_string('manageactionedit', 'core_grading'), 'b/document-edit');
00167         // icon to delete the current form definition
00168         echo $output->management_action_icon(new moodle_url($PAGE->url, array('deleteform' => $definition->id)),
00169             get_string('manageactiondelete', 'core_grading'), 'b/edit-delete');
00170         // icon to save the form as a new template
00171         if (has_capability('moodle/grade:sharegradingforms', context_system::instance())) {
00172             if (empty($definition->copiedfromid)) {
00173                 $hasoriginal = false;
00174             } else {
00175                 $hasoriginal = $DB->record_exists('grading_definitions', array('id' => $definition->copiedfromid));
00176             }
00177             if (!$controller->is_form_available()) {
00178                 // drafts can not be shared
00179                 $allowshare = false;
00180             } else if (!$hasoriginal) {
00181                 // was created from scratch or is orphaned
00182                 if (empty($definition->timecopied)) {
00183                     // was never shared before
00184                     $allowshare = true;
00185                 } else if ($definition->timemodified > $definition->timecopied) {
00186                     // was modified since last time shared
00187                     $allowshare = true;
00188                 } else {
00189                     // was not modified since last time shared
00190                     $allowshare = false;
00191                 }
00192             } else {
00193                 // was created from a template and the template still exists
00194                 if ($definition->timecreated == $definition->timemodified) {
00195                     // was not modified since created
00196                     $allowshare = false;
00197                 } else if (empty($definition->timecopied)) {
00198                     // was modified but was not re-shared yet
00199                     $allowshare = true;
00200                 } else if ($definition->timemodified > $definition->timecopied) {
00201                     // was modified since last time re-shared
00202                     $allowshare = true;
00203                 } else {
00204                     // was not modified since last time re-shared
00205                     $allowshare = false;
00206                 }
00207             }
00208             if ($allowshare) {
00209                 echo $output->management_action_icon(new moodle_url($PAGE->url, array('shareform' => $definition->id)),
00210                     get_string('manageactionshare', 'core_grading'), 'b/bookmark-new');
00211             }
00212         }
00213     } else {
00214         echo $output->management_action_icon($controller->get_editor_url($returnurl),
00215             get_string('manageactionnew', 'core_grading'), 'b/document-new');
00216         $pickurl = new moodle_url('/grade/grading/pick.php', array('targetid' => $controller->get_areaid()));
00217         if (!is_null($returnurl)) {
00218             $pickurl->param('returnurl', $returnurl->out(false));
00219         }
00220         echo $output->management_action_icon($pickurl,
00221             get_string('manageactionclone', 'core_grading'), 'b/edit-copy');
00222     }
00223     echo $output->container_end();
00224 
00225     // display the message if the form is currently not available (if applicable)
00226     if ($message = $controller->form_unavailable_notification()) {
00227         echo $output->notification($message);
00228     }
00229     // display the grading form preview
00230     if ($controller->is_form_defined()) {
00231         if ($definition->status == gradingform_controller::DEFINITION_STATUS_READY) {
00232             $tag = html_writer::tag('span', get_string('statusready', 'core_grading'), array('class' => 'status ready'));
00233         } else {
00234             $tag = html_writer::tag('span', get_string('statusdraft', 'core_grading'), array('class' => 'status draft'));
00235         }
00236         echo $output->heading(s($definition->name) . ' ' . $tag, 3, 'definition-name');
00237         echo $output->box($controller->get_formatted_description());
00238         echo $output->box($controller->render_preview($PAGE), 'definition-preview');
00239     }
00240 }
00241 
00242 
00243 echo $output->footer();
 All Data Structures Namespaces Files Functions Variables Enumerations