Can export Websites pages.

Work on export to be able to use the generic declaration of fields.
This commit is contained in:
Laurent Destailleur 2017-07-28 14:54:13 +02:00
parent 8d0f21866c
commit 46586f3055
16 changed files with 157 additions and 50 deletions

View File

@ -0,0 +1,60 @@
<?php
if (empty($keyforclass) || empty($keyforclassfile) || empty($keyforelement))
{
//print $keyforclass.' - '.$keyforclassfile.' - '.$keyforelement;
dol_print_error('', 'include of file commonfieldsinexport.inc.php was done but var $keyforclass or $keyforclassfile or $keyforelement was not set');
exit;
}
dol_include_once($keyforclassfile);
if (class_exists($keyforclass))
{
$tmpobject=new $keyforclass($this->db);
// Add common fields
foreach($tmpobject->fields as $keyfield => $valuefield)
{
$fieldname = 't' . '.' . $keyfield;
$fieldlabel = ucfirst($valuefield['label']);
$typeFilter = "Text";
$typefield=preg_replace('/\(.*$/', '', $valuefield['type']); // double(24,8) -> double
switch ($typefield) {
case 'int':
case 'integer':
case 'double':
case 'price':
$typeFilter = "Numeric";
break;
case 'date':
case 'datetime':
case 'timestamp':
$typeFilter = "Date";
break;
case 'boolean':
$typeFilter = "Boolean";
break;
/*
* case 'sellist':
* $tmp='';
* $tmpparam=unserialize($obj->param); // $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null
* if ($tmpparam['options'] && is_array($tmpparam['options'])) {
* $tmpkeys=array_keys($tmpparam['options']);
* $tmp=array_shift($tmpkeys);
* }
* if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) $typeFilter="List:".$tmp;
* break;
*/
}
if ($valuefield['enabled']) {
$this->export_fields_array[$r][$fieldname] = $fieldlabel;
$this->export_TypeFields_array[$r][$fieldname] = $typeFilter;
$this->export_entities_array[$r][$fieldname] = $keyforelement;
}
}
}
else
{
dol_print_error($this->db, 'Failed to find class '.$keyforclass.', even after the include of '.$keyforclassfile);
}
// End add common fields

View File

