Permalink
Browse files

Merge branch 'wip-MDL-27810-master' of git://github.com/samhemelryk/m…

…oodle
  • Loading branch information...
2 parents 2fc832a + 6708a1f commit 555cc4b4a02d68bd48b5e9fce2288b334dde4f08 @stronk7 stronk7 committed Jun 21, 2011
View
@@ -102,6 +102,11 @@ class portfolio_add_button {
*/
public function __construct($options=null) {
global $SESSION, $CFG;
+
+ if (empty($CFG->enableportfolios)) {
+ debugging('Building portfolio add button while portfolios is disabled. This code can be optimised.', DEBUG_DEVELOPER);
+ }
+
$this->instances = portfolio_instances();
if (empty($options)) {
return true;
View
@@ -1866,23 +1866,25 @@ function print_user_files($userid=0, $return=false) {
$output = '';
- $fs = get_file_storage();
-
- $found = false;
-
$submission = $this->get_submission($userid);
+ if (!$submission) {
+ return $output;
+ }
- if (($submission) && $files = $fs->get_area_files($this->context->id, 'mod_assignment', 'submission', $submission->id, "timemodified", false)) {
- require_once($CFG->libdir.'/portfoliolib.php');
+ $fs = get_file_storage();
+ $files = $fs->get_area_files($this->context->id, 'mod_assignment', 'submission', $submission->id, "timemodified", false);
+ if (!empty($files)) {
require_once($CFG->dirroot . '/mod/assignment/locallib.php');
- $button = new portfolio_add_button();
+ if ($CFG->enableportfolios) {
+ require_once($CFG->libdir.'/portfoliolib.php');
+ $button = new portfolio_add_button();
+ }
foreach ($files as $file) {
$filename = $file->get_filename();
- $found = true;
$mimetype = $file->get_mimetype();
$path = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$this->context->id.'/mod_assignment/submission/'.$submission->id.'/'.$filename);
$output .= '<a href="'.$path.'" ><img src="'.$OUTPUT->pix_url(file_mimetype_icon($mimetype)).'" class="icon" alt="'.$mimetype.'" />'.s($filename).'</a>';
- if ($this->portfolio_exportable() && has_capability('mod/assignment:exportownsubmission', $this->context)) {
+ if ($CFG->enableportfolios && $this->portfolio_exportable() && has_capability('mod/assignment:exportownsubmission', $this->context)) {
$button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id, 'fileid' => $file->get_id()), '/mod/assignment/locallib.php');
$button->set_format_by_file($file);
$output .= $button->to_html(PORTFOLIO_ADD_ICON_LINK);
@@ -85,19 +85,21 @@ class assignment_files implements renderable {
public $course;
public function __construct($context, $itemid, $filearea='submission') {
global $USER, $CFG;
- require_once($CFG->libdir . '/portfoliolib.php');
$this->context = $context;
list($context, $course, $cm) = get_context_info_array($context->id);
$this->cm = $cm;
$this->course = $course;
$fs = get_file_storage();
$this->dir = $fs->get_area_tree($this->context->id, 'mod_assignment', $filearea, $itemid);
- $files = $fs->get_area_files($this->context->id, 'mod_assignment', $filearea, $itemid, "timemodified", false);
- if (count($files) >= 1 && has_capability('mod/assignment:exportownsubmission', $this->context)) {
- $button = new portfolio_add_button();
- $button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id), '/mod/assignment/locallib.php');
- $button->reset_formats();
- $this->portfolioform = $button->to_html();
+ if (!empty($CFG->enableportfolios)) {
+ require_once($CFG->libdir . '/portfoliolib.php');
+ $files = $fs->get_area_files($this->context->id, 'mod_assignment', $filearea, $itemid, "timemodified", false);
+ if (count($files) >= 1 && has_capability('mod/assignment:exportownsubmission', $this->context)) {
+ $button = new portfolio_add_button();
+ $button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id), '/mod/assignment/locallib.php');
+ $button->reset_formats();
+ $this->portfolioform = $button->to_html();
+ }
}
$this->preprocess($this->dir, $filearea);
}
@@ -107,13 +109,14 @@ public function preprocess($dir, $filearea) {
$this->preprocess($subdir, $filearea);
}
foreach ($dir['files'] as $file) {
- $button = new portfolio_add_button();
- if (has_capability('mod/assignment:exportownsubmission', $this->context)) {
- $button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id, 'fileid' => $file->get_id()), '/mod/assignment/locallib.php');
- $button->set_format_by_file($file);
- $file->portfoliobutton = $button->to_html(PORTFOLIO_ADD_ICON_LINK);
- } else {
- $file->portfoliobutton = '';
+ $file->portfoliobutton = '';
+ if (!empty($CFG->enableportfolios)) {
+ $button = new portfolio_add_button();
+ if (has_capability('mod/assignment:exportownsubmission', $this->context)) {
+ $button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id, 'fileid' => $file->get_id()), '/mod/assignment/locallib.php');
+ $button->set_format_by_file($file);
+ $file->portfoliobutton = $button->to_html(PORTFOLIO_ADD_ICON_LINK);
+ }
}
$url = file_encode_url("$CFG->wwwroot/pluginfile.php", '/'.$this->context->id.'/mod_assignment/'.$filearea.'/'.$file->get_itemid(). $file->get_filepath().$file->get_filename(), true);
$filename = $file->get_filename();
View
@@ -56,6 +56,8 @@
$navlinks = array();
+ $canexportsess = has_capability('mod/chat:exportsession', $context);
+
/// Print a session if one has been specified
if ($start and $end and !$confirmdelete) { // Show a full transcript
@@ -101,8 +103,8 @@
echo $formatmessage->html;
}
}
- $participated_cap = array_key_exists($USER->id, $participates) && has_capability('mod/chat:exportparticipatedsession', $context);
- if (has_capability('mod/chat:exportsession', $context) || $participated_cap) {
+ $participatedcap = array_key_exists($USER->id, $participates) && has_capability('mod/chat:exportparticipatedsession', $context);
+ if (!empty($CFG->enableportfolios) && ($canexportsess || $participatedcap)) {
require_once($CFG->libdir . '/portfoliolib.php');
$buttonoptions = array(
'id' => $cm->id,
@@ -227,9 +229,8 @@
echo '<p align="right">';
echo "<a href=\"report.php?id=$cm->id&amp;start=$sessionstart&amp;end=$sessionend\">$strseesession</a>";
- if (has_capability('mod/chat:exportsession', $context)
- || (array_key_exists($USER->id, $sessionusers)
- && has_capability('mod/chat:exportparticipatedsession', $context))) {
+ $participatedcap = (array_key_exists($USER->id, $sessionusers) && has_capability('mod/chat:exportparticipatedsession', $context));
+ if (!empty($CFG->enableportfolios) && ($canexportsess || $participatedcap)) {
require_once($CFG->libdir . '/portfoliolib.php');
$buttonoptions = array(
'id' => $cm->id,
@@ -257,7 +258,7 @@
$lasttime = $message->timestamp;
}
- if (has_capability('mod/chat:exportsession', $context)) {
+ if (!empty($CFG->enableportfolios) && $canexportsess) {
require_once($CFG->libdir . '/portfoliolib.php');
$button = new portfolio_add_button();
$button->set_callback_options('chat_portfolio_caller', array('id' => $cm->id), '/mod/chat/locallib.php');
View
@@ -1291,7 +1291,7 @@ function data_print_template($template, $records, $data, $search='', $page=0, $r
$patterns[]='##export##';
- if ($CFG->enableportfolios && ($template == 'singletemplate' || $template == 'listtemplate')
+ 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');
View
@@ -720,7 +720,7 @@
$records = array();
}
- if ($mode == '' && $CFG->enableportfolios) {
+ if ($mode == '' && !empty($CFG->enableportfolios)) {
require_once($CFG->libdir . '/portfoliolib.php');
$button = new portfolio_add_button();
$button->set_callback_options('data_portfolio_caller', array('id' => $cm->id), '/mod/data/locallib.php');
View
@@ -190,7 +190,7 @@
/// Print the controls across the top
echo '<div class="discussioncontrols clearfix">';
- if (has_capability('mod/forum:exportdiscussion', $modcontext) && (!empty($CFG->enableportfolios))) {
+ if (!empty($CFG->enableportfolios) && has_capability('mod/forum:exportdiscussion', $modcontext)) {
require_once($CFG->libdir.'/portfoliolib.php');
$button = new portfolio_add_button();
$button->set_callback_options('forum_portfolio_caller', array('discussionid' => $discussion->id), '/mod/forum/locallib.php');
View
@@ -3295,7 +3295,7 @@ function forum_print_post($post, $discussion, $forum, &$cm, $course, $ownpost=fa
$commands[] = array('url'=>new moodle_url('/mod/forum/post.php', array('reply'=>$post->id)), 'text'=>$str->reply);
}
- if ($cm->cache->caps['mod/forum:exportpost'] || ($ownpost && $cm->cache->caps['mod/forum:exportownpost'])) {
+ if ($CFG->enableportfolios && ($cm->cache->caps['mod/forum:exportpost'] || ($ownpost && $cm->cache->caps['mod/forum:exportownpost']))) {
$p = array('postid' => $post->id);
require_once($CFG->libdir.'/portfoliolib.php');
$button = new portfolio_add_button();
@@ -3932,46 +3932,49 @@ function forum_print_attachments($post, $cm, $type) {
$canexport = (has_capability('mod/forum:exportpost', $context) || ($post->userid == $USER->id && has_capability('mod/forum:exportownpost', $context)));
- require_once($CFG->libdir.'/portfoliolib.php');
- if ($files = $fs->get_area_files($context->id, 'mod_forum', 'attachment', $post->id, "timemodified", false)) {
- $button = new portfolio_add_button();
- foreach ($files as $file) {
- $filename = $file->get_filename();
- $mimetype = $file->get_mimetype();
- $iconimage = '<img src="'.$OUTPUT->pix_url(file_mimetype_icon($mimetype)).'" class="icon" alt="'.$mimetype.'" />';
- $path = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$context->id.'/mod_forum/attachment/'.$post->id.'/'.$filename);
-
- if ($type == 'html') {
- $output .= "<a href=\"$path\">$iconimage</a> ";
- $output .= "<a href=\"$path\">".s($filename)."</a>";
- if ($canexport) {
- $button->set_callback_options('forum_portfolio_caller', array('postid' => $post->id, 'attachment' => $file->get_id()), '/mod/forum/locallib.php');
- $button->set_format_by_file($file);
- $output .= $button->to_html(PORTFOLIO_ADD_ICON_LINK);
- }
- $output .= "<br />";
-
- } else if ($type == 'text') {
- $output .= "$strattachment ".s($filename).":\n$path\n";
-
- } else { //'returnimages'
- if (in_array($mimetype, array('image/gif', 'image/jpeg', 'image/png'))) {
- // Image attachments don't get printed as links
- $imagereturn .= "<br /><img src=\"$path\" alt=\"\" />";
- if ($canexport) {
- $button->set_callback_options('forum_portfolio_caller', array('postid' => $post->id, 'attachment' => $file->get_id()), '/mod/forum/locallib.php');
- $button->set_format_by_file($file);
- $imagereturn .= $button->to_html(PORTFOLIO_ADD_ICON_LINK);
- }
- } else {
+ if (!empty($CFG->enableportfolios)) {
+ require_once($CFG->libdir.'/portfoliolib.php');
+ $files = $fs->get_area_files($context->id, 'mod_forum', 'attachment', $post->id, "timemodified", false);
+ if ($files) {
+ $button = new portfolio_add_button();
+ foreach ($files as $file) {
+ $filename = $file->get_filename();
+ $mimetype = $file->get_mimetype();
+ $iconimage = '<img src="'.$OUTPUT->pix_url(file_mimetype_icon($mimetype)).'" class="icon" alt="'.$mimetype.'" />';
+ $path = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$context->id.'/mod_forum/attachment/'.$post->id.'/'.$filename);
+
+ if ($type == 'html') {
$output .= "<a href=\"$path\">$iconimage</a> ";
- $output .= format_text("<a href=\"$path\">".s($filename)."</a>", FORMAT_HTML, array('context'=>$context));
+ $output .= "<a href=\"$path\">".s($filename)."</a>";
if ($canexport) {
$button->set_callback_options('forum_portfolio_caller', array('postid' => $post->id, 'attachment' => $file->get_id()), '/mod/forum/locallib.php');
$button->set_format_by_file($file);
$output .= $button->to_html(PORTFOLIO_ADD_ICON_LINK);
}
- $output .= '<br />';
+ $output .= "<br />";
+
+ } else if ($type == 'text') {
+ $output .= "$strattachment ".s($filename).":\n$path\n";
+
+ } else { //'returnimages'
+ if (in_array($mimetype, array('image/gif', 'image/jpeg', 'image/png'))) {
+ // Image attachments don't get printed as links
+ $imagereturn .= "<br /><img src=\"$path\" alt=\"\" />";
+ if ($canexport) {
+ $button->set_callback_options('forum_portfolio_caller', array('postid' => $post->id, 'attachment' => $file->get_id()), '/mod/forum/locallib.php');
+ $button->set_format_by_file($file);
+ $imagereturn .= $button->to_html(PORTFOLIO_ADD_ICON_LINK);
+ }
+ } else {
+ $output .= "<a href=\"$path\">$iconimage</a> ";
+ $output .= format_text("<a href=\"$path\">".s($filename)."</a>", FORMAT_HTML, array('context'=>$context));
+ if ($canexport) {
+ $button->set_callback_options('forum_portfolio_caller', array('postid' => $post->id, 'attachment' => $file->get_id()), '/mod/forum/locallib.php');
+ $button->set_format_by_file($file);
+ $output .= $button->to_html(PORTFOLIO_ADD_ICON_LINK);
+ }
+ $output .= '<br />';
+ }
}
}
}
View
@@ -67,7 +67,7 @@
</form>
<?php
// don't need cap check here, we share with the general export.
- if ($DB->count_records('glossary_entries', array('glossaryid' => $glossary->id))) {
+ if (!empty($CFG->enableportfolios) && $DB->count_records('glossary_entries', array('glossaryid' => $glossary->id))) {
require_once($CFG->libdir . '/portfoliolib.php');
$button = new portfolio_add_button();
$button->set_callback_options('glossary_full_portfolio_caller', array('id' => $cm->id), '/mod/glossary/locallib.php');
View
@@ -1098,7 +1098,9 @@ function glossary_print_entry_icons($course, $cm, $glossary, $entry, $mode='',$h
$return .= get_string('entryishidden','glossary');
}
- if (has_capability('mod/glossary:manageentries', $context) or (isloggedin() and has_capability('mod/glossary:write', $context) and $entry->userid == $USER->id)) {
+ $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));
@@ -1129,9 +1131,7 @@ function glossary_print_entry_icons($course, $cm, $glossary, $entry, $mode='',$h
$return .= " <font size=\"-1\">" . get_string("exportedentry","glossary") . "</font>";
}
}
- if (has_capability('mod/glossary:exportentry', $context)
- || ($entry->userid == $USER->id
- && has_capability('mod/glossary:exportownentry', $context))) {
+ 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');
@@ -1155,21 +1155,19 @@ function glossary_print_entry_icons($course, $cm, $glossary, $entry, $mode='',$h
$return .= '</span>';
- if (has_capability('mod/glossary:comment', $context) and $glossary->allowcomments) {
+ 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 (!empty($CFG->usecomments)) {
- 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>';
- }
}
//If we haven't calculated any REAL thing, delete result ($return)

0 comments on commit 555cc4b

Please sign in to comment.