Exemple #1
0
 public function __construct($fields, $objective_id = null)
 {
     if ($fields instanceof STDClass) {
         $this->objective_id = $objective_id;
         $fields = $this->uniquify_varnames($fields);
         $this->inverted_fields = invert_dictionary($fields);
         $this->fields = $fields;
     }
 }
Exemple #2
0
 public function __construct($resource_or_fields, $missing_tokens = null, $data_locale = null, $verbose = null, $objective_field = null, $objective_field_present = null, $include = null)
 {
     # The constructor can be instantiated with resources or a fields
     # structure. The structure is checked and fields structure is returned
     # if a resource type is matched.
     $DEFAULT_MISSING_TOKENS = array("", "N/A", "n/a", "NULL", "null", "-", "#DIV/0", "#REF!", "#NAME?", "NIL", "nil", "NA", "na", "#VALUE!", "#NULL!", "NaN", "#N/A", "#NUM!", "?");
     try {
         $resource_info = get_fields_structure($resource_or_fields);
         $this->fields = $resource_info[0];
         $resource_locale = $resource_info[1];
         $resource_missing_tokens = $resource_info[2];
         if (is_null($data_locale)) {
             $data_locale = $resource_locale;
         }
         if (is_null($missing_tokens)) {
             if (!is_null(${$resource_missing_tokens})) {
                 $missing_tokens = $resource_missing_tokens;
             }
         }
     } catch (Exception $e) {
         $this->fields = $resource_or_fields;
         if (is_null($data_locale)) {
             $data_locale = "en_utf8";
         }
         if (is_null($missing_tokens)) {
             $missing_tokens = $DEFAULT_MISSING_TOKENS;
         }
     }
     if (is_null($this->fields)) {
         error_log("No fields structure was found.");
         return;
     }
     $this->fields_by_name = invert_dictionary($this->fields, 'name');
     $this->fields_by_column_number = invert_dictionary($this->fields, 'column_number');
     find_locale($data_locale, $verbose);
     $this->missing_tokens = $missing_tokens;
     $this->fields_columns = array();
     foreach ($this->fields_by_column_number as $value) {
         array_push($this->fields_columns, $value);
     }
     sort($this->fields_columns);
     $this->filtered_fields = array();
     # Ids of the fields to be included
     if (is_null($include)) {
         foreach ($this->fields as $key => $value) {
             array_push($this->filtered_fields, $key);
         }
     } else {
         $this->filtered_fields = $include;
     }
     # To be updated in update_objective_field
     $this->row_ids = null;
     $this->headers = null;
     $this->objective_field = null;
     $this->objective_field_present = null;
     $this->filtered_indexes = null;
 }
 public function __construct($fields, $objective_id = null, $data_locale = null, $missing_tokens = null)
 {
     if ($fields instanceof STDClass) {
         $this->objective_id = $objective_id;
         $fields = $this->uniquify_varnames($fields);
         $this->inverted_fields = invert_dictionary($fields);
         $this->fields = $fields;
         $this->data_locale = $data_locale;
         $this->missing_tokens = $missing_tokens;
         if ($this->data_locale == null) {
             $this->data_locale = ModelFields::DEFAULT_LOCALE;
         }
         if ($this->missing_tokens == null) {
             $this->missing_tokens = $DEFAULT_MISSING_TOKENS = array("", "N/A", "n/a", "NULL", "null", "-", "#DIV/0", "#REF!", "#NAME?", "NIL", "nil", "NA", "na", "#VALUE!", "#NULL!", "NaN", "#N/A", "#NUM!", "?");
         }
     }
 }