/** * Delete an image * * @param array $imageInfo * integer id * string name * string description * integer category_id * string image * string url * integer created * @throws \Slideshow\Exception\SlideshowException * @return boolean|string */ public function deleteImage(array $imageInfo) { try { $this->adapter->getDriver()->getConnection()->beginTransaction(); $delete = $this->delete()->from('slideshow_image')->where(['id' => $imageInfo['id']]); $statement = $this->prepareStatementForSqlObject($delete); $result = $statement->execute(); // delete an image if (true !== ($imageDeleteResult = $this->deleteSlideShowImage($imageInfo['image']))) { throw new SlideshowException('Image deleting failed'); } $this->adapter->getDriver()->getConnection()->commit(); } catch (Exception $e) { $this->adapter->getDriver()->getConnection()->rollback(); ApplicationErrorLogger::log($e); return $e->getMessage(); } $result = $result->count() ? true : false; // fire the delete image event if ($result) { SlideshowEvent::fireDeleteImageEvent($imageInfo['id']); } return $result; }
/** * Add a new category * * @param array $categoryInfo * string name * @return boolean|string */ public function addCategory(array $categoryInfo) { try { $this->adapter->getDriver()->getConnection()->beginTransaction(); $insert = $this->insert()->into('slideshow_category')->values(array_merge($categoryInfo, ['language' => $this->getCurrentLanguage()])); $statement = $this->prepareStatementForSqlObject($insert); $statement->execute(); $insertId = $this->adapter->getDriver()->getLastGeneratedValue(); $this->adapter->getDriver()->getConnection()->commit(); } catch (Exception $e) { $this->adapter->getDriver()->getConnection()->rollback(); ApplicationErrorLogger::log($e); return $e->getMessage(); } // fire the add category event SlideshowEvent::fireAddCategoryEvent($insertId); return true; }