/**
  * @param string  $officeAlias
  * @param integer $day
  * @param integer $hour
  *
  * @return Appointment
  */
 public function create($officeAlias, $day, $hour)
 {
     if ($hour < 10) {
         $hour = '0' . $hour;
     }
     /** @var Client $client */
     $client = $this->getReference('client:00');
     /** @var Office $office */
     $office = $this->getReference($officeAlias);
     $serviceAlias = $this->services[rand(0, 5)];
     $description = 'Description: ' . $serviceAlias;
     /** @var Service $service */
     $service = $this->getReference('service:' . $serviceAlias);
     $date = new \DateTime($day . ' day');
     $date = new \DateTime($date->format('Y-m-d') . ' ' . $hour . ":00:00");
     if ($date->format('w') == 0 && $hour >= 13) {
         return;
     }
     $appointment = new Appointment();
     $appointment->setClient($client);
     $appointment->setDateTime($date);
     $appointment->setOffice($office);
     $appointment->setDuration(30);
     $appointment->setDescription($description);
     $appointment->setService($service);
     $appointment->setUser($this->getReference($this->doctors[rand(0, 4)]));
     return $appointment;
 }
 /**
  * @param ParameterBag $params
  *
  * @return Appointment
  */
 public function create($params)
 {
     $entity = new Appointment();
     $entity->setClient($params->get('client'));
     $entity->setDateTime($params->get('dateTime'));
     $entity->setDuration($params->get('duration'));
     $entity->setOffice($params->get('office'));
     $entity->setDescription($params->get('description'));
     $entity->setService($params->get('service'));
     $entity->setState($params->get('state', Appointment::STATE_NEW));
     $entity->setUser($params->get('user'));
     $this->persist($entity);
     return $entity;
 }
 /**
  * @param \DateTime $dayFrom
  * @param \DateTime $dayTo
  * @param Office    $office
  *
  * @return array
  */
 public function findByRange(\DateTime $dayFrom, \DateTime $dayTo, Office $office)
 {
     $builder = $this->getEntityManager()->createQueryBuilder();
     $params = ['dayFrom' => $dayFrom, 'dayTo' => $dayTo, 'office' => $office];
     $qb = $builder->select('a')->from(Appointment::clazz(), 'a')->where('a.dateTime > :dayFrom AND a.dateTime < :dayTo')->andWhere('a.office = :office')->setParameters($params);
     return $qb->getQuery()->getResult();
 }
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @see Console\Command\Command
  * @return int|null|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $manager = $this->getManager();
     $operator = new Group('Operator', ['ROLE_USER']);
     $doctor = new Group('Doctor', ['ROLE_USER']);
     $admin = new Group('Admin', ['ROLE_USER', 'ROLE_ADMIN']);
     $manager->persist($operator);
     $manager->persist($doctor);
     $manager->persist($admin);
     foreach ($this->doctorNames as $key => $name) {
         $dctr = new User();
         $dctr->setName($name);
         $dctr->setUsername($key);
         $dctr->setUsernameCanonical($key);
         $dctr->setEmail($key . '@ortofit.com.ua');
         $dctr->setUsernameCanonical($key . '@ortofit.com.ua');
         $dctr->setEnabled(true);
         $dctr->setSalt('skur7u3vt3400swsowowk88w80888k0');
         $dctr->setPassword('$2y$13$skur7u3vt3400swsowowkuFuZFwo2Igjz5jKzE8b0jPDu/NjeJi4O');
         $dctr->addGroup($doctor);
         $manager->persist($dctr);
     }
     $opr = new User();
     $opr->setUsername('operator');
     $opr->setName('operator');
     $opr->setUsernameCanonical('operator');
     $opr->setEmail('*****@*****.**');
     $opr->setUsernameCanonical('*****@*****.**');
     $opr->setEnabled(true);
     $opr->setSalt('skur7u3vt3400swsowowk88w80888k0');
     $opr->setPassword('$2y$13$skur7u3vt3400swsowowkuFuZFwo2Igjz5jKzE8b0jPDu/NjeJi4O');
     $opr->addGroup($operator);
     $manager->persist($opr);
     /** @var Appointment[] $apps */
     $apps = $manager->getRepository(Appointment::clazz())->findAll();
     foreach ($apps as $app) {
         $app->setUser($dctr);
         $manager->merge($app);
     }
     /** @var Service $services */
     $services = $manager->getRepository(Service::clazz())->find(1);
     $services->setName('Консультации');
     $services->setColor('#cdaa40');
     $services->setShort('(Конс.)');
     $manager->merge($services);
     $services = $manager->getRepository(Service::clazz())->find(2);
     $services->setName("Коррекция стелек");
     $services->setColor('#2e8b57');
     $services->setShort('(КС)');
     $manager->merge($services);
     $services = $manager->getRepository(Service::clazz())->find(3);
     $services->setName("Изготовление стелек ");
     $services->setColor('#818100');
     $services->setShort('(ИОС)');
     $manager->merge($services);
     //Массаж
     $services = $manager->getRepository(Service::clazz())->find(4);
     $services->setColor('#ff69b4');
     $services->setShort('(М)');
     $manager->merge($services);
     $services = new Service();
     $services->setName('Компьютерная диагностика');
     $services->setColor('#ffa500');
     $services->setShort('(КД)');
     $manager->persist($services);
     $services = new Service();
     $services->setName('Бесплатная консультация');
     $services->setColor('#4876ff');
     $services->setShort('(б/п конс)');
     $manager->persist($services);
     $manager->flush();
 }