Merge branch 'master' of https://github.com/thelia/thelia into upload_management

# By Manuel Raynaud (14) and Etienne Roudeix (1)
# Via Etienne Roudeix
* 'master' of https://github.com/thelia/thelia:
  cache dataccessfunctions
  fire event on insert content in createmethod
  fix issue, default foler is set on content creation
  allow to create new content
  update default param of content model
  create content listener for crud management
  dispatch event in pre/post crud method for content model
  display content modification page
  create contentUpdateEvent
  create contentCreateEvent
  create ContentEvent
  create contentModificationForm
  create content controller
  change folder_id parm by parent in list folder view
  use placeholder in folder update route
This commit is contained in:
gmorel
2013-09-23 11:55:24 +02:00
18 changed files with 1352 additions and 67 deletions

View File

@@ -2,7 +2,12 @@
namespace Thelia\Model;
use Propel\Runtime\Propel;
use Thelia\Core\Event\Content\ContentEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Model\Base\Content as BaseContent;
use Thelia\Model\ContentFolderQuery;
use Thelia\Model\Map\ContentTableMap;
use Thelia\Tools\URL;
use Propel\Runtime\Connection\ConnectionInterface;
@@ -30,13 +35,78 @@ class Content extends BaseContent
// and generate the position relative to this folder
}
/**
* {@inheritDoc}
*/
public function preInsert(ConnectionInterface $con = null)
public function getDefaultFolderId()
{
$this->setPosition($this->getNextPosition());
// Find default folder
$default_folder = ContentFolderQuery::create()
->filterByContentId($this->getId())
->filterByDefaultFolder(true)
->findOne();
return $default_folder == null ? 0 : $default_folder->getFolderId();
}
public function setDefaultFolder($folderId)
{
/* ContentFolderQuery::create()
->filterByContentId($this->getId)
->update(array("DefaultFolder" => 0));*/
return $this;
}
public function create($defaultFolderId)
{
$con = Propel::getWriteConnection(ContentTableMap::DATABASE_NAME);
$con->beginTransaction();
$this->dispatchEvent(TheliaEvents::BEFORE_CREATECONTENT, new ContentEvent($this));
try {
$this->save($con);
$cf = new ContentFolder();
$cf->setContentId($this->getId())
->setFolderId($defaultFolderId)
->setDefaultFolder(1)
->save($con);
$this->setPosition($this->getNextPosition())->save($con);
$con->commit();
$this->dispatchEvent(TheliaEvents::AFTER_CREATECONTENT,new ContentEvent($this));
} catch(\Exception $ex) {
$con->rollback();
throw $ex;
}
}
public function preUpdate(ConnectionInterface $con = null)
{
$this->dispatchEvent(TheliaEvents::BEFORE_UPDATECONTENT, new ContentEvent($this));
return true;
}
public function postUpdate(ConnectionInterface $con = null)
{
$this->dispatchEvent(TheliaEvents::AFTER_UPDATECONTENT, new ContentEvent($this));
}
public function preDelete(ConnectionInterface $con = null)
{
$this->dispatchEvent(TheliaEvents::BEFORE_DELETECONTENT, new ContentEvent($this));
return true;
}
public function postDelete(ConnectionInterface $con = null)
{
$this->dispatchEvent(TheliaEvents::AFTER_DELETECONTENT, new ContentEvent($this));
}
}