Skip to content

Commit

Permalink
refectory general
Browse files Browse the repository at this point in the history
  • Loading branch information
marciotrindade committed Jul 18, 2009
1 parent 352e7ba commit 8cdb5dd
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 153 deletions.
76 changes: 5 additions & 71 deletions app_controller.php
@@ -1,10 +1,9 @@
<?php

class AppController extends Controller
{
var $helpers = array("Html", "Form", "Javascript", "Session", "Time", "Text");
var $components = array("RequestHandler", "DebugKit.Toolbar");
//var $components = array("RequestHandler");
// var $components = array("RequestHandler");
var $beforFilter = array();

function __construct()
Expand All @@ -19,77 +18,12 @@ function __construct()
parent::__construct();
}

function beforeFilter() {
/*
* verifica se esta dentro do admim
* se estiver adiciona o metodo _adminFilter a lista de filtros
*/
if(isSet($this->params["admin"])){
// $this->beforFilter = array_merge_recursive($this->beforFilter, array("_adminFilter"));
}
/*
* loop em todos os nomes de filtros e chama os mesmos.
*/
function beforeFilter()
{
// loop em todos os nomes de filtros e chama os mesmos.
foreach($this->beforFilter as $filter){
$this->$filter();
}
}

/*
* filtro quando está dentro do Routing.admin
*/
function _adminFilter() {
// altera o layout
$this->layoutPath = "admin";
$this->viewPath .= "/admin";
$this->params["prefix"] = "";

/*
* se o usuário não estiver logado
* salva a url solicitada em uma seção e
* redireciona o usuário para a tela de login
*/
if(!$this->Session->check("user"))
{
if(!empty($this->params["url"])){
$url = $this->params["url"]["url"];
}else{
$url = "/";
}
$this->Session->write("redirect", $url);
$this->redirect(array("controller" => "users", "action"=>"login", "admin"=>false));
}
/*
* se está logado verifica se tem permissão de administrador
* não tendo redireciona para o paginas de permisão.
* tendo manda os dados do usuário para o view
*/
else
{
$user = $this->Session->read("user");

if(!in_array("adm", $user["Group"])){
$this->redirect(array("controller"=>"users", "action"=>"permission_denied", "admin" => false));
}
}
}

function beforeRender() {
if(isSet($this->params[Configure::read("Routing.admin")])){
$this->action = str_replace("admin_", "", $this->action);
}
}

function _filter(){
$this->passedArgs = am(array(
"sort" => "name",
"direction" => "asc",
"limit" => 20,
"page" => 1,
"key" => ""
), $this->passedArgs);
$this->set("limits", array(10 => 10, 20 => 20, 30 => 30, 50 => 50, 100 => 100));
}

}
?>
?>
17 changes: 2 additions & 15 deletions app_model.php
@@ -1,26 +1,13 @@
<?php

