/** * Muestra Layout y Template */ public static function render() { //header('Content-Type: text/html; charset=UTF-8'); $model = \Supernova\Core::$elements['controller']; $prefix = empty(\Supernova\Core::$elements['prefix']) ? "Default" : \Supernova\Core::$elements['prefix']; $namespace = "\\App\\Model\\" . $model; $viewName = \Supernova\Inflector::camelToUnder(\Supernova\Core::$elements['prefix'] . \Supernova\Core::$elements['action']); $viewFile = "View" . DS . $model . DS . $viewName . ".php"; $appView = ROOT . DS . "App" . DS . $viewFile; $pluginView = ROOT . DS . "Plugins" . DS . $model . DS . $viewFile; $views = array($appView, $pluginView); $content_for_layout = self::getContent($views); if (empty($content_for_layout)) { if (class_exists($namespace)) { $object = new $namespace(); if ($object->scaffolding == true) { preg_match("/(index|add|edit|delete)/i", \Supernova\Core::$elements['action'], $matches); $actionFnName = "template" . current($matches); $content_for_layout = \Supernova\Scaffolding::$actionFnName(); } } } if ($content_for_layout === false) { trigger_error(__("View not found:") . " " . \Supernova\Core::$elements['prefix'] . \Supernova\Core::$elements['action'] . " " . __('in') . " " . \Supernova\Core::$elements['controller'], E_USER_ERROR); die; } $layoutFile = ROOT . DS . "App" . DS . "Prefix" . DS . $prefix . DS . self::$layout . ".php"; if (file_exists($layoutFile)) { include $layoutFile; } else { trigger_error(__("Layout") . " " . self::$layout . ".php " . __("not found in prefix") . " " . $prefix, E_USER_ERROR); die; } }
private function set($value, $args = null) { if ($args) { $value = \Supernova\Inflector::camelToUnder($value); $this->results[$value] = current($args); } }
/** * Genera cache del modelo * @param string $model Nombre del modelo * @return null */ public static function generate($model) { $dirName = ROOT . DS . 'Cache'; if (!file_exists($dirName)) { mkdir($dirName, 0777, true); } chdir($dirName); $table = \Supernova\Inflector::camelToUnder(\Supernova\Inflector::pluralize($model)); $fields = \Supernova\Sql::getFields($table); file_put_contents($model, \Supernova\Crypt::encrypt(http_build_query($fields))); chmod($model, 0777); }
public static function generateUrl($url) { require ROOT . DS . "Config" . DS . "routing.php"; if (!is_array($url)) { if (array_key_exists($url, $routing['alias'])) { return self::generateUrl($routing['alias'][$url]); } return str_replace(' ', '-', $url); } $newUrl = array(); foreach ($routing['behaviourOrder'] as $eachOrder) { if (isset($url[$eachOrder])) { $newUrl[] = \Supernova\Inflector::camelToUnder($url[$eachOrder]); unset($url[$eachOrder]); } } foreach ($url as $k => $v) { $newUrl[$k] = $v; } array_filter($newUrl); $url = implode('/', $newUrl); return self::getBaseUrl() . $url; }
public static function removeResult($object) { if (self::connect()) { $namespace = explode("\\", get_class($object)); $model = end($namespace); $results = $object->toArray(); $table = \Supernova\Inflector::camelToUnder(\Supernova\Inflector::pluralize($model)); $query = 'DELETE FROM ' . $table . ' WHERE `' . $object->primaryKey . '`=\'' . \Supernova\Security::sanitize($results[$object->primaryKey]) . '\''; $sth = self::$connection->prepare($query); return $sth->execute(); } return false; }
public static function table($args) { $objects = $args['values']; if (!$objects) { return "<table class='table table-striped' ><tr><td>" . __("No results") . "</td></tr></table>"; } else { if (!is_object(current($objects))) { trigger_error(__("Objects not found in value called for Helper::table. Array or string found"), E_USER_WARNING); } $modelName = explode("\\", get_class(current($objects))); $modelName = end($modelName); $model = "\\App\\Model\\" . $modelName; $modelForm = $model . "Form"; $form = new $modelForm(); // get header $fields = current($objects)->toArray(); $labels = array_keys($fields); $labelTH = ""; foreach ($labels as $label) { $labelTH .= "<th>"; $labelTH .= isset($form->settings[$label]["widget"]["label"]) ? $form->settings[$label]["widget"]["label"] : $label; $labelTH .= "</th>"; } $labelTH .= "<th>Acciones</th>"; $eachData = ""; foreach ($objects as $object) { $results = $object->toArray(); $eachData .= "<tr>"; foreach ($results as $fields => $values) { $eachData .= "<td>"; if (isset($args['use']) && isset($args['use'][$fields])) { if (is_array($args['use'][$fields])) { $eachData .= $args['use'][$fields][$values]; } if (is_string($args['use'][$fields])) { $fn = explode("::", $args['use'][$fields]); if (method_exists($fn[0], $fn[1])) { if ($fn[1] != "getList") { $eachData .= $fn[0]::$fn[1]($values); } else { $list = $fn[0]::$fn[1](); $eachData .= isset($list[$values]) ? $list[$values] : ""; } } } } else { $eachData .= $values; } $eachData .= "</td>"; } $actions = isset($args['actions']) ? $args['actions'] : array('edit' => __('Edit'), 'delete' => __('Delete')); if ($actions) { $eachData .= "<td>"; $eachLink = ""; foreach ($actions as $action => $label) { $eachLink .= \Supernova\Helper::link(array("href" => \Supernova\Route::generateUrl(array("prefix" => \Supernova\Inflector::camelToUnder(\Supernova\Core::$elements['prefix']), "controller" => \Supernova\Inflector::camelToUnder(\Supernova\Core::$elements['controller']), "action" => $action, "id" => $results['id'])), "text" => $label)); } $eachData .= $eachLink; $eachData .= "</td>"; } $eachData .= "</tr>"; } } $output = <<<EOL <table class="table table-striped" > <thead> <tr> {$labelTH} </tr> </thead> <tbody> {$eachData} </tbody> <tfoot> </tfoot> </table> EOL; return $output; }