From: stephen@cubedesigners.com Date: Wed, 8 Jan 2020 19:27:20 +0000 (+0000) Subject: Done #3302 @5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=0c2e762ab1dddc44f00d5cc71b029591f178d81b;p=cubedesigners-v7.git Done #3302 @5 --- diff --git a/framework/application/forms/CMS/Element/CasestudiesTagList.php b/framework/application/forms/CMS/Element/CasestudiesTagList.php new file mode 100644 index 0000000..81a0db6 --- /dev/null +++ b/framework/application/forms/CMS/Element/CasestudiesTagList.php @@ -0,0 +1,30 @@ +setLabel(''); + $this->setAttrib('minChars', 1); + $this->setAttrib('tagsPosition', 'after'); + $this->setAttrib('searchAnywhere', 1); // Search anywhere in the word :) + $this->setAttrib('manageurl', '/admin/ajaxpopup/openselectlist/Cubedesigners_Form_CMS_Sub_Casestudies_Studies/' . $this->getName()); + $this->setAttrib('displayListManagement', 1); + $this->_setOptions(); + } + + protected function _setOptions() { + $options = array(); + $studies = Cubedesigners_Model_Casestudy::factory()->find(); + foreach ($studies as $study) { + $study = CubeIT_Util_Cms::unserialize($study); + $options[$study['id']] = $study['titre']; + } + $this->setMultiOptions($options); + } + + protected function _refreshOptions() { + + } + +} diff --git a/framework/application/forms/CMS/Sub/Home/CaseStudies.php b/framework/application/forms/CMS/Sub/Home/CaseStudies.php index 63719ce..f327150 100644 --- a/framework/application/forms/CMS/Sub/Home/CaseStudies.php +++ b/framework/application/forms/CMS/Sub/Home/CaseStudies.php @@ -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 index 0000000..b5221eb --- /dev/null +++ b/framework/application/views/helpers/CaseStudiesSelectGrid.php @@ -0,0 +1,105 @@ +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 = '
'; + + + while ($study = $query->fetch()) { + $res .= $this->_study(CubeIT_Util_Cms::unserialize($study)); + } + + $res .= '
'; // .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 .= '
'; + $c .= '

' . $study->titre . '

'; + //$c.= '

' . implode(' / ', $tag_names) . '

'; + $c .= '

' . $study->legende . '

'; + $c .= '
'; // .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']; + } + +} diff --git a/framework/application/views/scripts/templates/home.phtml b/framework/application/views/scripts/templates/home.phtml index 7684475..977ebc4 100644 --- a/framework/application/views/scripts/templates/home.phtml +++ b/framework/application/views/scripts/templates/home.phtml @@ -25,7 +25,7 @@ if ($this->case_studies['button']['label']) { echo $this->markupDotclear($this->case_studies['texte'], array(), array('class' => 'intro')); echo '
'; -echo $this->caseStudiesGrid(6); +echo $this->caseStudiesSelectGrid(explode(',', $this->case_studies['casestudies']), 6); echo '
'; if ($this->case_studies['button']['label']) {