From: Gusa Date: Sun, 16 Dec 2012 04:01:37 +0000 (+0100) Subject: Edit ad, not show 'new' field when all languages X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=3fc2ad8785b265db512716c9949c422a5d174de7;p=mobi%2F.git 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. --- 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; + } }