- Posts: 1
COMMUNITY FORUM
Copy Category
- dome412
-
Topic Author
- Offline
- New Member
subcategory1.1.1
subcategory1.1.2----subcategory1.2
subcategory1.2.1
subcategory1.2.2category2--subcategory1
----subcategory1.1
subcategory1.1.1
subcategory1.1.2
----subcategory1.2
subcategory1.2.1
subcategory1.2.2
and so on for category 3, 4, 5, etc..As you can see every different category has got the same subcategories.What I need is to have a copy function that permit me to copy the root category in another one "copy of category"(that I will rename) with related subcategories.In k2 category section, there isn't a copy button like the standard joomla category section.Could anybody help me?Thanks a lot!Domenico
Please Log in or Create an account to join the conversation.
- Mario
-
- Offline
- New Member
- Posts: 2
My case is the follow.
I have a Portfolio Page. Portfolio is also my parent Category.
Then i have some Subcategories like Film, Musicvideo and some else.
On my "Home" Page, my first site on the Website, i would like to show some Categories from my Subcategories.
But k2 has no option to do that, because it is not possible to copy a Subcategory to another parent Category.
I dont understand this. Its a Joomla out of the box feature to show Articles from some Category on another Page in another Category, without to copy the Article.
I hope for this feature in the future. Or has anybody a little plugin or hack for this?
Thanks!
Please Log in or Create an account to join the conversation.
- Chrysanthos
-
- Offline
- New Member
- Posts: 12
Please Log in or Create an account to join the conversation.
- Jacob Friedman
-
- Offline
- New Member
- Posts: 2
______In views/categories/view.html.php on line 73 :______________
JToolBarHelper::custom('Duplicate','restore.png','restore_f2.png',JText::_('Duplicate'), true);
______In controllers/categories.php on line 99:____________________________________
function duplicate() {
$mainframe = &JFactory::getApplication();
$model = & $this->getModel('categories');
$model->duplicate();
}
______In models/categories.php at the end:____________________________________
function duplicate() {
$mainframe = &JFactory::getApplication();
$cid = JRequest::getVar('cid');
$db = & JFactory::getDBO();
$idpush = 1;
// GET CATEGORY //
$query = "SELECT id, name, alias, description, parent, extraFieldsGroup, published, access, ordering, image, params, trash, plugins FROM #__k2_categories WHERE id={$cid[0]}";
$db->setQuery($query);
$result = $db->loadObject();
// GET HIGHEST ID //
$maxIDquery = "SELECT id FROM #__k2_categories ORDER BY id DESC LIMIT 3";
$db->setQuery($maxIDquery);
$maxID = $db->loadResult();
$highID = $maxID + $idpush;
$result->id = $highID;
$topparent = $highID;
$highID++;
// INSERT TOP-LEVEL PARENT //
$db->insertObject( '#__k2_categories', $result , 'id');
// GET CHILDREN //
$childrenquery = "SELECT id,trash FROM #__k2_categories WHERE parent={$cid[0]} AND trash=0";
$db->setQuery($childrenquery);
// CHILDREN / SUBCHILDREN //
$children = $db->loadResultArray();
$subChildren = array();
// FIND SUBCHILDREN, INSERT CHILD //
foreach($children as $child) {
$query = "SELECT id, name, alias, description, parent, extraFieldsGroup, published, access, ordering, image, params, trash, plugins FROM #__k2_categories WHERE id={$child} AND trash=0";
$db->setQuery($query);
$result1 = $db->loadObject();
$result1->id = $highID;
$result1->parent = $topparent;
$highID++;
// INSERT CHILD //
$db->insertObject( '#__k2_categories', $result1 , 'id');
$childquery = "SELECT id,trash FROM #__k2_categories
WHERE parent={$child} AND trash=0";
$db->setQuery($childquery);
$subChildrenQuery = $db->loadResultArray();
if($subChildrenQuery[0]){
foreach ($subChildrenQuery as $subChild) {
$query = "SELECT id, name, alias, description, parent, extraFieldsGroup, published, access, ordering, image, params, trash, plugins FROM #__k2_categories WHERE id={$subChild} AND trash=0";
$db->setQuery($query);
$result = $db->loadObject();
$result->id = $highID;
$result->parent = $result1->id;
$highID++;
// INSERT CHILD //
$db->insertObject( '#__k2_categories', $result , 'id');
}
}
}
$row = & JTable::getInstance('K2Category', 'Table');
foreach ($cid as $id) {
$row->load($id);
$row->publish($id, 1);
}
$cache = & JFactory::getCache('com_k2');
$cache->clean();
$msg = JText::_(count($children));
$mainframe->redirect('index.php?option=com_k2&view=categories', $msg);
}
}
Please Log in or Create an account to join the conversation.
- Jacob Friedman
-
- Offline
- New Member
- Posts: 2
Please Log in or Create an account to join the conversation.
- Peter Gasser
-
- Offline
- New Member
- Posts: 3
I have my "duplicate categories button" now
Thanks
Peter
Jacob Friedman said:Sorry, everything here's located in /administrator/components/com_k2. Drop it in, ready to roll. Cheers :)
Please Log in or Create an account to join the conversation.
- irish
-
- Offline
- Senior Member
- Posts: 53
The problem I was having with your code was that in the "models/categories.php at the end:" part, I had to replace the last " } " with your code.
Now all you will have to do is download the attached zip file and extract it on your local system or hard drive and upload the com_k2 folder and all contents to your servers: administrator/components/ folder and overwrite the com_k2 folders and files. Only the changed files for the duplication (copy categories) will be overwritten.
I have only tested this on K2 Component v2.3
Always! before changing core files make a backup in case you have problems.
Personally I keep a copy or backup of my server files on a disk in house. On test servers I usually browse all files to be changed on the server and rename them by adding "-saved" without the "quotes " to the end of a file name then upload the new files.
I have noticed that when trying to copy third level categories in number that it will only copy one at a time but if you copy any parent category along with its subs everything works just fine.
If you only want to copy the sub categories of the parent (to add them to another parent) just include the parent and once parent and subs are duplicated or copied select all subs and: 1) move the selected subs to an existing category or 2) rename the the parent and don't forget to check and see if the copied subs are attached to the correct parent which they should be once parent is renamed.
Hope this addition to Jacob Friedman's contribution helps...
Personally I think something like this should be expanded and included in the K2 Components core files as it is implicated in Joomla's core!
How about everyone else? please post comments so we can get this done....
Thanks again
irish
Please Log in or Create an account to join the conversation.
- Peter Gasser
-
- Offline
- New Member
- Posts: 3
Anybody has code for that?
Thanks
Peter
Please Log in or Create an account to join the conversation.
- irish
-
- Offline
- Senior Member
- Posts: 53
Peter Gasser said:The above code works perfect to copy categories, but I would also like to copy the sample content in this categories for various clients. Anybody has code for that?
Thanks
Peter
Please Log in or Create an account to join the conversation.
- Peter Gasser
-
- Offline
- New Member
- Posts: 3
Anybody has code for that?
Thanks
Peter
Jacob Friedman said:Sorry, everything here's located in /administrator/components/com_k2. Drop it in, ready to roll. Cheers :)
Please Log in or Create an account to join the conversation.
- Milan Stajkovic
-
- Offline
- New Member
- Posts: 5
irish said:Thank you for this "Jacob Friedman" it has been a big help. I had to figure out how to get it to work and since there were only two files in your post I went ahead and sorted out my issues and created a zip file with the correct paths and attached files. Hope you don't mind. The problem I was having with your code was that in the "models/categories.php at the end:" part, I had to replace the last " } " with your code.
Now all you will have to do is download the attached zip file and extract it on your local system or hard drive and upload the com_k2 folder and all contents to your servers: administrator/components/ folder and overwrite the com_k2 folders and files. Only the changed files for the duplication (copy categories) will be overwritten.
I have only tested this on K2 Component v2.3
Always! before changing core files make a backup in case you have problems.
Personally I keep a copy or backup of my server files on a disk in house. On test servers I usually browse all files to be changed on the server and rename them by adding "-saved" without the "quotes " to the end of a file name then upload the new files.
I have noticed that when trying to copy third level categories in number that it will only copy one at a time but if you copy any parent category along with its subs everything works just fine.
If you only want to copy the sub categories of the parent (to add them to another parent) just include the parent and once parent and subs are duplicated or copied select all subs and: 1) move the selected subs to an existing category or 2) rename the the parent and don't forget to check and see if the copied subs are attached to the correct parent which they should be once parent is renamed.
Hope this addition to Jacob Friedman's contribution helps...
Personally I think something like this should be expanded and included in the K2 Components core files as it is implicated in Joomla's core!
How about everyone else? please post comments so we can get this done....
Thanks again
irish
Please Log in or Create an account to join the conversation.
- Milan Stajkovic
-
- Offline
- New Member
- Posts: 5
Milan Stajkovic said:I did exactly what u said, its not workin for me. No category button in categories... By the way, i'm installing it to may local server, does that make any changes...? Tnx.. in advanced...
irish said:Thank you for this "Jacob Friedman" it has been a big help. I had to figure out how to get it to work and since there were only two files in your post I went ahead and sorted out my issues and created a zip file with the correct paths and attached files. Hope you don't mind. The problem I was having with your code was that in the "models/categories.php at the end:" part, I had to replace the last " } " with your code.
Now all you will have to do is download the attached zip file and extract it on your local system or hard drive and upload the com_k2 folder and all contents to your servers: administrator/components/ folder and overwrite the com_k2 folders and files. Only the changed files for the duplication (copy categories) will be overwritten.
I have only tested this on K2 Component v2.3
Always! before changing core files make a backup in case you have problems.
Personally I keep a copy or backup of my server files on a disk in house. On test servers I usually browse all files to be changed on the server and rename them by adding "-saved" without the "quotes " to the end of a file name then upload the new files.
I have noticed that when trying to copy third level categories in number that it will only copy one at a time but if you copy any parent category along with its subs everything works just fine.
If you only want to copy the sub categories of the parent (to add them to another parent) just include the parent and once parent and subs are duplicated or copied select all subs and: 1) move the selected subs to an existing category or 2) rename the the parent and don't forget to check and see if the copied subs are attached to the correct parent which they should be once parent is renamed.
Hope this addition to Jacob Friedman's contribution helps...
Personally I think something like this should be expanded and included in the K2 Components core files as it is implicated in Joomla's core!
How about everyone else? please post comments so we can get this done....
Thanks again
irish
Please Log in or Create an account to join the conversation.
- Julien Nicolas Immobilier
-
- Offline
- New Member
- Posts: 2
I've the same version of K2 than you (2.3).
Too bad because it would have help me a lot !!! K2 is fantastic but this "button copy categorie" should make it terrific !
Too many time when the structure of categories is repetitive :(
irish said:Thank you for this "Jacob Friedman" it has been a big help. I had to figure out how to get it to work and since there were only two files in your post I went ahead and sorted out my issues and created a zip file with the correct paths and attached files. Hope you don't mind. The problem I was having with your code was that in the "models/categories.php at the end:" part, I had to replace the last " } " with your code.
Now all you will have to do is download the attached zip file and extract it on your local system or hard drive and upload the com_k2 folder and all contents to your servers: administrator/components/ folder and overwrite the com_k2 folders and files. Only the changed files for the duplication (copy categories) will be overwritten.
I have only tested this on K2 Component v2.3
Always! before changing core files make a backup in case you have problems.
Personally I keep a copy or backup of my server files on a disk in house. On test servers I usually browse all files to be changed on the server and rename them by adding "-saved" without the "quotes " to the end of a file name then upload the new files.
I have noticed that when trying to copy third level categories in number that it will only copy one at a time but if you copy any parent category along with its subs everything works just fine.
If you only want to copy the sub categories of the parent (to add them to another parent) just include the parent and once parent and subs are duplicated or copied select all subs and: 1) move the selected subs to an existing category or 2) rename the the parent and don't forget to check and see if the copied subs are attached to the correct parent which they should be once parent is renamed.
Hope this addition to Jacob Friedman's contribution helps...
Personally I think something like this should be expanded and included in the K2 Components core files as it is implicated in Joomla's core!
How about everyone else? please post comments so we can get this done....
Thanks again
irish
Please Log in or Create an account to join the conversation.
- Julien Nicolas Immobilier
-
- Offline
- New Member
- Posts: 2
It work and work well also on K2 2.4 and Joomla 1.5.22 !
Thanks a lot...
P.S : My error was a fault of attention. Take care to copy the file on ADMINISTRATOR ! LOL
julien.nicolas said:It doesn't work for me... Is there because of my Joomla version 1.5.22 ? I've the same version of K2 than you (2.3).
Too bad because it would have help me a lot !!! K2 is fantastic but this "button copy categorie" should make it terrific !
Too many time when the structure of categories is repetitive :(
irish said:Thank you for this "Jacob Friedman" it has been a big help. I had to figure out how to get it to work and since there were only two files in your post I went ahead and sorted out my issues and created a zip file with the correct paths and attached files. Hope you don't mind. The problem I was having with your code was that in the "models/categories.php at the end:" part, I had to replace the last " } " with your code.
Now all you will have to do is download the attached zip file and extract it on your local system or hard drive and upload the com_k2 folder and all contents to your servers: administrator/components/ folder and overwrite the com_k2 folders and files. Only the changed files for the duplication (copy categories) will be overwritten.
I have only tested this on K2 Component v2.3
Always! before changing core files make a backup in case you have problems.
Personally I keep a copy or backup of my server files on a disk in house. On test servers I usually browse all files to be changed on the server and rename them by adding "-saved" without the "quotes " to the end of a file name then upload the new files.
I have noticed that when trying to copy third level categories in number that it will only copy one at a time but if you copy any parent category along with its subs everything works just fine.
If you only want to copy the sub categories of the parent (to add them to another parent) just include the parent and once parent and subs are duplicated or copied select all subs and: 1) move the selected subs to an existing category or 2) rename the the parent and don't forget to check and see if the copied subs are attached to the correct parent which they should be once parent is renamed.
Hope this addition to Jacob Friedman's contribution helps...
Personally I think something like this should be expanded and included in the K2 Components core files as it is implicated in Joomla's core!
How about everyone else? please post comments so we can get this done....
Thanks again
irish
Please Log in or Create an account to join the conversation.
- Milan Stajkovic
-
- Offline
- New Member
- Posts: 5
Always! before changing core files make a backup in case you have problems.
Personally I keep a copy or backup of my server files on a disk in house. On test servers I usually browse all files to be changed on the server and rename them by adding "-saved" without the "quotes " to the end of a file name then upload the new files.
I have noticed that when trying to copy third level categories in number that it will only copy one at a time but if you copy any parent category along with its subs everything works just fine.
If you only want to copy the sub categories of the parent (to add them to another parent) just include the parent and once parent and subs are duplicated or copied select all subs and: 1) move the selected subs to an existing category or 2) rename the the parent and don't forget to check and see if the copied subs are attached to the correct parent which they should be once parent is renamed.
Hope this addition to Jacob Friedman's contribution helps...
Personally I think something like this should be expanded and included in the K2 Components core files as it is implicated in Joomla's core!
How about everyone else? please post comments so we can get this done....
Thanks again
irish
Problem solved, sorry the mistake was mine!
Works perfect! Should be included in default version!
Please Log in or Create an account to join the conversation.