function get_content() { global $CFG, $PAGE; if (!$CFG->usecomments) { $this->content->text = ''; if ($this->page->user_is_editing()) { $this->content->text = get_string('disabledcomments'); } return $this->content; } if ($this->content !== NULL) { return $this->content; } if (empty($this->instance)) { return null; } $this->content->footer = ''; $this->content->text = ''; list($context, $course, $cm) = get_context_info_array($PAGE->context->id); $args = new stdClass(); $args->context = $PAGE->context; $args->course = $course; $args->area = 'page_comments'; $args->itemid = 0; // set 'env' to tell moodle tweak ui for this block $args->env = 'block_comments'; $args->component = 'block_comments'; $args->linktext = get_string('showcomments'); $comment = new comment($args); $comment->set_view_permission(true); $this->content = new stdClass(); $this->content->text = $comment->output(true); $this->content->footer = ''; return $this->content; }
function get_content() { global $CFG, $PAGE; if ($this->content !== NULL) { return $this->content; } if (!$CFG->usecomments) { $this->content = new stdClass(); $this->content->text = ''; if ($this->page->user_is_editing()) { $this->content->text = get_string('disabledcomments'); } return $this->content; } $this->content = new stdClass(); $this->content->footer = ''; $this->content->text = ''; if (empty($this->instance)) { return $this->content; } list($context, $course, $cm) = get_context_info_array($PAGE->context->id); $args = new stdClass(); $args->context = $PAGE->context; $args->course = $course; $args->area = 'page_comments'; $args->itemid = 0; $args->component = 'block_comments'; $args->linktext = get_string('showcomments'); $args->notoggle = true; $args->autostart = true; $args->displaycancel = false; $comment = new comment($args); $comment->set_view_permission(true); $comment->set_fullwidth(); $this->content = new stdClass(); $this->content->text = $comment->output(true); $this->content->footer = ''; return $this->content; }
/** * Prints or returns the HTML for this blog entry. * * @param bool $return * @return string */ public function print_html($return = false) { global $USER, $CFG, $COURSE, $DB, $OUTPUT, $PAGE; $user = $DB->get_record('user', array('id' => $this->userid)); $cmttext = ''; if (!empty($CFG->usecomments) and $CFG->blogusecomments) { require_once $CFG->dirroot . '/comment/lib.php'; // Comments $cmt = new stdClass(); $cmt->context = get_context_instance(CONTEXT_USER, $user->id); $cmt->courseid = $PAGE->course->id; $cmt->area = 'format_blog'; $cmt->itemid = $this->id; $cmt->showcount = $CFG->blogshowcommentscount; $cmt->component = 'blog'; $comment = new comment($cmt); $cmttext = $comment->output(true); } $this->summary = file_rewrite_pluginfile_urls($this->summary, 'pluginfile.php', SYSCONTEXTID, 'blog', 'post', $this->id); $options = array('overflowdiv' => true); $template['body'] = format_text($this->summary, $this->summaryformat, $options) . $cmttext; $template['title'] = format_string($this->subject); $template['userid'] = $user->id; $template['author'] = fullname($user); $template['created'] = userdate($this->created); if ($this->created != $this->lastmodified) { $template['lastmod'] = userdate($this->lastmodified); } $template['publishstate'] = $this->publishstate; $stredit = get_string('edit'); $strdelete = get_string('delete'); // Check to see if the entry is unassociated with group/course level access $unassociatedentry = false; if (!empty($CFG->useblogassociations) && ($this->publishstate == 'group' || $this->publishstate == 'course')) { if (!$DB->record_exists('blog_association', array('blogid' => $this->id))) { $unassociatedentry = true; } } // Start printing of the blog $table = new html_table(); $table->cellspacing = 0; $table->attributes['class'] = 'forumpost blog_entry blog' . ($unassociatedentry ? 'draft' : $template['publishstate']); $table->attributes['id'] = 'b' . $this->id; $table->width = '100%'; $picturecell = new html_table_cell(); $picturecell->attributes['class'] = 'picture left'; $picturecell->text = $OUTPUT->user_picture($user); $table->head[] = $picturecell; $topiccell = new html_table_cell(); $topiccell->attributes['class'] = 'topic starter'; $titlelink = html_writer::link(new moodle_url('/blog/index.php', array('entryid' => $this->id)), $template['title']); $topiccell->text = $OUTPUT->container($titlelink, 'subject'); $topiccell->text .= $OUTPUT->container_start('author'); $fullname = fullname($user, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $PAGE->course->id))); $by = new stdClass(); $by->name = html_writer::link(new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $PAGE->course->id)), $fullname); $by->date = $template['created']; $topiccell->text .= get_string('bynameondate', 'forum', $by); $topiccell->text .= $OUTPUT->container_end(); if ($this->uniquehash && $this->content) { if ($externalblog = $DB->get_record('blog_external', array('id' => $this->content))) { $urlparts = parse_url($externalblog->url); $topiccell->text .= $OUTPUT->container(get_string('retrievedfrom', 'blog') . get_string('labelsep', 'langconfig') . html_writer::link($urlparts['scheme'] . '://' . $urlparts['host'], $externalblog->name), 'externalblog'); } } $topiccell->header = false; $table->head[] = $topiccell; // Actual content $mainrow = new html_table_row(); $leftsidecell = new html_table_cell(); $leftsidecell->attributes['class'] = 'left side'; $mainrow->cells[] = $leftsidecell; $contentcell = new html_table_cell(); $contentcell->attributes['class'] = 'content'; $attachedimages = $OUTPUT->container($this->print_attachments(), 'attachments'); // retrieve associations in case they're needed early $blogassociations = $DB->get_records('blog_association', array('blogid' => $this->id)); // determine text for publish state switch ($template['publishstate']) { case 'draft': $blogtype = get_string('publishtonoone', 'blog'); break; case 'site': $blogtype = get_string('publishtosite', 'blog'); break; case 'public': $blogtype = get_string('publishtoworld', 'blog'); break; default: $blogtype = ''; break; } $contentcell->text .= $OUTPUT->container($blogtype, 'audience'); $contentcell->text .= $template['body']; $contentcell->text .= $attachedimages; // Uniquehash is used as a link to an external blog if (!empty($this->uniquehash)) { $contentcell->text .= $OUTPUT->container_start('externalblog'); $contentcell->text .= html_writer::link($this->uniquehash, get_string('linktooriginalentry', 'blog')); $contentcell->text .= $OUTPUT->container_end(); } // Links to tags $officialtags = tag_get_tags_csv('post', $this->id, TAG_RETURN_HTML, 'official'); $defaulttags = tag_get_tags_csv('post', $this->id, TAG_RETURN_HTML, 'default'); if (!empty($CFG->usetags) && ($officialtags || $defaulttags)) { $contentcell->text .= $OUTPUT->container_start('tags'); if ($officialtags) { $contentcell->text .= get_string('tags', 'tag') . ': ' . $OUTPUT->container($officialtags, 'officialblogtags'); if ($defaulttags) { $contentcell->text .= ', '; } } $contentcell->text .= $defaulttags; $contentcell->text .= $OUTPUT->container_end(); } // Add associations if (!empty($CFG->useblogassociations) && $blogassociations) { $contentcell->text .= $OUTPUT->container_start('tags'); $assocstr = ''; $hascourseassocs = false; $assoctype = ''; // First find and show the associated course foreach ($blogassociations as $assocrec) { $contextrec = $DB->get_record('context', array('id' => $assocrec->contextid)); if ($contextrec->contextlevel == CONTEXT_COURSE) { $assocurl = new moodle_url('/course/view.php', array('id' => $contextrec->instanceid)); $text = $DB->get_field('course', 'shortname', array('id' => $contextrec->instanceid)); //TODO: performance!!!! $assocstr .= $OUTPUT->action_icon($assocurl, new pix_icon('i/course', $text), null, array(), true); $hascourseassocs = true; $assoctype = get_string('course'); } } // Now show mod association foreach ($blogassociations as $assocrec) { $contextrec = $DB->get_record('context', array('id' => $assocrec->contextid)); if ($contextrec->contextlevel == CONTEXT_MODULE) { if ($hascourseassocs) { $assocstr .= ', '; $hascourseassocs = false; } $modinfo = $DB->get_record('course_modules', array('id' => $contextrec->instanceid)); $modname = $DB->get_field('modules', 'name', array('id' => $modinfo->module)); $assocurl = new moodle_url('/mod/' . $modname . '/view.php', array('id' => $modinfo->id)); $text = $DB->get_field($modname, 'name', array('id' => $modinfo->instance)); //TODO: performance!!!! $assocstr .= $OUTPUT->action_icon($assocurl, new pix_icon('icon', $text, $modname), null, array(), true); $assocstr .= ', '; $assoctype = get_string('modulename', $modname); } } $assocstr = substr($assocstr, 0, -2); $contentcell->text .= get_string('associated', 'blog', $assoctype) . ': ' . $assocstr; $contentcell->text .= $OUTPUT->container_end(); } if ($unassociatedentry) { $contentcell->text .= $OUTPUT->container(get_string('associationunviewable', 'blog'), 'noticebox'); } /// Commands $contentcell->text .= $OUTPUT->container_start('commands'); if (blog_user_can_edit_entry($this) && empty($this->uniquehash)) { $contentcell->text .= html_writer::link(new moodle_url('/blog/edit.php', array('action' => 'edit', 'entryid' => $this->id)), $stredit) . ' | '; $contentcell->text .= html_writer::link(new moodle_url('/blog/edit.php', array('action' => 'delete', 'entryid' => $this->id)), $strdelete) . ' | '; } $contentcell->text .= html_writer::link(new moodle_url('/blog/index.php', array('entryid' => $this->id)), get_string('permalink', 'blog')); $contentcell->text .= $OUTPUT->container_end(); if (isset($template['lastmod'])) { $contentcell->text .= '<div style="font-size: 55%;">'; $contentcell->text .= ' [ ' . get_string('modified') . ': ' . $template['lastmod'] . ' ]'; $contentcell->text .= '</div>'; } $mainrow->cells[] = $contentcell; $table->data = array($mainrow); if ($return) { return html_writer::table($table); } else { echo html_writer::table($table); } }
/** * Upgrade the submission from the old assignment to the new one * * @param context $oldcontext The context for the old assignment * @param stdClass $oldassignment The data record for the old assignment * @param stdClass $oldsubmission The data record for the old submission * @param stdClass $submission The new submission record * @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) { if ($oldsubmission->data1 != '') { // need to used this innit() otherwise it shows up undefined ! // require js for commenting comment::init(); $options = new stdClass(); $options->area = 'submission_comments_upgrade'; $options->course = $this->assignment->get_course(); $options->context = $this->assignment->get_context(); $options->itemid = $submission->id; $options->component = 'assignsubmission_comments'; $options->showcount = true; $options->displaycancel = true; $comment = new comment($options); $comment->add($oldsubmission->data1); $comment->set_view_permission(true); return $comment->output(true); } return true; }
/** * takes a list of records, the current data, a search string, * and mode to display prints the translated template * * @global object * @global object * @param string $template * @param array $records * @param object $data * @param string $search * @param int $page * @param bool $return * @return mixed */ function data_print_template($template, $records, $data, $search='', $page=0, $return=false) { global $CFG, $DB, $OUTPUT; $cm = get_coursemodule_from_instance('data', $data->id); $context = get_context_instance(CONTEXT_MODULE, $cm->id); static $fields = NULL; static $isteacher; static $dataid = NULL; if (empty($dataid)) { $dataid = $data->id; } else if ($dataid != $data->id) { $fields = NULL; } if (empty($fields)) { $fieldrecords = $DB->get_records('data_fields', array('dataid'=>$data->id)); foreach ($fieldrecords as $fieldrecord) { $fields[]= data_get_field($fieldrecord, $data); } $isteacher = has_capability('mod/data:managetemplates', $context); } if (empty($records)) { return; } foreach ($records as $record) { // Might be just one for the single template // Replacing tags $patterns = array(); $replacement = array(); // Then we generate strings to replace for normal tags foreach ($fields as $field) { $patterns[]='[['.$field->field->name.']]'; $replacement[] = highlight($search, $field->display_browse_field($record->id, $template)); } // Replacing special tags (##Edit##, ##Delete##, ##More##) $patterns[]='##edit##'; $patterns[]='##delete##'; if (has_capability('mod/data:manageentries', $context) or data_isowner($record->id)) { $replacement[] = '<a href="'.$CFG->wwwroot.'/mod/data/edit.php?d=' .$data->id.'&rid='.$record->id.'&sesskey='.sesskey().'"><img src="'.$OUTPUT->pix_url('t/edit') . '" class="iconsmall" alt="'.get_string('edit').'" title="'.get_string('edit').'" /></a>'; $replacement[] = '<a href="'.$CFG->wwwroot.'/mod/data/view.php?d=' .$data->id.'&delete='.$record->id.'&sesskey='.sesskey().'"><img src="'.$OUTPUT->pix_url('t/delete') . '" class="iconsmall" alt="'.get_string('delete').'" title="'.get_string('delete').'" /></a>'; } else { $replacement[] = ''; $replacement[] = ''; } $moreurl = $CFG->wwwroot . '/mod/data/view.php?d=' . $data->id . '&rid=' . $record->id; if ($search) { $moreurl .= '&filter=1'; } $patterns[]='##more##'; $replacement[] = '<a href="' . $moreurl . '"><img src="' . $OUTPUT->pix_url('i/search') . '" class="iconsmall" alt="' . get_string('more', 'data') . '" title="' . get_string('more', 'data') . '" /></a>'; $patterns[]='##moreurl##'; $replacement[] = $moreurl; $patterns[]='##user##'; $replacement[] = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$record->userid. '&course='.$data->course.'">'.fullname($record).'</a>'; $patterns[]='##export##'; if (!empty($CFG->enableportfolios) && ($template == 'singletemplate' || $template == 'listtemplate') && ((has_capability('mod/data:exportentry', $context) || (data_isowner($record->id) && has_capability('mod/data:exportownentry', $context))))) { require_once($CFG->libdir . '/portfoliolib.php'); $button = new portfolio_add_button(); $button->set_callback_options('data_portfolio_caller', array('id' => $cm->id, 'recordid' => $record->id), '/mod/data/locallib.php'); list($formats, $files) = data_portfolio_caller::formats($fields, $record); $button->set_formats($formats); $replacement[] = $button->to_html(PORTFOLIO_ADD_ICON_LINK); } else { $replacement[] = ''; } $patterns[] = '##timeadded##'; $replacement[] = userdate($record->timecreated); $patterns[] = '##timemodified##'; $replacement [] = userdate($record->timemodified); $patterns[]='##approve##'; if (has_capability('mod/data:approve', $context) && ($data->approval) && (!$record->approved)){ $replacement[] = '<span class="approve"><a href="'.$CFG->wwwroot.'/mod/data/view.php?d='.$data->id.'&approve='.$record->id.'&sesskey='.sesskey().'"><img src="'.$OUTPUT->pix_url('i/approve') . '" class="icon" alt="'.get_string('approve').'" /></a></span>'; } else { $replacement[] = ''; } $patterns[]='##comments##'; if (($template == 'listtemplate') && ($data->comments)) { if (!empty($CFG->usecomments)) { require_once($CFG->dirroot . '/comment/lib.php'); list($context, $course, $cm) = get_context_info_array($context->id); $cmt = new stdClass(); $cmt->context = $context; $cmt->course = $course; $cmt->cm = $cm; $cmt->area = 'database_entry'; $cmt->itemid = $record->id; $cmt->showcount = true; $cmt->component = 'mod_data'; $comment = new comment($cmt); $replacement[] = $comment->output(true); } } else { $replacement[] = ''; } // actual replacement of the tags $newtext = str_ireplace($patterns, $replacement, $data->{$template}); // no more html formatting and filtering - see MDL-6635 if ($return) { return $newtext; } else { echo $newtext; // hack alert - return is always false in singletemplate anyway ;-) /********************************** * Printing Ratings Form * *********************************/ if ($template == 'singletemplate') { //prints ratings options data_print_ratings($data, $record); } /********************************** * Printing Comments Form * *********************************/ if (($template == 'singletemplate') && ($data->comments)) { if (!empty($CFG->usecomments)) { require_once($CFG->dirroot . '/comment/lib.php'); list($context, $course, $cm) = get_context_info_array($context->id); $cmt = new stdClass(); $cmt->context = $context; $cmt->course = $course; $cmt->cm = $cm; $cmt->area = 'database_entry'; $cmt->itemid = $record->id; $cmt->showcount = true; $cmt->component = 'mod_data'; $comment = new comment($cmt); $comment->output(false); } } } } }
/** * takes a list of records, the current data, a search string, * and mode to display prints the translated template * * @global object * @global object * @param string $template * @param array $records * @param object $data * @param string $search * @param int $page * @param bool $return * @param object $jumpurl a moodle_url by which to jump back to the record list (can be null) * @return mixed */ function data_print_template($template, $records, $data, $search = '', $page = 0, $return = false, moodle_url $jumpurl = null) { global $CFG, $DB, $OUTPUT; $cm = get_coursemodule_from_instance('data', $data->id); $context = context_module::instance($cm->id); static $fields = NULL; static $isteacher; static $dataid = NULL; if (empty($dataid)) { $dataid = $data->id; } else { if ($dataid != $data->id) { $fields = NULL; } } if (empty($fields)) { $fieldrecords = $DB->get_records('data_fields', array('dataid' => $data->id)); foreach ($fieldrecords as $fieldrecord) { $fields[] = data_get_field($fieldrecord, $data); } $isteacher = has_capability('mod/data:managetemplates', $context); } if (empty($records)) { return; } if (!$jumpurl) { $jumpurl = new moodle_url('/mod/data/view.php', array('d' => $data->id)); } $jumpurl = new moodle_url($jumpurl, array('page' => $page, 'sesskey' => sesskey())); // Check whether this activity is read-only at present $readonly = data_in_readonly_period($data); foreach ($records as $record) { // Might be just one for the single template // Replacing tags $patterns = array(); $replacement = array(); // Then we generate strings to replace for normal tags foreach ($fields as $field) { $patterns[] = '[[' . $field->field->name . ']]'; $replacement[] = highlight($search, $field->display_browse_field($record->id, $template)); } $canmanageentries = has_capability('mod/data:manageentries', $context); // Replacing special tags (##Edit##, ##Delete##, ##More##) $patterns[] = '##edit##'; $patterns[] = '##delete##'; if ($canmanageentries || !$readonly && data_isowner($record->id)) { $replacement[] = '<a href="' . $CFG->wwwroot . '/mod/data/edit.php?d=' . $data->id . '&rid=' . $record->id . '&sesskey=' . sesskey() . '"><img src="' . $OUTPUT->pix_url('t/edit') . '" class="iconsmall" alt="' . get_string('edit') . '" title="' . get_string('edit') . '" /></a>'; $replacement[] = '<a href="' . $CFG->wwwroot . '/mod/data/view.php?d=' . $data->id . '&delete=' . $record->id . '&sesskey=' . sesskey() . '"><img src="' . $OUTPUT->pix_url('t/delete') . '" class="iconsmall" alt="' . get_string('delete') . '" title="' . get_string('delete') . '" /></a>'; } else { $replacement[] = ''; $replacement[] = ''; } $moreurl = $CFG->wwwroot . '/mod/data/view.php?d=' . $data->id . '&rid=' . $record->id; if ($search) { $moreurl .= '&filter=1'; } $patterns[] = '##more##'; $replacement[] = '<a href="' . $moreurl . '"><img src="' . $OUTPUT->pix_url('t/preview') . '" class="iconsmall" alt="' . get_string('more', 'data') . '" title="' . get_string('more', 'data') . '" /></a>'; $patterns[] = '##moreurl##'; $replacement[] = $moreurl; $patterns[] = '##delcheck##'; if ($canmanageentries) { $replacement[] = html_writer::checkbox('delcheck[]', $record->id, false, '', array('class' => 'recordcheckbox')); } else { $replacement[] = ''; } $patterns[] = '##user##'; $replacement[] = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $record->userid . '&course=' . $data->course . '">' . fullname($record) . '</a>'; $patterns[] = '##userpicture##'; $ruser = user_picture::unalias($record, null, 'userid'); $replacement[] = $OUTPUT->user_picture($ruser, array('courseid' => $data->course)); $patterns[] = '##export##'; if (!empty($CFG->enableportfolios) && ($template == 'singletemplate' || $template == 'listtemplate') && (has_capability('mod/data:exportentry', $context) || data_isowner($record->id) && has_capability('mod/data:exportownentry', $context))) { require_once $CFG->libdir . '/portfoliolib.php'; $button = new portfolio_add_button(); $button->set_callback_options('data_portfolio_caller', array('id' => $cm->id, 'recordid' => $record->id), 'mod_data'); list($formats, $files) = data_portfolio_caller::formats($fields, $record); $button->set_formats($formats); $replacement[] = $button->to_html(PORTFOLIO_ADD_ICON_LINK); } else { $replacement[] = ''; } $patterns[] = '##timeadded##'; $replacement[] = userdate($record->timecreated); $patterns[] = '##timemodified##'; $replacement[] = userdate($record->timemodified); $patterns[] = '##approve##'; if (has_capability('mod/data:approve', $context) && $data->approval && !$record->approved) { $approveurl = new moodle_url($jumpurl, array('approve' => $record->id)); $approveicon = new pix_icon('t/approve', get_string('approve', 'data'), '', array('class' => 'iconsmall')); $replacement[] = html_writer::tag('span', $OUTPUT->action_icon($approveurl, $approveicon), array('class' => 'approve')); } else { $replacement[] = ''; } $patterns[] = '##disapprove##'; if (has_capability('mod/data:approve', $context) && $data->approval && $record->approved) { $disapproveurl = new moodle_url($jumpurl, array('disapprove' => $record->id)); $disapproveicon = new pix_icon('t/block', get_string('disapprove', 'data'), '', array('class' => 'iconsmall')); $replacement[] = html_writer::tag('span', $OUTPUT->action_icon($disapproveurl, $disapproveicon), array('class' => 'disapprove')); } else { $replacement[] = ''; } $patterns[] = '##comments##'; if ($template == 'listtemplate' && $data->comments) { if (!empty($CFG->usecomments)) { require_once $CFG->dirroot . '/comment/lib.php'; list($context, $course, $cm) = get_context_info_array($context->id); $cmt = new stdClass(); $cmt->context = $context; $cmt->course = $course; $cmt->cm = $cm; $cmt->area = 'database_entry'; $cmt->itemid = $record->id; $cmt->showcount = true; $cmt->component = 'mod_data'; $comment = new comment($cmt); $replacement[] = $comment->output(true); } } else { $replacement[] = ''; } // actual replacement of the tags $newtext = str_ireplace($patterns, $replacement, $data->{$template}); // no more html formatting and filtering - see MDL-6635 if ($return) { return $newtext; } else { echo $newtext; // hack alert - return is always false in singletemplate anyway ;-) /********************************** * Printing Ratings Form * *********************************/ if ($template == 'singletemplate') { //prints ratings options data_print_ratings($data, $record); } /********************************** * Printing Comments Form * *********************************/ if ($template == 'singletemplate' && $data->comments) { if (!empty($CFG->usecomments)) { require_once $CFG->dirroot . '/comment/lib.php'; list($context, $course, $cm) = get_context_info_array($context->id); $cmt = new stdClass(); $cmt->context = $context; $cmt->course = $course; $cmt->cm = $cm; $cmt->area = 'database_entry'; $cmt->itemid = $record->id; $cmt->showcount = true; $cmt->component = 'mod_data'; $comment = new comment($cmt); $comment->output(false); } } } } }
/** * Upgrade the submission from the old setaskment to the new one * * @param context $oldcontext The context for the old setaskment * @param stdClass $oldsetaskment The data record for the old setaskment * @param stdClass $oldsubmission The data record for the old submission * @param stdClass $submission The new submission record * @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 $oldsetaskment, stdClass $oldsubmission, stdClass $submission, &$log) { if ($oldsubmission->data1 != '') { // Need to used this init() otherwise it does not have the javascript includes. comment::init(); $options = new stdClass(); $options->area = 'submission_comments_upgrade'; $options->course = $this->setaskment->get_course(); $options->context = $this->setaskment->get_context(); $options->itemid = $submission->id; $options->component = 'setasksubmission_comments'; $options->showcount = true; $options->displaycancel = true; $comment = new comment($options); $comment->add($oldsubmission->data1); $comment->set_view_permission(true); return $comment->output(true); } return true; }
/** * * @global object * @global object * @global object * @param object $course * @param object $cm * @param object $glossary * @param object $entry * @param string $mode * @param string $hook * @param string $type * @return string|void */ function glossary_print_entry_icons($course, $cm, $glossary, $entry, $mode='',$hook='', $type = 'print') { global $USER, $CFG, $DB, $OUTPUT; $context = get_context_instance(CONTEXT_MODULE, $cm->id); $output = false; //To decide if we must really return text in "return". Activate when needed only! $importedentry = ($entry->sourceglossaryid == $glossary->id); $ismainglossary = $glossary->mainglossary; $return = '<span class="commands">'; // Differentiate links for each entry. $altsuffix = ': '.strip_tags(format_text($entry->concept)); if (!$entry->approved) { $output = true; $return .= get_string('entryishidden','glossary'); } $iscurrentuser = ($entry->userid == $USER->id); if (has_capability('mod/glossary:manageentries', $context) or (isloggedin() and has_capability('mod/glossary:write', $context) and $iscurrentuser)) { // only teachers can export entries so check it out if (has_capability('mod/glossary:export', $context) and !$ismainglossary and !$importedentry) { $mainglossary = $DB->get_record('glossary', array('mainglossary'=>1,'course'=>$course->id)); if ( $mainglossary ) { // if there is a main glossary defined, allow to export the current entry $output = true; $return .= ' <a title="'.get_string('exporttomainglossary','glossary') . '" href="exportentry.php?id='.$entry->id.'&prevmode='.$mode.'&hook='.urlencode($hook).'"><img src="'.$OUTPUT->pix_url('export', 'glossary').'" class="iconsmall" alt="'.get_string('exporttomainglossary','glossary').$altsuffix.'" /></a>'; } } if ( $entry->sourceglossaryid ) { $icon = $OUTPUT->pix_url('minus', 'glossary'); // graphical metaphor (minus) for deleting an imported entry } else { $icon = $OUTPUT->pix_url('t/delete'); } //Decide if an entry is editable: // -It isn't a imported entry (so nobody can edit a imported (from secondary to main) entry)) and // -The user is teacher or he is a student with time permissions (edit period or editalways defined). $ineditperiod = ((time() - $entry->timecreated < $CFG->maxeditingtime) || $glossary->editalways); if ( !$importedentry and (has_capability('mod/glossary:manageentries', $context) or ($entry->userid == $USER->id and ($ineditperiod and has_capability('mod/glossary:write', $context))))) { $output = true; $return .= " <a title=\"" . get_string("delete") . "\" href=\"deleteentry.php?id=$cm->id&mode=delete&entry=$entry->id&prevmode=$mode&hook=".urlencode($hook)."\"><img src=\""; $return .= $icon; $return .= "\" class=\"iconsmall\" alt=\"" . get_string("delete") .$altsuffix."\" /></a> "; $return .= " <a title=\"" . get_string("edit") . "\" href=\"edit.php?cmid=$cm->id&id=$entry->id&mode=$mode&hook=".urlencode($hook)."\"><img src=\"" . $OUTPUT->pix_url('t/edit') . "\" class=\"iconsmall\" alt=\"" . get_string("edit") .$altsuffix. "\" /></a>"; } elseif ( $importedentry ) { $return .= " <font size=\"-1\">" . get_string("exportedentry","glossary") . "</font>"; } } if (!empty($CFG->enableportfolios) && (has_capability('mod/glossary:exportentry', $context) || ($iscurrentuser && has_capability('mod/glossary:exportownentry', $context)))) { require_once($CFG->libdir . '/portfoliolib.php'); $button = new portfolio_add_button(); $button->set_callback_options('glossary_entry_portfolio_caller', array('id' => $cm->id, 'entryid' => $entry->id), '/mod/glossary/locallib.php'); $filecontext = $context; if ($entry->sourceglossaryid == $cm->instance) { if ($maincm = get_coursemodule_from_instance('glossary', $entry->glossaryid)) { $filecontext = get_context_instance(CONTEXT_MODULE, $maincm->id); } } $fs = get_file_storage(); if ($files = $fs->get_area_files($filecontext->id, 'mod_glossary', 'attachment', $entry->id, "timemodified", false)) { $button->set_formats(PORTFOLIO_FORMAT_RICHHTML); } else { $button->set_formats(PORTFOLIO_FORMAT_PLAINHTML); } $return .= $button->to_html(PORTFOLIO_ADD_ICON_LINK); } $return .= " "; // just to make up a little the output in Mozilla ;) $return .= '</span>'; if (!empty($CFG->usecomments) && has_capability('mod/glossary:comment', $context) and $glossary->allowcomments) { require_once($CFG->dirroot . '/comment/lib.php'); $cmt = new stdClass(); $cmt->component = 'mod_glossary'; $cmt->context = $context; $cmt->course = $course; $cmt->cm = $cm; $cmt->area = 'glossary_entry'; $cmt->itemid = $entry->id; $cmt->showcount = true; $comment = new comment($cmt); $return .= '<div>'.$comment->output(true).'</div>'; $output = true; } //If we haven't calculated any REAL thing, delete result ($return) if (!$output) { $return = ''; } //Print or get if ($type == 'print') { echo $return; } else { return $return; } }
/** * Displays all comments for a single episode * @global stdClass $CFG * @param object $episode * @param object $cm * @param object $course */ function pcast_display_episode_comments($episode, $cm, $course) { global $CFG; $html = ''; if ($episode->userscancomment) { //Get episode comments and display the comment box $context = get_context_instance(CONTEXT_MODULE, $cm->id); $output = true; // Generate comment box using API if (!empty($CFG->usecomments)) { require_once $CFG->dirroot . '/comment/lib.php'; $cmt = new stdClass(); $cmt->component = 'pcast'; $cmt->context = $context; $cmt->course = $course; $cmt->cm = $cm; $cmt->area = 'pcast_episode'; $cmt->itemid = $episode->id; $cmt->showcount = true; $comment = new comment($cmt); $html = html_writer::tag('div', $comment->output(true), array('class' => 'pcast-comments')); } } echo $html; }
public function get_socialinfo() { global $CFG, $DB; $info = new \stdClass(); $info->ratings = null; $info->contextid = $this->get_context()->id; if ($this->gallery->can_like()) { $info->likes = $DB->count_records('mediagallery_userfeedback', array('itemid' => $this->record->id, 'liked' => 1)); $info->likedbyme = false; if ($fb = $this->get_userfeedback()) { if ($fb->liked) { $info->likedbyme = true; } } } if ($this->gallery->can_comment()) { $cmtopt = new \stdClass(); $cmtopt->area = 'item'; $cmtopt->context = $this->get_context(); $cmtopt->itemid = $this->record->id; $cmtopt->showcount = true; $cmtopt->component = 'mod_mediagallery'; $cmtopt->autostart = true; $comment = new \comment($cmtopt); $info->commentcontrol = $comment->output(true); preg_match('#comment-link-([\\w]+)#', $info->commentcontrol, $matches); $info->client_id = isset($matches[1]) ? $matches[1] : null; } // Creator name. $info->extradetails = ''; return $info; }
/** * */ public function display_browse($entry, $options = array()) { global $DB, $CFG; $field = $this->_field; $fieldid = $field->id; $df = $field->get_df(); // Only for existing entries. if (!($entry->id > 0)) { return ''; } $str = ''; require_once "{$CFG->dirroot}/comment/lib.php"; $cmt = new stdClass(); $cmt->context = $df->context; $cmt->courseid = $df->course->id; $cmt->cm = $df->cm; $cmt->itemid = $entry->id; $cmt->component = 'mod_dataform'; $cmt->area = $field->name; $cmt->showcount = isset($options['showcount']) ? $options['showcount'] : true; if (!empty($options['count'])) { $comment = new comment($cmt); $str = $comment->count(); } else { foreach ($options as $key => $val) { $cmt->{$key} = $val; } $comment = new comment($cmt); $str = $comment->output(true); } return $str; }
$showurl = new moodle_url($baseurl, array('action' => 'hide', 'sesskey' => sesskey())); $showicon = $OUTPUT->pix_icon('t/hide', get_string('hide')); } $showicon = html_writer::link($showurl, $showicon); $actions = array($editicon, $delicon, $showicon); echo '<strong>' . format_string($contrib->title) . '</strong> ' . implode(' ', $actions) . '</br>'; echo date('l jS F Y', $contrib->timemodified); echo '</br></br>'; $contribtext = file_rewrite_pluginfile_urls($contrib->content, 'pluginfile.php', $context->id, 'mod_giportfolio', 'contribution', $contrib->id); echo format_text($contribtext, $contrib->contentformat, array('noclean' => true, 'context' => $context)); echo '</br>'; $files = giportfolio_print_attachments($contrib, $cm, $type = null, $align = "right"); if ($files) { echo "<table border=\"0\" width=\"100%\" align=\"{$align}\"><tr><td align=\"{$align}\" nowrap=\"nowrap\">\n"; echo $files; echo "</td></tr></table>\n"; } echo '</br>'; $commentopts->itemid = $contrib->id; $commentbox = new comment($commentopts); echo $commentbox->output(); echo '</br>'; echo '</br>'; } } // SYNERGY. echo $OUTPUT->box_end(); echo '</br>'; // Lower navigation. echo '<div class="navbottom">' . $chnavigation . '</div>'; echo $OUTPUT->footer();
/** * * * * */ function render_resources_comments_ratings($course, $modules, $modinfo, $section, $page_context) { global $USER, $OUTPUT; foreach ($modules as $module) { $cm = $modinfo->get_cm($module->id); //Avoid comments and ratings for default 'News forum' if ($module->section == $section->id && $cm->name != 'News forum') { $url = new moodle_url('/mod/resource/view.php?id=' . $module->id); echo html_writer::link($url, $cm->name); // echo $cm->name . '<br>'; $args = new stdClass(); $args->context = $page_context; $args->course = $course; $args->area = 'resource'; $args->itemid = $module->id; $args->component = 'block_comments_and_ratings'; $args->showcount = true; $comment = new comment($args); $comment->set_fullwidth(); $comment->output(false); echo '<hr>'; // $ratingargs = new stdClass; // $ratingargs->context = $page_context; // $ratingargs->component = 'block_comments_and_ratings'; // $ratingargs->ratingarea = 'resource'; // $ratingargs->items = $modules; // $ratingargs->userid = $USER->id; // $ratingargs->scaleid = 1; // $ratingargs->aggregate = $cm->name; // $rm = new rating_manager(); // $modules = $rm->get_ratings($ratingargs); // // $output .= $OUTPUT->render($module->rating); } } }
if ($contribution->status != local_amos_contribution::STATE_REJECTED) { echo $output->single_button(new moodle_url($PAGE->url, array('reject' => $id)), get_string('contribreject', 'local_amos'), 'post', array('class' => 'singlebutton reject')); } } echo $output->help_icon('contribactions', 'local_amos'); echo html_writer::end_tag('div'); if (!empty($CFG->usecomments)) { $options = new stdClass(); $options->context = get_system_context(); $options->area = 'amos_contribution'; $options->itemid = $contribution->id; $options->showcount = true; $options->component = 'local_amos'; $options->autostart = true; $commentmanager = new comment($options); echo $output->container($commentmanager->output(), 'commentswrapper'); } echo $output->footer(); exit; } // Incoming contributions if (has_capability('local/amos:commit', get_system_context())) { $maintenances = $DB->get_records('amos_translators', array('userid' => $USER->id)); $maintainerof = array(); // list of languages the USER is maintainer of, or 'all' foreach ($maintenances as $maintained) { if ($maintained->lang === 'X') { $maintainerof = 'all'; break; } $maintainerof[] = $maintained->lang;