Ejemplo n.º 1
0
 public function executeIndex(sfWebRequest $request)
 {
     //Get user Id
     $userId = $this->getUser()->getGuardUser()->getId();
     //Get company owned by that user
     //Just 1 user owns a company. Should this be improved?
     $companyId = CompanyTable::getInstance()->findOneByUserId($userId)->getId();
     $languageCode = $request->getParameter('language');
     if ($languageCode != null) {
         $language = LanguageTable::getInstance()->findOneByCode($languageCode);
         if ($language == null) {
             //By default we use the current user's language.
             $language = $this->getUser()->getGuardUser()->getLanguage();
         }
     } else {
         //By default we use the current user's language.
         $language = $this->getUser()->getGuardUser()->getLanguage();
     }
     //Init combobox with the right value.
     $this->formLanguage = new LanguageListForm($language);
     //Doctrine Query used to show a pager with the Ads.
     $query = AdDescriptionTable::getInstance()->getAdsByCompanyandLanguageIdQuery($companyId, $language->getId());
     $this->pager = new sfDoctrinePager('AdDescription', sfConfig::get('app_max_ads_on_pager'));
     $this->pager->setQuery($query);
     $this->pager->setPage($request->getParameter('page', 1));
     $this->pager->init();
     $this->userLanguageId = $this->getUser()->getGuardUser()->getLanguage()->getId();
     $this->languageCode = $language->getCode();
 }
Ejemplo n.º 2
0
 /**
  * Retrieve the available language's ids.
  *
  * @return array an array with the available languages' ids.
  */
 private function availableLanguages()
 {
     //Doctrine_Collection with all our languages
     $languages = LanguageTable::getInstance()->findAll();
     //Using Doctrine_Collection_Iterator
     $iterator = $languages->getIterator();
     //Doctrine_Collection with the current descriptions for our ad
     //When creating the first time a new ad there is not Doctrine_Row for this ad in the Ad Table.
     //We check that edge condition.
     if ($this->getObject()->getAd()->exists()) {
         $adDescriptions = AdDescriptionTable::getInstance()->findByAdId($this->getObject()->getAdId());
     } else {
         $adDescriptions = array();
     }
     $availableLanguages = array();
     while ($language = $iterator->current()) {
         $match = false;
         foreach ($adDescriptions as $adDescription) {
             if ($adDescription->getLanguageId() == $language->getId()) {
                 //There is a match
                 $match = true;
                 break;
             }
         }
         if (!$match) {
             $availableLanguages[] = $language->getId();
         }
         $iterator->next();
     }
     return $availableLanguages;
 }
Ejemplo n.º 3
0
 /**
  * RESTful Web Service: receiving latitude and longitude, it sends a response with the found ads on thoses coordinates.
  * 
  * We will try to reduce as much as we can the number of methods and queries. While the tables in the data base do not have many rows 
  * we will try to make the queries directly in the data base. When the tables get bigger than now probably we are going to need
  * a solution based on queries to data base and php code. Right now and with this size, the fastest solution (IMHO) is to make the queries
  * directly on the data base.
  *
  * TODO: Take measures about the performance using queries directly to the data base and using Doctrine Objects with PHP
  *       Choose this or the other one solution. I got no time to make this profiling before. But to be serious I should do it.  
  *       Now I am using queries directly to the data base because I am making the supposition that this is the best to achieve high performance. 
  *
  * TODO: C-programmed dedicated server to make this stuff without using PHP should be the best to achieve the max performance.
  * 
  * @param sfRequest $request A request object
  */
 public function executeGetadsbygps(sfWebRequest $request)
 {
     //RESTFUL permits to use cookies to implement authentication (user / password)
     $this->ads = array();
     $this->ads = AdDescriptionTable::getInstance()->getAdsByGPSAndUserIdAndLanguageId($this->getRoute()->getParameters(), $this->getUser()->getGuardUser()->getId(), $this->getUser()->getGuardUser()->getLanguage()->getId());
     if (empty($this->ads)) {
         //If there are not results.
         //In production replace this line by a die command (trying to stop wasting TCP bandwidth)
         throw new sfError404Exception(sprintf('
         There are not offices or ads with GPS coordinates: longitude "%s" and
         latitude "%s".', $request->getParameter('longitude'), $request->getParameter('latitude')));
         //die;
     }
 }
Ejemplo n.º 4
0
 /**
  * Returns the string representation of this object.
  *
  * @return string
  */
 public function __toString()
 {
     $languageId = sfContext::getInstance()->getUser()->getGuardUser()->getLanguage()->getId();
     //Check if there is description with the user's language
     $adDescriptions = AdDescriptionTable::getInstance()->findByAdId($this->getId());
     foreach ($adDescriptions as $adDescription) {
         if ($adDescription->getLanguageId() == $languageId) {
             //We found it!!!
             return (string) $adDescription->getAdName();
         }
     }
     //Otherwise return with the default language
     $languageCode = sfConfig::get('app_default_language');
     $languageId = LanguageTable::getInstance()->findOneByCode($languageCode)->getId();
     foreach ($adDescriptions as $adDescription) {
         if ($adDescription->getLanguageId() == $languageId) {
             //We found the default language!!!
             return (string) $adDescription->getAdName();
         }
     }
     //Finally, if nothing was found, return nice error message.
     return (string) "Ad without default language";
 }
Ejemplo n.º 5
0
 /**
  * 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 current 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;
 }