MDL-14591: changed the definition of portfolio_add_button

to support passing the callbackfile explicitly if necessary
        and added my name next to some TODOs so I can find them later
This commit is contained in:
mjollnir_ 2008-07-25 10:31:10 +00:00
parent 32fe576f6a
commit ed1fcf794b
4 changed files with 27 additions and 16 deletions

View File

@ -135,12 +135,16 @@ define('PORTFOLIO_TIME_HIGH', 'high');
* back to the callback functions (passed by reference)
* these MUST be primatives to be added as hidden form fields.
* and the values get cleaned to PARAM_ALPHAEXT or PARAM_NUMBER or PARAM_PATH
* @param string $callbackfile this can be autodetected if it's in the same file as your caller,
* but more often, the caller is a script.php and the class in a lib.php
* so you can pass it here if necessary.
* this path should be relative (ie, not include) dirroot
* @param boolean $fullform either display the fullform with the dropmenu of available instances
* or just a small icon (which will trigger instance selection in a new screen)
* optional, defaults to true.
* @param boolean $return whether to echo or return content (optional defaults to false (echo)
*/
function portfolio_add_button($callbackclass, $callbackargs, $fullform=true, $return=false) {
function portfolio_add_button($callbackclass, $callbackargs, $callbackfile=null, $fullform=true, $return=false) {
global $SESSION, $CFG, $COURSE, $USER;
@ -148,13 +152,20 @@ function portfolio_add_button($callbackclass, $callbackargs, $fullform=true, $re
return;
}
$backtrace = debug_backtrace();
if (!array_key_exists(0, $backtrace) || !array_key_exists('file', $backtrace[0]) || !is_readable($backtrace[0]['file'])) {
debugging(get_string('nocallbackfile', 'portfolio'));
return;
}
if (empty($callbackfile)) {
$backtrace = debug_backtrace();
if (!array_key_exists(0, $backtrace) || !array_key_exists('file', $backtrace[0]) || !is_readable($backtrace[0]['file'])) {
debugging(get_string('nocallbackfile', 'portfolio'));
return;
}
$callbackfile = substr($backtrace[0]['file'], strlen($CFG->dirroot));
$callbackfile = substr($backtrace[0]['file'], strlen($CFG->dirroot));
} else {
if (!is_readable($CFG->dirroot . $callbackfile)) {
debugging(get_string('nocallbackfile', 'portfolio'));
return;
}
}
require_once($CFG->dirroot . $callbackfile);

View File

@ -1712,13 +1712,13 @@ class assignment_base {
'<a href="'.$ffurl.'" >'.$file.'</a>';
if ($this->portfolio_exportable() && true) { // @todo replace with capability check
$p['file'] = $file;
$output .= portfolio_add_button('assignment_portfolio_caller', $p, false, true);
$output .= portfolio_add_button('assignment_portfolio_caller', $p, null, false, true);
}
$output .= '<br />';
}
if ($this->portfolio_exportable() && true) { //@todo replace with check capability
unset($p['file']);// for all files
$output .= '<br />' . portfolio_add_button('assignment_portfolio_caller', $p, true, true);
$output .= '<br />' . portfolio_add_button('assignment_portfolio_caller', $p, null, true, true);
}
}
}
@ -3154,7 +3154,7 @@ class assignment_portfolio_caller extends portfolio_caller_base {
return $status;
}
$filearea = $CFG->dataroot . '/' . $this->assignment->file_area_name($this->userid);
//@todo this is a dreadful thing to have to call.
//@todo penny this is a dreadful thing to have to call (replace with files api anyway)
require_once($CFG->dirroot . '/backup/lib.php');
if ($this->file) {
return backup_copy_file($filearea . '/' . $this->file, $tempdir . '/' . $this->file);

View File

@ -101,13 +101,13 @@ class assignment_online extends assignment_base {
$mform->display();
} else {
print_box_start('generalbox boxwidthwide boxaligncenter', 'online');
if ($submission) {
if ($submission && true) { // @todo penny replace with capability check later
echo format_text($submission->data1, $submission->data2);
$p = array(
'userid' => $USER->id,
'assignmentid' => $this->cm->id,
);
portfolio_add_button('assignment_portfolio_caller', $p);
portfolio_add_button('assignment_portfolio_caller', $p, '/mod/assignment/lib.php'));
} 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

View File

@ -377,15 +377,15 @@ class assignment_upload extends assignment_base {
$output .= '<a href="'.$delurl.'">&nbsp;'
.'<img title="'.$strdelete.'" src="'.$CFG->pixpath.'/t/delete.gif" class="iconsmall" alt="" /></a> ';
}
if (true) { // @todo replace with capability check
if (true) { // @todo penny replace with capability check
$p['file'] = $file;
$output .= portfolio_add_button('assignment_portfolio_caller', $p, false, true);
$output .= portfolio_add_button('assignment_portfolio_caller', $p, '/mod/assignment/lib.php', false, true);
}
$output .= '<br />';
}
if (true) { //@todo replace with check capability
if (true) { //@todo penny replace with check capability
unset($p['file']);// for all files
$output .= '<br />' . portfolio_add_button('assignment_portfolio_caller', $p, true, true);
$output .= '<br />' . portfolio_add_button('assignment_portfolio_caller', $p, '/mod/assignment/lib.php', true, true);
}
}
}