Esempio n. 1
0
 /**
  * Creates all needed classes and fills them with random data
  */
 public function installAction()
 {
     Time::check();
     $this->createTables();
     Console::getInstance()->writeLine('Tables created in ' . Time::check() . ' sec.');
     $pupilService = $this->getPupilService();
     $count = $this->generateItems($pupilService, $this->getRequest()->getParam('pupils', 100000), ['email', 'birthday'], function ($item) {
         return ['name' => $item['full'], 'email' => $item['email'], 'birthday' => $item['birthday'], 'level' => \Application\Entity\Pupil::$levels[rand(0, 5)]];
     });
     Console::getInstance()->writeLine($count . ' pupils generated in ' . Time::check() . ' sec.');
     $teachersCount = $this->getRequest()->getParam('teachers', 10000);
     $teacherService = $this->getTeacherService();
     $this->generateItems($teacherService, $teachersCount, ['phone'], function ($item) {
         $gender = $item['gender'] === \NameGenerator\Gender::GENDER_MALE ? TeacherEntity::GENDER_MALE : TeacherEntity::GENDER_FEMALE;
         return ['gender' => $gender, 'name' => $item['full'], 'phone' => $item['phone']];
     });
     Console::getInstance()->writeLine($teachersCount . ' teachers generated in ' . Time::check() . ' sec.');
     $pupilMaxId = $pupilService->getMaxId();
     $teacherMaxId = $teacherService->getMaxId();
     $teacherPupilService = $this->getTeacherPupilService();
     $linksCount = 0;
     for ($teacherId = 1; $teacherId < $teacherMaxId; $teacherId++) {
         $except = [];
         for ($j = 0; $j < rand(0, 3); $j++) {
             $pupil_id = rand(0, $pupilMaxId);
             if (in_array($pupil_id, $except)) {
                 continue;
             }
             $except[] = $pupil_id;
             $teacherPupilService->insert(['teacher_id' => $teacherId, 'pupil_id' => $pupil_id]);
             $linksCount++;
         }
     }
     Console::getInstance()->writeLine($linksCount . ' links generated in ' . Time::check() . ' sec.');
 }