Ejemplo n.º 1
0
 /**
  * Given the fields being exported, and the single record,
  * work out which export format(s) we can use
  *
  * @param array $fields array of field objects
  * @param object $record The data record object
  *
  * @uses PORTFOLIO_FORMAT_PLAINHTML
  * @uses PORTFOLIO_FORMAT_RICHHTML
  *
  * @return array of PORTFOLIO_XX constants
  */
 public static function formats($fields, $record)
 {
     $formats = array(PORTFOLIO_FORMAT_PLAINHTML);
     $includedfiles = array();
     foreach ($fields as $singlefield) {
         if (is_callable(array($singlefield, 'get_file'))) {
             $includedfiles[] = $singlefield->get_file($record->id);
         }
     }
     if (count($includedfiles) == 1 && count($fields) == 1) {
         $formats = array(portfolio_format_from_mimetype($includedfiles[0]->get_mimetype()));
     } else {
         if (count($includedfiles) > 0) {
             $formats = array(PORTFOLIO_FORMAT_RICHHTML);
         }
     }
     return array($formats, $includedfiles);
 }
 /**
  * correllary to set_format_by_file, but this is used when we don't yet have a stored_file
  * when we're writing out a new type of file (like csv or pdf)
  *
  * @param string $extn the file extension we intend to generate
  * @param mixed        $extraformats any additional formats other than by mimetype
  *                                  eg leap2a etc
  */
 public function set_format_by_intended_file($extn, $extraformats = null)
 {
     $mimetype = mimeinfo('type', 'something. ' . $extn);
     $fileformat = portfolio_format_from_mimetype($mimetype);
     $this->intendedmimetype = $fileformat;
     if (is_string($extraformats)) {
         $extraformats = array($extraformats);
     } else {
         if (!is_array($extraformats)) {
             $extraformats = array();
         }
     }
     $this->set_formats(array_merge(array($fileformat), $extraformats));
 }