$string['instancenotsaved'] = 'Failed to save portfolio';
$string['instancenotdelete'] = 'Failed to delete portfolio';
$string['instancesaved'] = 'Portfolio saved successfully';
+$string['invalidaddformat'] = 'Invalid add format passed to portfolio_add_button. ($a) Must be one of PORTFOLIO_ADD_XXX';
$string['invalidtempid'] = 'Invalid export id. maybe it has expired';
$string['invalidformat'] = 'Something is exporting an invalid format, $a';
$string['invalidinstance'] = 'Could not find that portfolio instance';
*/
define('PORTFOLIO_TIME_HIGH', 'high');
+// ************************************************** //
+// available ways to add the portfolio export to a page
+// ************************************************** //
+
+/**
+* a whole form, containing a drop down menu (where necessary)
+* and a submit button
+*/
+define('PORTFOLIO_ADD_FULL_FORM', 1);
+
+
+/**
+* a whole form, containing a drop down menu (where necessary)
+* but has an icon instead of a button to submit
+*/
+define('PORTFOLIO_ADD_ICON_FORM', 2);
+
+/**
+* just an icon with a link around it (yuk, as will result in a long url
+* only use where necessary)
+*/
+define('PORTFOLIO_ADD_ICON_LINK', 3);
+
+/**
+* just some text with a link around it (yuk, as will result in a long url
+* only use where necessary)
+*/
+define('PORTFOLIO_ADD_TEXT_LINK', 4);
/**
* entry point to add an 'add to portfolio' button somewhere in moodle
* 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 int $format format to display the button or form or icon or link.
+* See constants PORTFOLIO_ADD_XXX for more info.
+* optional, defaults to PORTFOLI_ADD_FULL_FORM
+* @param str $addstr string to use for the button or icon alt text or link text.
+* this is whole string, not key. optional, defaults to 'Add to portfolio';
* @param boolean $return whether to echo or return content (optional defaults to false (echo)
*/
-function portfolio_add_button($callbackclass, $callbackargs, $callbackfile=null, $fullform=true, $return=false) {
+function portfolio_add_button($callbackclass, $callbackargs, $callbackfile=null, $format=PORTFOLIO_ADD_FULL_FORM, $addstr=null, $return=false) {
global $SESSION, $CFG, $COURSE, $USER;
$callersupports = call_user_func(array($callbackclass, 'supported_formats'));
- $output = '<form method="post" action="' . $CFG->wwwroot . '/portfolio/add.php" id="portfolio-add-button">' . "\n";
+ $formoutput = '<form method="post" action="' . $CFG->wwwroot . '/portfolio/add.php" id="portfolio-add-button">' . "\n";
+ $linkoutput = '<a href="' . $CFG->wwwroot . '/portfolio/add.php?';
foreach ($callbackargs as $key => $value) {
if (!empty($value) && !is_string($value) && !is_numeric($value)) {
$a->key = $key;
debugging(get_string('nonprimative', 'portfolio', $a));
return;
}
- $output .= "\n" . '<input type="hidden" name="ca_' . $key . '" value="' . $value . '" />';
+ $linkoutput .= 'ca_' . $key . '=' . $value . '&';
+ $formoutput .= "\n" . '<input type="hidden" name="ca_' . $key . '" value="' . $value . '" />';
}
- $output .= "\n" . '<input type="hidden" name="callbackfile" value="' . $callbackfile . '" />';
- $output .= "\n" . '<input type="hidden" name="callbackclass" value="' . $callbackclass . '" />';
- $output .= "\n" . '<input type="hidden" name="course" value="' . (!empty($COURSE) ? $COURSE->id : 0) . '" />';
+ $formoutput .= "\n" . '<input type="hidden" name="callbackfile" value="' . $callbackfile . '" />';
+ $formoutput .= "\n" . '<input type="hidden" name="callbackclass" value="' . $callbackclass . '" />';
+ $formoutput .= "\n" . '<input type="hidden" name="course" value="' . (!empty($COURSE) ? $COURSE->id : 0) . '" />';
+ $linkoutput .= 'callbackfile=' . $callbackfile . '&callbackclass='
+ . $callbackclass . '&course=' . (!empty($COURSE) ? $COURSE->id : 0);
$selectoutput = '';
if (count($instances) == 1) {
$instance = array_shift($instances);
debugging(get_string('instancemisconfigured', 'portfolio', get_string($error[$instance->get('id')], 'portfolio_' . $instance->get('plugin'))));
return;
}
- $output .= "\n" . '<input type="hidden" name="instance" value="' . $instance->get('id') . '" />';
+ $formoutput .= "\n" . '<input type="hidden" name="instance" value="' . $instance->get('id') . '" />';
+ $linkoutput .= '&instance=' . $instance->get('id');
}
else {
$selectoutput = portfolio_instance_select($instances, $callersupports, $callbackclass, 'instance', true);
}
- if ($fullform) {
- $output .= $selectoutput;
- $output .= "\n" . '<input type="submit" value="' . get_string('addtoportfolio', 'portfolio') .'" />';
- } else {
- $output .= "\n" . '<input type="image" src="' . $CFG->pixpath . '/t/portfolio.gif" alt=' . get_string('addtoportfolio', 'portfolio') .'" />';
- //@todo replace this with a little icon
- }
-
- $output .= "\n" . '</form>';
-
+ if (empty($addstr)) {
+ $addstr = get_string('addtoportfolio', 'portfolio');
+ }
+ if (empty($format)) {
+ $format = PORTFOLIO_ADD_FULL_FORM;
+ }
+ switch ($format) {
+ case PORTFOLIO_ADD_FULL_FORM:
+ $formoutput .= $selectoutput;
+ $formoutput .= "\n" . '<input type="submit" value="' . $addstr .'" />';
+ $formoutput .= "\n" . '</form>';
+ break;
+ case PORTFOLIO_ADD_ICON_FORM:
+ $formoutput .= $selectoutput;
+ $formoutput .= "\n" . '<input type="image" src="' . $CFG->pixpath . '/t/portfolio.gif" alt=' . $addstr .'" />';
+ $formoutput .= "\n" . '</form>';
+ break;
+ case PORTFOLIO_ADD_ICON_LINK:
+ $linkoutput .= '"><img src="' . $CFG->pixpath . '/t/portfolio.gif" alt=' . $addstr .'" /></a>';
+ break;
+ case PORTFOLIO_ADD_TEXT_LINK:
+ $linkoutput .= '">' . $addstr .'</a>';
+ break;
+ default:
+ debugging('asdfd');
+ print_error('invalidaddformat', 'portfolio', '', $format);
+ }
+ $output = (in_array($format, array(PORTFOLIO_ADD_FULL_FORM, PORTFOLIO_ADD_ICON_FORM)) ? $formoutput : $linkoutput);
if ($return) {
return $output;
} else {
$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();
- $output .= portfolio_add_button('assignment_portfolio_caller', $p, null, false, true);
+ $output .= portfolio_add_button('assignment_portfolio_caller', $p, null, PORTFOLIO_ADD_ICON_LINK, null, true);
}
$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, true, true);
+ $output .= '<br />' . portfolio_add_button('assignment_portfolio_caller', $p, null, PORTFOLIO_ADD_FULL_FORM, null, true);
}
}
if (has_capability('mod/assignment:exportownsubmission', $this->context)) {
$p['file'] = $file->get_id();
- $output .= portfolio_add_button('assignment_portfolio_caller', $p, '/mod/assignment/lib.php', false, true);
+ $output .= portfolio_add_button('assignment_portfolio_caller', $p, '/mod/assignment/lib.php', PORTFOLIO_ADD_ICON_LINK, null, true);
}
$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', true, true);
+ $output .= '<br />' . portfolio_add_button('assignment_portfolio_caller', $p, '/mod/assignment/lib.php', null, null, true);
}
}
&& ((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, false, true);
+ $replacement[] = portfolio_add_button('data_portfolio_caller', array('id' => $cm->id, 'record' => $record->id), null, PORTFOLIO_ADD_ICON_LINK, null, true);
} else {
$replacement[] = '';
}
$p = array(
'discussionid' => $discussion->id,
);
- //$portfolio = portfolio_add_button('forum_portfolio_caller', $p, '/mod/forum/lib.php', true, true);
+ // @todo penny check these arguments when uncommenting
+ //$portfolio = portfolio_add_button('forum_portfolio_caller', $p, '/mod/forum/lib.php', null, null, true);
}
echo '<table width="100%" class="discussioncontrols"><tr><td>';
$p = array(
'postid' => $post->id,
);
- //$commands[] = portfolio_add_button('forum_portfolio_caller', $p, '/mod/forum/lib.php', false, true);
+ // @todo penny check these arguments when uncommenting
+ //$commands[] = portfolio_add_button('forum_portfolio_caller', $p, '/mod/forum/lib.php', PORTFOLIO_ADD_TEXT_LINK, null, true);
}
echo '<div class="commands">';
'postid' => $post->id,
'attachment' => 1,
);
- //$output .= portfolio_add_button('forum_portfolio_caller', $p, '/mod/forum/lib.php', false, true);
+ // @todo penny check these arguments when uncommenting
+ //$output .= portfolio_add_button('forum_portfolio_caller', $p, '/mod/forum/lib.php', PORTFOLIO_ADD_ICON_FORM, null, true);
}
$output .= "<br />";
'postid' => $post->id,
'attachment' => 1,
);
- //portfolio_add_button('forum_portfolio_caller', $p, '/mod/forum/lib.php', false);
+ // @todo penny check these arguments when uncommenting
+ //portfolio_add_button('forum_portfolio_caller', $p, '/mod/forum/lib.php', PORTFOLIO_ADD_ICON_FORM);
}
echo '<br />';
}
</div>
</form>
<?php
- require_once($CFG->libdir . '/portfoliolib.php');
- $p = array(
- 'id' => $cm->id,
- );
- portfolio_add_button('glossary_csv_portfolio_caller', $p, '/mod/glossary/lib.php');
+ if ($DB->count_records('glossary_entries', array('glossaryid' => $glossary->id)) && true) { // @todo penny capability check
+ require_once($CFG->libdir . '/portfoliolib.php');
+ $p = array(
+ 'id' => $cm->id,
+ );
+ portfolio_add_button('glossary_csv_portfolio_caller', $p, '/mod/glossary/lib.php');
+ }
print_box_end();
print_footer($course);
?>
'id' => $cm->id,
'entryid' => $entry->id,
);
- $return .= portfolio_add_button('glossary_entry_portfolio_caller', $p, false, false, true);
+ $return .= portfolio_add_button('glossary_entry_portfolio_caller', $p, null, PORTFOLIO_ADD_ICON_LINK, null, true);
}
$return .= " "; // just to make up a little the output in Mozilla ;)
return has_capability('mod/resource:exportresource', get_context_instance(CONTEXT_MODULE, $this->cm->id));
}
- public static function add_button($resource, $fullform=true, $return=false) {
+ public static function add_button($resource, $format=null, $return=false) {
if (!has_capability('mod/resource:exportresource', get_context_instance(CONTEXT_MODULE, $resource->cm->id))) {
return;
}
debugging(get_string('portfolionotimplemented', 'resource'));
return false;
}
- return portfolio_add_button('resource_portfolio_caller', array('id' => $resource->cm->instance), '/mod/resource/lib.php', $fullform, $return);
+ return portfolio_add_button('resource_portfolio_caller', array('id' => $resource->cm->instance), '/mod/resource/lib.php', $format, null, $return);
}
public function get_sha1() {