public function edit()
 {
     $entity_so = CreateObject('property.soadmin_entity');
     $custom = createObject('phpgwapi.custom_fields');
     $location_id = phpgw::get_var('location_id');
     $project_type_id = phpgw::get_var('project_type_id');
     if ($location_id) {
         $req_types = $this->so->get(null, null, null, null, null, null, array('location_id' => $location_id, 'project_type_id' => $project_type_id));
         if (count($req_types) > 0) {
             $keys = array_keys($req_types);
             $req_type = $req_types[$keys[0]];
         }
     } else {
         $req_type = new logistic_resource_type_requirement();
     }
     if (isset($_POST['save'])) {
         $entity_id = phpgw::get_var('entity_id');
         $category_id = phpgw::get_var('category_id');
         $location_id = $GLOBALS['phpgw']->locations->get_id('property', ".entity.{$entity_id}.{$category_id}");
         $req_type->set_location_id($location_id);
         $req_type->set_project_type_id(phpgw::get_var('project_type_id'));
         $cust_attr_ids = phpgw::get_var('attributes');
         $selected_attributes[] = array();
         $req_type_array = $this->so->get(null, null, null, null, null, null, array('location_id' => $location_id, 'project_type_id' => $project_type_id));
         $req_types_for_delete = array();
         if (count($req_type_array) > 0) {
             foreach ($req_type_array as $rt) {
                 if (!in_array($rt->get_cust_attribute_id(), $cust_attr_ids)) {
                     $req_types_for_delete[] = $rt;
                 }
                 $selected_attributes[] = $rt->get_cust_attribute_id();
             }
             foreach ($cust_attr_ids as $attr) {
                 if (!in_array($attr, $selected_attributes)) {
                     $req_type_new = new logistic_resource_type_requirement();
                     $req_type_new->set_location_id($location_id);
                     $req_type_new->set_project_type_id(phpgw::get_var('project_type_id'));
                     $req_type_new->set_cust_attribute_id($attr);
                     $req_type_new_id = $this->so->store($req_type_new);
                 }
             }
             foreach ($req_types_for_delete as $del_req_type) {
                 $this->so->delete($del_req_type);
             }
         } else {
             foreach ($cust_attr_ids as $attr) {
                 $req_type->set_cust_attribute_id($attr);
                 $req_type_id = $this->so->store($req_type);
             }
         }
         $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'logistic.uiresource_type_requirement.view', 'location_id' => $location_id, 'project_type_id' => $req_type->get_project_type_id()));
     } else {
         if (isset($_POST['cancel'])) {
             $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'logistic.uiresource_type_requirement.index'));
         } else {
             $entity_list = execMethod('property.soadmin_entity.read', array('allrows' => true));
             array_unshift($entity_list, array('id' => '', 'name' => lang('select value')));
             if ($location_id) {
                 $loc_arr = $GLOBALS['phpgw']->locations->get_name($location_id);
                 $entity_arr = explode('.', $loc_arr['location']);
                 $entity = $entity_so->read_single($entity_arr[2]);
                 $category = $entity_so->read_single_category($entity_arr[2], $entity_arr[3]);
                 foreach ($entity_list as &$e) {
                     if ($e['id'] == $entity['id']) {
                         $e['selected'] = 1;
                     }
                 }
                 $category_list = $entity_so->read_category(array('allrows' => true, 'entity_id' => $entity_arr[2]));
                 foreach ($category_list as &$c) {
                     if ($c['id'] == $category['id']) {
                         $c['selected'] = 1;
                     }
                 }
                 $attributes = $custom->find('property', ".entity.{$entity_arr[2]}.{$entity_arr[3]}", 0, '', '', '', true, true);
                 $selected_attributes = $this->so->get_selected_attributes($location_id, $project_type_id);
                 foreach ($attributes as &$a) {
                     if (in_array($a['id'], $selected_attributes)) {
                         $a['checked'] = 'checked';
                     }
                 }
             }
             $project_type_array = $this->so_project->get_project_types($req_type->get_project_type_id());
             $data = array('value_id' => !empty($req_type) ? $req_type->get_id() : 0, 'entities' => $entity_list, 'categories' => $category_list, 'attributes' => $attributes, 'project_types' => $project_type_array, 'editable' => true, 'req_type' => $req_type);
             $GLOBALS['phpgw_info']['flags']['app_header'] = lang('logistic') . '::' . lang('Project type');
             phpgwapi_jquery::load_widget('core');
             self::add_javascript('logistic', 'logistic', 'resource_type_requirement.js');
             self::render_template_xsl(array('project/resource_type_requirement_item'), $data);
         }
     }
 }
 protected function populate(int $req_id, &$resource_type_requirement)
 {
     if ($resource_type_requirement == null) {
         $resource_type_requirement = new logistic_resource_type_requirement((int) $req_id);
         $resource_type_requirement->set_location_id($this->unmarshal($this->db->f('location_id'), 'int'));
         $resource_type_requirement->set_cust_attribute_id($this->unmarshal($this->db->f('cust_attribute_id'), 'string'));
         $resource_type_requirement->set_project_type_id($this->unmarshal($this->db->f('project_type_id'), 'int'));
     }
     return $resource_type_requirement;
 }
 /**
  * Get a static reference to the storage object associated with this model object
  *
  * @return the storage object
  */
 public static function get_so()
 {
     if (self::$so == null) {
         self::$so = CreateObject('logistic.soresource_type_requirement');
     }
     return self::$so;
 }