Exemplo n.º 1
0
 /**
  * Add appropriate form elements to the critieria form
  *
  * @param moodle_form $mform Moodle forms object
  * @param stdClass $data data used to define default value of the form
  */
 public function config_form_display(&$mform, $data = null)
 {
     global $CFG;
     $link = "<a href=\"{$CFG->wwwroot}/course/view.php?id={$data->id}\">" . s($data->fullname) . '</a>';
     $mform->addElement('checkbox', 'criteria_course[' . $data->id . ']', $link);
     if ($this->id) {
         $mform->setDefault('criteria_course[' . $data->id . ']', 1);
     }
 }
 /**
  * Defines fields to add to the settings form
  *
  * @param moodle_form $mform
  */
 protected function specific_definition($mform)
 {
     $mform->addElement('header', 'configheader', get_string('blocksettings', 'core_block'));
     $mform->addElement('text', 'config_blocktitle', get_string('config_blocktitle', 'block_course_contents'));
     $mform->setDefault('config_blocktitle', '');
     $mform->setType('config_blocktitle', PARAM_MULTILANG);
     $mform->addHelpButton('config_blocktitle', 'config_blocktitle', 'block_course_contents');
     $mform->addElement('advcheckbox', 'config_enumerate', get_string('config_enumerate', 'block_course_contents'), get_string('config_enumerate_label', 'block_course_contents'));
     $mform->setDefault('config_enumerate', 1);
     $mform->setType('config_enumerate', PARAM_BOOL);
 }
 /**
  * Add appropriate form elements to the critieria form
  *
  * @param moodle_form $mform Moodle forms object
  * @param stdClass $data containing default values to be set in the form
  */
 public function config_form_display(&$mform, $data = null)
 {
     $mform->addElement('checkbox', 'criteria_grade', get_string('enable'));
     $mform->addElement('text', 'criteria_grade_value', get_string('graderequired', 'completion'));
     $mform->disabledIf('criteria_grade_value', 'criteria_grade');
     $mform->setType('criteria_grade_value', PARAM_RAW);
     // Uses unformat_float.
     $mform->setDefault('criteria_grade_value', format_float($data));
     if ($this->id) {
         $mform->setDefault('criteria_grade', 1);
         $mform->setDefault('criteria_grade_value', format_float($this->gradepass));
     }
 }
Exemplo n.º 4
0
 /**
  * Add appropriate form elements to the critieria form
  *
  * @param moodle_form $mform Moodle forms object
  * @param stdClass $data containing default values to be set in the form
  */
 public function config_form_display(&$mform, $data = null)
 {
     $mform->addElement('checkbox', 'criteria_grade', get_string('enable'));
     $mform->addElement('text', 'criteria_grade_value', get_string('graderequired', 'completion'));
     $mform->setDefault('criteria_grade_value', $data);
     $mform->addElement('static', 'criteria_grade_value_note', '', get_string('criteriagradenote', 'completion'));
     if ($this->id) {
         $mform->setDefault('criteria_grade', 1);
         $mform->setDefault('criteria_grade_value', $this->gradepass);
     }
 }
