added two new contract methods to the caller class, load_data and expected_callbackargs (static)
this means that the base class is the only place that needs a constructor
and that no data loading happens in the constructor
this in turn means we can check callback argument validity much more lightly
also completely remoted portfolio_add_button function and replaced with a class
as the argument list was getting out of control. it's now much more readable.
$string['invalidbuttonproperty'] = 'Could not find that property ($a) of portfolio_button';
$string['manageportfolios'] = 'Manage portfolios';
$string['manageyourportfolios'] = 'Manage your portfolios';
+$string['missingcallbackarg'] = 'Missing callback argument $a->arg for class $a->class';
$string['moderatefilesizethreshold'] = 'Moderate transfer filesize';
$string['moderatefilesizethresholddesc'] = 'Filesizes over this threshold will be considered to take a moderate amount of time to transfer';
$string['moderatedbsizethreshold'] = 'Moderate transfer dbsize';
*/
protected $supportedformats;
+
+ public function __construct($callbackargs) {
+ $expected = call_user_func(array(get_class($this), 'expected_callbackargs'));
+ foreach ($expected as $key => $required) {
+ if (!array_key_exists($key, $callbackargs)) {
+ if ($required) {
+ $a = (object)array('key' => $key, 'class' => get_class($this));
+ throw new portfolio_caller_exception('missingcallbackarg', 'portfolio', null, $a);
+ }
+ continue;
+ }
+ $this->{$key} = $callbackargs[$key];
+ }
+ }
+
/**
* if this caller wants any additional config items
* they should be defined here.
public function heading_summary() {
return get_string('exportingcontentfrom', 'portfolio', $this->display_name());
}
+
+ public abstract function load_data();
+
+ public static abstract function expected_callbackargs();
+
}
/**
*/
protected $cm;
+ /**
+ *
+ * int cmid
+ */
+ protected $id;
+
/**
* stdclass course object
*/
if (!class_exists($class)) {
throw new portfolio_button_exception('nocallbackclass', 'portfolio', $class);
}
+
+ // this will throw exceptions
+ // but should not actually do anything other than verify callbackargs
+ $test = new $class($argarray);
+ unset($test);
+
$this->callbackclass = $class;
$this->callbackargs = $argarray;
}
}
}
-
-function portfolio_add_button($callbackclass, $callbackargs, $callbackfile=null, $format=PORTFOLIO_ADD_FULL_FORM, $addstr=null, $return=false, $callersupports=null) {
- $button = new portfolio_add_button();
- $button->set_callback_options($callbackclass, $callbackargs, $callbackfile);
- $button->set_formats($callersupports);
- if ($return) {
- return $button->to_html($format, $addstr);
- }
- $button->render();
-}
-
/**
* returns a drop menu with a list of available instances.
*
$found = false;
if ($files = $fs->get_area_files($this->context->id, 'assignment_submission', $userid, "timemodified", false)) {
- $p = array(
- 'assignmentid' => $this->cm->id,
- 'userid' => $USER->id,
- );
+ $button = new portfolio_add_button();
foreach ($files as $file) {
$filename = $file->get_filename();
$found = true;
$path = $browser->encodepath($CFG->wwwroot.'/pluginfile.php', '/'.$this->context->id.'/assignment_submission/'.$userid.'/'.$filename);
$output .= '<a href="'.$path.'" ><img src="'.$CFG->pixpath.'/f/'.$icon.'" class="icon" alt="'.$icon.'" />'.s($filename).'</a>';
if ($this->portfolio_exportable() && has_capability('mod/assignment:exportownsubmission', $this->context)) {
- $p['file'] = $file->get_id();
- $formats = array(portfolio_format_from_file($file));
- $output .= portfolio_add_button('assignment_portfolio_caller', $p, null, PORTFOLIO_ADD_ICON_LINK, null, true, $formats);
+ $button->set_formats(portfolio_format_from_file($file));
+ $button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id, 'file' => $file->get_id()));
+ $output .= $button->to_html(PORTFOLIO_ADD_ICON_LINK);
}
$output .= '<br />';
}
- if ($this->portfolio_exportable() && has_capability('mod/assignment:exportownsubmission', $this->context)) {
- unset($p['file']);// for all files
- $output .= '<br />' . portfolio_add_button('assignment_portfolio_caller', $p, null, PORTFOLIO_ADD_FULL_FORM, null, true);
+ if (count($files) > 1 && $this->portfolio_exportable() && has_capability('mod/assignment:exportownsubmission', $this->context)) {
+ $button->set_formats(PORTFOLIO_PORMAT_FILE);
+ $button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id));
+ $output .= '<br />' . $button->to_html();
}
}
private $assignment;
private $assignmentfile;
- private $file;
private $files;
+ protected $fileid;
- public function __construct($callbackargs) {
+ public static function expected_callbackargs() {
+ return array(
+ 'id' => true,
+ 'fileid' => false,
+ );
+ }
+
+ public function load_data() {
global $DB, $CFG;
- if (! $this->cm = get_coursemodule_from_id('assignment', $callbackargs['assignmentid'])) {
+ if (! $this->cm = get_coursemodule_from_id('assignment', $this->id)) {
throw new portfolio_caller_exception('invalidcoursemodule');
}
throw new portfolio_caller_exception('invalidid', 'assignment');
}
- if (!array_key_exists('userid', $callbackargs)) {
- throw new portfolio_caller_exception('invaliduserid', 'assignment');
- }
- if (!$this->user = $DB->get_record('user', array('id' => $callbackargs['userid']))) {
- throw new portfolio_caller_exception('invaliduserid', 'assignment');
- }
$this->assignmentfile = $CFG->dirroot . '/mod/assignment/type/' . $assignment->assignmenttype . '/assignment.class.php';
require_once($this->assignmentfile);
$assignmentclass = "assignment_$assignment->assignmenttype";
+
$this->assignment = new $assignmentclass($this->cm->id, $assignment, $this->cm);
+
if (!$this->assignment->portfolio_exportable()) {
throw new portfolio_caller_exception('notexportable', 'portfolio', $this->get_return_url());
}
+
$fs = get_file_storage();
- if (array_key_exists('file', $callbackargs)) {
- $this->file = $fs->get_file_by_id($callbackargs['file']);
- $this->files = array($this->file);
- $this->supportedformats = array(portfolio_format_from_file($this->file));
+ if ($this->fileid) {
+ $f = $fs->get_file_by_id($this->fileid);
+ $this->files = array($f);
} else {
$this->files = $fs->get_area_files($this->assignment->context->id, 'assignment_submission', $this->user->id, '', false);
}
+ if (is_array($this->files) && count($this->files) == 1) {
+ $f = array_values($this->files);
+ $this->supportedformats = array(portfolio_format_from_file($f[0]));
+ }
if (empty($this->supportedformats) && is_callable(array($this->assignment, 'portfolio_supported_formats'))) {
$this->supportedformats = $this->assignment->portfolio_supported_formats();
}
if (is_callable(array($this->assignment, 'portfolio_get_sha1'))) {
return $this->assignment->portfolio_get_sha1($this->user->id);
}
-
- // default ...
- if ($this->file) {
- return $this->file->get_contenthash();
- }
$sha1s = array();
foreach ($this->files as $file) {
$sha1s[] = $file->get_contenthash();
print_box_start('generalbox boxwidthwide boxaligncenter', 'online');
if ($submission && has_capability('mod/assignment:exportownsubmission', $this->context)) {
echo format_text($submission->data1, $submission->data2);
- $p = array(
- 'userid' => $USER->id,
- 'assignmentid' => $this->cm->id,
- );
- portfolio_add_button('assignment_portfolio_caller', $p, '/mod/assignment/lib.php');
+ $button = new portfolio_add_button();
+ $button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id), '/mod/assignment/lib.php');
+ $button->render();
} else if (!has_capability('mod/assignment:submit', $context)) { //fix for #4604
echo '<div style="text-align:center">'. get_string('guestnosubmit', 'assignment').'</div>';
} else if ($this->isopen()){ //fix for #4206
$browser = get_file_browser();
if ($files = $fs->get_area_files($this->context->id, 'assignment_submission', $userid, "timemodified", false)) {
- $p = array(
- 'assignmentid' => $this->cm->id,
- 'userid' => $USER->id,
- );
+ $button = new portfolio_add_button();
foreach ($files as $file) {
$filename = $file->get_filename();
$mimetype = $file->get_mimetype();
}
if (has_capability('mod/assignment:exportownsubmission', $this->context)) {
- $p['file'] = $file->get_id();
- $formats = array(portfolio_format_from_file($file));
- $output .= portfolio_add_button('assignment_portfolio_caller', $p, '/mod/assignment/lib.php', PORTFOLIO_ADD_ICON_LINK, null, true, $formats);
+ $button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id, 'file' => file->get_id()), '/mod/assignment/lib.php');
+ $button->set_formats(portfolio_format_from_file($file));
+ $output .= $button->to_html(PORTFOLIO_ADD_ICON_LINK);
}
$output .= '<br />';
}
- if (has_capability('mod/assignment:exportownsubmission', $this->context)) {
- unset($p['file']);// for all files
- $output .= '<br />' . portfolio_add_button('assignment_portfolio_caller', $p, '/mod/assignment/lib.php', null, null, true);
+ if (count($files) > 1 && has_capability('mod/assignment:exportownsubmission', $this->context)) {
+ $button->set_formats(PORTFOLIO_FORMAT_FILE);
+ $button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id), '/mod/assignment/lib.php');
+ $output .= $button->to_html();
}
}
class chat_portfolio_caller extends portfolio_module_caller_base {
private $chat;
- private $start;
- private $end;
+ protected $start;
+ protected $end;
+
+ public static function expected_callbackargs() {
+ return array(
+ 'id' => true,
+ 'start' => false,
+ 'end' => false,
+ );
+ }
+
+ public function load_data() {
+ global $DB;
- public function __construct($callbackargs) {
- global $DB, $USER;
- if (!$this->cm = get_coursemodule_from_id('chat', $callbackargs['id'])) {
+ if (!$this->cm = get_coursemodule_from_id('chat', $this->id)) {
throw new portfolio_caller_exception('invalidid', 'chat');
}
$this->chat = $DB->get_record('chat', array('id' => $this->cm->instance));
$select = 'chatid = ?';
$params = array($this->chat->id);
- if (array_key_exists('start', $callbackargs) && array_key_exists('end', $callbackargs)
- && !empty($callbackargs['start']) && !empty($callbackargs['end'])) {
+ if ($this->start && $this->end) {
$select .= ' AND timestamp >= ? AND timestamp <= ?';
- $params[] = $callbackargs['start'];
- $params[] = $callbackargs['end'];
- $this->start = $callbackargs['start'];
- $this->end = $callbackargs['end'];
+ $params[] = $this->start;
+ $params[] = $this->end;
}
$this->messages = $DB->get_records_select(
'chat_messages',
'timestamp ASC'
);
$select .= ' AND userid = ?';
- $params[] = $USER->id;
+ $params[] = $this->user->id;
$this->participated = $DB->record_exists_select(
'chat_messages',
$select,
$params
);
- $this->supportedformats = array(PORTFOLIO_FORMAT_HTML);
+ }
+
+ public static function supported_formats($caller) {
+ return array(PORTFOLIO_FORMAT_HTML);
}
public function expected_time() {
|| (array_key_exists($USER->id, $sessionusers)
&& has_capability('mod/chat:exportparticipatedsession', $context))) {
require_once($CFG->libdir . '/portfoliolib.php');
- $p = array(
+ $buttonoptions = array(
'id' => $cm->id,
'start' => $start,
'end' => $end,
);
- echo '<br />' . portfolio_add_button('chat_portfolio_caller', $p, '/mod/chat/lib.php', PORTFOLIO_ADD_FULL_FORM, null, true);
+ $button = new portfolio_add_button();
+ $button->set_callback_options('chat_portfolio_caller', $buttonoptions, '/mod/chat/lib.php');
+ $button->render();
}
print_simple_box_end();
}
|| (array_key_exists($USER->id, $sessionusers)
&& has_capability('mod/chat:exportparticipatedsession', $context))) {
require_once($CFG->libdir . '/portfoliolib.php');
- $p = array(
+ $buttonoptions = array(
'id' => $cm->id,
'start' => $sessionstart,
'end' => $sessionend,
);
- echo '<br />' . portfolio_add_button('chat_portfolio_caller', $p, '/mod/chat/lib.php', PORTFOLIO_ADD_TEXT_LINK, null, true);
+ $button = new portfolio_add_button();
+ $button->set_callback_options('chat_portfolio_caller', $buttonoptions, '/mod/chat/lib.php');
+ $button->render(PORTFOLIO_ADD_TEXT_LINK);
}
if (has_capability('mod/chat:deletelog', $context)) {
echo "<br /><a href=\"report.php?id=$cm->id&start=$sessionstart&end=$sessionend&deletesession=1\">$strdeletesession</a>";
if (has_capability('mod/chat:exportsession', $context)) {
require_once($CFG->libdir . '/portfoliolib.php');
- $p = array(
- 'id' => $cm->id,
- );
- echo '<br />' . portfolio_add_button('chat_portfolio_caller', $p, '/mod/chat/lib.php', PORTFOLIO_ADD_FULL_FORM, get_string('addalltoportfolio', 'portfolio'), true);
+ $button = new portfolio_add_button();
+ $button->set_callback_options('chat_portfolio_caller', array('id' => $cm->id), '/mod/chat/lib.php');
+ $button->render(null, get_string('addalltoportfolio', 'portfolio'));
}
&& ((has_capability('mod/data:exportentry', $context)
|| (data_isowner($record->id) && has_capability('mod/data:exportownentry', $context))))) {
require_once($CFG->libdir . '/portfoliolib.php');
- $replacement[] = portfolio_add_button('data_portfolio_caller', array('id' => $cm->id, 'record' => $record->id), null, PORTFOLIO_ADD_ICON_LINK, null, true);
+ $button = new portfolio_add_button();
+ $button->set_callback_options('data_portfolio_caller', array('id' => $cm->id, 'record' => $record->id));
+ $button->set_formats(PORTFOLIO_FORMAT_HTML);
+ $replacement[] = $button->to_html(PORTFOLIO_ADD_ICON_LINK);
} else {
$replacement[] = '';
}
require_once($CFG->libdir . '/portfoliolib.php');
class data_portfolio_caller extends portfolio_module_caller_base {
+ protected $recordid;
+ protected $exporttype;
+ protected $delimiter_name;
+
private $data;
private $selectedfields;
- private $exporttype;
private $fields;
private $fieldtypes;
- private $delimiter;
private $exportdata;
private $singlerecord;
+ public static function expected_callbackargs() {
+ return array(
+ 'id' => true,
+ 'recordid' => false,
+ 'delimiter_name' => false,
+ 'exporttype' => false,
+ );
+ }
+
public function __construct($callbackargs) {
+ parent::__construct($callbackargs);
+ if (empty($this->exporttype)) {
+ $this->exporttype = 'csv';
+ }
+ $this->selectedfields = array();
+ foreach ($callbackargs as $key => $value) {
+ if (strpos($key, 'field_') === 0) {
+ $this->selectedfields[] = substr($key, 6);
+ }
+ }
+ }
+
+ public function load_data() {
global $DB;
- if (!$this->cm = get_coursemodule_from_id('data', $callbackargs['id'])) {
+ if (!$this->cm = get_coursemodule_from_id('data', $this->id)) {
throw new portfolio_caller_exception('invalidid', 'data');
}
$this->data = $DB->get_record('data', array('id' => $this->cm->instance));
$this->fieldtypes[] = $tmp->type;
}
- if (array_key_exists('record', $callbackargs) && !empty($callbackargs['record'])) {
+ if ($this->recordid) {
//user has selected to export one single entry rather than the whole thing
// which is completely different
- $this->singlerecord = $DB->get_record('data_records', array('id' => $callbackargs['record']));
+ $this->singlerecord = $DB->get_record('data_records', array('id' => $this->recordid));
$this->singlerecord->content = $DB->get_records('data_content', array('recordid' => $this->singlerecord->id));
$this->exporttype = 'single';
$this->supportedformats = array(PORTFOLIO_FORMAT_HTML);
} else {
// all records as csv or whatever
- $this->selectedfields = array();
- foreach ($callbackargs as $key => $value) {
- if (strpos($key, 'field_') === 0) {
- $this->selectedfields[] = substr($key, 6);
- }
- }
- $this->delimiter = array_key_exists('delimiter_name', $callbackargs) ? $callbackargs['delimiter_name'] : null;
- $this->exporttype = array_key_exists('exporttype', $callbackargs) ? $callbackargs['exporttype'] : 'csv'; //@todo penny later support more
$this->exportdata = data_get_exportdata($this->cm->instance, $this->fields, $this->selectedfields);
}
}
$filename = clean_filename($this->cm->name . '-entry.html');
break;
case 'csv':
- $content = data_export_csv($this->exportdata, $this->delimiter, $this->cm->name, $count, true);
+ $content = data_export_csv($this->exportdata, $this->delimiter_name, $this->cm->name, $count, true);
$filename = clean_filename($this->cm->name . '.csv');
break;
case 'xls':
/// Print the controls across the top
- if (has_capability('mod/forum:exportdiscussion', $modcontext)) {
-
- $p = array(
- 'discussionid' => $discussion->id,
- );
- $portfolio = portfolio_add_button('forum_portfolio_caller', $p, '/mod/forum/lib.php', null, null, true);
- }
echo '<table width="100%" class="discussioncontrols"><tr><td>';
// groups selector not needed here
forum_print_mode_form($discussion->id, $displaymode);
echo "</td><td>";
- if (isset($portfolio)) {
- echo $portfolio . '</td><td>';
+ if (has_capability('mod/forum:exportdiscussion', $modcontext)) {
+ $button = new portfolio_add_button();
+ $button->set_callback_options('forum_portfolio_caller', array('discussionid' => $discussion->id), '/mod/forum/lib.php');
+ $button->render();
+ echo '</td><td>';
}
if ($forum->type != 'single'
$p = array(
'postid' => $post->id,
);
- $commands[] = portfolio_add_button('forum_portfolio_caller', $p, '/mod/forum/lib.php', PORTFOLIO_ADD_TEXT_LINK, null, true);
+ $button = new portfolio_add_button();
+ $button->set_callback_options('forum_portfolio_caller', array('postid' => $post->id));
+ if (empty($attachments)) {
+ $button->set_formats(PORTFOLIO_FORMAT_HTML);
+ }
+ $commands[] = $button->to_html(PORTFOLIO_ADD_TEXT_LINK);
}
echo '<div class="commands">';
$canexport = (has_capability('mod/forum:exportpost', $context) || ($post->userid == $USER->id && has_capability('mod/forum:exportownpost')));
if ($files = $fs->get_area_files($context->id, 'forum_attachment', $post->id, "timemodified", false)) {
+ require_once($CFG->libdir . '/portfoliolib.php');
+ $button = new portfolio_add_button();
foreach ($files as $file) {
$filename = $file->get_filename();
$mimetype = $file->get_mimetype();
$output .= "<a href=\"$path\">$iconimage</a> ";
$output .= "<a href=\"$path\">".s($filename)."</a>";
if ($canexport) {
- require_once($CFG->libdir . '/portfoliolib.php');
- $p = array(
- 'postid' => $post->id,
- 'attachment' => $file->get_id(),
- );
- $output .= portfolio_add_button(
- 'forum_portfolio_caller',
- $p, '/mod/forum/lib.php',
- PORTFOLIO_ADD_ICON_LINK,
- null, true,
- array(portfolio_format_from_file($file))
- );
+ $button->set_callback_options('forum_portfolio_caller', array('postid' => $post->id, 'attachment' => $file->get_id()));
+ $button->set_formats(portfolio_format_from_file($file));
+ $output .= $button->to_html(PORTFOLIO_ADD_ICON_LINK);
}
$output .= "<br />";
// Image attachments don't get printed as links
$imagereturn .= "<br /><img src=\"$path\" alt=\"\" />";
if ($canexport) {
- require_once($CFG->libdir . '/portfoliolib.php');
- $p = array(
- 'postid' => $post->id,
- 'attachment' => $file->get_id(),
- );
- $imagereturn .= portfolio_add_button(
- 'forum_portfolio_caller',
- $p, '/mod/forum/lib.php',
- PORTFOLIO_ADD_ICON_LINK,
- null, true,
- array(portfolio_format_from_file($file))
- );
+ $button->set_callback_options('forum_portfolio_caller', array('postid' => $post->id, 'attachment' => $file->get_id()));
+ $button->set_formats(portfolio_format_from_file($file));
+ $imagereturn .= $button->to_html(PORTFOLIO_ADD_ICON_LINK);
}
} else {
$output .= "<a href=\"$path\">$iconimage</a> ";
$output .= filter_text("<a href=\"$path\">".s($filename)."</a>");
if ($canexport) {
- require_once($CFG->libdir . '/portfoliolib.php');
- $p = array(
- 'postid' => $post->id,
- 'attachment' => $file->get_id(),
- );
- $output .= portfolio_add_button(
- 'forum_portfolio_caller',
- $p, '/mod/forum/lib.php',
- PORTFOLIO_ADD_ICON_LINK,
- null, true,
- array(portfolio_format_from_file($file))
- );
+ $button->set_callback_options('forum_portfolio_caller', array('postid' => $post->id, 'attachment' => $file->get_id()));
+ $button->set_formats(portfolio_format_from_file($file));
+ $output .= $button->to_html(PORTFOLIO_ADD_ICON_LINK);
}
$output .= '<br />';
}
require_once($CFG->libdir . '/portfoliolib.php');
class forum_portfolio_caller extends portfolio_module_caller_base {
+ protected $postid;
+ protected $discussionid;
+ protected $attachment;
+
private $post;
private $forum;
private $discussion;
- private $attachment;
private $postfiles;
private $allfiles;
private $posts;
+ public static function expected_callbackargs() {
+ return array(
+ 'postid' => false,
+ 'discussionid' => false,
+ 'attachment' => false,
+ );
+ }
+
function __construct($callbackargs) {
+ parent::__construct($callbackargs);
+ if (!$this->postid && !$this->discussionid) {
+ throw new portfolio_caller_exception('mustprovidediscussionorpost', 'forum');
+ }
+ }
+
+ public function load_data() {
global $DB;
- if (array_key_exists('postid', $callbackargs)) {
- if (!$this->post = $DB->get_record('forum_posts', array('id' => $callbackargs['postid']))) {
+ if ($this->postid) {
+ if (!$this->post = $DB->get_record('forum_posts', array('id' => $this->postid))) {
throw new portfolio_caller_exception('invalidpostid', 'forum');
}
}
+
$dparams = array();
- if (array_key_exists('discussionid', $callbackargs)) {
- $dbparams = array('id' => $callbackargs['discussionid']);
+ if ($this->discussionid) {
+ $dbparams = array('id' => $this->discussionid);
} else if ($this->post) {
$dbparams = array('id' => $this->post->discussion);
} else {
throw new portfolio_caller_exception('mustprovidediscussionorpost', 'forum');
}
+
if (!$this->discussion = $DB->get_record('forum_discussions', $dbparams)) {
throw new portfolio_caller_exception('invaliddiscussionid', 'forum');
}
+
if (!$this->forum = $DB->get_record('forum', array('id' => $this->discussion->forum))) {
throw new portfolio_caller_exception('invalidforumid', 'forum');
}
+
if (!$this->cm = get_coursemodule_from_instance('forum', $this->forum->id)) {
throw new portfolio_caller_exception('invalidcoursemodule');
}
+
$fs = get_file_storage();
- if ($this->attachment = (array_key_exists('attachment', $callbackargs) ? $callbackargs['attachment'] : false)) {
- if (!$this->post) {
- throw new portfolio_caller_exception('attachmentsnopost', 'forum');
- }
+ if ($this->attachment) {
if (!$f = $fs->get_file_by_id($this->attachment)) {
throw new portfolio_caller_exception('noattachments', 'forum');
}
// don't need cap check here, we share with the general export.
if ($DB->count_records('glossary_entries', array('glossaryid' => $glossary->id))) {
require_once($CFG->libdir . '/portfoliolib.php');
- $p = array(
- 'id' => $cm->id,
- );
- portfolio_add_button('glossary_csv_portfolio_caller', $p, '/mod/glossary/lib.php');
+ $button = new portfolio_add_button();
+ $button->set_callback_options('glossary_csv_portfolio_caller', array('id' => $cm->id), '/mod/glossary/lib.php');
+ $button->render();
}
print_box_end();
print_footer($course);
|| ($entry->userid == $USER->id
&& has_capability('mod/glossary:exportownentry', $context))) {
require_once($CFG->libdir . '/portfoliolib.php');
- $p = array(
- 'id' => $cm->id,
- 'entryid' => $entry->id,
- );
- $return .= portfolio_add_button('glossary_entry_portfolio_caller', $p, null, PORTFOLIO_ADD_ICON_LINK, null, true);
+ $button = new portfolio_add_button();
+ $button->set_callback_options('glossary_entry_portfolio_caller', array('id' => $cm->id, 'entryid' => $entry->id));
+ $return .= $button->to_html(PORTFOLIO_ADD_ICON_LINK);
}
$return .= " "; // just to make up a little the output in Mozilla ;)
private $glossary;
private $exportdata;
- public function __construct($callbackargs) {
+ public static function expected_callbackargs() {
+ return array(
+ 'id' => true,
+ );
+ }
+
+ public function load_data() {
global $DB;
- if (!$this->cm = get_coursemodule_from_id('glossary', $callbackargs['id'])) {
+ if (!$this->cm = get_coursemodule_from_id('glossary', $this->id)) {
throw new portfolio_caller_exception('invalidid', 'glossary');
}
if (!$this->glossary = $DB->get_record('glossary', array('id' => $this->cm->instance))) {
private $glossary;
private $entry;
+ protected $entryid;
- public function __construct($callbackargs) {
+ public static function expected_callbackargs() {
+ return array(
+ 'entryid' => true,
+ 'id' => true,
+ );
+ }
+
+ public function load_data() {
global $DB;
- if (!$this->cm = get_coursemodule_from_id('glossary', $callbackargs['id'])) {
+ if (!$this->cm = get_coursemodule_from_id('glossary', $this->id)) {
throw new portfolio_caller_exception('invalidid', 'glossary');
}
if (!$this->glossary = $DB->get_record('glossary', array('id' => $this->cm->instance))) {
throw new portfolio_caller_exception('invalidid', 'glossary');
}
- if (!array_key_exists('entryid', $callbackargs)
- || !$this->entry = $DB->get_record('glossary_entries', array('id' => $callbackargs['entryid']))) {
- throw new portfolio_caller_exception('noentry', 'glossary');
+ if ($this->entryid) {
+ if (!$this->entry = $DB->get_record('glossary_entries', array('id' => $this->entryid))) {
+ throw new portfolio_caller_exception('noentry', 'glossary');
+ }
+ // in case we don't have USER this will make the entry be printed
+ $this->entry->approved = true;
}
$this->supportedformats = array(PORTFOLIO_FORMAT_HTML);
}
}
public function prepare_package() {
- // in case we don't have USER this will make the entry be printed
- $this->entry->approved = true;
define('PORTFOLIO_INTERNAL', true);
ob_start();
- glossary_print_entry($this->get('course'), $this->cm, $this->glossary, $this->entry, null, null, false);
+ $entry = clone $this->entry;
+ glossary_print_entry($this->get('course'), $this->cm, $this->glossary, $entry, null, null, false);
$content = ob_get_clean();
return $this->exporter->write_new_file($content, clean_filename($this->entry->concept) . '.html');
}
private $resource;
private $resourcefile;
- public function __construct($callbackargs) {
- global $CFG;
- global $DB;
- if (!array_key_exists('id', $callbackargs) || !$this->cm = get_coursemodule_from_instance('resource', $callbackargs['id'])) {
+ public static function expected_callbackargs() {
+ return array(
+ 'id' => true,
+ );
+ }
+
+ public function load_data() {
+ global $CFG, $DB;
+ if (!$this->cm = get_coursemodule_from_instance('resource', $this->id)) {
throw new portfolio_caller_exception('invalidid');
}
$this->cm->type = $DB->get_field('resource', 'type', array('id' => $this->cm->instance));
$this->resourcefile = $CFG->dirroot.'/mod/resource/type/'.$this->cm->type.'/resource.class.php';
require_once($this->resourcefile);
$this->resource= new $resourceclass($this->cm->id);
+ $this->supportedformats = array(self::type_to_format($this->cm->type));
+ }
+
+ public static function type_to_format($type) {
// this is kind of yuk... but there's just not good enough OO here
$format = PORTFOLIO_FORMAT_FILE;
- switch ($this->cm->type) {
+ switch ($type) {
case 'html':
$format = PORTFOLIO_FORMAT_HTML;
case 'text':
case 'file':
// $format = portfolio_format_from_file($file); // change after we switch upload type resources over to new files api.
}
- $this->supportedformats = array($format);
+ return $format;
}
public function __wakeup() {
debugging(get_string('portfolionotimplemented', 'resource'));
return false;
}
- $callersupports = array();
+ $callersupports = array(self::type_to_format($resource->cm->type));
if ($resource->cm->type == 'file') {
// $callersupports = array(portfolio_format_from_file($file);
}
- return portfolio_add_button('resource_portfolio_caller', array('id' => $resource->cm->instance), '/mod/resource/lib.php', $format, null, $return, $callersupports);
+ $button = new portfolio_add_button();
+ $button->set_callback_options('resource_portfolio_caller', array('id' => $resource->cm->instance), '/mod/resource/lib.php');
+ $button->set_formats($callersupports);
+ if ($return) {
+ return $button->to_html($format);
+ }
+ $button->render($format);
}
public function get_sha1() {
require_once($CFG->dirroot . $callbackfile);
$caller = new $callbackclass($callbackargs);
$caller->set('user', $USER);
+ $caller->load_data();
if (!$caller->check_permissions()) {
throw new portfolio_caller_exception('nopermissions', 'portfolio', $caller->get_return_url());
}