Example #1
0
 /**
  * @param string $json_argument_array
  * @return integer
  * @throws BaseAjaxDependentArgumentMissingException
  */
 public static function count_file_items($json_argument_array)
 {
     $argument_array = json_decode($json_argument_array);
     $handling_class = Item::get_holder_handling_class_by_name($argument_array[0][1]);
     if ($handling_class) {
         $sql = $handling_class . get_item_list_sql($argument_array[1][1]);
     }
     if ($sql) {
         return Data_Wrapper::count_item_files($sql);
     } else {
         throw new BaseAjaxDependentArgumentMissingException();
     }
 }
Example #2
0
 /**
  * @param string $json_argument_array
  * @return integer
  */
 public static function count_equipment_items($json_argument_array)
 {
     $argument_array = json_decode($json_argument_array);
     $handling_class = Item::get_holder_handling_class_by_name($argument_array[0][1]);
     if ($handling_class) {
         $sql = $handling_class::get_item_list_sql($argument_array[1][1]);
     }
     if ($sql) {
         return Equipment_Wrapper::count_item_equipments($sql);
     } else {
         return null;
     }
 }
Example #3
0
 /**
  * Generates an item menu entry with sub-items
  * @param array $element_array
  * @param integer $key
  * @param integer $counter
  * @param array $link_base
  * @param string $holder_class
  * @param string $holder_id
  * @return array
  */
 public static function get_menu_element($element_array, $key, $counter, $link_base, $holder_class, $holder_id)
 {
     $result = array();
     $amount = count($element_array['fulfilled']);
     if ($element_array['display'] == true) {
         if ($element_array['occurrence'] == "multiple" and $amount > 0) {
             $result[$counter]['name'] = $element_array['name'] . " (" . $amount . ")";
         } else {
             $result[$counter]['name'] = $element_array['name'];
         }
         $result[$counter]['depends'] = false;
         $item_handling_cass = $element_array['handling_class'];
         $paramquery = $link_base;
         $paramquery['run'] = "item_add";
         $paramquery['dialog'] = $element_array['type'];
         $paramquery['key'] = $key;
         $paramquery['retrace'] = Retrace::create_retrace_string();
         $item_add_occurrence_array = $item_handling_cass::get_item_add_occurrence($element_array['type']);
         if (!is_array($item_add_occurrence_array) or count($item_add_occurrence_array) != 3) {
             $item_add_occurrence_array = array(true, true, "deny");
         }
         if ($element_array['occurrence'] == "once" and $item_add_occurrence_array[0] == true and $item_add_occurrence_array[2] == "edit" and is_array($element_array['fulfilled']) and $amount >= 1) {
             $paramquery['run'] = "item_edit";
         }
         $item_add_dialog_array = $item_handling_cass::get_item_add_dialog($element_array['type']);
         if (is_array($item_add_dialog_array)) {
             if (in_array($element_array['dialog'], $item_add_dialog_array[0])) {
                 $item_array_type = $element_array['dialog'];
             } else {
                 $item_array_type = $item_add_dialog_array[1];
             }
             if (trim($item_array_type) == "window") {
                 $result[$counter]['type'] = "ajax";
                 $ajax_handling_array = $item_handling_cass::get_item_add_script_handling_class($element_array['type']);
                 require_once "core/modules/" . $ajax_handling_array[0];
                 $ajax_init_array = $ajax_handling_array[1]::$ajax_handling_array[2]($element_array['pos_id'], $paramquery, $element_array['type_id'], $element_array['category_id'], $holder_class, $holder_id);
                 $result[$counter]['script'] = $ajax_init_array['script'];
                 $result[$counter]['window_title'] = $ajax_init_array['window_title'];
                 $result[$counter]['window_id'] = $ajax_init_array['window_id'];
                 $result[$counter]['click_id'] = $ajax_init_array['click_id'];
             } else {
                 $result[$counter]['type'] = "link";
             }
         } else {
             $result[$counter]['type'] = "link";
         }
         if (is_array($element_array['fulfilled']) and $amount >= 1) {
             if ($element_array['occurrence'] == "multiple" and $item_add_occurrence_array[1] == true or $element_array['occurrence'] == "once" and $item_add_occurrence_array[0] == false or $element_array['occurrence'] == "once" and $item_add_occurrence_array[0] == true and $item_add_occurrence_array[2] == "edit") {
                 $result[$counter]['image'] = "add_done";
             } else {
                 $result[$counter]['type'] = false;
                 $result[$counter]['image'] = "add_done_na";
             }
         } else {
             $result[$counter]['image'] = "add";
         }
         if ($element_array['requirement'] == "optional") {
             $result[$counter]['name'] = $result[$counter]['name'] . " (optional)";
         }
         $params = http_build_query($paramquery, '', '&');
         $result[$counter]['params'] = $params;
         $counter++;
     }
     if (is_array($element_array['sub_items']) and count($element_array['sub_items']) >= 1) {
         $result[$counter]['type'] = "line";
         $counter++;
         $sub_item_irgnore_array = array();
         foreach ($element_array['sub_items'] as $sub_item_key => $sub_item_value) {
             foreach ($sub_item_value as $sub_sub_item_key => $sub_sub_item_value) {
                 if (!in_array($sub_sub_item_key, $sub_item_irgnore_array)) {
                     if ($sub_sub_item_value['element_type'] == "item") {
                         $paramquery = $link_base;
                         $paramquery['run'] = "sub_item_add";
                         $paramquery['dialog'] = $sub_sub_item_value['type'];
                         $paramquery['key'] = $sub_sub_item_value['pos_id'];
                         $paramquery['parent'] = $element_array['type'];
                         $paramquery['parent_key'] = $element_array['pos_id'];
                         if ($sub_sub_item_value['takeover'] == false) {
                             $paramquery['parent_id'] = $element_array['fulfilled'][$sub_item_key]['id'];
                         }
                         $paramquery['retrace'] = Retrace::create_retrace_string();
                         $item_handling_cass = $sub_sub_item_value['handling_class'];
                         $item_add_occurrence_array = $item_handling_cass::get_item_add_occurrence($sub_sub_item_value['type']);
                         if (!is_array($item_add_occurrence_array) or count($item_add_occurrence_array) != 3) {
                             $item_add_occurrence_array = array(true, true, "deny");
                         }
                         if ($sub_sub_item_value['occurrence'] == "once" and $item_add_occurrence_array[0] == true and $item_add_occurrence_array[2] == "edit" and is_array($sub_sub_item_value['fulfilled']) and count($sub_sub_item_value['fulfilled']) >= 1) {
                             $paramquery['run'] = "sub_item_edit";
                         }
                         $item_add_dialog_array = $item_handling_cass::get_item_add_dialog($sub_sub_item_value['type']);
                         if (is_array($item_add_dialog_array)) {
                             if (in_array($sub_sub_item_value['dialog'], $item_add_dialog_array[0])) {
                                 $item_array_type = $sub_sub_item_value['dialog'];
                             } else {
                                 $item_array_type = $item_add_dialog_array[1];
                             }
                             if (trim($item_array_type) == "window") {
                                 $result[$counter]['type'] = "ajax";
                                 $ajax_handling_array = $item_handling_cass::get_item_add_script_handling_class($sub_sub_item_value['type']);
                                 require_once "core/modules/" . $ajax_handling_array[0];
                                 $item_holder = Item::get_holder_handling_class_by_name($element_array['type']);
                                 // Type of the ItemHolder
                                 $ajax_init_array = $ajax_handling_array[1]::$ajax_handling_array[2]($sub_sub_item_value['pos_id'], $paramquery, $sub_sub_item_value['type_id'], $sub_sub_item_value['category_id'], $item_holder, $element_array['fulfilled'][$sub_item_key]['id']);
                                 $result[$counter]['script'] = $ajax_init_array['script'];
                                 $result[$counter]['window_title'] = $ajax_init_array['window_title'];
                                 $result[$counter]['window_id'] = $ajax_init_array['window_id'];
                                 $result[$counter]['click_id'] = $ajax_init_array['click_id'];
                             } else {
                                 $result[$counter]['type'] = "link";
                             }
                         } else {
                             $result[$counter]['type'] = "link";
                         }
                         if ($sub_sub_item_value['takeover'] == true) {
                             $result[$counter]['name'] = $sub_sub_item_value['name'] . " (all)";
                             array_push($sub_item_irgnore_array, $sub_sub_item_key);
                         } else {
                             if ($element_array['fulfilled'][$sub_item_key]['name']) {
                                 $result[$counter]['name'] = $sub_sub_item_value['name'] . " (" . $element_array['fulfilled'][$sub_item_key]['name'] . ")";
                             } else {
                                 $result[$counter]['name'] = $sub_sub_item_value['name'];
                             }
                         }
                         if (is_array($sub_sub_item_value['fulfilled'])) {
                             if ($sub_sub_item_value['occurrence'] == "multiple" and $item_add_occurrence_array[1] == true or $sub_sub_item_value['occurrence'] == "once" and $item_add_occurrence_array[0] == false or $sub_sub_item_value['occurrence'] == "once" and $item_add_occurrence_array[0] == true and $item_add_occurrence_array[2] == "edit") {
                                 $result[$counter]['image'] = "add_done";
                             } else {
                                 $result[$counter]['type'] = false;
                                 $result[$counter]['image'] = "add_done_na";
                             }
                         } else {
                             $result[$counter]['image'] = "add";
                         }
                         $params = http_build_query($paramquery, '', '&');
                         $result[$counter]['depends'] = true;
                         $result[$counter]['params'] = $params;
                         $counter++;
                     }
                 }
             }
             if ($result[$counter - 1]['type'] != "line") {
                 $result[$counter]['type'] = "line";
                 $counter++;
             }
         }
     }
     return array(0 => $result, 1 => $counter);
 }
 /**
  * @see EventListenerInterface::listen_events()
  * @param object $event_object
  * @return bool
  */
 public static function listen_events($event_object)
 {
     global $transaction;
     if ($event_object instanceof ItemAddHolderEvent) {
         $type = $event_object->get_type();
         if ($type == "sample") {
             $sample_id = $event_object->get_id();
             $item_id = $event_object->get_item_id();
             $gid = $event_object->get_gid();
             $transaction_id = $transaction->begin();
             if (self::create($sample_id, $item_id, $gid, null, null) == false) {
                 if ($transaction_id != null) {
                     $transaction->rollback($transaction_id);
                 }
                 return false;
             } else {
                 if ($transaction_id != null) {
                     $transaction->commit($transaction_id);
                 }
             }
         }
     }
     if ($event_object instanceof ItemAddEvent) {
         $get_array = $event_object->get_get_array();
         $post_array = $event_object->get_post_array();
         $item_holder = $event_object->get_item_holder();
         $item_holder_name = $event_object->get_item_holder_name();
         if ($get_array['nav'] == "sample" and is_numeric($get_array['sample_id']) and !$get_array['parent'] and !$get_array['parent_key']) {
             $transaction_id = $transaction->begin();
             if ($get_array['parent_sample'] == "1") {
                 $parent = true;
             } else {
                 $parent = false;
             }
             if ($item_holder == true and $item_holder_name) {
                 $item_holder_class = Item::get_holder_handling_class_by_name($item_holder_name);
                 $item_holder_instance = $item_holder_class::get_instance_by_item_id($event_object->get_item_id());
                 if (self::$sample_instance_array[$get_array['sample_id']]) {
                     $sample = self::$sample_instance_array[$get_array['sample_id']];
                 } else {
                     $sample = new Sample($get_array['sample_id']);
                     self::$sample_instance_array[$get_array['sample_id']] = $sample;
                 }
                 $required_sub_item_array = $sample->list_required_sub_items($get_array['key']);
                 if (is_array($required_sub_item_array) and count($required_sub_item_array) >= 1) {
                     if ($required_sub_item_array[0] == "all") {
                         $sub_item_array = $item_holder_instance->get_item_holder_items(null);
                         if (is_array($sub_item_array) and count($sub_item_array)) {
                             foreach ($sub_item_array as $sub_item_key => $sub_item_value) {
                                 if (self::create($get_array['sample_id'], $sub_item_value, null, null, null, $event_object->get_item_id()) == false) {
                                     if ($transaction_id != null) {
                                         $transaction->rollback($transaction_id);
                                     }
                                     return false;
                                 }
                                 if (DataEntity::is_kind_of("file", $sub_item_value) or DataEntity::is_kind_of("value", $sub_item_value) or DataEntity::is_kind_of("parameter", $sub_item_value)) {
                                     $data_entity_id = DataEntity::get_entry_by_item_id($sub_item_value);
                                     $folder_id = $sample->get_item_holder_value("folder_id");
                                     $parent_data_entity_id = Folder::get_data_entity_id_by_folder_id($folder_id);
                                     $child_data_entity = new DataEntity($data_entity_id);
                                     if ($child_data_entity->set_as_child_of($parent_data_entity_id, true, $parent_item_id) == false) {
                                         return false;
                                     }
                                 }
                             }
                         }
                     } else {
                         foreach ($required_sub_item_array as $key => $value) {
                             $sub_item_array = $item_holder_instance->get_item_holder_items($value);
                             if (is_array($sub_item_array) and count($sub_item_array)) {
                                 foreach ($sub_item_array as $sub_item_key => $sub_item_value) {
                                     if (self::create($get_array['sample_id'], $sub_item_value, null, null, null, $event_object->get_item_id()) == false) {
                                         if ($transaction_id != null) {
                                             $transaction->rollback($transaction_id);
                                         }
                                         return false;
                                     }
                                     if (DataEntity::is_kind_of("file", $sub_item_value) or DataEntity::is_kind_of("value", $sub_item_value) or DataEntity::is_kind_of("parameter", $sub_item_value)) {
                                         $data_entity_id = DataEntity::get_entry_by_item_id($sub_item_value);
                                         $folder_id = $sample->get_item_holder_value("folder_id");
                                         $parent_data_entity_id = Folder::get_data_entity_id_by_folder_id($folder_id);
                                         $child_data_entity = new DataEntity($data_entity_id);
                                         if ($child_data_entity->set_as_child_of($parent_data_entity_id, true, $parent_item_id) == false) {
                                             return false;
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             if (self::create($get_array['sample_id'], $event_object->get_item_id(), $get_array['key'], $post_array['keywords'], $post_array['description'], null, $parent) == false) {
                 if ($transaction_id != null) {
                     $transaction->rollback($transaction_id);
                 }
                 return false;
             } else {
                 if ($transaction_id != null) {
                     $transaction->commit($transaction_id);
                 }
             }
         }
         if (($get_array['parent'] == "sample" or $get_array['parent'] == "parentsample") and is_numeric($get_array['key']) and is_numeric($get_array['parent_key'])) {
             $transaction_id = $transaction->begin();
             if (is_numeric($get_array['parent_id'])) {
                 if ($get_array['parent'] == "parentsample") {
                     $parent_sample = true;
                 } else {
                     $parent_sample = false;
                 }
                 if (self::create($get_array['parent_id'], $event_object->get_item_id(), $get_array['key'], null, null, null, false, $parent_sample) == false) {
                     if ($transaction_id != null) {
                         $transaction->rollback($transaction_id);
                     }
                     return false;
                 } else {
                     if ($transaction_id != null) {
                         $transaction->commit($transaction_id);
                     }
                 }
             } elseif ($get_array['nav']) {
                 $handling_class = Item::get_holder_handling_class_by_name($get_array['nav']);
                 if (class_exists($handling_class)) {
                     $item_holder = new $handling_class($get_array[$get_array['nav'] . '_id']);
                     $parent_id_array = $item_holder->get_item_add_information($get_array['parent_key']);
                     if (is_array($parent_id_array['fulfilled']) and count($parent_id_array['fulfilled']) >= 1) {
                         foreach ($parent_id_array['fulfilled'] as $key => $value) {
                             if (self::create($value['id'], $event_object->get_item_id(), $get_array['key']) == false) {
                                 if ($transaction_id != null) {
                                     $transaction->rollback($transaction_id);
                                 }
                                 return false;
                             }
                         }
                         if ($transaction_id != null) {
                             $transaction->commit($transaction_id);
                         }
                     }
                 } else {
                     return false;
                 }
             }
         }
     }
     if ($event_object instanceof ItemHolderAddEvent) {
         $id_array = $event_object->get_id_array();
         $item_id = $event_object->get_item_id();
         $parent_item_id = $event_object->get_parent_item_id();
         $pos_id = $event_object->get_pos_id();
         if (is_array($id_array) and count($id_array) >= 1) {
             if (is_array($id_array['sample']) and count($id_array['sample']) >= 1) {
                 foreach ($id_array['sample'] as $key => $value) {
                     $sample = new Sample($value['id']);
                     if ($sample->is_sub_item_required($value['pos_id'], $pos_id) == true) {
                         if (self::create($value['id'], $item_id, null, null, null, $parent_item_id, false) == false) {
                             return false;
                         }
                         if (DataEntity::is_kind_of("file", $item_id) or DataEntity::is_kind_of("value", $item_id) or DataEntity::is_kind_of("parameter", $sub_item_value)) {
                             $data_entity_id = DataEntity::get_entry_by_item_id($item_id);
                             $folder_id = $sample->get_item_holder_value("folder_id");
                             $parent_data_entity_id = Folder::get_data_entity_id_by_folder_id($folder_id);
                             $child_data_entity = new DataEntity($data_entity_id);
                             if ($child_data_entity->set_as_child_of($parent_data_entity_id, true, $parent_item_id) == false) {
                                 return false;
                             }
                         }
                     }
                 }
             }
         }
     }
     return true;
 }