|
@@ -53,4 +53,28 @@ class StatTree extends Model
|
|
return $instance;
|
|
return $instance;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ public function clone($name) {
|
|
|
|
+
|
|
|
|
+ // create stat tree
|
|
|
|
+ $instance = new StatTree();
|
|
|
|
+ $nextId = DB::select("select nextval('stat_tree_id_seq')");
|
|
|
|
+ $instance->id = $nextId[0]->nextval;
|
|
|
|
+ $instance->uid = Uuid::uuid4();
|
|
|
|
+ $instance->name = $name;
|
|
|
|
+ $instance->model = $this->model;
|
|
|
|
+ $instance->slug = $this->slug . '-' . rand(100, 999);
|
|
|
|
+ $instance->is_template = $this->is_template;
|
|
|
|
+ $instance->pro_id = $this->pro_id;
|
|
|
|
+ $instance->pro_scope_clause = $this->pro_scope_clause;
|
|
|
|
+ $instance->save();
|
|
|
|
+
|
|
|
|
+ // create tree lines
|
|
|
|
+ foreach ($this->rootLines as $line) {
|
|
|
|
+ $line->copy(null, $instance);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return $instance;
|
|
|
|
+
|
|
|
|
+ }
|
|
}
|
|
}
|