Пример #1
1
 /**
  * National Personal Identity number (personnummer)
  * @link https://no.wikipedia.org/wiki/Personnummer
  * @param \DateTime $birthdate
  * @param string $gender Person::GENDER_MALE || Person::GENDER_FEMALE
  * @return string on format DDMMYY#####
  */
 public function personalIdentityNumber(\DateTime $birthdate = null, $gender = null)
 {
     if (!$birthdate) {
         $birthdate = \Faker\Provider\DateTime::dateTimeThisCentury();
     }
     $datePart = $birthdate->format('dmy');
     /**
      * @todo These number should be random based on birth year
      * @link http://no.wikipedia.org/wiki/F%C3%B8dselsnummer
      */
     $randomDigits = (string) static::numerify('##');
     switch ($gender) {
         case static::GENDER_MALE:
             $genderDigit = static::randomElement(array(1, 3, 5, 7, 9));
             break;
         case static::GENDER_FEMALE:
             $genderDigit = static::randomElement(array(0, 2, 4, 6, 8));
             break;
         default:
             $genderDigit = (string) static::numerify('#');
     }
     $digits = $datePart . $randomDigits . $genderDigit;
     /**
      * @todo Calculate modulo 11 of $digits
      * @link http://no.wikipedia.org/wiki/F%C3%B8dselsnummer
      */
     $checksum = (string) static::numerify('##');
     return $digits . $checksum;
 }
Пример #2
0
 /**
  * @return JSON with reagents list which expiration date is closer than one week.
  */
 public function getCloseToExpirationDate()
 {
     $date = new \DateTime();
     $date->add(new \DateInterval('P7D'));
     $date = $date->format('Y-m-d');
     $odczynniki = Odczynnik::where('data_waznosci', '<=', $date)->get();
     return response()->json($odczynniki);
 }
Пример #3
0
 public function getUpcomingEvent()
 {
     $date = new \DateTime();
     $now = $date->format("Y-m-d H:i:s");
     $ret = array();
     $ret = $this->join('eschedule', 'eschedule.event_id', '=', 'event.event_id')->where('eschedule.eschedule_end_date', '>=', $now)->select('event.*')->groupBy('event.event_id')->orderBy('eschedule.eschedule_start_date')->get();
     return $ret;
 }
Пример #4
0
 public static function currentTimePoints()
 {
     $dtNow = new \DateTime();
     $timestamp = time();
     // Set a non-default timezone if needed
     $dtNow->setTimestamp($timestamp);
     $beginOfDay = clone $dtNow;
     // Go to midnight.  ->modify('midnight') does not do this for some reason
     $beginOfDay->setTime(0, 0, 0);
     $endOfDay = clone $beginOfDay;
     $endOfDay->modify('tomorrow');
     // adjust from the next day to the end of the day, per original question
     $endOfDay->modify('1 second ago');
     return ['time' => $timestamp, 'start' => strtotime($beginOfDay->format('m/d/Y H:i:s e')), 'end' => strtotime($endOfDay->format('m/d/Y H:i:s e'))];
 }
Пример #5
0
 /**
  * PESEL - Universal Electronic System for Registration of the Population
  * @link http://en.wikipedia.org/wiki/PESEL
  * @param  DateTime $birthdate
  * @param  string   $sex       M for male or F for female
  * @return string   11 digit number, like 44051401358
  */
 public static function pesel($birthdate = null, $sex = null)
 {
     if ($birthdate === null) {
         $birthdate = \Faker\Provider\DateTime::dateTimeThisCentury();
     }
     $weights = array(1, 3, 7, 9, 1, 3, 7, 9, 1, 3);
     $length = count($weights);
     $fullYear = (int) $birthdate->format('Y');
     $year = (int) $birthdate->format('y');
     $month = $birthdate->format('m') + ((int) ($fullYear / 100) - 14) % 5 * 20;
     $day = $birthdate->format('d');
     $result = array((int) ($year / 10), $year % 10, (int) ($month / 10), $month % 10, (int) ($day / 10), $day % 10);
     for ($i = 6; $i < $length; $i++) {
         $result[$i] = static::randomDigit();
     }
     if ($sex == "M") {
         $result[$length - 1] |= 1;
     } elseif ($sex == "F") {
         $result[$length - 1] ^= 1;
     }
     $checksum = 0;
     for ($i = 0; $i < $length; $i++) {
         $checksum += $weights[$i] * $result[$i];
     }
     $checksum = (10 - $checksum % 10) % 10;
     $result[] = $checksum;
     return implode('', $result);
 }
