]> _ Git - cubedesigners-v7.git/commitdiff
Allow multiple categories to be selected for Case Studies. Also fix Case Studies...
authorstephen@cubedesigners.com <stephen@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Thu, 11 Apr 2019 15:56:03 +0000 (15:56 +0000)
committerstephen@cubedesigners.com <stephen@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Thu, 11 Apr 2019 15:56:03 +0000 (15:56 +0000)
framework/application/forms/CMS/Sub/Casestudies/Studies.php
framework/application/views/helpers/CasestudiesList.php
framework/application/views/helpers/CategoriesDropdown.php
framework/application/views/helpers/CategoriesFilter.php [new file with mode: 0644]
framework/application/views/scripts/templates/casestudies.phtml
js/isotope-select.js

index 4d200a9514e41424a74f851e3ec082e3159cbfd3..dff148a8a7598fd55887fe78be8bdf1803b61abe 100644 (file)
@@ -62,7 +62,7 @@ class Cubedesigners_Form_CMS_Sub_Casestudies_Studies extends CubeIT_Form_List_Mo
                $blocs->setLegend('Contenu');
                $this->addSubForm($blocs, 'blocs');
 
-               $categories = new Cubedesigners_Form_Element_Categories('categories');
+               $categories = new Cubedesigners_Form_Element_CategoriesCheckboxes('categories');
                $categories->setLabel('Catégories');
                $this->addElement($categories);
 
index 711955ee8ad6296ae61d1df2e61ee450ff4e0b80..9c19ca0287599fb98a9d10c9548c340540edb8ca 100644 (file)
@@ -182,10 +182,17 @@ class Cubedesigners_View_Helper_CasestudiesList extends CubeIT_View_Helper_Abstr
         */
         $c.= '<h3>' . $s->legende . '</h3>';
 
+        // Make a list of class names for each category this study is
+        // assigned to so it can be filtered later on the frontend
+        $category_classes = array_reduce($s->categories, function($list, $categoryID) {
+            $list .= ' cat-'. $categoryID;
+            return $list;
+        });
+
 
                return $this->link($c, $url, array(
-                'data-cat' => $s->categories,
-                'class' => 'wow fadeInUp',
+                //'data-cat' => $s->categories,
+                'class' => 'wow fadeInUp' . $category_classes,
                 'data-wow-delay' => '300ms',
             )) . ' '; // Space needed between elements for justified alignment
        }
