Beispiel #1
0
 public function setNames($name)
 {
     $this->tblName = $name;
     $this->singularized = Singulars($this->tblName);
     $this->camelized = Camelize($this->singularized);
     return true;
 }
function MigrationsActions($params = NULL, &$obj = NULL)
{
    if (isset($_POST['migrations'])) {
        $path = INST_PATH . 'migrations/';
        $migrationsSelected = array();
        foreach ($_POST['migrations'] as $field => $value) {
            if ($value === 'on') {
                $Obj = 'create_' . Singulars($field);
                $migrationsSelected[Camelize($Obj)] = $field;
            } elseif (preg_match('[:selected]', $field)) {
                $all = false;
            }
        }
    }
    //		if(isset($all) and !$all and isset($migrationsSelected)):
    $var = $migrationsSelected;
    //		endif;
    $action = NULL;
    if (isset($_POST['migrations']['reset:all']) or isset($_POST['migrations']['reset:selected'])) {
        $action = 'Reset';
    } elseif (isset($_POST['migrations']['up:all']) or isset($_POST['migrations']['up:selected'])) {
        $action = 'up';
    } elseif (isset($_POST['migrations']['down:all']) or isset($_POST['migrations']['down:selected'])) {
        $action = 'down';
    }
    if (isset($var) and isset($action)) {
        foreach ($var as $Obj => $Tbl) {
            $file = $path . 'create_' . $Tbl . '.php';
            require_once $file;
            $objaux = new $Obj();
            $objaux->{$action}();
        }
    }
}
	function create_migrationsAction(){
		//Require_Admin_Login();
		if(isset($_POST['fields']['sub'])):
			$arraux = array();
			$arraux['Table'] = $_POST['create_migrations']['Table'];
			foreach($_POST['create_migrations'] as $row){
				if($row != $_POST['create_migrations']['Table'] and (isset($_POST['create_migrations']['scaffold']) and $row != $_POST['create_migrations']['scaffold']) and $row['Field'] !== ''):
					$arraux[] = array('field' => $row['Field'], 'type' => $row['Type'], 'null' => (isset($row['NotNull']) and $row['NotNull'] == 'on')? 'false': 'true', 'limit' => (isset($row['Length']))? $row['Length']: NULL);
				endif;
			}
			$path=INST_PATH.'migrations/';
			//$fp = fopen($path.'create_'.strtolower($arraux['Table']).'.php', "w+b");
			$string = "<?php \n class Create".Camelize(Singulars(strtolower($arraux['Table'])));
			$string .= " extends Migrations{ \n";
			$string .= "\tfunction up(){ \n";
			$string .= "\t\t".'$this'."->Create_Table(array('Table'=>'".$arraux['Table']."', \n";
			$i=2;
			foreach($arraux as $row){
				if($row != $arraux['Table']):
					$string .= "\t\t\t\t\t\t\t\tarray('field'=>'".$row['field']."', 'type'=>'".$row['type']."', 'null'=>'".$row['null']."'";
					if(isset($row['limit']) and $row['limit']) $string .= ", 'limit'=>'".$row['limit']."'";
					$string .= ")";
					if($i < sizeof($arraux)):
						$string .= ", \n";
					else:
						$string .= "\n";
					endif;
					$i++;
				endif;
			}
			$string .= "\t\t\t\t\t\t\t)); \n";
			$string .= "\t}\n";
			$string .= "\tfunction down(){\n";
			$string .= "\t\t".'$this'."->Drop_Table('".$arraux['Table']."');\n";
			$string .= "\t}\n}\n";
			$string .= "?>";
			file_put_contents($path.'create_'.strtolower($arraux['Table']).'.php', $string);
			//fwrite($fp, $string);
			//fclose($fp);

			if(isset($_POST['create_migrations']['scaffold']) and $_POST['create_migrations']['scaffold'] = 'on'):
				include_once('Scaffold.php');
			endif;

		endif;
		header("Location: ".INST_URI."console/index");
		exit;
	}
