$string['format_file'] = 'File';
$string['format_html'] = 'HTML';
$string['format_image'] = 'Image';
-$string['format_mbkp'] = 'Moodle Backup';
+$string['format_mbkp'] = 'Moodle Backup Format';
+$string['format_video'] = 'Video';
+$string['format_text'] = 'Plain Text';
$string['hidden'] = 'Hidden';
$string['instancedeleted'] = 'Portfolio deleted successfully';
$string['instanceismisconfigured'] = 'Portfolio instance is misconfigured, skipping. Error was: $a';
$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['invalidfileargument'] = 'Invalid file argument passed to portfolio_format_from_file - must be stored_file object';
$string['invalidformat'] = 'Something is exporting an invalid format, $a';
$string['invalidinstance'] = 'Could not find that portfolio instance';
$string['invalidproperty'] = 'Could not find that property ($a->property of $a->class)';
*/
define('PORTFOLIO_FORMAT_IMAGE', 'image');
+/**
+* video - subtype of file
+*/
+define('PORTFOLIO_FORMAT_VIDEO', 'video');
+
+/**
+* text - subtype of file
+*/
+define('PORTFOLIO_FORMAT_TEXT', 'text');
// **** EXPORT TIME LEVELS **** //
PORTFOLIO_FORMAT_FILE => 'portfolio_format_file',
PORTFOLIO_FORMAT_IMAGE => 'portfolio_format_image',
PORTFOLIO_FORMAT_HTML => 'portfolio_format_html',
+ PORTFOLIO_FORMAT_TEXT => 'portfolio_format_text',
+ PORTFOLIO_FORMAT_VIDEO => 'portfolio_format_video',
/*PORTFOLIO_FORMAT_MBKP, */ // later
/*PORTFOLIO_FORMAT_PIOP, */ // also later
);
}
+/**
+* this function returns the revelant portfolio export format
+* which is used to determine which portfolio plugins can be used
+* for exporting this content
+* according to the mime type of the given file
+* this only works when exporting exactly <b>one</b> file
+*
+* @param stored_file $file file to check mime type for
+* @return string the format constant (see PORTFOLIO_FORMAT_XXX constants)
+*/
+function portfolio_format_from_file($file) {
+ static $alreadymatched;
+ if (empty($alreadymatched)) {
+ $alreadymatched = array();
+ }
+ if (!($file instanceof stored_file)) {
+ throw new portfolio_exception('invalidfileargument', 'portfolio');
+ }
+ $mimetype = $file->get_mimetype();
+ if (array_key_exists($mimetype, $alreadymatched)) {
+ return $alreadymatched[$mimetype];
+ }
+ $allformats = portfolio_supported_formats();
+ foreach ($allformats as $format => $classname) {
+ $supportedmimetypes = call_user_func(array($classname, 'mimetypes'));
+ if (!is_array($supportedmimetypes)) {
+ debugging("one of the portfolio format classes, $classname, said it supported something funny for mimetypes, should have been array...");
+ debugging(print_r($supportedmimetypes, true));
+ continue;
+ }
+ if (in_array($mimetype, $supportedmimetypes)) {
+ $alreadymatched[$mimetype] = $format;
+ return $format;
+ }
+ }
+ return PORTFOLIO_FORMAT_FILE; // base case for files...
+}
+
+/**
+* walks both the caller formats and portfolio plugin formats
+* and looks for matches (walking the hierarchy as well)
+* and returns the intersection
+*
+* @param array $callerformats formats the caller supports
+* @param array $pluginformats formats the portfolio plugin supports
+*/
function portfolio_supported_formats_intersect($callerformats, $pluginformats) {
$allformats = portfolio_supported_formats();
$intersection = array();
* @return array list of formats
*/
public static function supported_formats($caller=null) {
- if ($caller && $caller->get('supportedformats')) {
- return $caller->get('supportedformats');
+ if ($caller && $formats = $caller->get('supportedformats')) {
+ if (is_array($formats)) {
+ return $formats;
+ }
+ debugging(get_class($caller) . ' has set a non array value of member variable supported formats - working around but should be fixed in code');
+ return array($formats);
}
return array(PORTFOLIO_FORMAT_FILE);
}
+
/**
* this is the "return to where you were" url
*
*
* the most basic type - pretty much everything is a subtype
*/
-class portfolio_format_file {}
+class portfolio_format_file {
+ public static function mimetypes() {
+ return array(null);
+ }
+}
/**
* this is just used to find an intersection of supported formats
*
* added for potential flickr plugin
*/
-class portfolio_format_image extends portfolio_format_file {}
+class portfolio_format_image extends portfolio_format_file {
+ public static function mimetypes() {
+ return mimeinfo_from_icon('type', 'image.gif', true);
+ }
+}
/**
* this is just used to find an intersection of supported formats
*
* in case we want to be really specific.
*/
-class portfolio_format_html extends portfolio_format_file {}
+class portfolio_format_html extends portfolio_format_file {
+ public static function mimetypes() {
+ return array('text/html');
+ }
+}
+
+/**
+* I guess there could be a youtube/google video plugin
+* and anyway, the flickr plugin can support it already
+*/
+class portfolio_format_video extends portfolio_format_file {
+ public static function mimetypes() {
+ return mimeinfo_from_icon('type', 'video.gif', true);
+ }
+}
+
+/**
+* class for plain text format.. not sure why we would need this yet
+* but since resource module wants to export it... we can
+*/
+class portfolio_format_text extends portfolio_format_file {
+ public static function mimetypes() {
+ return array('text/plain');
+ }
+}
/**
* this is just used to find an intersection of supported formats
if (!$this->assignment->portfolio_exportable()) {
throw new portfolio_caller_exception('notexportable', 'portfolio', $this->get_return_url());
}
- global $USER;
- $this->userid = $USER->id;
- $this->file = (array_key_exists('file', $callbackargs)) ? $callbackargs['file'] : null;
+ if (array_key_exists('file', $callbackargs)) {
+ $fs = get_file_storage();
+ $this->file = $fs->get_file_by_id($callbackargs['file']);
+ $this->supportedformats = array(portfolio_format_from_file($this->file));
+ } else if (is_callable(array($this->assignment, 'portfolio_supported_formats'))) {
+ $this->supportedformats = $this->assignment->portfolio_supported_formats();
+ }
}
public function prepare_package() {
}
// default ...
- $fs = get_file_storage();
- $status = true;
if ($this->file) {
- return $fs->get_file_by_id($this->file)->get_contenthash();
+ return $this->file->get_contenthash();
}
+ $fs = get_file_storage();
if ($files = $fs->get_area_files($this->assignment->context->id,
'assignment_submission', $this->user->id, '', false)) {
$sha1s = array();