index 7c81a3daaf00ad715e3cb53d772a939891c4258e..5e5585aed9a7b98600471f6bd52d0603f50ca15e 100644 (file)
@@ -2,6 +2,10 @@
 
 class Cubedesigners_View_Helper_CategoriesDropdown extends CubeIT_View_Helper_Abstract {
 
+    /*
+     * TODO: Refactor this to match new functionality of multiple categories per table? See CategoriesFilter.php. Also check that this isn't used elsewhere...
+     */
+
        public function CategoriesDropdown($table, $listID, $columnWidth = '170', $gutterSize = '32') {
 
         $this->headScript()->addIsotope();
diff --git a/framework/application/views/helpers/CategoriesFilter.php b/framework/application/views/helpers/CategoriesFilter.php
new file mode 100644 (file)
index 0000000..b5711ce
--- /dev/null
@@ -0,0 +1,64 @@
+<?php
+
+class Cubedesigners_View_Helper_CategoriesFilter extends CubeIT_View_Helper_Abstract {
+
+       public function CategoriesFilter($table, $listID, $columnWidth = '170', $gutterSize = '32') {
+
+        $this->headScript()->addIsotope();
+        $this->addScriptAndStyle('isotope-select');
+
+               $is_admin = Bootstrap::getInstance()->isAllowed("edition");
+               $db = Zend_Db_Table::getDefaultAdapter();
+
+               // Get distinct list of categories present in the table
+        // Since multiple categories can be assigned, we can't do an inner join for this
+        // Instead, get all studies and map them to their names
+
+        // First, get all possible categories
+               $select_categories = $db->select()
+                     ->from('categories')
+                     ->order('sort_order ASC');
+
+        $query_categories = $select_categories->query();
+        $all_categories = CubeIT_Util_Cms::unserialize($query_categories->fetchAll());
+        //echo 'CAT QUERY: '. (string) $select_categories;
+
+        // Next, get all case studies
+        $select = $db->select()
+                     ->from($table, ['categories']);
+
+        if (!$is_admin) {
+            $select->where($table.'.online = ?', 1);
+        }
+
+        $query = $select->query();
+
+               $categories = [
+                   '' => __('Choisir un domaine...'),
+                   '0' => __('Tout voir')
+        ];
+               while ($row = $query->fetch()) {
+
+                   $row = CubeIT_Util_Cms::unserialize($row);
+
+            foreach ($row->categories as $category) {
+                $categories[$category] = $all_categories[$category]->name;
+                   }
+
+               }
+
+               return $this->formSelect(
+                   $listID . '-filter', // Select element's name
+            null, // Value
+            [
+                // Attributes
+                'class' => 'category-dropdown form-select',
+                'data-container-id' => $listID,
+                'data-column-width' => $columnWidth,
+                'data-gutter' => $gutterSize
+            ],
+            $categories // Options
+        );
+       }
+
+}
index aa2e3fbe39abf4c9e25a1d01dc3c11d31a8279ce..d26b5b4121ed265c2ecc5abab8ea757819b02660 100644 (file)
@@ -7,9 +7,7 @@ $this->headScript()->addScriptAndStyle('casestudies');
 
 
        <div id="casestudies-tagslist" class="wow fadeInUp casestudies-filter">
-               <?php
-               echo $this->CategoriesDropdown('casestudies', 'casestudies-list', 512, 96);
-               ?>
+               <?= $this->CategoriesFilter('casestudies', 'casestudies-list', 512, 96); ?>
        </div>
 
        <div id="casestudies-list" class="casestudies-list grid">
index 197a9a311426cc7aeb39e109682a07429ec7d9cb..2cc5d09e8dfd0afb6e83fabe3f49b61b0a1fc9b7 100644 (file)
             if (id == 0) {
                 filterClass = '*';
             } else {
-                filterClass = '[data-cat="' + id + '"]';
+                filterClass = '.cat-' + id;
             }
 
             //fb('Filtering... ' + filterClass);
 
             //fb('Running resize...');
 
-            var container = this.container
-            var margin = this.gutter;
+            var container = this.container;
             var naturalWidth = this.columnWidth;
             var scaleFactor = 1;
 
-            var ww = Math.min($(window).width(), 1920);
-
-            ww *= 0.8; // Remove margins (10% each side)
+            var containerWidth = $(this.element).closest('div').outerWidth();
 
             // Handle extra padding that is added for small screens
             //if ($('html').hasClass('small')) {
-            // ww = ww - parseInt($('#main .content').css('paddingLeft')) - parseInt($('#main .content').css('paddingRight'));
-            // ww = ww - 68;
+            // containerWidth = containerWidth - parseInt($('#main .content').css('paddingLeft')) - parseInt($('#main .content').css('paddingRight'));
+            // containerWidth = containerWidth - 68;
             //}
 
-            var nbcol = Math.ceil(ww / (naturalWidth + margin));
-            var ew = Math.floor((ww - (margin * (nbcol - 1))) / nbcol);
-            if (ew > naturalWidth) {
-                nbcol++; // Add a column when elements are too big
-                ew = Math.floor((ww - (margin * (nbcol - 1))) / nbcol);
+            // We define the number of columns based on available width
+            var columns = 3;
+
+            if (containerWidth < 512) {
+                columns = 1;
+            } else if (containerWidth < 1024) {
+                columns = 2;
             }
 
+            // The margin ratio is based on the width of the main container
+            var marginRatio = 0.05;
+            var margin = marginRatio * containerWidth;
+            var ew = Math.floor((containerWidth - (margin * (columns - 1))) / columns);
+
             // Dynamically size text based on element width
             if (ew < naturalWidth) {
                 scaleFactor = ew / naturalWidth;