_seriesById = array(); $this->_seriesByName = array(); if (isset($data->list->id)) { $this->_addSeries($data); } else { foreach ($data as $series) { $this->_addSeries($series); } } } /** * Creates a new task series instance and adds it to internal lists. * * @param stdClass $data Object containing parsed JSON data */ private function _addSeries($data) { if (isset($data->taskseries)) { $series = new Zend_Service_RememberTheMilk_TaskSeries($data); $this->_seriesById[$series->getId()] = $series; $this->_seriesByName[$series->getName()] = $series; } } /** * Implementation of IteratorAggregate::getIterator(). * * @return ArrayIterator */ public function getIterator() { return new ArrayIterator($this->_series); } /** * Implementation of IteratorAggregate::getLength(). * * @return int */ public function getLength() { return count($this->_series); } /** * Returns a task series instance with the specified identifier. * * @param int $id Task series identifier * @return Zend_Service_RememberTheMilk_TaskSeries */ public function getSeriesById($id) { if (isset($this->_seriesById[$id])) { return $this->_seriesById[$id]; } return null; } /** * Returns a task series instance with the specified name. * * @param string $name Task series name * @return Zend_Service_RememberTheMilk_TaskSeries */ public function getSeriesByName($name) { if (isset($this->_seriesByName[$name])) { return $this->_seriesByName[$name]; } return null; } }