Beispiel #4
0
 /**
  * Metodo publico WriteModel($table)
  *
  * Este metodo se encarga de escribir en disco el archivo preliminar de modelo.
  * @param string $table Nombre de la tabla para crearle el modelo.
  */
 function WriteModel($table)
 {
     $file = Singulars($table) . ".php";
     $modelpath = INST_PATH . 'app/models/';
     if (!file_exists($modelpath . $file)) {
         $newModel = "<?php \n";
         $newModel .= "class " . Camelize(str_replace('.php', '', $file)) . " extends ActiveRecord {\n";
         $newModel .= "\tfunction __construct(){ \n";
         $newModel .= "\t} \n";
         $newModel .= "} \n";
         $newModel .= "?>";
         $fp = fopen($modelpath . $file, "w+b");
         fputs($fp, $newModel);
         fclose($fp);
     }
 }
 function paramsAction()
 {
     if (!empty($_POST)) {
         $pos = key($_POST);
         $model = Camelize($pos);
         $objCat = $this->{$model}->Niu($_POST[$pos]);
         $objCat->Save() or print $objCat->_error;
     }
     //social networks
     $this->network = $this->SocialNetwork->Niu();
     $this->networks = $this->SocialNetwork->Find();
     //stats
     $this->stat = $this->Stat->Niu();
     $this->stats = $this->Stat->Find();
     //countries
     $this->country = $this->Country->Niu();
     $this->countries = $this->Country->Find();
     //clients
     $this->client = $this->Client->Niu();
     $this->clients = $this->Client->Find();
     //clasifications
     $this->clasification = $this->Clasification->Niu();
     $this->clasifications = $this->Clasification->Find();
     //profiles
     $this->profile = $this->Profile->Niu();
     $this->profiles = $this->Profile->Find();
     //lugares (restaurante, etc)
     $this->place = $this->Place->Niu();
     $this->places = $this->Place->Find();
     //campaigns
     $this->campaign = $this->Campaign->Niu();
     $this->campaigns = $this->Campaign->Find();
     // message kinds
     $this->message_kind = $this->MessageKind->Niu();
     $this->message_kinds = $this->MessageKind->Find();
     // Fanpages
     $this->fanpage = $this->Fanpage->Niu();
     $this->fanpages = $this->Fanpage->Find();
     $this->title = 'Par&aacute;metros';
 }
Beispiel #6
0
<?
$arraux = (isset($arraux))? $arraux: NULL;
$path=INST_PATH;
				$_POST['migrations'][$arraux['Table']] = 'on';
				$_POST['migrations']['up:selected'] = true;
				$this->MigrationsActions();
				$file = Singulars(strtolower($arraux['Table']));
				// Creation of model
				$Obj = new NewAr();
				$Obj->WriteModel($arraux['Table']);
				
				
				// Creation of the list view
				$ClassName = Camelize($arraux['Table']);
				$ClassToUse = Camelize(Singulars($arraux['Table']));
				$directory = INST_PATH."app/templates/$file/";
				if(!is_dir($directory)) mkdir($directory);
				$fp = fopen($directory.'index.phtml', 'w+b');
				$content = '<div style="float:left; width:100%;">'."\n";
				$content .= "\t".'<div align="center">'."\n";
				$content .= "\t\t".'<table width="100%">'."\n";
				$content .= "\t\t\t".'<? foreach($this->data as $row){ ?>'."\n";
				$content .= "\t\t\t<tr>\n";
				$content .= "\t\t\t".'<? foreach($row->getArray() as $col){ ?>'."\n";
				$content .= "\t\t\t\t".'<td><?=$col;?></td>'."\n";
				$content .= "\t\t\t<? } ?>\n";
				$content .= "\t\t\t\t<td><a href=\"<?=INST_URI;?>$file/delete/<?=\$row->id;?>\">delete</a>&nbsp;<a href=\"<?=INST_URI;?>$file/addedit/<?=\$row->id;?>\">Edit</a></td>\n";
				$content .= "\t\t\t</tr>\n";
				$content .= "\t\t\t<? } ?>\n";
				$content .= "\t\t</table>\n";
				$content .= "\t</div>\n";
