/**
* Copy a single node and return the new id
*
* @param $data
* @return mixed
*/
public function copyNode($sn_data){
$this->db2->insert('items_configurations', $sn_data);
return $this->db2->insert_id();
}
/**
* Return a list of child nodes as an assoziative array
* from a given parent
*
* @param $parent_id
* @return mixed
*/
public function childList($parent_id){
$tmp = 'SELECT parent_id,item_id,template_id,position FROM items_templates WHERE parent_id='.$parent_id;
$
query=$this->db2->
query($tmp);
return $
query->result_array();
}
/**
* Copy the whole tree structure through an recursive function
*
* @param $node_data
*/
public function copyTree($node_data){
$new_parent = $this->copyNode($node_data);
$new_data = $this->childList($node_data['parent_id']);
if(is_array($new_data)){
foreach($new_data as $new_node_data) :
$new_node_data['parent_id'] = $new_parent;
$this->copyTree($new_node_data);
endforeach;
}
}