/** * 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 "CRUDEPATH' . DS . 'stencils" exists and contains stencil folder "' . $data['STENCIL_NAME'] . '"'); 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); }
/** * Check for existance of stencils. * * @return bool returns true on success or sets error messages and returns false. */ public static function stencils() { if (!File::dir_exists(STENCILSPATH)) { Error::set(CRUDE_ERROR, 'Crude stencils directory not found.'); Error::set(CRUDE_SOLUTION, 'Check that the directory <code>' . STENCILSPATH . '</code> exists and contains at minimum the default stencil.'); return false; } else { // check that the 'default' stencil exists in the stencils dir if (!Stencil::get(\Config::get('crude.default_stencil'))) { Error::set(CRUDE_ERROR, 'Default stencil not found in the stencils directory.'); Error::set(CRUDE_SOLUTION, 'The directory <code>' . STENCILSPATH . '</code> must contain at minimum the default stencil.'); return false; } } return true; }
/** * Breadcrumbs * * @param string key of specific element to return or null for all elements * @param string either 'next' or 'prev' to return the respective uri * @return mixed */ private static function _breadcrumbs($key = null, $direction = null) { // define breadcrumbs $breadcrumbs = array('tables' => array('Tables' => 'crude/crud/tables'), 'namespace' => array('Namespace' => 'crude/crud/namespace/' . Table::get('crud.TBL_NAME', '')), 'model' => array('Model' => 'crude/crud/model'), 'listing' => array('Listing' => 'crude/crud/listing'), 'form' => array('Form' => 'crude/crud/form'), 'input' => array('Input' => 'crude/crud/input'), 'validation' => array('Validation' => 'crude/crud/validation'), 'finish' => array('Finish' => 'crude/crud/finish/' . Table::get('crud.TBL_NAME', ''))); // get keys to be ommitted from breadcrumbs // this is set in config/crude.php $omit = array_flip(Stencil::get(Table::get('crud.STENCIL_NAME'), 'breadcrumb_ommissions')); $breadcrumbs = array_diff_key($breadcrumbs, $omit); if ($direction) { $lastkey = array_pop(array_keys($breadcrumbs)); reset($breadcrumbs); // set array pointer at matching element while (list($key, $val) = each($breadcrumbs)) { if ($key == \Request::active()->action) { break; } } // return previous uri if ($direction == 'prev') { // set array pointer to end if last element $key == $lastkey ? end($breadcrumbs) : prev($breadcrumbs); prev($breadcrumbs); return current(current($breadcrumbs)); } // return next uri if ($direction == 'next') { return current(current($breadcrumbs)); } } return $key ? current($breadcrumbs[$key]) : $breadcrumbs; }
/** * Resets 'crud' data to its default state * * @return void */ public static function reset_data() { \Session::destroy(); \Session::create(); \Session::set('crud', array('DB_NAME' => \Config::get('db.' . \Config::get('environment') . '.connection.database'), 'DB_TYPE' => \Config::get('db.' . \Config::get('environment') . '.type'), 'TBL_PREFIX' => \Config::get('db.' . \Config::get('environment') . '.table_prefix'), 'TBL_NAME' => null, 'TBL_PK' => null, 'TBL_SINGULAR' => null, 'TBL_PLURAL' => null, 'TBL_UCSINGULAR' => null, 'TBL_UCPLURAL' => null, 'TBL_COLUMN_PREFIX' => null, 'TBL_SORT_COLUMN' => null, 'COLUMNS' => null, 'NAMESPACE' => '', 'STENCIL_NAME' => \Config::get('crude.default_stencil'), 'STENCIL_DESC' => Stencil::get(\Config::get('crude.default_stencil'), 'desc'), 'STENCIL_OPTIONS' => Stencil::get_options())); }