/**
  * 
  */
 public function saveComposition($content, $product_array_streams, $studio_id, $design_array_streams = array(), $design_data = array())
 {
     try {
         $response = array();
         $xml = @simplexml_load_string($content);
         if (!is_object($xml)) {
             return array("ERROR" => "Error reading XML");
         } else {
             if (isset($this->session->data["user_id"]) || isset($this->session->data["customer_id"])) {
                 if (isset($this->session->data["user_id"])) {
                     $id_author = 0;
                 } else {
                     $id_author = $this->session->data["customer_id"];
                 }
                 $idea = new DesignIdea($this->db);
                 $data["product_id"] = $xml["id_product"];
                 $data["id_product_color"] = $xml["id_product_color"];
                 $data["name"] = utf8_encode($xml["name"]);
                 $data["id_author"] = $id_author;
                 if (!empty($xml["id_composition"]) && $idea->compositionExists($xml["id_composition"])) {
                     $data["id_composition"] = (string) $xml["id_composition"];
                 }
                 $idea->setFieldsData($data);
                 $i = 0;
                 foreach ($xml->design as $design_node) {
                     $designObj = new Design($this->db);
                     $designObj->setXML(utf8_encode($design_node->asXML()));
                     $designObj->setSnapshot($product_array_streams[$i]);
                     if (isset($design_array_streams[$i])) {
                         $designObj->setOnlyDesignSnapshot($design_array_streams[$i]);
                     }
                     if (isset($design_data[$i])) {
                         $designObj->setNumColors($design_data[$i]->num_colors);
                         $designObj->setNeedWhiteBase($design_data[$i]->need_white_base);
                     }
                     foreach ($design_node->design_element as $design_element_node) {
                         $design_element = new DesignElement($this->db);
                         $design_element->setDesignElement($design_element_node['id']);
                         $design_element->setType($design_element_node['type']);
                         $designObj->addDesignElement($design_element);
                     }
                     $idea->addDesign($designObj);
                     $i++;
                 }
                 if ($id_comp = $idea->save()) {
                     $this->session->data['studio_data'][$studio_id]['id_composition'] = $id_comp;
                     return array("id_composition" => $id_comp);
                     //everything ok!
                 } else {
                     return array("ERROR" => "error saving composition " . $idea->last_error);
                 }
             } else {
                 return array("ERROR" => "User not logged in ");
             }
         }
     } catch (Exception $e) {
         return array("ERROR" => (string) $e);
     }
 }