Location: PHPKode > projects > Nella Framework > nella-framework-7e780c6/Nella/Media/Model/ImageDao.php
<?php
/**
 * This file is part of the Nella Framework (http://nellafw.org).
 *
 * Copyright (c) 2006, 2012 Patrik Votoček (http://patrik.votocek.cz)
 *
 * For the full copyright and license information, please view the file LICENSE.txt that was distributed with this source code.
 */

namespace Nella\Media\Model;

use Doctrine\ORM\Mapping as orm;

/**
 * Image DAO
 *
 * @author	Patrik Votoček
 */
class ImageDao extends FileDao implements \Nella\NetteAddons\Media\Model\IImageDao
{
	/** @var \Nella\NetteAddons\Media\IImageCacheStorage */
	protected $cacheStorage;

	/**
	 * @param \Nella\NetteAddons\Media\IImageCacheStorage
	 * @return ImageDao
	 */
	public function setCacheStorage(\Nella\NetteAddons\Media\IImageCacheStorage $cacheStorage)
	{
		$this->cacheStorage = $cacheStorage;
		return $this;
	}

	/**
	 * @param object
	 * @param bool
	 * @param string|\Nette\Http\FileUpload
	 */
	public function save($entity, $withoutFlush = self::FLUSH, $originalPath = NULL)
	{
		if ($entity->id !== NULL && $this->cacheStorage) {
			$cacheStorage = $this->cacheStorage;
			$entity->onFlush[] = function($entity) use($cacheStorage) {
				$cacheStorage->remove($entity);
			};
		}

		return parent::save($entity, $withoutFlush, $originalPath);
	}

	/**
	 * @param object
	 * @param bool
	 */
	public function remove($entity, $withoutFlush = self::FLUSH)
	{
		if ($entity->id !== NULL && $this->cacheStorage) {
			$cacheStorage = $this->cacheStorage;
			$entity->onFlush[] = function($entity) use($cacheStorage) {
				$cacheStorage->remove($entity);
			};
		}
		parent::remove($entity, $withoutFlush);
	}
}
Return current item: Nella Framework