コード例 #1
0
ファイル: ArticleSeeder.php プロジェクト: lyrasoft/earth
 /**
  * doExecute
  *
  * @return  void
  */
 public function doExecute()
 {
     $faker = Factory::create();
     $languages = LanguageMapper::find(array('state' => 1))->code;
     $languages[] = '*';
     $categories = CategoryMapper::find(array('parent_id != 0', 'type' => 'article'));
     if (WarderHelper::tableExists('users')) {
         $userIds = UserMapper::findAll()->id;
     } else {
         $userIds = range(1, 50);
     }
     $tags = TagMapper::findAll()->dump();
     foreach ($categories as $category) {
         foreach (range(7, 15) as $i) {
             $data = new Data();
             $lang = $faker->randomElement($languages);
             $data['category_id'] = $category->id;
             $data['title'] = '(' . $lang . ') ' . $faker->sentence(mt_rand(3, 5));
             $data['alias'] = OutputFilter::stringURLSafe($data['title']);
             $data['introtext'] = '(' . $lang . ') ' . $faker->paragraph(5);
             $data['fulltext'] = $faker->paragraph(5);
             $data['image'] = UnsplashHelper::getImageUrl();
             $data['state'] = $faker->randomElement(array(1, 1, 1, 1, 0, 0));
             $data['version'] = mt_rand(1, 50);
             $data['created'] = $faker->dateTime->format(DateTime::getSqlFormat());
             $data['created_by'] = $faker->randomElement($userIds);
             $data['modified'] = $faker->dateTime->format(DateTime::getSqlFormat());
             $data['modified_by'] = $faker->randomElement($userIds);
             $data['ordering'] = $i;
             $data['language'] = $lang;
             $data['params'] = '';
             ArticleMapper::createOne($data);
             foreach ($faker->randomElements($tags, mt_rand(5, 7)) as $tag) {
                 $map = new Data();
                 $map->tag_id = $tag->id;
                 $map->target_id = $data->id;
                 $map->type = 'article';
                 TagMapMapper::createOne($map);
             }
             $this->outCounting();
         }
     }
 }
コード例 #2
0
ファイル: CategorySeeder.php プロジェクト: lyrasoft/earth
 /**
  * doExecute
  *
  * @return  void
  */
 public function doExecute()
 {
     $faker = Factory::create();
     $record = new CategoryRecord();
     $languages = LanguageMapper::find(array('state' => 1))->code;
     $languages[] = '*';
     if (WarderHelper::tableExists('users')) {
         $userIds = UserMapper::findAll()->id;
     } else {
         $userIds = range(1, 50);
     }
     $existsRecordIds = array();
     foreach ($this->types as $type) {
         $existsRecordIds[$type] = array(1);
     }
     foreach (range(1, 30) as $i) {
         $record->reset();
         $lang = $faker->randomElement($languages);
         $record['title'] = $faker->sentence(mt_rand(1, 3)) . ' - [' . $lang . ']';
         $record['alias'] = OutputFilter::stringURLSafe($record['title']);
         $record['type'] = $faker->randomElement($this->types);
         $record['description'] = $faker->paragraph(5);
         $record['image'] = UnsplashHelper::getImageUrl();
         $record['state'] = $faker->randomElement(array(1, 1, 1, 1, 0, 0));
         $record['version'] = mt_rand(1, 50);
         $record['created'] = $faker->dateTime->format(DateTime::getSqlFormat());
         $record['created_by'] = $faker->randomElement($userIds);
         $record['modified'] = $faker->dateTime->format(DateTime::getSqlFormat());
         $record['modified_by'] = $faker->randomElement($userIds);
         $record['language'] = $lang;
         $record['params'] = '';
         $record->setLocation($faker->randomElement($existsRecordIds[$record['type']]), $record::LOCATION_LAST_CHILD);
         $record->store();
         $record->rebuildPath();
         $existsRecordIds[$record['type']][] = $record->id;
         $this->outCounting();
     }
 }