From efb394d430059e53dd715a7f275228f39f7d26a8 Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Tue, 17 Dec 2019 12:24:55 +0000 Subject: [PATCH] wip #3270 @6 --- inc/ws/Controlleur/class.ws.ajax.php | 32 ++ inc/ws/Controlleur/class.ws.url.php | 26 +- inc/ws/Metier/class.ws.parametres.php | 536 ++++++++++++++------------ inc/ws/Util/class.ws.util.php | 3 +- 4 files changed, 338 insertions(+), 259 deletions(-) diff --git a/inc/ws/Controlleur/class.ws.ajax.php b/inc/ws/Controlleur/class.ws.ajax.php index 15e5d2709..33442d1ea 100644 --- a/inc/ws/Controlleur/class.ws.ajax.php +++ b/inc/ws/Controlleur/class.ws.ajax.php @@ -1312,4 +1312,36 @@ class wsAjax extends cubeAjax self::cleanCachesCollection($id); } + + public static function importFluidbookSettings($args, &$x) + { + global $core; + $dao = new wsDAOBook($core->con); + + new PHPExcel(); + + $reader = new PHPExcel_Reader_Excel2007(); + $xls = $reader->load($_FILES['file']['tmp_name']); + + $ignore = wsUrl::getReadonlySettings(); + + $sheet = $xls->getActiveSheet()->toArray(); + $nlines = count($sheet); + for ($i = 1; $i < $nlines; $i++) { + $line = $sheet[$i]; + $id = (int)$line[0]; + if (!$id) { + continue; + } + $settings = []; + foreach ($line as $k => $v) { + $col = $sheet[0][$k]; + if (in_array($col, $ignore, true)) { + continue; + } + $settings[$col] = $v; + } + $dao->setSettings($id, $settings); + } + } } \ No newline at end of file diff --git a/inc/ws/Controlleur/class.ws.url.php b/inc/ws/Controlleur/class.ws.url.php index 57ff35370..d60aded3b 100644 --- a/inc/ws/Controlleur/class.ws.url.php +++ b/inc/ws/Controlleur/class.ws.url.php @@ -2207,6 +2207,16 @@ html.tall{height:150%}' . "\n"; header('Location: https://www.orpi.com/'); } + public static function getAdditionalSettingsMap(): array + { + return ['book_id' => 'book_id', 'lang' => 'lang', 'theme' => 'theme', 'status' => 'status', 'proprietaire_id' => 'owner', 'date' => 'date', 'changedate' => 'changedate', 'hosting' => 'hosting', 'exportdatas' => 'exportdata']; + } + + public static function getReadonlySettings() + { + return ['book_id', 'date', 'changedate', 'hosting', 'exportdatas']; + } + public static function exportPublicationSettings($args) { global $core; @@ -2221,23 +2231,15 @@ html.tall{height:150%}' . "\n"; $xls = new PHPExcel(); $sheet = $xls->getActiveSheet(); $sheet->freezePane('B2'); - $standardSettings = ['book_id' => 'book_id', 'lang' => 'lang', 'theme' => 'theme', 'status' => 'status', 'proprietaire_id' => 'owner', 'date' => 'date', 'changedate' => 'changedate', 'hosting' => 'hosting', 'exportdatas' => 'exportdata']; + $standardSettings = self::getAdditionalSettingsMap(); + $readonlyList = self::getReadonlySettings(); $j = 0; foreach ($standardSettings as $column => $label) { - $readonly = false; - if ($label === 'exportdata') { - $readonly = true; - } else { + if ($label !== 'exportdata') { $sheet->getColumnDimensionByColumn($j)->setAutoSize(true); } - if ($label === 'hosting') { - $readonly = true; - } - if (strpos($column, 'date') !== false) { - $readonly = true; - } - if ($readonly) { + if (in_array($column, $readonlyList, true)) { self::_readonlyStyle($sheet->getStyle(PHPExcel_Cell::stringFromColumnIndex($j))); } $sheet->setCellValueByColumnAndRow($j, 1, $label); diff --git a/inc/ws/Metier/class.ws.parametres.php b/inc/ws/Metier/class.ws.parametres.php index 416703605..f4ffd94e5 100644 --- a/inc/ws/Metier/class.ws.parametres.php +++ b/inc/ws/Metier/class.ws.parametres.php @@ -1,251 +1,295 @@ parent = $parent; - $this->initFields(); - $this->datas = array(); - $this->setDefaultValues(); - } - - public function isEmpty() { - return count($this->datas) == 0; - } - - public function setParent($parent) { - $this->parent = $parent; - $this->initFields(); - } - - public function __set($varname, $value) { - if (empty($varname)) { - return; - } - $this->set($varname, $value); - } - - public function __unset($varname) { - $this->set($varname, null); - } - - public function __get($varname) { - return $this->get($varname); - } - - public function __isset($varname) { - return $this->_isset($varname); - } - - public function __sleep() { - return array('datas'); - } - - public function __wakeup() { - $this->initFields(); - } - - // Iterator functions - public function rewind() { - reset($this->fields); - } - - public function current() { - return $this->get($this->key()); - } - - public function key() { - return key($this->fields); - } - - public function next() { - return next($this->fields); - } - - public function valid() { - return $this->_isset($this->key()); - } - - protected function initFields() { - $this->fields = array(); - $this->forms = array(); - } - - protected function setDefaultValues() { - foreach ($this->fields as $k => $f) { - if (isset($f["default"])) { - $this->set($k, $f['default']); - } - } - } - - protected function set($varname, $value) { - if (!$this->_isset($varname)) { - throw new Exception('You are setting an attribute (' . get_class($this) . '::' . $varname . ') which not exists'); - } - - if (is_null($value)) { - $this->datas[$varname] = null; - return; - } - - switch ($this->fields[$varname]['type']) { - case 'integer': - if (!is_int($value)) { - $value = intval($value); - } - break; - case 'float': - if (!is_float($value)) { - $value = floatval($value); - } - break; - case 'boolean': - if (!is_bool($value)) { - $value = ($value == '' || $value == '0' || $value == 'false') ? false : true; - } - break; - case 'color': - case 'couleur': - $value = cubeMath::fill(ltrim($value, '#'), 6); - break; - case 'couleurAlpha': - $value = cubeMath::fill(ltrim($value, '#'), 6); - $value = cubeMath::fill($value, 8, 'f'); - break; - case 'date': - if (!is_int($value)) { - $value = intval($value); - } - break; - case 'file': - $e = explode('/', $value); - $value = array_pop($e); - break; - default: - $value = (string)$value; - break; - } // switch - $this->datas[$varname] = $value; - } - - protected function _isset($varname) { - return isset($this->fields[$varname]) && isset($this->fields[$varname]['default']); - } - - protected function get($varname) { - if (is_null($varname)) { - return false; - } - if (!$this->_isset($varname)) { - throw new Exception('You are getting an attribute (' . get_class($this) . '::' . $varname . ') which not exists'); - } - if (!isset($this->datas[$varname]) || is_null($this->datas[$varname])) { - return $this->getDefault($varname); - } - return $this->datas[$varname]; - } - - protected function getDefault($varname) { - if (substr($this->fields[$varname]['default'], 0, 1) == '$') { - return $this->get(substr($this->fields[$varname]['default'], 1)); - } else { - return $this->fields[$varname]['default']; - } - } - - public function getForm($name,$ignoreMeta=false) { - $f = $this->forms[$name]; - $f['fields'] = array(); - foreach ($f['fieldsnames'] as $n) { - if ($n == '|') { - if($ignoreMeta){ - continue; +class wsParametres extends cubeMetier implements Iterator +{ + + protected $datas; + protected $fields; + protected $forms; + protected $parent; + + // Magic functions + public function __construct($parent) + { + $this->parent = $parent; + $this->initFields(); + $this->datas = array(); + $this->setDefaultValues(); + } + + public function isEmpty() + { + return count($this->datas) == 0; + } + + public function setParent($parent) + { + $this->parent = $parent; + $this->initFields(); + } + + public function __set($varname, $value) + { + if (empty($varname)) { + return; + } + $this->set($varname, $value); + } + + public function __unset($varname) + { + $this->set($varname, null); + } + + public function __get($varname) + { + return $this->get($varname); + } + + public function __isset($varname) + { + return $this->_isset($varname); + } + + public function __sleep() + { + return array('datas'); + } + + public function __wakeup() + { + $this->initFields(); + } + + // Iterator functions + public function rewind() + { + reset($this->fields); + } + + public function current() + { + return $this->get($this->key()); + } + + public function key() + { + return key($this->fields); + } + + public function next() + { + return next($this->fields); + } + + public function valid() + { + return $this->_isset($this->key()); + } + + protected function initFields() + { + $this->fields = array(); + $this->forms = array(); + } + + protected function setDefaultValues() + { + foreach ($this->fields as $k => $f) { + if (isset($f["default"])) { + $this->set($k, $f['default']); + } + } + } + + protected function set($varname, $value) + { + if (!$this->_isset($varname)) { + throw new Exception('You are setting an attribute (' . get_class($this) . '::' . $varname . ') which not exists'); + } + + if (is_null($value)) { + $this->datas[$varname] = null; + return; + } + + switch ($this->fields[$varname]['type']) { + case 'integer': + if (!is_int($value)) { + $value = intval($value); } - $f['fields'][] = '|'; - } else { - $f['fields'][$n] = $this->fields[$n]; - $f['fields'][$n]['value'] = $this->get($n); - } - } - return $f; - } - - public function getForms() { - return array_keys($this->forms); - } - - public function fromRecord($r) { - $c = array_flip($r->columns()); - foreach ($this->fields as $n => $f) { - if (isset($c[$n]) && !is_null($r->$n)) { - $this->set($n, $r->$n); - } - } - } - - public function fromXML($xml) { - foreach ($this->fields as $n => $f) { - $xp = $xml->$n; - if (!$xp || !count($xp)) { - continue; - } - foreach ($xp as $x) { - $this->set($n, $x); - } - } - } - - public function toStandardObject() { - $res = new stdClass(); - foreach ($this as $k => $v) { - $res->$k = $v; - } - return $res; - } - - public function getHelp() { - $rubriques = array(); - foreach ($this->forms as $name => $form) { - $rub = array(); - foreach ($form['fieldsnames'] as $f) { - if ($f == '|') { - $rub[] = '|'; - } else { - - $d = self::formatValueForHelp($this->getDefault($f)); - $v = self::formatValueForHelp($this->get($f)); - if ($d != $v) { - $v = '' . $v . ''; - } - - - $field = $this->fields[$f]; - $t = array(); - $t[] = $f; - $t[] = $field['type']; - $t[] = $field['label']; - $t[] = $d; - $t[] = $v; - $rub[$f] = $t; - } - } - $rubriques[$form['label']] = $rub; - } - return $rubriques; - } - - public static function formatValueForHelp($v) { - if (is_bool($v)) { - $v = ($v) ? 'true' : 'false'; - } - return $v; - } + break; + case 'float': + if (!is_float($value)) { + $value = floatval($value); + } + break; + case 'boolean': + if ($value === 'TRUE') { + $value = true; + } + if ($value === 'FALSE') { + return false; + } + if (!is_bool($value)) { + $value = !($value == '' || $value == '0' || $value === 'false'); + } + $value = (bool)$value; + break; + case 'color': + case 'couleur': + $value = cubeMath::fill(ltrim($value, '#'), 6); + break; + case 'couleurAlpha': + $value = cubeMath::fill(ltrim($value, '#'), 6); + $value = cubeMath::fill($value, 8, 'f'); + break; + case 'date': + if (!is_int($value)) { + $value = intval($value); + } + break; + case 'file': + $e = explode('/', $value); + $value = array_pop($e); + break; + default: + $value = (string)$value; + break; + } // switch + $this->datas[$varname] = $value; + } + + protected function _isset($varname) + { + return isset($this->fields[$varname]) && isset($this->fields[$varname]['default']); + } + + protected function get($varname) + { + if (is_null($varname)) { + return false; + } + if (!$this->_isset($varname)) { + throw new Exception('You are getting an attribute (' . get_class($this) . '::' . $varname . ') which not exists'); + } + if (!isset($this->datas[$varname]) || is_null($this->datas[$varname])) { + return $this->getDefault($varname); + } + return $this->datas[$varname]; + } + + protected function getDefault($varname) + { + if (substr($this->fields[$varname]['default'], 0, 1) == '$') { + return $this->get(substr($this->fields[$varname]['default'], 1)); + } else { + return $this->fields[$varname]['default']; + } + } + + public function getForm($name, $ignoreMeta = false) + { + $f = $this->forms[$name]; + $f['fields'] = array(); + foreach ($f['fieldsnames'] as $n) { + if ($n == '|') { + if ($ignoreMeta) { + continue; + } + $f['fields'][] = '|'; + } else { + $f['fields'][$n] = $this->fields[$n]; + $f['fields'][$n]['value'] = $this->get($n); + } + } + return $f; + } + + public function getForms() + { + return array_keys($this->forms); + } + + public function fromRecord($r) + { + $c = array_flip($r->columns()); + foreach ($this->fields as $n => $f) { + if (isset($c[$n]) && !is_null($r->$n)) { + $this->set($n, $r->$n); + } + } + } + + public function fromXML($xml) + { + foreach ($this->fields as $n => $f) { + $xp = $xml->$n; + if (!$xp || !count($xp)) { + continue; + } + foreach ($xp as $x) { + $this->set($n, $x); + } + } + } + + public function toStandardObject() + { + $res = new stdClass(); + foreach ($this as $k => $v) { + $res->$k = $v; + } + return $res; + } + + public function toArray() + { + $res = []; + foreach ($this as $k => $v) { + $res[$k]=$v; + } + return $res; + } + + public function getHelp() + { + $rubriques = array(); + foreach ($this->forms as $name => $form) { + $rub = array(); + foreach ($form['fieldsnames'] as $f) { + if ($f == '|') { + $rub[] = '|'; + } else { + + $d = self::formatValueForHelp($this->getDefault($f)); + $v = self::formatValueForHelp($this->get($f)); + if ($d != $v) { + $v = '' . $v . ''; + } + + + $field = $this->fields[$f]; + $t = array(); + $t[] = $f; + $t[] = $field['type']; + $t[] = $field['label']; + $t[] = $d; + $t[] = $v; + $rub[$f] = $t; + } + } + $rubriques[$form['label']] = $rub; + } + return $rubriques; + } + + public static function formatValueForHelp($v) + { + if (is_bool($v)) { + $v = ($v) ? 'true' : 'false'; + } + return $v; + } } \ No newline at end of file diff --git a/inc/ws/Util/class.ws.util.php b/inc/ws/Util/class.ws.util.php index 4510ce25e..073fbf145 100644 --- a/inc/ws/Util/class.ws.util.php +++ b/inc/ws/Util/class.ws.util.php @@ -103,7 +103,8 @@ class wsUtil } $colslabels[$j] = $collabel; } - for ($i = 1; $i < count($s); $i++) { + $cs = count($s); + for ($i = 1; $i < $cs; $i++) { $r = []; foreach ($colslabels as $j => $collabel) { $r[$collabel] = $s[$i][$j]; -- 2.39.5