Пример #6
0
 /**
  * @param $dateOfBirth
  * @return \DateTime
  */
 protected function getDateOfBirth($dateOfBirth)
 {
     if (empty($dateOfBirth)) {
         $dateOfBirthParts = array(static::numberBetween(1800, 2099));
     } else {
         $dateOfBirthParts = explode('-', $dateOfBirth);
     }
     $baseDate = \Faker\Provider\DateTime::dateTimeBetween("first day of {$dateOfBirthParts[0]}", "last day of {$dateOfBirthParts[0]}");
     switch (count($dateOfBirthParts)) {
         case 1:
             $dateOfBirthParts[] = $baseDate->format('m');
             //don't break, we need the day also
         //don't break, we need the day also
         case 2:
             $dateOfBirthParts[] = $baseDate->format('d');
             //don't break, next line will
         //don't break, next line will
         case 3:
             break;
         default:
             throw new \InvalidArgumentException("Invalid date of birth - must be null or in the 'Y-m-d', 'Y-m', 'Y' format");
     }
     if ($dateOfBirthParts[0] < 1800 || $dateOfBirthParts[0] > 2099) {
         throw new \InvalidArgumentException("Invalid date of birth - year must be between 1900 and 2099, '{$dateOfBirthParts[0]}' received");
     }
     $dateOfBirthFinal = implode('-', $dateOfBirthParts);
     $date = \DateTime::createFromFormat('Y-m-d', $dateOfBirthFinal);
     //a full (invalid) date might have been supplied, check if it converts
     if ($date->format('Y-m-d') !== $dateOfBirthFinal) {
         throw new \InvalidArgumentException("Invalid date of birth - '{$date->format('Y-m-d')}' generated based on '{$dateOfBirth}' received");
     }
     return $date;
 }
Пример #7
0
 public function testCreatedAt()
 {
     $cron = new Cron();
     $dateTime = DateTime::dateTime();
     $expected = $dateTime;
     $cron->setCreatedAt($dateTime);
     $actual = $cron->getCreatedAt();
     $this->assertSame($expected, $actual);
 }
Пример #8
0
 public function testDeletedAt()
 {
     $post = new Post();
     $deletedAt = DateTime::dateTime();
     $expected = $deletedAt;
     $post->setDeletedAt($deletedAt);
     $actual = $post->getDeletedAt();
     $this->assertSame($expected, $actual);
 }
Пример #9
0
 /**
  * National Individual Identification Numbers
  *
  * @link   http://egov.kz/wps/portal/!utWCM/p/b1/04_Sj9S1tDAwMzY1NjLTj9CPykssy0xPLMnMz0vMAfGjzOKDvDxNnJwMHQ0sTMOMDBxNPJ2dggNCg13MDIEKIpEVGFiGOIMUuIcFOJkZGxgYE6ffAAdwNCCkP1w_ClUJFheAFeCxws8jPzdVPzcqx83SU9cRADxWbyg!/dl4/d5/L0lDUmlTUSEhL3dHa0FKRnNBLzRKVXFDQSEhL2Vu/
  * @param  \DateTime $birthDate
  * @return string 12 digits, like 780322300455
  */
 public static function individualIdentificationNumber(\DateTime $birthDate = null)
 {
     if (!$birthDate) {
         $birthDate = \Faker\Provider\DateTime::dateTimeBetween();
     }
     $dateAsString = $birthDate->format('ymd');
     $genderAndCenturyId = (string) static::numberBetween(1, 6);
     $randomDigits = (string) static::numerify('#####');
     return $dateAsString . $genderAndCenturyId . $randomDigits;
 }
Пример #10
0
 /**
  * National Personal Identity number (personas kods)
  * @link https://en.wikipedia.org/wiki/National_identification_number#Latvia
  * @param \DateTime $birthdate
  * @return string on format XXXXXX-XXXXX
  */
 public function personalIdentityNumber(\DateTime $birthdate = null)
 {
     if (!$birthdate) {
         $birthdate = \Faker\Provider\DateTime::dateTimeThisCentury();
     }
     $datePart = $birthdate->format('dmy');
     $randomDigits = (string) static::numerify('####');
     $checksum = Luhn::computeCheckDigit($datePart . $randomDigits);
     return $datePart . '-' . $randomDigits . $checksum;
 }
Пример #11
0
 /**
  * National Business Identification Numbers
  *
  * @link   http://egov.kz/wps/portal/Content?contentPath=%2Fegovcontent%2Fbus_business%2Ffor_businessmen%2Farticle%2Fbusiness_identification_number&lang=en
  * @param  \DateTime $registrationDate
  * @return string 12 digits, like 150140000019
  */
 public static function businessIdentificationNumber(\DateTime $registrationDate = null)
 {
     if (!$registrationDate) {
         $registrationDate = \Faker\Provider\DateTime::dateTimeThisYear();
     }
     $dateAsString = $registrationDate->format('ym');
     $legalEntityType = (string) static::numberBetween(4, 6);
     $legalEntityAdditionalType = (string) static::numberBetween(0, 3);
     $randomDigits = (string) static::numerify('######');
     return $dateAsString . $legalEntityType . $legalEntityAdditionalType . $randomDigits;
 }
