/**
  * 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)]);
     }
 }
 /**
  * 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>');
 }
 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();
 }
Example #4
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]);
 }