From 6d86bbfb77d71db395dea2c6775dedf83cebcf10 Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Fri, 2 Sep 2016 16:13:24 +0000 Subject: [PATCH] done #655 @4.5 --- .htaccess | 1 + .../controllers/MaintenanceController.php | 37 ++++++++- .../forms/CMS/Sub/Exemples/Fluidbook.php | 4 + .../forms/CMS/Sub/Home/Services/Example.php | 24 +++--- .../CMS/Sub/Home/Services/References.php | 11 +++ framework/application/models/Reference.php | 66 ++++++++++++++-- .../application/views/helpers/Exemples.php | 27 ++----- .../views/helpers/HomeReferences.php | 2 +- .../views/helpers/HomeServices.php | 77 ++++++++++--------- 9 files changed, 170 insertions(+), 79 deletions(-) create mode 100644 framework/application/forms/CMS/Sub/Home/Services/References.php diff --git a/.htaccess b/.htaccess index 57e4523..d5a4959 100644 --- a/.htaccess +++ b/.htaccess @@ -40,6 +40,7 @@ RewriteRule ^js/ - [NC,L] RewriteRule ^images/ - [NC,L] RewriteRule ^files/ - [NC,L] + RewriteRule ^references/ - [NC,L] # Redirect CMS files to the right URL RewriteRule ^([a-f0-9]{6,})-([a-z0-9-._])([a-z0-9-._])([a-z0-9-._]*)$ files/$2/$3/$1-$2$3$4 [NC,L] # Ignore static files or directories diff --git a/framework/application/controllers/MaintenanceController.php b/framework/application/controllers/MaintenanceController.php index ab8f4f7..d171279 100644 --- a/framework/application/controllers/MaintenanceController.php +++ b/framework/application/controllers/MaintenanceController.php @@ -8,9 +8,38 @@ class MaintenanceController extends CubeIT_Controller_MaintenanceController { return $url; } - public function importEn() { - $import = new CubeIT_Translate_Import_Excel('fr', 'en'); - $import->import(PUBLIC_PATH . '/translations_en.xlsx'); - Bootstrap::getInstance()->getCache()->clean(); + // public function importEn() { + // $import = new CubeIT_Translate_Import_Excel('fr', 'en'); + // $import->import(PUBLIC_PATH . '/translations_en.xlsx'); + // Bootstrap::getInstance()->getCache()->clean(); + // } + + public function importReferences() { + set_time_limit(0); + + $ws = new CubeIT_Services_Fluidbook('vincent@cubedesigners.com', 'iquique'); + $references = Fluidbook_Model_Reference::factory()->find(); + + $fluidbooks = array(); + foreach ($references as $reference) { + $ids = $reference->getFluidbookId(); + foreach ($ids as $locale => $id) { + if (!$id) { + continue; + } + $fluidbooks[] = $id; + } + } + $fluidbooks = array_values(array_unique($fluidbooks)); + + foreach ($fluidbooks as $fluidbook) { + $meta = $ws->getMetadata($fluidbook); + $dir = PUBLIC_PATH . '/references/' . $fluidbook . '-' . CubeIT_Text::str2URL($meta->title); + try { + $ws->installBookIfNeeded($fluidbook, $dir, $meta->date); + } catch (exception $e) { + } + + } } } diff --git a/framework/application/forms/CMS/Sub/Exemples/Fluidbook.php b/framework/application/forms/CMS/Sub/Exemples/Fluidbook.php index 4bed9b2..c663a07 100644 --- a/framework/application/forms/CMS/Sub/Exemples/Fluidbook.php +++ b/framework/application/forms/CMS/Sub/Exemples/Fluidbook.php @@ -58,4 +58,8 @@ class Fluidbook_Form_CMS_Sub_Exemples_Fluidbook extends CubeIT_Form_List_Model { ->setAdditionnalColumns(array('fluidbook_id', 'featured', 'homeimage', 'date')) ->setSearchColumns(array('text', 'fluidbook_id', 'title')); } + + function getTitle() { + return parent::getTitle() . ' (#' . $this->getIdValue() . ')'; + } } \ No newline at end of file diff --git a/framework/application/forms/CMS/Sub/Home/Services/Example.php b/framework/application/forms/CMS/Sub/Home/Services/Example.php index 386043d..8bf4a75 100644 --- a/framework/application/forms/CMS/Sub/Home/Services/Example.php +++ b/framework/application/forms/CMS/Sub/Home/Services/Example.php @@ -2,19 +2,19 @@ class Fluidbook_Form_CMS_Sub_Home_Services_Example extends CubeIT_Form_SubForm { - public function init() { - parent::init(); + public function init() { + parent::init(); - $title = new CubeIT_Form_Element_Text('title'); - $title->setLabel('Titre du exemple'); - $this->addElement($title); + $title = new CubeIT_Form_Element_Text('title'); + $title->setLabel('Titre du exemple'); + $this->addElement($title); - $link = new CubeIT_Form_Element_Url('link'); - $link->setLabel('URL du Fluidbook exemple'); - $this->addElement($link); + $exemple = new Fluidbook_Form_CMS_Sub_Home_Services_References('exemple'); + $exemple->setLabel('Exemple'); + $this->addElement($exemple); - $image = new CubeIT_Form_Element_File_Image('image'); - $image->setLabel('Image'); - $this->addElement($image); - } + $image = new CubeIT_Form_Element_File_Image('image'); + $image->setLabel('Image'); + $this->addElement($image); + } } \ No newline at end of file diff --git a/framework/application/forms/CMS/Sub/Home/Services/References.php b/framework/application/forms/CMS/Sub/Home/Services/References.php new file mode 100644 index 0000000..dd9a038 --- /dev/null +++ b/framework/application/forms/CMS/Sub/Home/Services/References.php @@ -0,0 +1,11 @@ +setBaseForm(new Fluidbook_Form_CMS_Sub_Exemples_Fluidbook()); + $this->setDisplayListManagement(false); + } +} \ No newline at end of file diff --git a/framework/application/models/Reference.php b/framework/application/models/Reference.php index d26d094..38e852b 100644 --- a/framework/application/models/Reference.php +++ b/framework/application/models/Reference.php @@ -15,7 +15,7 @@ class Fluidbook_Model_Reference extends CubeIT_Model_Data_Table { protected $categories; protected $homeimage; - protected $_types = array('categories' => 'list', 'title' => 'json', 'text' => 'json', 'image' => 'json'); + protected $_types = array('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); @@ -32,21 +32,77 @@ class Fluidbook_Model_Reference extends CubeIT_Model_Data_Table { return $table; } - public function getUrl() { - $res = parent::getUrl(); + public function getFinalFluidbookId() { + $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_string($res)) { + if (!is_array($res) && !is_object($res)) { return $res; } if (!$res->en) { $res->en = $res->fr; } + + return $res; + } + + protected function _getFinalURL($url, $locale = null) { + if ($url) { + return $url; + } + if (null === $locale) { + return $this->_getLocalReference($this->getFinalFluidbookId()); + } else { + return $this->_getLocalReference($this->getFinalFluidbookId()->$locale); + } + } + + 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) { + $d = $dir->getBasename(); + break; + } + } + if (null === $d) { + return; + } + + return '/references/' . $d . '/'; + } + + public function getFinalFluidbookPage() { + $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->fr = $this->_getFinalURL($res->en, 'en'); + return $res; } public function hasUrl() { - return $this->getUrl() != ''; + $furl = $this->getFinalUrl(); + return $furl && $furl != '-'; } } \ No newline at end of file diff --git a/framework/application/views/helpers/Exemples.php b/framework/application/views/helpers/Exemples.php index 1cb83c1..93345d1 100644 --- a/framework/application/views/helpers/Exemples.php +++ b/framework/application/views/helpers/Exemples.php @@ -101,10 +101,6 @@ class Fluidbook_View_Helper_Exemples extends CubeIT_View_Helper_Abstract { $fr = $f->unserialize('fr'); $f = $f->unserialize(); - fb($fr->toArray()); - fb($f->toArray()); - - $res = ''; $res .= $this->htmlElement($f->getTitle(), 'h3'); @@ -115,18 +111,8 @@ class Fluidbook_View_Helper_Exemples extends CubeIT_View_Helper_Abstract { $image = CubeIT_Util_Cms::extractFile($f->getImage()); - $fluibdookId = $f->getFluidbookId(); - $fluidbookPage = $f->getFluidbookPage(); - if (!$fluibdookId) { - $fluibdookId = $fr->getFluidbookId(); - $fluidbookPage = $fr->getFluidbookPage(); - } - if ($fluidbookPage == 0) { - $fluidbookPage = $fr->getFluidbookPage(); - } - - if (!$image && $fluibdookId) { - $res .= $this->exemplePublication($fluibdookId, $fluidbookPage); + if (!$image && $f->getFinalFluidbookId()) { + $res .= $this->exemplePublication($f->getFinalFluidbookId(), $f->getFinalFluidbookPage()); } else { $res .= $this->htmlElement('', 'div', array('style' => 'background-image:url(' . $this->imageProcess()->imageProcessGetURL($image, $f->getTitle() . ' - ' . $f->getText(), 660, 440, array(), 'R') . ');', @@ -140,14 +126,15 @@ class Fluidbook_View_Helper_Exemples extends CubeIT_View_Helper_Abstract { $attrs['class'] = 'no-featured'; } - $res .= $this->_rollover($f, $category); + $res .= $this->_rollover($f, $category, $f->getFinalUrl()); return $this->htmlElement($res, 'article', $attrs); } - protected function _rollover($f, $category) { + protected function _rollover($f, $category, $url) { $res = ''; - if ($f->getUrl()) { - $res = $this->link(__('Voir le Fluidbook'), $f->getUrl(), array('class' => 'button', 'data-event' => array('category' => 'exemple', 'action' => 'see', 'label' => $f->getTitle()))); + + if ($url) { + $res = $this->linkTruePopupFullscreen(__('Voir le Fluidbook'), $url, array('class' => 'button', 'data-event' => array('category' => 'exemple', 'action' => 'see', 'label' => $f->getTitle()))); } if ($category == 3) { $firstCat = 0; diff --git a/framework/application/views/helpers/HomeReferences.php b/framework/application/views/helpers/HomeReferences.php index 8b9c63c..580107d 100644 --- a/framework/application/views/helpers/HomeReferences.php +++ b/framework/application/views/helpers/HomeReferences.php @@ -44,7 +44,7 @@ class Fluidbook_View_Helper_HomeReferences extends Fluidbook_View_Helper_HomeLay ); if ($fluidbook->hasUrl()) { $rollover = $this->htmlElement($fluidbook->getTitle(), 'h3'); - $rollover .= $this->link(__('Voir le Fluidbook'), $fluidbook->getUrl()); + $rollover .= $this->linkTruePopupFullscreen(__('Voir le Fluidbook'), $fluidbook->getFinalUrl()); $res .= $this->htmlElement($this->htmlElement($rollover, 'div', array('class' => 'content')), 'div', array('class' => 'hover')); } diff --git a/framework/application/views/helpers/HomeServices.php b/framework/application/views/helpers/HomeServices.php index ec12c98..90dd7e6 100644 --- a/framework/application/views/helpers/HomeServices.php +++ b/framework/application/views/helpers/HomeServices.php @@ -6,62 +6,65 @@ class Fluidbook_View_Helper_HomeServices extends Fluidbook_View_Helper_HomeLayer */ public function homeServices($data) { - $this->headScript()->addScriptAndStyle('214-home-services'); + $this->headScript()->addScriptAndStyle('214-home-services'); $this->data = $data; - $res = '
'; - $res .= $this->_leftText(); - $res .= '
'; // .text + $res = '
'; + $res .= $this->_leftText(); + $res .= '
'; // .text - $res .= ''; // .carousel - return $this->_layer($res, 'services'); + return $this->_layer($res, 'services'); } - public function _rollover($example) { + public function _rollover($example) { - $res = ''; + $res = ''; - if (!empty($example['link'])) { - $res .= $this->link(__('Voir le Fluidbook'), $example['link'], ['class' => 'button']); - } + $model = Fluidbook_Model_Reference::findOneById($example['exemple']); + $ex = $model->unserialize(); - $res = $this->htmlElement($res, 'div', ['class' => 'inner']); // Wrapper for vertical centering + if ($ex->hasUrl()) { + $res .= $this->linkTruePopupFullscreen(__('Voir le Fluidbook'), $ex->getFinalUrl(), ['class' => 'button']); + } - return $this->htmlElement($res, 'div', ['class' => 'more']); + $res = $this->htmlElement($res, 'div', ['class' => 'inner']); // Wrapper for vertical centering + + return $this->htmlElement($res, 'div', ['class' => 'more']); } } \ No newline at end of file -- 2.39.5