Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/portfolio/formats.php
Go to the documentation of this file.
00001 <?php
00031 defined('MOODLE_INTERNAL') || die();
00032 
00037 abstract class portfolio_format {
00038 
00042     public static function mimetypes() {
00043         throw new coding_exception('mimetypes() method needs to be overridden in each subclass of portfolio_format');
00044     }
00045 
00051     public static function get_file_directory() {
00052         throw new coding_exception('get_file_directory() method needs to be overridden in each subclass of portfolio_format');
00053     }
00054 
00069     public static function file_output($file, $options=null) {
00070         throw new coding_exception('file_output() method needs to be overridden in each subclass of portfolio_format');
00071     }
00072 
00073     public static function make_tag($file, $path, $attributes) {
00074         $srcattr = 'href';
00075         $tag     = 'a';
00076         $content = $file->get_filename();
00077         if (in_array($file->get_mimetype(), portfolio_format_image::mimetypes())) {
00078             $srcattr = 'src';
00079             $tag     = 'img';
00080             $content = '';
00081         }
00082 
00083         $attributes[$srcattr] = $path; // this will override anything we might have been passed (which is good)
00084         $dom = new DomDocument();
00085         $elem = null;
00086         if ($content) {
00087             $elem = $dom->createElement($tag, $content);
00088         } else {
00089             $elem = $dom->createElement($tag);
00090         }
00091 
00092         foreach ($attributes as $key => $value) {
00093             $elem->setAttribute($key, $value);
00094         }
00095         $dom->appendChild($elem);
00096         return $dom->saveXML($elem);
00097     }
00098 
00118     public static function conflicts($format) {
00119         return false;
00120     }
00121 }
00122 
00126 class portfolio_format_file extends portfolio_format {
00127 
00128     public static function mimetypes() {
00129         return array();
00130     }
00131 
00132     public static function get_file_directory() {
00133         return false;
00134     }
00135 
00136     public static function file_output($file, $options=null) {
00137         throw new portfolio_exception('fileoutputnotsupported', 'portfolio');
00138     }
00139 }
00140 
00144 class portfolio_format_image extends portfolio_format_file {
00148     public static function mimetypes() {
00149         return mimeinfo_from_icon('type', 'image', true);
00150     }
00151 
00152     public static function conflicts($format) {
00153         return ($format == PORTFOLIO_FORMAT_RICHHTML
00154             || $format == PORTFOLIO_FORMAT_PLAINHTML);
00155     }
00156 }
00157 
00163 class portfolio_format_plainhtml extends portfolio_format_file {
00164 
00165     public static function mimetypes() {
00166         return array('text/html');
00167     }
00168 
00169     public static function conflicts($format) {
00170         return ($format == PORTFOLIO_FORMAT_RICHHTML
00171             || $format == PORTFOLIO_FORMAT_FILE);
00172     }
00173 }
00174 
00180 class portfolio_format_video extends portfolio_format_file {
00181     public static function mimetypes() {
00182         return array_merge(
00183             mimeinfo_from_icon('type', 'video', true),
00184             mimeinfo_from_icon('type', 'avi', true)
00185         );
00186     }
00187 }
00188 
00193 class portfolio_format_text extends portfolio_format_file {
00194     public static function mimetypes() {
00195         return array('text/plain');
00196     }
00197 
00198     public static function conflicts($format ) {
00199         return ($format == PORTFOLIO_FORMAT_PLAINHTML
00200             || $format == PORTFOLIO_FORMAT_RICHHTML);
00201     }
00202 }
00203 
00208 abstract class portfolio_format_rich extends portfolio_format {
00209 
00210     public static function mimetypes() {
00211         return array();
00212     }
00213 
00214 }
00215 
00220 class portfolio_format_richhtml extends portfolio_format_rich {
00221     public static function get_file_directory() {
00222         return 'site_files/';
00223     }
00224     public static function file_output($file, $options=null) {
00225         $path = self::get_file_directory() . $file->get_filename();
00226         $attributes = array();
00227         if (!empty($options['attributes']) && is_array($options['attributes'])) {
00228             $attributes = $options['attributes'];
00229         }
00230         return self::make_tag($file, $path, $attributes);
00231     }
00232     public static function conflicts($format) { // TODO revisit the conflict with file, since we zip here
00233         return ($format == PORTFOLIO_FORMAT_PLAINHTML || $format == PORTFOLIO_FORMAT_FILE);
00234     }
00235 
00236 }
00237 
00238 class portfolio_format_leap2a extends portfolio_format_rich {
00239 
00240     public static function get_file_directory() {
00241         return 'files/';
00242     }
00243 
00244     public static function file_id_prefix() {
00245         return 'storedfile';
00246     }
00247 
00255     public static function file_output($file, $options=null) {
00256         $id = '';
00257         if (!is_array($options)) {
00258             $options = array();
00259         }
00260         if (!array_key_exists('entry', $options)) {
00261             $options['entry'] = true;
00262         }
00263         if (!empty($options['entry'])) {
00264             $path = 'portfolio:' . self::file_id_prefix() . $file->get_id();
00265         } else {
00266             $path = self::get_file_directory() . $file->get_filename();
00267         }
00268         $attributes = array();
00269         if (!empty($options['attributes']) && is_array($options['attributes'])) {
00270             $attributes = $options['attributes'];
00271         }
00272         $attributes['rel']    = 'enclosure';
00273         return self::make_tag($file, $path, $attributes);
00274     }
00275 
00276     public static function leap2a_writer(stdclass $user=null) {
00277         global $CFG;
00278         if (empty($user)) {
00279             global $USER;
00280             $user = $USER;
00281         }
00282         require_once($CFG->libdir . '/portfolio/formats/leap2a/lib.php');
00283         return new portfolio_format_leap2a_writer($user);
00284     }
00285 
00286     public static function manifest_name() {
00287         return 'leap2a.xml';
00288     }
00289 }
00290 
00291 
00296 //class portfolio_format_mbkp extends portfolio_format_rich {}
00297 
00303 class portfolio_format_pdf extends portfolio_format_file {
00304     public static function mimetypes() {
00305         return array('application/pdf');
00306     }
00307 }
00308 
00314 class portfolio_format_document extends portfolio_format_file {
00315     public static function mimetypes() {
00316         return array_merge(
00317             array('text/plain', 'text/rtf'),
00318             mimeinfo_from_icon('type', 'word', true),
00319             mimeinfo_from_icon('type', 'docx', true),
00320             mimeinfo_from_icon('type', 'odt', true)
00321         );
00322     }
00323 }
00324 
00330 class portfolio_format_spreadsheet extends portfolio_format_file {
00331     public static function mimetypes() {
00332         return array_merge(
00333             mimeinfo_from_icon('type', 'excel', true),
00334             mimeinfo_from_icon('type', 'xlsm', true),
00335             mimeinfo_from_icon('type', 'ods', true)
00336         );
00337     }
00338 }
00339 
00345 class portfolio_format_presentation extends portfolio_format_file {
00346     public static function mimetypes() {
00347         return mimeinfo_from_icon('type', 'powerpoint', true);
00348     }
00349 }
 All Data Structures Namespaces Files Functions Variables Enumerations