Skip to content
Browse files

Backup pre-viaje

  • Loading branch information...
1 parent 9df6f31 commit 6eb70e13e1a76e46b371498b398dbb13438d57f6 @Luraguse committed
View
31 application/controllers/indexcontroller.php
@@ -0,0 +1,31 @@
+<?php
+class IndexController extends Controller {
+
+ function beforeAction(){
+ }
+ function index() {
+
+ }
+
+ function show() {
+ // $this->dataBase()->buscar()->donde(1);
+ }
+
+ function actualizar() {
+ // $this->database()->actualizar($var, $valores); // $var = get, $valores = post
+ }
+
+ function crear() {
+ // $this->database()->crear();
+
+ }
+
+ function borrar($id) {
+ echo "<pre>",var_dump($this),"</pre>";
+ // $this->database()->borrar($id);
+
+ }
+
+ function afterAction(){
+ }
+}
View
6 application/models/index.php
@@ -0,0 +1,6 @@
+<?php
+class Index extends Model {
+ function __construct() {
+ parent::__construct();
+ }
+}
View
0 application/views/footer.php
No changes.
View
0 application/views/header.php
No changes.
View
9 application/views/index/index.php
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <link rel="stylesheet" src="<?php echo "/th_website/public/css/style.css"?>">
+ </head>
+ <body>
+
+ </body>
+</html>
View
0 application/views/index/show.php
No changes.
View
25 config/config.php
@@ -1,19 +1,20 @@
<?php
// Definicion de constantes
-define ('DB_NAME', '');
-define ('DB_USER', '');
-define ('DB_PASSWORD', '');
-define ('DB_HOST', '');
+define ('DB_NAME', 'test');
+define ('DB_USER', 'root');
+define ('DB_PASSWORD', 'd34d50ul7r1b3');
+define ('DB_HOST', 'localhost');
-define ('BASE_PATH','');
-define ('JS_FULL_PATH', '');
-define ('CSS_FULL_PATH', '');
-define ('JS_PUBLIC_PATH', '');
-define ('CSS_PUBLIC_PATH', '');
+define ('BASE_PATH', "http://localhost/mvc/public");
+define ('BASE_FILE_PATH', $_SERVER['DOCUMENT_ROOT'].DS."mvc".DS."public");
+define ('JS_FULL_PATH', BASE_FILE_PATH.DS.'js');
+define ('CSS_FULL_PATH', BASE_FILE_PATH.DS.'css');
+define ('JS_PUBLIC_PATH', BASE_PATH.DS.'js');
+define ('CSS_PUBLIC_PATH', BASE_PATH.DS.'css');
-define ('PAGINATE_LIMIT', '5');
+define ('PAGINATE_LIMIT', '5');
// Defaults
-define('DEFAULT_CONTROLLER','');
-define('DEFAULT_ACTION','');
+define('DEFAULT_CONTROLLER','index');
+define('DEFAULT_ACTION', 'index');
View
5 config/routing.php
@@ -1,7 +1,4 @@
<?php
$routing = array(
'/admin\/(.*?)\/(.*?)\/(.*)/' => 'admin/\1_\2/\3'
-);
-
-$default['controller'] = 'home';
-$default['action'] = 'index';
+);
View
4 library/bootstrap.class.php
@@ -14,8 +14,8 @@ function __construct(){
private function setUrl() {
$url = isset($_GET['url'])?rtrim($_GET['url'], "/"):null;
$urlArray = explode("/", $url);
- $this->controller = (!empty($urlArray[0]) && $urlArray !== "")?$urlArray[0]:'home';
- $this->action = isset($urlArray[1])?$urlArray[1]:'index';
+ $this->controller = (!empty($urlArray[0]) && $urlArray !== "")?$urlArray[0]:DEFAULT_CONTROLLER;
+ $this->action = isset($urlArray[1])?$urlArray[1]:DEFAULT_ACTION;
$this->param['param1'] = isset($urlArray[2])?$urlArray[2]:null;
$this->param['param2'] = isset($urlArray[3])?$urlArray[3]:null;
$this->param['param3'] = isset($urlArray[4])?$urlArray[4]:null;
View
4 library/combinararchivos.class.php
@@ -31,7 +31,7 @@ private function crear_lista_de_archivos_en_directorio($directorio, $extension)
$dir = opendir($directorio);
$array_archivos = array();
while($archivo = readdir($dir)) {
- if(pathinfo($archivo, PATHINFO_EXTENSION) == $extension) {
+ if(pathinfo($archivo, PATHINFO_EXTENSION) == $extension && pathinfo($archivo, PATHINFO_FILENAME) != "custom") {
if($extension == "js")
$array_archivos[] = JS_FULL_PATH.DS.$archivo;
else if($extension == "css")
@@ -98,7 +98,7 @@ private function combinar_contenido_de_archivos() {
if ($archivos_existen === true){
$contenido = "";
foreach($this->_lista_de_archivos as $archivo) {
- $contenido .= file_get_contents($archivo);
+ $contenido .= file_get_contents($archivo)."\n";
}
return $contenido;
} else {
View
21 library/conexion.class.php
@@ -0,0 +1,21 @@
+<?php
+
+class Conexion{
+
+ private $conexion;
+
+ public function __construct($DB_TYPE = "mysql", $DB_HOST = DB_HOST, $DB_NAME = DB_NAME, $DB_USER = DB_USER, $DB_PASS = DB_PASSWORD) {
+ $this->conectar($DB_TYPE, $DB_HOST, $DB_NAME, $DB_USER, $DB_PASS);
+ echo "conectado";
+ return $this->conexion;
+ }
+
+ private function conectar($DB_TYPE, $DB_HOST, $DB_NAME, $DB_USER, $DB_PASS) {
+ try{
+ $this->conexion = new PDO($DB_TYPE.':host='.$DB_HOST.';dbname='.$DB_NAME, $DB_USER, $DB_PASS);
+ $this->conexion->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+ } catch (PDOException $e) {
+ echo $e->getMessage();
+ }
+ }
+}
View
23 library/connection.class.php
@@ -1,23 +0,0 @@
-<?php
-
-class Connection{
-
- private $connection;
-
- public function __construct($DB_TYPE = "mysql", $DB_HOST = DB_HOST, $DB_NAME = DB_NAME, $DB_USER = DB_USER, $DB_PASS = DB_PASSWORD) {
- $this->connect($DB_TYPE, $DB_HOST, $DB_NAME, $DB_USER, $DB_PASS);
- }
-
- private function connect($DB_TYPE, $DB_HOST, $DB_NAME, $DB_USER, $DB_PASS) {
- try{
- $this->connection = new PDO($DB_TYPE.':host='.$DB_HOST.';dbname='.$DB_NAME, $DB_USER, $DB_PASS);
- $this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- } catch (PDOException $e) {
- echo $e->getMessage();
- }
- }
-
- public function connection() {
- return $this->connection;
- }
-}
View
365 library/database.class.php
@@ -1,4 +1,367 @@
<?php
class DataBase {
-}
+ private $_mainTable;
+ private $_connection;
+
+ private $_orderBy;
+ private $_order;
+ private $_hasOne = array();
+// private $_hasMany;
+// private $_tVYPAV; // Tiene varios y pertenece a varios
+ private $_limit = PAGINATE_LIMIT;
+ private $_limited = null;
+ private $_page = 1;
+ private $_totalResults;
+
+ private $_search = array();
+ private $_returnFields = array();
+ private $_searchType;
+ private $_likeMode = "nonStrict";
+
+
+
+ public function __construct($modelName) {
+ // parent::__construct($modelName);
+ $this->_mainTable = $modelName;
+ }
+
+ public function crear() {
+ // INSERT INTO tabla keys VALUES (:values)
+ // INSERT INTO modelo $_POST[keys] VALUES (:$_POST[keys])
+ }
+
+ public function buscar() {
+
+ }
+
+ public function actualizar() {
+ // UPDATE tabla SET (keys) = (:values) WHERE id = :id
+ // UPDATE modelo set $_POST[keys] = (:$_POST[keys]) WHERE id = :$_GET[id] arg[0]
+ }
+
+ public function actualizarTodos() {
+ // UPDATE modelo SET $_pOST[keys] = (:$_POST[keys]) WHERE campo = :$_GET[id]
+ }
+
+ public function borrar() {
+ // DELETE FROM tabla WHERE key = :id
+ }
+
+ public function borrarTodos() {
+ // DELETE FROM model WHERE key = :id
+ }
+
+ // Funciones generales
+
+ public function setTable($table){
+ $this->_mainTable = $table;
+ }
+
+ public function returnFields() {
+
+ if(func_num_args() > 1) {
+ foreach(func_get_args() as $arrVal) {
+ array_push($this->_returnFields, $arrVal);
+ }
+ } else if (func_num_args() == 1) {
+ $arg = func_get_arg(0);
+ if(is_array($arg)) {
+ foreach($arg as $arrVal) {
+ array_push($this->_returnFields, $arrVal);
+ }
+ } else if (is_string($arg)) {
+ $stringArray = $this->splitWords($arg);
+ foreach($stringArray as $val) {
+ array_push($this->_returnFields, $val);
+ }
+ } else {
+ die("error en return fields");
+ }
+ } else {
+ die("argumentos de return fields no puede estar en blanco");
+ }
+ }
+
+ private function splitWords($palabras) {
+ $palabras = preg_replace('/[,\s]+$/', "", $palabras);
+ $palabras = preg_split('/[,\s]+/', $palabras);
+
+ return $palabras;
+ }
+
+ // Funciones para Busqueda
+
+ public function where($arg, $field = null) {
+ if($field === null && is_numeric($arg)) {
+ $this->_search['id'] = $arg;
+ } else if ($field != null) {
+ if(is_string($field) && is_string($arg)) {
+ $this->_search[$field] = $arg;
+ } else {
+ die("field can only be string");
+ }
+ } else {
+ // Error where;
+ die("error con where");
+ }
+ $this->_searchType = "where";
+ }
+
+ public function like($search, $field = null) {
+ if(!empty($search) && $field != null && !empty($field) ) {
+ $this->_search[$field] = $search;
+ $this->_searchType = "like";
+ } else {
+ die("error like");
+ }
+ }
+
+ public function all($table) {
+ $this->_mainTable = $table;
+ $this->_searchType = "all";
+ }
+
+ public function likeMode($mode) {
+ if($mode == "strict") {
+ $this->_likeMode = $mode;
+ } else {
+ $this->_likeMode = "nonStrict";
+ }
+ }
+
+ public function hasOne($table, $fields) {
+ $this->_hasOne[$table] = array();
+ if(is_array($fields)) {
+ $this->_hasOne[$table] = $fields;
+ } else {
+ $stringArray = $this->splitWords($fields);
+ foreach($stringArray as $val) {
+ array_push($this->_hasOne[$table], $val);
+ }
+ }
+ }
+/*
+ public function belongsTo() {
+
+ }
+
+ public function hasMany() {
+
+ }
+*/
+
+ public function setLimit($limit) {
+ $this->_limited = true;
+ $this->_limit = (int) $limit;
+ }
+
+ public function setPage($page) {
+ $this->_page = (int) $page;
+ }
+
+ public function orderBy($orderBy, $order = "ASC") {
+ $this->_orderBy = $orderBy;
+ $this->_order = ($order == "ASC")?$order:"DESC";
+ }
+
+ public function getTotalPages() {
+ return floor($this->_totalResults/$this->_limit);
+ }
+
+ private function getWhereStatement() {
+ $select = $this->getSelect();
+ $from = $this->getFrom();
+ switch ($this->_searchType) {
+ case "where":
+ $where = " WHERE ".$this->getWhere();
+ break;
+ case "like":
+ $where = " WHERE ".$this->getLike();
+ break;
+ case "all":
+ $where = "";
+ break;
+ default:
+ $where = "";
+ break;
+ }
+ $order = $this->getOrder();
+ $limit = $this->getLimit();
+ $this->_resultsQuery = "SELECT ".$select." FROM ".$from.$where.$order.$limit;
+ $this->_queryTotalPages = "SELECT ".$select." FROM ".$from.$where;
+
+ //$this->_bindValues;
+ }
+
+ public function getResults() {
+ if($this->_connection == null) {
+ $this->_connection = new Connection();
+ }
+ $this->getStatements();
+ $result = $this->_connection->prepare($this->_resultsQuery);
+ $result->setFetchMode(PDO::FETCH_ASSOC);
+ if($this->_searchType == "where") {
+ foreach($this->_search as $key => $val) {
+ $result->bindValue($key,$val);
+ }
+ } else if ($this->_searchType == "like") {
+ foreach($this->_search as $key => $val) {
+ $result->bindValue($key, "%".$val."%");
+ }
+ }
+ try{
+ $result->execute();
+ } catch (PDOException $e){
+ echo "ERROR: " . $e->getMessage();
+ }
+
+ $page = $this->_connection->prepare($this->_queryTotalPages);
+ $page->setFetchMode(PDO::FETCH_ASSOC);
+ foreach($this->_search as $key => $val) {
+ $page->bindValue($key,$val);
+ }
+ try{
+ $page->execute();
+ } catch (PDOException $e) {
+ echo $e->getMessage();
+ }
+
+ $qResult = $result->fetchAll();
+ $this->_totalResults = $page->rowCount();
+ // return array($qResult, $this->getTotalPages());
+ $this->restartValues();
+ return (count($qResult) == 1)?$qResult[0]:$qResult;
+ }
+
+ public function getSelect() {
+ $string = "";
+ $count = count($this->_returnFields);
+ if($count > 0) {
+ $string .= $this->joinFields($this->_returnFields, $this->_mainTable);
+ $stringExtraFields = $this->getExtraFields();
+ if(!empty($stringExtraFields)) {
+ $string .= ", ".$stringExtraFields;
+ }
+ } else {
+ $string = "*";
+ }
+ return $string;
+ }
+
+ private function getExtraFields() {
+ $string = "";
+ if(count($this->_hasOne) > 0) {
+ foreach($this->_hasOne as $key => $val) {
+ if(is_string($val)) {
+ $string .= ", ".$key.".".$val;
+ } else if (is_array($val)) {
+ $string .= $this->joinFields($val, $key);
+ } else {
+ die("error con getExtraFields");
+ }
+ }
+ }
+ return $string;
+ }
+
+ public function getFrom() {
+ $string = $this->_mainTable;
+ $string .= $this->getJoinOn();
+ return $string;
+ }
+
+ private function getJoinOn() {
+ $string = "";
+ if(count($this->_hasOne) > 0) {
+ foreach($this->_hasOne as $key => $val) {
+ $string .= " LEFT JOIN ".$key." ON ".$this->_mainTable.".id_".$key." = ".$key.".id";
+ }
+ }
+ return $string;
+ }
+
+ public function getWhere() {
+ $string = "";
+ $i = 0;
+ $searchCount = count($this->_search);
+ if($searchCount > 0) {
+ foreach($this->_search as $key => $val) {
+ $string .= $this->_mainTable.".".$key." = :".$key;
+ if($i < ($searchCount -1)) {
+ $string .= " AND ";
+ }
+ $i++;
+ }
+ } else {
+ die("getWhere error, no hay parametros");
+ }
+ return $string;
+ }
+
+ public function getLike() {
+ $string = "";
+ $i = 0;
+ $searchCount = count($this->_search);
+ if($searchCount > 0) {
+ foreach($this->_search as $key => $val) {
+ $string .= $this->_mainTable.".".$key." LIKE :".$key;
+ if($i < ($searchCount - 1)) {
+ $string .= ($this->_likeMode == "nonStrict")? " OR ": " AND ";
+ }
+ $i++;
+ }
+ } else {
+ die("getLike error");
+ }
+ return $string;
+ }
+
+ public function getOrder() {
+ $string = "";
+ if(is_string($this->_orderBy) && is_string($this->_order)) {
+ $string .= " ORDER BY ".$this->_mainTable.".".$this->_orderBy." ".$this->_order;
+ }
+ return $string;
+ }
+
+ public function getLimit() {
+ $string = "";
+ if($this->_limit > 0 && $this->_page > 0 && $this->_limited != null) {
+ $string .= " LIMIT ".(($this->_page - 1) * $this->_limit).",".$this->_limit;
+ }
+
+ return $string;
+ }
+
+ private function joinFields($val, $table) {
+ $string = "";
+ $count = count($val);
+ if($count > 0) {
+ foreach($val as $i => $field) {
+ $string .= $table.".".$field;
+ if($i < ($count -1)) {
+ $string .= ", ";
+ }
+ }
+ }
+ return $string;
+ }
+
+ private function restartValues() {
+ $this->_orderBy = null;
+ $this->_order = null;
+ $this->_limit = PAGINATE_LIMIT;
+ $this->_page = 1;
+ $this->_totalResults = null;
+ $this->_limited = null;
+
+ $this->_searchType = null;
+ $this->_likeMode = "nonStrict";
+ $this->_hasOne = array();
+ $this->_search = array();
+ $this->_returnFields = array();
+ }
+}
+
+// SELECT campos FROM tabla LEFT JOIN tabla.campo ON tabla2.campo2 WHERE campo = valor ORDER BY id ASC LIMIT x,y
View
9 library/model.class.php
@@ -1,6 +1,6 @@
<?php
class Model {
- protected $ModelName;
+ protected $modelName;
protected $Buscar;
public $Sanitize = array();
@@ -9,10 +9,9 @@ class Model {
public $CombinarJs;
function __construct() {
- $this->ModelName = get_class($this);
- $this->Connection = new Connection();
- $this->Buscar = new Busqueda($this->Connection, strtolower($this->ModelName));
- $this->DataBase = new DataBase($this->Connection, strtolower($this->ModelName));
+ $this->modelName = strtolower(get_class($this));
+ $this->dataBase = new DataBase($this->modelName);
+ //$this->DataBase = new DataBase($this->ModelName);
}
public function Buscar() {
View
10 library/busqueda.class.php → library/query.class.php
@@ -1,5 +1,5 @@
<?php
-class Busqueda {
+class Query {
private $_connection;
@@ -13,7 +13,7 @@ class Busqueda {
private $_page = 1;
private $_totalResults;
- private $_mainTable;
+ protected $_mainTable;
private $_search = array();
private $_returnFields = array();
@@ -21,9 +21,8 @@ class Busqueda {
private $_likeMode = "nonStrict";
// Conectarse
- public function __construct($connection, $model) {
+ public function __construct($model) {
$this->_mainTable = $model;
- $this->_connection = $connection->connection();
}
public function setTable($table){
@@ -162,6 +161,9 @@ private function getStatements() {
}
public function getResults() {
+ if($this->_connection == null) {
+ $this->_connection = new Connection();
+ }
$this->getStatements();
$result = $this->_connection->prepare($this->_resultsQuery);
$result->setFetchMode(PDO::FETCH_ASSOC);
View
1,738 public/css/custom.css
0 additions, 1,738 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
49 public/js/custom.js
0 additions, 49 deletions not shown because the diff is too large. Please use a local Git client to view these changes.

0 comments on commit 6eb70e1

Please sign in to comment.
Something went wrong with that request. Please try again.