コード例 #1
0
ファイル: ContentTest.php プロジェクト: fachriza/thelia
 public function testAddFolderToContent()
 {
     $content = $this->getRandomContent();
     do {
         $folder = $this->getRandomFolder();
         $test = ContentFolderQuery::create()->filterByContent($content)->filterByFolder($folder);
     } while ($test->count() > 0);
     $event = new ContentAddFolderEvent($content, $folder->getId());
     $event->setDispatcher($this->dispatcher);
     $contentAction = new Content($this->getContainer());
     $contentAction->addFolder($event);
     $testAddFolder = ContentFolderQuery::create()->filterByContent($content)->filterByFolder($folder)->findOne();
     $this->assertNotNull($testAddFolder);
     $this->assertEquals($content->getId(), $testAddFolder->getContentId(), 'check if content id are equals');
     $this->assertEquals($folder->getId(), $testAddFolder->getFolderId(), 'check if folder id are equals');
     return $testAddFolder;
 }
コード例 #2
0
ファイル: Content.php プロジェクト: vigourouxjulien/thelia
 /**
  *
  * associate a folder to a content if the association already does not exists
  *
  * @param ContentAddFolderEvent $event
  */
 public function addFolder(ContentAddFolderEvent $event)
 {
     if (ContentFolderQuery::create()->filterByContent($event->getContent())->filterByFolderId($event->getFolderId())->count() <= 0) {
         $contentFolder = (new ContentFolder())->setFolderId($event->getFolderId())->setContent($event->getContent())->setDefaultFolder(false);
         $contentFolder->setPosition($contentFolder->getNextPosition())->save();
     }
 }