commit
0c4ab031b1
45 changed files with 2775 additions and 737 deletions
|
|
@ -1,6 +1,2 @@
|
||||||
# phamodels
|
# phamodels
|
||||||
A simple component for create models.
|
|
||||||
|
|
||||||
## About
|
|
||||||
|
|
||||||
PhaModels is a simple component for create a lightweight ORM for MySQL.
|
PhaModels is a simple component for create a lightweight ORM for MySQL.
|
||||||
|
|
|
||||||
479
bin/padmin
Executable file
479
bin/padmin
Executable file
|
|
@ -0,0 +1,479 @@
|
||||||
|
#!/usr/bin/php
|
||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
if (file_exists(__DIR__.'/../../../autoload.php'))
|
||||||
|
{
|
||||||
|
require __DIR__.'/../../../autoload.php';
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
require __DIR__.'/vendor/autoload.php';
|
||||||
|
}
|
||||||
|
|
||||||
|
use PhangoApp\PhaModels\SQLClass;
|
||||||
|
use PhangoApp\PhaModels\Webmodel;
|
||||||
|
use PhangoApp\PhaUtils\Utils;
|
||||||
|
use League\CLImate\CLImate;
|
||||||
|
|
||||||
|
Utils::load_config('config');
|
||||||
|
|
||||||
|
$options=getopt('', array('model:'));
|
||||||
|
|
||||||
|
padminConsole($options);
|
||||||
|
|
||||||
|
function padminConsole($options)
|
||||||
|
{
|
||||||
|
|
||||||
|
#$options=get_opts_console('', $arr_opts=array('model:'));
|
||||||
|
|
||||||
|
$climate = new League\CLImate\CLImate;
|
||||||
|
|
||||||
|
if(!isset($options['model']))
|
||||||
|
{
|
||||||
|
|
||||||
|
//echo "Use: php console.php -m=padmin -c=padmin --model=module/model\n";
|
||||||
|
|
||||||
|
$climate->white()->backgroundBlack()->out("Use: padmin --model=path/to/model");
|
||||||
|
|
||||||
|
exit(0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$arr_option=explode('/', $options['model']);
|
||||||
|
|
||||||
|
settype($arr_option[0], 'string');
|
||||||
|
settype($arr_option[1], 'string');
|
||||||
|
|
||||||
|
#Webmodel::$model_path='./modules/';
|
||||||
|
|
||||||
|
$model_file=$options['model'].'.php';
|
||||||
|
|
||||||
|
if(!is_file($model_file))
|
||||||
|
{
|
||||||
|
|
||||||
|
$climate->white()->backgroundRed()->out("Error: cannot find the model file in ".$arr_option[0]."/models/models_".$arr_option[1].".php");
|
||||||
|
|
||||||
|
exit(1);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
WebModel::load_model($options['model']);
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
if(count(Webmodel::$model)>0)
|
||||||
|
{
|
||||||
|
|
||||||
|
$first_item=current(Webmodel::$model);
|
||||||
|
|
||||||
|
$first_item->connect_to_db();
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$climate->white()->backgroundRed()->out('Error: file don\'t have models');
|
||||||
|
exit(1);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch(Exception $e)
|
||||||
|
{
|
||||||
|
$climate->white()->backgroundRed()->out($e->getMessage());
|
||||||
|
exit(1);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//print_r(get_declared_classes());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
update_table();
|
||||||
|
|
||||||
|
$post_install_script=Webmodel::$model_path.$arr_option[0].'/install/post_install.php';
|
||||||
|
|
||||||
|
$post_install_lock=Webmodel::$model_path.$arr_option[0].'/install/lock';
|
||||||
|
|
||||||
|
if(file_exists($post_install_script) && !file_exists($post_install_lock))
|
||||||
|
{
|
||||||
|
|
||||||
|
//echo "Executing post_install script...\n";
|
||||||
|
|
||||||
|
$climate->white()->backgroundBlack()->out('Executing post_install script...');
|
||||||
|
|
||||||
|
include($post_install_script);
|
||||||
|
|
||||||
|
if(post_install())
|
||||||
|
{
|
||||||
|
|
||||||
|
if(!file_put_contents($post_install_lock, 'installed'))
|
||||||
|
{
|
||||||
|
|
||||||
|
//echo "Done, but cannot create this file: ".$arr_option[0].'/install/lock'.". Check your permissions and create the file if the script executed satisfally \n";
|
||||||
|
$climate->white()->backgroundBlack()->out("Done, but cannot create this file: ".$arr_option[0].'/install/lock'.". Check your permissions and create the file if the script executed satisfally");
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
//echo "Done\n";
|
||||||
|
$climate->white()->backgroundBlack()->out('Done');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
//echo "Error, please, check ${post_install_script} file and execute padmin.php again\n";
|
||||||
|
$climate->white()->backgroundRed()->out("Error, please, check ${post_install_script} file and execute padmin.php again");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//echo "All things done\n";
|
||||||
|
|
||||||
|
$climate->white()->backgroundBlack()->out("All things done");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This Function is used for padmin.php for create new tables and fields based in Webmodel class.
|
||||||
|
*
|
||||||
|
* @param Webmodel $model The model used for create or update a sql table.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function update_table()
|
||||||
|
{
|
||||||
|
//include(__DIR__.'/../src/Databases/'.Webmodel::$type_db.'.php');
|
||||||
|
|
||||||
|
Webmodel::$arr_sql_index=array();
|
||||||
|
Webmodel::$arr_sql_set_index=array();
|
||||||
|
|
||||||
|
Webmodel::$arr_sql_unique=array();
|
||||||
|
Webmodel::$arr_sql_set_unique=array();
|
||||||
|
|
||||||
|
$arr_etable=array();
|
||||||
|
|
||||||
|
$query=SQLClass::webtsys_query("show tables");
|
||||||
|
|
||||||
|
while(list($table)=SQLClass::webtsys_fetch_row($query))
|
||||||
|
{
|
||||||
|
|
||||||
|
$arr_etable[$table]=1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach(Webmodel::$model as $key => $thing)
|
||||||
|
{
|
||||||
|
|
||||||
|
$arr_table=array();
|
||||||
|
|
||||||
|
$allfields=array();
|
||||||
|
$fields=array();
|
||||||
|
$types=array();
|
||||||
|
$defaults=array();
|
||||||
|
|
||||||
|
$field="";
|
||||||
|
$type="";
|
||||||
|
$null="";
|
||||||
|
$key_db="";
|
||||||
|
$default="";
|
||||||
|
$extra="";
|
||||||
|
$key_field_old=Webmodel::$model[$key]->idmodel;
|
||||||
|
|
||||||
|
if(!isset($arr_etable[$key]))
|
||||||
|
{
|
||||||
|
//If table not exists make this
|
||||||
|
|
||||||
|
echo "Creating table $key\n";
|
||||||
|
|
||||||
|
Webmodel::$model[$key]->create_table();
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if(isset(Webmodel::$model[$key]))
|
||||||
|
{
|
||||||
|
//Obtain all fields of model
|
||||||
|
|
||||||
|
foreach(Webmodel::$model[$key]->components as $kfield => $value)
|
||||||
|
{
|
||||||
|
|
||||||
|
$allfields[$kfield]=1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//unset($allfields['Id'.ucfirst($key)]);
|
||||||
|
|
||||||
|
$arr_null['NO']='NOT NULL';
|
||||||
|
$arr_null['YES']='NULL';
|
||||||
|
|
||||||
|
unset($allfields[Webmodel::$model[$key]->idmodel]);
|
||||||
|
|
||||||
|
$query=SQLClass::webtsys_query("describe `".$key."`");
|
||||||
|
|
||||||
|
list($key_field_old, $type, $null, $key_db, $default, $extra)=SQLClass::webtsys_fetch_row($query);
|
||||||
|
|
||||||
|
while(list($field, $type, $null, $key_db, $default, $extra)=SQLClass::webtsys_fetch_row($query))
|
||||||
|
{
|
||||||
|
|
||||||
|
$fields[]=$field;
|
||||||
|
$types[$field]=$type;
|
||||||
|
$keys[$field]=$key_db;
|
||||||
|
$defaults[$field]=$default;
|
||||||
|
|
||||||
|
$null_set[$field]=$arr_null[$null];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach($fields as $field)
|
||||||
|
{
|
||||||
|
|
||||||
|
if(isset($allfields[$field]))
|
||||||
|
{
|
||||||
|
|
||||||
|
$type=strtoupper($types[$field]);
|
||||||
|
|
||||||
|
unset($allfields[$field]);
|
||||||
|
|
||||||
|
if(Webmodel::$model[$key]->components[$field]->get_type_sql()!=($type.' '.$null_set[$field].' DEFAULT "'.$defaults[$field].'"'))
|
||||||
|
{
|
||||||
|
|
||||||
|
$query=SQLClass::webtsys_query('alter table `'.$key.'` modify `'.$field.'` '.Webmodel::$model[$key]->components[$field]->get_type_sql());
|
||||||
|
|
||||||
|
echo "Upgrading ".$field." from ".$key."...\n";
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Check if indexed
|
||||||
|
|
||||||
|
if(Webmodel::$model[$key]->components[$field]->indexed==true && $keys[$field]=='')
|
||||||
|
{
|
||||||
|
|
||||||
|
Webmodel::$arr_sql_index[$key][$field]='CREATE INDEX `index_'.$key.'_'.$field.'` ON `'.$key.'`(`'.$field.'`);';
|
||||||
|
Webmodel::$arr_sql_set_index[$key][$field]='';
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Check if unique
|
||||||
|
|
||||||
|
if(Webmodel::$model[$key]->components[$field]->unique==true && $keys[$field]=='')
|
||||||
|
{
|
||||||
|
|
||||||
|
Webmodel::$arr_sql_unique[$key][$field]=' ALTER TABLE `'.$key.'` ADD UNIQUE (`'.$field.'`)';
|
||||||
|
Webmodel::$arr_sql_set_unique[$key][$field]='';
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Set index
|
||||||
|
|
||||||
|
if(isset(Webmodel::$model[$key]->components[$field]->related_model) && $keys[$field]=='')
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
Webmodel::$arr_sql_index[$key][$field]='CREATE INDEX `index_'.$key.'_'.$field.'` ON `'.$key.'`(`'.$field.'`);';
|
||||||
|
|
||||||
|
$table_related=Webmodel::$model[$key]->components[$field]->related_model->name;
|
||||||
|
|
||||||
|
$id_table_related=Webmodel::load_id_model_related(Webmodel::$model[$key]->components[$field], Webmodel::$model);
|
||||||
|
|
||||||
|
Webmodel::$arr_sql_set_index[$key][$field]='ALTER TABLE `'.$key.'` ADD CONSTRAINT `'.$field.'_'.$key.'IDX` FOREIGN KEY ( `'.$field.'` ) REFERENCES `'.$table_related.'` (`'.$id_table_related.'`) ON DELETE RESTRICT ON UPDATE RESTRICT;';
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!isset(Webmodel::$model[$key]->components[$field]->related_model) && $keys[$field]!='' && Webmodel::$model[$key]->components[$field]->indexed==false && Webmodel::$model[$key]->components[$field]->unique!=true)
|
||||||
|
{
|
||||||
|
|
||||||
|
echo "---Delete index for ".$field." from ".$key."\n";
|
||||||
|
|
||||||
|
$query=SQLClass::webtsys_query('DROP INDEX `index_'.$key.'_'.$field.'` ON '.$key);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
|
||||||
|
{
|
||||||
|
|
||||||
|
$allfields[$field]=0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Check if new id...
|
||||||
|
|
||||||
|
if($key_field_old!=Webmodel::$model[$key]->idmodel)
|
||||||
|
{
|
||||||
|
|
||||||
|
$query=SQLClass::webtsys_query('alter table `'.$key.'` change `'.$key_field_old.'` `'.Webmodel::$model[$key]->idmodel.'` INT NOT NULL AUTO_INCREMENT');
|
||||||
|
|
||||||
|
echo "Renaming id for this model to ".Webmodel::$model[$key]->idmodel."...\n";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Check if new fields...
|
||||||
|
|
||||||
|
foreach($allfields as $new_field => $new)
|
||||||
|
{
|
||||||
|
|
||||||
|
if($allfields[$new_field]==1)
|
||||||
|
{
|
||||||
|
|
||||||
|
$query=SQLClass::webtsys_query('alter table `'.$key.'` add `'.$new_field.'` '.Webmodel::$model[$key]->components[$new_field]->get_type_sql());
|
||||||
|
|
||||||
|
echo "Adding ".$new_field." to ".$key."...\n";
|
||||||
|
|
||||||
|
//Check if indexed
|
||||||
|
|
||||||
|
if(Webmodel::$model[$key]->components[$new_field]->indexed==true)
|
||||||
|
{
|
||||||
|
|
||||||
|
Webmodel::$arr_sql_index[$key][$new_field]='CREATE INDEX `index_'.$key.'_'.$new_field.'` ON `'.$key.'`(`'.$new_field.'`);';
|
||||||
|
Webmodel::$arr_sql_set_index[$key][$new_field]='';
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isset(Webmodel::$model[$key]->components[$new_field]->related_model) )
|
||||||
|
{
|
||||||
|
|
||||||
|
/*echo "---Creating index for ".$new_field." from ".$key."\n";
|
||||||
|
|
||||||
|
$query=SQLClass::webtsys_query('CREATE INDEX index_'.$key.'_'.$new_field.' ON '.$key.'('.$new_field.')');*/
|
||||||
|
|
||||||
|
Webmodel::$arr_sql_index[$key][$new_field]='CREATE INDEX `index_'.$key.'_'.$new_field.'` ON `'.$key.'`(`'.$new_field.'`);';
|
||||||
|
|
||||||
|
$table_related=Webmodel::$model[$key]->components[$new_field]->related_model->name;
|
||||||
|
|
||||||
|
$id_table_related=Webmodel::load_id_model_related(Webmodel::$model[$key]->components[$new_field], $model);
|
||||||
|
|
||||||
|
Webmodel::$arr_sql_set_index[$key][$new_field]='ALTER TABLE `'.$key.'` ADD CONSTRAINT `'.$new_field.'_'.$key.'IDX` FOREIGN KEY ( `'.$new_field.'` ) REFERENCES `'.$table_related.'` (`'.$id_table_related.'`) ON DELETE RESTRICT ON UPDATE RESTRICT;';
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
|
||||||
|
{
|
||||||
|
|
||||||
|
//Bug, need fixed.
|
||||||
|
if($keys[$new_field]!='')
|
||||||
|
{
|
||||||
|
|
||||||
|
$query=SQLClass::webtsys_query('ALTER TABLE `'.$key.'` DROP FOREIGN KEY '.$new_field.'_'.$key.'IDX');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//}
|
||||||
|
|
||||||
|
$query=SQLClass::webtsys_query('alter table `'.$key.'` drop `'.$new_field.'`');
|
||||||
|
|
||||||
|
echo "Deleting ".$new_field." from ".$key."...\n";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$arr_etable[$key]=0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Create Indexes...
|
||||||
|
|
||||||
|
foreach(Webmodel::$arr_sql_index as $model_name => $arr_index)
|
||||||
|
{
|
||||||
|
foreach(Webmodel::$arr_sql_index[$model_name] as $key_data => $sql_index)
|
||||||
|
{
|
||||||
|
|
||||||
|
echo "---Creating index for ".$key_data." on model ".$model_name."\n";
|
||||||
|
|
||||||
|
$query=SQLClass::webtsys_query($sql_index);
|
||||||
|
|
||||||
|
if(Webmodel::$arr_sql_set_index[$model_name][$key_data]!='')
|
||||||
|
{
|
||||||
|
$query=SQLClass::webtsys_query(Webmodel::$arr_sql_set_index[$model_name][$key_data]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Create Uniques...
|
||||||
|
|
||||||
|
foreach(Webmodel::$arr_sql_unique as $model_name => $arr_index)
|
||||||
|
{
|
||||||
|
foreach(Webmodel::$arr_sql_unique[$model_name] as $key_data => $sql_index)
|
||||||
|
{
|
||||||
|
|
||||||
|
echo "---Creating unique for ".$key_data." on model ".$model_name."\n";
|
||||||
|
|
||||||
|
$query=SQLClass::webtsys_query($sql_index);
|
||||||
|
|
||||||
|
if(Webmodel::$arr_sql_set_unique[$model_name][$key_data]!='')
|
||||||
|
{
|
||||||
|
$query=SQLClass::webtsys_query(Webmodel::$arr_sql_set_unique[$model_name][$key_data]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function load_id_model_related($foreignkeyfield)
|
||||||
|
{
|
||||||
|
|
||||||
|
//global $model;
|
||||||
|
|
||||||
|
$table_related=$foreignkeyfield->related_model->name;
|
||||||
|
|
||||||
|
$id_table_related='';
|
||||||
|
|
||||||
|
if(!isset(Webmodel::$model[ $table_related ]->idmodel))
|
||||||
|
{
|
||||||
|
|
||||||
|
//$id_table_related='Id'.ucfirst(PhangoVar::Webmodel::$model[$key]->components[$new_field]->related_model);
|
||||||
|
//Need load the model
|
||||||
|
|
||||||
|
if(isset($foreignkeyfield->params_loading_mod['module']) && isset($foreignkeyfield->params_loading_mod['model']))
|
||||||
|
{
|
||||||
|
|
||||||
|
$model=load_model($foreignkeyfield->params_loading_mod);
|
||||||
|
|
||||||
|
//obtain id
|
||||||
|
|
||||||
|
$id_table_related=Webmodel::$model[ $foreignkeyfield->params_loading_mod['model'] ]->idmodel;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
$id_table_related=Webmodel::$model[ $table_related ]->idmodel;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if($id_table_related=='')
|
||||||
|
{
|
||||||
|
|
||||||
|
//Set standard...
|
||||||
|
|
||||||
|
$id_table_related='Id'.ucfirst($table_related);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return $id_table_related;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
536
bin/padmin.php
536
bin/padmin.php
|
|
@ -1,536 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
include(__DIR__.'/../../../../autoload.php');
|
|
||||||
|
|
||||||
use PhangoApp\PhaRouter\Routes;
|
|
||||||
use PhangoApp\PhaRouter\Controller;
|
|
||||||
use PhangoApp\PhaModels\Webmodel;
|
|
||||||
use PhangoApp\PhaModels\ModelForm;
|
|
||||||
use PhangoApp\PhaView\View;
|
|
||||||
use PhangoApp\PhaI18n\I18n;
|
|
||||||
use PhangoApp\PhaUtils\Utils;
|
|
||||||
use PhangoApp\PhaModels\MySQLClass;
|
|
||||||
|
|
||||||
class_alias('PhangoApp\PhaRouter\Controller', 'ControllerSwitchClass');
|
|
||||||
class_alias('PhangoApp\PhaRouter\Routes', 'Routes');
|
|
||||||
class_alias('PhangoApp\PhaModels\Webmodel', 'Webmodel');
|
|
||||||
class_alias('PhangoApp\PhaModels\ModelForm', 'ModelForm');
|
|
||||||
class_alias('PhangoApp\PhaModels\MySQLClass', 'MySQLClass');
|
|
||||||
class_alias('PhangoApp\PhaView\View', 'View');
|
|
||||||
class_alias('PhangoApp\PhaUtils\Utils', 'Utils');
|
|
||||||
class_alias('PhangoApp\PhaI18n\I18n', 'I18n');
|
|
||||||
|
|
||||||
include(__DIR__.'/../../../../libraries/phangovar.php');
|
|
||||||
|
|
||||||
$options = getopt("m:");
|
|
||||||
|
|
||||||
if(!isset($options['m']))
|
|
||||||
{
|
|
||||||
|
|
||||||
die("Use: php padmin.php -m app/model\n");
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
if(strpos($options['m'], '/')===false)
|
|
||||||
{
|
|
||||||
|
|
||||||
die("Use: php padmin.php -m app/model\n");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
$arr_option=explode('/', $options['m']);
|
|
||||||
|
|
||||||
settype($arr_option[0], 'string');
|
|
||||||
settype($arr_option[1], 'string');
|
|
||||||
|
|
||||||
//Load the config.
|
|
||||||
|
|
||||||
include(__DIR__.'/../../../../config.php');
|
|
||||||
|
|
||||||
Webmodel::$model_path=__DIR__.'/../../../../modules/';
|
|
||||||
|
|
||||||
$model_file=Webmodel::$model_path.$arr_option[0].'/models/models_'.$arr_option[1].'.php';
|
|
||||||
|
|
||||||
if(!is_file($model_file))
|
|
||||||
{
|
|
||||||
|
|
||||||
die("Error: cannot find the model file in ".$arr_option[0]."/models/models_".$arr_option[1].".php\n");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
WebModel::load_model($options['m']);
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
$first_item=current($model);
|
|
||||||
|
|
||||||
$first_item->connect_to_db();
|
|
||||||
|
|
||||||
} catch(Exception $e)
|
|
||||||
{
|
|
||||||
|
|
||||||
echo $e->getMessage()."\n";
|
|
||||||
die;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//print_r(get_declared_classes());
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
update_table(Webmodel::$model);
|
|
||||||
|
|
||||||
$post_install_script=Webmodel::$model_path.$arr_option[0].'/install/post_install.php';
|
|
||||||
|
|
||||||
$post_install_lock=Webmodel::$model_path.$arr_option[0].'/install/lock';
|
|
||||||
|
|
||||||
if(file_exists($post_install_script) && !file_exists($post_install_lock))
|
|
||||||
{
|
|
||||||
|
|
||||||
echo "Executing post_install script...\n";
|
|
||||||
|
|
||||||
include($post_install_script);
|
|
||||||
|
|
||||||
if(post_install())
|
|
||||||
{
|
|
||||||
|
|
||||||
if(!file_put_contents($post_install_lock, 'installed'))
|
|
||||||
{
|
|
||||||
|
|
||||||
echo "Done, but cannot create this file: ".$arr_option[0].'/install/lock'.". Check your permissions and create the file if the script executed satisfally \n";
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
echo "Done\n";
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
echo "Error, please, check ${post_install_script} file and execute padmin.php again\n";
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
echo "All things done\n";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This Function is used for padmin.php for create new tables and fields based in Webmodel class.
|
|
||||||
*
|
|
||||||
* @param Webmodel $model The model used for create or update a sql table.
|
|
||||||
*/
|
|
||||||
|
|
||||||
function update_table($model)
|
|
||||||
{
|
|
||||||
//include(__DIR__.'/../src/Databases/'.Webmodel::$type_db.'.php');
|
|
||||||
|
|
||||||
$arr_sql_index=array();
|
|
||||||
$arr_sql_set_index=array();
|
|
||||||
|
|
||||||
$arr_sql_unique=array();
|
|
||||||
$arr_sql_set_unique=array();
|
|
||||||
|
|
||||||
$arr_etable=array();
|
|
||||||
|
|
||||||
$query=MySQLClass::webtsys_query("show tables");
|
|
||||||
|
|
||||||
while(list($table)=MySQLClass::webtsys_fetch_row($query))
|
|
||||||
{
|
|
||||||
|
|
||||||
$arr_etable[$table]=1;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach($model as $key => $thing)
|
|
||||||
|
|
||||||
{
|
|
||||||
|
|
||||||
$arr_table=array();
|
|
||||||
|
|
||||||
$allfields=array();
|
|
||||||
$fields=array();
|
|
||||||
$types=array();
|
|
||||||
|
|
||||||
$field="";
|
|
||||||
$type="";
|
|
||||||
$null="";
|
|
||||||
$key_db="";
|
|
||||||
$default="";
|
|
||||||
$extra="";
|
|
||||||
$key_field_old=$model[$key]->idmodel;
|
|
||||||
|
|
||||||
if(!isset($arr_etable[$key]))
|
|
||||||
{
|
|
||||||
//If table not exists make this
|
|
||||||
|
|
||||||
foreach($model[$key]->components as $field => $data)
|
|
||||||
{
|
|
||||||
|
|
||||||
$arr_table[]='`'.$field.'` '.$model[$key]->components[$field]->get_type_sql();
|
|
||||||
|
|
||||||
//Check if indexed
|
|
||||||
|
|
||||||
if($model[$key]->components[$field]->indexed==true)
|
|
||||||
{
|
|
||||||
|
|
||||||
$arr_sql_index[$key][$field]='CREATE INDEX `index_'.$key.'_'.$field.'` ON '.$key.'(`'.$field.'`);';
|
|
||||||
$arr_sql_set_index[$key][$field]='';
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//Check if unique
|
|
||||||
|
|
||||||
if($model[$key]->components[$field]->unique==true)
|
|
||||||
{
|
|
||||||
|
|
||||||
$arr_sql_unique[$key][$field]=' ALTER TABLE `'.$key.'` ADD UNIQUE (`'.$field.'`)';
|
|
||||||
$arr_sql_set_unique[$key][$field]='';
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//Check if foreignkeyfield...
|
|
||||||
if(isset($model[$key]->components[$field]->related_model))
|
|
||||||
{
|
|
||||||
|
|
||||||
//Create indexes...
|
|
||||||
|
|
||||||
$arr_sql_index[$key][$field]='CREATE INDEX `index_'.$key.'_'.$field.'` ON '.$key.'(`'.$field.'`);';
|
|
||||||
|
|
||||||
$table_related=$model[$key]->components[$field]->related_model->name;
|
|
||||||
|
|
||||||
$id_table_related=load_id_model_related($model[$key]->components[$field], $model);
|
|
||||||
|
|
||||||
//'Id'.ucfirst($model[$key]->components[$field]->related_model);
|
|
||||||
|
|
||||||
$arr_sql_set_index[$key][$field]='ALTER TABLE `'.$key.'` ADD CONSTRAINT `'.$field.'_'.$key.'IDX` FOREIGN KEY ( `'.$field.'` ) REFERENCES `'.$table_related.'` (`'.$id_table_related.'`) ON DELETE RESTRICT ON UPDATE RESTRICT;';
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$sql_query="create table `$key` (\n".implode(",\n", $arr_table)."\n) DEFAULT CHARSET=utf8;\n";
|
|
||||||
|
|
||||||
echo "Creating table $key\n";
|
|
||||||
|
|
||||||
$query=MySQLClass::webtsys_query($sql_query);
|
|
||||||
|
|
||||||
/*foreach($arr_sql_index as $key_data => $sql_index)
|
|
||||||
{
|
|
||||||
|
|
||||||
echo "---Creating index for ".$key_data."\n";
|
|
||||||
|
|
||||||
$query=MySQLClass::webtsys_query($sql_index);
|
|
||||||
$query=MySQLClass::webtsys_query($arr_sql_set_index[$key_data]);
|
|
||||||
|
|
||||||
}*/
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
if(isset($model[$key]))
|
|
||||||
{
|
|
||||||
//Obtain all fields of model
|
|
||||||
|
|
||||||
foreach($model[$key]->components as $kfield => $value)
|
|
||||||
{
|
|
||||||
|
|
||||||
$allfields[$kfield]=1;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//unset($allfields['Id'.ucfirst($key)]);
|
|
||||||
|
|
||||||
$arr_null['NO']='NOT NULL';
|
|
||||||
$arr_null['YES']='NULL';
|
|
||||||
|
|
||||||
unset($allfields[$model[$key]->idmodel]);
|
|
||||||
|
|
||||||
$query=MySQLClass::webtsys_query("describe `".$key."`");
|
|
||||||
|
|
||||||
list($key_field_old, $type, $null, $key_db, $default, $extra)=MySQLClass::webtsys_fetch_row($query);
|
|
||||||
|
|
||||||
while(list($field, $type, $null, $key_db, $default, $extra)=MySQLClass::webtsys_fetch_row($query))
|
|
||||||
{
|
|
||||||
|
|
||||||
$fields[]=$field;
|
|
||||||
$types[$field]=$type;
|
|
||||||
$keys[$field]=$key_db;
|
|
||||||
|
|
||||||
$null_set[$field]=$arr_null[$null];
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach($fields as $field)
|
|
||||||
{
|
|
||||||
|
|
||||||
if(isset($allfields[$field]))
|
|
||||||
{
|
|
||||||
|
|
||||||
$type=strtoupper($types[$field]);
|
|
||||||
|
|
||||||
unset($allfields[$field]);
|
|
||||||
|
|
||||||
if($model[$key]->components[$field]->get_type_sql()!=($type.' '.$null_set[$field]))
|
|
||||||
{
|
|
||||||
|
|
||||||
$query=MySQLClass::webtsys_query('alter table `'.$key.'` modify `'.$field.'` '.$model[$key]->components[$field]->get_type_sql());
|
|
||||||
|
|
||||||
echo "Upgrading ".$field." from ".$key."...\n";
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//Check if indexed
|
|
||||||
|
|
||||||
if($model[$key]->components[$field]->indexed==true && $keys[$field]=='')
|
|
||||||
{
|
|
||||||
|
|
||||||
$arr_sql_index[$key][$field]='CREATE INDEX `index_'.$key.'_'.$field.'` ON `'.$key.'`(`'.$field.'`);';
|
|
||||||
$arr_sql_set_index[$key][$field]='';
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//Check if unique
|
|
||||||
|
|
||||||
if($model[$key]->components[$field]->unique==true && $keys[$field]=='')
|
|
||||||
{
|
|
||||||
|
|
||||||
$arr_sql_unique[$key][$field]=' ALTER TABLE `'.$key.'` ADD UNIQUE (`'.$field.'`)';
|
|
||||||
$arr_sql_set_unique[$key][$field]='';
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//Set index
|
|
||||||
|
|
||||||
if(isset($model[$key]->components[$field]->related_model) && $keys[$field]=='')
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
$arr_sql_index[$key][$field]='CREATE INDEX `index_'.$key.'_'.$field.'` ON `'.$key.'`(`'.$field.'`);';
|
|
||||||
|
|
||||||
$table_related=$model[$key]->components[$field]->related_model->name;
|
|
||||||
|
|
||||||
$id_table_related=load_id_model_related($model[$key]->components[$field], $model);
|
|
||||||
|
|
||||||
$arr_sql_set_index[$key][$field]='ALTER TABLE `'.$key.'` ADD CONSTRAINT `'.$field.'_'.$key.'IDX` FOREIGN KEY ( `'.$field.'` ) REFERENCES `'.$table_related.'` (`'.$id_table_related.'`) ON DELETE RESTRICT ON UPDATE RESTRICT;';
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!isset($model[$key]->components[$field]->related_model) && $keys[$field]!='' && $model[$key]->components[$field]->indexed==false && $model[$key]->components[$field]->unique!=true)
|
|
||||||
{
|
|
||||||
|
|
||||||
echo "---Delete index for ".$field." from ".$key."\n";
|
|
||||||
|
|
||||||
$query=MySQLClass::webtsys_query('DROP INDEX `index_'.$key.'_'.$field.'` ON '.$key);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
else
|
|
||||||
|
|
||||||
{
|
|
||||||
|
|
||||||
$allfields[$field]=0;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//Check if new id...
|
|
||||||
|
|
||||||
if($key_field_old!=$model[$key]->idmodel)
|
|
||||||
{
|
|
||||||
|
|
||||||
$query=MySQLClass::webtsys_query('alter table `'.$key.'` change `'.$key_field_old.'` `'.$model[$key]->idmodel.'` INT NOT NULL AUTO_INCREMENT');
|
|
||||||
|
|
||||||
echo "Renaming id for this model to ".$model[$key]->idmodel."...\n";
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//Check if new fields...
|
|
||||||
|
|
||||||
foreach($allfields as $new_field => $new)
|
|
||||||
{
|
|
||||||
|
|
||||||
if($allfields[$new_field]==1)
|
|
||||||
{
|
|
||||||
|
|
||||||
$query=MySQLClass::webtsys_query('alter table `'.$key.'` add `'.$new_field.'` '.$model[$key]->components[$new_field]->get_type_sql());
|
|
||||||
|
|
||||||
echo "Adding ".$new_field." to ".$key."...\n";
|
|
||||||
|
|
||||||
//Check if indexed
|
|
||||||
|
|
||||||
if($model[$key]->components[$new_field]->indexed==true)
|
|
||||||
{
|
|
||||||
|
|
||||||
$arr_sql_index[$key][$new_field]='CREATE INDEX `index_'.$key.'_'.$new_field.'` ON `'.$key.'`(`'.$new_field.'`);';
|
|
||||||
$arr_sql_set_index[$key][$new_field]='';
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if(isset($model[$key]->components[$new_field]->related_model) )
|
|
||||||
{
|
|
||||||
|
|
||||||
/*echo "---Creating index for ".$new_field." from ".$key."\n";
|
|
||||||
|
|
||||||
$query=MySQLClass::webtsys_query('CREATE INDEX index_'.$key.'_'.$new_field.' ON '.$key.'('.$new_field.')');*/
|
|
||||||
|
|
||||||
$arr_sql_index[$key][$new_field]='CREATE INDEX `index_'.$key.'_'.$new_field.'` ON `'.$key.'`(`'.$new_field.'`);';
|
|
||||||
|
|
||||||
$table_related=$model[$key]->components[$new_field]->related_model->name;
|
|
||||||
|
|
||||||
$id_table_related=load_id_model_related($model[$key]->components[$new_field], $model);
|
|
||||||
|
|
||||||
$arr_sql_set_index[$key][$new_field]='ALTER TABLE `'.$key.'` ADD CONSTRAINT `'.$new_field.'_'.$key.'IDX` FOREIGN KEY ( `'.$new_field.'` ) REFERENCES `'.$table_related.'` (`'.$id_table_related.'`) ON DELETE RESTRICT ON UPDATE RESTRICT;';
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
else
|
|
||||||
|
|
||||||
{
|
|
||||||
|
|
||||||
/*if(isset($model[$key]->components[$new_field]->related_model) )
|
|
||||||
{*/
|
|
||||||
|
|
||||||
//Drop foreignkeyfield
|
|
||||||
|
|
||||||
//Bug, need fixed.
|
|
||||||
if($keys[$new_field]!='')
|
|
||||||
{
|
|
||||||
|
|
||||||
$query=MySQLClass::webtsys_query('ALTER TABLE `'.$key.'` DROP FOREIGN KEY '.$new_field.'_'.$key.'IDX');
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//}
|
|
||||||
|
|
||||||
$query=MySQLClass::webtsys_query('alter table `'.$key.'` drop `'.$new_field.'`');
|
|
||||||
|
|
||||||
echo "Deleting ".$new_field." from ".$key."...\n";
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
$arr_etable[$key]=0;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//Create Indexes...
|
|
||||||
|
|
||||||
foreach($arr_sql_index as $model_name => $arr_index)
|
|
||||||
{
|
|
||||||
foreach($arr_sql_index[$model_name] as $key_data => $sql_index)
|
|
||||||
{
|
|
||||||
|
|
||||||
echo "---Creating index for ".$key_data." on model ".$model_name."\n";
|
|
||||||
|
|
||||||
$query=MySQLClass::webtsys_query($sql_index);
|
|
||||||
|
|
||||||
if($arr_sql_set_index[$model_name][$key_data]!='')
|
|
||||||
{
|
|
||||||
$query=MySQLClass::webtsys_query($arr_sql_set_index[$model_name][$key_data]);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Create Uniques...
|
|
||||||
|
|
||||||
foreach($arr_sql_unique as $model_name => $arr_index)
|
|
||||||
{
|
|
||||||
foreach($arr_sql_unique[$model_name] as $key_data => $sql_index)
|
|
||||||
{
|
|
||||||
|
|
||||||
echo "---Creating unique for ".$key_data." on model ".$model_name."\n";
|
|
||||||
|
|
||||||
$query=MySQLClass::webtsys_query($sql_index);
|
|
||||||
|
|
||||||
if($arr_sql_set_unique[$model_name][$key_data]!='')
|
|
||||||
{
|
|
||||||
$query=MySQLClass::webtsys_query($arr_sql_set_unique[$model_name][$key_data]);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*foreach($arr_etable as $table => $value)
|
|
||||||
{
|
|
||||||
|
|
||||||
if($value==1)
|
|
||||||
{
|
|
||||||
|
|
||||||
$query=MySQLClass::webtsys_query('DROP TABLE `'.$table.'`');
|
|
||||||
|
|
||||||
echo 'Deleting table '.$table."\n";
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}*/
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function load_id_model_related($foreignkeyfield, $model)
|
|
||||||
{
|
|
||||||
|
|
||||||
//global $model;
|
|
||||||
|
|
||||||
$table_related=$foreignkeyfield->related_model->name;
|
|
||||||
|
|
||||||
$id_table_related='';
|
|
||||||
|
|
||||||
if(!isset($model[ $table_related ]->idmodel))
|
|
||||||
{
|
|
||||||
|
|
||||||
//$id_table_related='Id'.ucfirst(PhangoVar::$model[$key]->components[$new_field]->related_model);
|
|
||||||
//Need load the model
|
|
||||||
|
|
||||||
if(isset($foreignkeyfield->params_loading_mod['module']) && isset($foreignkeyfield->params_loading_mod['model']))
|
|
||||||
{
|
|
||||||
|
|
||||||
$model=load_model($foreignkeyfield->params_loading_mod);
|
|
||||||
|
|
||||||
//obtain id
|
|
||||||
|
|
||||||
$id_table_related=$model[ $foreignkeyfield->params_loading_mod['model'] ]->idmodel;
|
|
||||||
|
|
||||||
/*unset(PhangoVar::$model[ $foreignkeyfield->params_loading_mod['model'] ]);
|
|
||||||
|
|
||||||
unset($cache_model);*/
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
$id_table_related=$model[ $table_related ]->idmodel;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if($id_table_related=='')
|
|
||||||
{
|
|
||||||
|
|
||||||
//Set standard...
|
|
||||||
|
|
||||||
$id_table_related='Id'.ucfirst($table_related);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return $id_table_related;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
||||||
|
|
@ -18,5 +18,6 @@
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"PhangoApp\\PhaModels\\": "src"
|
"PhangoApp\\PhaModels\\": "src"
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
"bin": ["bin/padmin"]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,9 @@ function element_exists_method_class($class, $idrow, $field_search='')
|
||||||
|
|
||||||
settype($idrow, 'integer');
|
settype($idrow, 'integer');
|
||||||
|
|
||||||
$num_elements=$class->select_count('where '.$field_search.'=\''.$idrow.'\'', $class->idmodel);
|
$class->set_conditions('where '.$field_search.'=\''.$idrow.'\'');
|
||||||
|
|
||||||
|
$num_elements=$class->select_count($class->idmodel);
|
||||||
|
|
||||||
return $num_elements;
|
return $num_elements;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,12 +19,12 @@
|
||||||
* @param string $field The field where search.
|
* @param string $field The field where search.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function select_a_field_method_class($class, $where, $field)
|
function select_a_field_method_class($class, $field)
|
||||||
{
|
{
|
||||||
|
|
||||||
$arr_field=array();
|
$arr_field=array();
|
||||||
|
|
||||||
$query=$class->select($where, array($field), $raw_query=1);
|
$query=$class->select(array($field), $raw_query=1);
|
||||||
|
|
||||||
while(list($field_choose)=$class->fetch_row($query))
|
while(list($field_choose)=$class->fetch_row($query))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,11 @@ function select_a_row_method_class($class, $idrow, $arr_select=array(), $raw_que
|
||||||
|
|
||||||
settype($idrow, 'integer');
|
settype($idrow, 'integer');
|
||||||
|
|
||||||
$query=$class->select('where '.$class->name.'.`'.$class->idmodel.'`=\''.$idrow.'\'', $arr_select, $raw_query);
|
$class->set_conditions('where '.$class->name.'.`'.$class->idmodel.'`=\''.$idrow.'\'');
|
||||||
|
|
||||||
|
$class->set_limit('limit 1');
|
||||||
|
|
||||||
|
$query=$class->select($arr_select, $raw_query);
|
||||||
|
|
||||||
return $class->fetch_array($query, $assoc);
|
return $class->fetch_array($query, $assoc);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,12 +23,14 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
function select_a_row_where_method_class($class, $where, $arr_select=array(), $raw_query=0, $assoc=0)
|
function select_a_row_where_method_class($class, $arr_select=array(), $raw_query=0, $assoc=0)
|
||||||
{
|
{
|
||||||
|
|
||||||
settype($idrow, 'integer');
|
settype($idrow, 'integer');
|
||||||
|
|
||||||
$query=$class->select($where, $arr_select, $raw_query);
|
$query=$class->select($arr_select, $raw_query);
|
||||||
|
|
||||||
|
$class->set_limit('limit 1');
|
||||||
|
|
||||||
return $class->fetch_array($query, $assoc);
|
return $class->fetch_array($query, $assoc);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function select_to_array_method_class($class, $where="", $arr_select=array(), $raw_query=0, $index_id='')
|
function select_to_array_method_class($class, $arr_select=array(), $raw_query=0, $index_id='')
|
||||||
{
|
{
|
||||||
|
|
||||||
$arr_return=array();
|
$arr_return=array();
|
||||||
|
|
@ -43,7 +43,7 @@ function select_to_array_method_class($class, $where="", $arr_select=array(), $r
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$query=$class->select($where, $arr_select, $raw_query);
|
$query=$class->select($arr_select, $raw_query);
|
||||||
|
|
||||||
while($arr_row=$class->fetch_array($query))
|
while($arr_row=$class->fetch_array($query))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ class BooleanField extends PhangoField {
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->size=1;
|
$this->size=1;
|
||||||
$this->form='SelectForm';
|
$this->form='PhangoApp\PhaModels\Forms\SelectForm';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -50,7 +50,7 @@ class BooleanField extends PhangoField {
|
||||||
|
|
||||||
//Int for simple compatibility with sql dbs.
|
//Int for simple compatibility with sql dbs.
|
||||||
|
|
||||||
return 'INT('.$this->size.') NOT NULL';
|
return 'INT('.$this->size.') NOT NULL DEFAULT "0"';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -83,9 +83,9 @@ class BooleanField extends PhangoField {
|
||||||
function get_parameters_default()
|
function get_parameters_default()
|
||||||
{
|
{
|
||||||
|
|
||||||
$arr_values=array($this->default_value, I18n::lang('common', 'no', 'No'), 0, I18n::lang('common', 'yes', 'Yes'), 1);;
|
$this->form_loaded->arr_select=array(0 => I18n::lang('common', 'no', 'No'), 1 => I18n::lang('common', 'yes', 'Yes'));
|
||||||
|
|
||||||
|
|
||||||
return array($this->name_component, '', $arr_values);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ class CharField extends PhangoField {
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->size=$size;
|
$this->size=$size;
|
||||||
$this->form='TextForm';
|
$this->form='PhangoApp\PhaModels\Forms\BaseForm';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
namespace PhangoApp\PhaModels\CoreFields;
|
namespace PhangoApp\PhaModels\CoreFields;
|
||||||
use PhangoApp\PhaUtils\Utils;
|
use PhangoApp\PhaUtils\Utils;
|
||||||
use PhangoApp\PhaI18n\I18n;
|
use PhangoApp\PhaI18n\I18n;
|
||||||
|
use PhangoApp\PhaModels\Forms\SelectForm;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
@ -14,7 +15,6 @@ class ChoiceField extends PhangoField {
|
||||||
public $value=0;
|
public $value=0;
|
||||||
public $label="";
|
public $label="";
|
||||||
public $required=0;
|
public $required=0;
|
||||||
public $form="";
|
|
||||||
public $quot_open='\'';
|
public $quot_open='\'';
|
||||||
public $quot_close='\'';
|
public $quot_close='\'';
|
||||||
public $std_error='';
|
public $std_error='';
|
||||||
|
|
@ -22,18 +22,18 @@ class ChoiceField extends PhangoField {
|
||||||
public $arr_values=array();
|
public $arr_values=array();
|
||||||
public $arr_formatted=array();
|
public $arr_formatted=array();
|
||||||
public $default_value='';
|
public $default_value='';
|
||||||
|
public $form='PhangoApp\PhaModels\Forms\SelectForm';
|
||||||
|
|
||||||
|
|
||||||
function __construct($size=11, $type='integer', $arr_values=array(), $default_value='')
|
function __construct($size=11, $type='integer', $arr_values=array(), $default_value='')
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->size=$size;
|
$this->size=$size;
|
||||||
$this->form='SelectForm';
|
|
||||||
$this->type=$type;
|
$this->type=$type;
|
||||||
$this->arr_values=$arr_values;
|
$this->arr_values=$arr_values;
|
||||||
$this->default_value=$default_value;
|
$this->default_value=$default_value;
|
||||||
$this->arr_formatted['']='';
|
$this->arr_formatted['']=I18n::lang('common', 'none_selected', 'None selected');
|
||||||
|
|
||||||
|
|
||||||
foreach($arr_values as $value)
|
foreach($arr_values as $value)
|
||||||
{
|
{
|
||||||
|
|
@ -99,13 +99,13 @@ class ChoiceField extends PhangoField {
|
||||||
|
|
||||||
case 'integer':
|
case 'integer':
|
||||||
|
|
||||||
return 'INT('.$this->size.') NOT NULL';
|
return 'INT('.$this->size.') NOT NULL DEFAULT "0"';
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'string':
|
case 'string':
|
||||||
|
|
||||||
return 'VARCHAR('.$this->size.') NOT NULL';
|
return 'VARCHAR('.$this->size.') NOT NULL DEFAULT ""';
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -120,10 +120,12 @@ class ChoiceField extends PhangoField {
|
||||||
public function show_formatted($value)
|
public function show_formatted($value)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
$this->restart_formatted();
|
||||||
|
|
||||||
return $this->arr_formatted[$value];
|
return $this->arr_formatted[$value];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
function get_parameters_default()
|
function get_parameters_default()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
@ -145,13 +147,26 @@ class ChoiceField extends PhangoField {
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
$arr_values=array(0, 'Option 1', 0, 'Option 2', 1);
|
$arr_values=array(0 => 'Option 1', 1 => 'Option 2');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return array($this->name_component, '', $arr_values);
|
return array($this->name_component, '', $arr_values);
|
||||||
|
|
||||||
}
|
}*/
|
||||||
|
/*
|
||||||
|
public function create_form()
|
||||||
|
{
|
||||||
|
|
||||||
|
$form=new SelectForm($this->name_component, $this->value);
|
||||||
|
$form->default_value=$this->default_value;
|
||||||
|
$form->required=$this->required;
|
||||||
|
$form->label=$this->label;
|
||||||
|
$form->arr_select=$this->arr_formatted;
|
||||||
|
|
||||||
|
return $form;
|
||||||
|
|
||||||
|
}*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ class DateField extends PhangoField {
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->size=$size;
|
$this->size=$size;
|
||||||
$this->form='DateForm';
|
$this->form='PhangoApp\PhaModels\CoreForms\DateForm';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -106,7 +106,7 @@ class DateField extends PhangoField {
|
||||||
function get_type_sql()
|
function get_type_sql()
|
||||||
{
|
{
|
||||||
|
|
||||||
return 'INT('.$this->size.') NOT NULL';
|
return 'INT('.$this->size.') NOT NULL DEFAULT "0"';
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
85
src/CoreFields/DateTimeField.php
Normal file
85
src/CoreFields/DateTimeField.php
Normal file
|
|
@ -0,0 +1,85 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Antonio de la Rosa <webmaster@web-t-sys.com>
|
||||||
|
* @file
|
||||||
|
* @package ExtraFields
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhangoApp\PhaModels\CoreFields;
|
||||||
|
|
||||||
|
class DateTimeField extends DateField
|
||||||
|
{
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->form='DateTimeForm';
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function check($value)
|
||||||
|
{
|
||||||
|
|
||||||
|
$timestamp=parent::check($value);
|
||||||
|
|
||||||
|
return date('YmdHis', $timestamp);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function search_field($value)
|
||||||
|
{
|
||||||
|
|
||||||
|
$value_check=$this->check($value);
|
||||||
|
|
||||||
|
return substr($value_check, 0, 8);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show_formatted($value)
|
||||||
|
{
|
||||||
|
|
||||||
|
$timestamp=$this->obtain_timestamp_datefield($value);
|
||||||
|
|
||||||
|
return parent::show_formatted($timestamp);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_type_sql()
|
||||||
|
{
|
||||||
|
|
||||||
|
return 'VARCHAR(14) NOT NULL DEFAULT ""';
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static public function obtain_timestamp_datefield($value)
|
||||||
|
{
|
||||||
|
|
||||||
|
$year=substr($value, 0, 4);
|
||||||
|
$month=substr($value, 4, 2);
|
||||||
|
$day=substr($value, 6, 2);
|
||||||
|
$hour=substr($value, 8, 2);
|
||||||
|
$minute=substr($value, 10, 2);
|
||||||
|
$second=substr($value, 12, 2);
|
||||||
|
|
||||||
|
settype($year, 'integer');
|
||||||
|
settype($month, 'integer');
|
||||||
|
settype($day, 'integer');
|
||||||
|
settype($hour, 'integer');
|
||||||
|
settype($minute, 'integer');
|
||||||
|
settype($second, 'integer');
|
||||||
|
|
||||||
|
$timestamp=mktime($hour, $minute, $second, $month, $day, $year);
|
||||||
|
|
||||||
|
return $timestamp;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
@ -22,7 +22,7 @@ class DoubleField extends PhangoField {
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->size=$size;
|
$this->size=$size;
|
||||||
$this->form='TextForm';
|
$this->form='PhangoApp\PhaModels\Forms\BaseForm';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -38,7 +38,7 @@ class DoubleField extends PhangoField {
|
||||||
function get_type_sql()
|
function get_type_sql()
|
||||||
{
|
{
|
||||||
|
|
||||||
return 'DOUBLE NOT NULL';
|
return 'DOUBLE NOT NULL DEFAULT "0"';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ class EmailField extends PhangoField {
|
||||||
public $size=200;
|
public $size=200;
|
||||||
public $value="";
|
public $value="";
|
||||||
public $label="";
|
public $label="";
|
||||||
public $form="TextForm";
|
public $form='PhangoApp\PhaModels\Forms\BaseForm';
|
||||||
public $class="";
|
public $class="";
|
||||||
public $required=0;
|
public $required=0;
|
||||||
public $quot_open='\'';
|
public $quot_open='\'';
|
||||||
|
|
@ -50,7 +50,7 @@ class EmailField extends PhangoField {
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->std_error.='Email format error';
|
$this->std_error='Email format error';
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
|
|
||||||
|
|
@ -62,7 +62,7 @@ class EmailField extends PhangoField {
|
||||||
function get_type_sql()
|
function get_type_sql()
|
||||||
{
|
{
|
||||||
|
|
||||||
return 'VARCHAR('.$this->size.') NOT NULL';
|
return 'VARCHAR('.$this->size.') NOT NULL DEFAULT ""';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -77,6 +77,27 @@ class EmailField extends PhangoField {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* By default primaryfield use a hidden form
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function create_form()
|
||||||
|
{
|
||||||
|
|
||||||
|
/*$form=new PasswordForm($this->name_component, $this->value);
|
||||||
|
$form->default_value=$this->default_value;
|
||||||
|
$form->required=$this->required;
|
||||||
|
$form->label=$this->label;
|
||||||
|
$form->type='password';*/
|
||||||
|
|
||||||
|
$form=parent::create_form();
|
||||||
|
|
||||||
|
$form->field=new EmailField();
|
||||||
|
|
||||||
|
return $form;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ class FileField extends PhangoField {
|
||||||
public $value="";
|
public $value="";
|
||||||
public $label="";
|
public $label="";
|
||||||
public $required=0;
|
public $required=0;
|
||||||
public $form="FileForm";
|
public $form='PhangoApp\PhaModels\Forms\BaseForm';
|
||||||
public $name_file="";
|
public $name_file="";
|
||||||
public $path="";
|
public $path="";
|
||||||
public $url_path="";
|
public $url_path="";
|
||||||
|
|
@ -109,7 +109,7 @@ class FileField extends PhangoField {
|
||||||
function get_type_sql()
|
function get_type_sql()
|
||||||
{
|
{
|
||||||
|
|
||||||
return 'VARCHAR(255) NOT NULL';
|
return 'VARCHAR(255) NOT NULL DEFAULT ""';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,30 +18,27 @@ class ForeignKeyField extends IntegerField{
|
||||||
//field related in the model...
|
//field related in the model...
|
||||||
public $related_model='';
|
public $related_model='';
|
||||||
public $container_model='';
|
public $container_model='';
|
||||||
public $null_relation=1;
|
|
||||||
public $params_loading_mod=array();
|
public $params_loading_mod=array();
|
||||||
public $default_id=0;
|
public $default_id=0;
|
||||||
public $yes_zero=0;
|
public $yes_zero=0;
|
||||||
public $fields_related_model;
|
public $fields_related_model;
|
||||||
public $name_field_to_field;
|
public $name_field_to_field;
|
||||||
|
|
||||||
function __construct($related_model, $size=11, $null_relation=1, $default=0)
|
function __construct($related_model, $size=11, $default=0)
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->size=$size;
|
$this->size=$size;
|
||||||
$this->form='SelectForm';
|
$this->form='PhangoApp\PhaModels\Forms\SelectForm';
|
||||||
$this->related_model=&$related_model;
|
$this->related_model=&$related_model;
|
||||||
$this->container_model=$this->related_model->name;
|
$this->container_model=$this->related_model->name;
|
||||||
//Fields obtained from related_model if you make a query...
|
//Fields obtained from related_model if you make a query...
|
||||||
$this->fields_related_model=array();
|
$this->fields_related_model=array();
|
||||||
//Representative field for related model...
|
//Representative field for related model...
|
||||||
$this->name_field_to_field='';
|
$this->name_field_to_field='';
|
||||||
$this->null_relation=$null_relation;
|
|
||||||
$this->default_id=$default;
|
$this->default_id=$default;
|
||||||
|
$this->quot_open='';
|
||||||
//PhangoVar::$model[$related_model]->related_models_delete[]=array('model' => $this->name_model, 'related_field' => $this->name_component);
|
$this->quot_close='';
|
||||||
|
$this->protected=1;
|
||||||
//echo get_parent_class();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -57,8 +54,6 @@ class ForeignKeyField extends IntegerField{
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
//show_error('You need load model before set relantionship', $this->related_model.' model not exists. You need load model before set relantionship with ForeignKeyField with '.$this->name_model.' model', $output_external='');
|
|
||||||
|
|
||||||
throw new \Exception($this->related_model.' model not exists. You need load model before set relantionship with ForeignKeyField with '.$this->name_model.' model');
|
throw new \Exception($this->related_model.' model not exists. You need load model before set relantionship with ForeignKeyField with '.$this->name_model.' model');
|
||||||
|
|
||||||
die;
|
die;
|
||||||
|
|
@ -82,36 +77,22 @@ class ForeignKeyField extends IntegerField{
|
||||||
|
|
||||||
//Need checking if the value exists with a select_count
|
//Need checking if the value exists with a select_count
|
||||||
|
|
||||||
$num_rows=$this->related_model->select_count('where '.$this->related_model.'.'.$this->related_model->idmodel.'='.$value, $this->related_model->idmodel);
|
$this->related_model->set_conditions('where '.$this->related_model->name.'.'.$this->related_model->idmodel.'='.$value);
|
||||||
|
|
||||||
|
$num_rows=$this->related_model->select_count();
|
||||||
|
|
||||||
if($num_rows>0)
|
if($num_rows>0)
|
||||||
{
|
{
|
||||||
|
|
||||||
if($value==0 && $this->yes_zero==0)
|
|
||||||
{
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return $value;
|
return $value;
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
if($this->default_id<=0 && $this->yes_zero==0)
|
|
||||||
{
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
return $this->default_id;
|
return $this->default_id;
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -131,10 +112,7 @@ class ForeignKeyField extends IntegerField{
|
||||||
function get_type_sql()
|
function get_type_sql()
|
||||||
{
|
{
|
||||||
|
|
||||||
$arr_null[0]='NOT NULL';
|
return 'INT('.$this->size.') NOT NULL DEFAULT "0"';
|
||||||
$arr_null[1]='NULL';
|
|
||||||
|
|
||||||
return 'INT('.$this->size.') '.$arr_null[$this->null_relation];
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
144
src/CoreFields/I18nField.php
Normal file
144
src/CoreFields/I18nField.php
Normal file
|
|
@ -0,0 +1,144 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Antonio de la Rosa <webmaster@web-t-sys.com>
|
||||||
|
* @file i18n_fields.php
|
||||||
|
* @package ExtraFields\I18nFields
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhangoApp\PhaModels\CoreFields;
|
||||||
|
|
||||||
|
use PhangoApp\PhaI18n\I18n;
|
||||||
|
use PhangoApp\PhaModels\Forms\MultiLangForm;
|
||||||
|
use PhangoApp\PhaModels\CoreFields\SlugifyField;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Multilanguage fields.
|
||||||
|
*
|
||||||
|
* With this field you can create fields for i18n sites.
|
||||||
|
*/
|
||||||
|
|
||||||
|
class I18nField extends PhangoField {
|
||||||
|
|
||||||
|
public $value="";
|
||||||
|
public $label="";
|
||||||
|
public $required=0;
|
||||||
|
public $form="PhangoApp\PhaModels\Forms\MultiLangForm";
|
||||||
|
public $quot_open='\'';
|
||||||
|
public $quot_close='\'';
|
||||||
|
public $std_error='';
|
||||||
|
public $related_field='';
|
||||||
|
public $type_field='';
|
||||||
|
|
||||||
|
//This method is used for check all members from serialize
|
||||||
|
|
||||||
|
function __construct($type_field)
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->type_field=&$type_field;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function check($value)
|
||||||
|
{
|
||||||
|
|
||||||
|
settype($value, 'array');
|
||||||
|
|
||||||
|
foreach(I18n::$arr_i18n as $lang_item)
|
||||||
|
{
|
||||||
|
|
||||||
|
settype($value[$lang_item], 'string');
|
||||||
|
|
||||||
|
$value[$lang_item]=$this->type_field->check($value[$lang_item]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if($this->required==1 && $value[I18n::$language]=='')
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->std_error=I18n::lang('common', 'error_you_need_this_language_field', 'Error, you need this language field').' '.I18n::$language;
|
||||||
|
|
||||||
|
return '';
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$ser_value=addslashes(serialize($value));
|
||||||
|
|
||||||
|
return $ser_value;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function get_type_sql()
|
||||||
|
{
|
||||||
|
|
||||||
|
return 'TEXT NOT NULL DEFAULT ""';
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static function show_formatted($value)
|
||||||
|
{
|
||||||
|
|
||||||
|
$arr_lang=@unserialize($value);
|
||||||
|
|
||||||
|
settype($arr_lang, 'array');
|
||||||
|
|
||||||
|
settype($arr_lang[I18n::$language], 'string');
|
||||||
|
|
||||||
|
settype($arr_lang[I18n::$language], 'string');
|
||||||
|
|
||||||
|
if($arr_lang[I18n::$language]=='' && $arr_lang[I18n::$language]=='')
|
||||||
|
{
|
||||||
|
|
||||||
|
//Need view var with text...
|
||||||
|
|
||||||
|
//$arr_lang_first=array_unique($arr_lang);
|
||||||
|
foreach($arr_lang as $key_lang => $val_lang)
|
||||||
|
{
|
||||||
|
|
||||||
|
if($val_lang!='')
|
||||||
|
{
|
||||||
|
|
||||||
|
return $val_lang;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else if($arr_lang[I18n::$language]=='')
|
||||||
|
{
|
||||||
|
|
||||||
|
return $arr_lang[I18n::$language];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return $arr_lang[I18n::$language];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function add_slugify_i18n_post($field, $post)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
foreach(PhangoVar::$arr_i18n as $lang_field)
|
||||||
|
{
|
||||||
|
|
||||||
|
$post[$field.'_'.$lang_field]=SlugifyField::check($post[$field][$lang_field]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return $post;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
@ -15,7 +15,7 @@ class ImageField extends PhangoField {
|
||||||
public $value="";
|
public $value="";
|
||||||
public $label="";
|
public $label="";
|
||||||
public $required=0;
|
public $required=0;
|
||||||
public $form="ImageForm";
|
public $form='PhangoApp\PhaModels\Forms\BaseForm';
|
||||||
public $name_file="";
|
public $name_file="";
|
||||||
public $path="";
|
public $path="";
|
||||||
public $url_path="";
|
public $url_path="";
|
||||||
|
|
@ -31,6 +31,7 @@ class ImageField extends PhangoField {
|
||||||
public $img_minimal_height=array();
|
public $img_minimal_height=array();
|
||||||
public $func_token='Utils::get_token';
|
public $func_token='Utils::get_token';
|
||||||
public $move_file_func='move_uploaded_file';
|
public $move_file_func='move_uploaded_file';
|
||||||
|
public $size=255;
|
||||||
|
|
||||||
function __construct($name_file, $path, $url_path, $type, $thumb=0, $img_width=array('mini' => 150), $quality_jpeg=85)
|
function __construct($name_file, $path, $url_path, $type, $thumb=0, $img_width=array('mini' => 150), $quality_jpeg=85)
|
||||||
{
|
{
|
||||||
|
|
@ -371,7 +372,7 @@ class ImageField extends PhangoField {
|
||||||
function get_type_sql()
|
function get_type_sql()
|
||||||
{
|
{
|
||||||
|
|
||||||
return 'VARCHAR(255) NOT NULL';
|
return 'VARCHAR('.$this->size.') NOT NULL DEFAULT ""';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ class IntegerField extends PhangoField {
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->size=$size;
|
$this->size=$size;
|
||||||
$this->form='TextForm';
|
$this->form='PhangoApp\PhaModels\Forms\BaseForm';
|
||||||
$this->only_positive=$only_positive;
|
$this->only_positive=$only_positive;
|
||||||
$this->min_num=$min_num;
|
$this->min_num=$min_num;
|
||||||
$this->max_num=$max_num;
|
$this->max_num=$max_num;
|
||||||
|
|
@ -64,7 +64,7 @@ class IntegerField extends PhangoField {
|
||||||
function get_type_sql()
|
function get_type_sql()
|
||||||
{
|
{
|
||||||
|
|
||||||
return 'INT('.$this->size.') NOT NULL';
|
return 'INT('.$this->size.') NOT NULL DEFAULT "0"';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ class KeyField extends PhangoField {
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->size=$size;
|
$this->size=$size;
|
||||||
$this->form='TextForm';
|
$this->form='PhangoApp\PhaModels\Forms\BaseForm';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -43,7 +43,7 @@ class KeyField extends PhangoField {
|
||||||
function get_type_sql()
|
function get_type_sql()
|
||||||
{
|
{
|
||||||
|
|
||||||
return 'INT('.$this->size.') NOT NULL';
|
return 'INT('.$this->size.') NOT NULL DEFAULT "0"';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
26
src/CoreFields/MoneyField.php
Normal file
26
src/CoreFields/MoneyField.php
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PhangoApp\PhaModels\CoreFields;
|
||||||
|
|
||||||
|
class MoneyField extends DoubleField{
|
||||||
|
|
||||||
|
|
||||||
|
function show_formatted($value)
|
||||||
|
{
|
||||||
|
|
||||||
|
return $this->currency_format($value);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static function currency_format($value, $symbol_currency='€')
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
return number_format($value, 2).' '.$symbol_currency;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
51
src/CoreFields/NormalizeField.php
Normal file
51
src/CoreFields/NormalizeField.php
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Antonio de la Rosa <webmaster@web-t-sys.com>
|
||||||
|
* @file
|
||||||
|
* @package ExtraFields
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhangoApp\PhaModels\CoreFields;
|
||||||
|
|
||||||
|
class NormalizeField extends TextField {
|
||||||
|
|
||||||
|
|
||||||
|
public $form='HiddenForm';
|
||||||
|
|
||||||
|
public function check($value)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
return $this->check_text($value);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function search_field($value)
|
||||||
|
{
|
||||||
|
|
||||||
|
return $this->check_text($value);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static public function check_text($value, $separator='-')
|
||||||
|
{
|
||||||
|
|
||||||
|
$str_normalize=slugify(strip_tags($value));
|
||||||
|
|
||||||
|
$arr_normalize=explode($separator, $str_normalize);
|
||||||
|
|
||||||
|
sort($arr_normalize);
|
||||||
|
|
||||||
|
$value=implode('%', $arr_normalize);
|
||||||
|
|
||||||
|
return $value;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
@ -17,7 +17,7 @@ class ParentField extends IntegerField{
|
||||||
|
|
||||||
$this->parent_model=&$parent_model;
|
$this->parent_model=&$parent_model;
|
||||||
$this->size=$size;
|
$this->size=$size;
|
||||||
$this->form='SelectForm';
|
$this->form='PhangoApp\PhaModels\Forms\BaseForm';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,16 +9,18 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace PhangoApp\PhaModels\CoreFields;
|
namespace PhangoApp\PhaModels\CoreFields;
|
||||||
|
use PhangoApp\PhaModels\Forms\PasswordForm;
|
||||||
use PhangoApp\PhaUtils\Utils;
|
use PhangoApp\PhaUtils\Utils;
|
||||||
|
use PhangoApp\PhaI18n\I18n;
|
||||||
|
|
||||||
class PasswordField extends CharField {
|
class PasswordField extends CharField {
|
||||||
|
|
||||||
|
|
||||||
function __construct($size=255)
|
function __construct($size=255)
|
||||||
{
|
{
|
||||||
|
$this->min_length=5;
|
||||||
$this->size=$size;
|
$this->size=$size;
|
||||||
$this->form='PasswordForm';
|
$this->form='PhangoApp\PhaModels\Forms\PasswordForm';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -34,9 +36,22 @@ class PasswordField extends CharField {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
$token_pass=Utils::generate_random_password();
|
$token_pass=Utils::generate_random_password();
|
||||||
|
|
||||||
$hash_password=$token_pass.'_'.sha1($token_pass.'_'.$value);
|
$hash_password=$token_pass.'_'.sha1($token_pass.'_'.$value);
|
||||||
|
*/
|
||||||
|
|
||||||
|
if(strlen($value)<$this->min_length)
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->std_error=I18n::lang('common', 'password_min_length', 'Minimal password length:').' '.$this->min_length;
|
||||||
|
|
||||||
|
return '';
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$hash_password=password_hash($value, PASSWORD_DEFAULT);
|
||||||
|
|
||||||
return $hash_password;
|
return $hash_password;
|
||||||
|
|
||||||
|
|
@ -49,8 +64,8 @@ class PasswordField extends CharField {
|
||||||
|
|
||||||
//If pass have _ check if work fine...
|
//If pass have _ check if work fine...
|
||||||
|
|
||||||
$token_pass=preg_replace('/(.*)[_].*/', '$1', $hash_password_check);
|
//$token_pass=preg_replace('/(.*)[_].*/', '$1', $hash_password_check);
|
||||||
|
/*
|
||||||
$hash_password=$token_pass.'_'.sha1($token_pass.'_'.$value);
|
$hash_password=$token_pass.'_'.sha1($token_pass.'_'.$value);
|
||||||
|
|
||||||
if($hash_password==$hash_password_check)
|
if($hash_password==$hash_password_check)
|
||||||
|
|
@ -58,12 +73,37 @@ class PasswordField extends CharField {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
}*/
|
||||||
|
|
||||||
|
if(password_verify($value, $hash_password_check))
|
||||||
|
{
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* By default primaryfield use a hidden form
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function create_form()
|
||||||
|
{
|
||||||
|
|
||||||
|
$form=new PasswordForm($this->name_component, $this->value);
|
||||||
|
$form->default_value=$this->default_value;
|
||||||
|
$form->required=$this->required;
|
||||||
|
$form->label=$this->label;
|
||||||
|
$form->type='password';
|
||||||
|
|
||||||
|
return $form;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
33
src/CoreFields/PercentField.php
Normal file
33
src/CoreFields/PercentField.php
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PhangoApp\PhaModels\CoreFields;
|
||||||
|
|
||||||
|
class PercentField extends IntegerField{
|
||||||
|
|
||||||
|
|
||||||
|
function check($value)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
settype($value, "integer");
|
||||||
|
|
||||||
|
//Reload related model if not exists, if exists, only check cache models...
|
||||||
|
|
||||||
|
if($value>100 || $value<0)
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->std_error=i18n_lang('common', 'the_value_can_not_be_greater_than_100', 'The value cannot be greater than 100');
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return $value;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
@ -14,6 +14,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace PhangoApp\PhaModels\CoreFields;
|
namespace PhangoApp\PhaModels\CoreFields;
|
||||||
|
use PhangoApp\PhaModels\Forms\BaseForm;
|
||||||
use PhangoApp\PhaUtils\Utils;
|
use PhangoApp\PhaUtils\Utils;
|
||||||
|
|
||||||
class PhangoField {
|
class PhangoField {
|
||||||
|
|
@ -87,7 +88,13 @@ class PhangoField {
|
||||||
* Form define the function for use in forms...
|
* Form define the function for use in forms...
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public $form="";
|
public $form='PhangoApp\PhaModels\Forms\BaseForm';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Variable where save a copy of form created from this Field
|
||||||
|
*/
|
||||||
|
|
||||||
|
public $form_loaded;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Array for create initial parameters for form..
|
* Array for create initial parameters for form..
|
||||||
|
|
@ -95,6 +102,25 @@ class PhangoField {
|
||||||
|
|
||||||
public $parameters=array();
|
public $parameters=array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A method used for set if this field can be update or insert by everyone.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public $protected=false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A property that set the default value
|
||||||
|
*/
|
||||||
|
|
||||||
|
public $default_value='';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A property for know if updated or insert this field
|
||||||
|
*/
|
||||||
|
|
||||||
|
public $update=0;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method used for internal tasks related with searchs. You can overwrite this method in your PhangoField object if you need translate the value that the user want search to a real value into the database.
|
* Method used for internal tasks related with searchs. You can overwrite this method in your PhangoField object if you need translate the value that the user want search to a real value into the database.
|
||||||
*/
|
*/
|
||||||
|
|
@ -126,7 +152,7 @@ class PhangoField {
|
||||||
public function get_type_sql()
|
public function get_type_sql()
|
||||||
{
|
{
|
||||||
|
|
||||||
return 'VARCHAR('.$this->size.') NOT NULL';
|
return 'VARCHAR('.$this->size.') NOT NULL DEFAULT "0"';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -137,7 +163,7 @@ class PhangoField {
|
||||||
public function get_parameters_default()
|
public function get_parameters_default()
|
||||||
{
|
{
|
||||||
|
|
||||||
return array($this->name_component, '', '');
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -152,6 +178,22 @@ class PhangoField {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method for create a form, you only need subclass the field if you want another form different to default
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
public function create_form()
|
||||||
|
{
|
||||||
|
|
||||||
|
$form=new BaseForm($this->name_component, $this->value);
|
||||||
|
$form->default_value=$this->default_value;
|
||||||
|
$form->required=$this->required;
|
||||||
|
$form->label=$this->label;
|
||||||
|
|
||||||
|
return $form;
|
||||||
|
|
||||||
|
}*/
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
34
src/CoreFields/PhoneField.php
Normal file
34
src/CoreFields/PhoneField.php
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Antonio de la Rosa <webmaster@web-t-sys.com>
|
||||||
|
* @file
|
||||||
|
* @package ExtraFields
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhangoApp\PhaModels\CoreFields;
|
||||||
|
|
||||||
|
class PhoneField extends CharField{
|
||||||
|
|
||||||
|
|
||||||
|
public function check($value)
|
||||||
|
{
|
||||||
|
|
||||||
|
if(!preg_match('/^[0-9]+$/', $value))
|
||||||
|
{
|
||||||
|
|
||||||
|
return '';
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return $value;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace PhangoApp\PhaModels\CoreFields;
|
namespace PhangoApp\PhaModels\CoreFields;
|
||||||
use PhangoApp\PhaUtils\Utils;
|
use PhangoApp\PhaUtils\Utils;
|
||||||
|
use PhangoApp\PhaModels\Forms\HiddenForm;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PrimaryField is used for primary keys for models
|
* PrimaryField is used for primary keys for models
|
||||||
|
|
@ -21,7 +22,7 @@ class PrimaryField extends PhangoField {
|
||||||
* Initial label for the field. The label is used for create forms from a PhangoField.
|
* Initial label for the field. The label is used for create forms from a PhangoField.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public $label="";
|
public $label="#ID";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Boolean value that is used for check if the field is required for fill a row in the db model.
|
* Boolean value that is used for check if the field is required for fill a row in the db model.
|
||||||
|
|
@ -33,7 +34,13 @@ class PrimaryField extends PhangoField {
|
||||||
* By default, the form used for this field is HiddenForm.
|
* By default, the form used for this field is HiddenForm.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public $form="HiddenForm";
|
public $form='PhangoApp\PhaModels\Forms\HiddenForm';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* By default this field is protected.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public $protected=true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check function that convert the value on a PrimaryField value.
|
* Check function that convert the value on a PrimaryField value.
|
||||||
|
|
@ -72,6 +79,23 @@ class PrimaryField extends PhangoField {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* By default primaryfield use a hidden form
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
public function create_form()
|
||||||
|
{
|
||||||
|
|
||||||
|
$form=new BaseForm($this->name_component, $this->value);
|
||||||
|
$form->default_value=$this->default_value;
|
||||||
|
$form->required=$this->required;
|
||||||
|
$form->label=$this->label;
|
||||||
|
$form->type='hidden';
|
||||||
|
|
||||||
|
return $form;
|
||||||
|
|
||||||
|
}*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
@ -12,7 +12,7 @@ class SerializeField extends PhangoField {
|
||||||
public $value="";
|
public $value="";
|
||||||
public $label="";
|
public $label="";
|
||||||
public $required=0;
|
public $required=0;
|
||||||
public $form="TextForm";
|
public $form='PhangoApp\PhaModels\Forms\BaseForm';
|
||||||
public $quot_open='\'';
|
public $quot_open='\'';
|
||||||
public $quot_close='\'';
|
public $quot_close='\'';
|
||||||
public $std_error='';
|
public $std_error='';
|
||||||
|
|
@ -78,7 +78,7 @@ class SerializeField extends PhangoField {
|
||||||
function get_type_sql()
|
function get_type_sql()
|
||||||
{
|
{
|
||||||
|
|
||||||
return 'TEXT NOT NULL';
|
return 'TEXT NOT NULL DEFAULT ""';
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
49
src/CoreFields/SlugifyField.php
Normal file
49
src/CoreFields/SlugifyField.php
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PhangoApp\PhaModels\CoreFields;
|
||||||
|
|
||||||
|
/** This class can be used for create orders or searchs in mysql if you need other thing distinct to default search of default order (default order don't work fine with serializefields how i18nfield). The programmer have the responsability of update this fields via update or insert method.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
class SlugifyField extends PhangoField {
|
||||||
|
|
||||||
|
|
||||||
|
public $value="";
|
||||||
|
public $label="";
|
||||||
|
public $required=0;
|
||||||
|
public $form="TextForm";
|
||||||
|
public $quot_open='\'';
|
||||||
|
public $quot_close='\'';
|
||||||
|
public $std_error='';
|
||||||
|
public $type='TEXT';
|
||||||
|
|
||||||
|
static function check($value)
|
||||||
|
{
|
||||||
|
|
||||||
|
return slugify($value);
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_type_sql()
|
||||||
|
{
|
||||||
|
|
||||||
|
return $this->type.' NOT NULL DEFAULT ""';
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static function add_slugify_i18n_fields($model_name, $field)
|
||||||
|
{
|
||||||
|
|
||||||
|
foreach(PhangoVar::$arr_i18n as $lang_field)
|
||||||
|
{
|
||||||
|
|
||||||
|
PhangoVar::$model[$model_name]->components[$field.'_'.$lang_field]=new SlugifyField();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
@ -22,7 +22,7 @@ class TextField extends PhangoField {
|
||||||
function __construct($multilang=0)
|
function __construct($multilang=0)
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->form='TextAreaForm';
|
$this->form='PhangoApp\PhaModels\Forms\BaseForm';
|
||||||
$this->multilang=$multilang;
|
$this->multilang=$multilang;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -41,7 +41,7 @@ class TextField extends PhangoField {
|
||||||
function get_type_sql()
|
function get_type_sql()
|
||||||
{
|
{
|
||||||
|
|
||||||
return 'TEXT NOT NULL';
|
return 'TEXT NOT NULL DEFAULT ""';
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,8 @@ class TextHTMLField extends PhangoField {
|
||||||
function __construct($multilang=0)
|
function __construct($multilang=0)
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->form='TextAreaForm';
|
$this->form='PhangoApp\PhaModels\Forms\BaseForm';
|
||||||
$this->multilang=$multilang;
|
|
||||||
$this->set_safe_html_tags();
|
$this->set_safe_html_tags();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -85,7 +85,7 @@ class TextHTMLField extends PhangoField {
|
||||||
function get_type_sql()
|
function get_type_sql()
|
||||||
{
|
{
|
||||||
|
|
||||||
return 'TEXT NOT NULL';
|
return 'TEXT NOT NULL DEFAULT ""';
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
502
src/CoreForms.php
Normal file
502
src/CoreForms.php
Normal file
|
|
@ -0,0 +1,502 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Base file include where basic static public function and methods for create MVC applications
|
||||||
|
*
|
||||||
|
* This file contains principal static public s and methods for create models, text formatting, forms creation, definition of basic variables, basic ORM that use on 90% of db searchs, etc...
|
||||||
|
*
|
||||||
|
* Functions used for generate forms from models
|
||||||
|
* This static public s are called via $model->form
|
||||||
|
*
|
||||||
|
* @author Antonio de la Rosa <webmaster@web-t-sys.com>
|
||||||
|
* @file
|
||||||
|
* @package CoreForms
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhangoApp\PhaModels;
|
||||||
|
|
||||||
|
use PhangoApp\PhaUtils\Utils;
|
||||||
|
|
||||||
|
class CoreForms {
|
||||||
|
|
||||||
|
/* Function form used for text fields on a form. Show a text html input.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param string $name Name of this text field for use in forms
|
||||||
|
* @param string $class Css class used in the text field
|
||||||
|
* @param string $value Initial value for the form
|
||||||
|
*/
|
||||||
|
|
||||||
|
static public function TextForm($name="", $class='', $value='')
|
||||||
|
{
|
||||||
|
|
||||||
|
return '<input type="text" name="'.$name.'" id="'.$name.'_field_form" class="'.$class.'" value="'.$value.'" />';
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Prepare a value for input text
|
||||||
|
|
||||||
|
static public function TextFormSet($post, $value)
|
||||||
|
{
|
||||||
|
|
||||||
|
$value = Utils::replace_quote_text( $value );
|
||||||
|
return $value;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Create a input password
|
||||||
|
|
||||||
|
static public function PasswordForm($name="", $class='', $value='')
|
||||||
|
{
|
||||||
|
|
||||||
|
$value = Utils::replace_quote_text( $value );
|
||||||
|
|
||||||
|
return '<input type="password" name="'.$name.'" class="'.$class.'" id="'.$name.'_field_form" value="'.$value.'" />';
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Prepare a value for input password
|
||||||
|
|
||||||
|
static public function PasswordFormSet($post, $value)
|
||||||
|
{
|
||||||
|
|
||||||
|
$value = ''; //Utils::replace_quote_text( $value );
|
||||||
|
|
||||||
|
return $value;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Create a input file
|
||||||
|
|
||||||
|
static public function FileForm($name="", $class='', $value='', $delete_inline=0, $path_file='')
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$file_url=$path_file.'/'.$value;
|
||||||
|
|
||||||
|
$file_exist='';
|
||||||
|
|
||||||
|
if($value!='')
|
||||||
|
{
|
||||||
|
|
||||||
|
$file_exist='<a href="'.$file_url.'">'.basename($value).'</a> ';
|
||||||
|
|
||||||
|
if($delete_inline==1)
|
||||||
|
{
|
||||||
|
|
||||||
|
$file_exist.=I18n::lang('common', 'delete_file', 'Delete file').' <input type="checkbox" name="delete_'.$name.'" class="'.$class.'" value="1" />';
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return '<input type="hidden" name="'.$name.'" value="'.$value.'"/><input type="file" name="'.$name.'" class="'.$class.'" value="" /> '.$file_exist;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Prepare a value for input password
|
||||||
|
|
||||||
|
static public function FileFormSet($post, $value)
|
||||||
|
{
|
||||||
|
|
||||||
|
$value = Utils::replace_quote_text( $value );
|
||||||
|
|
||||||
|
return $value;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Create a special form for a image
|
||||||
|
|
||||||
|
static public function ImageForm($name="", $class='', $value='', $delete_inline=0, $path_image='')
|
||||||
|
{
|
||||||
|
|
||||||
|
$image_url=$path_image.'/'.$value;
|
||||||
|
|
||||||
|
$image_exist='';
|
||||||
|
|
||||||
|
if($value!='')
|
||||||
|
{
|
||||||
|
|
||||||
|
$image_exist='<a href="'.$image_url.'">'.basename($value).'</a> ';
|
||||||
|
|
||||||
|
if($delete_inline==1)
|
||||||
|
{
|
||||||
|
|
||||||
|
$image_exist.=I18n::lang('common', 'delete_image', 'Delete image').' <input type="checkbox" name="delete_'.$name.'" class="'.$class.'" value="1" />';
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return '<input type="hidden" name="'.$name.'" value="'.$value.'"/><input type="file" name="'.$name.'" class="'.$class.'" value="" /> '.$image_exist;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Prepare a value for input password
|
||||||
|
|
||||||
|
static public function ImageFormSet($post, $value)
|
||||||
|
{
|
||||||
|
|
||||||
|
$value = Utils::replace_quote_text( $value );
|
||||||
|
|
||||||
|
return $value;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Create a textarea
|
||||||
|
|
||||||
|
static public function TextAreaForm($name="", $class='', $value='')
|
||||||
|
{
|
||||||
|
|
||||||
|
return '<textarea name="'.$name.'" class="'.$class.'" id="'.$name.'_field_form">'.$value.'</textarea>';
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Prepare the value for the textarea
|
||||||
|
|
||||||
|
static public function TextAreaFormSet($post, $value)
|
||||||
|
{
|
||||||
|
|
||||||
|
$value = Utils::replace_quote_text( $value );
|
||||||
|
|
||||||
|
return $value;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Create a input hidden
|
||||||
|
|
||||||
|
static public function HiddenForm($name="", $class='', $value='')
|
||||||
|
{
|
||||||
|
|
||||||
|
return '<input type="hidden" name="'.$name.'" value="'.$value.'" id="'.$name.'_field_form"/>';
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Prepare the value for a input hidden
|
||||||
|
|
||||||
|
static public function HiddenFormSet($post, $value)
|
||||||
|
{
|
||||||
|
|
||||||
|
$value = Utils::replace_quote_text( $value );
|
||||||
|
|
||||||
|
return $value;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Create a input checkbox
|
||||||
|
|
||||||
|
static public function CheckBoxForm($name="", $class='', $value='')
|
||||||
|
{
|
||||||
|
|
||||||
|
$arr_checked[$value]='';
|
||||||
|
|
||||||
|
$arr_checked[0]='';
|
||||||
|
$arr_checked[1]='checked';
|
||||||
|
|
||||||
|
return '<input type="checkbox" name="'.$name.'" value="1" id="'.$name.'_field_form" class="'.$class.'" '.$arr_checked[$value].'/>';
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Prepare the value for the checkbox
|
||||||
|
|
||||||
|
static public function CheckBoxFormSet($post, $value)
|
||||||
|
{
|
||||||
|
|
||||||
|
settype($value, 'integer');
|
||||||
|
|
||||||
|
return $value;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Create a select
|
||||||
|
|
||||||
|
static public function SelectForm($name="", $class='', $value='', $more_options='')
|
||||||
|
{
|
||||||
|
|
||||||
|
$select='<select name="'.$name.'" id="'.$name.'_field_form" class="'.$class.'" '.$more_options.'>'."\n";
|
||||||
|
|
||||||
|
list($key, $default)= each($value);
|
||||||
|
|
||||||
|
$arr_selected=array();
|
||||||
|
|
||||||
|
$arr_selected[$default]="selected=\"selected\"";
|
||||||
|
|
||||||
|
//Check if array is safe.
|
||||||
|
|
||||||
|
$z=count($value);
|
||||||
|
|
||||||
|
for($x=1;$x<$z;$x+=2)
|
||||||
|
{
|
||||||
|
|
||||||
|
$val=$value[$x+1];
|
||||||
|
|
||||||
|
settype($val, "string");
|
||||||
|
settype($arr_selected[$val], "string");
|
||||||
|
|
||||||
|
if($val=='optgroup')
|
||||||
|
{
|
||||||
|
$select.='<optgroup label="'.$value[$x].'">';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if($val=="end_optgroup")
|
||||||
|
{
|
||||||
|
|
||||||
|
$select.='</optgroup>';
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
$select.= '<option value="'.$val.'" '.$arr_selected[$val].'>'.$value[$x].'</option>'."\n";
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$select.='</select>'."\n";
|
||||||
|
|
||||||
|
return $select;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Prepare the value for the select
|
||||||
|
|
||||||
|
static public function SelectFormSet($post, $value)
|
||||||
|
{
|
||||||
|
|
||||||
|
$value = preg_replace('/<(.*?)\/(.*?)option(.*?)>/', '', $value);
|
||||||
|
|
||||||
|
$post[0]=$value;
|
||||||
|
|
||||||
|
return $post;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Crate a multiple select
|
||||||
|
|
||||||
|
static public function SelectManyForm($name="", $class='', $value='', $more_options='' )
|
||||||
|
{
|
||||||
|
|
||||||
|
$select='<select name="'.$name.'[]" id="'.$name.'_field_form" class="'.$class.'" '.$more_options.' multiple>'."\n";
|
||||||
|
|
||||||
|
list($key, $arr_values)= each($value);
|
||||||
|
|
||||||
|
$arr_selected=array();
|
||||||
|
|
||||||
|
foreach($arr_values as $default)
|
||||||
|
{
|
||||||
|
|
||||||
|
$arr_selected[$default]="selected";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Check if array is safe.
|
||||||
|
|
||||||
|
$z=count($value);
|
||||||
|
|
||||||
|
for($x=1;$x<$z;$x+=2)
|
||||||
|
{
|
||||||
|
|
||||||
|
$val=$value[$x+1];
|
||||||
|
|
||||||
|
settype($val, "string");
|
||||||
|
settype($arr_selected[$val], "string");
|
||||||
|
|
||||||
|
if($val=='optgroup')
|
||||||
|
{
|
||||||
|
$select.='<optgroup label="'.$value[$x].'">';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if($val=="end_optgroup")
|
||||||
|
{
|
||||||
|
|
||||||
|
$select.='</optgroup>';
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
$select.= '<option value="'.$val.'" '.$arr_selected[$val].'>'.$value[$x].'</option>'."\n";
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$select.='</select>'."\n";
|
||||||
|
|
||||||
|
return $select;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Prepare the value for the multiple select
|
||||||
|
|
||||||
|
static public function SelectManyFormSet($post, $value)
|
||||||
|
{
|
||||||
|
|
||||||
|
if(gettype($value)!='array')
|
||||||
|
{
|
||||||
|
|
||||||
|
$arr_value=unserialize($value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
$arr_value=$value;
|
||||||
|
|
||||||
|
}
|
||||||
|
//$value = preg_replace('/<(.*?)\/(.*?)option(.*?)>/', '', $value);
|
||||||
|
|
||||||
|
$post[0]=$arr_value;
|
||||||
|
|
||||||
|
return $post;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//A special form for dates in format day/month/year
|
||||||
|
|
||||||
|
static public function DateForm($field, $class='', $value='', $set_time=1, $see_title=1)
|
||||||
|
{
|
||||||
|
|
||||||
|
if($value==0)
|
||||||
|
{
|
||||||
|
|
||||||
|
$day='';
|
||||||
|
$month='';
|
||||||
|
$year='';
|
||||||
|
$hour='';
|
||||||
|
$minute='';
|
||||||
|
$second='';
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
//$value+=$user_data['format_time'];
|
||||||
|
|
||||||
|
$day=date('j', $value);
|
||||||
|
$month=date('n', $value);
|
||||||
|
$year=date('Y', $value);
|
||||||
|
$hour=date('G', $value);
|
||||||
|
$minute=date('i', $value);
|
||||||
|
$second=date('s', $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
$date='<span id="'.$field.'_field_form" class="'.$class.'">';
|
||||||
|
|
||||||
|
if($set_time<=1)
|
||||||
|
{
|
||||||
|
|
||||||
|
$date.='<input type="text" name="'.$field.'[]" value="'.$day.'" size="2" maxlength="2"/>'."\n";
|
||||||
|
$date.='<input type="text" name="'.$field.'[]" value="'.$month.'" size="2" maxlength="2"/>'."\n";
|
||||||
|
$date.='<input type="text" name="'.$field.'[]" value="'.$year.'" size="4" maxlength="4"/>'."\n ";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if($set_time>0)
|
||||||
|
{
|
||||||
|
|
||||||
|
$hour_txt=I18n::lang('common', 'hour', 'Hour');
|
||||||
|
$minute_txt=I18n::lang('common', 'minute', 'Minute');
|
||||||
|
$second_txt=I18n::lang('common', 'second', 'Second');
|
||||||
|
|
||||||
|
if($see_title==0)
|
||||||
|
{
|
||||||
|
|
||||||
|
$hour_txt='';
|
||||||
|
$minute_txt='';
|
||||||
|
$second_txt='';
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$date.=$hour_txt.' <input type="text" name="'.$field.'[]" value="'.$hour.'" size="2" maxlength="2" />'."\n";
|
||||||
|
$date.=$minute_txt.' <input type="text" name="'.$field.'[]" value="'.$minute.'" size="2" maxlength="2" />'."\n";
|
||||||
|
$date.=$second_txt.' <input type="text" name="'.$field.'[]" value="'.$second.'" size="2" maxlength="2" />'."\n";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
echo '</span>';
|
||||||
|
|
||||||
|
return $date;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Prepare value form dateform
|
||||||
|
|
||||||
|
static public function DateFormSet($post, $value)
|
||||||
|
{
|
||||||
|
|
||||||
|
if(gettype($value)=='array')
|
||||||
|
{
|
||||||
|
foreach($value as $key => $val)
|
||||||
|
{
|
||||||
|
|
||||||
|
settype($value[$key], 'integer');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
settype($value[3], 'integer');
|
||||||
|
settype($value[4], 'integer');
|
||||||
|
settype($value[5], 'integer');
|
||||||
|
|
||||||
|
$final_value=mktime ($value[3], $value[4], $value[5], $value[1], $value[0], $value[2] );
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
settype($value, 'integer');
|
||||||
|
|
||||||
|
$final_value=$value;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return $final_value;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static public function RadioIntForm($name="", $class='', $value=array(), $more_options='')
|
||||||
|
{
|
||||||
|
$select='';
|
||||||
|
|
||||||
|
list($key, $default)= each($value);
|
||||||
|
|
||||||
|
$arr_selected=array();
|
||||||
|
|
||||||
|
$arr_selected[$default]="checked";
|
||||||
|
|
||||||
|
//Check if array is safe.
|
||||||
|
|
||||||
|
$z=count($value);
|
||||||
|
|
||||||
|
for($x=1;$x<$z;$x+=2)
|
||||||
|
{
|
||||||
|
|
||||||
|
$val=$value[$x+1];
|
||||||
|
|
||||||
|
settype($arr_selected[$val], "string");
|
||||||
|
|
||||||
|
$select.= $value[$x].' <input type="radio" name="'.$name.'" value="'.$val.'" '.$arr_selected[$val].' />'."\n";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return $select;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Prepare the value for the select
|
||||||
|
|
||||||
|
static public function RadioIntFormSet($post, $value)
|
||||||
|
{
|
||||||
|
|
||||||
|
settype($value, 'integer');
|
||||||
|
|
||||||
|
$post[0]=$value;
|
||||||
|
|
||||||
|
return $post;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
178
src/ExtraModels/UserPhangoModel.php
Normal file
178
src/ExtraModels/UserPhangoModel.php
Normal file
|
|
@ -0,0 +1,178 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Antonio de la Rosa <webmaster@web-t-sys.com>
|
||||||
|
* @file
|
||||||
|
* @package ExtraUtils/Login
|
||||||
|
*
|
||||||
|
* Now, we define components for use in models. Components are fields on a table.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhangoApp\PhaModels\ExtraModels;
|
||||||
|
|
||||||
|
use PhangoApp\Phai18n\I18n;
|
||||||
|
use PhangoApp\PhaModels\Webmodel;
|
||||||
|
use PhangoApp\PhaUtils\Utils;
|
||||||
|
|
||||||
|
I18n::load_lang('users');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Children class of webmodel for use with login class
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
class UserPhangoModel extends Webmodel {
|
||||||
|
|
||||||
|
public $username='username';
|
||||||
|
public $email='email';
|
||||||
|
public $password='password';
|
||||||
|
public $repeat_password='repeat_password';
|
||||||
|
|
||||||
|
public function insert($post, $safe_query=0)
|
||||||
|
{
|
||||||
|
|
||||||
|
if($this->check_user_exists($post[$this->username], $post[$this->email]))
|
||||||
|
{
|
||||||
|
|
||||||
|
if(!$this->check_password($post['password'], $post['repeat_password']))
|
||||||
|
{
|
||||||
|
|
||||||
|
//$this->components['password']->required=0;
|
||||||
|
|
||||||
|
$this->forms[$this->password]->std_error=I18n::lang('users', 'pasword_not_equal_repeat_password', 'Passwords are not equal');
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return parent::insert($post, $safe_query);
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->std_error=I18n::lang('users', 'cannot_insert_user_email_or_user', 'A user already exists with this email or username');
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update($post, $safe_query=0)
|
||||||
|
{
|
||||||
|
|
||||||
|
if(isset($post[$this->username]) && $post[$this->email])
|
||||||
|
{
|
||||||
|
|
||||||
|
if(!isset($post['IdUser_admin']))
|
||||||
|
{
|
||||||
|
|
||||||
|
settype($_GET['IdUser_admin'], 'integer');
|
||||||
|
|
||||||
|
$post['IdUser_admin']=$_GET['IdUser_admin'];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if($this->check_user_exists($post[$this->username], $post[$this->email], $post['IdUser_admin']))
|
||||||
|
{
|
||||||
|
|
||||||
|
if(!$this->check_password($post['password'], $post['repeat_password']))
|
||||||
|
{
|
||||||
|
|
||||||
|
//$this->components['password']->required=0;
|
||||||
|
|
||||||
|
$this->forms[$this->password]->std_error=I18n::lang('users', 'pasword_not_equal_repeat_password', 'Passwords are not equal');
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if(Utils::form_text($post['password'])=='')
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->components[$this->password]->required=0;
|
||||||
|
unset($post[$this->password]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return parent::update($post, $safe_query);
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->std_error=I18n::lang('users', 'cannot_insert_user_email_or_user', 'A user already exists with this email or username');
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
return parent::update($post, $safe_query);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function check_password($password, $repeat_password)
|
||||||
|
{
|
||||||
|
|
||||||
|
$password=Utils::form_text($password);
|
||||||
|
$repeat_password=Utils::form_text($repeat_password);
|
||||||
|
|
||||||
|
if($password!=$repeat_password)
|
||||||
|
{
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function check_user_exists($user, $email, $iduser=0)
|
||||||
|
{
|
||||||
|
|
||||||
|
$user=$this->components[$this->username]->check($user);
|
||||||
|
$email=$this->components[$this->email]->check($email);
|
||||||
|
|
||||||
|
$where_sql='where ('.$this->username.'="'.$user.'" or '.$this->email.'="'.$email.'")';
|
||||||
|
|
||||||
|
settype($iduser, 'integer');
|
||||||
|
|
||||||
|
if($iduser>0)
|
||||||
|
{
|
||||||
|
|
||||||
|
$where_sql.=' and IdUser_admin!='.$iduser;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->set_conditions($where_sql);
|
||||||
|
|
||||||
|
$c=$this->select_count();
|
||||||
|
|
||||||
|
if($c==0)
|
||||||
|
{
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
80
src/Forms/BaseForm.php
Normal file
80
src/Forms/BaseForm.php
Normal file
|
|
@ -0,0 +1,80 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PhangoApp\PhaModels\Forms;
|
||||||
|
|
||||||
|
use PhangoApp\PhaModels\CoreFields\CharField;
|
||||||
|
use PhangoApp\PhaI18n\I18n;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Basic class for create forms
|
||||||
|
*/
|
||||||
|
|
||||||
|
class BaseForm {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $name The name of form
|
||||||
|
* @param string $name The default value of the form
|
||||||
|
* @param string $name Field class instance used for check files
|
||||||
|
*/
|
||||||
|
|
||||||
|
public $std_error='';
|
||||||
|
|
||||||
|
public function __construct($name, $value)
|
||||||
|
{
|
||||||
|
$this->label=$name;
|
||||||
|
$this->name=$name;
|
||||||
|
$this->default_value=$value;
|
||||||
|
$this->css='';
|
||||||
|
$this->type='text';
|
||||||
|
$this->required=0;
|
||||||
|
$this->field=new CharField();
|
||||||
|
$this->txt_error = I18n::lang('common', 'error_in_field', 'Error in field');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function form()
|
||||||
|
{
|
||||||
|
|
||||||
|
return '<input type="'.$this->type.'" class="'.$this->css.'" name="'.$this->name.'" value="'.$this->setform($this->default_value).'">';
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static method where is registered the js necessary for a field
|
||||||
|
*/
|
||||||
|
|
||||||
|
static public function js()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static method where is registered the js necessary for a field
|
||||||
|
*/
|
||||||
|
|
||||||
|
static public function css()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static method where is registered the js necessary for a field
|
||||||
|
*/
|
||||||
|
|
||||||
|
static public function header()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method for escape value for html input
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function setform($value)
|
||||||
|
{
|
||||||
|
|
||||||
|
return str_replace('"', '"', $value);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
22
src/Forms/DateTimeForm.php
Normal file
22
src/Forms/DateTimeForm.php
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PhangoApp\PhaModels\Forms;
|
||||||
|
use PhangoApp\PhaModels\CoreFields\DateTimeField;
|
||||||
|
|
||||||
|
class DateTimeForm {
|
||||||
|
|
||||||
|
public $set_time=1;
|
||||||
|
|
||||||
|
function form()
|
||||||
|
{
|
||||||
|
|
||||||
|
$timestamp=DateTimeField::obtain_timestamp_datefield($value);
|
||||||
|
// return '<input type="'.$this->type.'" class="'.$this->css.'" name="'.$this->name.'" value="'.$this->setform($this->default_value).'">';
|
||||||
|
|
||||||
|
return DateForm($this->name, $class, $this->default_value, $this->set_time);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
25
src/Forms/HiddenForm.php
Normal file
25
src/Forms/HiddenForm.php
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PhangoApp\PhaModels\Forms;
|
||||||
|
|
||||||
|
use PhangoApp\PhaModels\Forms\BaseForm;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Basic class for create forms
|
||||||
|
*/
|
||||||
|
|
||||||
|
class HiddenForm extends BaseForm{
|
||||||
|
|
||||||
|
public function __construct($name, $value='')
|
||||||
|
{
|
||||||
|
|
||||||
|
parent::__construct($name, $value);
|
||||||
|
|
||||||
|
$this->type='hidden';
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
322
src/Forms/MultiLangForm.php
Normal file
322
src/Forms/MultiLangForm.php
Normal file
|
|
@ -0,0 +1,322 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PhangoApp\PhaModels\Forms;
|
||||||
|
|
||||||
|
use PhangoApp\PhaI18n\I18n;
|
||||||
|
use PhangoApp\PhaUtils\Utils;
|
||||||
|
use PhangoApp\PhaModels\Forms\BaseForm;
|
||||||
|
use PhangoApp\PhaView\View;
|
||||||
|
|
||||||
|
class MultiLangForm extends BaseForm{
|
||||||
|
|
||||||
|
public $type_form;
|
||||||
|
|
||||||
|
public function __construct($name, $value)
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->type_form=new BaseForm($name, $value);
|
||||||
|
|
||||||
|
parent::__construct($name, $value);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function form()
|
||||||
|
{
|
||||||
|
|
||||||
|
//make a foreach with all langs
|
||||||
|
//default, es_ES, en_US, show default if no exists translation for selected language.
|
||||||
|
/*
|
||||||
|
foreach(I18n::$arr_i18n as $lang_select)
|
||||||
|
{
|
||||||
|
|
||||||
|
$arr_selected[Utils::slugify($lang_select)]='hidden_form';
|
||||||
|
$arr_selected[Utils::slugify(I18n::$language)]='no_hidden_form';
|
||||||
|
|
||||||
|
settype($arr_values[$lang_select], 'string');
|
||||||
|
echo '<div class="'.$arr_selected[Utils::slugify($lang_select)].'" id="'.$this->name.'_'.$lang_select.'">';
|
||||||
|
echo $this->type_form($this->name.'['.$lang_select.']', '', $arr_values[$lang_select]);
|
||||||
|
echo '</div>';
|
||||||
|
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<div id="languages">
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$arr_selected=array();
|
||||||
|
|
||||||
|
foreach(I18n::$arr_i18n as $lang_item)
|
||||||
|
{
|
||||||
|
//set
|
||||||
|
|
||||||
|
$arr_selected[Utils::slugify($lang_item)]='no_choose_flag';
|
||||||
|
$arr_selected[Utils::slugify(I18n::$language)]='choose_flag';
|
||||||
|
|
||||||
|
?>
|
||||||
|
<a class="<?php echo $arr_selected[Utils::slugify($lang_item)]; ?>" id="<?php echo $this->name.'_'.$lang_item; ?>_flag" href="#" onclick="change_form_language_<?php echo $this->name; ?>('<?php echo $this->name; ?>', '<?php echo $this->name.'_'.$lang_item; ?>'); return false;"><img src="<?php echo View::get_media_url('images/languages/'.$lang_item.'.png'); ?>" alt="<?php echo $lang_item; ?>"/></a>
|
||||||
|
<?php
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
<hr />
|
||||||
|
<script language="Javascript">
|
||||||
|
|
||||||
|
function change_form_language_<?php echo $this->name; ?>(field, lang_field)
|
||||||
|
{
|
||||||
|
|
||||||
|
if(typeof jQuery == 'undefined')
|
||||||
|
{
|
||||||
|
alert('<?php echo I18n::lang('common', 'cannot_load_jquery', 'Cannot load jquery'); ?>');
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
<?php
|
||||||
|
|
||||||
|
foreach(I18n::$arr_i18n as $lang_item)
|
||||||
|
{
|
||||||
|
|
||||||
|
?>
|
||||||
|
$("#<?php echo $this->name.'_'.$lang_item; ?>").hide();//removeClass("no_hidden_form").addClass("hidden_form");
|
||||||
|
$("#<?php echo $this->name.'_'.$lang_item; ?>_flag").removeClass("choose_flag").addClass("no_choose_flag");
|
||||||
|
<?php
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
lang_field=lang_field.replace('[', '\\[');
|
||||||
|
lang_field=lang_field.replace(']', '\\]');
|
||||||
|
|
||||||
|
$("#"+lang_field).show();//.removeClass("hidden_form").addClass("no_hidden_form");
|
||||||
|
$("#"+lang_field+'_flag').removeClass("no_choose_flag").addClass("choose_flag");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
ob_start();
|
||||||
|
|
||||||
|
if(gettype($arr_values)!='array')
|
||||||
|
{
|
||||||
|
|
||||||
|
$arr_values = @unserialize( $arr_values );
|
||||||
|
|
||||||
|
if(gettype($arr_values)!='array')
|
||||||
|
{
|
||||||
|
|
||||||
|
$arr_values=array();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
foreach(I18n::$arr_i18n as $lang_select)
|
||||||
|
{
|
||||||
|
|
||||||
|
$arr_selected[Utils::slugify($lang_select)]='hidden_form';
|
||||||
|
$arr_selected[Utils::slugify(I18n::$language)]='no_hidden_form';
|
||||||
|
|
||||||
|
settype($arr_values[$lang_select], 'string');
|
||||||
|
echo '<div class="'.$arr_selected[Utils::slugify($lang_select)].'" id="'.$this->name.'_'.$lang_select.'">';
|
||||||
|
echo $this->type_form($this->name.'['.$lang_select.']', '', $arr_values[$lang_select]);
|
||||||
|
echo '</div>';
|
||||||
|
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<div id="languages">
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$arr_selected=array();
|
||||||
|
|
||||||
|
foreach(PhangoVar::$arr_i18n as $lang_item)
|
||||||
|
{
|
||||||
|
//set
|
||||||
|
|
||||||
|
$arr_selected[Utils::slugify($lang_item)]='no_choose_flag';
|
||||||
|
$arr_selected[Utils::slugify(I18n::$language)]='choose_flag';
|
||||||
|
|
||||||
|
?>
|
||||||
|
<a class="<?php echo $arr_selected[Utils::slugify($lang_item)]; ?>" id="<?php echo $this->name.'_'.$lang_item; ?>_flag" href="#" onclick="change_form_language_<?php echo $this->name; ?>('<?php echo $this->name; ?>', '<?php echo $this->name.'_'.$lang_item; ?>'); return false;"><img src="<?php echo get_url_image('languages/'.$lang_item.'.png'); ?>" alt="<?php echo $lang_item; ?>"/></a>
|
||||||
|
<?php
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
<hr />
|
||||||
|
<script language="Javascript">
|
||||||
|
|
||||||
|
function change_form_language_<?php echo $this->name; ?>(field, lang_field)
|
||||||
|
{
|
||||||
|
|
||||||
|
if(typeof jQuery == 'undefined')
|
||||||
|
{
|
||||||
|
alert('<?php echo PhangoVar::$lang['common']['cannot_load_jquery']; ?>');
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
<?php
|
||||||
|
|
||||||
|
foreach(PhangoVar::$arr_i18n as $lang_item)
|
||||||
|
{
|
||||||
|
|
||||||
|
?>
|
||||||
|
$("#<?php echo $this->name.'_'.$lang_item; ?>").hide();//removeClass("no_hidden_form").addClass("hidden_form");
|
||||||
|
$("#<?php echo $this->name.'_'.$lang_item; ?>_flag").removeClass("choose_flag").addClass("no_choose_flag");
|
||||||
|
<?php
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
lang_field=lang_field.replace('[', '\\[');
|
||||||
|
lang_field=lang_field.replace(']', '\\]');
|
||||||
|
|
||||||
|
$("#"+lang_field).show();//.removeClass("hidden_form").addClass("no_hidden_form");
|
||||||
|
$("#"+lang_field+'_flag').removeClass("no_choose_flag").addClass("choose_flag");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
$text_form=ob_get_contents();
|
||||||
|
|
||||||
|
ob_end_clean();
|
||||||
|
|
||||||
|
return $text_form;
|
||||||
|
*/
|
||||||
|
|
||||||
|
if(!get_class($this->type_form))
|
||||||
|
{
|
||||||
|
|
||||||
|
throw new \Exception('Error: need set the $type_form property with a valid class form in '.$this->name);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if(gettype($this->default_value)!='array')
|
||||||
|
{
|
||||||
|
|
||||||
|
$arr_values=unserialize($this->default_value);
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
$arr_values=$this->default_value;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//print_r($this->default_value);
|
||||||
|
|
||||||
|
foreach(I18n::$arr_i18n as $lang_select)
|
||||||
|
{
|
||||||
|
|
||||||
|
$slug=Utils::slugify($lang_select);
|
||||||
|
$lang_slug=Utils::slugify(I18n::$language);
|
||||||
|
|
||||||
|
$arr_selected[$slug]='hidden_form';
|
||||||
|
$arr_selected[$lang_slug]='no_hidden_form';
|
||||||
|
|
||||||
|
$this->type_form->name=$this->name.'['.$lang_select.']';
|
||||||
|
|
||||||
|
$this->type_form->default_value=$this->setform($arr_values[$lang_select]);
|
||||||
|
|
||||||
|
echo '<div class="'.$arr_selected[$slug].' '.$this->name.'_group" id="'.$this->name.'_'.$lang_select.'">';
|
||||||
|
echo $this->type_form->form();
|
||||||
|
echo '</div>';
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
<div id="languages">
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$arr_selected=array();
|
||||||
|
|
||||||
|
$language=Utils::slugify(I18n::$language);
|
||||||
|
|
||||||
|
foreach(I18n::$arr_i18n as $lang_item)
|
||||||
|
{
|
||||||
|
//set
|
||||||
|
|
||||||
|
$lang_item_slug=Utils::slugify($lang_item);
|
||||||
|
|
||||||
|
$arr_selected[$lang_item_slug]='no_choose_flag';
|
||||||
|
$arr_selected[$language]='choose_flag';
|
||||||
|
|
||||||
|
?>
|
||||||
|
<a class="flag <?php echo $arr_selected[$lang_item_slug]; ?> <?php echo $this->name; ?>_flag" alt="<?php echo $this->name; ?>" id="<?php echo $lang_item; ?>_flag" href="#"><img src="<?php echo View::get_media_url('images/languages/'.$lang_item.'.png'); ?>" alt="<?php echo $lang_item; ?>"/></a>
|
||||||
|
<?php
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
<br />
|
||||||
|
<hr />
|
||||||
|
<?php
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static public function header()
|
||||||
|
{
|
||||||
|
|
||||||
|
ob_start();
|
||||||
|
|
||||||
|
?>
|
||||||
|
<script language="Javascript">
|
||||||
|
$(document).ready( function () {
|
||||||
|
|
||||||
|
$('.flag').click( function () {
|
||||||
|
|
||||||
|
if( $(this).hasClass('no_choose_flag') )
|
||||||
|
{
|
||||||
|
group=$(this).attr('alt');
|
||||||
|
|
||||||
|
lang=$(this).attr('id').replace('_flag', '');
|
||||||
|
|
||||||
|
flag='.'+group+'_flag';
|
||||||
|
|
||||||
|
show_input='#'+group+'_'+lang;
|
||||||
|
|
||||||
|
remove_input='.'+group+'_group'
|
||||||
|
|
||||||
|
//Change flags
|
||||||
|
|
||||||
|
$(flag).removeClass('choose_flag').addClass('no_choose_flag');
|
||||||
|
|
||||||
|
$(this).removeClass('no_choose_flag').addClass('choose_flag');
|
||||||
|
|
||||||
|
//Change inputs
|
||||||
|
|
||||||
|
$(remove_input).removeClass('no_hidden_form').addClass('hidden_form');
|
||||||
|
|
||||||
|
$(show_input).removeClass('hidden_form').addClass('no_hidden_form');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
<?php
|
||||||
|
|
||||||
|
View::$header[]=ob_get_contents();
|
||||||
|
|
||||||
|
ob_end_clean();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
32
src/Forms/PasswordForm.php
Normal file
32
src/Forms/PasswordForm.php
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PhangoApp\PhaModels\Forms;
|
||||||
|
|
||||||
|
use PhangoApp\PhaModels\Forms\BaseForm;
|
||||||
|
use PhangoApp\PhaModels\CoreFields\PasswordField;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Basic class for create forms
|
||||||
|
*/
|
||||||
|
|
||||||
|
class PasswordForm extends BaseForm{
|
||||||
|
|
||||||
|
public function __construct($name, $value='')
|
||||||
|
{
|
||||||
|
|
||||||
|
parent::__construct($name, $value);
|
||||||
|
|
||||||
|
$this->field=new PasswordField();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function form()
|
||||||
|
{
|
||||||
|
|
||||||
|
return '<input type="password" class="'.$this->css.'" name="'.$this->name.'" value="">';
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
52
src/Forms/SelectForm.php
Normal file
52
src/Forms/SelectForm.php
Normal file
|
|
@ -0,0 +1,52 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PhangoApp\PhaModels\Forms;
|
||||||
|
|
||||||
|
use PhangoApp\PhaModels\Forms\BaseForm;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Basic class for create forms
|
||||||
|
*/
|
||||||
|
|
||||||
|
class SelectForm extends BaseForm{
|
||||||
|
|
||||||
|
public $arr_select=array();
|
||||||
|
|
||||||
|
public function form()
|
||||||
|
{
|
||||||
|
|
||||||
|
//return '<input type="password" class="'.$this->css.'" name="'.$this->name.'" value="">';
|
||||||
|
$arr_selected[$this->default_value]=' selected';
|
||||||
|
|
||||||
|
ob_start();
|
||||||
|
|
||||||
|
?>
|
||||||
|
<select name="<?php echo $this->name; ?>">
|
||||||
|
<?php
|
||||||
|
|
||||||
|
foreach($this->arr_select as $value => $select)
|
||||||
|
{
|
||||||
|
|
||||||
|
settype($arr_selected[$value], 'string');
|
||||||
|
|
||||||
|
?>
|
||||||
|
<option value="<?php echo $value; ?>"<?php echo $arr_selected[$value]; ?>><?php echo $select; ?></option>
|
||||||
|
<?php
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
</select>
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$input=ob_get_contents();
|
||||||
|
|
||||||
|
ob_end_clean();
|
||||||
|
|
||||||
|
return $input;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
78
src/Forms/TextAreaEditor.php
Normal file
78
src/Forms/TextAreaEditor.php
Normal file
|
|
@ -0,0 +1,78 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PhangoApp\PhaModels\Forms;
|
||||||
|
|
||||||
|
use PhangoApp\PhaModels\Forms\BaseForm;
|
||||||
|
use PhangoApp\PhaUtils\Utils;
|
||||||
|
use PhangoApp\PhaView\View;
|
||||||
|
use PhangoApp\PhaRouter\Routes;
|
||||||
|
use PhangoApp\PhaI18n\I18n;
|
||||||
|
|
||||||
|
class TextAreaEditor extends BaseForm {
|
||||||
|
|
||||||
|
public function form()
|
||||||
|
{
|
||||||
|
|
||||||
|
//PhangoVar::$arr_cache_jscript[]='tinymce_path.js';
|
||||||
|
if(!isset(View::$header['tinymce']))
|
||||||
|
{
|
||||||
|
View::$js[]='jquery.min.js';
|
||||||
|
View::$js[]='tinymce/tinymce.min.js';
|
||||||
|
|
||||||
|
ob_start();
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
|
||||||
|
$(document).ready( function () {
|
||||||
|
|
||||||
|
|
||||||
|
tinymce.init({
|
||||||
|
selector: "textarea.tinymce_editor",
|
||||||
|
//theme: "modern",
|
||||||
|
height: 300,
|
||||||
|
plugins: [
|
||||||
|
"advlist autolink link image lists charmap print preview hr anchor pagebreak",
|
||||||
|
"searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
|
||||||
|
"table contextmenu directionality emoticons template paste textcolor"
|
||||||
|
],
|
||||||
|
file_browser_callback: function(field_name, url, type, win){
|
||||||
|
var filebrowser = "<?php echo Routes::make_module_url('gallery', 'index'); ?>";
|
||||||
|
tinymce.activeEditor.windowManager.open({
|
||||||
|
title : "<?php echo I18n::lang('common', 'load_file', 'Load_image'); ?>",
|
||||||
|
width : 520,
|
||||||
|
height : 400,
|
||||||
|
url : filebrowser
|
||||||
|
}, {
|
||||||
|
window : win,
|
||||||
|
input : field_name
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
|
||||||
|
View::$header['tinymce']=ob_get_contents();
|
||||||
|
|
||||||
|
ob_end_clean();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
<p><textarea class="tinymce_editor" name="<?php echo $this->name; ?>"><?php echo $this->default_value; ?></textarea></p>
|
||||||
|
<?php
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
@ -221,7 +221,8 @@ class ModelForm {
|
||||||
|
|
||||||
$func_setvalue=$this->form.'Set';
|
$func_setvalue=$this->form.'Set';
|
||||||
|
|
||||||
$this->parameters[2]=$func_setvalue($this->parameters[2], $value, $form_type_set);
|
//$this->parameters[2]=$func_setvalue($this->parameters[2], $value, $form_type_set);
|
||||||
|
$this->parameters[2]=call_user_func_array($func_setvalue, array($this->parameters[2], $value, $form_type_set));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -317,21 +318,21 @@ class ModelForm {
|
||||||
|
|
||||||
$form=$arr_form[$key_form];
|
$form=$arr_form[$key_form];
|
||||||
|
|
||||||
$post[$key_form]=$form->type->check($post[$key_form]);
|
$post[$key_form]=$form->field->check($post[$key_form]);
|
||||||
|
|
||||||
if($post[$key_form]=='' && $form->required==1)
|
if($post[$key_form]=='' && $form->required==1)
|
||||||
{
|
{
|
||||||
|
|
||||||
if($form->type->std_error!='')
|
if($form->field->std_error!='')
|
||||||
{
|
{
|
||||||
|
|
||||||
$form->std_error=$form->type->std_error;
|
$form->std_error=$form->field->std_error;
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
$form->std_error=$form->txt_error;
|
$form->std_error=I18n::lang('common', 'field_required', 'Field is required');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -374,7 +375,7 @@ class ModelForm {
|
||||||
* @param array $show_error An option for choose if in the form is showed
|
* @param array $show_error An option for choose if in the form is showed
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static public function set_values_form($post, $arr_form, $show_error=1)
|
static public function set_values_form($arr_form, $post, $show_error=1)
|
||||||
{
|
{
|
||||||
|
|
||||||
//Foreach to $post values
|
//Foreach to $post values
|
||||||
|
|
@ -389,29 +390,43 @@ class ModelForm {
|
||||||
if(isset($arr_form[$name_field]))
|
if(isset($arr_form[$name_field]))
|
||||||
{
|
{
|
||||||
|
|
||||||
if($arr_form[$name_field]->type->std_error!='' && $show_error==1)
|
if($show_error==1)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
/*if($arr_form[$name_field]->std_error!='')
|
if($arr_form[$name_field]->std_error!='')
|
||||||
{
|
{
|
||||||
|
|
||||||
$arr_form[$name_field]->std_error=$arr_form[$name_field]->txt_error;
|
$arr_form[$name_field]->std_error=$arr_form[$name_field]->txt_error;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else*/
|
else
|
||||||
if($arr_form[$name_field]->std_error=='')
|
if($arr_form[$name_field]->std_error=='')
|
||||||
{
|
{
|
||||||
|
|
||||||
$arr_form[$name_field]->std_error=$arr_form[$name_field]->type->std_error;
|
$arr_form[$name_field]->std_error=$arr_form[$name_field]->field->std_error;
|
||||||
|
|
||||||
|
}*/
|
||||||
|
|
||||||
|
if($arr_form[$name_field]->field->std_error!='')
|
||||||
|
{
|
||||||
|
|
||||||
|
$arr_form[$name_field]->std_error=$arr_form[$name_field]->field->std_error;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
/*else
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Set value for ModelForm to $value
|
//Set value for ModelForm to $value
|
||||||
|
|
||||||
$arr_form[$name_field]->set_param_value_form($value);
|
$arr_form[$name_field]->default_value=$value;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -426,6 +441,24 @@ class ModelForm {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static public function pass_errors_to_form($model)
|
||||||
|
{
|
||||||
|
|
||||||
|
foreach(array_keys($model->components) as $key)
|
||||||
|
{
|
||||||
|
|
||||||
|
if(isset($model->forms[$key]))
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
$model->forms[$key]->field->std_error=$model->components[$key]->std_error;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
355
src/Webmodel.php
355
src/Webmodel.php
|
|
@ -3,6 +3,8 @@
|
||||||
namespace PhangoApp\PhaModels;
|
namespace PhangoApp\PhaModels;
|
||||||
|
|
||||||
use PhangoApp\PhaI18n\I18n;
|
use PhangoApp\PhaI18n\I18n;
|
||||||
|
use PhangoApp\PhaModels\CoreFields\PrimaryField;
|
||||||
|
use PhangoApp\PhaModels\Forms\BaseForm;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The most important class for the framework
|
* The most important class for the framework
|
||||||
|
|
@ -172,7 +174,7 @@ class Webmodel {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* If you checked the values that you going to save on your model, please, put this value to 1 or true.
|
* If you checked the values that you going to save on your model, please, put this value to 1 or 1.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
@ -235,6 +237,34 @@ class Webmodel {
|
||||||
|
|
||||||
static public $model=array();
|
static public $model=array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A string where is saved the conditions used for create queries
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
public $conditions='WHERE 1=1';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A string where is set the order of query
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
public $order_by='';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A string where is saved the limit of rows in query
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
public $limit='';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A string where is saved the limit of rows in query
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
public $reset_conditions=1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal arrays for create new indexes in the tables
|
* Internal arrays for create new indexes in the tables
|
||||||
*
|
*
|
||||||
|
|
@ -246,6 +276,30 @@ class Webmodel {
|
||||||
static public $arr_sql_unique=array();
|
static public $arr_sql_unique=array();
|
||||||
static public $arr_sql_set_unique=array();
|
static public $arr_sql_set_unique=array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple property for save models in object mode
|
||||||
|
*/
|
||||||
|
|
||||||
|
static public $m;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A simple array for load js, header and css from forms objects only one time
|
||||||
|
*/
|
||||||
|
|
||||||
|
static public $form_type=array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A simple array for control if was loaded contents from a form
|
||||||
|
*/
|
||||||
|
|
||||||
|
static public $form_type_checked=array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A simple switch for know if updated or insert this model
|
||||||
|
*/
|
||||||
|
|
||||||
|
public $update=0;
|
||||||
|
|
||||||
//Construct the model
|
//Construct the model
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -265,7 +319,9 @@ class Webmodel {
|
||||||
|
|
||||||
$this->name=$name_model;
|
$this->name=$name_model;
|
||||||
$this->idmodel='Id'.ucfirst($this->name);
|
$this->idmodel='Id'.ucfirst($this->name);
|
||||||
$this->components[$this->idmodel]=new \PrimaryField();
|
$this->components[$this->idmodel]=new PrimaryField();
|
||||||
|
$this->components[$this->idmodel]->name_model=$name_model;
|
||||||
|
$this->components[$this->idmodel]->name_component=$this->idmodel;
|
||||||
$this->label=$this->name;
|
$this->label=$this->name;
|
||||||
|
|
||||||
if(!isset(Webmodel::$connection_func[$this->db_selected]))
|
if(!isset(Webmodel::$connection_func[$this->db_selected]))
|
||||||
|
|
@ -278,7 +334,11 @@ class Webmodel {
|
||||||
$this->cache=$cache;
|
$this->cache=$cache;
|
||||||
$this->type_cache=$type_cache;
|
$this->type_cache=$type_cache;
|
||||||
|
|
||||||
|
//Global access to models
|
||||||
|
|
||||||
|
Webmodel::$model[$name_model]=&$this;
|
||||||
|
|
||||||
|
Webmodel::$m->$name_model=&Webmodel::$model[$name_model];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -294,11 +354,11 @@ class Webmodel {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static public function load_model($model)
|
static public function load_model($model_path)
|
||||||
{
|
{
|
||||||
|
|
||||||
$app_model=$model;
|
//$app_model=$model;
|
||||||
|
/*
|
||||||
if(strpos($model, '/'))
|
if(strpos($model, '/'))
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
@ -309,10 +369,11 @@ class Webmodel {
|
||||||
$model=$arr_model[1];
|
$model=$arr_model[1];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
$path_model=Webmodel::$model_path.$app_model.'/'.Webmodel::$model_folder.'/models_'.$model.'.php';
|
$path_model=$model_path.'.php';
|
||||||
|
|
||||||
if(!isset(Webmodel::$cache_model[$app_model.'/'.$model]))
|
if(!isset(Webmodel::$cache_model[$path_model]))
|
||||||
{
|
{
|
||||||
|
|
||||||
if(is_file($path_model))
|
if(is_file($path_model))
|
||||||
|
|
@ -320,7 +381,7 @@ class Webmodel {
|
||||||
|
|
||||||
include($path_model);
|
include($path_model);
|
||||||
|
|
||||||
Webmodel::$cache_model[$app_model.'/'.$model]=1;
|
Webmodel::$cache_model[$path_model]=1;
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -366,13 +427,6 @@ class Webmodel {
|
||||||
|
|
||||||
ob_clean();
|
ob_clean();
|
||||||
|
|
||||||
//$text_error='<p>Output: '.$output.'</p>';
|
|
||||||
|
|
||||||
/*$arr_error_sql[0]='<p>Error: Cannot connect to MySQL db.</p>';
|
|
||||||
$arr_error_sql[1]='<p>Error: Cannot connect to MySQL db, '.$output.'</p>';
|
|
||||||
|
|
||||||
show_error($arr_error_sql[0], $arr_error_sql[1]);*/
|
|
||||||
|
|
||||||
throw new \Exception('Error: cannot connect to database');
|
throw new \Exception('Error: cannot connect to database');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -431,7 +485,7 @@ class Webmodel {
|
||||||
unset($this->components[$this->idmodel]);
|
unset($this->components[$this->idmodel]);
|
||||||
$this->idmodel=$name_id;
|
$this->idmodel=$name_id;
|
||||||
//$this->components[$this->idmodel]=new PrimaryField();
|
//$this->components[$this->idmodel]=new PrimaryField();
|
||||||
$this->register($this->idmodel, 'PrimaryField', array());
|
$this->register($this->idmodel, new PrimaryField($this->idmodel));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -501,6 +555,60 @@ class Webmodel {
|
||||||
return SQLClass::webtsys_query($sql_query, $this->db_selected);
|
return SQLClass::webtsys_query($sql_query, $this->db_selected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function set_conditions($conditions, $order_by='', $limit='')
|
||||||
|
{
|
||||||
|
|
||||||
|
$conditions=trim($conditions);
|
||||||
|
|
||||||
|
if($conditions=='')
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->conditions="WHERE 1=1";
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->conditions=$conditions;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->order_by=$order_by;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function set_order($order_by)
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->order_by=$order_by;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function set_limit($limit)
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->limit=$limit;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function reset_conditions()
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->conditions='WHERE 1=1';
|
||||||
|
|
||||||
|
$this->order_by='order by '.$this->idmodel.' ASC';
|
||||||
|
|
||||||
|
$this->limit='';
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show_conditions()
|
||||||
|
{
|
||||||
|
|
||||||
|
return $this->conditions;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method insert a row in database using model how mirage of table.
|
* This method insert a row in database using model how mirage of table.
|
||||||
*
|
*
|
||||||
|
|
@ -509,7 +617,7 @@ class Webmodel {
|
||||||
* @param array $post Is an array with data to insert. You have a key that represent the name of field to fill with data, and the value that is the data for fill.
|
* @param array $post Is an array with data to insert. You have a key that represent the name of field to fill with data, and the value that is the data for fill.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function insert($post)
|
public function insert($post, $safe_query=0)
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->set_phango_connection();
|
$this->set_phango_connection();
|
||||||
|
|
@ -519,23 +627,27 @@ class Webmodel {
|
||||||
$post=$this->unset_no_required($post);
|
$post=$this->unset_no_required($post);
|
||||||
|
|
||||||
//Check if minimal fields are fill and if fields exists in components.Check field's values.
|
//Check if minimal fields are fill and if fields exists in components.Check field's values.
|
||||||
|
/*
|
||||||
if(!$this->modify_id)
|
if(!$this->modify_id)
|
||||||
{
|
{
|
||||||
|
|
||||||
unset($post[$this->idmodel]);
|
unset($post[$this->idmodel]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
$this->update=0;
|
||||||
|
|
||||||
$arr_fields=array();
|
$arr_fields=array();
|
||||||
|
|
||||||
if( $fields=$this->check_all($post) )
|
if( $fields=$this->check_all($post, $safe_query) )
|
||||||
{
|
{
|
||||||
|
|
||||||
if( !( $query=SQLClass::webtsys_query($this->prepare_insert_sql($fields), $this->db_selected) ) )
|
if( !( $query=SQLClass::webtsys_query($this->prepare_insert_sql($fields), $this->db_selected) ) )
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->std_error.=I18n::lang('error_model', 'cant_insert', 'Can\'t insert').' ';
|
$this->std_error.=I18n::lang('error_model', 'cant_insert', 'Can\'t insert').' ';
|
||||||
|
ModelForm::pass_errors_to_form($this);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -549,6 +661,7 @@ class Webmodel {
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
|
ModelForm::pass_errors_to_form($this);
|
||||||
$this->std_error.=I18n::lang('error_model', 'cant_insert', 'Can\'t insert').' ';
|
$this->std_error.=I18n::lang('error_model', 'cant_insert', 'Can\'t insert').' ';
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -570,11 +683,20 @@ class Webmodel {
|
||||||
* @param $conditions is a string containing a sql string beginning by "where". Example: where id=1.
|
* @param $conditions is a string containing a sql string beginning by "where". Example: where id=1.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function update($post, $conditions="")
|
public function update($post, $safe_query=0)
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->set_phango_connection();
|
$this->set_phango_connection();
|
||||||
|
|
||||||
|
$conditions=trim($this->conditions.' '.$this->order_by.' '.$this->limit);
|
||||||
|
|
||||||
|
if($this->reset_conditions==1)
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->reset_conditions();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
//Make conversion from post
|
//Make conversion from post
|
||||||
|
|
||||||
//Check if minimal fields are fill and if fields exists in components.
|
//Check if minimal fields are fill and if fields exists in components.
|
||||||
|
|
@ -592,9 +714,13 @@ class Webmodel {
|
||||||
|
|
||||||
$post=$this->unset_no_required($post);
|
$post=$this->unset_no_required($post);
|
||||||
|
|
||||||
|
//With this property your fields can save if insert or update
|
||||||
|
|
||||||
|
$this->update=1;
|
||||||
|
|
||||||
//Checking and sanitizing data from $post array for use in the query
|
//Checking and sanitizing data from $post array for use in the query
|
||||||
|
|
||||||
if( $fields=$this->check_all($post) )
|
if( $fields=$this->check_all($post, $safe_query) )
|
||||||
{
|
{
|
||||||
|
|
||||||
//Foreach for create the query that comes from the $post array
|
//Foreach for create the query that comes from the $post array
|
||||||
|
|
@ -607,6 +733,7 @@ class Webmodel {
|
||||||
$quot_open=$component->quot_open;
|
$quot_open=$component->quot_open;
|
||||||
$quot_close=$component->quot_close;
|
$quot_close=$component->quot_close;
|
||||||
|
|
||||||
|
/*
|
||||||
if(get_class($component)=='ForeignKeyField' && $fields[$key]==NULL)
|
if(get_class($component)=='ForeignKeyField' && $fields[$key]==NULL)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
@ -614,7 +741,7 @@ class Webmodel {
|
||||||
$quot_close='';
|
$quot_close='';
|
||||||
$fields[$key]='NULL';
|
$fields[$key]='NULL';
|
||||||
|
|
||||||
}
|
}*/
|
||||||
|
|
||||||
$arr_fields[]='`'.$key.'`='.$quot_open.$fields[$key].$quot_close;
|
$arr_fields[]='`'.$key.'`='.$quot_open.$fields[$key].$quot_close;
|
||||||
|
|
||||||
|
|
@ -652,6 +779,7 @@ class Webmodel {
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->std_error.=I18n::lang('error_model', 'cant_update', 'Can\'t update').' ';
|
$this->std_error.=I18n::lang('error_model', 'cant_update', 'Can\'t update').' ';
|
||||||
|
ModelForm::pass_errors_to_form($this);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -665,7 +793,7 @@ class Webmodel {
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//Validation of $post fail, add error to $model->std_error
|
//Validation of $post fail, add error to $model->std_error
|
||||||
|
ModelForm::pass_errors_to_form($this);
|
||||||
$this->std_error.=I18n::lang('error_model', 'cant_update', 'Can\'t update').' ';
|
$this->std_error.=I18n::lang('error_model', 'cant_update', 'Can\'t update').' ';
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -690,7 +818,7 @@ class Webmodel {
|
||||||
* @param $raw_query If set to 0, you obtain fields from table related if you selected a foreignkey field, if set to 1, you obtain an array without any join.
|
* @param $raw_query If set to 0, you obtain fields from table related if you selected a foreignkey field, if set to 1, you obtain an array without any join.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function select($conditions="", $arr_select=array(), $raw_query=0)
|
public function select($arr_select=array(), $raw_query=0)
|
||||||
{
|
{
|
||||||
//Check conditions.., script must check, i can't make all things!, i am not a machine!
|
//Check conditions.., script must check, i can't make all things!, i am not a machine!
|
||||||
|
|
||||||
|
|
@ -808,7 +936,7 @@ class Webmodel {
|
||||||
|
|
||||||
//$conditions is a variable where store the result from $arr_select and $arr_extra_select
|
//$conditions is a variable where store the result from $arr_select and $arr_extra_select
|
||||||
|
|
||||||
if(preg_match('/^where/', $conditions) || preg_match('/^WHERE/', $conditions))
|
/*if(preg_match('/^where/', $conditions) || preg_match('/^WHERE/', $conditions))
|
||||||
{
|
{
|
||||||
|
|
||||||
$conditions=str_replace('where', '', $conditions);
|
$conditions=str_replace('where', '', $conditions);
|
||||||
|
|
@ -822,6 +950,22 @@ class Webmodel {
|
||||||
|
|
||||||
$conditions='WHERE '.$where.' '.$conditions;
|
$conditions='WHERE '.$where.' '.$conditions;
|
||||||
|
|
||||||
|
}*/
|
||||||
|
|
||||||
|
if($where!='')
|
||||||
|
{
|
||||||
|
|
||||||
|
$where=' and '.$where;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$conditions=trim($this->conditions.$where.' '.$this->order_by.' '.$this->limit);
|
||||||
|
|
||||||
|
if($this->reset_conditions==1)
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->reset_conditions();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//$this->create_extra_fields();
|
//$this->create_extra_fields();
|
||||||
|
|
@ -863,7 +1007,7 @@ class Webmodel {
|
||||||
* @param string $fields_for_count Array for fields used for simple counts based on foreignkeyfields.
|
* @param string $fields_for_count Array for fields used for simple counts based on foreignkeyfields.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function select_count($conditions, $field='', $fields_for_count=array())
|
public function select_count($field='', $fields_for_count=array())
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->set_phango_connection();
|
$this->set_phango_connection();
|
||||||
|
|
@ -922,6 +1066,23 @@ class Webmodel {
|
||||||
|
|
||||||
$where=implode(" and ", $arr_where);
|
$where=implode(" and ", $arr_where);
|
||||||
|
|
||||||
|
if($where!='')
|
||||||
|
{
|
||||||
|
|
||||||
|
$where=' and '.$where;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$conditions=trim($this->conditions.$where.' '.$this->order_by.' '.$this->limit);
|
||||||
|
|
||||||
|
if($this->reset_conditions==1)
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->reset_conditions();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
if(preg_match('/^where/', $conditions) || preg_match('/^WHERE/', $conditions))
|
if(preg_match('/^where/', $conditions) || preg_match('/^WHERE/', $conditions))
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
@ -936,7 +1097,7 @@ class Webmodel {
|
||||||
|
|
||||||
$conditions='WHERE '.$where.' '.$conditions;
|
$conditions='WHERE '.$where.' '.$conditions;
|
||||||
|
|
||||||
}
|
}*/
|
||||||
|
|
||||||
$query=SQLClass::webtsys_query('select count('.$this->name.'.`'.$field.'`) from '.implode(', ', $arr_model).' '.$conditions, $this->db_selected);
|
$query=SQLClass::webtsys_query('select count('.$this->name.'.`'.$field.'`) from '.implode(', ', $arr_model).' '.$conditions, $this->db_selected);
|
||||||
|
|
||||||
|
|
@ -954,11 +1115,13 @@ class Webmodel {
|
||||||
* @param string $conditions Conditions have same sintax that $conditions from $this->select method
|
* @param string $conditions Conditions have same sintax that $conditions from $this->select method
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function delete($conditions="")
|
public function delete()
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->set_phango_connection();
|
$this->set_phango_connection();
|
||||||
|
|
||||||
|
$conditions=trim($this->conditions.' '.$this->order_by.' '.$this->limit);
|
||||||
|
|
||||||
foreach($this->components as $name_field => $component)
|
foreach($this->components as $name_field => $component)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
@ -974,10 +1137,14 @@ class Webmodel {
|
||||||
//Delete rows on models with foreignkeyfields to this model...
|
//Delete rows on models with foreignkeyfields to this model...
|
||||||
//You need load all models with relationship if you want delete related rows...
|
//You need load all models with relationship if you want delete related rows...
|
||||||
|
|
||||||
|
$this->set_conditions($this->conditions);
|
||||||
|
|
||||||
|
$this->set_limit($this->limit);
|
||||||
|
|
||||||
if(count($this->related_models_delete)>0)
|
if(count($this->related_models_delete)>0)
|
||||||
{
|
{
|
||||||
|
|
||||||
$arr_deleted=$this->select_to_array($conditions, array($this->idmodel), 1);
|
$arr_deleted=$this->select_to_array(array($this->idmodel), 1);
|
||||||
|
|
||||||
$arr_id=array_keys($arr_deleted);
|
$arr_id=array_keys($arr_deleted);
|
||||||
|
|
||||||
|
|
@ -988,13 +1155,21 @@ class Webmodel {
|
||||||
|
|
||||||
if( isset( Webmodel::$model[ $arr_set_model['model'] ]->components[ $arr_set_model['related_field'] ] ) )
|
if( isset( Webmodel::$model[ $arr_set_model['model'] ]->components[ $arr_set_model['related_field'] ] ) )
|
||||||
{
|
{
|
||||||
|
$this->set_conditions('where '.$arr_set_model['related_field'].' IN ('.implode(', ', $arr_id).')');
|
||||||
|
|
||||||
Webmodel::$model[ $arr_set_model['model'] ]->delete('where '.$arr_set_model['related_field'].' IN ('.implode(', ', $arr_id).')');
|
Webmodel::$model[ $arr_set_model['model'] ]->delete();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if($this->reset_conditions==1)
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->reset_conditions();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return SQLClass::webtsys_query('delete from '.$this->name.' '.$conditions, $this->db_selected);
|
return SQLClass::webtsys_query('delete from '.$this->name.' '.$conditions, $this->db_selected);
|
||||||
|
|
@ -1062,7 +1237,7 @@ class Webmodel {
|
||||||
|
|
||||||
//Check if indexed
|
//Check if indexed
|
||||||
|
|
||||||
if($this->components[$field]->indexed==true)
|
if($this->components[$field]->indexed==1)
|
||||||
{
|
{
|
||||||
|
|
||||||
Webmodel::$arr_sql_index[$this->name][$field]='CREATE INDEX `index_'.$this->name.'_'.$field.'` ON '.$this->name.'(`'.$field.'`);';
|
Webmodel::$arr_sql_index[$this->name][$field]='CREATE INDEX `index_'.$this->name.'_'.$field.'` ON '.$this->name.'(`'.$field.'`);';
|
||||||
|
|
@ -1072,7 +1247,7 @@ class Webmodel {
|
||||||
|
|
||||||
//Check if unique
|
//Check if unique
|
||||||
|
|
||||||
if($this->components[$field]->unique==true)
|
if($this->components[$field]->unique==1)
|
||||||
{
|
{
|
||||||
|
|
||||||
Webmodel::$arr_sql_unique[$this->name][$field]=' ALTER TABLE `'.$this->name.'` ADD UNIQUE (`'.$field.'`)';
|
Webmodel::$arr_sql_unique[$this->name][$field]=' ALTER TABLE `'.$this->name.'` ADD UNIQUE (`'.$field.'`)';
|
||||||
|
|
@ -1103,6 +1278,17 @@ class Webmodel {
|
||||||
|
|
||||||
return SQLClass::webtsys_query($sql_query);
|
return SQLClass::webtsys_query($sql_query);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method used for update tables
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function update_table()
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -1198,7 +1384,7 @@ class Webmodel {
|
||||||
if(count($this->forms)==0)
|
if(count($this->forms)==0)
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->create_form();
|
$this->create_forms();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1259,7 +1445,7 @@ class Webmodel {
|
||||||
* @param array $post Is an array with data to update. You have a key that represent the name of field to fill with data, and the value that is the data for fill.
|
* @param array $post Is an array with data to update. You have a key that represent the name of field to fill with data, and the value that is the data for fill.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function check_all($post)
|
public function check_all($post, $safe_query=0)
|
||||||
{
|
{
|
||||||
|
|
||||||
I18n::load_lang('error_model');
|
I18n::load_lang('error_model');
|
||||||
|
|
@ -1283,13 +1469,14 @@ class Webmodel {
|
||||||
|
|
||||||
//Make a foreach inside components, fields that are not found in components, are ignored
|
//Make a foreach inside components, fields that are not found in components, are ignored
|
||||||
|
|
||||||
foreach($this->components as $key => $value)
|
foreach($this->components as $key => $field)
|
||||||
{
|
{
|
||||||
|
|
||||||
//If is set the variable for this component make checking
|
//If is set the variable for this component make checking
|
||||||
|
|
||||||
if(isset($post[$key]))
|
if(isset($post[$key]) && ($field->protected==0 || $safe_query==1))
|
||||||
{
|
{
|
||||||
|
$this->components[$key]->update=$this->update;
|
||||||
|
|
||||||
//Check if the value is valid..
|
//Check if the value is valid..
|
||||||
|
|
||||||
|
|
@ -1339,7 +1526,7 @@ class Webmodel {
|
||||||
|
|
||||||
$this->std_error=implode(', ', $arr_std_error);
|
$this->std_error=implode(', ', $arr_std_error);
|
||||||
|
|
||||||
//If error return false
|
//If error return 0
|
||||||
|
|
||||||
if($set_error>0)
|
if($set_error>0)
|
||||||
{
|
{
|
||||||
|
|
@ -1390,7 +1577,7 @@ class Webmodel {
|
||||||
* @param array $fields_form The values of this array are used for obtain ModelForms from the fields with the same key that array values.
|
* @param array $fields_form The values of this array are used for obtain ModelForms from the fields with the same key that array values.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function create_form($fields_form=array())
|
public function create_forms($fields_form=array())
|
||||||
{
|
{
|
||||||
|
|
||||||
//With function for create form, we use an array for specific order, after i can insert more fields in the form.
|
//With function for create form, we use an array for specific order, after i can insert more fields in the form.
|
||||||
|
|
@ -1406,21 +1593,12 @@ class Webmodel {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//foreach($this->components as $component_name => $component)
|
|
||||||
foreach($fields_form as $component_name)
|
foreach($fields_form as $component_name)
|
||||||
{
|
{
|
||||||
|
|
||||||
if(isset($this->components[$component_name]))
|
if(isset($this->components[$component_name]))
|
||||||
{
|
{
|
||||||
|
|
||||||
$component=&$this->components[$component_name];
|
|
||||||
|
|
||||||
//Create form from model's components
|
|
||||||
|
|
||||||
$this->forms[$component_name]=new ModelForm($this->name, $component_name, $component->form, Webmodel::set_name_default($component_name), $component, $component->required, '');
|
|
||||||
|
|
||||||
$this->forms[$component_name]->set_all_parameters_form($component->get_parameters_default());
|
|
||||||
|
|
||||||
if($this->components[$component_name]->label=='')
|
if($this->components[$component_name]->label=='')
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
@ -1428,27 +1606,58 @@ class Webmodel {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->forms[$component_name]->label=$this->components[$component_name]->label;
|
$this->create_form($component_name);
|
||||||
|
|
||||||
//Set parameters to default
|
|
||||||
//$parameters_value=$this->components[$component_name]->parameters;
|
|
||||||
|
|
||||||
/*if($this->forms[$component_name]->parameters[2]==0)
|
|
||||||
{*/
|
|
||||||
|
|
||||||
//$this->forms[$component_name]->parameters=$this->components[$component_name]->parameters;
|
|
||||||
|
|
||||||
|
|
||||||
//}
|
|
||||||
|
|
||||||
//Use method from ModelForm for set initial parameters...
|
|
||||||
|
|
||||||
//$this->forms[$component_name]->set_parameter_value($parameters_initial_value);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
foreach(array_keys(Webmodel::$form_type) as $type)
|
||||||
|
{
|
||||||
|
$type::js();
|
||||||
|
$type::css();
|
||||||
|
$type::header();
|
||||||
|
|
||||||
|
Webmodel::$form_type_checked[$type]=1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Webmodel::$form_type=array();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method for create a simple form from a field
|
||||||
|
* @param string $component_name The name of the component that is used for create the form
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function create_form($component_name)
|
||||||
|
{
|
||||||
|
|
||||||
|
$component=$this->components[$component_name];
|
||||||
|
|
||||||
|
$form_class=$component->form;
|
||||||
|
|
||||||
|
$this->forms[$component_name]=new $form_class($component_name, $component->value);
|
||||||
|
|
||||||
|
$type_class=get_class($this->forms[$component_name]);
|
||||||
|
|
||||||
|
if(!isset(Webmodel::$form_type_checked[$type_class]))
|
||||||
|
{
|
||||||
|
|
||||||
|
Webmodel::$form_type[$type_class]=1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->forms[$component_name]->default_value=$component->default_value;
|
||||||
|
$this->forms[$component_name]->required=$component->required;
|
||||||
|
$this->forms[$component_name]->label=$component->label;
|
||||||
|
|
||||||
|
$this->components[$component_name]->form_loaded=&$this->forms[$component_name];
|
||||||
|
|
||||||
|
$this->components[$component_name]->get_parameters_default();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -1588,11 +1797,14 @@ class Webmodel {
|
||||||
* @param string $arguments Array with arguments for construct the new field
|
* @param string $arguments Array with arguments for construct the new field
|
||||||
* @param boolean $required A boolean used for set the default required value
|
* @param boolean $required A boolean used for set the default required value
|
||||||
*/
|
*/
|
||||||
public function register($name, $type, $arguments, $required=0)
|
public function register($name, $type_class, $required=0)
|
||||||
{
|
{
|
||||||
|
|
||||||
$rc=new \ReflectionClass($type);
|
/*$rc=new \ReflectionClass($type);
|
||||||
$this->components[$name]=$rc->newInstanceArgs($arguments);
|
$this->components[$name]=$rc->newInstanceArgs($arguments);*/
|
||||||
|
|
||||||
|
$this->components[$name]=&$type_class;
|
||||||
|
|
||||||
//Set first label...
|
//Set first label...
|
||||||
$this->components[$name]->label=Webmodel::set_name_default($name);
|
$this->components[$name]->label=Webmodel::set_name_default($name);
|
||||||
$this->components[$name]->name_model=$this->name;
|
$this->components[$name]->name_model=$this->name;
|
||||||
|
|
@ -1701,4 +1913,15 @@ class Webmodel {
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//A simple shortcut for access to models
|
||||||
|
|
||||||
|
class SuperModel {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Webmodel::$m=new SuperModel();
|
||||||
|
|
||||||
?>
|
?>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue