From af2805f72b51868961b5b998ddff73b0cf7efd21 Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Thu, 20 Feb 2020 18:25:39 +0000 Subject: [PATCH] wip #3375 @3 --- framework/application/configs/application.ini | 2 +- framework/application/models/Reference.php | 246 +++++++++--------- 2 files changed, 131 insertions(+), 117 deletions(-) diff --git a/framework/application/configs/application.ini b/framework/application/configs/application.ini index 1bcb6e0..18a7940 100644 --- a/framework/application/configs/application.ini +++ b/framework/application/configs/application.ini @@ -1,5 +1,5 @@ [production] -dev = false +dev = true firephp = true minify.js = true diff --git a/framework/application/models/Reference.php b/framework/application/models/Reference.php index 24a43a5..e372a85 100644 --- a/framework/application/models/Reference.php +++ b/framework/application/models/Reference.php @@ -1,120 +1,134 @@ 'list', 'featured_categories' => 'list', 'title' => 'json', 'text' => 'json', 'image' => 'json', 'homeimage' => 'json', 'fluidbook_id' => 'json', 'fluidbook_page' => 'json'); - - public static function getSchema($schema) { - $table = parent::getSchema($schema); - $table->addColumn('title', 'text'); - $table->addColumn('text', 'text'); - $table->addColumn('url', 'text'); - $table->addColumn('date', 'date'); - $table->addColumn('fluidbook_id', 'text'); - $table->addColumn('fluidbook_page', 'string', array("default" => '{"fr":2,"en":0}', "length" => 128)); - $table->addColumn('featured', 'boolean'); - $table->addColumn('image', 'string', array('length' => 64)); - $table->addColumn('homeimage', 'string', array('length' => 64)); - $table->addColumn('categories', 'string', array('length' => 64)); - $table->addColumn('featured_categories', 'string', array('length' => 64)); - return $table; - } - - public function getFluidbookId() { - $res = parent::getFluidbookId(); - return $this->_setFrDefault($res); - } - - protected function _setFrDefault($res) { - - if (CubeIT_Util_Json::isJson($res)) { - $res = CubeIT_Util_Json::decode($res); - } - - if (!is_array($res) && !is_object($res)) { - return $res; - } - $res = CubeIT_Util_Object::asObject($res); - - if (!$res->en) { - $res->en = $res->fr; - } - - return $res; - } - - protected function _getFinalURL($url, $locale = null) { - $append = ''; - if ($url) { - if (substr($url, 0, 1) == '#') { - $append = $url; - } else { - return $url; - } - - } - if (null === $locale) { - return $this->_getLocalReference($this->getFluidbookId()) . $append; - } else { - return $this->_getLocalReference($this->getFluidbookId()->$locale) . $append; - } - } - - protected function _getLocalReference($id) { - $dirs = CubeIT_Files::getDirectoryIterator(PUBLIC_PATH . '/references'); - $d = null; - foreach ($dirs as $dir) { - if (!$dir->isDir()) { - continue; - } - $e = explode('-', $dir->getBasename(), 2); - if ($e[0] == $id && $e[1] != '') { - $d = $dir->getBasename(); - break; - } - } - if (null === $d) { - return; - } - - return '/references/' . $d . '/'; - } - - public function getFluidbookPage() { - $res = parent::getFluidbookPage(); - return $this->_setFrDefault($res); - } - - public function getFinalUrl() { - $res = parent::getUrl(); - - $res = $this->_setFrDefault($res); - - if (!is_array($res) && !is_object($res)) { - return $this->_getFinalURL($res); - } - - $res->fr = $this->_getFinalURL($res->fr, 'fr'); - $res->en = $this->_getFinalURL($res->en, 'en'); - - return $res; - } - - public function hasUrl() { - $furl = $this->getFinalUrl(); - return $furl && $furl != '-'; - } +class Fluidbook_Model_Reference extends CubeIT_Model_Data_Table +{ + protected static $_table = 'exemples'; + + protected $title; + protected $text; + protected $date; + protected $url; + protected $fluidbook_id; + protected $fluidbook_page; + protected $image; + protected $categories; + protected $featured_categories; + protected $homeimage; + + protected $_types = array('categories' => 'list', 'featured_categories' => 'list', 'title' => 'json', 'text' => 'json', 'image' => 'json', 'homeimage' => 'json', 'fluidbook_id' => 'json', 'fluidbook_page' => 'json'); + + public static function getSchema($schema) + { + $table = parent::getSchema($schema); + $table->addColumn('title', 'text'); + $table->addColumn('text', 'text'); + $table->addColumn('url', 'text'); + $table->addColumn('date', 'date'); + $table->addColumn('fluidbook_id', 'text'); + $table->addColumn('fluidbook_page', 'string', array("default" => '{"fr":2,"en":0}', "length" => 128)); + $table->addColumn('featured', 'boolean'); + $table->addColumn('image', 'string', array('length' => 64)); + $table->addColumn('homeimage', 'string', array('length' => 64)); + $table->addColumn('categories', 'string', array('length' => 64)); + $table->addColumn('featured_categories', 'string', array('length' => 64)); + return $table; + } + + public function getFluidbookId() + { + $res = parent::getFluidbookId(); + return $this->_setFrDefault($res); + } + + protected function _setFrDefault($res) + { + + if (CubeIT_Util_Json::isJson($res)) { + $res = CubeIT_Util_Json::decode($res); + } + + if (!is_array($res) && !is_object($res)) { + return $res; + } + $res = CubeIT_Util_Object::asObject($res); + + + if (!isset($res->fr)) { + $res->fr = ''; + } + + if (!isset($res->en) || !$res->en) { + $res->en = $res->fr; + } + + return $res; + } + + protected function _getFinalURL($url, $locale = null) + { + $append = ''; + if ($url) { + if (substr($url, 0, 1) == '#') { + $append = $url; + } else { + return $url; + } + + } + if (null === $locale) { + return $this->_getLocalReference($this->getFluidbookId()) . $append; + } else { + return $this->_getLocalReference($this->getFluidbookId()->$locale) . $append; + } + } + + protected function _getLocalReference($id) + { + $dirs = CubeIT_Files::getDirectoryIterator(PUBLIC_PATH . '/references'); + $d = null; + foreach ($dirs as $dir) { + if (!$dir->isDir()) { + continue; + } + $e = explode('-', $dir->getBasename(), 2); + if ($e[0] == $id && $e[1] != '') { + $d = $dir->getBasename(); + break; + } + } + if (null === $d) { + return; + } + + return '/references/' . $d . '/'; + } + + public function getFluidbookPage() + { + $res = parent::getFluidbookPage(); + return $this->_setFrDefault($res); + } + + public function getFinalUrl() + { + $res = parent::getUrl(); + + $res = $this->_setFrDefault($res); + + if (!is_array($res) && !is_object($res)) { + return $this->_getFinalURL($res); + } + + $res->fr = $this->_getFinalURL($res->fr, 'fr'); + $res->en = $this->_getFinalURL($res->en, 'en'); + + return $res; + } + + public function hasUrl() + { + $furl = $this->getFinalUrl(); + return $furl && $furl != '-'; + } } \ No newline at end of file -- 2.39.5