Selaa lähdekoodia

Structure changes for use oxusmedia/webapp as a composer package

Gabriel Badano 5 vuotta sitten
vanhempi
commit
432ffff3a4

+ 4 - 6
index.php

@@ -1,14 +1,12 @@
 <?php
 
-error_reporting(E_ALL & ~E_NOTICE);
-ini_set('display_errors', 1);
-
 date_default_timezone_set("America/Montevideo");
 
-require("protected/config/config.php");
+if (file_exists('protected/vendor/autoload.php'))
+    require("protected/vendor/autoload.php");
 
-require("protected/vendor/autoload.php");
+$config = require("protected/config/config.php");
 
-$_webApp = new oxusmedia\webApp\webApp(SITIO, $_SERVER["DOCUMENT_ROOT"] . '/webapp-admin/protected/');
+$_webApp = new oxusmedia\webApp\webApp($config);
 
 $_webApp->run();

+ 3 - 5
protected/composer.json

@@ -1,6 +1,6 @@
 {
   "require": {
-    "oxusmedia/webapp": "dev-master"
+    "oxusmedia/webapp": ">=1.0.0"
   },
   "repositories": [
     {
@@ -10,12 +10,10 @@
   ],
   "scripts": {
     "post-update-cmd": [
-      "chmod +x vendor/oxusmedia/webapp/scripts/installassets.bash",
-      "vendor/oxusmedia/webapp/scripts/installassets.bash ../assets"
+      "php vendor/oxusmedia/webapp/scripts/installassets.php ../assets"
     ],
     "post-install-cmd": [
-      "chmod +x vendor/oxusmedia/webapp/scripts/installassets.bash",
-      "vendor/oxusmedia/webapp/scripts/installassets.bash ../assets"
+      "php vendor/oxusmedia/webapp/scripts/installassets.php ../assets"
     ]
   }
 }

+ 12 - 7
protected/config/config.php

@@ -1,12 +1,17 @@
 <?php
 
-define('DEBUG', true);
+return array(
 
-define('SITIO' , 'http://sitio.com/');
-define('TITULO', 'SitioAdmin');
+    'SITE'          => 'http://sitio.com/',
+    'TITULO'        => 'SitioAdmin',
 
-define('DB_SERVER', 'localhost');
-define('DB_USER'  , '');
-define('DB_PASS'  , '');
-define('DB_DB'    , '');
+    'DEBUG'         => true,
 
+    'DB_SERVER'     => 'localhost',
+    'DB_USER'       => '',
+    'DB_PASS'       => '',
+    'DB_DB'         => '',
+
+    'DIR_PROTECTED' => $_SERVER['DOCUMENT_ROOT'] . '/protected/',
+
+);

+ 12 - 12
protected/controllers/site.php

@@ -2,10 +2,10 @@
 
 use oxusmedia\webApp\controller;
 use oxusmedia\webApp\form;
-use oxusmedia\webApp\webApp_column;
-use oxusmedia\webApp\webApp_input;
-use oxusmedia\webApp\webApp_password;
-use oxusmedia\webApp\webApp_button;
+use oxusmedia\webApp\column;
+use oxusmedia\webApp\input;
+use oxusmedia\webApp\password;
+use oxusmedia\webApp\button;
 
 class site extends controller
 {
@@ -22,7 +22,7 @@ class site extends controller
     {
         if ($this->webApp()->isLoggedIn())
 
-            header("Location: " . SITIO);
+            $this->redirect($this->webApp()->getSite());
 
         else{
 
@@ -38,7 +38,7 @@ class site extends controller
 
                     if ($this->webApp()->login($param["usuario"], $param["contrasena"])) {
 
-                        header("Location: " . SITIO);
+                        $this->redirect($this->webApp()->getSite());
 
                         return;
 
@@ -50,7 +50,7 @@ class site extends controller
 
             $this->titulo = 'Iniciar sesión';
 
-            $this->addCss(SITIO . 'assets/css/login.css');
+            $this->addCss($this->webApp()->getSite() . 'assets/css/login.css');
 
             $this->render('login', array(
                 'loginForm' => $this->constructLoginForm()
@@ -64,16 +64,16 @@ class site extends controller
     {
         return new form('login',
             array(
-                new webApp_column(array(
-                    new webApp_input('usuario'),
-                    new webApp_password('contrasena', array(
+                new column(array(
+                    new input('usuario'),
+                    new password('contrasena', array(
                         'label' => 'Contraseña',
                     ))
                 ))
             ),
             array(
                 'buttons' => array(
-                    new webApp_button('login', webApp_button::SUBMIT, webApp_button::PRIMARY, array(
+                    new button('login', button::SUBMIT, button::PRIMARY, array(
                         'label' => 'Iniciar sesión'
                     ))
                 )
@@ -85,7 +85,7 @@ class site extends controller
     {
         $this->webApp()->logout();
 
-        header("Location: " . SITIO . 'site/login');
+        $this->redirect($this->webApp()->getSite() . 'site/login');
     }
 
 }

+ 22 - 22
protected/controllers/usuario.php

@@ -4,11 +4,11 @@ use oxusmedia\webApp\webApp;
 use oxusmedia\webApp\controller;
 use oxusmedia\webApp\grid;
 use oxusmedia\webApp\form;
-use oxusmedia\webApp\webApp_column;
-use oxusmedia\webApp\webApp_input;
-use oxusmedia\webApp\webApp_hidden;
-use oxusmedia\webApp\webApp_password;
-use oxusmedia\webApp\webApp_select;
+use oxusmedia\webApp\column;
+use oxusmedia\webApp\input;
+use oxusmedia\webApp\hidden;
+use oxusmedia\webApp\password;
+use oxusmedia\webApp\select;
 use oxusmedia\webApp\gridActionButton;
 use oxusmedia\webApp\notificacion;
 
@@ -95,35 +95,35 @@ class usuario extends controller
 
         $form = new form('usuario', array(
 
-            new webApp_column(array(
+            new column(array(
 
-                new webApp_input('usuario', array(
+                new input('usuario', array(
                     'rules' => array(
                         'required' => true
                     )
                 )),
 
-                new webApp_input('email', array(
+                new input('email', array(
                     'rules' => array(
                         'required' => true,
                         'email'    => true
                     )
                 )),
 
-                new webApp_password('pass', array(
+                new password('pass', array(
                     'label' => 'Contraseña',
                     'rules' => array(
                         'required' => true
                     )
                 )),
 
-                new webApp_input('nombre', array(
+                new input('nombre', array(
                     'rules' => array(
                         'required' => true
                     )
                 )),
 
-                new webApp_select('role', $this->getRoleDescription())
+                new select('role', $this->getRoleDescription())
 
             ))
 
@@ -171,31 +171,31 @@ class usuario extends controller
 
             $form = new form('usuario', array(
 
-                new webApp_column(array(
+                new column(array(
 
-                    new webApp_hidden('id'),
+                    new hidden('id'),
 
-                    new webApp_input('email', array(
+                    new input('email', array(
                         'rules' => array(
                             'required' => true,
                             'email'    => true
                         )
                     )),
 
-                    new webApp_password('pass', array(
+                    new password('pass', array(
                         'label'       => 'Contraseña',
                         'htmlOptions' => array(
                             'placeholder' => 'dejar vacío para no cambiar la contraseña'
                         )
                     )),
 
-                    new webApp_input('nombre', array(
+                    new input('nombre', array(
                         'rules' => array(
                             'required' => true
                         )
                     )),
 
-                    new webApp_select('role', $this->getRoleDescription(), $usuario->usuario == 'admin' ? array('htmlOptions' => array('disabled' => 'disabled')) : null)
+                    new select('role', $this->getRoleDescription(), $usuario->usuario == 'admin' ? array('htmlOptions' => array('disabled' => 'disabled')) : null)
 
                 ))
 
@@ -294,23 +294,23 @@ class usuario extends controller
 
         $form = new form('usuario', array(
 
-            new webApp_column(array(
+            new column(array(
 
-                new webApp_input('email', array(
+                new input('email', array(
                     'rules' => array(
                         'required' => true,
                         'email'    => true
                     )
                 )),
 
-                new webApp_password('pass', array(
+                new password('pass', array(
                     'label'       => 'Contraseña',
                     'htmlOptions' => array(
                         'placeholder' => 'dejar vacío para no cambiar la contraseña'
                     )
                 )),
 
-                new webApp_input('nombre', array(
+                new input('nombre', array(
                     'rules' => array(
                         'required' => true
                     )
@@ -339,7 +339,7 @@ class usuario extends controller
                     )
                 );
 
-                webApp::notify('Sus datos se actualizaron correctamente', notificacion::SUCCESS);
+                $this->notify('Sus datos se actualizaron correctamente', notificacion::SUCCESS);
 
             }
 

+ 1 - 1
protected/views/_includes/header.php

@@ -2,7 +2,7 @@
 <html>
 <head>
 
-    <title><?php echo (empty($this->titulo) ? '' : ($this->titulo . ' | ')) . TITULO;?></title>
+    <title><?php echo (empty($this->titulo) ? '' : ($this->titulo . ' | ')) . $this->webApp()->getConfig('TITULO');?></title>
 
     <?php $this->renderInclude("head");?>
 

+ 5 - 5
protected/views/_includes/menu.php

@@ -3,8 +3,8 @@
 <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
 
     <div class="navbar-header">
-        <a class="navbar-brand" href="<?php echo SITIO;?>">
-            <?php echo TITULO;?>
+        <a class="navbar-brand" href="<?php echo $this->webApp()->getSite();?>">
+            <?php echo $this->webApp()->getConfig('TITULO');?>
         </a>
     </div>
 
@@ -23,9 +23,9 @@
             </a>
             <ul class="dropdown-menu dropdown-user">
                 <li class="divider"></li>
-                <li><a href="<?php echo SITIO;?>usuario/miperfil"><i class="fa fa-user fa-fw"></i> Mi perfil</a></li>
+                <li><a href="<?php echo $this->webApp()->getSite();?>usuario/miperfil"><i class="fa fa-user fa-fw"></i> Mi perfil</a></li>
                 <li class="divider"></li>
-                <li><a href="<?php echo SITIO;?>site/logout"><i class="fa fa-sign-out fa-fw"></i> Cerrar sesión</a></li>
+                <li><a href="<?php echo $this->webApp()->getSite();?>site/logout"><i class="fa fa-sign-out fa-fw"></i> Cerrar sesión</a></li>
             </ul>
         </li>
     </ul>
@@ -37,7 +37,7 @@
             <ul class="nav" id="side-menu">
 
                 <li>
-                    <a href="<?php echo SITIO;?>usuario"><i class="fa fa-users fa-fw"></i> <span>Usuarios</span></a>
+                    <a href="<?php echo $this->webApp()->getSite();?>usuario"><i class="fa fa-users fa-fw"></i> <span>Usuarios</span></a>
                 </li>
 
                 <li>

+ 2 - 2
protected/views/site/login.php

@@ -2,7 +2,7 @@
 <html>
 <head>
 
-    <title><?php echo $this->titulo . ' | ' . TITULO;?></title>
+    <title><?php echo $this->titulo . ' | ' . $this->webApp()->getConfig('TITULO');?></title>
 
     <?php $this->renderInclude("head");?>
 
@@ -11,7 +11,7 @@
 
     <div class="login-wrap">
 
-        <h2 class="logo"><?php echo TITULO;?></h2>
+        <h2 class="logo"><?php echo $this->webApp()->getConfig('TITULO');?></h2>
 
         <?php echo $loginForm->render();?>