Exemplo n.º 5
0
 /**
  * Add appropriate form elements to the critieria form
  *
  * @param moodle_form $mform Moodle forms object
  * @param stdClass $data containing default values to be set in the form
  */
 public function config_form_display(&$mform, $data = null)
 {
     $mform->addElement('checkbox', 'criteria_grade', get_string('enable'));
     $mform->addElement('text', 'criteria_grade_value', get_string('graderequired', 'completion'));
     $mform->disabledIf('criteria_grade_value', 'criteria_grade');
     $mform->setType('criteria_grade_value', PARAM_RAW);
     // Uses unformat_float.
     // Grades are stored in Moodle with 5 decimal points, make sure we do not accidentally round them
     // when setting the form value.
     $mform->setDefault('criteria_grade_value', format_float($data, 5));
     if ($this->id) {
         $mform->setDefault('criteria_grade', 1);
         $mform->setDefault('criteria_grade_value', format_float($this->gradepass, 5));
     }
 }
 /**
  * Print the section which contains the post form (i. e. section number 2)
  * 
  * @global object $this->output
  * @param object $course
  * @param object $sectioninfo
  * @param moodle_form $postform
  * @param int id of post when editing a post (0 for new post)
  */
 protected function print_postform_section($course, $sectioninfo, $postform, $postid)
 {
     global $USER;
     $o = '';
     // ... usually this is section 2, because activities on time line are required to be in section 1.
     if (isset($sectioninfo[FORMAT_SOCIALWALL_POSTFORMSECTION])) {
         $thissection = $sectioninfo[FORMAT_SOCIALWALL_POSTFORMSECTION];
         $o .= html_writer::start_tag('li', array('id' => 'section-' . $thissection->section, 'class' => 'section main clearfix', 'role' => 'region', 'aria-label' => get_section_name($course, $thissection)));
         $o .= html_writer::start_tag('div', array('class' => 'content'));
         $url = new moodle_url('/course/format/socialwall/pages/editnotification.php', array('courseid' => $course->id));
         $linktext = $this->output->pix_icon('i/settings', get_string('editnotification', 'format_socialwall')) . " " . get_string('editnotification', 'format_socialwall');
         $linkparams = array('class' => 'pf-notificationsetting', 'id' => 'pfnotificationsetting_' . $course->id);
         $o .= html_writer::link($url, $linktext, $linkparams);
         $o .= html_writer::tag('div', '', array('class' => 'clearfix'));
         $o .= $postform->render();
         // Render prepared attaches section.
         if ($USER->editing) {
             $o .= html_writer::tag('div', '', array('class' => 'clearfix'));
             $thissection = $sectioninfo[FORMAT_SOCIALWALL_POSTFORMSECTION];
             $o .= html_writer::start_div('attachactivies');
             $o .= get_string('attachactivities', 'format_socialwall');
             if (!empty($thissection->sequence)) {
                 $o .= html_writer::empty_tag('br') . get_string('attachedactivities', 'format_socialwall');
             }
             $o .= $this->courserenderer->course_section_cm_list($course, $thissection, 0);
             $o .= $this->courserenderer->course_section_add_cm_control($course, FORMAT_SOCIALWALL_POSTFORMSECTION, 0);
             $o .= html_writer::end_div();
         }
         // Render the recent attaches section, when user is editing or updating;
         if ($USER->editing or $postid > 0) {
             $content = '';
             // Check, whether there are recent activities attached.
             $cache = cache::make('format_socialwall', 'attachedrecentactivities');
             if (!($attachedrecentactivities = $cache->get($course->id . '_' . $postid))) {
                 $attachedrecentactivities = array();
             }
             // Add recent postform list is necessary as a target for js popup dialog, even there are no recentactivities.
             $content .= $this->render_postform_recent_activities($course, $postid, $attachedrecentactivities);
             if ($USER->editing) {
                 $l = $this->output->pix_icon('t/add', get_string('addrecentactivity', 'format_socialwall'));
                 $l .= " " . get_string('addrecentactivity', 'format_socialwall');
                 $c = html_writer::tag('span', $l, array('id' => 'tl-addrecentactivity-text'));
                 $c .= html_writer::link('#', '', array('style' => 'display:none', 'id' => 'tl-addrecentactivity-link'));
                 $content .= html_writer::tag('div', $c, array('id' => 'tl-addrecentactitity-wrapper'));
             }
             if ($USER->editing or count($attachedrecentactivities) > 0) {
                 // Show attached existing activities here.
                 $content = get_string('attachedrecentactivities', 'format_socialwall') . $content;
                 $o .= html_writer::tag('div', $content, array('class' => 'attachactivies'));
             }
         }
         $o .= $this->section_footer();
     }
     if ($USER->editing) {
         $o .= html_writer::tag('div', $this->render_postform_recent_activities_form($course, $postid), array('style' => 'display:none'));
     }
     echo $o;
 }
Exemplo n.º 7
0
/**
 * Set secondary fields (i.e. fields derived from the form fields)
 * for this HotPot acitivity
 *
 * @param stdclass $data (passed by reference)
 * @param moodle_form $mform
 */
