/** * Saves the pool to the database. * * @param \MusicBox\Entity\Like $pool */ public function save($pool) { $poolData = array('address_id' => $pool->getAddress()->getId(), 'access_info' => $pool->getAccessInfo()); if ($pool->getId()) { $this->db->update('pools', $poolData, array('pool_id' => $pool->getId())); $newFile = $this->handleFileUpload($item); if ($newFile) { $poolData['image'] = $pool->getImage(); } } else { // The pool is new, note the creation timestamp. $poolData['created_at'] = time(); $this->db->insert('pools', $poolData); // Get the id of the newly created pool and set it on the entity. $id = $this->db->lastInsertId(); $pool->setId($id); // If a new image was uploaded, update the pool with the new // filename. $newFile = $this->handleFileUpload($pool); if ($newFile) { $newData = array('image' => $pool->getImage()); $this->db->update('pools', $newData, array('pool_id' => $id)); } } }