/** * Get stencil data. * * @return mixed returns the array or string on success or false on failure */ public static function get($stencil_name, $key = null) { $stencil_path = STENCILSPATH . $stencil_name . DS . 'config.php'; if (!File::file_exists($stencil_path)) { return false; } if (!($stencil_data = \Fuel::load($stencil_path))) { return false; } // return value if key found if (isset($key)) { if (isset($stencil_data[$key])) { return $stencil_data[$key]; } else { return false; } } // build inflections replacement array $tbl_singular = Table::get('crud.TBL_SINGULAR'); $tbl_plural = Table::get('crud.TBL_PLURAL'); if ($tbl_prefix = Table::get('crud.TBL_PREFIX')) { $pfx_path = str_replace('_', DS, $tbl_prefix); $tbl_singular = str_replace($tbl_prefix, $pfx_path, $tbl_singular); $tbl_plural = str_replace($tbl_prefix, $pfx_path, $tbl_plural); } $inflections = array(':SINGULAR' => $tbl_singular, ':PLURAL' => $tbl_plural); // make the replacements foreach ($stencil_data['files'] as $key => $value) { $stencil_data['files'][$key]['output_path'] = str_replace(array_keys($inflections), array_values($inflections), $value['output_path']); } return $stencil_data; }
/** * Table construct * * <code> * $users = new Table('table_name'); * </code> * * @param string $table_name Table name */ public function __construct($table_name) { // Redefine vars $table_name = (string) $table_name; $this->table = Table::get($table_name); $this->name = $table_name; }
/** * Return a list of table name in the configured database. * * @return array the table list as: array('table_name' => 'table_class') */ public static function get_listing() { $rval = array(); $table_prefix = Table::get('crud.TBL_PREFIX', false); $tables = \DB::list_tables(); foreach ($tables as $table_name) { $table_class = 'bold'; if (!$table_prefix and strpos($table_name, '_') !== false) { $table_class = 'notice_text'; } if ($table_prefix and strpos($table_name, $table_prefix) === false) { $table_class = 'disabled_text'; } $rval[$table_name] = $table_class; } return $rval; }
<?php // This deletes the slider table ONLY if it is empty if (Table::get('slider') !== false) { $table = new Table('slider'); if ($table->count() < 1) { // no user data remaining. It's safe to drop Table::drop('slider'); } }
/** * 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; }
require_once('Table.php'); $page = new Page(0, "OrderUp - Table Designation"); $tmpl = new Template(); $tmpl->code = isset($_GET['code']) ? $_GET['code'] : -1; if( !$_SESSION['active'] || $_SESSION['roleid'] > 2 ) { $loc = urlencode("table.php"); header("Location: /login.php?code=10&fwd=$loc"); } $page->run(); $tables = Table::get(); if( $tables && is_array($tables) ) { $tmpl->tables = $tables; } else { $tmpl->tables = array($tables); } switch($tmpl->code) { case 0: $tmpl->css = "error"; $tmpl->message = "To be activated, this device needs to be assigned to a table.";
/** * * @param Table $table * @return bool */ public function createRoot($table) { if (!$table->isLoaded()) { throw new \Exception('Node must be loaded.'); return false; } if (!$table->isTree()) { throw new \Exception('Model must be a tree.'); return false; } if ($table->isInTree()) { throw new \Exception('Node already in a tree.'); return false; } $site_id = \hat\common\SystemConfig::getSiteId(); $id = $table->get('id'); $table_name = $table->getTableName(); $behavior_name = 'nestedset'; $lft_key = $table->getBehavior()->getFieldName($behavior_name, 'lft'); $rgt_key = $table->getBehavior()->getFieldName($behavior_name, 'rgt'); $level_key = $table->getBehavior()->getFieldName($behavior_name, 'level'); $root_id_key = $table->getBehavior()->getFieldName($behavior_name, 'root_id'); $this->reset(); $sql = "SELECT MAX({$root_id_key}) FROM {$table_name} WHERE {$root_id_key} > 0"; if ($table->getBehavior()->isIt('multitenant')) { $tenant_identifier = $table->getBehavior()->getFieldName('multitenant', 'identifier'); $sql .= " AND {$tenant_identifier} = {$site_id} "; } $r = $this->queryStmt($sql); if ($r !== false) { $r = $this->getResultsDbRow(); } else { throw new \Exception("Error creating root:" . $this->getLastPdoErrorMessage()); return false; } $root_id = 0; if (isset($r[0]) && isset($r[0]['max'])) { $root_id = $r[0]['max']; } $root_id++; // increment for next root_id $this->reset(); $sql = "UPDATE {$table_name} SET {$root_id_key} = {$root_id}, {$lft_key} = 1, {$rgt_key} = 2, {$level_key} = 0 WHERE id = {$id} "; if ($table->getBehavior()->isIt('multitenant')) { $tenant_identifier = $table->getBehavior()->getFieldName('multitenant', 'identifier'); $sql .= " AND {$tenant_identifier} = {$site_id} "; } $r = $this->queryStmt($sql); if ($r !== false) { $r = $this->getResultsDbRow(); } else { throw new \Exception("Error creating root:" . $this->getLastPdoErrorMessage()); return false; } //\hat\dbg::alert($r, true); return true; }