0
@@ -61,6 +61,8 @@ class SCAR_Generic implements Iterator {
0
+ 'acts_as_materialized_path' => false,
0
@@ -276,6 +278,101 @@ class SCAR_Generic implements Iterator {
0
return (isset($this->_data['relations'][$klass])) ? $this->_data['relations'][$klass] : false;
0
+ * Says that this object acts with the Materialized Path pattern
0
+ * enables the calls for hasChildren and getChildren()
0
+ * @param string $col the column that contains path
0
+ * @return SCAR_Generic
0
+ public function actsAsMaterializedPath($col) {
0
+ $this->_data['acts_as_materialized_path'] = $col;
0
+ * Says a boolean if this object supports children or not
0
+ public function hasChildren() {
0
+ return ($this->_data['acts_as_materialized_path']) ? true : false;
0
+ * get the children for this object based on the model type
0
+ * @return mixed SCAR_Generic or array()
0
+ public function getChildren() {
0
+ if (!$this->hasChildren()) {
0
+ // if we don't know who we are, throw an exception
0
+ // can't multiplex children
0
+ if (!$this->whoAmI()) {
0
+ throw new SCAR_Method_Call_Exception('getChildren', $this);
0
+ if ($this->_data['acts_as_materialized_path']) {
0
+ $scar = call_user_func_array(array($this->getSCAR(), 'get'), array($this->getName()));
0
+ $call = 'by' . Inflector::Camelize($this->_data['acts_as_materialized_path']);
0
+ $scar->$call('LIKE', $this->path.'%');
0
+ * looks at criteria to determine if a givnn object can have a parent
0
+ public function hasParent() {
0
+ if (!$this->_data['acts_as_materialized_path']) {
0
+ // multiplex or 0 rows not valid
0
+ if (!$this->whoAmI()) {
0
+ if (strrpos($this->path, '/', -2) === 0) {
0
+ * get the parent for this object based on the nesting model types
0
+ * @return SCAR_Generic or false
0
+ public function getParent() {
0
+ if (!$this->hasParent()) {
0
+ // if we don't know who we are, throw an exception
0
+ // can't multiplex children
0
+ if (!$this->whoAmI()) {
0
+ throw new SCAR_Method_Call_Exception('getParent', $this);
0
+ if ($this->_data['acts_as_materialized_path']) {
0
+ $scar = call_user_func_array(array($this->getSCAR(), 'get'), array($this->getName()));
0
+ $call = 'by' . Inflector::Camelize($this->_data['acts_as_materialized_path']);
0
+ $path = substr($this->path, 0, strrpos($this->path, '/', -2) + 1);
0
+ var_dump($this->id.' '.$path);
0
+ $scar->$call($path); // path minus last node
0
* Saves a SCAR object into the database
Comments
No one has commented yet.