public function getCollection($name, $autoload = true) { if (empty($this->_collections[$name])) { // Load class $classname = 'Eyeem_Collection_' . ucfirst($name); if (class_exists($classname)) { $collection = new $classname(); } else { $collection = new Eyeem_RessourceCollection(); } // Collection name (match the name in URL: friendsPhotos, comments, likers, etc ...) $collection->setName($name); // Which kind of objects we are handling (user, album, photo, etc) $collection->setType(static::$collections[$name]); // Keep a link to the current object $collection->setParentRessource($this); } else { $collection = $this->_collections[$name]; } if ($autoload == true) { // If we have some properties already available (offset, limit, total, items) if ($properties = $this->getAttribute($name, false)) { $collection->setProperties($properties); } // If we don't have the total in the collection properties if (!isset($properties['total'])) { // But have it available as totalX property. if (static::$name == 'photo' && $name == 'likers') { $totalKey = 'totalLikes'; } else { $totalKey = 'total' . ucfirst($name); } if ($total = $this->getAttribute($totalKey, false)) { $collection->setTotal($total); } } } return $this->_collections[$name] = $collection; }
public function flush() { parent::flush(); $this->_ids = null; }