Keyword

Sort itemAuthorLatest in itemView by custom field

  • Gerben
  • Gerben's Avatar Topic Author
  • Offline
  • Senior Member
More
11 years 8 months ago #119290 by Gerben
Hi there,

I know how to sort the items (to create a menu item and link it to a user)
How can this be done for all the users in once? I made a custom field in the database that users can update so they can set the items on top of there page.

I have the same problem on the userView page. The items in the userItemList are sorting by date but i want to sort them by custom field.
Where can i set this to a custom database field?

Really looking forward to a answer to this, trying to find a solution for a week but just can't find it :)

Geppie

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
11 years 8 months ago #119291 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: Sort itemAuthorLatest in itemView by custom field
Hello Geppie,

By default K2 does not support this functionality, however there are several extensions posted ad the JED or at the extend K2 section of this site that offer filtering from extrafields.

Please Log in or Create an account to join the conversation.

  • Gerben
  • Gerben's Avatar Topic Author
  • Offline
  • Senior Member
More
11 years 8 months ago - 11 years 8 months ago #119292 by Gerben
Hi Krikor,

Thank you for your quick reply. I found a way to filter the itemAuthorLatest items.

I did this by modify the models/itemlist.php
function getAuthorLatest and then added ORDER BY i.neworder ASC"; on row 856

But i can not find the way how the sort to userItemList in the userview.
Do you know where i can find this or add this option?

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
11 years 8 months ago #119293 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: Sort itemAuthorLatest in itemView by custom field
The query is built using cases. Try looking for case 'user'.

Although I strongly recommend you against doing this because it is a core hack.
In the next update you will lose all of your changes and you wlll need to reapply them.

Please Log in or Create an account to join the conversation.

  • Gerben
  • Gerben's Avatar Topic Author
  • Offline
  • Senior Member
More
11 years 8 months ago #119294 by Gerben
Thank you for warning me Krikor but i have to filter by this custom field.
I found the case user but can't see where to put the "ORDER BY i.neworder ASC"

I will keep on trying :) Can you give me another push in the right direction?

Thanks

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
11 years 8 months ago #119295 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: Sort itemAuthorLatest in itemView by custom field
$query is the variable for building the $query, so you need to edit this variable.

Please Log in or Create an account to join the conversation.

  • Gerben
  • Gerben's Avatar Topic Author
  • Offline
  • Senior Member
More
11 years 7 months ago #119296 by Gerben
Yes, i was thinking that but how can i order the query :)

$query .= " AND i.created_by={$id} AND i.created_by_alias='' ";

Must be this?

$query .= " AND i.created_by={$id} AND i.created_by_alias=' ' ORDER BY i.neworder ASC" ;

But is not working..

Please Log in or Create an account to join the conversation.

  • Gerben
  • Gerben's Avatar Topic Author
  • Offline
  • Senior Member
More
11 years 7 months ago #119297 by Gerben
Krikor, any idea how to set the sort/order option?

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
11 years 7 months ago #119298 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: Sort itemAuthorLatest in itemView by custom field
There are several cases for $ordering switch ($ordering)

Make sure these predefined values are not overriding your query, eg. make sure the 'user' case is not inheriting these values.

Please Log in or Create an account to join the conversation.

  • Gerben
  • Gerben's Avatar Topic Author
  • Offline
  • Senior Member
More
11 years 7 months ago #119299 by Gerben
That's a lot more difficult to do then it sounds :D

I added to the ordering switch ($ordering)

case 'neworder' :
$orderby = 'i.neworder ASC';
break;

But how can i insert this into the case 'user' ?

It's breaking my mind for more then a week now :D

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
11 years 7 months ago #119300 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: Sort itemAuthorLatest in itemView by custom field
I would follow a different approach

Is the case == user
do the custom ordering
else for all other cases
$query .= " ORDER BY ".$orderby;

Line 337 approx.

Please Log in or Create an account to join the conversation.

  • Gerben
  • Gerben's Avatar Topic Author
  • Offline
  • Senior Member
More
11 years 7 months ago #119301 by Gerben
Cheers Krikor for pushing me in the good direction.

Fixed it with this:

if ($task == 'user')
{

$query .= " ORDER BY i.neworder ASC";
}
else{

$query .= " ORDER BY ".$orderby;
}

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
11 years 7 months ago #119302 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: Sort itemAuthorLatest in itemView by custom field
Congrats :)

Remember to back it up so you won't lose it.

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum