From a6cca7c03613dd007ccf8f21c36af1b63f7cd2df Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 18 Dec 2010 17:09:30 -0500 Subject: [PATCH] Extracting a method from paginator component. --- cake/libs/controller/components/paginator.php | 83 +++++++++++-------- 1 file changed, 47 insertions(+), 36 deletions(-) diff --git a/cake/libs/controller/components/paginator.php b/cake/libs/controller/components/paginator.php index 9bf89f991..4a0bd2ffc 100644 --- a/cake/libs/controller/components/paginator.php +++ b/cake/libs/controller/components/paginator.php @@ -64,42 +64,7 @@ class PaginatorComponent extends Component { } $assoc = null; - if (is_string($object)) { - $assoc = null; - if (strpos($object, '.') !== false) { - list($object, $assoc) = pluginSplit($object); - } - - if ($assoc && isset($this->Controller->{$object}->{$assoc})) { - $object = $this->Controller->{$object}->{$assoc}; - } elseif ( - $assoc && isset($this->Controller->{$this->Controller->modelClass}) && - isset($this->Controller->{$this->Controller->modelClass}->{$assoc} - )) { - $object = $this->Controller->{$this->Controller->modelClass}->{$assoc}; - } elseif (isset($this->Controller->{$object})) { - $object = $this->Controller->{$object}; - } elseif ( - isset($this->Controller->{$this->Controller->modelClass}) && isset($this->Controller->{$this->Controller->modelClass}->{$object} - )) { - $object = $this->Controller->{$this->Controller->modelClass}->{$object}; - } - } elseif (empty($object) || $object === null) { - if (isset($this->Controller->{$this->Controller->modelClass})) { - $object = $this->Controller->{$this->Controller->modelClass}; - } else { - $className = null; - $name = $this->Controller->uses[0]; - if (strpos($this->Controller->uses[0], '.') !== false) { - list($name, $className) = explode('.', $this->Controller->uses[0]); - } - if ($className) { - $object = $this->Controller->{$className}; - } else { - $object = $this->Controller->{$name}; - } - } - } + $object = $this->_getObject($object); if (!is_object($object)) { throw new MissingModelException($object); @@ -252,4 +217,50 @@ class PaginatorComponent extends Component { } return $results; } + +/** + * Get the object pagination will occur on. + * + * @param mixed $object The object you are looking for. + * @return mixed The model object to paginate on. + */ + protected function _getObject($object) { + if (is_string($object)) { + $assoc = null; + if (strpos($object, '.') !== false) { + list($object, $assoc) = pluginSplit($object); + } + + if ($assoc && isset($this->Controller->{$object}->{$assoc})) { + $object = $this->Controller->{$object}->{$assoc}; + } elseif ( + $assoc && isset($this->Controller->{$this->Controller->modelClass}) && + isset($this->Controller->{$this->Controller->modelClass}->{$assoc} + )) { + $object = $this->Controller->{$this->Controller->modelClass}->{$assoc}; + } elseif (isset($this->Controller->{$object})) { + $object = $this->Controller->{$object}; + } elseif ( + isset($this->Controller->{$this->Controller->modelClass}) && isset($this->Controller->{$this->Controller->modelClass}->{$object} + )) { + $object = $this->Controller->{$this->Controller->modelClass}->{$object}; + } + } elseif (empty($object) || $object === null) { + if (isset($this->Controller->{$this->Controller->modelClass})) { + $object = $this->Controller->{$this->Controller->modelClass}; + } else { + $className = null; + $name = $this->Controller->uses[0]; + if (strpos($this->Controller->uses[0], '.') !== false) { + list($name, $className) = explode('.', $this->Controller->uses[0]); + } + if ($className) { + $object = $this->Controller->{$className}; + } else { + $object = $this->Controller->{$name}; + } + } + } + return $object; + } } \ No newline at end of file