public function __construct(dialogue $dialogue = null, conversation $conversation = null)
 {
     global $USER;
     $this->_dialogue = $dialogue;
     $this->_conversation = $conversation;
     $this->_authorid = $USER->id;
     $this->_bodyformat = editors_get_preferred_format();
     $this->_timecreated = time();
     $this->_timemodified = time();
 }
Example #2
0
                $event = \mod_mediagallery\event\item_updated::create($params);
                $event->add_record_snapshot('mediagallery_item', $item->get_record());
                $event->trigger();
            }
        }
        redirect(new moodle_url('/mod/mediagallery/view.php', array('g' => $gallery->id, 'editing' => 1)));
    } else {
        if ($item) {
            $data = $item->get_record();
            $draftitemid = file_get_submitted_draft_itemid('content');
            file_prepare_draft_area($draftitemid, $context->id, 'mod_mediagallery', 'item', $data->id);
            if ($gallery->galleryfocus == \mod_mediagallery\base::TYPE_AUDIO) {
                $draftitemidthumb = file_get_submitted_draft_itemid('customthumbnail');
                $data->customthumbnail = $draftitemidthumb;
            }
            $draftideditor = file_get_submitted_draft_itemid('description');
            $currenttext = file_prepare_draft_area($draftideditor, $context->id, 'mod_mediagallery', 'description', empty($data->id) ? null : $data->id, array('subdirs' => 0), empty($data->description) ? '' : $data->description);
            $data->content = $draftitemid;
            $data->description = array('text' => $currenttext, 'format' => editors_get_preferred_format(), 'itemid' => $draftideditor);
            $data->tags = $item->get_tags();
            $mform->set_data($data);
        }
    }
}
$maxitems = $mediagallery->maxitems;
if (!$item && $maxitems != 0 && count($gallery->get_items()) >= $maxitems) {
    print_error('errortoomanyitems', 'mediagallery', '', $maxitems);
}
echo $OUTPUT->header();
$mform->display();
echo $OUTPUT->footer();
Example #3
0
    /**
     * Allocate a submission to a user for review
     *
     * @param stdClass $submission Submission object with at least id property
     * @param int $reviewerid User ID
     * @param int $weight of the new assessment, from 0 to 16
     * @param bool $bulk repeated inserts into DB expected
     * @return int ID of the new assessment or an error code
     */
    public function add_allocation(stdclass $submission, $reviewerid, $weight=1, $bulk=false) {
        global $DB;

        if ($DB->record_exists('workshop_assessments', array('submissionid' => $submission->id, 'reviewerid' => $reviewerid))) {
            return self::ALLOCATION_EXISTS;
        }

        $weight = (int)$weight;
        if ($weight < 0) {
            $weight = 0;
        }
        if ($weight > 16) {
            $weight = 16;
        }

        $now = time();
        $assessment = new stdclass();
        $assessment->submissionid           = $submission->id;
        $assessment->reviewerid             = $reviewerid;
        $assessment->timecreated            = $now;         // do not set timemodified here
        $assessment->weight                 = $weight;
        $assessment->generalcommentformat   = editors_get_preferred_format();
        $assessment->feedbackreviewerformat = editors_get_preferred_format();

        return $DB->insert_record('workshop_assessments', $assessment, true, $bulk);
    }
Example #4
0
    /**
     * Function to create a dummy discussion.
     *
     * @param array|stdClass $record
     * @return stdClass the discussion object
     */
    public function create_forum_discussion($record = null) {
        global $DB;

        // Increment the forum discussion count.
        $this->forumdiscussioncount++;

        $record = (array) $record;

        if (!isset($record['course'])) {
            throw new coding_exception('course must be present in phpunit_util::create_forum_discussion() $record');
        }

        if (!isset($record['forum'])) {
            throw new coding_exception('forum must be present in phpunit_util::create_forum_discussion() $record');
        }

        if (!isset($record['userid'])) {
            throw new coding_exception('userid must be present in phpunit_util::create_forum_discussion() $record');
        }

        if (!isset($record['name'])) {
            $record['name'] = "Discussion " . $this->forumdiscussioncount;
        }

        if (!isset($record['subject'])) {
            $record['subject'] = "Subject for discussion " . $this->forumdiscussioncount;
        }

        if (!isset($record['message'])) {
            $record['message'] = html_writer::tag('p', 'Message for discussion ' . $this->forumdiscussioncount);
        }

        if (!isset($record['messageformat'])) {
            $record['messageformat'] = editors_get_preferred_format();
        }

        if (!isset($record['messagetrust'])) {
            $record['messagetrust'] = "";
        }

        if (!isset($record['assessed'])) {
            $record['assessed'] = '1';
        }

        if (!isset($record['groupid'])) {
            $record['groupid'] = "-1";
        }

        if (!isset($record['timestart'])) {
            $record['timestart'] = "0";
        }

        if (!isset($record['timeend'])) {
            $record['timeend'] = "0";
        }

        if (!isset($record['mailnow'])) {
            $record['mailnow'] = "0";
        }

        $record = (object) $record;

        // Add the discussion.
        $record->id = forum_add_discussion($record, null, null, $record->userid);

        return $record;
    }
Example #5
0
 /**
  * Instantiates a new event and optionally populates its properties with the
  * data provided
  *
  * @param stdClass $data Optional. An object containing the properties to for
  *                  an event
  */
 public function __construct($data = null)
 {
     global $CFG, $USER;
     // First convert to object if it is not already (should either be object or assoc array)
     if (!is_object($data)) {
         $data = (object) $data;
     }
     $this->editoroptions['maxbytes'] = $CFG->maxbytes;
     $data->eventrepeats = 0;
     if (empty($data->id)) {
         $data->id = null;
     }
     if (!empty($data->subscriptionid)) {
         $data->subscription = calendar_get_subscription($data->subscriptionid);
     }
     // Default to a user event
     if (empty($data->eventtype)) {
         $data->eventtype = 'user';
     }
     // Default to the current user
     if (empty($data->userid)) {
         $data->userid = $USER->id;
     }
     if (!empty($data->timeduration) && is_array($data->timeduration)) {
         $data->timeduration = make_timestamp($data->timeduration['year'], $data->timeduration['month'], $data->timeduration['day'], $data->timeduration['hour'], $data->timeduration['minute']) - $data->timestart;
     }
     if (!empty($data->description) && is_array($data->description)) {
         $data->format = $data->description['format'];
         $data->description = $data->description['text'];
     } else {
         if (empty($data->description)) {
             $data->description = '';
             $data->format = editors_get_preferred_format();
         }
     }
     // Ensure form is defaulted correctly
     if (empty($data->format)) {
         $data->format = editors_get_preferred_format();
     }
     if (empty($data->context)) {
         $data->context = $this->calculate_context($data);
     }
     $this->properties = $data;
 }
