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 » plugins » User management plugins » Admin generator foreign key sort Doctrine (Solved)
Admin generator foreign key sort Doctrine (Solved) [message #96785] Mon, 05 April 2010 01:10 Go to next message
rernst  is currently offline rernst
Messages: 82
Registered: October 2009
Member
Hi,

I have seen a variety of posts on the subject but no real solution (?!?) for my case. I am running 1.4 with Doctrine. The Advanced Admin Generator plugin has not been available for a long time.

Does anyone know how to get this to work again?

[Updated on: Fri, 07 May 2010 00:27]

Re: Admin generator foreign key sort Doctrine [message #96831 is a reply to message #96785 ] Tue, 06 April 2010 02:25 Go to previous messageGo to next message
rernst  is currently offline rernst
Messages: 82
Registered: October 2009
Member
Bump? I thought Doctrine was the default ORM for 1.4 now, now foreign key sort possible? Can someone at least verify this?

I have looked at the generated code and I guess the method to add the sort would be possible but I do not see how to establish the column header click with the action that manages the sort.
Re: Admin generator foreign key sort Doctrine [message #96965 is a reply to message #96831 ] Thu, 08 April 2010 15:19 Go to previous messageGo to next message
rernst  is currently offline rernst
Messages: 82
Registered: October 2009
Member
Bump another time. How do I modify this thing (Doctrine) to achieve this? Solutions are for Propel.
Re: Admin generator foreign key sort Doctrine [message #97121 is a reply to message #96785 ] Sun, 11 April 2010 14:11 Go to previous messageGo to next message
chris89  is currently offline chris89
Messages: 10
Registered: January 2009
Junior Member
Have you found a solution for this problem yet? I'd be very intressed in this because i have the same Problem in my Backend, too.
Re: Admin generator foreign key sort Doctrine [message #97125 is a reply to message #97121 ] Sun, 11 April 2010 16:06 Go to previous messageGo to next message
Fabrizio  is currently offline Fabrizio
Messages: 4
Registered: January 2010
Location: Italy
Junior Member
I too have the same problem.
Any advice on how you can add sorting to columns with foreign key?
Re: Admin generator foreign key sort Doctrine [message #97222 is a reply to message #97121 ] Tue, 13 April 2010 03:27 Go to previous messageGo to next message
rernst  is currently offline rernst
Messages: 82
Registered: October 2009
Member
You new, never did. I have the sincere belief that despite the 'officialdom' of Doctrine for 1.4 there is only a tiny fraction of actual users. Sad to see and even sadder to have invested effort into it. Embarassed

I think eventually this will change and Doctrine certainly at this point is the stronger option but Propel is far from dead and as far as true usability is concerned the preferred option.

My two cents.
Re: Admin generator foreign key sort Doctrine [message #98634 is a reply to message #97222 ] Fri, 07 May 2010 00:38 Go to previous messageGo to next message
rernst  is currently offline rernst
Messages: 82
Registered: October 2009
Member
Ok, this is how I solved the problem. First of all I overrode AddSortQuery in my actions class like this:

    protected function addSortQuery($query) {
        if (array(null, null) == ($sort = $this->getSort())) {
            return;
        }
        $s = $sort[0];
        $fields = $this->varHolder->get('configuration')->getFieldsDefault();
        if ($fields != null) {
            $field = $fields[$s];
            if ($field != null) {
                if (isset($field["sortBy"])) {
                    $criterion = $field["sortBy"];
                    if ($criterion != null) {
                        $s = $criterion;
                    }
                }
            }

        }

        $query->addOrderBy($s . ' ' . $sort[1]);
    }

What this essentially does is check whether the configuration file (yml generator) has a 'sortBy' definition. This would look like this:

        breed:            { label: Primary breed, sortBy : b.description }


The sortBy definition defines the table and field in that table that this foreign key references. This allows flexibility in respect to the fact that any field can be used and there is no need to enforce naming conventions.

Now we still need to make sure that the hyperlink for sorting shows up in the header of the table.

The second part is a bit of a pain because it requires you to override a template in the admin generator. You either copy the existing admin generator template (and thus create your own admin generator) or edit the existing one (I use the sfAdminThemejRollerPlugin so I simply changed that one - recommended plugin but has a few bugs that I fixed first).

The file you are after is _list_th_tabular.php. Towards the top of the file is a line that reads something like this:

<?php if ($field->isReal()): ?>


This checks whether the field in question is an actual column in the table. All you have to do is add a definition that checks whether 'orderBy' has been defined for this field, so change the line to read:

<?php if ($field->isReal() || $field->getConfig('sortBy')): ?>


Note that this may look slightly different depending upon which exact admin theme you are using.

If you need to sort by partials you can work similarly. Note that this method also allows you to override what exactly you sort by if you click on 'real' sort by table columns.

Hope this all makes sense.
Re: Admin generator foreign key sort Doctrine [message #102821 is a reply to message #98634 ] Tue, 20 July 2010 19:55 Go to previous message
bodidd  is currently offline bodidd
Messages: 1
Registered: July 2010
Junior Member
not sure what version post by rernst was for. for 1.4, this worked for me. thanks to rernst because i wouldn't have come up with it on my own.

  protected function addSortQuery($query)
  {
    $rootAlias = $query->getRootAlias();
    if (array(null, null) == ($sort = $this->getSort()))
    {
      return;
    }
    $s = $sort[0];
    $fields = $this->varHolder->get('configuration')->getFieldsDefault();
    if ($fields != null)
    {
      $field = $fields[$s];
      if ($field != null)
      {
        if (isset($field["sortBy"]))
        {
          $criterion = $field["sortBy"];
          if ($criterion != null)
          {
            $s = $criterion;
          }
        }
      }
    }
    $query->addOrderBy($rootAlias.'.'.$s . ' ' . $sort[1]);
  }

[Updated on: Tue, 20 July 2010 21:23]

Previous Topic:sfDoctrineGuardPlugin few kinds of user data
Next Topic:SfDoctrineGuardPlugin : How to desecure the action of a module
Goto Forum:
  

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