- Posts: 29
COMMUNITY FORUM
- Forum
- K2 Community Forum
- English K2 Community
- k2 item > Update "ordering" when moving it from one category to another
k2 item > Update "ordering" when moving it from one category to another
- RomyS
- Topic Author
- Offline
- Junior Member
Less
More
3 years 9 months ago #178099
by RomyS
k2 item > Update "ordering" when moving it from one category to another was created 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
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.
- JoomlaWorks
- Offline
- Admin
Less
More
- Posts: 6218
3 years 9 months ago #178115
by JoomlaWorks
Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by JoomlaWorks on topic k2 item > Update "ordering" when moving it from one category to another
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.
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
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 29
3 years 9 months ago - 3 years 9 months ago #178133
by RomyS
Replied by RomyS on topic k2 item > Update "ordering" when moving it from one category to another
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
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.
- JoomlaWorks
- Offline
- Admin
Less
More
- Posts: 6218
3 years 9 months ago #178145
by JoomlaWorks
Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by JoomlaWorks on topic k2 item > Update "ordering" when moving it from one category to another
Seems OK.
Since we don't explicitly set any ordering on save, it should not conflict with anything.
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
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 29
3 years 9 months ago #178148
by RomyS
Replied by RomyS on topic k2 item > Update "ordering" when moving it from one category to another
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
Regards
Please Log in or Create an account to join the conversation.
- JoomlaWorks
- Offline
- Admin
Less
More
- Posts: 6218
3 years 9 months ago #178155
by JoomlaWorks
Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by JoomlaWorks on topic k2 item > Update "ordering" when moving it from one category to another
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
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 29
3 years 9 months ago #178192
by RomyS
Replied by RomyS on topic k2 item > Update "ordering" when moving it from one category to another
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!
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.
- JoomlaWorks
- Offline
- Admin
Less
More
- Posts: 6218
3 years 9 months ago #178200
by JoomlaWorks
Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by JoomlaWorks on topic k2 item > Update "ordering" when moving it from one category to another
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.
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.
- Forum
- K2 Community Forum
- English K2 Community
- k2 item > Update "ordering" when moving it from one category to another