class AppModel extends Model
{
/*
* unique
* used for validation
*/
function unique($data) {
function unique($data)
{
return $this->isUnique(array(key($data)=>current($data)));
}

function afterFind($result){
foreach($result as &$rs){
if(isSet($rs[$this->name]['created'])){
$rs[$this->name]['created'] = date('m/d/Y H:i:s', strtotime($rs[$this->name]['created']));
}
if(isSet($rs[$this->name]['modified'])){
$rs[$this->name]['modified'] = date('m/d/Y H:i:s', strtotime($rs[$this->name]['modified']));
}
}
return $result;
}

}
?>
14 changes: 2 additions & 12 deletions config/database.php.default
@@ -1,6 +1,6 @@
<?php
class DATABASE_CONFIG {

class DATABASE_CONFIG
{
var $default = array(
'driver' => 'mysql',
'persistent' => false,
Expand All @@ -10,15 +10,5 @@ class DATABASE_CONFIG {
'database' => 'base_development',
'prefix' => '',
);

var $test = array(
'driver' => 'mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'root',
'password' => '',
'database' => 'base_test',
'prefix' => '',
);
}
?>
1 change: 0 additions & 1 deletion config/routes.php
@@ -1,7 +1,6 @@
<?php
Router::connect('/', array('controller' => 'pages', 'action' => "show", 'home'));

Router::connect('/pages/menu/*', array('controller' => 'pages', 'action' => 'menu'));
Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'show'));

Router::connect('/admin', array('controller' => 'pages', 'action' => 'index', 'admin' => true));
Expand Down
9 changes: 5 additions & 4 deletions controllers/admin/pages_controller.php
@@ -1,12 +1,13 @@
<?php
class PagesController extends AdminController {
class PagesController extends AdminController
{
var $name = 'Pages';

function index($parent_id=false)
function index($id=false)
{
if ($parent_id)
if ($id)
{
$collection = $this->Page->find("all", array("conditions" => array("Page.parent_id" => $parent_id), "order" => "Page.position"));
$collection = $this->Page->childrens($id);
}else{
$collection = $this->Page->root("all");
}
Expand Down
3 changes: 2 additions & 1 deletion controllers/admin/users_controller.php
@@ -1,5 +1,6 @@
<?php
class UsersController extends AdminController {
class UsersController extends AdminController
{
var $name = 'Users';
var $order = "username";
}
Expand Down
27 changes: 8 additions & 19 deletions controllers/pages_controller.php
@@ -1,34 +1,23 @@
<?php
/**
* PagesController
*
* @package default
* @author Marcio Trindade
**/

class PagesController extends AppController {
class PagesController extends AppController
{
var $name = 'Pages';

function show($id = null) {
function show($id = null)
{
if (!$id) {
$this->redirect(array('action'=>'home'));
}
$this->set('page', $this->Page->findByPermalink($id));
$this->set('page', $this->Page->show($id));

$template = Inflector::underscore($id);
if (file_exists(VIEWS . $this->viewPath . DS . $template . $this->ext)) {
$this->render($template);
$template = $template;
} else {
$this->render("show");
$template = "show";
}
}

function menu($id=0)
{
return $this->Page->find("all", array(
"conditions" => array("parent_id" => $id),
"contain" => array()
));
$this->render($template);
}

}
Expand Down
42 changes: 30 additions & 12 deletions models/page.php
@@ -1,5 +1,6 @@
<?php
class Page extends AppModel {
class Page extends AppModel
{
var $name = "Page";

var $validate = array(
Expand All @@ -8,19 +9,36 @@ class Page extends AppModel {
"message" => MSG_REQUIRED
)
);

var $belongsTo = array("Parent" => array("className" => "Page", "foreignKey" => "parent_id", "counterCache" => true));
var $hasMany = array("Childrens" => array("className" => "Page", "foreignKey" => "parent_id", "order" => "position"));

var $actsAs = array(
"Permalink",
"Containable",
"NamedScope" => array(
"root" => array(
"conditions" => array("Page.parent_id" => 0),
"order" => "Page.position ASC"
)
)
);
var $actsAs = array("Permalink", "Containable");

function root()
{
return $this->find("all", array(
"conditions" => array("Page.parent_id" => 0),
"order" => "Page.position",
"contain" => array()
));
}

function childrens($id)
{
return $this->find("all", array(
"conditions" => array("Page.parent_id" => $id),
"order" => "Page.position",
"contain" => array()
));
}

function show($id)
{
return $this->find('first' , array(
"conditions" => array("permalink" => $id),
"contain" => array()
));
}
}
?>
5 changes: 2 additions & 3 deletions views/layouts/_menu.ctp
@@ -1,6 +1,5 @@
<ul id="menu">
<li><?php echo $html->link("Home", "/"); ?></li>
<?php foreach ($this->requestAction("/pages/menu") as $page): ?>
<?php echo $this->element("../layouts/_submenu", array("page" => $page)); ?>
<?php endforeach ?>
<li><?php echo $html->link("Test", "/pages/test"); ?></li>
<li><?php echo $html->link("About us", "/pages/about-us"); ?></li>
</ul>
10 changes: 0 additions & 10 deletions views/layouts/_submenu.ctp

This file was deleted.

1 change: 0 additions & 1 deletion views/layouts/default.ctp
Expand Up @@ -13,7 +13,6 @@

echo $javascript->link(array(
"jquery",
"plugins/jquery-ui",
"application",
"default",
"http://www.google-analytics.com/ga.js"
Expand Down
1 change: 0 additions & 1 deletion views/pages/home.ctp

This file was deleted.

3 changes: 0 additions & 3 deletions views/pages/index.ctp

This file was deleted.

0 comments on commit 8cdb5dd

Please sign in to comment.