Use new code style
This commit is contained in:
@ -20,14 +20,11 @@ defined('ABSPATH') || exit;
|
||||
function wu_cast_model_to_array($model) {
|
||||
|
||||
if (is_a($model, '\\WP_Ultimo\\Models\\Base_Model')) {
|
||||
|
||||
$model = $model->to_array();
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
return $model;
|
||||
|
||||
} // end wu_cast_model_to_array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a list of Model objects to a list of ID => $label_field
|
||||
@ -43,14 +40,11 @@ function wu_models_to_options($models, $label_field = 'name') {
|
||||
$options_list = array();
|
||||
|
||||
foreach ($models as $model) {
|
||||
|
||||
$options_list[$model->get_id()] = call_user_func(array($model, "get_{$label_field}"));
|
||||
|
||||
} // end foreach;
|
||||
$options_list[ $model->get_id() ] = call_user_func(array($model, "get_{$label_field}"));
|
||||
}
|
||||
|
||||
return $options_list;
|
||||
|
||||
} // end wu_models_to_options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the schema of a particular model.
|
||||
@ -65,14 +59,11 @@ function wu_model_get_schema($class_name) {
|
||||
$schema = array();
|
||||
|
||||
if (method_exists($class_name, 'get_schema')) {
|
||||
|
||||
$schema = $class_name::get_schema();
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
return $schema;
|
||||
|
||||
} // end wu_model_get_schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of required fields form a model schema.
|
||||
@ -87,21 +78,14 @@ function wu_model_get_required_fields($class_name) {
|
||||
$required_fields = array();
|
||||
|
||||
if (method_exists($class_name, 'validation_rules')) {
|
||||
|
||||
$validation_rules = (new $class_name)->validation_rules();
|
||||
$validation_rules = (new $class_name())->validation_rules();
|
||||
|
||||
foreach ($validation_rules as $field => $validation_rule) {
|
||||
|
||||
if (strpos((string) $validation_rule, 'required|') !== false || $validation_rule === 'required') {
|
||||
|
||||
$required_fields[] = $field;
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end foreach;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $required_fields;
|
||||
|
||||
} // end wu_model_get_required_fields;
|
||||
}
|
||||
|
Reference in New Issue
Block a user