Keyword

k2 item > Update "ordering" when moving it from one category to another

  • RomyS
  • RomyS's Avatar Topic Author
  • Offline
  • Junior Member
More
3 years 9 months ago #178099 by RomyS
Hi Fotis!
I have a problem with the "ordering" when copying an article and then changing it category. The article still maintains the same order as in its previous category, so it appears very low when ordering it manually ... Can you tell me if I can touch the /tables/k2item.php or /model/item.php so that when it changes category, also check the last order of that new category?

Something like that, but when saving an article if it changes its category ...
$this->table->getNextOrder("catid = {$post} AND trash = 0");

I hope you can help me to solve this, I would appreciate it very much.

regards

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

More
3 years 9 months ago #178115 by JoomlaWorks
We don't specify any ordering as you may notice from the code.

As such, you'll have to edit the save method in the item's backend model and if you detect a category change, query the items table for the new category's items and get the highest ordering so you can "move" the item upon saving.

Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

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

  • RomyS
  • RomyS's Avatar Topic Author
  • Offline
  • Junior Member
More
3 years 9 months ago - 3 years 9 months ago #178133 by RomyS
Thanks again, Fotis!

This works for me. How you see it?


if (!$isNew) {
$id = JRequest::getInt('id');
$currentRow = JTable::getInstance('K2Item', 'Table');
$currentRow->load($id);
if ($currentRow->catid !== $row->catid ) {

$row->ordering = $row->getNextOrder("catid = ".(int)$row->catid." AND trash = 0");

}
}


Can it generate a conflict with other lines, or affect the queries of the database?

I would appreciate your help!
regards
Last edit: 3 years 9 months ago by RomyS.

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

More
3 years 9 months ago #178145 by JoomlaWorks
Seems OK.

Since we don't explicitly set any ordering on save, it should not conflict with anything.

Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

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

  • RomyS
  • RomyS's Avatar Topic Author
  • Offline
  • Junior Member
More
3 years 9 months ago #178148 by RomyS
Excellent, thank you very much for confirming! I will apply it and test it for a few days and then I will write to you again.
Regards

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

More
3 years 9 months ago #178155 by JoomlaWorks
Awaiting for your feedback.

Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

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

  • RomyS
  • RomyS's Avatar Topic Author
  • Offline
  • Junior Member
More
3 years 9 months ago #178192 by RomyS
Update: everything works ok! Without problems and ordering in each case when saving the article in a different category.
We give the post by Solved? Is the hack useful for new k2 updates?

Thank you very much team!

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

More
3 years 9 months ago #178200 by JoomlaWorks
No need to add "solved". :)

As for getting this into K2, it's really an edge case. I can add a ton of edge cases but that would balloon the K2 settings and it's not worth it.

Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

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


Powered by Kunena Forum