Ejemplo n.º 1
0
 /**
  * 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;
     }
 }
Ejemplo n.º 2
0
 public function __construct()
 {
     self::$model['singular'] = ucfirst(\Supernova\Inflector::singularize(\Supernova\Core::$elements['controller']));
     self::$model['plural'] = ucfirst(\Supernova\Inflector::pluralize(\Supernova\Core::$elements['controller']));
     self::$action = ucfirst(\Supernova\Inflector::underToCamel(\Supernova\Core::$elements['prefix']));
     self::$action .= ucfirst(\Supernova\Inflector::underToCamel(\Supernova\Core::$elements['action']));
 }
Ejemplo n.º 3
0
 public static function templateIndex()
 {
     extract(\Supernova\View::$values);
     $name = \Supernova\Core::$elements['controller'];
     $pluralName = \Supernova\Inflector::pluralize($name);
     $title = inject(__("List from %name%"), array("name" => $pluralName));
     $table = \Supernova\Helper::table(array('values' => ${$pluralName}, 'use' => array('created' => '\\Supernova\\Helper::formatDate', 'updated' => '\\Supernova\\Helper::formatDate')));
     $link = \Supernova\Helper::link(array("href" => \Supernova\Route::generateUrl(array("prefix" => \Supernova\Core::$elements['prefix'], "controller" => $name, "action" => "Add")), "text" => inject(__("Add %name%"), array("name" => $name))));
     return "\n        <div class='panel panel-default' id='buttons'>\n            <div class='panel-heading'>{$title}</div>\n            <div class='panel-body'>\n                {$table}\n                {$link}\n            </div>\n        </div>\n        ";
 }
Ejemplo n.º 4
0
 /**
  * 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);
 }
Ejemplo n.º 5
0
 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;
 }
Ejemplo n.º 6
0
 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;
 }
Ejemplo n.º 7
0
    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;
    }
Ejemplo n.º 8
0
/**
 * Inyecta variables a un string
 * @param  string $str  texto
 * @param  array  $vars variables a reemplazar en el string
 * @return string       string inyectado
 */
function inject($str = "", $vars = array())
{
    return \Supernova\Inflector::inject($str, $vars);
}
Ejemplo n.º 9
0
 /**
  * Ingresa el nombre del prefijo
  * @param array $urlQuery Arreglo con request
  */
 public static function setPrefix($urlQuery)
 {
     $prefix = ucfirst(\Supernova\Inflector::underToCamel(current($urlQuery)));
     require ROOT . DS . "Config" . DS . "routing.php";
     if (in_array($prefix, $routing['prefix'])) {
         self::$elements['prefix'] = $prefix;
         return true;
     }
     self::$elements['prefix'] = "";
     return false;
 }
Ejemplo n.º 10
0
 public static function processPost()
 {
     if ($post = \Supernova\Core::getPostParameters()) {
         $namespace = "\\App\\Model\\" . \Supernova\Core::$elements['controller'];
         $formNamespace = $namespace . "Form";
         $objectForm = new $formNamespace();
         foreach ($post['data'] as $model => $values) {
             if ($namespace == "\\App\\Model\\" . ucfirst(\Supernova\Inflector::underToCamel($model))) {
                 $object = new $namespace();
                 foreach ($values as $key => $val) {
                     $setter = "set" . ucfirst(\Supernova\Inflector::underToCamel($key));
                     if (isset($objectForm->settings[$key]['widget']['use']) && !empty($objectForm->settings[$key]['widget']['use'])) {
                         $fn = explode("::", $objectForm->settings[$key]['widget']['use']);
                         if (method_exists($fn[0], $fn[1])) {
                             $val = $fn[0]::$fn[1]($val);
                         }
                     }
                     $object->{$setter}($val);
                 }
                 return $object->isValid() ? true : $object->onError();
             }
         }
     }
     return null;
 }