コード例 #1
0
 function change_content_type($old_content_type_id, $current_content_type_id)
 {
     $this->CI->load->model('content/content_types_model');
     $this->Entry->content_type_id = $current_content_type_id;
     // Check if a content type exists with this id
     $Content_type = new Content_types_model();
     $Content_type->get_by_id($old_content_type_id);
     if ($Content_type->exists()) {
         // Get and set the new fields array which will now
         // be used for validating and processing instead of the fields array
         $this->old_fields = new Content_fields_model();
         $this->old_fields->order_by('sort', 'ASC')->include_related('content_field_types', array('model_name'))->get_by_content_type_id($old_content_type_id);
         // Get entry data
         $this->_get_entry_data();
         foreach ($this->fields as $Field) {
             // If the field has a value set try to find
             // a matching tag name in the new content type's fields
             foreach ($this->old_fields as $Old_field) {
                 if ($Field->short_tag == $Old_field->short_tag) {
                     $this->Entry_data->{'field_id_' . $Field->id} = $this->Entry_data->{'field_id_' . $Old_field->id};
                 }
             }
         }
         // Set old fields to NULL
         foreach ($this->old_fields as $Old_field) {
             $this->Entry_data->{'field_id_' . $Old_field->id} = NULL;
         }
     }
 }