Get all of the directories within a given directory.
public static directories ( string $directory ) : array | ||
$directory | string | |
return | array |
/** * Run the database seeds. * * @return void */ public function run() { // Model::unguard(); DB::statement('SET FOREIGN_KEY_CHECKS=0;'); $folderpath = base_path() . '/database/seeds/templates/'; $folders = File::directories($folderpath); $latest = '11232015'; foreach ($folders as $value) { $_dir = explode("/", str_replace('\\', '/', $value)); $cnt = count($_dir); $name = $_dir[$cnt - 1]; $latest_date = DateTime::createFromFormat('mdY', $latest); $now = DateTime::createFromFormat('mdY', $name); if ($now > $latest_date) { $latest = $name; } } $filePath = $folderpath . $latest . '/Masterfile.xlsx'; $reader = ReaderFactory::create(Type::XLSX); // for XLSX files $reader->open($filePath); DB::table('channel_items')->truncate(); foreach ($reader->getSheetIterator() as $sheet) { if ($sheet->getName() == 'MKL Mapping') { $cnt = 0; foreach ($sheet->getRowIterator() as $row) { if ($row[0] != '') { if ($cnt > 0) { // dd($row); if (!ctype_digit(trim($row[4])) || !ctype_digit(trim($row[5])) || !ctype_digit(trim($row[6]))) { InvalidMapping::create(['premise_code' => trim($row[0]), 'customer_code' => trim($row[1]), 'store_code' => trim($row[2]), 'sku_code' => trim($row[3]), 'ig' => trim($row[4]), 'multiplier' => trim($row[5]), 'minstock' => trim($row[6]), 'type' => 'MKL Mapping', 'remarks' => 'Invalid mapping']); } else { $channel = ''; if (trim($row[0]) != '') { $channel = Channel::where('channel_code', trim($row[0]))->first(); } $item = Item::where('sku_code', trim($row[3]))->first(); if (!empty($item)) { $item_type = ItemType::where('type', "MKL")->first(); $osa_tagging = 0; if (isset($row[7])) { $osa_tagging = trim($row[7]); } $npi_tagging = 0; if (isset($row[8])) { $npi_tagging = trim($row[8]); } ChannelItem::firstOrCreate(['channel_id' => $channel->id, 'item_id' => $item->id, 'item_type_id' => $item_type->id, 'ig' => trim($row[4]), 'fso_multiplier' => trim($row[5]), 'min_stock' => trim($row[6]), 'osa_tagged' => $osa_tagging, 'npi_tagged' => $npi_tagging]); } } } $cnt++; } } } } $reader->close(); }
public function run() { $folderpath = 'database/seeds/seed_files'; $folders = File::directories($folderpath); $latest = '11232015'; foreach ($folders as $value) { $_dir = explode("/", $value); $cnt = count($_dir); $name = $_dir[$cnt - 1]; $latest_date = DateTime::createFromFormat('mdY', $latest); $now = DateTime::createFromFormat('mdY', $name); if ($now > $latest_date) { $latest = $name; } } $file_path = $folderpath . "/" . $latest . "/Secondary Display.xlsx"; echo (string) $file_path, "\n"; Model::unguard(); DB::statement('SET FOREIGN_KEY_CHECKS=0;'); DB::table('secondary_display_lookups')->truncate(); $reader = ReaderFactory::create(Type::XLSX); // for XLSX files $filePath = $file_path; $reader->open($filePath); // Accessing the sheet name when reading foreach ($reader->getSheetIterator() as $sheet) { if ($sheet->getName() == 'Sheet1') { $cnt = 0; foreach ($sheet->getRowIterator() as $row) { if ($cnt > 0) { // dd($row); $store = Store::where('store_code', trim($row[1]))->first(); $brands = array(); if (!empty($store)) { $x = 1; for ($i = 3; $i < 29; $i++) { if ($row[$i] == "1.0") { $brands[] = $x; } $x++; } foreach ($brands as $value) { SecondaryDisplayLookup::create(['store_id' => $store->id, 'secondary_display_id' => $value]); } } } $cnt++; } } else { } } $reader->close(); DB::statement('SET FOREIGN_KEY_CHECKS=1;'); Model::reguard(); }
public function run() { Model::unguard(); DB::statement('SET FOREIGN_KEY_CHECKS=0;'); $folderpath = base_path() . '/database/seeds/seed_files/'; $folders = File::directories($folderpath); $latest = '11232015'; foreach ($folders as $value) { $_dir = explode("/", str_replace('\\', '/', $value)); $cnt = count($_dir); $name = $_dir[$cnt - 1]; $latest_date = DateTime::createFromFormat('mdY', $latest); $now = DateTime::createFromFormat('mdY', $name); if ($now > $latest_date) { $latest = $name; } } $filePath = $folderpath . $latest . '/Masterfile.xlsx'; $reader = ReaderFactory::create(Type::XLSX); // for XLSX files $reader->open($filePath); echo 'Seeding ' . $filePath . PHP_EOL; // DB::table('other_barcodes')->truncate(); Item::where('active', 1)->update(['cleared' => 0]); foreach ($reader->getSheetIterator() as $sheet) { if ($sheet->getName() == 'Other Codes') { $cnt = 0; foreach ($sheet->getRowIterator() as $row) { if (!is_null($row[0]) && trim($row[0]) != '') { if ($cnt > 0) { $item = Item::where('sku_code', trim($row[0]))->first(); if (!empty($item)) { if ($item->cleared == 0) { OtherBarcode::where('item_id', $item->id)->delete(); $item->cleared = 1; $item->save(); } $area = Area::where('area', strtoupper($row[1]))->first(); if (!empty($item) && !empty($area)) { OtherBarcode::firstOrCreate(['item_id' => $item->id, 'area_id' => $area->id, 'other_barcode' => trim($row[2])]); } } else { // dd($row); } } $cnt++; } } } } $reader->close(); DB::statement('SET FOREIGN_KEY_CHECKS=1;'); Model::reguard(); }
public function run() { $folderpath = 'database/seeds/seed_files'; $folders = File::directories($folderpath); $latest = '11232015'; foreach ($folders as $value) { $_dir = explode("/", $value); $cnt = count($_dir); $name = $_dir[$cnt - 1]; $latest_date = DateTime::createFromFormat('mdY', $latest); $now = DateTime::createFromFormat('mdY', $name); if ($now > $latest_date) { $latest = $name; } } $file_path = $folderpath . "/" . $latest . "/Store SOS.xlsx"; echo (string) $file_path, "\n"; Model::unguard(); DB::statement('SET FOREIGN_KEY_CHECKS=0;'); DB::table('store_sos_tags')->truncate(); $reader = ReaderFactory::create(Type::XLSX); // for XLSX files $filePath = $file_path; $reader->open($filePath); // Accessing the sheet name when reading foreach ($reader->getSheetIterator() as $sheet) { if ($sheet->getName() == 'Sheet1') { $cnt = 0; foreach ($sheet->getRowIterator() as $row) { if (!empty($row[0])) { // dd($row); if ($cnt > 0) { // dd($row); $store = Store::where('store_code', $row[0])->first(); // dd($store); $category = FormCategory::where('category', strtoupper($row[2]))->first(); // dd($category); $sos = SosTagging::where('sos_tag', strtoupper($row[3]))->first(); // dd($sos); StoreSosTag::insert(array('store_id' => $store->id, 'form_category_id' => $category->id, 'sos_tag_id' => $sos->id)); // echo (string)$row[0], "\n"; } $cnt++; } } } else { } } $reader->close(); DB::statement('SET FOREIGN_KEY_CHECKS=1;'); Model::reguard(); }
public function run() { $folderpath = 'database/seeds/seed_files'; $folders = File::directories($folderpath); $latest = '11232015'; foreach ($folders as $value) { $_dir = explode("/", $value); $cnt = count($_dir); $name = $_dir[$cnt - 1]; $latest_date = DateTime::createFromFormat('mdY', $latest); $now = DateTime::createFromFormat('mdY', $name); if ($now > $latest_date) { $latest = $name; } } $file_path = $folderpath . "/" . $latest . "/Secondary Display.xlsx"; echo (string) $file_path, "\n"; Model::unguard(); DB::statement('SET FOREIGN_KEY_CHECKS=0;'); DB::table('secondary_displays')->truncate(); $reader = ReaderFactory::create(Type::XLSX); // for XLSX files $filePath = $file_path; $reader->open($filePath); // Accessing the sheet name when reading foreach ($reader->getSheetIterator() as $sheet) { if ($sheet->getName() == 'Sheet2') { $cnt = 0; foreach ($sheet->getRowIterator() as $row) { if (!is_null($row[0])) { if ($cnt > 0) { $category = FormCategory::firstOrCreate(['category' => strtoupper($row[0])]); $category->secondary_display = 1; $category->update(); if (!empty($category)) { SecondaryDisplay::create(array('category_id' => $category->id, 'brand' => $row[1])); } } $cnt++; } } } else { } } $reader->close(); DB::statement('SET FOREIGN_KEY_CHECKS=1;'); Model::reguard(); }
public function run() { $folderpath = 'database/seeds/seed_files'; $folders = File::directories($folderpath); $latest = '11232015'; foreach ($folders as $value) { $_dir = explode("/", $value); $cnt = count($_dir); $name = $_dir[$cnt - 1]; $latest_date = DateTime::createFromFormat('mdY', $latest); $now = DateTime::createFromFormat('mdY', $name); if ($now > $latest_date) { $latest = $name; } } $file_path = $folderpath . "/" . $latest . "/Sub Form.xlsx"; echo (string) $file_path, "\n"; Model::unguard(); DB::statement('SET FOREIGN_KEY_CHECKS=0;'); DB::table('temp_forms')->truncate(); $reader = ReaderFactory::create(Type::XLSX); // for XLSX files $filePath = $file_path; $reader->open($filePath); // Accessing the sheet name when reading foreach ($reader->getSheetIterator() as $sheet) { if ($sheet->getName() == 'Sheet1') { $cnt = 0; foreach ($sheet->getRowIterator() as $row) { if ($cnt > 0) { if (!is_null($row[2])) { $prompt = addslashes($row[1]); DB::statement('INSERT INTO temp_forms (code, prompt, required, type, choices, expected_answer) VALUES ("' . $row[0] . '","' . $prompt . '","' . $row[2] . '","' . $row[3] . '","' . $row[4] . '","' . $row[6] . '");'); } } $cnt++; } } else { } } $reader->close(); DB::statement('SET FOREIGN_KEY_CHECKS=1;'); Model::reguard(); }
public function run() { Model::unguard(); DB::statement('SET FOREIGN_KEY_CHECKS=0;'); $folderpath = base_path() . '/database/seeds/seed_files/'; $folders = File::directories($folderpath); $latest = '11232015'; foreach ($folders as $value) { $_dir = explode("/", str_replace('\\', '/', $value)); $cnt = count($_dir); $name = $_dir[$cnt - 1]; $latest_date = DateTime::createFromFormat('mdY', $latest); $now = DateTime::createFromFormat('mdY', $name); if ($now > $latest_date) { $latest = $name; } } $filePath = $folderpath . $latest . '/Masterfile.xlsx'; $reader = ReaderFactory::create(Type::XLSX); // for XLSX files $reader->open($filePath); // DB::table('store_items'); foreach ($reader->getSheetIterator() as $sheet) { if ($sheet->getName() == 'Assortment Mapping') { $cnt = 0; foreach ($sheet->getRowIterator() as $row) { if ($row[0] != '') { if ($cnt > 0) { if (!ctype_digit(trim($row[4]))) { InvalidMapping::create(['premise_code' => trim($row[0]), 'customer_code' => trim($row[1]), 'store_code' => trim($row[2]), 'sku_code' => trim($row[3]), 'ig' => trim($row[4]), 'multiplier' => trim($row[5]), 'minstock' => trim($row[6]), 'type' => 'Assortment Mapping', 'remarks' => 'Invalid mapping']); } else { $channel = ''; $customer = ''; $store = ''; if (trim($row[0]) != '') { $channel = Channel::where('channel_code', trim($row[0]))->get(); } if (trim($row[1]) != '') { $customer = Customer::where('customer_code', trim($row[1]))->get(); } if (trim($row[2]) != '') { $store = Store::where('store_code', trim($row[2]))->first(); } // dd($store); $stores = Store::where(function ($query) use($channel) { if (!empty($channel)) { $channel_id = []; foreach ($channel as $value) { $channel_id[] = $value->id; } $query->whereIn('channel_id', $channel_id); } })->where(function ($query) use($customer) { if (!empty($customer)) { $customer_id = []; foreach ($customer as $value) { $customer_id[] = $value->id; } $query->whereIn('customer_id', $customer_id); } })->where(function ($query) use($store) { if (!empty($store)) { $query->where('store', $store->id); } })->get(); // dd($stores); $item = Item::where('sku_code', trim($row[3]))->first(); if (!empty($item)) { $item_type = ItemType::where('type', "ASSORTMENT")->first(); foreach ($stores as $store) { $w_mkl = StoreItem::where('store_id', $store->id)->where('item_id', $item->id)->get(); $cw_mkl = ChannelItem::where('channel_id', $store->channel_id)->where('item_id', $item->id)->get(); if (count($w_mkl) == 0) { StoreItem::firstOrCreate(['store_id' => $store->id, 'item_id' => $item->id, 'item_type_id' => $item_type->id, 'ig' => trim($row[4]), 'fso_multiplier' => trim($row[5]), 'min_stock' => trim($row[6]), 'osa_tagged' => 0, 'npi_tagged' => 0]); } if (count($cw_mkl) == 0) { ChannelItem::firstOrCreate(['channel_id' => $store->channel_id, 'item_id' => $item->id, 'item_type_id' => $item_type->id, 'ig' => trim($row[4]), 'fso_multiplier' => trim($row[5]), 'min_stock' => trim($row[6]), 'osa_tagged' => 0, 'npi_tagged' => 0]); } } } } } $cnt++; } } } } $reader->close(); $hash = UpdateHash::find(1); if (empty($hash)) { UpdateHash::create(['hash' => \Hash::make(date('Y-m-d H:i:s'))]); } else { $hash->hash = md5(date('Y-m-d H:i:s')); $hash->update(); } DB::statement('SET FOREIGN_KEY_CHECKS=1;'); Model::reguard(); }
public function run() { $folderpath = 'database/seeds/seed_files'; $folders = File::directories($folderpath); $latest = '11232015'; foreach ($folders as $value) { $_dir = explode("/", $value); $cnt = count($_dir); $name = $_dir[$cnt - 1]; $latest_date = DateTime::createFromFormat('mdY', $latest); $now = DateTime::createFromFormat('mdY', $name); if ($now > $latest_date) { $latest = $name; } } $file_path = $folderpath . "/" . $latest . "/OSA Target.xlsx"; echo (string) $file_path, "\n"; Model::unguard(); DB::statement('SET FOREIGN_KEY_CHECKS=0;'); DB::table('osa_lookups')->truncate(); DB::table('osa_lookup_targets')->truncate(); $reader = ReaderFactory::create(Type::XLSX); // for XLSX files $filePath = $file_path; $reader->open($filePath); // Accessing the sheet name when reading foreach ($reader->getSheetIterator() as $sheet) { if ($sheet->getName() == 'Sheet1') { $cnt = 0; foreach ($sheet->getRowIterator() as $row) { if (!is_null($row[0])) { if ($cnt > 0) { // dd($row); $customer_id = 0; $customer = Customer::where('customer_code', $row[0])->first(); if (!empty($customer)) { $customer_id = $customer->id; } $region_id = 0; $region = Region::where('region_code', $row[1])->first(); if (!empty($region)) { $region_id = $region->id; } $distributor_id = 0; $distributor = Distributor::where('distributor_code', $row[2])->first(); if (!empty($distributor)) { $distributor_id = $distributor->id; } $store_id = 0; $store = Store::where('store_code', $row[3])->first(); if (!empty($store)) { $store_id = $store->id; } $template_id = 0; $template = AuditTemplate::where('template_code', $row[4])->first(); if (!empty($template)) { $template_id = $template->id; } $category = FormCategory::where('category', $row[5])->first(); if (!empty($category)) { $osalookup_id = 0; $osalookup = OsaLookup::where('customer_id', $customer_id)->where('region_id', $region_id)->where('distributor_id', $distributor_id)->where('store_id', $store_id)->where('template_id', $template_id)->first(); if (empty($osalookup)) { $osalookup = new OsaLookup(); $osalookup->customer_id = $customer_id; $osalookup->region_id = $region_id; $osalookup->distributor_id = $distributor_id; $osalookup->store_id = $store_id; $osalookup->template_id = $template_id; $osalookup->save(); } $osalookup_id = $osalookup->id; OsaLookupTarget::create(array('osa_lookup_id' => $osalookup_id, 'category_id' => $category->id, 'target' => $row[8], 'total' => $row[9])); } } $cnt++; } } } else { } } $reader->close(); DB::statement('SET FOREIGN_KEY_CHECKS=1;'); Model::reguard(); }
public static function find() { self::$dir = app_path() . '/plugins/'; $plugins = array_merge(File::directories(self::$dir), glob(self::$dir . '*.php')); foreach ($plugins as $key => $val) { $plugins[$key] = self::_strip($val); } return $plugins; }
private function _getLangPacks() { $langFiles = array(); $langs = \File::directories(mkny_lang_path()); foreach ($langs as $lang) { $langFiles[] = class_basename($lang); } return $langFiles; }
private function cleanup($requestId) { $dirs = \File::directories(self::DIR); foreach ($dirs as $dir) { if (strpos($dir, $requestId) !== false) { continue; } \File::deleteDirectory($dir); } }
function makeupBlocks() { $blocks_path = HelperFile::normalizeFilePath(Manager::getPath('blocks')); if (file_exists($blocks_path)) { foreach (\File::directories($blocks_path) as $path) { $path = HelperFile::normalizeFilePath($path); Manager::block(trim(str_replace($blocks_path, '', $path), '/')); } } }
protected function copyDirectories() { $directories = \File::directories(base_path()); foreach ($directories as $directory) { if (!strpos($directory, 'vendor') && !strpos($directory, 'backup')) { $folder = str_replace(base_path(), '', $directory); \File::copyDirectory($directory, base_path() . '/backup/' . $this->timestamp . $folder); } } }
/** * Execute the console command. * * @return mixed */ public function handle() { $path = base_path('vendor'); $vendor_paths = \File::directories($path); $path = rtrim(rtrim($path, '\\'), '/'); $this->info('Сканируем установленные пакеты на наличие папок .git и .svn'); $check_directories = []; foreach ($vendor_paths as $vendor_path) { $package_paths = File::directories($vendor_path); foreach ($package_paths as $package_path) { $check_directories[] = (string) $package_path; } } $progress = new \Symfony\Component\Console\Helper\ProgressBar($this->output, sizeof($check_directories)); $progress->setFormat('debug'); $progress->start(); foreach ($check_directories as $directory) { $progress->advance(); $is_git = $this->checkGit($directory); if (!$is_git) { $this->checkSvn($directory); } } $progress->finish(); $this->info(''); $this->info('Сканирование завершено.'); $table = []; $separator = ['-', '-', '-', '-']; if ($this->touched_git) { $this->info('Имеются изменные файлы GIT: '); foreach ($this->touched_git as $package_path => $files) { $package = larasafepath($package_path); foreach ($files as $file => $type) { $table[] = ['GIT', $package, larasafepath($file), \Illuminate\Support\Arr::get($this->git_types, $type, $type)]; } $table[] = $separator; } } if ($this->touched_svn) { $this->info('Имеются изменные файлы SVN: '); foreach ($this->touched_svn as $package_path => $files) { $package = larasafepath($package_path); foreach ($files as $file => $type) { $table[] = ['SVN', $package, trim(str_replace($package, '', larasafepath($file)), '/'), \Illuminate\Support\Arr::get($this->svn_types, $type, $type)]; } $table[] = $separator; } } if ($table) { unset($table[sizeof($table) - 1]); $this->info(''); $this->table(['VCS', 'package', 'file', 'type'], $table); } }
/** * Execute the console command. * * @return void */ public function fire() { $now = time(); foreach (File::directories('public/uploads') as $dir) { $dirtime = filemtime($dir); if ($now - $dirtime > 3600) { File::deleteDirectory($dir); $this->info('Directory ' . $dir . ' was deleted'); } } }
public function hasUiLanguage($languageCode) { $directories = \File::directories(app_path() . '/lang/'); $uiLanguages = array(); foreach ($directories as $directory) { $dir = basename($directory); if ($dir === $languageCode) { return true; } } return false; }
/** * Create virtual array for theme change * @return array */ public function themes() { $path = themes_path(); $dir_arr = \File::directories($path); $themes = array(); foreach ($dir_arr as $path) { $name_arr = explode('/', $path); $name = array_pop($name_arr); $theme_name = array_get(theme_settings($path), 'theme_name'); $themes[$name] = $theme_name; } return $themes; }
/** * Execute the console command. * * @return void */ public function fire() { $path_to_copy_from = base_path('workbench/static/public'); $dirs_to_copy = \File::directories($path_to_copy_from); $path_to_copy_into = base_path('workbench/pongocms/cms/public'); foreach ($dirs_to_copy as $dir) { $dir_arr = explode('/', $dir); $dir_name = end($dir_arr); \File::copyDirectory($dir, $path_to_copy_into . '/' . $dir_name); $this->info($dir_name . ' copied!'); } $this->info('Assets imported successfully!'); // Calling asset:publish $this->call('asset:publish', array('--bench' => 'pongocms/cms')); return; }
public function run() { $folderpath = 'database/seeds/seed_files'; $folders = File::directories($folderpath); $latest = '11232015'; foreach ($folders as $value) { $_dir = explode("/", $value); $cnt = count($_dir); $name = $_dir[$cnt - 1]; $latest_date = DateTime::createFromFormat('mdY', $latest); $now = DateTime::createFromFormat('mdY', $name); if ($now > $latest_date) { $latest = $name; } } $file_path = $folderpath . "/" . $latest . "/Category Tagging.xlsx"; echo (string) $file_path, "\n"; Model::unguard(); DB::statement('SET FOREIGN_KEY_CHECKS=0;'); Excel::selectSheets('Sheet1')->load($file_path, function ($reader) { $records = $reader->get(); $records->each(function ($row) { if (!is_null($row->category)) { $form_category = FormCategory::where('category', $row->category)->first(); // dd($form_category); if (!empty($form_category)) { $form_category->sos_tagging = $row->sos; $form_category->osa_tagging = $row->osa; $form_category->secondary_display = $row->secondary_display; $form_category->update(); } } }); }); DB::statement('SET FOREIGN_KEY_CHECKS=1;'); Model::reguard(); }
public function run() { $start_date = ''; $end_date = ''; $folderpath = 'database/seeds/seed_files'; $folders = File::directories($folderpath); $latest = '11232015'; foreach ($folders as $value) { $_dir = explode("/", $value); $cnt = count($_dir); $name = $_dir[$cnt - 1]; $latest_date = DateTime::createFromFormat('mdY', $latest); $now = DateTime::createFromFormat('mdY', $name); if ($now > $latest_date) { $latest = $name; } } $file_path = $folderpath . "/" . $latest . "/Store Mapping.xlsx"; echo (string) $file_path, "\n"; // dd($file_path); Model::unguard(); DB::statement('SET FOREIGN_KEY_CHECKS=0;'); DB::table('audit_templates')->truncate(); Excel::selectSheets('Sheet1')->load($file_path, function ($reader) { $records = $reader->get(); $records->each(function ($row) { if (!is_null($row->template)) { $template = AuditTemplate::where('template', $row->template)->first(); if (count($template) == 0) { $newtemplate = new AuditTemplate(); $newtemplate->template_code = $row->channel_code; $newtemplate->template = $row->template; $newtemplate->save(); } } }); }); DB::table('grade_matrixs')->truncate(); Excel::selectSheets('Sheet1')->load($file_path, function ($reader) { $records = $reader->get(); $records->each(function ($row) { if (!is_null($row->enrollment_type)) { $matrix = GradeMatrix::where('desc', $row->enrollment_type)->first(); if (count($matrix) == 0) { $newmatrix = new GradeMatrix(); $newmatrix->desc = $row->enrollment_type; $newmatrix->save(); } } }); }); DB::table('users')->truncate(); DB::table('role_user')->truncate(); Excel::selectSheets('Sheet1')->load($file_path, function ($reader) { $records = $reader->get(); $records->each(function ($row) { if (!is_null($row->fullname)) { $userlist = explode("/", $row->fullname); $emaillist = explode("/", $row->email); // dd($row); for ($i = 0; $i < count($userlist); $i++) { $user = User::where('username', $row->username)->first(); if (count($user) == 0) { if (empty($emaillist[$i])) { $email = strtolower($row->username . "@unilever.com"); } else { $email = strtolower($emaillist[$i]); } $newuser = User::create(array('name' => strtoupper($userlist[$i]), 'email' => $email, 'username' => $row->username, 'password' => Hash::make('password'))); $newuser->roles()->attach(3); } else { // $user->name = strtoupper($row->fullname); // $user->username = $row->username; // $user->email = strtolower($row->email); // $user->update(); // if(!$user->hasRole('field')){ // $user->roles()->attach(3); // } // echo $user->hasRole('field'); } } } }); }); DB::table('accounts')->truncate(); Excel::selectSheets('Sheet1')->load($file_path, function ($reader) { $records = $reader->get(); $records->each(function ($row) { if (!is_null($row->account)) { $account = Account::where('account', $row->account)->first(); if (count($account) == 0) { $newaccount = new Account(); $newaccount->account = $row->account; $newaccount->save(); } } }); }); DB::table('customers')->truncate(); Excel::selectSheets('Sheet1')->load($file_path, function ($reader) { $records = $reader->get(); $records->each(function ($row) { if (!is_null($row->account)) { // var_dump($row); $account = Account::where('account', $row->account)->first(); if (!empty($account)) { $customer = Customer::where('account_id', $account->id)->where('customer_code', $row->customer_code)->where('customer', $row->customer)->first(); if (count($customer) == 0) { $newcustomer = new Customer(); $newcustomer->account_id = $account->id; $newcustomer->customer_code = $row->customer_code; $newcustomer->customer = $row->customer; $newcustomer->save(); } } } }); }); DB::table('areas')->truncate(); Excel::selectSheets('Sheet1')->load($file_path, function ($reader) { $records = $reader->get(); $records->each(function ($row) { if (!is_null($row->account)) { $account = Account::where('account', $row->account)->first(); if (!empty($account)) { $customer = Customer::where('account_id', $account->id)->where('customer_code', $row->customer_code)->where('customer', $row->customer)->first(); if (!empty($customer)) { $area = Area::where('customer_id', $customer->id)->where('area', $row->area)->first(); if (count($area) == 0) { $newarea = new Area(); $newarea->customer_id = $customer->id; $newarea->area = $row->area; $newarea->save(); } } } } }); }); DB::table('regions')->truncate(); Excel::selectSheets('Sheet1')->load($file_path, function ($reader) { $records = $reader->get(); $records->each(function ($row) { if (!is_null($row->account)) { $region = Region::where('region_code', $row->region_code)->where('region', $row->region)->first(); if (count($region) == 0) { $newregion = new Region(); $newregion->region_code = $row->region_code; $newregion->region = $row->region; $newregion->save(); } } }); }); DB::table('distributors')->truncate(); Excel::selectSheets('Sheet1')->load($file_path, function ($reader) { $records = $reader->get(); $records->each(function ($row) { if (!is_null($row->account)) { $dis = Distributor::where('distributor_code', $row->distributor_code)->where('distributor', $row->distributor)->first(); if (count($dis) == 0) { $newdis = new Distributor(); $newdis->distributor_code = $row->distributor_code; $newdis->distributor = strtoupper($row->distributor); $newdis->save(); } } }); }); DB::table('stores')->truncate(); DB::table('store_user')->truncate(); Excel::selectSheets('Sheet1')->load($file_path, function ($reader) { $records = $reader->get(); $records->each(function ($row) { if (!is_null($row->account)) { $account = Account::where('account', $row->account)->first(); if (!empty($account)) { $customer = Customer::where('account_id', $account->id)->where('customer_code', $row->customer_code)->where('customer', $row->customer)->first(); if (!empty($customer)) { $region = Region::where('region_code', $row->region_code)->first(); $dis = Distributor::where('distributor_code', $row->distributor_code)->first(); $store = Store::where('account_id', $account->id)->where('customer_id', $customer->id)->where('region_id', $region->id)->where('distributor_id', $dis->id)->where('store_code', $row->store_code)->where('store', $row->store_name)->first(); if (count($store) == 0) { $template = AuditTemplate::where('template', $row->template)->first(); $matrix = GradeMatrix::where('desc', $row->enrollment_type)->first(); $newstore = new Store(); $newstore->account_id = $account->id; $newstore->customer_id = $customer->id; $newstore->region_id = $region->id; $newstore->distributor_id = $dis->id; $newstore->store_code = $row->store_code; $newstore->store = $row->store_name; $newstore->grade_matrix_id = $matrix->id; $newstore->audit_template_id = $template->id; $newstore->save(); $emaillist = explode("/", $row->email); for ($i = 0; $i < count($emaillist); $i++) { if (empty($emaillist[$i])) { $email = strtolower($row->username . "@unilever.com"); } else { $email = strtolower($emaillist[$i]); } $user = User::where('email', $email)->first(); $newstore->users()->attach($user->id); } } else { $emaillist = explode("/", $row->email); for ($i = 0; $i < count($emaillist); $i++) { if (empty($emaillist[$i])) { $email = strtolower($row->username . "@unilever.com"); } else { $email = strtolower($emaillist[$i]); } $user = User::where('email', $email)->first(); $store->users()->attach($user->id); } } } } } }); }); DB::statement('SET FOREIGN_KEY_CHECKS=1;'); Model::reguard(); }
public function run() { Model::unguard(); DB::statement('SET FOREIGN_KEY_CHECKS=0;'); $folderpath = base_path() . '/database/seeds/seed_files/'; $folders = File::directories($folderpath); $latest = '11232015'; foreach ($folders as $value) { $_dir = explode("/", str_replace('\\', '/', $value)); $cnt = count($_dir); $name = $_dir[$cnt - 1]; $latest_date = DateTime::createFromFormat('mdY', $latest); $now = DateTime::createFromFormat('mdY', $name); if ($now > $latest_date) { $latest = $name; } } $filePath = $folderpath . $latest . '/Masterfile.xlsx'; $reader = ReaderFactory::create(Type::XLSX); // for XLSX files $reader->open($filePath); // DB::table('divisions')->truncate(); // DB::table('categories')->truncate(); // DB::table('sub_categories')->truncate(); // DB::table('brands')->truncate(); // DB::table('items')->truncate(); foreach ($reader->getSheetIterator() as $sheet) { if ($sheet->getName() == 'Items') { $cnt = 0; Item::where('active', 1)->update(['active' => 0, 'cleared' => 0]); foreach ($sheet->getRowIterator() as $row) { if ($row[0] != '') { if ($cnt > 0) { $division = Division::firstOrCreate(['division' => strtoupper($row[9])]); $category = Category::firstOrCreate(['category' => strtoupper($row[1]), 'category_long' => strtoupper($row[0])]); $sub_category = SubCategory::firstOrCreate(['category_id' => $category->id, 'sub_category' => strtoupper($row[7])]); $brand = Brand::firstOrCreate(['brand' => strtoupper($row[8])]); $itemExist = Item::where('sku_code', strtoupper($row[2]))->first(); if (empty($itemExist)) { $item = Item::firstOrCreate(['sku_code' => trim($row[2]), 'barcode' => $row[3], 'description' => strtoupper($row[4]), 'description_long' => strtoupper($row[5]), 'conversion' => trim($row[6]), 'lpbt' => trim($row[10]), 'division_id' => $division->id, 'category_id' => $category->id, 'sub_category_id' => $sub_category->id, 'brand_id' => $brand->id, 'active' => 1]); } else { $itemExist->sku_code = trim($row[2]); $itemExist->barcode = $row[3]; $itemExist->description = strtoupper($row[4]); $itemExist->description_long = strtoupper($row[5]); $itemExist->conversion = trim($row[6]); $itemExist->lpbt = trim($row[10]); $itemExist->division_id = $division->id; $itemExist->category_id = $category->id; $itemExist->sub_category_id = $sub_category->id; $itemExist->brand_id = $brand->id; $itemExist->active = 1; $itemExist->save(); } } $cnt++; } } } } $reader->close(); DB::statement('SET FOREIGN_KEY_CHECKS=1;'); Model::reguard(); }
public static function getViewFolderTree($dir, $ret = array()) { $tmp = new \stdClass(); $dirArr = explode('/', $dir); $tmp->directory = end($dirArr); $tmp->path = $dir; $tmp->files = \File::files($dir); foreach ($tmp->files as $fk => $file) { $filArr = explode('/', $file); $tmp->files[$fk] = end($filArr); } $tmp->folders = \File::directories($dir); foreach ($tmp->folders as $fk => $folder) { $tmp->folders[$fk] = static::getViewFolderTree($folder, $ret); } $ret = $tmp; return $ret; }
public function run() { Model::unguard(); DB::statement('SET FOREIGN_KEY_CHECKS=0;'); DB::table('form_categories')->truncate(); DB::table('form_groups')->truncate(); DB::table('forms')->truncate(); DB::table('single_selects')->truncate(); DB::table('form_single_selects')->truncate(); DB::table('multi_selects')->truncate(); DB::table('form_multi_selects')->truncate(); DB::table('form_formulas')->truncate(); DB::table('form_conditions')->truncate(); DB::table('audit_template_forms')->truncate(); DB::table('audit_template_groups')->truncate(); DB::table('audit_template_categories')->truncate(); // \DB::beginTransaction(); // try { $folderpath = 'database/seeds/seed_files'; $folders = File::directories($folderpath); $latest = '11232015'; foreach ($folders as $value) { $_dir = explode("/", $value); $cnt = count($_dir); $name = $_dir[$cnt - 1]; $latest_date = DateTime::createFromFormat('mdY', $latest); $now = DateTime::createFromFormat('mdY', $name); if ($now > $latest_date) { $latest = $name; } } // $this->filename = $folderpath.$latest.'/mtprimarysales.csv'; $files = File::allFiles($folderpath . "/" . $latest . "/templates"); foreach ($files as $file) { echo (string) $file, "\n"; $reader = ReaderFactory::create(Type::XLSX); // for XLSX files $reader->open($file); // // Accessing the sheet name when reading foreach ($reader->getSheetIterator() as $sheet) { if ($sheet->getName() == 'Sheet1') { $cnt = 0; foreach ($sheet->getRowIterator() as $row) { if ($cnt > 0) { if ($row[1] != '') { $start_date = $row[4]; $end_date = $row[5]; $template = AuditTemplate::firstOrCreate(['template' => $row[1]]); $template->start_date = $start_date; $template->end_date = $end_date; $template->update(); $category = FormCategory::firstOrCreate(['category' => $row[3]]); // dd($category); $group = FormGroup::firstOrCreate(['group_desc' => $row[6]]); $type = $row[11]; if (strtoupper($type) == 'DOUBLE') { $form_type = FormType::where('form_type', "NUMERIC")->first(); } else { $form_type = FormType::where('form_type', strtoupper($type))->first(); } $image = ""; if (!empty($row[15])) { $image = $row[15]; } if ($form_type->id == 11) { $index1 = array(); $index2 = array(); preg_match_all('/{(.*?)}/', $row[12], $matches); foreach ($matches[1] as $key => $a) { $data = DB::table('temp_forms')->where('code', $a)->first(); if (!empty($data)) { $other_form = FormRepository::insertForm($template, $a, $data->type, $data->required, $data->prompt, $data->choices, $data->expected_answer, $image, null, null, null); $index1[$a] = $other_form->id; $index2[$a] = $other_form->prompt . '_' . $other_form->id; } else { $other_form = DB::table('forms')->where('code', $a)->first(); // echo $a; if (empty($other_form)) { // dd($a); } // $other_form = FormRepository::insertForm($template,$a,$data->form_type_id,$data->required,$data->prompt,null,$data->expected_answer,null,$image); $index1[$a] = '!' . $other_form->id; $index2[$a] = $other_form->prompt . '_' . $other_form->id; } } $formula1 = $row[12]; $formula2 = $row[12]; foreach ($matches[1] as $key => $a) { $formula1 = str_replace('{' . $a . '}', $index1[$a], $formula1); $formula2 = str_replace('{' . $a . '}', ' :' . $index2[$a] . ': ', $formula2); } $form = FormRepository::insertForm($template, $row[7], $row[11], $row[10], $row[9], $formula1, null, $image, $formula2, null, null); } elseif ($form_type->id == 12) { $options = explode("~", $row[12]); preg_match_all('/(.*?){(.*?)}/', $row[12], $matches); $data_con = array(); $options = explode("~", $row[12]); foreach ($options as $option) { $with_value = preg_match('/{(.*?)}/', $option, $match); $x1 = array(); $x2 = array(); $_opt1 = ""; $_opt2 = ""; if ($with_value) { $codes = explode('^', $match[1]); if (count($codes) > 0) { foreach ($codes as $code) { if ($code != '') { $other_data = DB::table('temp_forms')->where('code', $code)->first(); if (empty($other_data)) { $other_data = DB::table('forms')->where('code', $code)->first(); } $other_form = FormRepository::insertForm($template, $code, $other_data->type, $other_data->required, $other_data->prompt, $other_data->choices, $other_data->expected_answer, null, null, null, null); $x1[] = $other_form->id; $x2[] = $other_form->prompt . '_' . $other_form->id; } } } if (count($x1) > 0) { $_opt1 = implode("^", $x1); } if (count($x2) > 0) { $_opt2 = implode("^", $x2); } } $data_con[] = ['option' => strtoupper(strtok($option, '{')), 'condition' => $_opt1, 'condition_desc' => $_opt2]; } // dd($data_con); $form = FormRepository::insertForm($template, $row[7], $row[11], $row[10], $row[9], $row[12], $row[14], $image, array(), $data_con, $row[16]); } else { $form = FormRepository::insertForm($template, $row[7], $row[11], $row[10], $row[9], $row[12], $row[14], $image, null, null, $row[16]); } $cat_order = 1; $a_cat_id = 0; $clast_cnt = AuditTemplateCategory::getLastOrder($template->id); if (empty($clast_cnt)) { $a_cat = AuditTemplateCategory::create(['category_order' => $cat_order, 'audit_template_id' => $template->id, 'category_id' => $category->id]); $a_cat_id = $a_cat->id; } else { $cat = AuditTemplateCategory::categoryExist($template->id, $category->id); if (empty($cat)) { $cat_order = $clast_cnt->category_order + 1; $a_cat = AuditTemplateCategory::create(['category_order' => $cat_order, 'audit_template_id' => $template->id, 'category_id' => $category->id]); $a_cat_id = $a_cat->id; } else { $a_cat_id = $cat->id; } } $grp_order = 1; $a_grp_id = 0; $glast_cnt = AuditTemplateGroup::getLastOrder($a_cat_id); if (empty($glast_cnt)) { $a_grp = AuditTemplateGroup::create(['group_order' => $grp_order, 'audit_template_category_id' => $a_cat_id, 'form_group_id' => $group->id]); $a_grp_id = $a_grp->id; } else { $grp = AuditTemplateGroup::categoryExist($a_cat_id, $group->id); if (empty($grp)) { $grp_order = $glast_cnt->group_order + 1; $a_grp = AuditTemplateGroup::create(['group_order' => $grp_order, 'audit_template_category_id' => $a_cat_id, 'form_group_id' => $group->id]); $a_grp_id = $a_grp->id; } else { $a_grp_id = $grp->id; } } $order = 1; $a_frm_id = 0; $last_cnt = AuditTemplateForm::getLastOrder($a_grp_id); if (!empty($last_cnt)) { $order = $last_cnt->order + 1; } AuditTemplateForm::create(array('audit_template_group_id' => $a_grp_id, 'order' => $order, 'audit_template_id' => $template->id, 'form_id' => $form->id)); } } $cnt++; } } // }elseif($sheet->getName() == 'Others') { // // $cnt = 0; // // foreach ($sheet->getRowIterator() as $row) { // // if($cnt > 0){ // // if(!is_null($row[2])){ // // $prompt = addslashes($row[1]); // // DB::statement('INSERT INTO temp_forms (code, prompt, required, type, choices) VALUES ("'.$row[0].'","'.$prompt.'","'.$row[2].'","'.$row[3].'","'.$row[4].'");'); // // } // // } // // $cnt++; // // } // }else{ // } } $reader->close(); } $users = User::all(); foreach ($users as $user) { $mapping = UserMapping::where('user_name', $user->name)->where('start_date', $start_date)->where('end_date', $end_date)->first(); if (!empty($mapping)) { $mapping->mapped_stores = $user->stores->count(); $mapping->update(); } else { UserMapping::create(['user_name' => $user->name, 'start_date' => $start_date, 'end_date' => $end_date, 'mapped_stores' => $user->stores->count()]); } } DB::statement('SET FOREIGN_KEY_CHECKS=1;'); Model::reguard(); }
public function getLangs($path) { return array_map('basename', \File::directories($path)); }
/** * Return all directories/folders from a given path * @param string $path Path to folder/directory * @return array|null */ function zbase_directories($path) { if (zbase_directory_check($path)) { return \File::directories($path); } return null; }
| load your controllers and models. This is useful for keeping all of | your classes in the "global" namespace without Composer updating. | */ ClassLoader::addDirectories(array(app_path() . '/commands', app_path() . '/controllers', app_path() . '/models', app_path() . '/database/seeds', app_path() . '/plugins')); /* |-------------------------------------------------------------------------- | Plugin registering |-------------------------------------------------------------------------- | | We want to add class support to any more complex classes with a subfolder | structure, so we'll load in the directory /plugins as well as scanning | the direct folder. | */ ClassLoader::addDirectories(File::directories(app_path() . '/plugins')); /* |-------------------------------------------------------------------------- | Theme functions |-------------------------------------------------------------------------- | | Built on top of Laravel is our custom theme functions, we need to make | sure they're all loaded so there's no errors | */ $functions = array('metadata', 'theme', 'page'); foreach ($functions as $function) { require app_path() . '/functions/' . $function . '.php'; } View::addNamespace('theme', 'public/themes/' . Metadata::item('theme', 'default')); View::addLocation(get_theme_path('layouts'));
/** * @return array|null */ protected function getLocales() { if ($this->locales === null) { $locales = \File::directories($this->lang_path); $this->locales = array_map([$this, 'cleanLocaleDir'], $locales); } $locales = $this->locales; return $locales; }
private function getAllLanguageFolders() { return \File::directories($this->getLanguageFolder()); }
/** * Settings page. * * @return View */ public function settings() { $dirs = array(); foreach (File::directories(base_path('themes')) as $dir) { $name = basename($dir); $dirs[$name] = ucfirst($name); } return View::make('Dashboard.Settings')->withOptions(App::make('options'))->withDirs($dirs); }
private function makeDirTreeJSON($currenttemplate, $format, $pretty = true) { $r = array(); $path = Config::get('config.templatedir') . $format . '/'; foreach (File::directories($path) as $dir) { unset($filename); $dirname = substr($dir, strlen($path)); if ($pretty) { $displaydir = ucfirst(str_replace('_', ' ', $dirname)); } else { $displaydir = $dirname; } $r[] = array('id' => "{$format}/{$dirname}", 'parent' => '#', 'text' => $displaydir); $donefilenames = array(); foreach (File::allFiles($dir) as $file) { $fullfilename = $file->getFileName(); if (substr($fullfilename, -5) == '.html') { $filename = substr($fullfilename, 0, -5); } if (substr($fullfilename, -4) == '.cml' or substr($fullfilename, -4) == '.css') { $filename = substr($fullfilename, 0, -4); } if (substr($fullfilename, -3) == '.js') { $filename = substr($fullfilename, 0, -3); } if (isset($filename) and !in_array($filename, $donefilenames)) { if (File::exists('templates/' . $format . '/' . $dirname . '/' . $filename . '.html')) { $exists = true; } else { $exists = false; } if ($pretty) { $displayname = ucfirst(str_replace('_', ' ', $filename)); } else { $displayname = $filename; } if ("{$format}/{$dirname}/{$filename}" == $currenttemplate) { $r[] = array('id' => $filename, 'exists' => $exists, 'parent' => "{$format}/{$dirname}", 'text' => $displayname, 'state' => array('selected' => 'true')); } else { $r[] = array('id' => $filename, 'exists' => $exists, 'parent' => "{$format}/{$dirname}", 'text' => $displayname); } $donefilenames[] = $filename; } } } // dd(json_encode($r)); return json_encode($r); }