$root = (strpos($this->name,'IPF_') === 0) ? IPF::get('ipf_path') : IPF::get('project_path');
$this->path = $root.DIRECTORY_SEPARATOR.strtolower(str_replace('_',DIRECTORY_SEPARATOR,$this->name)).DIRECTORY_SEPARATOR;
- if (array_key_exists('models',$data)) {
- foreach ($data['models'] as &$modelname) {
- if (!IPF_Utils::isValidName($modelname))
- throw new IPF_Exception_Panic("Model name \"$modelname\" is incorrect");
- $this->models[] = $modelname;
- }
- } else {
- try {
- $it = new DirectoryIterator($this->path.DIRECTORY_SEPARATOR.'models');
- foreach ($it as $file) {
- $e = explode('.', $file->getFileName(), 2);
- if (count($e) == 2 && $e[1] === 'php') {
- $this->models[] = $e[0];
- }
+ $models = array();
+ try {
+ $it = new DirectoryIterator($this->path.DIRECTORY_SEPARATOR.'models');
+ foreach ($it as $file) {
+ $e = explode('.', $file->getFileName(), 2);
+ if (count($e) == 2 && $e[1] === 'php') {
+ $models[] = $e[0];
}
- } catch(RuntimeException $e) {
- // nothing to do
}
+ } catch (RuntimeException $e) {
+ // nothing to do
}
+
+ // reorder models according to a given parameter
+ if (array_key_exists('models', $data)) {
+ foreach ($data['models'] as $modelname) {
+ if (!in_array($modelname, $models))
+ throw new IPF_Exception_Panic("Model \"$modelname\" does not exist.");
+ }
+ $models = array_merge($data['models'], array_diff($models, $data['models']));
+ }
+
+ $this->models = $models;
}
public function modelList()