Пример #12
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     // Creating the Seeder for the
     // Bookings Table
     /*
      * Creating 100 seed data for the bookings table
      * */
     for ($i = 0; $i <= 100; $i++) {
         DB::table('bookings')->insert(['client_id' => random_int(1, 1000), 'car_id' => random_int(1, 1000), 'receive_place' => Faker\Provider\bn_BD\Address::state(), 'leaving_place' => Faker\Provider\bn_BD\Address::state(), 'receive_date' => \Faker\Provider\DateTime::date('Y-m-d'), 'leaving_date' => \Faker\Provider\DateTime::dateTimeThisMonth(), 'price_plan' => random_int(1, 3), 'promotion_code' => random_int(10, 20), 'created_at' => \Faker\Provider\DateTime::date('Y-m-d'), 'updated_at' => \Faker\Provider\DateTime::date('Y-m-d'), 'status' => random_int(1, 3)]);
     }
 }
 /**
  * National Personal Identity number (personnummer)
  * @link http://en.wikipedia.org/wiki/Personal_identity_number_(Sweden)
  * @param \DateTime $birthdate
  * @param string $gender Person::GENDER_MALE || Person::GENDER_FEMALE
  * @return string on format XXXXXX-XXXX
  */
 public function personalIdentityNumber(\DateTime $birthdate = null, $gender = null)
 {
     if (!$birthdate) {
         $birthdate = \Faker\Provider\DateTime::dateTimeThisCentury();
     }
     $datePart = $birthdate->format('ymd');
     if ($gender && $gender == static::GENDER_MALE) {
         $randomDigits = (string) static::numerify('##') . static::randomElement(array(1, 3, 5, 7, 9));
     } elseif ($gender && $gender == static::GENDER_FEMALE) {
         $randomDigits = (string) static::numerify('##') . static::randomElement(array(0, 2, 4, 6, 8));
     } else {
         $randomDigits = (string) static::numerify('###');
     }
     $checksum = Luhn::computeCheckDigit($datePart . $randomDigits);
     return $datePart . '-' . $randomDigits . $checksum;
 }
Пример #14
0
 /**
  * National Personal Identity Number (Henkilötunnus)
  * @link http://www.finlex.fi/fi/laki/ajantasa/2010/20100128
  * @param \DateTime $birthdate
  * @param string $gender Person::GENDER_MALE || Person::GENDER_FEMALE
  * @return string on format DDMMYYCZZZQ, where DDMMYY is the date of birth, C the century sign, ZZZ the individual number and Q the control character (checksum)
  */
 public function personalIdentityNumber(\DateTime $birthdate = null, $gender = null)
 {
     $checksumCharacters = '0123456789ABCDEFHJKLMNPRSTUVWXY';
     if (!$birthdate) {
         $birthdate = \Faker\Provider\DateTime::dateTimeThisCentury();
     }
     $datePart = $birthdate->format('dmy');
     switch ((int) ($birthdate->format('Y') / 100)) {
         case 18:
             $centurySign = '+';
             break;
         case 19:
             $centurySign = '-';
             break;
         case 20:
             $centurySign = 'A';
             break;
         default:
             throw new \InvalidArgumentException('Year must be between 1800 and 2099 inclusive.');
     }
     $randomDigits = self::numberBetween(0, 89);
     if ($gender && $gender == static::GENDER_MALE) {
         if ($randomDigits === 0) {
             $randomDigits .= static::randomElement(array(3, 5, 7, 9));
         } else {
             $randomDigits .= static::randomElement(array(1, 3, 5, 7, 9));
         }
     } elseif ($gender && $gender == static::GENDER_FEMALE) {
         if ($randomDigits === 0) {
             $randomDigits .= static::randomElement(array(2, 4, 6, 8));
         } else {
             $randomDigits .= static::randomElement(array(0, 2, 4, 6, 8));
         }
     } else {
         if ($randomDigits === 0) {
             $randomDigits .= self::numberBetween(2, 9);
         } else {
             $randomDigits .= (string) static::numerify('#');
         }
     }
     $randomDigits = str_pad($randomDigits, 3, '0', STR_PAD_LEFT);
     $checksum = $checksumCharacters[(int) ($datePart . $randomDigits) % strlen($checksumCharacters)];
     return $datePart . $centurySign . $randomDigits . $checksum;
 }
Пример #15
0
 /**
  * @link https://en.wikipedia.org/wiki/National_identification_number#South_Africa
  *
  * @param int    $minAge
  * @param int    $maxAge
  * @param bool   $citizen
  * @param string $gender
  *
  * @return string
  */
 public function idNumber($minAge = 16, $maxAge = 100, $citizen = true, $gender = null)
 {
     switch (strtolower($gender)) {
         case static::GENDER_FEMALE:
             $genderDigit = self::numberBetween(0, 4);
             break;
         case static::GENDER_MALE:
             $genderDigit = self::numberBetween(5, 9);
             break;
         default:
             $genderDigit = rand(0, 9);
     }
     $citizenDigit = $citizen === true ? '0' : '1';
     $birthDateString = DateTime::dateTimeBetween(sprintf('-%d years', $maxAge), sprintf('-%d years', $minAge))->format('ymd');
     $sequenceDigits = str_pad(self::randomNumber(3), 3, 0, STR_PAD_BOTH);
     $raceDigit = self::randomNumber(1);
     $partialIdNumber = $birthDateString . $genderDigit . $sequenceDigits . $citizenDigit . $raceDigit;
     $idNumber = $partialIdNumber . Luhn::computeCheckDigit($partialIdNumber);
     return $idNumber;
 }
Пример #16
0
 /**
  * National Personal Identity number (asmens kodas)
  * @link https://en.wikipedia.org/wiki/National_identification_number#Lithuania
  * @link https://lt.wikipedia.org/wiki/Asmens_kodas
  * @param string [male|female]
  * @param \DateTime $birthdate
  * @param string $randomNumber three integers
  * @return string on format XXXXXXXXXXX
  */
 public function personalIdentityNumber($gender = 'male', \DateTime $birthdate = null, $randomNumber = '')
 {
     if (!$birthdate) {
         $birthdate = \Faker\Provider\DateTime::dateTimeThisCentury();
     }
     $genderNumber = $gender == 'male' ? (int) 1 : (int) 0;
     $firstNumber = (int) floor($birthdate->format('Y') / 100) * 2 - 34 - $genderNumber;
     $datePart = $birthdate->format('ymd');
     $randomDigits = (string) (!$randomNumber || strlen($randomNumber < 3)) ? static::numerify('###') : substr($randomNumber, 0, 3);
     $partOfPerosnalCode = $firstNumber . $datePart . $randomDigits;
     $sum = self::calculateSum($partOfPerosnalCode, 1);
     $liekana = $sum % 11;
     if ($liekana !== 10) {
         $lastNumber = $liekana;
         return $firstNumber . $datePart . $randomDigits . $lastNumber;
     }
     $sum = self::calculateSum($partOfPerosnalCode, 2);
     $liekana = (int) $sum % 11;
     $lastNumber = $liekana !== 10 ? $liekana : 0;
     return $firstNumber . $datePart . $randomDigits . $lastNumber;
 }
Пример #17
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Faker::create();
     //$faker->addProvider(new Faker\Provider\DateTime($faker));
     $data = CombatRound::where('challenge_id', '=', 5)->get();
     foreach ($data as $d) {
         $time1 = DateTime::time($format = 'H:i:s', $max = '00:02:00');
         $time2 = DateTime::time($format = 'H:i:s', $max = '00:02:00');
         $zonaRoja1 = $faker->numberBetween($min = 2, $max = 5);
         $nZonaRojo1 = $zonaRoja1 + 1;
         $zonaVerde1 = $faker->numberBetween($min = 1, $max = 5);
         $nZonaVerde1 = $zonaVerde1 + 1;
         $zonaAzul1 = $faker->numberBetween($min = 2, $max = 5);
         $nZonaAzul1 = $zonaAzul1 + 1;
         $zonaRoja2 = $faker->numberBetween($min = 2, $max = 5);
         $nZonaRojo2 = $zonaRoja2 + 1;
         $zonaVerde2 = $faker->numberBetween($min = 1, $max = 5);
         $nZonaVerde2 = $zonaVerde2 + 1;
         $zonaAzul2 = $faker->numberBetween($min = 2, $max = 5);
         $nZonaAzul2 = $zonaAzul2 + 1;
         BlockRise::create(['combat_id' => $d['id'], 'team_id_1' => $d['versus_one'], 'time_team_1' => $time1, 'zon_pun_roj_1' => $zonaRoja1, 'num_api_roj_1' => $nZonaRojo1, 'zon_pun_ver_1' => $zonaVerde1, 'num_api_ver_1' => $nZonaVerde1, 'zon_pun_azu_1' => $zonaAzul1, 'num_api_azu_1' => $nZonaAzul1, 'team_id_2' => $d['versus_two'], 'time_team_2' => $time2, 'zon_pun_roj_2' => $zonaRoja2, 'num_api_roj_2' => $nZonaRojo2, 'zon_pun_ver_2' => $zonaVerde2, 'num_api_ver_2' => $nZonaVerde2, 'zon_pun_azu_2' => $zonaAzul2, 'num_api_azu_2' => $nZonaAzul2]);
     }
 }
Пример #18
0
 public function actionFotoform()
 {
     $model = new FotoForm();
     $id_album = Yii::$app->request->get('id_album', 0);
     if ($model->load(Yii::$app->request->post())) {
         $model->id_album = $id_album;
         $model->file = UploadedFile::getInstance($model, 'file');
         $name_foto = DateTime::date();
         $foto_path = 'upload/' . $name_foto . '.' . $model->file->extension;
         $model->file->saveAs('upload/' . $name_foto . '.' . $model->file->extension);
         $model->foto_path = $foto_path . 'small.jpg';
         $this->fotoResize($foto_path);
         if ($fotos = $model->add()) {
         }
         return $this->redirect(['album', 'id' => $id_album]);
     }
     return $this->render('fotoform', ['model' => $model, 'id_album' => $id_album]);
 }
 /**
  * Generate the admin form type entity.
  */
 private function generateBehatTest()
 {
     $configDir = $this->bundle->getPath() . '/Resources/config';
     // Get the context names for each section config file
     $sectionInfo = array();
     $dir = $configDir . '/pageparts/';
     foreach ($this->sections as $section) {
         $data = Yaml::parse($dir . $section);
         $sectionInfo[basename($section, '.yml')] = array('context' => $data['context'], 'pagetempates' => array());
     }
     /*
         Example $sectionInfo contents:
         Array
         (
             [main] => Array
                 (
                     [context] => main
                     [pagetempates] => Array
                         (
                         )
                 )
         )
     */
     // Get a list of page templates that use this context
     $allTemplates = glob($configDir . '/pagetemplates/*.yml');
     $contextTemplates = array();
     foreach ($allTemplates as $templatePath) {
         $parts = explode("/", $templatePath);
         $fileName = basename($parts[count($parts) - 1], '.yml');
         $data = Yaml::parse($templatePath);
         $templateName = $data['name'];
         if (array_key_exists('rows', $data) && is_array($data['rows'])) {
             foreach ($data['rows'] as $row) {
                 if (is_array($row) && array_key_exists('regions', $row) && is_array($row['regions'])) {
                     foreach ($row['regions'] as $region) {
                         $contextTemplates[$region['name']][$fileName] = $templateName;
                     }
                 }
             }
         }
     }
     /*
         Example $contextTemplates contents:
         Array
         (
             [main] => Array
                 (
                     [full-width-page] => Full width page
                     [homepage] => Home page
                     [sidebar-page] => Page with left sidebar
                 )
             [top] => Array
                 (
                     [homepage] => Home page
                 )
             [sidebar] => Array
                 (
                     [homepage] => Home page
                     [sidebar-page] => Page with left sidebar
                 )
         )
     */
     // Link the page templates to the sections
     foreach ($sectionInfo as $fileName => $info) {
         $context = $info['context'];
         if (array_key_exists($context, $contextTemplates)) {
             $sectionInfo[$fileName]['pagetempates'] = $contextTemplates[$context];
         }
     }
     /*
         Example $sectionInfo contents:
         Array
         (
             [main] => Array
                 (
                     [context] => main
                     [pagetempates] => Array
                         (
                             [full-width-page] => Full width page
                             [homepage] => Home page
                             [sidebar-page] => Page with left sidebar
                         )
     
                 )
     
         )
     */
     $folder = $this->registry->getRepository('KunstmaanMediaBundle:Folder')->findOneBy(array('rel' => 'image'));
     $images = $this->registry->getRepository('KunstmaanMediaBundle:Media')->findBy(array('folder' => $folder, 'deleted' => false), array(), 2);
     // Get all the available pages
     $allPages = glob($this->bundle->getPath() . '/Entity/Pages/*.php');
     $pages = array();
     foreach ($allPages as $pageFile) {
         $parts = explode("/", $pageFile);
         $className = basename($parts[count($parts) - 1], '.php');
         $contents = file_get_contents($pageFile);
         if (strpos($contents, 'abstract class') === false && strpos($contents, 'interface ') === false) {
             $classNamespace = '\\' . $this->bundle->getNamespace() . '\\Entity\\Pages\\' . $className;
             $entity = new $classNamespace();
             if (!method_exists($entity, 'getPagePartAdminConfigurations') || !method_exists($entity, 'getPageTemplates')) {
                 continue;
             }
             $ppConfigs = $entity->getPagePartAdminConfigurations();
             $ptConfigs = $entity->getPageTemplates();
             foreach ($ppConfigs as $ppConfig) {
                 $parts = explode(":", $ppConfig);
                 $ppConfigFilename = $parts[count($parts) - 1];
                 // Context found in this Page class
                 if (array_key_exists($ppConfigFilename, $sectionInfo)) {
                     // Search for templates
                     foreach ($ptConfigs as $ptConfig) {
                         $parts = explode(":", $ptConfig);
                         $ptConfigFilename = $parts[count($parts) - 1];
                         // Page template found
                         if (array_key_exists($ptConfigFilename, $sectionInfo[$ppConfigFilename]['pagetempates'])) {
                             $formType = $entity->getDefaultAdminType();
                             if (!is_object($formType)) {
                                 $formType = $this->container->get($formType);
                             }
                             // Get all page properties
                             $form = $this->container->get('form.factory')->create($formType);
                             $children = $form->createView()->children;
                             $pageFields = array();
                             foreach ($children as $field) {
                                 $name = $field->vars['name'];
                                 $attr = $field->vars['attr'];
                                 $blocks = $field->vars['block_prefixes'];
                                 if ($name == 'title' || $name == 'pageTitle') {
                                     continue;
                                 }
                                 if ($blocks[1] == 'hidden') {
                                     // do nothing
                                 } elseif ($blocks[1] == 'choice' && $blocks[1] == 'entity') {
                                     // do nothing
                                 } elseif ($blocks[1] == 'datetime') {
                                     $pageFields[]['datetime'] = array('label' => $this->labelCase($name), 'date_random' => DateTime::date('d/m/Y'), 'time_random' => DateTime::time('H:i'));
                                 } elseif ($blocks[1] == 'number') {
                                     $pageFields[]['decimal'] = array('label' => $this->labelCase($name), 'random' => Base::randomFloat(2, 0, 99999));
                                 } elseif ($blocks[1] == 'integer') {
                                     $pageFields[]['integer'] = array('label' => $this->labelCase($name), 'random' => Base::randomNumber(3000, 99999));
                                 } elseif ($blocks[1] == 'checkbox') {
                                     $pageFields[]['boolean'] = array('label' => $this->labelCase($name));
                                 } elseif ($blocks[1] == 'media') {
                                     $id = count($images) > 0 ? $images[0]->getId() : 1;
                                     $pageFields[]['media'] = array('label' => $this->labelCase($name), 'random' => $id);
                                 } elseif ($blocks[2] == 'urlchooser') {
                                     $pageFields[]['link'] = array('label' => $this->labelCase($name), 'random' => 'http://www.' . strtolower(Lorem::word()) . '.com');
                                 } elseif ($blocks[2] == 'textarea' && array_key_exists('class', $attr) && $attr['class'] == 'rich_editor') {
                                     $pageFields[]['rich_text'] = array('label' => $this->labelCase($name), 'random' => Lorem::sentence());
                                 } elseif ($blocks[2] == 'textarea' || $blocks[1] == 'text') {
                                     $pageFields[]['text'] = array('label' => $this->labelCase($name), 'random' => Lorem::word());
                                 }
                             }
                             $pages[] = array('name' => $className, 'section' => $sectionInfo[$ppConfigFilename]['context'], 'template' => $sectionInfo[$ppConfigFilename]['pagetempates'][$ptConfigFilename], 'fields' => $pageFields);
                         }
                     }
                 }
             }
         }
     }
     /*
         Example $pages contents:
         Array
         (
             [0] => Array
                 (
                     [name] => ContentPage
                     [section] => main
                     [template] => Page with left sidebar
                     [fields] => Array
                         (
                             ...
                         )
                 )
             [1] => Array
                 (
                     [name] => ContentPage
                     [section] => main
                     [template] => Full width page
                     [fields] => Array
                         (
                             ...
                         )
                 )
             [2] => Array
                 (
                     [name] => HomePage
                     [section] => main
                     [template] => Home page
                     [fields] => Array
                         (
                             ...
                         )
                 )
         )
     */
     // Add some random values in the field array, so that this values can be uses as test values
     foreach ($this->fields as $fkey => $fieldSet) {
         foreach ($fieldSet as $key => $values) {
             switch ($key) {
                 case 'multi_line':
                 case 'single_line':
                     $values[0]['random1'] = Lorem::word();
                     $values[0]['random2'] = Lorem::word();
                     $values[0]['lName'] = $this->labelCase($values[0]['fieldName']);
                     break;
                 case 'rich_text':
                     $values[0]['random1'] = Lorem::sentence();
                     $values[0]['random2'] = Lorem::sentence();
                     $values[0]['lName'] = $this->labelCase($values[0]['fieldName']);
                     break;
                 case 'link':
                     $values['url']['random1'] = 'http://www.' . strtolower(Lorem::word()) . '.com';
                     $values['url']['random2'] = 'http://www.' . strtolower(Lorem::word()) . '.com';
                     $values['url']['lName'] = $this->labelCase($values['url']['fieldName']);
                     $values['text']['random1'] = Lorem::word();
                     $values['text']['random2'] = Lorem::word();
                     $values['text']['lName'] = $this->labelCase($values['text']['fieldName']);
                     $values['new_window']['lName'] = $this->labelCase($values['new_window']['fieldName']);
                     break;
                 case 'image':
                     if (count($images) > 0) {
                         if (count($images) > 1) {
                             $values['image']['id_random1'] = $images[0]->getId();
                             $values['image']['url_random1'] = $images[0]->getUrl();
                             $values['image']['id_random2'] = $images[1]->getId();
                             $values['image']['url_random2'] = $images[1]->getUrl();
                         } else {
                             $values['image']['id_random1'] = $values['image']['id_random2'] = $images[0]->getId();
                             $values['image']['url_random1'] = $values['image']['url_random2'] = $images[0]->getUrl();
                         }
                     } else {
                         $values['image']['id_random1'] = $values['image']['id_random2'] = '1';
                         $values['image']['url_random1'] = $values['image']['url_random2'] = 'XXX';
                     }
                     $values['image']['lName'] = $this->labelCase($values['image']['fieldName']);
                     $values['alt_text']['random1'] = Lorem::word();
                     $values['alt_text']['random2'] = Lorem::word();
                     $values['alt_text']['lName'] = $this->labelCase($values['alt_text']['fieldName']);
                     break;
                 case 'boolean':
                     $values[0]['lName'] = $this->labelCase($values[0]['fieldName']);
                     break;
                 case 'integer':
                     $values[0]['random1'] = Base::randomNumber(3000, 99999);
                     $values[0]['random2'] = Base::randomNumber(3000, 99999);
                     $values[0]['lName'] = $this->labelCase($values[0]['fieldName']);
                     break;
                 case 'decimal':
                     $values[0]['random1'] = Base::randomFloat(2, 0, 99999);
                     $values[0]['random2'] = Base::randomFloat(2, 0, 99999);
                     $values[0]['lName'] = $this->labelCase($values[0]['fieldName']);
                     break;
                 case 'datetime':
                     $values[0]['date_random1'] = DateTime::date('d/m/Y');
                     $values[0]['date_random2'] = DateTime::date('d/m/Y');
                     $values[0]['time_random1'] = DateTime::time('H:i');
                     $values[0]['time_random2'] = DateTime::time('H:i');
                     $dparts = explode('/', $values[0]['date_random1']);
                     $values[0]['datetime_random1'] = $dparts[2] . '-' . $dparts[1] . '-' . $dparts[0] . ' ' . $values[0]['time_random1'] . ':00';
                     $dparts = explode('/', $values[0]['date_random2']);
                     $values[0]['datetime_random2'] = $dparts[2] . '-' . $dparts[1] . '-' . $dparts[0] . ' ' . $values[0]['time_random2'] . ':00';
                     $values[0]['lName'] = $this->labelCase($values[0]['fieldName']);
                     break;
             }
             $this->fields[$fkey][$key] = $values;
         }
     }
     $params = array('name' => $this->entity, 'pages' => $pages, 'fields' => $this->fields);
     $this->renderFile('/Features/PagePart.feature', $this->bundle->getPath() . '/Features/Admin' . $this->entity . '.feature', $params);
     $this->assistant->writeLine('Generating behat test : <info>OK</info>');
 }
Пример #20
0
 public function ownThisBookFromDetails()
 {
     $currentUserId = Auth::id();
     $bookIdToOwn = $_POST['bookIdToOwn'];
     $datetime = new \DateTime();
     $datetime->setTimeZone(new \DateTimeZone('Europe/Skopje'));
     $owns = DB::select('select * from bookstore.owns where book_id = ' . $bookIdToOwn . ' and user_id =' . $currentUserId);
     if (sizeof($owns) == 0) {
         $idTag = DB::table('owns')->insertGetId(array('book_id' => $bookIdToOwn, 'user_id' => $currentUserId, 'created_at' => $datetime, 'updated_at' => $datetime));
     } else {
         DB::table('owns')->where('book_id', $bookIdToOwn)->where('user_id', $currentUserId)->update(array('updated_at' => $datetime));
     }
     $path = '/book/' . $bookIdToOwn;
     header("Location: " . $path);
     exit;
 }
 public function testFixedSeedWithMaximumTimestamp()
 {
     $max = '2018-03-01 12:00:00';
     mt_srand(1);
     $unixTime = DateTimeProvider::unixTime($max);
     $datetimeAD = DateTimeProvider::dateTimeAD($max);
     $dateTime1 = DateTimeProvider::dateTime($max);
     $dateTimeBetween = DateTimeProvider::dateTimeBetween('2014-03-01 06:00:00', $max);
     $date = DateTimeProvider::date('Y-m-d', $max);
     $time = DateTimeProvider::time('H:i:s', $max);
     $iso8601 = DateTimeProvider::iso8601($max);
     $dateTimeThisCentury = DateTimeProvider::dateTimeThisCentury($max);
     $dateTimeThisDecade = DateTimeProvider::dateTimeThisDecade($max);
     $dateTimeThisMonth = DateTimeProvider::dateTimeThisMonth($max);
     $amPm = DateTimeProvider::amPm($max);
     $dayOfMonth = DateTimeProvider::dayOfMonth($max);
     $dayOfWeek = DateTimeProvider::dayOfWeek($max);
     $month = DateTimeProvider::month($max);
     $monthName = DateTimeProvider::monthName($max);
     $year = DateTimeProvider::year($max);
     $dateTimeThisYear = DateTimeProvider::dateTimeThisYear($max);
     mt_srand();
     //regenerate Random Date with same seed and same maximum end timestamp
     mt_srand(1);
     $this->assertEquals($unixTime, DateTimeProvider::unixTime($max));
     $this->assertEquals($datetimeAD, DateTimeProvider::dateTimeAD($max));
     $this->assertEquals($dateTime1, DateTimeProvider::dateTime($max));
     $this->assertEquals($dateTimeBetween, DateTimeProvider::dateTimeBetween('2014-03-01 06:00:00', $max));
     $this->assertEquals($date, DateTimeProvider::date('Y-m-d', $max));
     $this->assertEquals($time, DateTimeProvider::time('H:i:s', $max));
     $this->assertEquals($iso8601, DateTimeProvider::iso8601($max));
     $this->assertEquals($dateTimeThisCentury, DateTimeProvider::dateTimeThisCentury($max));
     $this->assertEquals($dateTimeThisDecade, DateTimeProvider::dateTimeThisDecade($max));
     $this->assertEquals($dateTimeThisMonth, DateTimeProvider::dateTimeThisMonth($max));
     $this->assertEquals($amPm, DateTimeProvider::amPm($max));
     $this->assertEquals($dayOfMonth, DateTimeProvider::dayOfMonth($max));
     $this->assertEquals($dayOfWeek, DateTimeProvider::dayOfWeek($max));
     $this->assertEquals($month, DateTimeProvider::month($max));
     $this->assertEquals($monthName, DateTimeProvider::monthName($max));
     $this->assertEquals($year, DateTimeProvider::year($max));
     $this->assertEquals($dateTimeThisYear, DateTimeProvider::dateTimeThisYear($max));
     mt_srand();
 }
