/** * Try to find a specific collection record from the cache, and create * it in the database if it does not exist * * @param Dto_CollectionInfo $collToFind * @param int $stamp * @param int $spotId * @return Dto_CollectionInfo */ protected function matchCreateSpecificCollection(Dto_CollectionInfo $collToFind, $stamp, $spotId) { $title = $collToFind->getTitle(); $catType = $collToFind->getCatType(); $year = $collToFind->getYear(); foreach ($this->getCollectionsFromLocalCache($title, $catType, $year) as $collection) { if ($collToFind->equalColl($collection)) { /* Save stamp to update collection stamp later on */ $this->mc_updateMcStamp[$collToFind->getMcId()] = array('stamp' => $stamp, 'spotid' => $spotId); return $collection; } // if } // foreach /* * We did not find the correct specific collection, * so we add it to our database, and add it to the * cache */ $this->_conn->exec('INSERT INTO collections(mcid, season, episode, partscurrent, partstotal) VALUES (:mcid, :season, :episode, :partscurrent, :partstotal)', array(':mcid' => array($collToFind->getMcId(), PDO::PARAM_INT), ':season' => array($collToFind->getSeason(), PDO::PARAM_STR), ':episode' => array($collToFind->getEpisode(), PDO::PARAM_STR), ':partscurrent' => array($collToFind->getPartsCurrent(), PDO::PARAM_STR), ':partstotal' => array($collToFind->getPartsTotal(), PDO::PARAM_STR))); $collToFind->setId($this->_conn->lastInsertId('collections')); // and add it to the cache $this->addSpecificCollectionToLocalCache($title, $catType, $collToFind->getYear(), $collToFind); /* Save stamp to update collection stamp later on */ $this->mc_updateMcStamp[$collToFind->getMcId()] = array('stamp' => $stamp, 'spotid' => $spotId); return $collToFind; }