2016-03-29 06:53:06 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Skobkin\Bundle\PointToolsBundle\DataFixtures\ORM;
|
|
|
|
|
|
|
|
use Doctrine\Common\DataFixtures\AbstractFixture;
|
|
|
|
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
|
|
|
|
use Doctrine\Common\Persistence\ObjectManager;
|
|
|
|
use Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Comment;
|
|
|
|
use Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Post;
|
|
|
|
use Skobkin\Bundle\PointToolsBundle\Entity\User;
|
|
|
|
|
|
|
|
class LoadCommentsData extends AbstractFixture implements OrderedFixtureInterface
|
|
|
|
{
|
|
|
|
public function load(ObjectManager $om)
|
|
|
|
{
|
|
|
|
/** @var Post $post */
|
2016-12-11 22:53:56 +00:00
|
|
|
$post = $this->getReference('test_post_longpost');
|
2016-03-29 06:53:06 +00:00
|
|
|
|
2016-12-11 22:53:56 +00:00
|
|
|
/** @var User[] $users */
|
|
|
|
$users = [
|
|
|
|
$this->getReference('test_user_99999'),
|
|
|
|
$this->getReference('test_user_99998'),
|
|
|
|
$this->getReference('test_user_99997'),
|
|
|
|
$this->getReference('test_user_99996'),
|
|
|
|
$this->getReference('test_user_99995'),
|
|
|
|
];
|
2016-03-29 06:53:06 +00:00
|
|
|
|
|
|
|
$comments = [];
|
|
|
|
|
|
|
|
foreach (range(1, 10000) as $num) {
|
|
|
|
$comment = (new Comment())
|
|
|
|
->setNumber($num)
|
2016-12-11 22:53:56 +00:00
|
|
|
->setDeleted(mt_rand(0, 15) ? false : true)
|
2016-03-29 06:53:06 +00:00
|
|
|
->setCreatedAt(new \DateTime())
|
2016-12-11 22:58:58 +00:00
|
|
|
->setAuthor($users[array_rand($users)])
|
2016-03-29 06:53:06 +00:00
|
|
|
->setRec(false)
|
2016-12-11 22:53:56 +00:00
|
|
|
->setText(
|
|
|
|
'Some text with [link to @skobkin-ru site](https://skobk.in/) and `code block`'.PHP_EOL.
|
|
|
|
'and some quotation:'.PHP_EOL.
|
|
|
|
'> test test quote'.PHP_EOL.
|
|
|
|
'and some text after'
|
|
|
|
)
|
2016-03-29 06:53:06 +00:00
|
|
|
;
|
|
|
|
|
2016-12-11 22:53:56 +00:00
|
|
|
if (count($comments) > 0 && mt_rand(0, 1)) {
|
|
|
|
$comment->setParent($comments[mt_rand(0, count($comments) - 1)]);
|
2016-03-29 06:53:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$post->addComment($comment);
|
|
|
|
$comments[] = $comment;
|
|
|
|
|
|
|
|
$om->persist($comment);
|
|
|
|
}
|
|
|
|
|
|
|
|
$om->flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getOrder()
|
|
|
|
{
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
}
|