<?php\r
\r
\r
-class Fluidbook_Model_Reference extends CubeIT_Model_Data_Table {\r
- protected static $_table = 'exemples';\r
-\r
- protected $title;\r
- protected $text;\r
- protected $date;\r
- protected $url;\r
- protected $fluidbook_id;\r
- protected $fluidbook_page;\r
- protected $image;\r
- protected $categories;\r
- protected $featured_categories;\r
- protected $homeimage;\r
-\r
- protected $_types = array('categories' => 'list', 'featured_categories' => 'list', 'title' => 'json', 'text' => 'json', 'image' => 'json', 'homeimage' => 'json', 'fluidbook_id' => 'json', 'fluidbook_page' => 'json');\r
-\r
- public static function getSchema($schema) {\r
- $table = parent::getSchema($schema);\r
- $table->addColumn('title', 'text');\r
- $table->addColumn('text', 'text');\r
- $table->addColumn('url', 'text');\r
- $table->addColumn('date', 'date');\r
- $table->addColumn('fluidbook_id', 'text');\r
- $table->addColumn('fluidbook_page', 'string', array("default" => '{"fr":2,"en":0}', "length" => 128));\r
- $table->addColumn('featured', 'boolean');\r
- $table->addColumn('image', 'string', array('length' => 64));\r
- $table->addColumn('homeimage', 'string', array('length' => 64));\r
- $table->addColumn('categories', 'string', array('length' => 64));\r
- $table->addColumn('featured_categories', 'string', array('length' => 64));\r
- return $table;\r
- }\r
-\r
- public function getFluidbookId() {\r
- $res = parent::getFluidbookId();\r
- return $this->_setFrDefault($res);\r
- }\r
-\r
- protected function _setFrDefault($res) {\r
-\r
- if (CubeIT_Util_Json::isJson($res)) {\r
- $res = CubeIT_Util_Json::decode($res);\r
- }\r
-\r
- if (!is_array($res) && !is_object($res)) {\r
- return $res;\r
- }\r
- $res = CubeIT_Util_Object::asObject($res);\r
-\r
- if (!$res->en) {\r
- $res->en = $res->fr;\r
- }\r
-\r
- return $res;\r
- }\r
-\r
- protected function _getFinalURL($url, $locale = null) {\r
- $append = '';\r
- if ($url) {\r
- if (substr($url, 0, 1) == '#') {\r
- $append = $url;\r
- } else {\r
- return $url;\r
- }\r
-\r
- }\r
- if (null === $locale) {\r
- return $this->_getLocalReference($this->getFluidbookId()) . $append;\r
- } else {\r
- return $this->_getLocalReference($this->getFluidbookId()->$locale) . $append;\r
- }\r
- }\r
-\r
- protected function _getLocalReference($id) {\r
- $dirs = CubeIT_Files::getDirectoryIterator(PUBLIC_PATH . '/references');\r
- $d = null;\r
- foreach ($dirs as $dir) {\r
- if (!$dir->isDir()) {\r
- continue;\r
- }\r
- $e = explode('-', $dir->getBasename(), 2);\r
- if ($e[0] == $id && $e[1] != '') {\r
- $d = $dir->getBasename();\r
- break;\r
- }\r
- }\r
- if (null === $d) {\r
- return;\r
- }\r
-\r
- return '/references/' . $d . '/';\r
- }\r
-\r
- public function getFluidbookPage() {\r
- $res = parent::getFluidbookPage();\r
- return $this->_setFrDefault($res);\r
- }\r
-\r
- public function getFinalUrl() {\r
- $res = parent::getUrl();\r
-\r
- $res = $this->_setFrDefault($res);\r
-\r
- if (!is_array($res) && !is_object($res)) {\r
- return $this->_getFinalURL($res);\r
- }\r
-\r
- $res->fr = $this->_getFinalURL($res->fr, 'fr');\r
- $res->en = $this->_getFinalURL($res->en, 'en');\r
-\r
- return $res;\r
- }\r
-\r
- public function hasUrl() {\r
- $furl = $this->getFinalUrl();\r
- return $furl && $furl != '-';\r
- }\r
+class Fluidbook_Model_Reference extends CubeIT_Model_Data_Table\r
+{\r
+ protected static $_table = 'exemples';\r
+\r
+ protected $title;\r
+ protected $text;\r
+ protected $date;\r
+ protected $url;\r
+ protected $fluidbook_id;\r
+ protected $fluidbook_page;\r
+ protected $image;\r
+ protected $categories;\r
+ protected $featured_categories;\r
+ protected $homeimage;\r
+\r
+ protected $_types = array('categories' => 'list', 'featured_categories' => 'list', 'title' => 'json', 'text' => 'json', 'image' => 'json', 'homeimage' => 'json', 'fluidbook_id' => 'json', 'fluidbook_page' => 'json');\r
+\r
+ public static function getSchema($schema)\r
+ {\r
+ $table = parent::getSchema($schema);\r
+ $table->addColumn('title', 'text');\r
+ $table->addColumn('text', 'text');\r
+ $table->addColumn('url', 'text');\r
+ $table->addColumn('date', 'date');\r
+ $table->addColumn('fluidbook_id', 'text');\r
+ $table->addColumn('fluidbook_page', 'string', array("default" => '{"fr":2,"en":0}', "length" => 128));\r
+ $table->addColumn('featured', 'boolean');\r
+ $table->addColumn('image', 'string', array('length' => 64));\r
+ $table->addColumn('homeimage', 'string', array('length' => 64));\r
+ $table->addColumn('categories', 'string', array('length' => 64));\r
+ $table->addColumn('featured_categories', 'string', array('length' => 64));\r
+ return $table;\r
+ }\r
+\r
+ public function getFluidbookId()\r
+ {\r
+ $res = parent::getFluidbookId();\r
+ return $this->_setFrDefault($res);\r
+ }\r
+\r
+ protected function _setFrDefault($res)\r
+ {\r
+\r
+ if (CubeIT_Util_Json::isJson($res)) {\r
+ $res = CubeIT_Util_Json::decode($res);\r
+ }\r
+\r
+ if (!is_array($res) && !is_object($res)) {\r
+ return $res;\r
+ }\r
+ $res = CubeIT_Util_Object::asObject($res);\r
+\r
+\r
+ if (!isset($res->fr)) {\r
+ $res->fr = '';\r
+ }\r
+\r
+ if (!isset($res->en) || !$res->en) {\r
+ $res->en = $res->fr;\r
+ }\r
+\r
+ return $res;\r
+ }\r
+\r
+ protected function _getFinalURL($url, $locale = null)\r
+ {\r
+ $append = '';\r
+ if ($url) {\r
+ if (substr($url, 0, 1) == '#') {\r
+ $append = $url;\r
+ } else {\r
+ return $url;\r
+ }\r
+\r
+ }\r
+ if (null === $locale) {\r
+ return $this->_getLocalReference($this->getFluidbookId()) . $append;\r
+ } else {\r
+ return $this->_getLocalReference($this->getFluidbookId()->$locale) . $append;\r
+ }\r
+ }\r
+\r
+ protected function _getLocalReference($id)\r
+ {\r
+ $dirs = CubeIT_Files::getDirectoryIterator(PUBLIC_PATH . '/references');\r
+ $d = null;\r
+ foreach ($dirs as $dir) {\r
+ if (!$dir->isDir()) {\r
+ continue;\r
+ }\r
+ $e = explode('-', $dir->getBasename(), 2);\r
+ if ($e[0] == $id && $e[1] != '') {\r
+ $d = $dir->getBasename();\r
+ break;\r
+ }\r
+ }\r
+ if (null === $d) {\r
+ return;\r
+ }\r
+\r
+ return '/references/' . $d . '/';\r
+ }\r
+\r
+ public function getFluidbookPage()\r
+ {\r
+ $res = parent::getFluidbookPage();\r
+ return $this->_setFrDefault($res);\r
+ }\r
+\r
+ public function getFinalUrl()\r
+ {\r
+ $res = parent::getUrl();\r
+\r
+ $res = $this->_setFrDefault($res);\r
+\r
+ if (!is_array($res) && !is_object($res)) {\r
+ return $this->_getFinalURL($res);\r
+ }\r
+\r
+ $res->fr = $this->_getFinalURL($res->fr, 'fr');\r
+ $res->en = $this->_getFinalURL($res->en, 'en');\r
+\r
+ return $res;\r
+ }\r
+\r
+ public function hasUrl()\r
+ {\r
+ $furl = $this->getFinalUrl();\r
+ return $furl && $furl != '-';\r
+ }\r
}
\ No newline at end of file