Example #1
0
 /**
  * @see ProjectInterface::get_current_status_requirements()
  * @param bool $force_inherit
  * @param integer $status_id
  * @return array
  */
 public function get_current_status_requirements($force_inherit = false, $status_id = null)
 {
     global $runtime_data;
     if ($this->project_id and $this->project) {
         if ($status_id == null) {
             $status_id = $this->get_current_status_id();
         }
         if ($runtime_data->is_object_data($this, "PROJECT_" . $this->project_id . "_" . $status_id . "_CURRENT_STATUS_REQUIREMENTS") == true) {
             return $runtime_data->read_object_data($this, "PROJECT_" . $this->project_id . "_" . $status_id . "_CURRENT_STATUS_REQUIREMENTS");
         } else {
             $project_template = new ProjectTemplate($this->project->get_template_id());
             $status_attribute_array = $project_template->get_status_attributes($status_id);
             $requirements_array = $project_template->get_status_requirements($status_id);
             if ($status_attribute_array['requirement'] == "optional") {
                 $requirement_default = "optional";
             } else {
                 $requirement_default = "force";
             }
             $return_array = array();
             $parent_item_array = array();
             $counter = 0;
             $type_counter = 0;
             $category_counter = 0;
             $fulfilled_counter = 0;
             $filter_counter = 0;
             $sub_item_counter = 0;
             if (is_array($requirements_array) and count($requirements_array) >= 1) {
                 $project_item = new ProjectItem($this->project_id);
                 $item_array = $project_item->get_project_status_items_with_pos_id($status_id);
                 $item_type_array = Item::list_types();
                 foreach ($requirements_array as $key => $value) {
                     // ITEM
                     if ($value['xml_element'] == "item" and !$value['close']) {
                         $in_item = true;
                         $return_array[$counter]['element_type'] = "item";
                         $return_array[$counter]['display'] = true;
                         $return_array[$counter]['type'] = $value['type'];
                         $return_array[$counter]['name'] = $value['name'];
                         $return_array[$counter]['dialog'] = $value['dialog'];
                         $return_array[$counter]['handling_class'] = Item::get_handling_class_by_type($value['type']);
                         if ($value['requirement'] and $status_attribute_array['requirement'] != "optional") {
                             $return_array[$counter]['requirement'] = $value['requirement'];
                         } else {
                             $return_array[$counter]['requirement'] = $requirement_default;
                         }
                         if ($value['occurrence']) {
                             $return_array[$counter]['occurrence'] = $value['occurrence'];
                         } else {
                             $return_array[$counter]['occurrence'] = "once";
                         }
                         if (is_numeric($value['pos_id'])) {
                             $pos_id = $value['pos_id'];
                             $return_array[$counter]['pos_id'] = $value['pos_id'];
                         } else {
                             $pos_id = $counter;
                             $return_array[$counter]['pos_id'] = $counter;
                         }
                         if (is_array($item_array) and count($item_array) >= 1) {
                             $item_instance_array = array();
                             foreach ($item_array as $item_key => $item_value) {
                                 if (is_array($item_type_array) and count($item_type_array) >= 1) {
                                     foreach ($item_type_array as $item_type => $item_handling_class) {
                                         if (class_exists($item_handling_class)) {
                                             if ($item_handling_class::is_kind_of($item_type, $item_value['item_id']) == true and $item_value['pos_id'] == $pos_id and $item_value['pos_id'] !== null and $pos_id !== null) {
                                                 $item_instance = $item_handling_class::get_instance_by_item_id($item_value['item_id'], true);
                                                 $return_array[$counter]['fulfilled'][$fulfilled_counter]['item_id'] = $item_value['item_id'];
                                                 $return_array[$counter]['fulfilled'][$fulfilled_counter]['id'] = $item_instance->get_item_object_id();
                                                 $return_array[$counter]['fulfilled'][$fulfilled_counter]['name'] = $item_instance->get_item_object_name();
                                                 array_push($item_instance_array, $item_instance);
                                                 $fulfilled_counter++;
                                                 break;
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                         if ($value['inherit'] == "all" or $force_inherit == true) {
                             if (is_array($item_instance_array) and count($item_instance_array) >= 1 and $fulfilled_counter >= 1) {
                                 foreach ($item_instance_array as $object_key => $object_value) {
                                     if (is_object($object_value)) {
                                         if ($object_value instanceof ItemHolderInterface) {
                                             $return_array[$counter]['sub_items'][$object_key] = $object_value->get_item_add_information();
                                         }
                                     }
                                 }
                             }
                         }
                     }
                     if ($value['xml_element'] == "item" and $value['close'] == "1") {
                         $counter++;
                         $type_counter = 0;
                         $category_counter = 0;
                         $fulfilled_counter = 0;
                         $sub_item_type_counter = 0;
                         $type = null;
                         $in_item = false;
                     }
                     // ITEMI
                     if ($value['xml_element'] == "itemi" and !$value['close']) {
                         if (is_numeric($value['parent_status']) and is_numeric($value['parent_pos_id']) and is_numeric($value['pos_id'])) {
                             $parent_requirement_array = $this->get_current_status_requirements(true, $value['parent_status']);
                             $parent_requirement_array = $parent_requirement_array[$value['parent_pos_id']];
                             $sub_item_array = $parent_requirement_array['sub_items'];
                             unset($parent_requirement_array['sub_items']);
                             if (!is_numeric($parent_item_array[$value['parent_status']])) {
                                 $return_array[$counter] = $parent_requirement_array;
                                 $return_array[$counter]['display'] = false;
                                 $parent_item_counter = $counter;
                                 $parent_item_array[$value['parent_status']] = $counter;
                             } else {
                                 $parent_item_counter = $parent_item_array[$value['parent_status']];
                             }
                             if (is_array($sub_item_array) and count($sub_item_array) >= 1) {
                                 foreach ($sub_item_array as $sub_item_key => $sub_item_value) {
                                     $return_array[$parent_item_counter]['sub_items'][$sub_item_key][$value['pos_id']] = $sub_item_value[$value['pos_id']];
                                     if ($value['takeover'] == "true") {
                                         $return_array[$parent_item_counter]['sub_items'][$sub_item_key][$value['pos_id']]['takeover'] = true;
                                     } else {
                                         $return_array[$parent_item_counter]['sub_items'][$sub_item_key][$value['pos_id']]['takeover'] = false;
                                     }
                                 }
                             }
                         } elseif ($in_item == true and is_array($item_instance_array) and count($item_instance_array) >= 1) {
                             foreach ($item_instance_array as $object_key => $object_value) {
                                 if (is_numeric($value['pos_id'])) {
                                     $pos_id = $value['pos_id'];
                                 } else {
                                     $pos_id = $sub_item_counter;
                                 }
                                 $return_array[$counter]['sub_items'][$object_key][$pos_id] = $object_value->get_item_add_information($pos_id);
                             }
                         }
                     }
                     // TYPE
                     if ($value['xml_element'] == "type" and !$value['close'] and $in_item = true and is_numeric($value['id'])) {
                         $return_array[$counter]['type_id'][$type_counter] = $value['id'];
                         $type_counter++;
                     }
                     // CATEGORY
                     if ($value['xml_element'] == "category" and !$value['close'] and $in_item = true and is_numeric($value['id'])) {
                         $return_array[$counter]['category_id'][$category_counter] = $value['id'];
                         $category_counter++;
                     }
                     // EXTENSION
                     if ($value['xml_element'] == "extension" and !$value['close']) {
                         $extension_id = Extension::get_id_by_identifier($value['identifier']);
                         $extension = new Extension($extension_id);
                         $return_array[$counter]['element_type'] = "extension";
                         $return_array[$counter]['name'] = $extension->get_name();
                         $return_array[$counter]['extension'] = $value['identifier'];
                         if ($value['requirement'] and $status_attribute_array['requirement'] != "optional") {
                             $return_array[$counter]['requirement'] = $value['requirement'];
                         } else {
                             $return_array[$counter]['requirement'] = $requirement_default;
                         }
                         if ($value['occurrence']) {
                             $return_array[$counter]['occurrence'] = $value['occurrence'];
                         } else {
                             $return_array[$counter]['occurrence'] = "once";
                         }
                         $return_array[$counter]['fulfilled'] = ProjectExtension::get_status($extension_id, $this->project_id);
                         $in_extension = true;
                     }
                     if ($value['xml_element'] == "extension" and $value['close'] == "1") {
                         $counter++;
                         $filter_counter = 0;
                         $in_extension = false;
                     }
                     // FILTER
                     if ($value['xml_element'] == "filter" and !$value['close'] and $in_extension == true and is_numeric($value['status'])) {
                         $return_array[$counter]['filter'][$filter_counter]['status'] = $value['status'];
                         if ($value['type']) {
                             $return_array[$counter]['filter'][$filter_counter]['type'] = $value['type'];
                         }
                         $filter_counter++;
                     }
                 }
             }
             if (is_array($return_array) and count($return_array) >= 1) {
                 foreach ($return_array as $key => $value) {
                     if (!$value['name'] and $value['type']) {
                         if ($return_array[$key]['handling_class']) {
                             $return_array[$key]['name'] = "Add " . $return_array[$key]['handling_class']::get_generic_name($value['type'], $value['type_id']);
                         }
                     }
                     if (is_array($value['sub_items']) and count($value['sub_items']) >= 1) {
                         foreach ($value['sub_items'] as $sub_item_key => $sub_item_value) {
                             if (!$sub_item_value['name'] and $sub_item_value['type']) {
                                 if ($return_array[$key]['sub_items'][$sub_item_key]['handling_class']) {
                                     $return_array[$key]['sub_items'][$sub_item_key]['name'] = "Add " . $return_array[$key]['sub_items'][$sub_item_key]['handling_class']::get_generic_name($sub_item_value['type'], $sub_item_value['type_id']);
                                 }
                             }
                         }
                     }
                 }
             }
             $runtime_data->write_object_data($this, "PROJECT_" . $this->project_id . "_" . $status_id . "_CURRENT_STATUS_REQUIREMENTS", $return_array);
             return $return_array;
         }
     } else {
         return null;
     }
 }