예제 #1
0
 public function testSearchById()
 {
     $content = ContentQuery::create()->findOne();
     if (null === $content) {
         $content = new \Thelia\Model\Content();
         $content->setVisible(1);
         $content->setTitle('foo');
         $content->save();
     }
     $otherParameters = array("visible" => "*");
     $this->baseTestSearchById($content->getId(), $otherParameters);
 }
예제 #2
0
파일: import.php 프로젝트: alex63530/thelia
function createContents($faker, $folders, $con)
{
    echo "start creating contents\n";
    $fileSystem = new \Symfony\Component\Filesystem\Filesystem();
    $contents = array();
    if (($handle = fopen(THELIA_ROOT . '/setup/import/contents.csv', "r")) !== FALSE) {
        $row = 0;
        while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) {
            $row++;
            if ($row == 1) {
                continue;
            }
            $content = new \Thelia\Model\Content();
            $content->setVisible(1)->setPosition($row - 1)->setLocale('fr_FR')->setTitle(trim($data[0]))->setChapo($faker->text(20))->setDescription($faker->text(200))->setLocale('en_US')->setTitle(trim($data[1]))->setChapo($faker->text(20))->setDescription($faker->text(200));
            // folder
            $contentFolders = explode(';', $data[7]);
            $defaultFolder = null;
            foreach ($contentFolders as $contentFolder) {
                $contentFolder = trim($contentFolder);
                if (array_key_exists($contentFolder, $folders)) {
                    $content->addFolder($folders[$contentFolder]);
                    if (null === $defaultFolder) {
                        $defaultFolder = $folders[$contentFolder]->getId();
                    }
                }
            }
            $content->getContentFolders()->getFirst()->setDefaultFolder(true)->save($con);
            $content->save($con);
            $images = explode(';', $data[6]);
            foreach ($images as $image) {
                $image = trim($image);
                if (empty($image)) {
                    continue;
                }
                $contentImage = new \Thelia\Model\ContentImage();
                $contentImage->setContentId($content->getId())->setFile($image)->save($con);
                $fileSystem->copy(THELIA_ROOT . 'setup/import/images/' . $image, THELIA_ROOT . 'local/media/images/content/' . $image, true);
            }
            $contents[trim($data[1])] = $content;
        }
        fclose($handle);
    }
    echo "Contents created successfully\n";
    return $contents;
}