]> _ Git - cubedesigners-v7.git/commitdiff
Done #3302 @5
authorstephen@cubedesigners.com <stephen@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Wed, 8 Jan 2020 19:27:20 +0000 (19:27 +0000)
committerstephen@cubedesigners.com <stephen@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Wed, 8 Jan 2020 19:27:20 +0000 (19:27 +0000)
framework/application/forms/CMS/Element/CasestudiesTagList.php [new file with mode: 0644]
framework/application/forms/CMS/Sub/Home/CaseStudies.php
framework/application/views/helpers/CaseStudiesSelectGrid.php [new file with mode: 0644]
framework/application/views/scripts/templates/home.phtml

diff --git a/framework/application/forms/CMS/Element/CasestudiesTagList.php b/framework/application/forms/CMS/Element/CasestudiesTagList.php
new file mode 100644 (file)
index 0000000..81a0db6
--- /dev/null
@@ -0,0 +1,30 @@
+<?php\r
+\r
+class Cubedesigners_Form_CMS_Element_CasestudiesTagList extends CubeIT_Form_Element_TagList {\r
+\r
+    public function init() {\r
+        parent::init();\r
+        $this->setLabel('');\r
+        $this->setAttrib('minChars', 1);\r
+        $this->setAttrib('tagsPosition', 'after');\r
+        $this->setAttrib('searchAnywhere', 1); // Search anywhere in the word :)\r
+        $this->setAttrib('manageurl', '/admin/ajaxpopup/openselectlist/Cubedesigners_Form_CMS_Sub_Casestudies_Studies/' . $this->getName());\r
+        $this->setAttrib('displayListManagement', 1);\r
+        $this->_setOptions();\r
+    }\r
+\r
+    protected function _setOptions() {\r
+        $options = array();\r
+        $studies = Cubedesigners_Model_Casestudy::factory()->find();\r
+        foreach ($studies as $study) {\r
+            $study = CubeIT_Util_Cms::unserialize($study);\r
+            $options[$study['id']] = $study['titre'];\r
+        }\r
+        $this->setMultiOptions($options);\r
+    }\r
+\r
+    protected function _refreshOptions() {\r
+\r
+    }\r
+\r
+}\r
index 63719ceec37ffe8826ce5407f0df8c493ed91e05..f327150cf59af8058a0c86827e7b0b1e9f435db3 100644 (file)
@@ -13,9 +13,14 @@ class Cubedesigners_Form_CMS_Sub_Home_CaseStudies extends CubeIT_Form_SubForm {
         $texte->setLabel('Texte');
         $this->addElement($texte);
 
-        $display_count = new CubeIT_Form_Element_Number('display_count');
-        $display_count->setLabel('Number of Case Studies to display');
-        $this->addElement($display_count);
+        //$display_count = new CubeIT_Form_Element_Number('display_count');
+        //$display_count->setLabel('Number of Case Studies to display');
+        //$this->addElement($display_count);
+
+        $studies = new Cubedesigners_Form_CMS_Element_CasestudiesTagList('casestudies');
+        $studies->setLabel("Case Studies (6 max / leave empty for random selection)");
+        $studies->setAttrib("placeholder", "Search...");
+        $this->addElement($studies);
 
         $lien = new CubeIT_Form_Element_Link();
         $lien->urlEnabled(false)->fileEnabled(false);
@@ -23,4 +28,4 @@ class Cubedesigners_Form_CMS_Sub_Home_CaseStudies extends CubeIT_Form_SubForm {
         $this->addSubForm($lien, 'button');
     }
 
-}
\ No newline at end of file
+}
diff --git a/framework/application/views/helpers/CaseStudiesSelectGrid.php b/framework/application/views/helpers/CaseStudiesSelectGrid.php
new file mode 100644 (file)
index 0000000..b5221eb
--- /dev/null
@@ -0,0 +1,105 @@
+<?php
+
+class Cubedesigners_View_Helper_CaseStudiesSelectGrid extends CubeIT_View_Helper_Abstract
+{
+
+    protected $_tags;
+    protected $_page_data;
+    protected $_counter = 0;
+
+    public function caseStudiesSelectGrid($IDs = [], $limit = 6)
+    {
+
+        $this->addScriptAndStyle('casestudies_grid');
+
+        // ToDo: see if there's a better way to do this
+        $this->_page_data = Bootstrap::getInstance()->getCMSDatasOfPage(4); // ID 4 = casestudies page
+
+        $db = Zend_Db_Table::getDefaultAdapter();
+
+        $select = $db->select()->from('casestudies');
+
+        if (!empty($IDs) && !empty($IDs[0])) {
+            $select->where('id IN(?)', $IDs);
+            $select->order(new Zend_Db_Expr('FIELD(id, ' . implode(',', $IDs) . ')'));
+        } else {
+            $select->order('RAND()');
+        }
+
+        if (!Bootstrap::getInstance()->isAllowed("edition")) {
+            $select->where('online = ?', 1);
+        }
+
+        $select->limit($limit);
+
+        $query = $select->query();
+
+        $res = '<div class="casestudies-grid">';
+
+
+        while ($study = $query->fetch()) {
+            $res .= $this->_study(CubeIT_Util_Cms::unserialize($study));
+        }
+
+        $res .= '</div>'; // .casestudies-grid
+
+        return $res;
+    }
+
+    protected function _study($study)
+    {
+
+        // Max display size is 512 but we over-sample the size by 20% because there is a CSS scale effect on hover
+        $image = $this->view->imageProcess($study->visuel, $study->titre, 615, 615, ['class' => 'responsive casestudies-grid-item-image']);
+        $url = Cubedesigners_Util::generateAutoUri($study, $this->_page_data['seourl_stu']);
+
+        /*
+        $tag_names = [];
+        foreach ($study->tags_secondaires as $categoryID) {
+            $tag_names[] = $this->_getTagName($categoryID);
+        }
+        */
+
+        $hover_style = empty($study->hover_color) ? '' : 'background-color:' . CubeIT_Util_Cms::hexToRGBA($study->hover_color, 0.75) . ';';
+
+        $c = $image;
+        $c .= '<div class="casestudies-grid-item-label" style="' . $hover_style . '">';
+        $c .= '<h2 class="casestudies-grid-item-title">' . $study->titre . '</h2>';
+        //$c.= '<h3 class="casestudies-grid-item-tags">' . implode(' / ', $tag_names) . '</h3>';
+        $c .= '<h3 class="casestudies-grid-item-tags">' . $study->legende . '</h3>';
+        $c .= '</div>'; // .casestudies-grid-item-label
+
+
+        // Create a staggered delay for each row (3 items per row)
+        $delay = 300 + (($this->_counter % 3) * 200);
+
+        $this->_counter++;
+
+        return $this->link($c, $url, array(
+                'data-cat' => $study->categories,
+                'class' => 'casestudies-grid-item wow fadeInUp',
+                'data-wow-delay' => $delay . 'ms',
+            )) . ' '; // Space needed between elements for justified alignment
+    }
+
+
+    // Get secondary category names
+    protected function _getTagName($catID)
+    {
+
+        // Cache the query data if it's not already done
+        if (!$this->_tags) {
+
+            $db = Zend_Db_Table::getDefaultAdapter();
+            $query = $db->select()->from('tags')->query();
+
+            while ($category = $query->fetch()) {
+                $category = CubeIT_Util_Cms::unserializeRow($category);
+                $this->_tags[$category->id] = CubeIT_Util_Object::toArray($category);
+            }
+        }
+
+        return $this->_tags[$catID]['name'];
+    }
+
+}
index 76844757579aeb3ef3f81e163803be3c2ff0f2d7..977ebc4707a0aca87ff4b4ffc457d1257332b766 100644 (file)
@@ -25,7 +25,7 @@ if ($this->case_studies['button']['label']) {
 echo $this->markupDotclear($this->case_studies['texte'], array(), array('class' => 'intro'));
 
 echo '<div class="casestudies">';
-echo $this->caseStudiesGrid(6);
+echo $this->caseStudiesSelectGrid(explode(',', $this->case_studies['casestudies']), 6);
 echo '</div>';
 
 if ($this->case_studies['button']['label']) {