From 3fc2ad8785b265db512716c9949c422a5d174de7 Mon Sep 17 00:00:00 2001 From: Gusa Date: Sun, 16 Dec 2012 05:01:37 +0100 Subject: [PATCH] Edit ad, not show 'new' field when all languages If the current ad has a description for every available language in the system do not show the new field. --- lib/form/doctrine/AdForm.class.php | 48 +++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/lib/form/doctrine/AdForm.class.php b/lib/form/doctrine/AdForm.class.php index 00e8c9b..ab3c8b6 100644 --- a/lib/form/doctrine/AdForm.class.php +++ b/lib/form/doctrine/AdForm.class.php @@ -86,7 +86,10 @@ class AdForm extends BaseAdForm $adDescription->Ad = $this->getObject(); $newAdDescriptionForm = new AdDescriptionForm($adDescription); - $this->embedForm('new', $newAdDescriptionForm); + if (!$this->isTheLanguageInformationComplete()) + { + $this->embedForm('new', $newAdDescriptionForm); + } $this->embedRelation('AdDescription'); @@ -220,4 +223,47 @@ class AdForm extends BaseAdForm Doctrine_Manager::connection()->execute("UPDATE ad SET ad_gps=null WHERE id=$rowId"); } } + + /** + * Check if the current ad has a description for every available language in the system. + * + * @return boolean true, if the current ad has a description for every available language, otherwise false. + */ + private function isTheLanguageInformationComplete() + { + if($this->isNew()) + { + return false; + } + + //Doctrine_Collection with all our languages + $languages = LanguageTable::getInstance()->findAll(); + + //Using Doctrine_Collection_Iterator + $iterator = $languages->getIterator(); + + //Doctrine_Collection with the available descriptions for our ad + $adDescriptions = AdDescriptionTable::getInstance()->findByAdId($this->getObject()->getId()); + + while ($language = $iterator->current()) + { + $match = false; + foreach ($adDescriptions as $adDescription) + { + if ($adDescription->getLanguageId() == $language->getId()) + { + //There is a match + $match = true; + break; + } + } + if (!$match) + { + return false; + } + $iterator->next(); + } + + return true; + } } -- 2.1.4