From efc22a4cd8b8dc4b6ea9c6be07c37eba0466def6 Mon Sep 17 00:00:00 2001 From: Alexis Algoud Date: Tue, 13 Dec 2016 09:49:59 +0100 Subject: [PATCH] include default list conception --- htdocs/core/class/coreobject.class.php | 7 +- htdocs/core/class/listview.class.php | 159 +++++++++++++-------- htdocs/inventory/class/inventory.class.php | 11 +- 3 files changed, 113 insertions(+), 64 deletions(-) diff --git a/htdocs/core/class/coreobject.class.php b/htdocs/core/class/coreobject.class.php index dc52fdd9bf5..96cbbb89a88 100644 --- a/htdocs/core/class/coreobject.class.php +++ b/htdocs/core/class/coreobject.class.php @@ -27,6 +27,8 @@ class CoreObject extends CommonObject { public $db; + public $withChild = true; + protected $__fields=array(); /** * Constructor @@ -216,7 +218,7 @@ class CoreObject extends CommonObject { $sql = 'SELECT '.$this->get_field_list().',datec,tms FROM '.MAIN_DB_PREFIX.$this->table_element.' WHERE rowid='.$id; - var_dump($sql); + $res = $this->db->query( $sql ); if($obj = $this->db->fetch_object($res)) { @@ -238,8 +240,8 @@ class CoreObject extends CommonObject { } public function fetchChild() { - if($this->withChild && !empty($this->childtables) && !empty($this->fk_element)) { + if($this->withChild && !empty($this->childtables) && !empty($this->fk_element)) { foreach($this->childtables as &$childTable) { $className = ucfirst($childTable); @@ -248,6 +250,7 @@ class CoreObject extends CommonObject { $sql = " SELECT rowid FROM ".MAIN_DB_PREFIX.$childTable." WHERE ".$this->fk_element."=".$this->rowid; $res = $this->db->query($sql); + if($res) { while($obj = $db->fetch_object($res)) { diff --git a/htdocs/core/class/listview.class.php b/htdocs/core/class/listview.class.php index 8df337b699c..db66f9f15a3 100644 --- a/htdocs/core/class/listview.class.php +++ b/htdocs/core/class/listview.class.php @@ -41,33 +41,30 @@ class Listview { if(!isset($TParam['orderby']['noOrder']))$TParam['orderby']['noOrder']=array(); if(!isset($TParam['no-select'])) $TParam['no-select'] = 1; - if(!isset($TParam['liste']))$TParam['liste']=array(); - $TParam['liste'] = array_merge(array( - 'messageNothing'=>"Il n'y a aucun élément à afficher." - ,'picto_precedent'=>'<' - ,'picto_suivant'=>'>' - ,'order_down'=>img_down() - ,'order_up'=>img_up() + if(!isset($TParam['list']))$TParam['list']=array(); + $TParam['list'] = array_merge(array( + 'messageNothing'=>$langs->trans('ListMessageNothingToShow') ,'noheader'=>0 ,'useBottomPagination'=>0 ,'image'=>'' - ,'titre'=>'Liste' + ,'title'=>$langs->trans('List') ,'orderDown'=>'' ,'orderUp'=>'' ,'id'=>$this->id - ,'picto_search'=>img_picto('Search', 'search.png') ,'head_search'=>'' ,'export'=>array() - ,'view_type'=>'' - ),$TParam['liste']); + ,'view_type'=>'' //TODO to include graph or kanban instead of list + ),$TParam['list']); + + $POSTList = GETPOST('Listview'); if(empty($TParam['limit']))$TParam['limit']=array(); - if(!empty($_REQUEST['TListTBS'][$this->id]['page'])) $TParam['limit']['page'] = $_REQUEST['TListTBS'][$this->id]['page']; + if(!empty($POSTList[$this->id]['page'])) $TParam['limit']['page'] = $POSTList[$this->id]['page']; $TParam['limit']=array_merge(array('page'=>1, 'nbLine'=>$conf->liste_limit, 'global'=>0), $TParam['limit']); - if(!empty($_REQUEST['TListTBS'][$this->id]['orderBy'])) { - $TParam['orderBy'] = $_REQUEST['TListTBS'][$this->id]['orderBy']; + if(!empty($POSTList[$this->id]['orderBy'])) { + $TParam['orderBy'] = $POSTList[$this->id]['orderBy']; } // print_r($TParam); @@ -124,9 +121,9 @@ class Listview { // Si le type de "recherche" est "calendars" on a 2 champs de transmis, [début et fin] ou [que début] ou [que fin] => un BETWEEN Sql serait utile que dans le 1er cas // donc l'utilisation des opérateur >= et <= permettent un fonctionnement générique $TSQLDate=array(); - if(!empty($value['deb'])) + if(!empty($value['start'])) { - $valueDeb = $this->dateToSQLDate($value['deb']); + $valueDeb = $this->dateToSQLDate($value['start']); if(isset($this->TBind[$sBindKey.'_start'])) // TODO can't use this in query case { @@ -137,9 +134,9 @@ class Listview { } - if(!empty($value['fin'])) + if(!empty($value['end'])) { - $valueFin = $this->dateToSQLDate($value['fin']); + $valueFin = $this->dateToSQLDate($value['end']); if(isset($this->TBind[$sBindKey.'_end'])) { // TODO can't use this in query case $this->TBind[$sBindKey.'_end'] = $valueFin; } @@ -198,7 +195,7 @@ class Listview { private function search($sql,&$TParam) { - if(!empty($_REQUEST['TListTBS'][$this->id]['search'])) { + if(!empty($_REQUEST['Listview'][$this->id]['search'])) { $sqlGROUPBY=''; if(strpos($sql,'GROUP BY')!==false) { //TODO regex list($sql, $sqlGROUPBY) = explode('GROUP BY', $sql); @@ -206,7 +203,7 @@ class Listview { if(strpos($sql,'WHERE ')===false)$sql.=' WHERE 1 '; //TODO regex - foreach($_REQUEST['TListTBS'][$this->id]['search'] as $key=>$value) + foreach($_REQUEST['Listview'][$this->id]['search'] as $key=>$value) { $TsKey = $this->getSearchKey($key, $TParam); $TsBindKey = $this->getTsBindKey($TsKey); @@ -222,7 +219,7 @@ class Listview { //if (!empty($value)) var_dump($sKey); $sBindKey = $TsBindKey[$i]; - if($allow_is_null && !empty($_REQUEST['TListTBS'][$this->id]['search_on_null'][$key])) + if($allow_is_null && !empty($_REQUEST['Listview'][$this->id]['search_on_null'][$key])) { $this->TBind[$sBindKey.'_null'] = $sKey.' IS NULL '; $TSQLMore[] = $sKey.' IS NULL '; @@ -302,31 +299,31 @@ class Listview { foreach($TParam['search'] as $key=>$param_search) { - $value = isset($_REQUEST['TListTBS'][$this->id]['search'][$key]) ? $_REQUEST['TListTBS'][$this->id]['search'][$key] : ''; + $value = isset($_REQUEST['Listview'][$this->id]['search'][$key]) ? $_REQUEST['Listview'][$this->id]['search'][$key] : ''; $typeRecherche = (is_array($param_search) && isset($param_search['recherche'])) ? $param_search['recherche'] : $param_search; if(is_array($typeRecherche)) { $typeRecherche = array(''=>' ') + $typeRecherche; - $fsearch=$form->combo('','TListTBS['.$this->id.'][search]['.$key.']', $typeRecherche,$value,0,'',' listviewtbs="combo" init-value="'.$value.'" '); + $fsearch=$form->combo('','Listview['.$this->id.'][search]['.$key.']', $typeRecherche,$value,0,'',' listviewtbs="combo" init-value="'.$value.'" '); } else if($typeRecherche==='calendar') { - $fsearch=$form->calendrier('','TListTBS['.$this->id.'][search]['.$key.']',$value,10,10,' listviewtbs="calendar" '); + $fsearch=$form->calendrier('','Listview['.$this->id.'][search]['.$key.']',$value,10,10,' listviewtbs="calendar" '); } else if($typeRecherche==='calendars') { - $fsearch=$form->calendrier('','TListTBS['.$this->id.'][search]['.$key.'][deb]',isset($value['deb'])?$value['deb']:'',10,10,' listviewtbs="calendars" ') - .' '.$form->calendrier('','TListTBS['.$this->id.'][search]['.$key.'][fin]',isset($value['fin'])?$value['fin']:'',10,10,' listviewtbs="calendars" '); + $fsearch=$form->calendrier('','Listview['.$this->id.'][search]['.$key.'][start]',isset($value['start'])?$value['start']:'',10,10,' listviewtbs="calendars" ') + .' '.$form->calendrier('','Listview['.$this->id.'][search]['.$key.'][end]',isset($value['end'])?$value['end']:'',10,10,' listviewtbs="calendars" '); } else if(is_string($typeRecherche)) { $fsearch=$TParam['search'][$key]; } else { - $fsearch=$form->texte('','TListTBS['.$this->id.'][search]['.$key.']',$value,15,255,' listviewtbs="input" '); + $fsearch=$form->texte('','Listview['.$this->id.'][search]['.$key.']',$value,15,255,' listviewtbs="input" '); } if(!empty($param_search['allow_is_null'])) { - $valueNull = isset($_REQUEST['TListTBS'][$this->id]['search_on_null'][$key]) ? 1 : 0; - $fsearch.=' '.$form->checkbox1('', 'TListTBS['.$this->id.'][search_on_null]['.$key.']',1, $valueNull,' onclick=" if($(this).is(\':checked\')){ $(this).prev().val(\'\'); }" ').img_help(1, $langs->trans('SearchOnNUllValue')); + $valueNull = isset($_REQUEST['Listview'][$this->id]['search_on_null'][$key]) ? 1 : 0; + $fsearch.=' '.$form->checkbox1('', 'Listview['.$this->id.'][search_on_null]['.$key.']',1, $valueNull,' onclick=" if($(this).is(\':checked\')){ $(this).prev().val(\'\'); }" ').img_help(1, $langs->trans('SearchOnNUllValue')); } @@ -342,7 +339,7 @@ class Listview { } - $search_button = ' '.$TParam['liste']['picto_search'].''; + $search_button = ' '.$TParam['liste']['picto_search'].''; if(!empty($TParam['liste']['head_search'])) { $TParam['liste']['head_search'].='
'.$langs->trans('Search').' '.$search_button.'
'; @@ -519,22 +516,77 @@ class Listview { $TExport=$this->setExport($TParam, $TField, $THeader); $TField = $this->addTotalGroup($TField,$TTotalGroup); - var_dump( - array( - 'entete'=>$THeader - ,'champs'=>$TField - ,'recherche'=>$TSearch - ,'total'=>$TTotal - ,'export'=>$TExport - ) - , array( - 'liste'=>array_merge(array('haveExport'=>count($TExport), 'id'=>$this->id, 'nb_columns'=>count($THeader) ,'totalNB'=>count($TField), 'nbSearch'=>count($TSearch), 'haveTotal'=>(int)!empty($TTotal), 'havePage'=>(int)!empty($TPagination) ), $TParam['liste']) - ) - , $TPagination - - ); + $out = $javaScript; - $javaScript; + $out.=load_fiche_titre($TParam['list']['title']); + print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, count($TField), 'title_products.png', 0, '', '', $limit); + /* + $out.=' + + [onshow;block=begin; when [liste.noheader]==0] + + + [onshow;block=end] + + +
+ [liste.image;magnet=img; strconv=no] +
[liste.titre; strconv=no]
+ +
+ + + + + + + + + + + [onshow;block=tr;when [liste.nbSearch]+-0] + + + + + + + + + + + + + + + + + [onshow;block=tr; when [liste.haveTotal]+-0 ] + + + + +
[liste.head_search;strconv=no;magnet=tr]
[entete.libelle;block=th;strconv=no] + [onshow;block=span; when [entete.order]==1][liste.order_down;strconv=no][liste.order_up;strconv=no] + [entete.more;strconv=no;] +
[recherche.val;block=td;strconv=no]
[champs_sub1.val;block=td; strconv=no]
[champs_sub1.val;block=td; strconv=no]
[total.val;block=td;strconv=no;frm=0 000,00]
+ +
+ [onshow;block=div; when [liste.haveExport]+-0 ] + [export.label;block=a;] +
+

+ [liste.messageNothing;strconv=no] [onshow; block=p; when [liste.totalNB]==0] +

';*/ } public function renderArray(&$db,$TField, $TParam=array()) { @@ -611,14 +663,14 @@ class Listview { global $user; $contextpage=md5($_SERVER['PHP_SELF']); - if((float)DOL_VERSION>=4.0 && empty($TParam['no-select'])) { + if(empty($TParam['no-select'])) { dol_include_once('/core/class/html.form.class.php'); global $db,$conf,$user; $form=new Form($db); - $selectedfields = GETPOST('TListTBS_'.$this->id.'_selectedfields'); + $selectedfields = GETPOST('Listview'.$this->id.'_selectedfields'); if(!empty($selectedfields)) { include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; @@ -662,7 +714,7 @@ class Listview { } } - $selectedfields=$form->multiSelectArrayWithCheckbox('TListTBS_'.$this->id.'_selectedfields', $TFieldVisibility, $contextpage); // This also change content of $arrayfields_0 + $selectedfields=$form->multiSelectArrayWithCheckbox('Listview'.$this->id.'_selectedfields', $TFieldVisibility, $contextpage); // This also change content of $arrayfields_0 } @@ -721,17 +773,6 @@ class Listview { else $value=(string)$value; } - if(isset($TParam['subQuery'][$field])) { - $dbSub = new TPDOdb; //TODO finish it - $dbSub->Execute( strtr($TParam['subQuery'][$field], array_merge( $trans, array('@val@'=>$value) )) ); - $subResult = ''; - while($dbSub->Get_line()) { - $subResult.= implode(', ',$dbSub->currentLine).'
'; - } - $value=$subResult; - $dbSub->close(); - } - $trans['@'.$field.'@'] = $value; if(!empty($TParam['math'][$field])) { diff --git a/htdocs/inventory/class/inventory.class.php b/htdocs/inventory/class/inventory.class.php index d092a876ad2..59ad70cec4e 100644 --- a/htdocs/inventory/class/inventory.class.php +++ b/htdocs/inventory/class/inventory.class.php @@ -87,7 +87,8 @@ class Inventory extends CoreObject function sort_det() { - usort($this->Inventorydet, array('Inventory', 'customSort')); + + if(!empty($this->Inventorydet)) usort($this->Inventorydet, array('Inventory', 'customSort')); } function fetch($id,$annexe = true) @@ -99,8 +100,12 @@ class Inventory extends CoreObject $this->sort_det(); $this->amount = 0; - foreach($this->Inventorydet as &$det){ - $this->amount+=$det->qty_view * $det->pmp; + + if(!empty($this->Inventorydet )) { + foreach($this->Inventorydet as &$det){ + $this->amount+=$det->qty_view * $det->pmp; + } + } return $res;