コード例 #1
0
 /**
  * @param int $count
  * @param Video[] $videos
  * @param User[] $users
  * @param Repository $repo
  * @throws \Exception
  */
 protected function createComments($count, $videos, $users, Repository $repo)
 {
     $this->out->writeln(Comment::class);
     /** @var ProgressHelper $progress */
     $progress = $this->getHelperSet()->get('progress');
     $progress->start($this->out, count($videos) * $count);
     foreach ($videos as $video) {
         $comments = [];
         for ($i = 0; $i < $count; ++$i) {
             $comment = new Comment();
             $comment->author = $this->faker->randomElement($users);
             $comment->text = $this->faker->realText(100);
             $comment->inReplyTo = $this->faker->optional(0.25)->randomElement($comments);
             $video->comments->add($comment);
             $comments[] = $comment;
             $progress->advance();
         }
         $repo->persist($video);
     }
     $progress->finish();
 }
コード例 #2
0
 private function createRubrics($count = 50)
 {
     print_r("Create rubrics. Count: " . $count . "...");
     $this->faker->unique(true);
     for ($i = 1; $i <= $count; $i++) {
         $rubric = new Rubric();
         $rubric->title = ucfirst($this->faker->word);
         if ($i === 1) {
             $parent_id = NULL;
         } else {
             do {
                 $parent_id = $this->faker->optional(0.7)->numberBetween(1, $i);
             } while ($parent_id === $i);
         }
         $rubric->parent_id = $parent_id;
         $rubric->save();
     }
     print_r("DONE" . PHP_EOL);
 }
コード例 #3
0
 private function generateAttributes(FakerGenerator $faker, $attributes, $code, $scopeId)
 {
     foreach ($attributes as $attribute) {
         $attributeFaker = $faker;
         if (1 - $attribute->required > 0.001) {
             $attributeFaker = $faker->optional($attribute->required);
         }
         $value = $attributeFaker->format($attribute->generatorMethod, $attribute->generatorArguments);
         if ($value !== null) {
             if ($value instanceof \DateTime) {
                 $value = $value->format('Y-m-d H:i:s');
             }
             $valueKey = sprintf('%s-%s-%s', $code, $attribute->id, $scopeId);
             $this->batch['value'][$attribute->type][$valueKey] = ['entity_id' => null, 'attribute_id' => $attribute->id, 'scope_id' => $scopeId, 'value' => $value];
             $this->batch['value_index'][$code][] = [$attribute->type, $valueKey];
         }
     }
     return $this;
 }