@ -18,15 +18,17 @@ if ($resql) // This can fail when class is used on old database (during migra
$fieldname=$keyforaliasextra.'.'.$obj->name;
$fieldlabel=ucfirst($obj->label);
$typeFilter="Text";
switch($obj->type)
{
$typefield=preg_replace('/\(.*$/', '', $obj->type); // double(24,8) -> double
switch ($typefield) {
case 'int':
case 'integer':
case 'double':
case 'price':
$typeFilter="Numeric";
break;
case 'date':
case 'datetime':
case 'timestamp':
$typeFilter="Date";
break;
case 'boolean':

View File

@ -363,10 +363,6 @@ class DolibarrModules // Can not be abstract, because we need to insta
/**
* Constructor. Define names, constants, directories, boxes, permissions
*
@ -381,6 +377,7 @@ class DolibarrModules // Can not be abstract, because we need to insta
// a try catch on Fatal error to manage this correctly.
// We need constructor into function unActivateModule into admin.lib.php
/**
* Enables a module.
* Inserts all informations into database
@ -2161,5 +2158,4 @@ class DolibarrModules // Can not be abstract, because we need to insta
{
return $this->_remove(array(), $options);
}
}

View File

@ -62,7 +62,7 @@ class modStripe extends DolibarrModules
// Name of image file used for this module.
// If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue'
// If file is in module/img directory, use this->picto=DOL_URL_ROOT.'/module/img/file.png'
$this->picto='stripe@stripe';
$this->picto='stripe';
// Data directories to create when module is enabled.
$this->dirs = array();

View File

@ -71,7 +71,7 @@ class modWebsites extends DolibarrModules
$this->depends = array('modFckeditor'); // List of modules id that must be enabled if this module is enabled
$this->requiredby = array(); // List of modules id to disable if this one is disabled
$this->conflictwith = array(); // List of modules id this module is in conflict with
$this->langfiles = array("websites");
$this->langfiles = array("website");
// Constants
//-----------
@ -122,5 +122,22 @@ class modWebsites extends DolibarrModules
'target'=>'',
'user'=>2); // 0=Menu for internal users, 1=external users, 2=both
$r++;
// Exports
$r=1;
$this->export_code[$r]=$this->rights_class.'_'.$r;
$this->export_label[$r]='MyWebsitePages'; // Translation key (used only if key ExportDataset_xxx_z not found)
$this->export_icon[$r]='globe';
$keyforclass = 'WebsitePage'; $keyforclassfile='/websites/class/websitepage.class.php'; $keyforelement='Website';
include DOL_DOCUMENT_ROOT.'/core/commonfieldsinexport.inc.php';
//$keyforselect='myobject'; $keyforelement='myobject'; $keyforaliasextra='extra';
//include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
//$this->export_dependencies_array[$r]=array('mysubobject'=>'ts.rowid', 't.myfield'=>array('t.myfield2','t.myfield3')); // To force to activate one or several fields if we select some fields that need same (like to select a unique key if we ask a field of a child to avoid the DISTINCT to discard them, or for computed field than need several other fields)
$this->export_sql_start[$r]='SELECT DISTINCT ';
$this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'website_page as t, '.MAIN_DB_PREFIX.'website as p';
$this->export_sql_end[$r] .=' WHERE t.fk_website = p.rowid';
$this->export_sql_end[$r] .=' AND p.entity IN ('.getEntity('website').')';
$r++;
}
}

View File

@ -127,20 +127,23 @@ class Export
// Test if permissions are ok
$bool=true;
foreach($module->export_permission[$r] as $val)
if (isset($module->export_permission))
{
$perm=$val;
//print_r("$perm[0]-$perm[1]-$perm[2]<br>");
if (! empty($perm[2]))
{
$bool=$user->rights->{$perm[0]}->{$perm[1]}->{$perm[2]};
}
else
{
$bool=$user->rights->{$perm[0]}->{$perm[1]};
}
if ($perm[0]=='user' && $user->admin) $bool=true;
if (! $bool) break;
foreach($module->export_permission[$r] as $val)
{
$perm=$val;
//print_r("$perm[0]-$perm[1]-$perm[2]<br>");
if (! empty($perm[2]))
{
$bool=$user->rights->{$perm[0]}->{$perm[1]}->{$perm[2]};
}
else
{
$bool=$user->rights->{$perm[0]}->{$perm[1]};
}
if ($perm[0]=='user' && $user->admin) $bool=true;
if (! $bool) break;
}
}
//print $bool." $perm[0]"."<br>";

View File

@ -591,7 +591,7 @@ if ($step == 2 && $datatoexport)
$i++;
$entity=(! empty($objexport->array_export_entities[0][$code])?$objexport->array_export_entities[0][$code]:$objexport->array_export_icon[0]);
$entityicon=(! empty($entitytoicon[$entity])?$entitytoicon[$entity]:$entity);
$entityicon=strtolower(! empty($entitytoicon[$entity])?$entitytoicon[$entity]:$entity);
$entitylang=(! empty($entitytolang[$entity])?$entitytolang[$entity]:$entity);
print '<td class="nowrap">';
@ -783,7 +783,7 @@ if ($step == 3 && $datatoexport)
$i++;
$entity=(! empty($objexport->array_export_entities[0][$code])?$objexport->array_export_entities[0][$code]:$objexport->array_export_icon[0]);
$entityicon=(! empty($entitytoicon[$entity])?$entitytoicon[$entity]:$entity);
$entityicon=strtolower(! empty($entitytoicon[$entity])?$entitytoicon[$entity]:$entity);
$entitylang=(! empty($entitytolang[$entity])?$entitytolang[$entity]:$entity);
print '<td class="nowrap">';
@ -978,7 +978,7 @@ if ($step == 4 && $datatoexport)
print '<tr class="oddeven">';
$entity=(! empty($objexport->array_export_entities[0][$code])?$objexport->array_export_entities[0][$code]:$objexport->array_export_icon[0]);
$entityicon=(! empty($entitytoicon[$entity])?$entitytoicon[$entity]:$entity);
$entityicon=strtolower(! empty($entitytoicon[$entity])?$entitytoicon[$entity]:$entity);
$entitylang=(! empty($entitytolang[$entity])?$entitytolang[$entity]:$entity);
print '<td class="nowrap">';

View File

@ -32,6 +32,11 @@ ALTER TABLE llx_website_page MODIFY COLUMN pageurl varchar(255);
ALTER TABLE llx_website_page ADD COLUMN lang varchar(6);
ALTER TABLE llx_website_page ADD COLUMN fk_page integer;
ALTER TABLE llx_website_page MODIFY COLUMN status INTEGER DEFAULT 1;
UPDATE llx_website_page set status = 1 WHERE status IS NULL;
ALTER TABLE llx_website ADD COLUMN import_key varchar(14);
ALTER TABLE llx_website_page ADD COLUMN import_key varchar(14);
ALTER TABLE llx_fichinter ADD COLUMN import_key varchar(14);
ALTER TABLE llx_livraison ADD COLUMN import_key varchar(14);
ALTER TABLE llx_livraison ADD COLUMN extraparams varchar(255);

View File

@ -29,5 +29,6 @@ CREATE TABLE llx_website
fk_user_create integer,
fk_user_modif integer,
date_creation datetime,
tms timestamp
tms timestamp,
import_key varchar(14) -- import key
) ENGINE=innodb;

View File

@ -28,9 +28,10 @@ CREATE TABLE llx_website_page
lang varchar(6),
fk_page integer,
content mediumtext, -- text is not enough in size
status integer,
status integer DEFAULT 1,
fk_user_create integer,
fk_user_modif integer,
date_creation datetime,
tms timestamp
tms timestamp,
import_key varchar(14) -- import key
) ENGINE=innodb;

View File

@ -40,4 +40,6 @@ ClonePage=Clone page/container
CloneSite=Clone site
ConfirmClonePage=Please enter code/alias of new page and if it is a translation of the cloned page.
PageIsANewTranslation=The new page is a translation of the current page ?
LanguageMustNotBeSameThanClonedPage=You clone a page as a translation. The language of the new page must be different than language of source page.
LanguageMustNotBeSameThanClonedPage=You clone a page as a translation. The language of the new page must be different than language of source page.
ParentPageId=Parent page ID
WebsiteId=Website ID

View File

@ -61,8 +61,7 @@ class MyObject extends CommonObject
/**
* 'type' if the field format, 'label' the translation key, 'enabled' is a condition when the filed must be managed,
* 'visible' says if field is visible in list (-1 means not shown by default but can be aded into list to be viewed)
* 'notnull' if not null in database
* 'index' if we want an index in database
* 'notnull' if not null in database, 'index' if we want an index in database
* 'position' is the sort order of field
* 'searchall' is 1 if we want to search in this field when making a search from the quick search button
* 'isameasure' must be set to 1 if you want to have a total on list for this field. Field type must be summable like integer or double(24,8).
@ -86,7 +85,6 @@ class MyObject extends CommonObject
'fk_user_creat' =>array('type'=>'integer', 'label'=>'UserAuthor', 'enabled'=>1, 'visible'=>-1, 'notnull'=>true, 'position'=>500),
'fk_user_modif' =>array('type'=>'integer', 'label'=>'UserModif', 'enabled'=>1, 'visible'=>-1, 'position'=>500),
//'fk_user_valid' =>array('type'=>'integer', 'label'=>'UserValid', 'enabled'=>1, 'visible'=>-1, 'position'=>500),
'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-1, 'notnull'=>true, 'position'=>500),
'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-1, 'index'=>true, 'position'=>1000, 'nullifempty'=>1),
);
// END MODULEBUILDER PROPERTIES

View File

@ -276,23 +276,23 @@ class modMyModule extends DolibarrModules
// Exports
$r=1;
// Example:
/* BEGIN MODULEBUILDER EXPORT MYOBJECT
/* BEGIN MODULEBUILDER EXPORT MYOBJECT */
/*
$langs->load("mymodule@mymodule");
$this->export_code[$r]=$this->rights_class.'_'.$r;
$this->export_label[$r]='MyModule'; // Translation key (used only if key ExportDataset_xxx_z not found)
$this->export_enabled[$r]='1'; // Condition to show export in list (ie: '$user->id==3'). Set to 1 to always show when module is enabled.
$this->export_icon[$r]='generic:MyModule'; // Put here code of icon then string for translation key of module name
//$this->export_permission[$r]=array(array("mymodule","level1","level2"));
$this->export_fields_array[$r]=array('t.rowid'=>"Id",'t.ref'=>'Ref','t.label'=>'Label','t.datec'=>"DateCreation",'t.tms'=>"DateUpdate");
$this->export_TypeFields_array[$r]=array('t.rowid'=>'Numeric', 't.ref'=>'Text', 't.label'=>'Label', 't.datec'=>"Date", 't.tms'=>"Date");
// $this->export_entities_array[$r]=array('t.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.zip'=>'company','s.town'=>'company','s.fk_pays'=>'company','s.phone'=>'company','s.siren'=>'company','s.siret'=>'company','s.ape'=>'company','s.idprof4'=>'company','s.code_compta'=>'company','s.code_compta_fournisseur'=>'company','f.rowid'=>"invoice",'f.facnumber'=>"invoice",'f.datec'=>"invoice",'f.datef'=>"invoice",'f.total'=>"invoice",'f.total_ttc'=>"invoice",'f.tva'=>"invoice",'f.paye'=>"invoice",'f.fk_statut'=>'invoice','f.note'=>"invoice",'fd.rowid'=>'invoice_line','fd.description'=>"invoice_line",'fd.price'=>"invoice_line",'fd.total_ht'=>"invoice_line",'fd.total_tva'=>"invoice_line",'fd.total_ttc'=>"invoice_line",'fd.tva_tx'=>"invoice_line",'fd.qty'=>"invoice_line",'fd.date_start'=>"invoice_line",'fd.date_end'=>"invoice_line",'fd.fk_product'=>'product','p.ref'=>'product');
// $this->export_dependencies_array[$r]=array('invoice_line'=>'fd.rowid','product'=>'fd.rowid'); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them
// $this->export_sql_start[$r]='SELECT DISTINCT ';
// $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'myobject as t';
// $this->export_sql_order[$r] .=' ORDER BY t.ref';
// $r++;
END MODULEBUILDER EXPORT MYOBJECT */
$this->export_label[$r]='MyObjectLines'; // Translation key (used only if key ExportDataset_xxx_z not found)
$this->export_icon[$r]='myobject@mymodule';
$keyforclass = 'MyObject'; $keyforclassfile='/mymobule/class/myobject.class.php'; $keyforelement='myobject';
include DOL_DOCUMENT_ROOT.'/core/commonfieldsinexport.inc.php';
$keyforselect='myobject'; $keyforaliasextra='extra'; $keyforelement='myobject';
include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
//$this->export_dependencies_array[$r]=array('mysubobject'=>'ts.rowid', 't.myfield'=>array('t.myfield2','t.myfield3')); // To force to activate one or several fields if we select some fields that need same (like to select a unique key if we ask a field of a child to avoid the DISTINCT to discard them, or for computed field than need several other fields)
$this->export_sql_start[$r]='SELECT DISTINCT ';
$this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'myobject as t';
$this->export_sql_end[$r] .=' WHERE 1 = 1';
$this->export_sql_end[$r] .=' AND t.entity IN ('.getEntity('myobject').')';
$r++; */
/* END MODULEBUILDER EXPORT MYOBJECT */
}
/**

Binary file not shown.

After

Width:  |  Height:  |  Size: 366 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 305 B

View File

@ -58,8 +58,30 @@ class WebsitePage extends CommonObject
public $date_creation;
public $date_modification;
// BEGIN MODULEBUILDER PROPERTIES
/**
*/
* @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
*/
public $fields=array(
'rowid' =>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-1, 'notnull'=>true, 'index'=>true, 'position'=>1, 'comment'=>'Id'),
'pageurl' =>array('type'=>'varchar(16)', 'label'=>'WEBSITE_PAGENAME', 'enabled'=>1, 'visible'=>1, 'notnull'=>true, 'index'=>true, 'position'=>10, 'searchall'=>1, 'comment'=>'Alias of page'),
'title' =>array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>1, 'visible'=>1, 'position'=>30, 'searchall'=>1),
'description' =>array('type'=>'varchar(255)', 'label'=>'Description', 'enabled'=>1, 'visible'=>1, 'position'=>30, 'searchall'=>1),
'keywords' =>array('type'=>'varchar(255)', 'label'=>'Keywords', 'enabled'=>1, 'visible'=>1, 'position'=>45, 'searchall'=>0),
'content' =>array('type'=>'mediumtext', 'label'=>'Content', 'enabled'=>1, 'visible'=>1, 'position'=>45, 'searchall'=>0),
'lang' =>array('type'=>'varchar(6)', 'label'=>'Lang', 'enabled'=>1, 'visible'=>1, 'position'=>45, 'searchall'=>0),
//'status' =>array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'index'=>true, 'position'=>1000),
'fk_website' =>array('type'=>'integer', 'label'=>'WebsiteId', 'enabled'=>1, 'visible'=>1, 'position'=>40, 'searchall'=>0),
'fk_page' =>array('type'=>'integer', 'label'=>'ParentPageId', 'enabled'=>1, 'visible'=>1, 'position'=>45, 'searchall'=>0),
'date_creation' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-1, 'notnull'=>true, 'position'=>500),
'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-1, 'notnull'=>true, 'position'=>500),
//'date_valid' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-1, 'position'=>500),
//'fk_user_creat' =>array('type'=>'integer', 'label'=>'UserAuthor', 'enabled'=>1, 'visible'=>-1, 'notnull'=>true, 'position'=>500),
//'fk_user_modif' =>array('type'=>'integer', 'label'=>'UserModif', 'enabled'=>1, 'visible'=>-1, 'position'=>500),
//'fk_user_valid' =>array('type'=>'integer', 'label'=>'UserValid', 'enabled'=>1, 'visible'=>-1, 'position'=>500),
'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-1, 'index'=>true, 'position'=>1000, 'nullifempty'=>1),
);
// END MODULEBUILDER PROPERTIES
/**
@ -142,7 +164,7 @@ class WebsitePage extends CommonObject
$sql .= ' '.(! isset($this->lang)?'NULL':"'".$this->db->escape($this->lang)."'").',';
$sql .= ' '.(empty($this->fk_page)?'NULL':$this->db->escape($this->fk_page)).',';
$sql .= ' '.(! isset($this->status)?'NULL':$this->status).',';
$sql .= ' '.(! isset($this->date_creation) || dol_strlen($this->date_creation)==0?'NULL':"'".$this->db->idate($this->date_creation)."'").',';
$sql .= ' '.(! isset($this->date_creation) || dol_strlen($this->date_creation)==0?"'".$this->db->idate($now)."'":"'".$this->db->idate($this->date_creation)."'").',';
$sql .= ' '.(! isset($this->date_modification) || dol_strlen($this->date_modification)==0?'NULL':"'".$this->db->idate($this->date_modification)."'");
$sql .= ')';