Exemple #1
0
 /**
  * @see ItemClassInterface::delete()
  * @return bool
  */
 public function delete()
 {
     global $transaction;
     if ($this->class_id and $this->item_class and $this->item_has_item_class) {
         $transaction_id = $transaction->begin();
         $item_link_array = $this->list_items();
         if (is_array($item_link_array) and count($item_link_array) >= 1) {
             foreach ($item_link_array as $key => $value) {
                 $item_has_item_class_access = new ItemHasItemClass_Access($value);
                 if ($item_has_item_class_access->delete() == false) {
                     if ($transaction_id != null) {
                         $transaction->rollback($transaction_id);
                     }
                     return false;
                 }
             }
         }
         $item_information_array = ItemInformation::list_class_information($this->class_id);
         if (is_array($item_information_array) and count($item_information_array) >= 1) {
             foreach ($item_information_array as $key => $value) {
                 $item_information = new ItemInformation($value);
                 if ($item_information->unlink_class($this->class_id) == false) {
                     if ($transaction_id != null) {
                         $transaction->rollback($transaction_id);
                     }
                     return false;
                 }
             }
         }
         if ($this->item_class->delete() == true) {
             if ($transaction_id != null) {
                 $transaction->commit($transaction_id);
             }
             $this->__destruct();
             return true;
         } else {
             if ($transaction_id != null) {
                 $transaction->rollback($transaction_id);
             }
             return false;
         }
     } else {
         return false;
     }
 }
 /**
  * Get item informations for rendering item_informations.
  *
  * @return void
  */
 public function getItemInformations()
 {
     global $data;
     global $settings;
     // get target item informations
     $this->getTargetItemInformations();
     $array = array();
     foreach ($settings['item_informations'] as $code => $item_informations) {
         $array[$code] = ItemInformation::whereIn('code', $item_informations)->get()->toArray();
         $arraySecond = array();
         foreach ($array[$code] as $key => $row) {
             $row['settings'] = json_decode($row['settings'], true);
             $arraySecond[$row['code']] = $row;
         }
         $array[$code] = $arraySecond;
     }
     $data['item_informations'] = $array;
 }
 /**
  * @see ProjectItemInterface::set_information()
  * @param string $description
  * @param string $keywords
  * @return bool
  */
 public function set_information($description, $keywords)
 {
     global $transaction;
     if ($description or $keywords) {
         $transaction_id = $transaction->begin();
         $item_information = new ItemInformation(null);
         if ($item_information->create($description, $keywords) != null) {
             if ($this->is_item_information() != false or $this->is_class_information(true) != false) {
                 if ($this->is_item_information() != false) {
                     $item_information->link_item($this->item_id);
                 }
                 if ($this->is_class_information(true) != false) {
                     $item_information->link_class($this->item_class_id);
                 }
                 if ($transaction_id != null) {
                     $transaction->commit($transaction_id);
                 }
                 return true;
             } else {
                 if ($transaction_id != null) {
                     $transaction->rollback($transaction_id);
                 }
                 return false;
             }
         } else {
             if ($transaction_id != null) {
                 $transaction->rollback($transaction_id);
             }
             return false;
         }
     } else {
         return false;
     }
 }
Exemple #4
0
 /**
  * Deletes an item
  * @return bool
  * @throws ItemDeleteInformationException
  * @throws ItemDeleteClassException
  * @throws ItemDeleteEventFailedException
  * @throws ItemDeleteFailedException
  * @throws ItemNoInstanceException
  */
 protected function delete()
 {
     global $transaction;
     if ($this->item_id and $this->item) {
         $transaction_id = $transaction->begin();
         try {
             $item_information_array = ItemInformation::list_item_information($this->item_id);
             if (is_array($item_information_array) and count($item_information_array) >= 1) {
                 foreach ($item_information_array as $key => $value) {
                     $item_information = new ItemInformation($value);
                     if ($item_information->unlink_item($this->item_id) == false) {
                         throw new ItemDeleteInformationException();
                     }
                 }
             }
             // Item Classes
             $item_class_array = ItemClass::list_classes_by_item_id($this->item_id);
             if (is_array($item_class_array) and count($item_class_array) >= 1) {
                 foreach ($item_class_array as $key => $value) {
                     $item_class = new ItemClass($value);
                     if ($item_class->unlink_item($this->item_id) == false) {
                         throw new ItemDeleteClassException();
                     }
                 }
             }
             // Event
             $item_delete_event = new ItemDeleteEvent($this->item_id);
             $event_handler = new EventHandler($item_delete_event);
             if ($event_handler->get_success() == false) {
                 throw new ItemDeleteEventFailedException();
             }
             if ($this->item->delete() == false) {
                 throw new ItemDeleteFailedException();
             }
         } catch (BaseException $e) {
             if ($transaction_id != null) {
                 $transaction->rollback($transaction_id);
             }
             throw $e;
         }
         if ($transaction_id != null) {
             $transaction->commit($transaction_id);
         }
         return true;
     } else {
         throw new ItemNoInstanceException();
     }
 }