Example #6
0
 /**
  * Prepares the form before data are set
  *
  * Additional wysiwyg editors are prepared here
  * along with the stopbutton switch, type and text
  *
  * @param array $data to be set
  * @return void
  */
 function data_preprocessing(&$data)
 {
     // Note: if you call "file_prepare_draft_area()" without setting itemid
     // (the first argument), then it will be assigned automatically, and the files
     // for this context will be transferred automatically, which is what we want
     $data['sourceitemid'] = 0;
     if ($this->is_add()) {
         $contextid = null;
     } else {
         $contextid = $this->context->id;
     }
     $options = hotpot::sourcefile_options();
     // array('subdirs' => 1, 'maxbytes' => 0, 'maxfiles' => -1);
     file_prepare_draft_area($data['sourceitemid'], $contextid, 'mod_hotpot', 'sourcefile', 0, $options);
     if ($this->is_add()) {
         // set fields from user preferences, where possible
         foreach (hotpot::user_preferences_fieldnames() as $fieldname) {
             if (!isset($data[$fieldname])) {
                 $data[$fieldname] = get_user_preferences('hotpot_' . $fieldname, '');
             }
         }
     }
     // set entry/exit page settings
     foreach (hotpot::text_page_types() as $type) {
         // extract boolean switches for page options
         foreach (hotpot::text_page_options($type) as $name => $mask) {
             $data[$type . '_' . $name] = $data[$type . 'options'] & $mask;
         }
         // setup custom wysiwyg editor
         $draftitemid = 0;
         if ($this->is_add()) {
             // adding a new hotpot instance
             $data[$type . 'editor'] = array('text' => file_prepare_draft_area($draftitemid, $contextid, 'mod_hotpot', $type, 0), 'format' => editors_get_preferred_format(), 'itemid' => file_get_submitted_draft_itemid($type));
         } else {
             // editing an existing hotpot
             $data[$type . 'editor'] = array('text' => file_prepare_draft_area($draftitemid, $contextid, 'mod_hotpot', $type, 0, $options, $data[$type . 'text']), 'format' => $data[$type . 'format'], 'itemid' => file_get_submitted_draft_itemid($type));
         }
     }
     // timelimit
     if ($data['timelimit'] > 0) {
         $data['timelimitspecific'] = $data['timelimit'];
         $data['timelimit'] = hotpot::TIME_SPECIFIC;
     } else {
         $data['timelimitspecific'] = 0;
     }
     // delay3
     if ($data['delay3'] > 0) {
         $data['delay3specific'] = $data['delay3'];
         $data['delay3'] = hotpot::TIME_SPECIFIC;
     } else {
         $data['delay3specific'] = 0;
     }
     // set stopbutton options
     switch ($data['stopbutton']) {
         case hotpot::STOPBUTTON_SPECIFIC:
             $data['stopbutton_yesno'] = 1;
             $data['stopbutton_type'] = 'specific';
             $data['stopbutton_text'] = $data['stoptext'];
             break;
         case hotpot::STOPBUTTON_LANGPACK:
             $data['stopbutton_yesno'] = 1;
             $data['stopbutton_type'] = $data['stoptext'];
             $data['stopbutton_text'] = '';
             break;
         case hotpot::STOPBUTTON_NONE:
         default:
             $data['stopbutton_yesno'] = 0;
             $data['stopbutton_type'] = '';
             $data['stopbutton_text'] = '';
     }
     // set review options
     if (empty($data['reviewoptions'])) {
         $default = 0;
     } else {
         $default = $data['reviewoptions'];
     }
     list($times, $items) = hotpot::reviewoptions_times_items();
     foreach ($times as $timename => $timevalue) {
         foreach ($items as $itemname => $itemvalue) {
             $data[$timename . $itemname] = min(1, $default & $timevalue & $itemvalue);
         }
     }
 }
Example #7
0
 /**
  * Prepares the form before data are set
  *
  * Additional wysiwyg editor are prepared here, the introeditor is prepared automatically by core.
  * Grade items are set here because the core modedit supports single grade item only.
  *
  * @param array $data to be set
  * @return void
  */
 public function data_preprocessing(&$data)
 {
     if ($this->current->instance) {
         // editing an existing workshop - let us prepare the added editor elements (intro done automatically)
         $draftitemid = file_get_submitted_draft_itemid('instructauthors');
         $data['instructauthorseditor']['text'] = file_prepare_draft_area($draftitemid, $this->context->id, 'mod_workshop', 'instructauthors', 0, workshop::instruction_editors_options($this->context), $data['instructauthors']);
         $data['instructauthorseditor']['format'] = $data['instructauthorsformat'];
         $data['instructauthorseditor']['itemid'] = $draftitemid;
         $draftitemid = file_get_submitted_draft_itemid('instructreviewers');
         $data['instructreviewerseditor']['text'] = file_prepare_draft_area($draftitemid, $this->context->id, 'mod_workshop', 'instructreviewers', 0, workshop::instruction_editors_options($this->context), $data['instructreviewers']);
         $data['instructreviewerseditor']['format'] = $data['instructreviewersformat'];
         $data['instructreviewerseditor']['itemid'] = $draftitemid;
         $draftitemid = file_get_submitted_draft_itemid('conclusion');
         $data['conclusioneditor']['text'] = file_prepare_draft_area($draftitemid, $this->context->id, 'mod_workshop', 'conclusion', 0, workshop::instruction_editors_options($this->context), $data['conclusion']);
         $data['conclusioneditor']['format'] = $data['conclusionformat'];
         $data['conclusioneditor']['itemid'] = $draftitemid;
     } else {
         // adding a new workshop instance
         $draftitemid = file_get_submitted_draft_itemid('instructauthors');
         file_prepare_draft_area($draftitemid, null, 'mod_workshop', 'instructauthors', 0);
         // no context yet, itemid not used
         $data['instructauthorseditor'] = array('text' => '', 'format' => editors_get_preferred_format(), 'itemid' => $draftitemid);
         $draftitemid = file_get_submitted_draft_itemid('instructreviewers');
         file_prepare_draft_area($draftitemid, null, 'mod_workshop', 'instructreviewers', 0);
         // no context yet, itemid not used
         $data['instructreviewerseditor'] = array('text' => '', 'format' => editors_get_preferred_format(), 'itemid' => $draftitemid);
         $draftitemid = file_get_submitted_draft_itemid('conclusion');
         file_prepare_draft_area($draftitemid, null, 'mod_workshop', 'conclusion', 0);
         // no context yet, itemid not used
         $data['conclusioneditor'] = array('text' => '', 'format' => editors_get_preferred_format(), 'itemid' => $draftitemid);
     }
 }
Example #8
0
        $discussionsubscribe = true;
    } else if (!isset($discussion) && \mod_forum\subscriptions::is_subscribed($USER->id, $forum, null, $cm)) {
        // Starting a new discussion, and the user is subscribed to the forum - subscribe to the discussion.
        $discussionsubscribe = true;
    } else {
        // User is not subscribed to either forum or discussion. Follow user preference.
        $discussionsubscribe = $USER->autosubscribe;
    }
}