Пример #22
0
 public static function monthNameGenitive($max = 'now')
 {
     return static::$monthsGenitive[parent::month($max) - 1];
 }
Пример #23
0
 /**
  * Performs the migration
  *
  * @param string $path
  *        	the location of the XML file.
  */
 public function actionIndex($path = null, $parentAlias = 'news-fr')
 {
     $output = '';
     $fullXml = simplexml_load_file($path);
     $xml = $fullXml->channel;
     echo $xml->title[0] . "\n";
     // Get news parent.
     $parentResource = ModxSiteContent::getResourceByAlias($parentAlias);
     if ($parentResource == null) {
         throw new \Exception('News parent resource not found.');
     }
     // Delete previous news.
     if ($this->deletePrevious) {
         $parentResource->deleteChildren();
         $output .= Yii::t('app', 'Previous resources have been deleted.') . "\n";
         if ($this->resetCounter) {
             ModxSiteContent::resetCounter();
             $output .= Yii::t('app', 'Site content id auto-increment has been reseted.') . "\n";
         }
     }
     $imagesUrls = $this->getAttachmentsUrls($xml);
     $entriesCount = 0;
     foreach ($xml->item as $entryIndex => $entry) {
         $entryOut = '';
         $knownType = true;
         // Get the namespaces.
         $namespaces = $entry->getNameSpaces(true);
         $wp = $entry->children($namespaces['wp']);
         $entryContent = $entry->children($namespaces['content']);
         // var_export($wp->post_type);
         switch ($wp->post_type[0]) {
             case 'post':
                 // Get data from the xml entry.
                 $modxResource = new ModxSiteContent();
                 $wpTitle = (string) $entry->title[0];
                 $wpDate = (string) $wp->post_date[0];
                 $pubDate = new \DateTime($wpDate);
                 $entryContentText = (string) $entryContent;
                 $postName = (string) $wp->post_name[0];
                 // Replace urls.
                 foreach ($imagesUrls as $imageUrl) {
                     $imageUrlNoProtocol = preg_replace('(^https?://)', '', $imageUrl);
                     $entryContentText = preg_replace('(https?://' . preg_quote($imageUrlNoProtocol) . ')', $this->imagesLocalUrl . basename($imageUrl), $entryContentText);
                 }
                 // Set paragraphs.
                 $entryContentParagraphs = explode("\n", $entryContentText);
                 $entryContentMulitParagraph = '<p>' . implode('</p><p>', $entryContentParagraphs) . '</p>';
                 // Output to console.
                 // $entryOut .= Yii::t('console', 'Title') . ': ' . $wpTitle . "\n";
                 // $entryOut .= Yii::t('console', 'Date') . ': ' . $pubDate->getTimestamp() . "\n";
                 // $entryOut .= Yii::t('console', 'Content') . ': ' . $entryContent . "\n";
                 // Set modx resource.
                 $modxResource->parent = $parentResource->id;
                 $modxResource->pagetitle = $wpTitle;
                 $modxResource->publishedon = $pubDate->getTimestamp();
                 $modxResource->published = '1';
                 $modxResource->content = $entryContentMulitParagraph;
                 $modxResource->hidemenu = '1';
                 $modxResource->alias = $this->aliasPrefix . $postName . $this->aliasSuffix;
                 $modxResource->template = isset($this->modxTemplate) ? $this->modxTemplate : $parentResource->template;
                 if ($this->freezeUri) {
                     $modxResource->uri_override = 1;
                     $modxResource->uri = $this->uriPrefix . $postName . $this->uriSuffix;
                 }
                 if ($modxResource->save()) {
                     $entriesCount++;
                 } else {
                     throw new \Exception('Could not save content ' . print_r($modxResource->errors, true));
                 }
                 break;
             default:
                 $knownType = false;
                 break;
         }
         if ($knownType) {
             $output .= $entryOut . (strlen($entryOut) > 0 ? "\n" : '');
         }
     }
     // Import images.
     if ($this->importImages) {
         $attachmentImporter = new AttachmentImporter(['parallelDownloads' => $this->parallelImageDownloads, 'imagesPath' => $this->imagesPath, 'replaceFiles' => $this->replaceImages]);
         $attachmentImporter->importImages($imagesUrls);
     }
     $output .= Yii::t('app', 'Entries count: {entriesCount}', ['entriesCount' => $entriesCount]) . "\n";
     echo $output;
 }
Пример #24
0
 /**
  * Return a valid company registration number.
  *
  * @return string
  */
 public function companyNumber()
 {
     return sprintf('%s/%s/%s', \Faker\Provider\DateTime::dateTimeBetween('-50 years', 'now')->format('Y'), static::randomNumber(6, true), static::randomElement(static::$legalEntities));
 }