Beispiel #7
0
 function __construct()
 {
     if (isset($_GET['_error'])) {
         switch ($_GET['_error']) {
             case '401':
             case '403':
             case '404':
             case '500':
                 echo 'Error! (' . $_GET['_error'] . ')';
                 break;
         }
         die;
     }
     if (isset($_GET['url'])) {
         $request = explode("/", $_GET['url']);
         unset($_GET['url']);
     }
     $path = INST_PATH . 'app/controllers/';
     if (!isset($request[0]) or strcmp($request[0], "") === 0) {
         $request[0] = DEF_CONTROLLER;
     }
     if (!isset($request[1]) or strcmp($request[1], "") === 0) {
         $request[1] = DEF_ACTION;
     }
     $controllerFile = $request[0] . "_controller.php";
     $controller = array_shift($request);
     $action = array_shift($request);
     foreach ($request as $key => $value) {
         if (empty($value)) {
             unset($request[$key]);
         }
     }
     $params = array();
     if (sizeof($request) === 1 and !strstr($request[0], "=") and is_numeric($request[0])) {
         $params['id'] = $request[0];
     } elseif (sizeof($request) > 0 and strstr($request[0], "=")) {
         for ($i = 0; $i < sizeof($request); $i++) {
             $p = explode('=', $request[$i]);
             if (isset($p[1])) {
                 $params[$p[0]] = $p[1];
             } else {
                 $params[] = $p[0];
             }
             unset($request[$i]);
         }
     } elseif (sizeof($request) > 0) {
         foreach ($request as $index => $varParam) {
             $params[] = $varParam;
             unset($request[$index]);
         }
     }
     if (is_array($params)) {
         $params = array_merge($params, $_GET);
     } else {
         $params = $_GET;
     }
     if (defined('SITE_STATUS') and SITE_STATUS == 'MAINTENANCE') {
         $urlToLand = explode('/', LANDING_PAGE);
         $replace = false;
         if (LANDING_REPLACE == 'ALL') {
             $replace = true;
         } else {
             $locations = explode(',', LANDING_REPLACE);
             if (in_array($controller . '/' . $action, $locations)) {
                 $replace = true;
             }
         }
         if ($replace) {
             $controller = $urlToLand[0];
             $action = $urlToLand[1];
             $controllerFile = $controller . '_controller.php';
         }
     }
     define('_CONTROLLER', $controller);
     define('_ACTION', $action);
     define("_FULL_URL", INST_URI . _CONTROLLER . '/' . _ACTION . '/' . implode('/', $params));
     if (file_exists($path . $controllerFile)) {
         require $path . $controllerFile;
         $classPage = Camelize($controller) . "Controller";
         $page = new $classPage();
         $page->params($params);
         // 			$page->__controller = $controller;
         // 			$page->__action = $action;
         //loads of helpers
         if (isset($page->helper) and sizeof($page->helper) > 0) {
             $page->LoadHelper($page->helper);
         }
         //before filter, executed before the action execution
         if (method_exists($page, "before_filter")) {
             $page->before_filter();
         }
         if (method_exists($page, $action . "Action")) {
             $page->{$action . "Action"}();
             //before render, executed after the action execution and before the data renderize
             if (method_exists($page, "before_render")) {
                 $page->before_render();
             }
             if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) and $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' and $page->canRespondToAJAX()) {
                 echo $page->respondToAJAX();
             } else {
                 $page->display(array('controller' => $controller, 'action' => $action));
             }
         } else {
             echo "Missing Action";
         }
     } else {
         echo "Missing Controller";
     }
 }
 function ToPascalCase($String)
 {
     return Camelize($String);
 }
Beispiel #9
0
 /**
  * método mágico __call()
  * 
  * Este método es ejecutado por PHP cuando se accede a un m?todo que no existe.
  * A través de este método mágico se realiza el mapeo relacional, asumiendo que el llamado
  * a un método, es el llamado a un modelo realiza la subconsulta según las condiciones de relación y devuelve el 
  * objeto del modelo requerido.
  * Es imperativo que las variables {@link $has_many}, {@link $belongs_to}, {@link $has_one}, {@link $has_and_belongs_to}, 
  * estén correctamente creadas con las tablas a las que tienen su relación.
  * Tambien define el comportamiento cuando se hace un llamado a un método no definido en la clase, invocando a la función 
  * definida en las extensiones.
  * Incluso define el comportamiento del método Find_by_{campo_en_la_tabla}().
  *
  * @param string $ClassName Nombre del método al que se invoca.
  * @param mixed $val Valor pasado por parámetro dentro del método.
  */
 public function __call($ClassName, $val = NULL)
 {
     $field = Singulars(strtolower($ClassName));
     $classFromCall = Camelize($ClassName);
     if (preg_match('/Find_by_/', $ClassName)) {
         $nustring = str_replace("Find_by_", '', $ClassName);
         return $this->Find(array('conditions' => '`' . $nustring . "`='" . $val[0] . "'"));
     } elseif (file_exists(INST_PATH . 'app/models/' . $field . '.php')) {
         $way = isset($val[0]) ? $val[0] : 'down';
         $foreign = strtolower($field) . "_id";
         $prefix = unCamelize(get_class($this));
         if (!class_exists($classFromCall)) {
             require_once INST_PATH . 'app/models/' . $field . '.php';
         }
         $obj1 = new $classFromCall();
         $conditions = "`" . $prefix . "_id`='" . $this->id . "'";
         if (get_parent_class($obj1) == 'ActiveRecord') {
             if ($classFromCall == get_class($this) and in_array($ClassName, $this->has_many_and_belongs_to)) {
                 $conditions = $way == 'up' ? "id='" . $this->{$foreign} . "'" : $conditions;
             } elseif (in_array($ClassName, $this->belongs_to)) {
                 $conditions = "id='" . $this->{$foreign} . "'";
             }
             return $conditions !== NULL ? $obj1->Find(array('conditions' => $conditions)) : $obj1->Niu();
         }
         return NULL;
     } else {
         return $ClassName($val, $this);
     }
 }