This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use the new forum.
Home » legacy support » symfony 1.1 » sfPropelPager with I18n
sfPropelPager with I18n [message #58815] Fri, 15 August 2008 18:18 Go to next message
psande  is currently offline psande
Messages: 8
Registered: August 2008
Location: Montevideo - Uruguay
Junior Member

Hi everyone!
I have to develope a program that manage the news with I18n, and I had a problem with sfPropelPager that dont support I18n.

I surfed the web and the forum and I just found this two entries:
http://www.symfony-project.org/forum/index.php/m/48763/
http://groups.google.es/group/symfony-es/browse_thread/threa d/e8f00368d629649a

Here is what I did:
<?php
  class clPropelPagerI18n extends sfPropelPager {
    protected $culture = null;
    
    public function __construct($class, $maxPerPage = 10, $culture){
      $original_culture = sfPropel::getDefaultCulture();
      $this->culture = $culture;
      sfPropel::setDefaultCulture($culture);
      
      parent::__construct($class, $maxPerPage);
      $this->setPeerMethod('doSelectWithI18n');
      
      sfPropel::setDefaultCulture($original_culture);
    }
    
    public function getResults(){
      $original_culture = sfPropel::getDefaultCulture();
      sfPropel::setDefaultCulture($this->culture);
      $result_set = parent::getResults();
      sfPropel::setDefaultCulture($original_culture);
      return $result_set;
    }
  }    


Implementation:
  public static function retrievePropelPagerBySystem($system, $culture, $page_number, $objects_per_page=6)
  {
    $c = new Criteria();
    $c->addJoin(clCoreNewsPeer::NEWS_ID, clCoreNewsCoreGenericdataSystemPeer::CORE_GENERICDATA_SYSTEM_ID, Criteria::LEFT_JOIN);
    $c->add(clCoreNewsCoreGenericdataSystemPeer::CORE_GENERICDATA_SYSTEM_ID, $system, Criteria::EQUAL);
    $c->add(clCoreNewsPeer::NEWS_PUBLISH_AT, date('Y-m-d'), Criteria::LESS_EQUAL);
    $c->add(clCoreNewsPeer::NEWS_UNPUBLISH_AT, date('Y-m-d'), Criteria::GREATER_EQUAL);
    $c->add(clCoreNewsPeer::NEWS_STATUS, 1, Criteria::EQUAL);
    
    $pager = new clPropelPagerI18n('clCoreNews', $objects_per_page, $culture);
    $pager->setCriteria($c);
    $pager->setPage($page_number);
    $pager->init();
    
    return $pager;
  }


Questions:
Is this a well implemented sfPropelPager with I18n?
Is ok to change sfPropel::setDefaultCulture to make my pager work?
Is necessary to change the sfPropel::setDefaultCulture in the __construct? I think yes, because there are not the same number of pages of one language or another, but I don“t know if sfPropelPager use the culture there.

Thanks everybody, and forget my horrible english hehehe.


Re: sfPropelPager with I18n [message #61366 is a reply to message #58815 ] Fri, 19 September 2008 18:18 Go to previous messageGo to next message
jamsoft  is currently offline jamsoft
Messages: 21
Registered: August 2008
Location: Poland
Junior Member
Currently (I use sf 1.1) the solution for I18n is to manage it manually. I mean that you should add join(s) for i18n table(s).

I saw in your post good way using method doSelectWithI18n but entire query would be fake (db results would be multiplied), because method doCount which is used by propel's init doesn't add i18n join. And currently there is no doCountWithI18n in any model. After it will be implemented we can use it with setPeerCountMethod of sfPropelPager.
Example (loading all news items with I18n):
$c = new Criteria();
$culture_for_query=sfContext::getInstance()->getUser()->getCulture();
$c->add(NewsI18nPeer::CULTURE, $culture_for_query);
$max_per_page = 2;
$c->addJoin(NewsPeer::ID, NewsI18nPeer::ID);
$pager = new sfPropelPager('News', $max_per_page);
$pager->setCriteria($c);
$pager->setPage(sfContext::getInstance()->getRequest()->getParameter('page', 1));
$pager->init();


rest break is good - for many problems - espacially programming
Re: sfPropelPager with I18n [message #61369 is a reply to message #61366 ] Fri, 19 September 2008 19:22 Go to previous messageGo to next message
psande  is currently offline psande
Messages: 8
Registered: August 2008
Location: Montevideo - Uruguay
Junior Member

Thanks for your answer!
Actually, I tested it a lot of times, but I'm going to check what you said.
I think that the real problem could be the use of sfPropel::setDefaultCulture.
What happens if a another client do a request while I change the DefaultCulture? I think it could be a problem...
Re: sfPropelPager with I18n [message #62868 is a reply to message #61366 ] Sat, 11 October 2008 12:10 Go to previous messageGo to next message
jamsoft  is currently offline jamsoft
Messages: 21
Registered: August 2008
Location: Poland
Junior Member
I found a function as a snippet: doCountwithI18n

http://www.symfony-project.org/snippets/snippet/237


rest break is good - for many problems - espacially programming
Re: sfPropelPager with I18n [message #63017 is a reply to message #62868 ] Mon, 13 October 2008 21:28 Go to previous message
psande  is currently offline psande
Messages: 8
Registered: August 2008
Location: Montevideo - Uruguay
Junior Member

Thanks! I'm reading it right now...
Previous Topic:sfValidatorCallback arguments
Next Topic:Encoded DB access information
Goto Forum:
  

powered by FUDforum - copyright ©2001-2004 FUD Forum Bulletin Board Software