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 » support » symfony 1.3 and 1.4 » Admin generator, filters and I18n
Admin generator, filters and I18n [message #89981] Mon, 14 December 2009 16:24 Go to next message
silent_hill_dev  is currently offline silent_hill_dev
Messages: 56
Registered: December 2009
Location: Argentina
Member
Hi everyone. I've a quick question. How do I add i18n fields to a form filter? (the one that appears at the list action on the generated admin). I can add them from a normal from with:

$this->embedI18n( array( 'en', 'es' ) );


But I can't do the same with the filters.


Thanks in advance.
Re: Admin generator, filters and I18n [message #91562 is a reply to message #89981 ] Fri, 15 January 2010 21:59 Go to previous messageGo to next message
silent_hill_dev  is currently offline silent_hill_dev
Messages: 56
Registered: December 2009
Location: Argentina
Member
Anyone..? I didn't find anything about this topic.
Re: Admin generator, filters and I18n [message #91671 is a reply to message #91562 ] Mon, 18 January 2010 13:04 Go to previous messageGo to next message
rodrigobb  is currently offline rodrigobb
Messages: 36
Registered: October 2008
Member
You need to modify your EntityFormFilter (where Entity is your object class - Article, Book, etc.).

Three easy steps

1) configure function
Add an input for each field you want to include in your filter

$this->widgetSchema['name']     = new sfWidgetFormFilterInput(array('with_empty' => false));
$this->validatorSchema['name']  = new sfValidatorPass(array('required' => false));


2) add a query modification when filtering for that field
I've done it for Doctrine. Pay atention to the method name addFIELDColumnQuery.

public function addNameColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (is_array($values) && isset($values['text']) && '' != $values['text'])
    {
      $query->leftJoin('r.Translation t') 
            // ->andWhere('t.lang = ?', $especify_one_language) // or it will search in all of them
            ->andWhere('CONCAT(t.name, t.shortname) like ?', '%' . $values['text'] . '%');
    }
  }


3) Add your searching fields
public function getFields()
  {
    return parent::getFields() + array('name' => 'Text');
  }


Hope it helps
Re: Admin generator, filters and I18n [message #91672 is a reply to message #91671 ] Mon, 18 January 2010 13:06 Go to previous messageGo to next message
rodrigobb  is currently offline rodrigobb
Messages: 36
Registered: October 2008
Member
And of course, add it to the generator.yml

      filter:
        display: [name, other_fields]
Re: Admin generator, filters and I18n [message #91859 is a reply to message #89981 ] Wed, 20 January 2010 14:00 Go to previous messageGo to next message
silent_hill_dev  is currently offline silent_hill_dev
Messages: 56
Registered: December 2009
Location: Argentina
Member
Thanks! I'll give it a try. I couldn't find anything about this topic on the documentation. Is there any doc that talks about it?


Thank you again for your complete answer.
Re: Admin generator, filters and I18n [message #91866 is a reply to message #91672 ] Wed, 20 January 2010 15:10 Go to previous messageGo to next message
silent_hill_dev  is currently offline silent_hill_dev
Messages: 56
Registered: December 2009
Location: Argentina
Member
It works like a charm! thank you so much!

Now, what if, for example, you have 6 models with i18n fields "name" and "description". Could I make a generic class with the code you wrote and then make my i18n filter forms inherit from it? All of this, of course, would be to avoid code duplication.

How could I do that?

Thanks!
Re: Admin generator, filters and I18n [message #98729 is a reply to message #91671 ] Sat, 08 May 2010 15:12 Go to previous messageGo to next message
thelonious
Messages: 3
Registered: November 2009
Junior Member
Thank you very much, rodrigobb, it works great!

However, there's a nasty little problem:

I left
// ->andWhere('t.lang = ?', $especify_one_language)....
commented, so I have one Text Field in the filter, but it searches in both my translations. And it finds the right things.

I also have the i18n-field in question shown as a column in the list, it shows me the german variant when not filtering and also when having searched for a german text.

But when I searched for an english text, although the right objects are found, there is nothing in the translated column, neither english nor german (which is the user culture, the navigation buttons and so on are shown in german).

Any idea?
Re: Admin generator, filters and I18n [message #98730 is a reply to message #98729 ] Sat, 08 May 2010 16:18 Go to previous messageGo to next message
thelonious
Messages: 3
Registered: November 2009
Junior Member
I ended up writing a new function that retrieves the german translation with an extra Doctrine Query and showing that in a partial in the admin generator list.

It works, but this is probably not how it should be done...
Re: Admin generator, filters and I18n [message #102705 is a reply to message #89981 ] Mon, 19 July 2010 01:14 Go to previous messageGo to next message
wm_maw  is currently offline wm_maw
Messages: 8
Registered: July 2010
Location: Bucuresti
Junior Member

This problem is busting my day also.
Please somebody reply if you find something more useful.


Using SYMFONY 1.4.6
Re: Admin generator, filters and I18n [message #102708 is a reply to message #102705 ] Mon, 19 July 2010 03:39 Go to previous message
wm_maw  is currently offline wm_maw
Messages: 8
Registered: July 2010
Location: Bucuresti
Junior Member

This is my solution so far:

class MenuFormFilter extends BaseMenuFormFilter
{
  private $rootAlias;
	
  public function configure()
  {
		$this->widgetSchema['title']     = new sfWidgetFormFilterInput(array('with_empty' => false));
		$this->validatorSchema['title']  = new sfValidatorPass(array('required' => false));
		
		$this->widgetSchema['type'] = new sfWidgetFormChoice(array(
			'choices'  => Doctrine_Core::getTable('Menu')->getTypes(),
			'expanded' => false,
		));
	
		$this->validatorSchema['type'] = new sfValidatorChoice(array(
			'choices' => array_keys(Doctrine_Core::getTable('Menu')->getTypes()),
		));
		
  }
	
  public function addTitleColumnQuery(Doctrine_Query $q, $field, $values)
  {
    if (is_array($values) && isset($values['text']) && '' != $values['text'])
    {
			$this->JoinTable($q);
      $q->andWhere('t.title like ?', '%' . str_replace(" ","%",$values['text']) . '%');
    }
  }
	
  public function addTypeColumnQuery(Doctrine_Query $q, $field, $values){
    if (isset($values) && '%' != $values)
    {
      $this->JoinTable($q);
      $q->andWhere('t.type = ?', $values);
    }
  }
	
  private function JoinTable(Doctrine_Query $q){
		if(empty($this->rootAlias)){
			$request  = sfContext::getInstance()->getRequest();
			$this->rootAlias = $q->getRootAlias();
      $q->leftJoin($this->rootAlias.'.Translation t')
      ->andWhere('t.lang = ?', $request->getParameter('sf_culture', 'ro')); // or it will search in all of them
		}
	}
	
  public function getFields(){
    return parent::getFields() + array('type' => 'Text') + array('title' => 'Text');
  }
}


$request = sfContext::getInstance()->getRequest();
//this is not working so please tell me how to access the request in the filter...

[Updated on: Mon, 19 July 2010 03:42]


Using SYMFONY 1.4.6
Previous Topic:How to remove a partial cache which is contextual ?
Next Topic:symfony templating component
Goto Forum:
  

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