$mform_post->set_data(array(        'attachments'=>$draftitemid,
                                    'general'=>$heading,
                                    'subject'=>$post->subject,
                                    'message'=>array(
                                        'text'=>$currenttext,
                                        'format'=>empty($post->messageformat) ? editors_get_preferred_format() : $post->messageformat,
                                        'itemid'=>$draftid_editor
                                    ),
                                    'discussionsubscribe' => $discussionsubscribe,
                                    'mailnow'=>!empty($post->mailnow),
                                    'userid'=>$post->userid,
                                    'parent'=>$post->parent,
                                    'discussion'=>$post->discussion,
                                    'course'=>$course->id) +
                                    $page_params +

                            (isset($post->format)?array(
                                    'format'=>$post->format):
                                array())+

                            (isset($discussion->timestart)?array(
 function data_preprocessing($question)
 {
     global $QTYPES;
     $answer = $this->answer;
     $default_values = array();
     if (count($answer)) {
         $key = 0;
         foreach ($answer as $answer) {
             $default_values['answer[' . $key . ']'] = $answer->answer;
             //  is necessary ? to-do test it
             $default_values['fraction[' . $key . ']'] = $answer->fraction;
             $default_values['tolerance[' . $key . ']'] = $answer->tolerance;
             $default_values['tolerancetype[' . $key . ']'] = $answer->tolerancetype;
             $default_values['correctanswerlength[' . $key . ']'] = $answer->correctanswerlength;
             $default_values['correctanswerformat[' . $key . ']'] = $answer->correctanswerformat;
             // prepare draft files
             $draftid = file_get_submitted_draft_itemid('feedback[' . $key . ']');
             $default_values['feedback[' . $key . ']']['text'] = file_prepare_draft_area($draftid, $this->context->id, 'question', 'answerfeedback', !empty($answer->id) ? (int) $answer->id : null, $this->fileoptions, !empty($answer->feedback) ? $answer->feedback : '');
             $default_values['feedback[' . $key . ']']['format'] = !empty($answer->feedbackformat) ? $answer->feedbackformat : editors_get_preferred_format();
             $default_values['feedback[' . $key . ']']['itemid'] = $draftid;
             $key++;
         }
     }
     $default_values['synchronize'] = 0;
     $QTYPES['numerical']->set_numerical_unit_data($this, $question, $default_values);
     /*  if (isset($question->options)){
                     $default_values['unitgradingtype'] = $question->options->unitgradingtype ;
                     $default_values['unitpenalty'] = $question->options->unitpenalty ;
                     switch ($question->options->showunits){
                         case 'O' :
                         case '1' :
                             $default_values['showunits0'] = $question->options->showunits ;
                             $default_values['unitrole'] = 0 ;
                             break;
                         case '2' :
                         case '3' :
                             $default_values['showunits1'] = $question->options->showunits ;
                             $default_values['unitrole'] = 1 ;
                             break;
                     }
                     $default_values['unitsleft'] = $question->options->unitsleft ;
                     $default_values['instructions'] = $question->options->instructions  ;
     
                     if (isset($question->options->units)){
                         $units  = array_values($question->options->units);
                         if (!empty($units)) {
                             foreach ($units as $key => $unit){
                                 $default_values['unit['.$key.']'] = $unit->unit;
                                 $default_values['multiplier['.$key.']'] = $unit->multiplier;
                             }
                         }
                     }
                 }
                */
     $key = 0;
     $formdata = array();
     $fromform = new stdClass();
     //this should be done before the elements are created and stored as $this->formdata ;
     //fill out all data sets and also the fields for the next item to add.
     /* if(!empty($this->datasetdefs)){
             $j = $this->noofitems * count($this->datasetdefs);
             for ($itemnumber = $this->noofitems; $itemnumber >= 1; $itemnumber--){
                 $data = array();
                 foreach ($this->datasetdefs as $defid => $datasetdef){
                     if (isset($datasetdef->items[$itemnumber])){
                         $formdata["number[$j]"] = $datasetdef->items[$itemnumber]->value;
                         $formdata["definition[$j]"] = $defid;
                         $formdata["itemid[$j]"] = $datasetdef->items[$itemnumber]->id;
                         $data[$datasetdef->name] = $datasetdef->items[$itemnumber]->value;
                     }
                     $j--;
                 }
                 // echo "<p>answers avant  comment <pre>";print_r($answer);echo"</pre></p>";
                 // echo "<p>data avant  comment <pre>";print_r($data);echo"</pre></p>";
     
                 if($this->noofitems != 0 ) {
                     if(!isset($question->id)) $question->id = 0 ;
                     $comment = $this->qtypeobj->comment_on_datasetitems($question->id,$this->nonemptyanswer, $data, $itemnumber);//$this->
                      if ($comment->outsidelimit) {
                          $this->outsidelimit=$comment->outsidelimit ;
                     }
                     $totalcomment='';
                     // echo "<p> comment <pre>";print_r($comment);echo"</pre></p>";
     
                     foreach ($this->nonemptyanswer as $key => $answer) {
                         $totalcomment .= $comment->stranswers[$key].'<br/>';
                     }
     
                     $formdata['answercomment['.$itemnumber.']'] = $totalcomment ;
                 }
             }
             // $formdata['reload'] = '1';
             // $formdata['nextpageparam[forceregeneration]'] = $this->regenerate;
             $formdata['selectdelete'] = '1';
             $formdata['selectadd'] = '1';
             $j = $this->noofitems * count($this->datasetdefs)+1;
             $data = array(); // data for comment_on_datasetitems later
                $idx =1 ;
                 foreach ($this->datasetdefs as $defid => $datasetdef){
                    $formdata["datasetdef[$idx]"] = $defid;
                     $idx++;
                 }
             $formdata = $this->qtypeobj->custom_generator_set_data($this->datasetdefs, $formdata);
             }*/
     $question = (object) ((array) $question + $default_values + $this->formdata);
     return $question;
 }
Example #10
0
print get_string('advice_edit', 'ouwiki', $OUTPUT->help_icon('createlinkedwiki', 'ouwiki'));
if ($ouwiki->timeout) {
    $countdowntext = get_string('countdowntext', 'ouwiki', $ouwiki->timeout / 60);
    print "<script type='text/javascript'>\n                document.write('<p><div id=\"ouw_countdown\"></div>{$countdowntext}<span id=\"ouw_countdownurgent\"></span></p>');\n        </script>";
}
// Set up basic form data
$data = new StdClass();
$data->id = $cm->id;
$data->startversionid = $pageversion->versionid;
$data->page = $pagename;
$data->frompage = $frompage;
$data->newsection = $newsection;
$data->section = $section;
$data->user = $subwiki->userid;
// Prepare form file manager attachments
if ($useattachments) {
    $attachmentsdraftid = file_get_submitted_draft_itemid('attachments');
    file_prepare_draft_area($attachmentsdraftid, $context->id, 'mod_ouwiki', 'attachment', empty($pageversion->versionid) ? null : $pageversion->versionid);
    $data->attachments = $attachmentsdraftid;
}
// Prepare form editor attachments
$contentdraftid = file_get_submitted_draft_itemid('content');
$currenttext = file_prepare_draft_area($contentdraftid, $context->id, 'mod_ouwiki', 'content', empty($pageversion->versionid) ? null : $pageversion->versionid, array('subdirs' => false), empty($existing) ? '' : $existing);
$data->content = array('text' => $currenttext, 'format' => empty($pageversion->xhtmlformat) ? editors_get_preferred_format() : $pageversion->xhtmlformat, 'itemid' => $contentdraftid);
$mform->set_data($data);
$mform->display();
$stringlist = array(array('savefailnetwork', 'ouwiki'), array('savefailtitle', 'ouwiki'));
$jsmodule = array('name' => 'mod_ouwiki_edit', 'fullpath' => '/mod/ouwiki/module.js', 'requires' => array('base', 'event', 'io', 'node', 'anim', 'moodle-core-notification-alert', 'button'), 'strings' => $stringlist);
$PAGE->requires->js_init_call('M.mod_ouwiki_edit.init', null, true, $jsmodule);
// Footer
ouwiki_print_footer($course, $cm, $subwiki, $pagename);
Example #11
0
$url->param('m', $message->id());
local_mail_setup_page($message->course(), $url);
// Remove recipients
if ($remove) {
    require_sesskey();
    $message->remove_recipient(key($remove));
}
// Set up form
$data = array();
$customdata = array();
$customdata['message'] = $message;
$customdata['context'] = $PAGE->context;
$mform = new mail_compose_form($url, $customdata);
$draftareaid = file_get_submitted_draft_itemid('message');
$content = file_prepare_draft_area($draftareaid, $PAGE->context->id, 'local_mail', 'message', $message->id(), mail_compose_form::file_options(), $message->content());
$format = $message->format() >= 0 ? $message->format() : editors_get_preferred_format();
$data['course'] = $message->course()->id;
$data['subject'] = $message->subject();
$data['content']['format'] = $format;
$data['content']['text'] = $content;
$data['content']['itemid'] = $draftareaid;
$data['attachments'] = $draftareaid;
$mform->set_data($data);
// Process form
if ($data = $mform->get_data()) {
    $fs = get_file_storage();
    // Discard message
    if (!empty($data->discard)) {
        $fs->delete_area_files($PAGE->context->id, 'local_mail', 'message', $message->id());
        $message->discard();
        $params = array('t' => 'course', 'c' => $message->course()->id);
Example #12
0
    function get_numerical_options(&$question) {
        global $DB;
        if (!$options = $DB->get_record('question_numerical_options', array('question' => $question->id))) {
            $question->options->unitgradingtype = 0; // total grade
            $question->options->unitpenalty = 0.1; // default for old questions
            // the default
            if ($defaultunit = $this->get_default_numerical_unit($question)) {
                // so units can be graded
                $question->options->showunits = NUMERICALQUESTIONUNITTEXTINPUTDISPLAY ;
            }else {
                // only numerical will be graded
                $question->options->showunits = NUMERICALQUESTIONUNITNODISPLAY ;
            }
            $question->options->unitsleft = 0 ;
            $question->options->instructions = '';
            $question->options->instructionsformat = editors_get_preferred_format();
        } else {
            $question->options->unitgradingtype = $options->unitgradingtype;
            $question->options->unitpenalty = $options->unitpenalty;
            $question->options->showunits = $options->showunits;
            $question->options->unitsleft = $options->unitsleft;
            $question->options->instructions = $options->instructions;
            $question->options->instructionsformat = $options->instructionsformat; 
        }

        return true;
    }
Example #13
0
 function set_data($question)
 {
     global $QTYPES;
     // prepare question text
     $draftid = file_get_submitted_draft_itemid('questiontext');
     if (!empty($question->questiontext)) {
         $questiontext = $question->questiontext;
     } else {
         $questiontext = '';
     }
     $questiontext = file_prepare_draft_area($draftid, $this->context->id, 'question', 'questiontext', empty($question->id) ? null : (int) $question->id, $this->fileoptions, $questiontext);
     $question->questiontext = array();
     $question->questiontext['text'] = $questiontext;
     $question->questiontext['format'] = empty($question->questiontextformat) ? editors_get_preferred_format() : $question->questiontextformat;
     $question->questiontext['itemid'] = $draftid;
     // prepare general feedback
     $draftid = file_get_submitted_draft_itemid('generalfeedback');
     if (empty($question->generalfeedback)) {
         $question->generalfeedback = '';
     }
     $feedback = file_prepare_draft_area($draftid, $this->context->id, 'question', 'generalfeedback', empty($question->id) ? null : (int) $question->id, $this->fileoptions, $question->generalfeedback);
     $question->generalfeedback = array();
     $question->generalfeedback['text'] = $feedback;
     $question->generalfeedback['format'] = empty($question->generalfeedbackformat) ? editors_get_preferred_format() : $question->generalfeedbackformat;
     $question->generalfeedback['itemid'] = $draftid;
     // Remove unnecessary trailing 0s form grade fields.
     if (isset($question->defaultgrade)) {
         $question->defaultgrade = 0 + $question->defaultgrade;
     }
     if (isset($question->penalty)) {
         $question->penalty = 0 + $question->penalty;
     }
     // Set any options.
     $extra_question_fields = $QTYPES[$question->qtype]->extra_question_fields();
     if (is_array($extra_question_fields) && !empty($question->options)) {
         array_shift($extra_question_fields);
         foreach ($extra_question_fields as $field) {
             if (isset($question->options->{$field})) {
                 $question->{$field} = $question->options->{$field};
             }
         }
     }
     // subclass adds data_preprocessing code here
     $question = $this->data_preprocessing($question);
     parent::set_data($question);
 }
 /**
  * Constructor for the base referentiel class
  *
  * Constructor for the base referentiel class.
  * If cmid is set create the cm, course, referentiel objects.
  * If the referentiel is hidden and the user is not a teacher then
  * this prints a page header and notice.
  *
  * @global object
  * @global object
  * @param int $cmid the current course module id - not set for new assignments
  * @param object $referentiel usually null, but if we have it we pass it to save db access
  * @param object $cm usually null, but if we have it we pass it to save db access
  * @param object $course usually null, but if we have it we pass it to save db access
  */
 function referentiel($cmid = 'staticonly', $referentiel = NULL, $cm = NULL, $course = NULL)
 {
     global $COURSE, $DB;
     if ($cmid == 'staticonly') {
         //use static functions only!
         return;
     }
     global $CFG;
     if ($cm) {
         $this->cm = $cm;
     } else {
         if (!($this->cm = get_coursemodule_from_id('referentiel', $cmid))) {
             print_error('invalidcoursemodule');
         }
     }
     // Valable pour Moodle 2.1 et Moodle 2.2
     ////if ($CFG->version < 2011120100) {
     $this->context = context_module::instance($this->cm->id);
     //} else {
     //    //  $this->context = context_module::instance($this->cm);
     //}
     if ($course) {
         $this->course = $course;
     } else {
         if ($this->cm->course == $COURSE->id) {
             $this->course = $COURSE;
         } else {
             if (!($this->course = $DB->get_record('course', array('id' => $this->cm->course)))) {
                 print_error('invalidid', 'referentiel');
             }
         }
     }
     // valeurs par defaut
     $this->referentiel = new stdClass();
     $this->referentiel->name = "";
     $this->referentiel->description_instance = "";
     $this->referentiel->label_domaine = trim(get_string('domaine', 'referentiel'));
     $this->referentiel->label_competence = trim(get_string('competence', 'referentiel'));
     $this->referentiel->label_item = trim(get_string('item', 'referentiel'));
     $this->referentiel->label_item = trim(get_string('item', 'referentiel'));
     $this->referentiel->config = $this->creer_configuration('config');
     $this->referentiel->config_impression = $this->creer_configuration('configuration_impression');
     $this->referentiel->config_globale = $this->referentiel->config;
     $this->referentiel->config_impression_globale = $this->referentiel->config_impression;
     $this->referentiel->ref_referentiel = 0;
     $this->referentiel->visible = 1;
     $this->referentiel->intro = "";
     $this->referentiel->introformat = 1;
     $this->referentiel->maxbytes = 1048576;
     if ($referentiel) {
         $this->referentiel = $referentiel;
     } else {
         if (!($this->referentiel = $DB->get_record('referentiel', array('id' => $this->cm->instance)))) {
             print_error('invalidid', 'referentiel');
         }
     }
     $this->referentiel->cmidnumber = $this->cm->idnumber;
     // compatibility with modedit referentiel obj
     $this->referentiel->course = $this->course->id;
     // compatibility with modedit referentiel obj
     if (!empty($this->referentiel->ref_referentiel)) {
         // occurrence associe
         $this->referentiel_referentiel = $DB->get_record('referentiel_referentiel', array('id' => $this->referentiel->ref_referentiel));
     }
     $this->strreferentiel = get_string('modulename', 'referentiel');
     $this->strreferentiels = get_string('modulenameplural', 'referentiel');
     $this->strsubmissions = get_string('submissions', 'referentiel');
     $this->strlastmodified = get_string('lastmodified');
     $this->pagetitle = strip_tags($this->course->shortname . ': ' . $this->strreferentiel . ': ' . format_string($this->referentiel->name, true));
     // visibility handled by require_login() with $cm parameter
     // get current group only when really needed
     /// Set up things for a HTML editor if it's needed
     $this->defaultformat = editors_get_preferred_format();
 }
Example #15
0
 /**
  * Upgrade the submission from the old assignment to the new one
  *
  * @param context $oldcontext - the database for the old assignment context
  * @param stdClass $oldassignment The data record for the old assignment
  * @param stdClass $oldsubmission The data record for the old submission
  * @param stdClass $submission The data record for the new submission
  * @param string $log Record upgrade messages in the log
  * @return bool true or false - false will trigger a rollback
  */
 public function upgrade(context $oldcontext, stdClass $oldassignment, stdClass $oldsubmission, stdClass $submission, &$log)
 {
     global $DB;
     $onlinetextsubmission = new stdClass();
     $onlinetextsubmission->onlinetext = $oldsubmission->data1;
     $onlinetextsubmission->onlineformat = $oldsubmission->data2;
     $onlinetextsubmission->submission = $submission->id;
     $onlinetextsubmission->assignment = $this->assignment->get_instance()->id;
     if ($onlinetextsubmission->onlinetext === null) {
         $onlinetextsubmission->onlinetext = '';
     }
     if ($onlinetextsubmission->onlineformat === null) {
         $onlinetextsubmission->onlineformat = editors_get_preferred_format();
     }
     if (!$DB->insert_record('assignsubmission_onlinetext', $onlinetextsubmission) > 0) {
         $log .= get_string('couldnotconvertsubmission', 'mod_assign', $submission->userid);
         return false;
     }
     // now copy the area files
     $this->assignment->copy_area_files_for_upgrade($oldcontext->id, 'mod_assignment', 'submission', $oldsubmission->id, $this->assignment->get_context()->id, 'assignsubmission_onlinetext', ASSIGNSUBMISSION_ONLINETEXT_FILEAREA, $submission->id);
     return true;
 }
 /**
  * (non-PHPdoc)
  * @see moodleform_mod::data_preprocessing()
  */
 public function data_preprocessing(&$toform)
 {
     if (!empty($this->_feedbacks)) {
         $key = 0;
         foreach ($this->_feedbacks as $feedback) {
             $toform['feedbacktext[' . $key . ']'] = $feedback->feedbacktext;
             if ($feedback->mingrade > 0) {
                 $toform['feedbackboundaries[' . $key . ']'] = 100.0 * $feedback->mingrade / $toform['grade'] . '%';
             }
             $key++;
         }
     }
     // Set the pdfintro text.
     if ($this->current->instance) {
         if (!$toform['docscreated']) {
             // Editing an existing pdfintro - let us prepare the added editor elements (intro done automatically).
             $draftitemid = file_get_submitted_draft_itemid('pdfintro');
             $text = file_prepare_draft_area($draftitemid, $this->context->id, 'mod_offlinequiz', 'pdfintro', false, offlinequiz_get_editor_options($this->context), $toform['pdfintro']);
             // $default_values['pdfintro']['format'] = $default_values['pdfintro'];
             $toform['pdfintro'] = array();
             $toform['pdfintro']['text'] = $text;
             $toform['pdfintro']['format'] = editors_get_preferred_format();
             $toform['pdfintro']['itemid'] = $draftitemid;
         }
     } else {
         // Adding a new feedback instance.
         $draftitemid = file_get_submitted_draft_itemid('pdfintro');
         // No context yet, itemid not used.
         file_prepare_draft_area($draftitemid, null, 'mod_offlinequiz', 'pdfintro', false);
         $toform['pdfintro'] = array();
         $toform['pdfintro']['text'] = get_string('pdfintrotext', 'offlinequiz');
         $toform['pdfintro']['format'] = editors_get_preferred_format();
         $toform['pdfintro']['itemid'] = $draftitemid;
     }
     if (empty($toform['timelimit'])) {
         $toform['timelimitenable'] = 0;
     } else {
         $toform['timelimitenable'] = 1;
     }
     if (isset($toform['review'])) {
         $review = (int) $toform['review'];
         unset($toform['review']);
         $toform['attemptclosed'] = $review & OFFLINEQUIZ_REVIEW_ATTEMPT;
         $toform['correctnessclosed'] = $review & OFFLINEQUIZ_REVIEW_CORRECTNESS;
         $toform['marksclosed'] = $review & OFFLINEQUIZ_REVIEW_MARKS;
         $toform['specificfeedbackclosed'] = $review & OFFLINEQUIZ_REVIEW_SPECIFICFEEDBACK;
         $toform['generalfeedbackclosed'] = $review & OFFLINEQUIZ_REVIEW_GENERALFEEDBACK;
         $toform['rightanswerclosed'] = $review & OFFLINEQUIZ_REVIEW_RIGHTANSWER;
         $toform['sheetclosed'] = $review & OFFLINEQUIZ_REVIEW_SHEET;
         $toform['gradedsheetclosed'] = $review & OFFLINEQUIZ_REVIEW_GRADEDSHEET;
     }
 }
Example #17
0
}
if (empty($users)) {
    print_error('no_usergroups', 'block_quickmail');
}
// we are presenting the form with values populated from either the log or drafts table in the db
if (!empty($type)) {
    $email = $DB->get_record('block_quickmail_' . $type, array('id' => $typeid));
    //$emailmailto = array();
    if ($messageIDresend == 1) {
        list($email->mailto, $email->additional_emails) = quickmail::clean($email->failuserids);
    }
} else {
    $email = new stdClass();
    $email->id = null;
}
$email->messageformat = editors_get_preferred_format();
$default_sigid = $DB->get_field('block_quickmail_signatures', 'id', array('userid' => $USER->id, 'default_flag' => 1));
$email->sigid = $default_sigid ? $default_sigid : -1;
// Some setters for the form
$email->type = $type;
$email->typeid = $typeid;
$editor_options = array('trusttext' => false, 'subdirs' => 1, 'maxfiles' => EDITOR_UNLIMITED_FILES, 'accepted_types' => '*', 'context' => $context);
$email = file_prepare_standard_editor($email, 'message', $editor_options, $context, 'block_quickmail', $type, $email->id);
$selected = array();
if (!empty($email->mailto)) {
    foreach (explode(',', $email->mailto) as $id) {
        $selected[$id] = (object) array('id' => $id, 'firstname' => null, 'lastname' => null, 'email' => $id, 'mailformat' => '1', 'suspended' => '0', 'maildisplay' => '2', 'status' => '0');
        if (is_numeric($selected[$id]->id)) {
            $selected[$id] = $users[$id];
        }
        unset($users[$id]);
 public function set_data($question)
 {
     question_bank::get_qtype($question->qtype)->set_default_options($question);
     // Prepare question text.
     $draftid = file_get_submitted_draft_itemid('questiontext');
     if (!empty($question->questiontext)) {
         $questiontext = $question->questiontext;
     } else {
         $questiontext = $this->_form->getElement('questiontext')->getValue();
         $questiontext = $questiontext['text'];
     }
     $questiontext = file_prepare_draft_area($draftid, $this->context->id, 'question', 'questiontext', empty($question->id) ? null : (int) $question->id, $this->fileoptions, $questiontext);
     $question->questiontext = array();
     $question->questiontext['text'] = $questiontext;
     $question->questiontext['format'] = empty($question->questiontextformat) ? editors_get_preferred_format() : $question->questiontextformat;
     $question->questiontext['itemid'] = $draftid;
     // Prepare general feedback.
     $draftid = file_get_submitted_draft_itemid('generalfeedback');
     if (empty($question->generalfeedback)) {
         $generalfeedback = $this->_form->getElement('generalfeedback')->getValue();
         $question->generalfeedback = $generalfeedback['text'];
     }
     $feedback = file_prepare_draft_area($draftid, $this->context->id, 'question', 'generalfeedback', empty($question->id) ? null : (int) $question->id, $this->fileoptions, $question->generalfeedback);
     $question->generalfeedback = array();
     $question->generalfeedback['text'] = $feedback;
     $question->generalfeedback['format'] = empty($question->generalfeedbackformat) ? editors_get_preferred_format() : $question->generalfeedbackformat;
     $question->generalfeedback['itemid'] = $draftid;
     // Remove unnecessary trailing 0s form grade fields.
     if (isset($question->defaultgrade)) {
         $question->defaultgrade = 0 + $question->defaultgrade;
     }
     if (isset($question->penalty)) {
         $question->penalty = 0 + $question->penalty;
     }
     // Set any options.
     $extraquestionfields = question_bank::get_qtype($question->qtype)->extra_question_fields();
     if (is_array($extraquestionfields) && !empty($question->options)) {
         array_shift($extraquestionfields);
         foreach ($extraquestionfields as $field) {
             if (property_exists($question->options, $field)) {
                 $question->{$field} = $question->options->{$field};
             }
         }
     }
     // Subclass adds data_preprocessing code here.
     $question = $this->data_preprocessing($question);
     parent::set_data($question);
 }
 /**
  * Constructor for the grouptool class
  *
  * If cmid is set create the cm, course, checkmark objects.
  *
  * @param int $cmid the current course module id - not set for new grouptools
  * @param stdClass $grouptool usually null, but if we have it we pass it to save db access
  * @param stdClass $cm usually null, but if we have it we pass it to save db access
  * @param stdClass $course usually null, but if we have it we pass it to save db access
  */
 public function __construct($cmid, $grouptool = null, $cm = null, $course = null)
 {
     global $DB;
     if ($cmid == 'staticonly') {
         // Use static functions only!
         return;
     }
     global $CFG;
     if (!empty($cm)) {
         $this->cm = $cm;
     } else {
         if (!($this->cm = get_coursemodule_from_id('grouptool', $cmid))) {
             print_error('invalidcoursemodule');
         }
     }
     $this->context = context_module::instance($this->cm->id);
     if ($course) {
         $this->course = $course;
     } else {
         if (!($this->course = $DB->get_record('course', array('id' => $this->cm->course)))) {
             print_error('invalidid', 'grouptool');
         }
     }
     if ($grouptool) {
         $this->grouptool = $grouptool;
     } else {
         if (!($this->grouptool = $DB->get_record('grouptool', array('id' => $this->cm->instance)))) {
             print_error('invalidid', 'grouptool');
         }
     }
     $this->grouptool->cmidnumber = $this->cm->idnumber;
     $this->grouptool->course = $this->course->id;
     $this->strgrouptool = get_string('modulename', 'grouptool');
     $this->strgrouptools = get_string('modulenameplural', 'grouptool');
     $this->strlastmodified = get_string('lastmodified');
     $this->pagetitle = strip_tags($this->course->shortname . ': ' . $this->strgrouptool . ': ' . format_string($this->grouptool->name, true));
     /*
      * visibility handled by require_login() with $cm parameter
      * get current group only when really needed
      */
     // Set up things for a HTML editor if it's needed!
     $this->defaultformat = editors_get_preferred_format();
 }
Example #20
0
/**
 * Prepares 'editor' formslib element from data in database
 *
 * The passed $data record must contain field foobar, foobarformat and optionally foobartrust. This
 * function then copies the embedded files into draft area (assigning itemids automatically),
 * creates the form element foobar_editor and rewrites the URLs so the embedded images can be
 * displayed.
 * In your mform definition, you must have an 'editor' element called foobar_editor. Then you call
 * your mform's set_data() supplying the object returned by this function.
 *
 * @param object $data database field that holds the html text with embedded media
 * @param string $field the name of the database field that holds the html text with embedded media
 * @param array $options editor options (like maxifiles, maxbytes etc.)
 * @param object $context context of the editor
 * @param string $component
 * @param string $filearea file area name
 * @param int $itemid item id, required if item exists
 * @return object modified data object
 */
function file_prepare_standard_editor($data, $field, array $options, $context = null, $component = null, $filearea = null, $itemid = null)
{
    $options = (array) $options;
    if (!isset($options['trusttext'])) {
        $options['trusttext'] = false;
    }
    if (!isset($options['forcehttps'])) {
        $options['forcehttps'] = false;
    }
    if (!isset($options['subdirs'])) {
        $options['subdirs'] = false;
    }
    if (!isset($options['maxfiles'])) {
        $options['maxfiles'] = 0;
        // no files by default
    }
    if (!isset($options['noclean'])) {
        $options['noclean'] = false;
    }
    if (is_null($itemid) or is_null($context)) {
        $contextid = null;
        $itemid = null;
        if (!isset($data->{$field})) {
            $data->{$field} = '';
        }
        if (!isset($data->{$field . 'format'})) {
            $data->{$field . 'format'} = editors_get_preferred_format();
        }
        if (!$options['noclean']) {
            $data->{$field} = clean_text($data->{$field}, $data->{$field . 'format'});
        }
    } else {
        if ($options['trusttext']) {
            // noclean ignored if trusttext enabled
            if (!isset($data->{$field . 'trust'})) {
                $data->{$field . 'trust'} = 0;
            }
            $data = trusttext_pre_edit($data, $field, $context);
        } else {
            if (!$options['noclean']) {
                $data->{$field} = clean_text($data->{$field}, $data->{$field . 'format'});
            }
        }
        $contextid = $context->id;
    }
    if ($options['maxfiles'] != 0) {
        $draftid_editor = file_get_submitted_draft_itemid($field);
        $currenttext = file_prepare_draft_area($draftid_editor, $contextid, $component, $filearea, $itemid, $options, $data->{$field});
        $data->{$field . '_editor'} = array('text' => $currenttext, 'format' => $data->{$field . 'format'}, 'itemid' => $draftid_editor);
    } else {
        $data->{$field . '_editor'} = array('text' => $data->{$field}, 'format' => $data->{$field . 'format'}, 'itemid' => 0);
    }
    return $data;
}
Example #21
0
 /**
  * The numerical options control the display and the grading of the unit
  * part of the numerical question and related types (calculateds)
  * Questions previous to 2,0 do not have this table as multianswer questions
  * in all versions including 2,0. The default values are set to give the same grade
  * as old question.
  *
  */
 function save_numerical_options($question)
 {
     global $DB;
     $result = new stdClass();
     $update = true;
     $options = $DB->get_record('question_numerical_options', array('question' => $question->id));
     if (!$options) {
         $options = new stdClass();
         $options->question = $question->id;
         $options->instructions = '';
         $options->id = $DB->insert_record('question_numerical_options', $options);
     }
     if (isset($question->options->unitgradingtype)) {
         $options->unitgradingtype = $question->options->unitgradingtype;
     } else {
         $options->unitgradingtype = 0;
     }
     if (isset($question->unitpenalty)) {
         $options->unitpenalty = $question->unitpenalty;
     } else {
         //so this is either an old question or a close question type
         $options->unitpenalty = 1;
     }
     // if we came from the form then 'unitrole' exists
     if (isset($question->unitrole)) {
         switch ($question->unitrole) {
             case '0':
                 $options->showunits = NUMERICALQUESTIONUNITNODISPLAY;
                 break;
             case '1':
                 $options->showunits = NUMERICALQUESTIONUNITTEXTDISPLAY;
                 break;
             case '2':
                 $options->showunits = NUMERICALQUESTIONUNITTEXTINPUTDISPLAY;
                 $options->unitgradingtype = 0;
                 break;
             case '3':
                 $options->showunits = $question->multichoicedisplay;
                 $options->unitgradingtype = $question->unitgradingtypes;
                 break;
         }
     } else {
         if (isset($question->showunits)) {
             $options->showunits = $question->showunits;
         } else {
             if ($defaultunit = $this->get_default_numerical_unit($question)) {
                 // so units can be used
                 $options->showunits = NUMERICALQUESTIONUNITTEXTINPUTDISPLAY;
             } else {
                 // only numerical will be graded
                 $options->showunits = NUMERICALQUESTIONUNITNODISPLAY;
             }
         }
     }
     if (isset($question->unitsleft)) {
         $options->unitsleft = $question->unitsleft;
     } else {
         $options->unitsleft = 0;
     }
     if (isset($question->instructions) && is_array($question->instructions)) {
         $options->instructions = $this->import_or_save_files($question->instructions, $question->context, 'qtype_' . $question->qtype, 'instruction', $question->id);
         $options->instructionsformat = $question->instructions['format'];
     } else {
         $options->instructions = '';
         $options->instructionsformat = editors_get_preferred_format();
     }
     $DB->update_record('question_numerical_options', $options);
     return $result;
 }
Example #22
0
/**
 * Prepares 'editor' formslib element from data in database
 *
 * The passed $data record must contain field foobar, foobarformat and optionally foobartrust. This
 * function then copies the embedded files into draft area (assigning itemids automatically),
 * creates the form element foobar_editor and rewrites the URLs so the embedded images can be
 * displayed.
 * In your mform definition, you must have an 'editor' element called foobar_editor. Then you call
 * your mform's set_data() supplying the object returned by this function.
 *
 * @category files
 * @param stdClass $data database field that holds the html text with embedded media
 * @param string $field the name of the database field that holds the html text with embedded media
 * @param array $options editor options (like maxifiles, maxbytes etc.)
 * @param stdClass $context context of the editor
 * @param string $component
 * @param string $filearea file area name
 * @param int $itemid item id, required if item exists
 * @return stdClass modified data object
 */
function file_prepare_standard_editor($data, $field, array $options, $context = null, $component = null, $filearea = null, $itemid = null)
{
    $options = (array) $options;
    if (!isset($options['trusttext'])) {
        $options['trusttext'] = false;
    }
    if (!isset($options['forcehttps'])) {
        $options['forcehttps'] = false;
    }
    if (!isset($options['subdirs'])) {
        $options['subdirs'] = false;
    }
    if (!isset($options['maxfiles'])) {
        $options['maxfiles'] = 0;
        // no files by default
    }
    if (!isset($options['noclean'])) {
        $options['noclean'] = false;
    }
    //sanity check for passed context. This function doesn't expect $option['context'] to be set
    //But this function is called before creating editor hence, this is one of the best places to check
    //if context is used properly. This check notify developer that they missed passing context to editor.
    if (isset($context) && !isset($options['context'])) {
        //if $context is not null then make sure $option['context'] is also set.
        debugging('Context for editor is not set in editoroptions. Hence editor will not respect editor filters', DEBUG_DEVELOPER);
    } else {
        if (isset($options['context']) && isset($context)) {
            //If both are passed then they should be equal.
            if ($options['context']->id != $context->id) {
                $exceptionmsg = 'Editor context [' . $options['context']->id . '] is not equal to passed context [' . $context->id . ']';
                throw new coding_exception($exceptionmsg);
            }
        }
    }
    if (is_null($itemid) or is_null($context)) {
        $contextid = null;
        $itemid = null;
        if (!isset($data)) {
            $data = new stdClass();
        }
        if (!isset($data->{$field})) {
            $data->{$field} = '';
        }
        if (!isset($data->{$field . 'format'})) {
            $data->{$field . 'format'} = editors_get_preferred_format();
        }
        if (!$options['noclean']) {
            $data->{$field} = clean_text($data->{$field}, $data->{$field . 'format'});
        }
    } else {
        if ($options['trusttext']) {
            // noclean ignored if trusttext enabled
            if (!isset($data->{$field . 'trust'})) {
                $data->{$field . 'trust'} = 0;
            }
            $data = trusttext_pre_edit($data, $field, $context);
        } else {
            if (!$options['noclean']) {
                $data->{$field} = clean_text($data->{$field}, $data->{$field . 'format'});
            }
        }
        $contextid = $context->id;
    }
    if ($options['maxfiles'] != 0) {
        $draftid_editor = file_get_submitted_draft_itemid($field);
        $currenttext = file_prepare_draft_area($draftid_editor, $contextid, $component, $filearea, $itemid, $options, $data->{$field});
        $data->{$field . '_editor'} = array('text' => $currenttext, 'format' => $data->{$field . 'format'}, 'itemid' => $draftid_editor);
    } else {
        $data->{$field . '_editor'} = array('text' => $data->{$field}, 'format' => $data->{$field . 'format'}, 'itemid' => 0);
    }
    return $data;
}
Example #23
0
 public function data_preprocessing(&$default_values)
 {
     $editoroptions = feedback_get_editor_options();
     if ($this->current->instance) {
         // editing an existing feedback - let us prepare the added editor elements (intro done automatically)
         $draftitemid = file_get_submitted_draft_itemid('page_after_submit');
         $default_values['page_after_submit_editor']['text'] = file_prepare_draft_area($draftitemid, $this->context->id, 'mod_feedback', 'page_after_submit', false, $editoroptions, $default_values['page_after_submit']);
         $default_values['page_after_submit_editor']['format'] = $default_values['page_after_submitformat'];
         $default_values['page_after_submit_editor']['itemid'] = $draftitemid;
     } else {
         // adding a new feedback instance
         $draftitemid = file_get_submitted_draft_itemid('page_after_submit_editor');
         // no context yet, itemid not used
         file_prepare_draft_area($draftitemid, null, 'mod_feedback', 'page_after_submit', false);
         $default_values['page_after_submit_editor']['text'] = '';
         $default_values['page_after_submit_editor']['format'] = editors_get_preferred_format();
         $default_values['page_after_submit_editor']['itemid'] = $draftitemid;
     }
 }
Example #24
0
        $heading = get_string('yournewtopic', 'forum');
    }
}
if (forum_is_subscribed($USER->id, $forum->id)) {
    $subscribe = true;
} else {
    if (forum_user_has_posted($forum->id, 0, $USER->id)) {
        $subscribe = false;
    } else {
        // user not posted yet - use subscription default specified in profile
        $subscribe = !empty($USER->autosubscribe);
    }
}
$draftid_editor = file_get_submitted_draft_itemid('message');
$currenttext = file_prepare_draft_area($draftid_editor, $modcontext->id, 'mod_forum', 'post', empty($post->id) ? null : $post->id, array('subdirs' => true), $post->message);
$mform_post->set_data(array('attachments' => $draftitemid, 'general' => $heading, 'subject' => $post->subject, 'message' => array('text' => $currenttext, 'format' => empty($post->messageformat) ? editors_get_preferred_format() : $post->messageformat, 'itemid' => $draftid_editor), 'subscribe' => $subscribe ? 1 : 0, 'mailnow' => !empty($post->mailnow), 'userid' => $post->userid, 'parent' => $post->parent, 'discussion' => $post->discussion, 'course' => $course->id) + $page_params + (isset($post->format) ? array('format' => $post->format) : array()) + (isset($discussion->timestart) ? array('timestart' => $discussion->timestart) : array()) + (isset($discussion->timeend) ? array('timeend' => $discussion->timeend) : array()) + (isset($post->groupid) ? array('groupid' => $post->groupid) : array()) + (isset($discussion->id) ? array('discussion' => $discussion->id) : array()));
if ($fromform = $mform_post->get_data()) {
    if (empty($SESSION->fromurl)) {
        $errordestination = "{$CFG->wwwroot}/mod/forum/view.php?f={$forum->id}";
    } else {
        $errordestination = $SESSION->fromurl;
    }
    $fromform->itemid = $fromform->message['itemid'];
    $fromform->messageformat = $fromform->message['format'];
    $fromform->message = $fromform->message['text'];
    // WARNING: the $fromform->message array has been overwritten, do not use it anymore!
    $fromform->messagetrust = trusttext_trusted($modcontext);
    $contextcheck = isset($fromform->groupinfo) && has_capability('mod/forum:movediscussions', $modcontext);
    if ($fromform->edit) {
        // Updating a post
        unset($fromform->groupid);
Example #25
0
 /**
  * Function to create a dummy discussion.
  *
  * @param array|stdClass $record
  * @return stdClass the discussion object
  */
 public function create_discussion($record = null)
 {
     global $DB;
     // Increment the forum discussion count.
     $this->forumdiscussioncount++;
     $record = (array) $record;
     if (!isset($record['course'])) {
         throw new coding_exception('course must be present in phpunit_util::create_discussion() $record');
     }
     if (!isset($record['forum'])) {
         throw new coding_exception('forum must be present in phpunit_util::create_discussion() $record');
     }
     if (!isset($record['userid'])) {
         throw new coding_exception('userid must be present in phpunit_util::create_discussion() $record');
     }
     if (!isset($record['name'])) {
         $record['name'] = "Discussion " . $this->forumdiscussioncount;
     }
     if (!isset($record['subject'])) {
         $record['subject'] = "Subject for discussion " . $this->forumdiscussioncount;
     }
     if (!isset($record['message'])) {
         $record['message'] = html_writer::tag('p', 'Message for discussion ' . $this->forumdiscussioncount);
     }
     if (!isset($record['messageformat'])) {
         $record['messageformat'] = editors_get_preferred_format();
     }
     if (!isset($record['messagetrust'])) {
         $record['messagetrust'] = "";
     }
     if (!isset($record['assessed'])) {
         $record['assessed'] = '1';
     }
     if (!isset($record['groupid'])) {
         $record['groupid'] = "-1";
     }
     if (!isset($record['timestart'])) {
         $record['timestart'] = "0";
     }
     if (!isset($record['timeend'])) {
         $record['timeend'] = "0";
     }
     if (!isset($record['mailnow'])) {
         $record['mailnow'] = "0";
     }
     if (isset($record['timemodified'])) {
         $timemodified = $record['timemodified'];
     }
     if (!isset($record['pinned'])) {
         $record['pinned'] = FORUM_DISCUSSION_UNPINNED;
     }
     $record = (object) $record;
     // Add the discussion.
     $record->id = forum_add_discussion($record, null, null, $record->userid);
     if (isset($timemodified)) {
         // Enforce the time modified.
         $post = $DB->get_record('forum_posts', array('discussion' => $record->id));
         $record->timemodified = $timemodified;
         $post->modified = $post->created = $timemodified;
         $DB->update_record('forum_discussions', $record);
         $DB->update_record('forum_posts', $post);
     }
     return $record;
 }
Example #26
0
    /**
     * Constructor for the base assignment class
     *
     * Constructor for the base assignment class.
     * If cmid is set create the cm, course, assignment objects.
     * If the assignment is hidden and the user is not a teacher then
     * this prints a page header and notice.
     *
     * @global object
     * @global object
     * @param int $cmid the current course module id - not set for new assignments
     * @param object $assignment usually null, but if we have it we pass it to save db access
     * @param object $cm usually null, but if we have it we pass it to save db access
     * @param object $course usually null, but if we have it we pass it to save db access
     */
    function assignment_base($cmid='staticonly', $assignment=NULL, $cm=NULL, $course=NULL) {
        global $COURSE, $DB;

        if ($cmid == 'staticonly') {
            //use static functions only!
            return;
        }

        global $CFG;

        if ($cm) {
            $this->cm = $cm;
        } else if (! $this->cm = get_coursemodule_from_id('assignment', $cmid)) {
            print_error('invalidcoursemodule');
        }

        $this->context = get_context_instance(CONTEXT_MODULE, $this->cm->id);

        if ($course) {
            $this->course = $course;
        } else if ($this->cm->course == $COURSE->id) {
            $this->course = $COURSE;
        } else if (! $this->course = $DB->get_record('course', array('id'=>$this->cm->course))) {
            print_error('invalidid', 'assignment');
        }

        if ($assignment) {
            $this->assignment = $assignment;
        } else if (! $this->assignment = $DB->get_record('assignment', array('id'=>$this->cm->instance))) {
            print_error('invalidid', 'assignment');
        }

        $this->assignment->cmidnumber = $this->cm->idnumber; // compatibility with modedit assignment obj
        $this->assignment->courseid   = $this->course->id; // compatibility with modedit assignment obj

        $this->strassignment = get_string('modulename', 'assignment');
        $this->strassignments = get_string('modulenameplural', 'assignment');
        $this->strsubmissions = get_string('submissions', 'assignment');
        $this->strlastmodified = get_string('lastmodified');
        $this->pagetitle = strip_tags($this->course->shortname.': '.$this->strassignment.': '.format_string($this->assignment->name,true));

        // visibility handled by require_login() with $cm parameter
        // get current group only when really needed

    /// Set up things for a HTML editor if it's needed
        $this->defaultformat = editors_get_preferred_format();
    }
                $draftitemid = file_get_submitted_draft_itemid('attachments');
                file_prepare_draft_area($draftitemid, $filecontext->id, 'mod_forumng', 'draft', $draft->get_id(), $fileoptions);
                $initialvalues->attachments = $draftitemid;
                $messagedraftitemid = file_get_submitted_draft_itemid('message');
                $initialvalues->message = file_prepare_draft_area($messagedraftitemid, $filecontext->id, 'mod_forumng', 'draftmessage', $draft->get_id(), $fileoptions, $initialvalues->message);
                $initialvalues->message['itemid'] = $messagedraftitemid;
            }
            if ($edit || $draft) {
                $mform->set_data($initialvalues);
            } else {
                $draftitemid = file_get_submitted_draft_itemid('attachments');
                file_prepare_draft_area($draftitemid, $filecontext->id, 'mod_forumng', 'attachment', null, $fileoptions);
                $initialvalues->attachments = $draftitemid;
                $messagedraftitemid = file_get_submitted_draft_itemid('message');
                file_prepare_draft_area($messagedraftitemid, $filecontext->id, 'mod_forumng', 'message', 0, $fileoptions);
                $initialvalues->message = array('text' => '', 'format' => editors_get_preferred_format(), 'itemid' => $messagedraftitemid);
                $mform->set_data($initialvalues);
            }
            // Require JavaScript (form.js).
            $forum->print_form_js();
            // Print form
            $mform->display();
            // In iframe mode, inform parent that iframe has loaded.
            if ($iframe) {
                $PAGE->requires->js_init_code('window.parent.iframe_has_loaded(window);', true);
            }
            // Display footer
            print $out->footer();
        }
    }
} catch (Exception $e) {
Example #28
0
 if ($mform->is_cancelled()) {
     redirect($workshop->view_url());
 } elseif ($cansubmit and $formdata = $mform->get_data()) {
     if ($formdata->example == 0) {
         // this was used just for validation, it must be set to zero when dealing with normal submissions
         unset($formdata->example);
     } else {
         throw new coding_exception('Invalid submission form data value: example');
     }
     $timenow = time();
     if (is_null($submission->id)) {
         $formdata->workshopid = $workshop->id;
         $formdata->example = 0;
         $formdata->authorid = $USER->id;
         $formdata->timecreated = $timenow;
         $formdata->feedbackauthorformat = editors_get_preferred_format();
     }
     $formdata->timemodified = $timenow;
     $formdata->title = trim($formdata->title);
     $formdata->content = '';
     // updated later
     $formdata->contentformat = FORMAT_HTML;
     // updated later
     $formdata->contenttrust = 0;
     // updated later
     $formdata->late = 0x0;
     // bit mask
     if (!empty($workshop->submissionend) and $workshop->submissionend < time()) {
         $formdata->late = $formdata->late | 0x1;
     }
     if ($workshop->phase == workshop::PHASE_ASSESSMENT) {
Example #29
0
if (!($frmpost = $mform->get_data())) {
    if ($postid) {
        $post->post = $post->id;
        $post->general = $streditpost;
        $post->tags = oublog_get_tags_csv($post->id);
    } else {
        $post = new stdClass();
        $post->general = $straddpost;
    }
    $post->blog = $oublog->id;
    $draftitemid = file_get_submitted_draft_itemid('attachments');
    file_prepare_draft_area($draftitemid, $context->id, 'mod_oublog', 'attachment', empty($post->id) ? null : $post->id);
    $draftid_editor = file_get_submitted_draft_itemid('message');
    $currenttext = file_prepare_draft_area($draftid_editor, $context->id, 'mod_oublog', 'message', empty($post->id) ? null : $post->id, array('subdirs' => 0), empty($post->message) ? '' : $post->message);
    $post->attachments = $draftitemid;
    $post->message = array('text' => $currenttext, 'format' => empty($post->messageformat) ? editors_get_preferred_format() : $post->messageformat, 'itemid' => $draftid_editor);
    $mform->set_data($post);
    // Print the header
    if ($blogtype == 'personal') {
        $PAGE->navbar->add(fullname($oubloguser), new moodle_url('/user/view.php', array('id' => $oubloguser->id)));
        $PAGE->navbar->add(format_string($oubloginstance->name), $viewurl);
    }
    $PAGE->navbar->add($post->general);
    $PAGE->set_title(format_string($oublog->name));
    $PAGE->set_heading(format_string($course->fullname));
    echo $OUTPUT->header();
    $renderer = $PAGE->get_renderer('mod_oublog');
    echo $renderer->render_pre_postform($oublog, $cm);
    $mform->display();
    echo $OUTPUT->footer();
} else {