From 4e107dac41f58d3ed6064809d8ee461ea8592e2c Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Fri, 6 Feb 2009 16:39:18 +0000 Subject: Implement fix for ticket #35. *** Requires reinstall of core *** * Added new field in items table (path) which is sanitized version of name. * Added __set method on Items_module to set the path field whenever the name field is changed. * Made some changes to the scaffolding so missing the path column would not kill the scaffolding. * Changed MY_url::site so not having a 3rd parameter won't throw an error. --- core/models/item.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'core/models') diff --git a/core/models/item.php b/core/models/item.php index e29f3245..e188e0a3 100644 --- a/core/models/item.php +++ b/core/models/item.php @@ -215,10 +215,10 @@ class Item_Model extends ORM_MPTT { if (empty($this->relative_path)) { foreach ($this->parents() as $parent) { if ($parent->id > 1) { - $paths[] = $parent->name; + $paths[] = $parent->path; } } - $paths[] = $this->name; + $paths[] = $this->path; $this->relative_path = implode($paths, "/"); } return $this->relative_path; @@ -241,6 +241,16 @@ class Item_Model extends ORM_MPTT { } } + /** + * @see ORM::__get() + */ + public function __set($column, $value) { + if ($column == "name") { + parent::__set("path", preg_replace("/[^A-Za-z0-9\.\-_]/", "_", $value)); + } + parent::__set($column, $value); + } + /** * @see ORM::save() */ -- cgit v1.2.3