/**
  * @see ProjectTemplateInterface::create()
  * @param integer $data_entity_id
  * @param integer $category_id
  * @param bool $parent_template
  * @return bool
  * @throws ProjectTemplateCreateException
  * @throws ProjectTemplateCreateOLDLNotFoundException
  * @throws ProjectTemplateCreateOLDLCreateException
  */
 public function create($data_entity_id, $category_id, $parent_template)
 {
     global $transaction;
     if ($this->project_template and is_numeric($data_entity_id) and is_numeric($category_id) and isset($parent_template)) {
         $xml_cache = new XmlCache($data_entity_id);
         $xml_array = $xml_cache->get_xml_array();
         $oldl_found = false;
         $title_found = false;
         $id_found = false;
         $id = null;
         $title = "";
         if (is_array($xml_array) and count($xml_array) >= 1) {
             foreach ($xml_array as $key => $value) {
                 $value[1] = trim(strtolower($value[1]));
                 $value[2] = trim($value[2]);
                 if ($value[1] == "oldl" and $value[2] != "#") {
                     if ($value[3]['type']) {
                         if ($value[3]['type'] != "project") {
                             return false;
                         }
                     }
                     $oldl_found = true;
                 }
                 if ($value[1] == "title" and $value[2] != "#") {
                     if ($value[2]) {
                         $title = trim($value[2]);
                         $title_found = true;
                     }
                 }
                 if ($value[1] == "id" and $value[2] != "#") {
                     if ($value[2]) {
                         if (is_numeric(trim($value[2]))) {
                             $id = (int) trim($value[2]);
                             $id_found = true;
                         }
                     }
                 }
             }
             if ($oldl_found == false or $title_found == false) {
                 throw new ProjectTemplateCreateOLDLNotFoundException();
             }
             $transaction_id = $transaction->begin();
             $oldl = new Oldl(null);
             if (($oldl_id = $oldl->create($data_entity_id)) == null) {
                 if ($transaction_id != null) {
                     $transaction->rollback($transaction_id);
                 }
                 throw new ProjectTemplateCreateOLDLCreateException();
             }
             if ($this->project_template->create($id, $title, $category_id, $parent_template, $oldl_id) == false) {
                 if ($transaction_id != null) {
                     $transaction->rollback($transaction_id);
                 }
                 throw new ProjectTemplateCreateException("DB Failed");
             } else {
                 if ($transaction_id != null) {
                     $transaction->commit($transaction_id);
                 }
                 return true;
             }
         } else {
             throw new ProjectTemplateCreateException("XML File Empty or Corrupt");
         }
     } else {
         throw new ProjectTemplateCreateException("Missing Information");
     }
 }
 /**
  * @see SampleTemplateInterface::create()
  * @param integer $object_id
  * @param integer $category_id
  * @return bool
  */
 public function create($data_entity_id, $category_id)
 {
     global $transaction;
     if ($this->sample_template and is_numeric($data_entity_id) and is_numeric($category_id)) {
         $xml_cache = new XmlCache($data_entity_id);
         $xml_array = $xml_cache->get_xml_array();
         $oldl_found = false;
         $title_found = false;
         $id_found = false;
         $id = null;
         $title = "";
         if (is_array($xml_array) and count($xml_array) >= 1) {
             foreach ($xml_array as $key => $value) {
                 $value[1] = trim(strtolower($value[1]));
                 $value[2] = trim($value[2]);
                 if ($value[1] == "oldl" and $value[2] != "#") {
                     if ($value[3]['type']) {
                         if ($value[3]['type'] == "sample") {
                             $oldl_found = true;
                         }
                     }
                 }
                 if ($value[1] == "title" and $value[2] != "#") {
                     if ($value[2]) {
                         $title = trim($value[2]);
                         $title_found = true;
                     }
                 }
                 if ($value[1] == "id" and $value[2] != "#") {
                     if ($value[2]) {
                         if (is_numeric(trim($value[2]))) {
                             $id = (int) trim($value[2]);
                             $id_found = true;
                         }
                     }
                 }
             }
             if ($oldl_found == false or $title_found == false) {
                 return false;
             }
             $transaction_id = $transaction->begin();
             $oldl = new Oldl(null);
             if (($oldl_id = $oldl->create($data_entity_id)) == null) {
                 if ($transaction_id != null) {
                     $transaction->rollback($transaction_id);
                 }
                 return false;
             }
             if ($this->sample_template->create($id, $title, $category_id, $oldl_id) == false) {
                 if ($transaction_id != null) {
                     $transaction->rollback($transaction_id);
                 }
                 return false;
             } else {
                 if ($transaction_id != null) {
                     $transaction->commit($transaction_id);
                 }
                 return true;
             }
         } else {
             return false;
         }
     } else {
         return false;
     }
 }