From 3bbe643264b8bcfc01078c1b13fd60f3d85ae5cc Mon Sep 17 00:00:00 2001 From: efalcy <efalcy@afi-sa.fr> Date: Wed, 24 Feb 2016 15:27:58 +0100 Subject: [PATCH] dev #32668 : fix rt comments --- .../opac/controllers/BibController.php | 2 +- library/Class/Article.php | 20 +++++-------------- library/Class/Catalogue.php | 3 +-- library/Class/CustomField/Value.php | 10 ++++++++++ library/Trait/CustomFields.php | 8 ++++++++ library/ZendAfi/View/Helper/BibView.php | 4 +++- .../View/Helper/Calendar/RenderFilters.php | 10 ++-------- 7 files changed, 30 insertions(+), 27 deletions(-) diff --git a/application/modules/opac/controllers/BibController.php b/application/modules/opac/controllers/BibController.php index 5b7f4ea3927..6e374f01ace 100644 --- a/application/modules/opac/controllers/BibController.php +++ b/application/modules/opac/controllers/BibController.php @@ -195,7 +195,7 @@ class BibController extends ZendAfi_Controller_Action { function bibviewAction() { $id_bib = (int)$this->_request->getParam('id'); - if (!$id_bib || $id_bib == 0) { + if (!$id_bib) { $this->_redirect('opac/bib/index'); return; } diff --git a/library/Class/Article.php b/library/Class/Article.php index e8327beffd0..c332ee2a77d 100644 --- a/library/Class/Article.php +++ b/library/Class/Article.php @@ -378,19 +378,12 @@ class ArticleLoader extends Storm_Model_Loader { if (!$custom_fields) return $articles; - $cfs = []; - foreach($custom_fields as $id => $value) { - if (!$cf=Class_CustomField::find($id)) - continue; - $cfs[$cf->getLabel()] = $value; - } return array_filter($articles, - function ($article) use ($cfs) + function ($article) use ($custom_fields) { - - foreach($cfs as $name => $value) { - if (!$article->findCustomFieldValueMatching($name,$value)) + foreach($custom_fields as $id => $value) { + if (!$article->findCustomFieldValueMatching($id,$value)) return false; } return true; @@ -583,12 +576,9 @@ class Class_Article extends Storm_Model_Abstract { 'referenced_in' => 'id_notice'])); } - public function findCustomFieldValueMatching($name,$match) { - $value = $this->getCustomField($name); - if (is_array($value)) - return in_array($match,$value); + public function findCustomFieldValueMatching($id,$match) { + $value = $this->getCustomFieldValueById($id); return in_array($match, explode(';',$value)); - } diff --git a/library/Class/Catalogue.php b/library/Class/Catalogue.php index dd244d1e225..954c5307ef3 100644 --- a/library/Class/Catalogue.php +++ b/library/Class/Catalogue.php @@ -474,8 +474,7 @@ class CatalogueLoader extends Storm_Model_Loader { public function getNoticesFromCacheByPreferences($preferences) { return (new Storm_Cache()) ->memoize([$preferences, __CLASS__, __FUNCTION__], - function() use ($preferences) { - return Class_Catalogue::getLoader()->fetchAllNoticesByPreferences($preferences);}); + function() use ($preferences) { return Class_Catalogue::getLoader()->fetchAllNoticesByPreferences($preferences);}); } diff --git a/library/Class/CustomField/Value.php b/library/Class/CustomField/Value.php index 60c5107632a..08911b18c96 100644 --- a/library/Class/CustomField/Value.php +++ b/library/Class/CustomField/Value.php @@ -74,5 +74,15 @@ class Class_CustomField_Value extends Storm_Model_Abstract { return explode(';', $this->getValue()); } + + + public function getValueAsArray() { + $options=$this->getSelectedOptionsList(); + if (!empty($options)) + return $options; + + return [$this->getValue()]; + + } } ?> diff --git a/library/Trait/CustomFields.php b/library/Trait/CustomFields.php index 3281bb99e92..20acca6d799 100644 --- a/library/Trait/CustomFields.php +++ b/library/Trait/CustomFields.php @@ -40,6 +40,14 @@ trait Trait_CustomFields { } + + public function getCustomFieldValueById($id) { + if (!$cfv = Class_CustomField_Value::findFirstBy(['custom_field_id' => $id, + 'model_id' => $this->getId()])) + return ''; + return $cfv->getValue(); + } + public function getCustomField($name) { if (isset($this->custom_fields[$name])) return $this->custom_fields[$name]; diff --git a/library/ZendAfi/View/Helper/BibView.php b/library/ZendAfi/View/Helper/BibView.php index 30fad885bef..b8e10e1609f 100644 --- a/library/ZendAfi/View/Helper/BibView.php +++ b/library/ZendAfi/View/Helper/BibView.php @@ -23,7 +23,7 @@ class ZendAfi_View_Helper_BibView extends ZendAfi_View_Helper_BaseHelper { protected $bib; - public function bibView($bib, $back_url) { + public function bibView($bib, $back_url = null) { $this->bib = $bib; return @@ -54,6 +54,8 @@ class ZendAfi_View_Helper_BibView extends ZendAfi_View_Helper_BaseHelper { protected function _renderBackLink($back_url) { + if (!$back_url) + return ''; return $this->_tag('div', $this->view->tagAnchor($back_url, $this->_('Retour')), ['class' => 'back_link']); } diff --git a/library/ZendAfi/View/Helper/Calendar/RenderFilters.php b/library/ZendAfi/View/Helper/Calendar/RenderFilters.php index b3b67727ca5..1c4e64c1cfe 100644 --- a/library/ZendAfi/View/Helper/Calendar/RenderFilters.php +++ b/library/ZendAfi/View/Helper/Calendar/RenderFilters.php @@ -200,14 +200,8 @@ class ZendAfi_View_Helper_Calendar_FilterElementsCustomField extends ZendAfi_Vie $elements = []; foreach ($values as $value) { - if ($value->getFieldType()!=Class_CustomField_Meta::MULTI_CHECKBOX) { - $elements[ $value->getValue() ] = $value->getValue(); - continue; - } - foreach (explode(';',$value->getValue()) as $arrvalue) { - $elements[$arrvalue] = $arrvalue; - } - + foreach ($value->getValueAsArray() as $value) + $elements[$value]=$value; } return $elements; -- GitLab