Example #1
0
    public static function file_header($file_path)
    {
        // get all table data
        $data = Table::get_all_data();
        $date = date("F j, Y, g:i a");
        return <<<HEADER
/**
 * Generated by Crude CRUD generator for Fuel on
 * {$date}
 *
 * @file      {$file_path}
 * @database  {$data['DB_NAME']}
 * @type      {$data['DB_TYPE']}
 * @table     {$data['TBL_NAME']}
 * @stencil   {$data['STENCIL_NAME']}
 */

HEADER;
    }
Example #2
0
 /**
  * Download generated zip file.
  *
  * @return  exit()
  */
 public static function download_zip()
 {
     // get all table data
     $data = Table::get_all_data();
     // build file path
     // use database__table for filename
     $zippath = \Config::get('crude.crudzip_path');
     $filename = $data['DB_NAME'] . '__' . $data['TBL_NAME'] . '.zip';
     // create tmp/crude if non-existant
     if (!self::dir_exists($zippath)) {
         self::create_dir(dirname($zippath), basename($zippath), 0755);
     }
     // delete tmp file if it exists
     if (self::file_exists($zippath . $filename)) {
         self::delete($zippath . $filename);
     }
     // load the stencil configuration data
     if (!($stencil_data = Stencil::get($data['STENCIL_NAME']))) {
         Error::set(CRUDE_ERROR, 'Could not load the selected stencil');
         Error::set(CRUDE_SOLUTION, 'Check that directory &quot;CRUDEPATH' . DS . 'stencils&quot; exists and contains stencil folder &quot;' . $data['STENCIL_NAME'] . '&quot;');
         return false;
     }
     // increase script timeout value
     ini_set("max_execution_time", 300);
     // create zip object
     $zip = new \ZipArchive();
     // open archive
     if ($zip->open($zippath . $filename, \ZIPARCHIVE::CREATE) !== TRUE) {
         die("Could not open archive");
     }
     // build the archive
     foreach ($stencil_data['files'] as $key => $file) {
         $data['file_header'] = Stencil::file_header($file['output_path'], $data['TABLE_NAME'], $data['STENCIL_NAME']);
         $zip->addFromString($file['output_path'], \View::factory($file['stencil_path'], $data)) or die("ERROR: Could not add file: {$key}");
     }
     $zip->close();
     self::download($zippath . $filename);
 }
Example #3
0
 /**
  * Set common template variables.
  */
 public static function _set_template_vars($template)
 {
     // breadcrumbs
     $template->set_global('breadcrumbs', self::_breadcrumbs(), false);
     // set global template vars with table data
     $data = Table::get_all_data();
     foreach ($data as $key => $value) {
         $template->set_global($key, $value);
     }
     $template->title = 'CRUD';
     $template->content = \View::factory('crud/' . \Request::active()->action, $data);
 }