function hotpot_process_formdata(stdclass &$data, $mform)
{
    global $CFG;
    require_once $CFG->dirroot . '/mod/hotpot/locallib.php';
    if ($mform->is_add()) {
        $data->timecreated = time();
    } else {
        $data->timemodified = time();
    }
    // get context for this HotPot instance
    $context = hotpot_get_context(CONTEXT_MODULE, $data->coursemodule);
    $sourcefile = null;
    $data->sourcefile = '';
    $data->sourcetype = '';
    if ($data->sourceitemid) {
        $options = hotpot::sourcefile_options();
        file_save_draft_area_files($data->sourceitemid, $context->id, 'mod_hotpot', 'sourcefile', 0, $options);
        $fs = get_file_storage();
        $files = $fs->get_area_files($context->id, 'mod_hotpot', 'sourcefile');
        // do we need to remove the draft files ?
        // otherwise the "files" table seems to get full of "draft" records
        // $fs->delete_area_files($context->id, 'user', 'draft', $data->sourceitemid);
        foreach ($files as $hash => $file) {
            if ($file->get_sortorder() == 1) {
                $data->sourcefile = $file->get_filepath() . $file->get_filename();
                $data->sourcetype = hotpot::get_sourcetype($file);
                $sourcefile = $file;
                break;
            }
        }
        unset($fs, $files, $file, $hash, $options);
    }
    if (is_null($sourcefile) || $data->sourcefile == '' || $data->sourcetype == '') {
        // sourcefile was missing or not a recognized type - shouldn't happen !!
    }
    // process text fields that may come from source file
    $source = false;
    $textfields = array('name', 'entrytext', 'exittext');
    foreach ($textfields as $textfield) {
        $textsource = $textfield . 'source';
        if (!isset($data->{$textsource})) {
            $data->{$textsource} = hotpot::TEXTSOURCE_SPECIFIC;
        }
        switch ($data->{$textsource}) {
            case hotpot::TEXTSOURCE_FILE:
                if ($data->sourcetype && $sourcefile && empty($source)) {
                    $class = 'hotpot_source_' . $data->sourcetype;
                    $source = new $class($sourcefile, $data);
                }
                $method = 'get_' . $textfield;
                if ($source && method_exists($source, $method)) {
                    $data->{$textfield} = $source->{$method}();
                } else {
                    $data->{$textfield} = '';
                }
                break;
            case hotpot::TEXTSOURCE_FILENAME:
                $data->{$textfield} = basename($data->sourcefile);
                break;
            case hotpot::TEXTSOURCE_FILEPATH:
                $data->{$textfield} = str_replace(array('/', '\\'), ' ', $data->sourcefile);
                break;
            case hotpot::TEXTSOURCE_SPECIFIC:
            default:
                if (isset($data->{$textfield})) {
                    $data->{$textfield} = trim($data->{$textfield});
                } else {
                    $data->{$textfield} = $mform->get_original_value($textfield, '');
                }
        }
        // default activity name is simply "HotPot"
        if ($textfield == 'name' && $data->{$textfield} == '') {
            $data->{$textfield} = get_string('modulename', 'hotpot');
        }
    }
    // process entry/exit page settings
    foreach (hotpot::text_page_types() as $type) {
        // show page (boolean switch)
        $pagefield = $type . 'page';
        if (!isset($data->{$pagefield})) {
            $data->{$pagefield} = 0;
        }
        // set field names
        $textfield = $type . 'text';
        $formatfield = $type . 'format';
        $editorfield = $type . 'editor';
        $sourcefield = $type . 'textsource';
        $optionsfield = $type . 'options';
        // ensure text, format and option fields are set
        // (these fields can't be null in the database)
        if (!isset($data->{$textfield})) {
            $data->{$textfield} = $mform->get_original_value($textfield, '');
        }
        if (!isset($data->{$formatfield})) {
            $data->{$formatfield} = $mform->get_original_value($formatfield, FORMAT_HTML);
        }
        if (!isset($data->{$optionsfield})) {
            $data->{$optionsfield} = $mform->get_original_value($optionsfield, 0);
        }
        // set text and format fields
        if ($data->{$sourcefield} == hotpot::TEXTSOURCE_SPECIFIC) {
            // transfer wysiwyg editor text
            if ($itemid = $data->{$editorfield}['itemid']) {
                if (isset($data->{$editorfield}['text'])) {
                    // get the text that was sent from the browser
                    $editoroptions = hotpot::text_editors_options($context);
                    $text = file_save_draft_area_files($itemid, $context->id, 'mod_hotpot', $type, 0, $editoroptions, $data->{$editorfield}['text']);
                    // remove leading and trailing white space,
                    //  - empty html paragraphs (from IE)
                    //  - and blank lines (from Firefox)
                    $text = preg_replace('/^((<p>\\s*<\\/p>)|(<br[^>]*>)|\\s)+/is', '', $text);
                    $text = preg_replace('/((<p>\\s*<\\/p>)|(<br[^>]*>)|\\s)+$/is', '', $text);
                    $data->{$textfield} = $text;
                    $data->{$formatfield} = $data->{$editorfield}['format'];
                }
            }
        }
        // set entry/exit page options
        foreach (hotpot::text_page_options($type) as $name => $mask) {
            $optionfield = $type . '_' . $name;
            if ($data->{$pagefield}) {
                if (empty($data->{$optionfield})) {
                    // disable this option
                    $data->{$optionsfield} = $data->{$optionsfield} & ~$mask;
                } else {
                    // enable this option
                    $data->{$optionsfield} = $data->{$optionsfield} | $mask;
                }
            }
        }
        // don't show exit page if no content is specified
        if ($type == 'exit' && empty($data->{$optionsfield}) && empty($data->{$textfield})) {
            $data->{$pagefield} = 0;
        }
    }
    // timelimit
    if ($data->timelimit == hotpot::TIME_SPECIFIC) {
        $data->timelimit = $data->timelimitspecific;
    }
    // delay3
    if ($data->delay3 == hotpot::TIME_SPECIFIC) {
        $data->delay3 = $data->delay3specific;
    }
    // set stopbutton and stoptext
    if (empty($data->stopbutton_yesno)) {
        $data->stopbutton = hotpot::STOPBUTTON_NONE;
        $data->stoptext = $mform->get_original_value('stoptext', '');
    } else {
        if (!isset($data->stopbutton_type)) {
            $data->stopbutton_type = '';
        }
        if (!isset($data->stopbutton_text)) {
            $data->stopbutton_text = '';
        }
        if ($data->stopbutton_type == 'specific') {
            $data->stopbutton = hotpot::STOPBUTTON_SPECIFIC;
            $data->stoptext = $data->stopbutton_text;
        } else {
            $data->stopbutton = hotpot::STOPBUTTON_LANGPACK;
            $data->stoptext = $data->stopbutton_type;
        }
    }
    // set review options
    $data->reviewoptions = 0;
    list($times, $items) = hotpot::reviewoptions_times_items();
    foreach ($times as $timename => $timevalue) {
        foreach ($items as $itemname => $itemvalue) {
            $name = $timename . $itemname;
            // e.g. duringattemptresponses
            if (isset($data->{$name})) {
                if ($data->{$name}) {
                    $data->reviewoptions += $timevalue & $itemvalue;
                }
                unset($data->{$name});
            }
        }
    }
    // save these form settings as user preferences
    $preferences = array();
    foreach (hotpot::user_preferences_fieldnames() as $fieldname) {
        if (isset($data->{$fieldname})) {
            $preferences['hotpot_' . $fieldname] = $data->{$fieldname};
        }
    }
    set_user_preferences($preferences);
}
 /** print the section which contains the post form (i. e. section number 2)
  * 
  * @global record $USER
  * @global record $PAGE
  * @global object $OUTPUT
  * @param record $course
  * @param object $sectioninfo
  * @param moodle_form $postform
  */
 protected function print_postform_section($course, $sectioninfo, $postform)
 {
     global $USER, $PAGE, $OUTPUT;
     $o = '';
     // ... usually this is section 2, because activities on time line are required to be in section 1.
     if (isset($sectioninfo[FORMAT_SOCIALWALL_POSTFORMSECTION])) {
         $thissection = $sectioninfo[FORMAT_SOCIALWALL_POSTFORMSECTION];
         $o .= html_writer::start_tag('li', array('id' => 'section-' . $thissection->section, 'class' => 'section main clearfix', 'role' => 'region', 'aria-label' => get_section_name($course, $thissection)));
         $o .= html_writer::start_tag('div', array('class' => 'content'));
         $url = new moodle_url('/course/format/socialwall/pages/editnotification.php', array('courseid' => $course->id));
         $linktext = $OUTPUT->pix_icon('i/settings', get_string('editnotification', 'format_socialwall')) . " " . get_string('editnotification', 'format_socialwall');
         $linkparams = array('class' => 'pf-notificationsetting', 'id' => 'pfnotificationsetting_' . $course->id);
         $o .= html_writer::link($url, $linktext, $linkparams);
         $o .= html_writer::tag('div', '', array('class' => 'clearfix'));
         $o .= $postform->render();
         if ($PAGE->user_allowed_editing()) {
             $o .= html_writer::tag('div', '', array('class' => 'clearfix'));
             $thissection = $sectioninfo[FORMAT_SOCIALWALL_POSTFORMSECTION];
             if (empty($thissection->sequence)) {
                 if ($USER->editing) {
                     $o .= html_writer::start_div('attachactivies');
                     $o .= get_string('attachactivities', 'format_socialwall');
                 } else {
                     $o .= html_writer::start_div('');
                 }
             } else {
                 if ($USER->editing) {
                     $o .= html_writer::start_div('attachactivies');
                     $o .= get_string('attachactivities', 'format_socialwall');
                     $o .= html_writer::empty_tag('br') . get_string('attachedactivities', 'format_socialwall');
                 } else {
                     $o .= html_writer::start_div('');
                     $o .= get_string('attachedactivities', 'format_socialwall');
                 }
             }
             $o .= $this->courserenderer->course_section_cm_list($course, $thissection, 0);
             $o .= $this->courserenderer->course_section_add_cm_control($course, FORMAT_SOCIALWALL_POSTFORMSECTION, 0);
             $o .= html_writer::end_div();
         }
         $o .= $this->section_footer();
     }
     echo $o;
 }