public function __construct(array $attributes = []) { parent::__construct($attributes); $this->errors = new MessageBag(); $this->validator = \App::make('validator'); $this->manejaConcurrencia = true; }
/** * @param $text * @return $this */ public function answer($text) { if (\Config::get('gitter.output')) { $client = \App::make(Client::class); $room = \App::make(Room::class); $client->request('message.send', ['roomId' => $room->id], ['text' => (string) $text], 'POST'); } return $this; }
public function storeResultsAdmin($result_for_storing, $bodies, $sample_combined_result, $project, $words, $words_sample) { //names for two different files - for admin usage and simple for client usage $filename = 'results_admin'; $client_filename = 'results'; $storage_file = $project->storage_path() . $filename; if (file_exists($storage_file)) { unlink($storage_file); } //пустые массивы для организации исходных данных с плоской структурой пригодной для записи в таблицы $data_for_storing = []; //admin usage data with each entry at each handled url $client_for_storing = []; //simplified results for client usage foreach ($result_for_storing as $zone => $units_array) { foreach ($units_array as $unit => $data_array) { $data_for_storing[$unit][0] = $unit; $client_for_storing[$unit][0] = $unit; $data_for_storing[$unit]['body'] = $bodies[$unit]; $client_for_storing[$unit]['body'] = $bodies[$unit]; $data_for_storing[$unit][$zone] = $result_for_storing[$zone][$unit]['average']; $client_for_storing[$unit][$zone] = $result_for_storing[$zone][$unit]['average']; //add the each url entries - only for admin usage foreach ($result_for_storing[$zone][$unit]['entries'] as $key => $entry_value) { $data_for_storing[$unit][substr($zone, 0, 1) . "-" . $key] = $result_for_storing[$zone][$unit]['entries'][$key]; } } } foreach ($sample_combined_result as $zone => $units) { foreach ($units as $unit => $val) { $data_for_storing[$unit][$zone . "-diff"] = $data_for_storing[$unit][$zone] - $val; $data_for_storing[$unit][$zone . "-sample"] = $val; $client_for_storing[$unit][$zone . "-diff"] = $data_for_storing[$unit][$zone] - $val; $client_for_storing[$unit][$zone . "-sample"] = $val; } } //remove from client version the strings containing only zeros foreach ($client_for_storing as $unit => $zone_entries) { //$zone_entries[0] is a string and may begin with digital $remove_pos = true; foreach ($zone_entries as $zone_entry) { if ($zone_entry != $unit && $zone_entry != 0) { $remove_pos = false; break; } } if ($remove_pos) { unset($client_for_storing[$unit]); } } //prepare words row for storing $words_admin = ['words count', ""]; $words_client = ['words count', ""]; $counter = new Counter(); foreach ($words as $zone => $res_arr) { $zone_words_avg[$zone] = $counter->getAverage(array_values($res_arr)); $words_admin[] = $zone_words_avg[$zone]; $words_client[] = $zone_words_avg[$zone]; foreach ($res_arr as $word_count) { $words_admin[] = $word_count; } } foreach ($words_sample as $zone => $value) { $words_admin[] = $zone_words_avg[$zone] - $value; $words_admin[] = $value; $words_client[] = $zone_words_avg[$zone] - $value; $words_client[] = $value; } //prepare urls row for storing $refs_lines = file(storage_path("tmp/" . $project->dir . "/reports/Handled_referencies.txt"), FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); $query = array_shift($refs_lines); $refs = []; $refs[$query] = []; while (true) { $line = array_shift($refs_lines); if (is_null($line)) { break; } if (strpos($line, 'http') !== false) { $refs[$query][] = $line; } else { $query = $line; $refs[$query] = []; } } $refs_admin = ["", "", ""]; foreach ($refs as $query => $urls_arr) { $refs_per_query[$query] = count($urls_arr); $refs_admin = array_merge($refs_admin, $urls_arr); } $refs_admin_add = array_slice($refs_admin, 2); $refs_admin = array_merge($refs_admin, $refs_admin_add, $refs_admin_add, $refs_admin_add, $refs_admin_add); // get as_is info $asis_info = $this->get_asis_info($client_for_storing, $refs_per_query, $project); // apply as_is info to client_for_storing info if (isset($asis_info['dops']) && !empty($asis_info['dops'])) { $asis_info['push_to'] = isset($asis_info['push_to']) ? array_merge($asis_info['push_to'], $asis_info['dops']) : $asis_info['dops']; } if (isset($asis_info['push_to'])) { foreach ($asis_info['push_to'] as $query) { if (isset($client_for_storing[$query])) { $client_for_storing[$query]['plain'] += 1; $client_for_storing[$query]['plain-diff'] += 1; } else { // $client_for_storing = array_merge( [$query=>['0'=>$query, // 'body' => 0, // 'plain' => 1, // 'fragment' => 0, // 'a' => 0, // 'h1' => 0, // 'title' => 0, // 'plain-diff' => 1, // 'plain-sample' => 0, // 'fragment-diff' => 0, // 'fragment-sample' => 0, // 'a-diff' => 0, // 'a-sample' => 0, // 'h1-diff' => 0, // 'h1-sample' => 0, // 'title-diff' => 0, // 'title-sample' => 0 // ]], $client_for_storing); $client_for_storing = [$query => ['0' => $query, 'body' => 0, 'plain' => 1, 'fragment' => 0, 'a' => 0, 'h1' => 0, 'title' => 0, 'plain-diff' => 1, 'plain-sample' => 0, 'fragment-diff' => 0, 'fragment-sample' => 0, 'a-diff' => 0, 'a-sample' => 0, 'h1-diff' => 0, 'h1-sample' => 0, 'title-diff' => 0, 'title-sample' => 0]] + $client_for_storing; } } } foreach ($asis_info['units'] as $unit) { $client_for_storing[$unit[0]][$unit[1]] += -1; if ($unit[1] == 'plain') { $client_for_storing[$unit[0]]['plain-diff'] += -1; } } //delete from client-report units with only "0" values //which can appear after subtractions foreach ($client_for_storing as $unit => $unit_arr) { if (array_unique(array_values($unit_arr)) == array($unit, 0)) { unset($client_for_storing[$unit]); } } //store to admin file $excel = \App::make('excel'); $storagefile = Excel::create($filename, function ($excel) use($data_for_storing, $project, $words_admin, $refs_admin, $refs_per_query, $asis_info) { $excel->sheet("Admin", function ($sheet) use($data_for_storing, $project, $words_admin, $refs_admin, $refs_per_query, $asis_info) { $sheet->getStyle("C1:C999")->getAlignment()->setWrapText(true); $sheet->freezeFirstRowAndColumn(); $sheet->fromArray($data_for_storing, null, 'A1', false, true); $sheet->prependRow(array($project->dir)); $row_num = 1; $sheet->setHeight($row_num, 20); $row_num++; $sheet->setHeight($row_num, 20); foreach ($data_for_storing as $unit => $arr) { $row_num++; $sheet->setHeight($row_num, 20); } $sheet->appendRow($row_num + 1, $words_admin); $sheet->setHeight($row_num + 1, 20); $sheet->appendRow($row_num + 2, $refs_admin); $sheet->setHeight($row_num + 2, 200); $sheet->row($row_num + 2, function ($row) { $row->setTextRotation(90); }); //merge cells for queries and prepare array for inserting $curr_column_index = 3; $query_admin = ["", "", ""]; for ($i = 1; $i <= 5; $i++) { //the same operation for five zones foreach ($refs_per_query as $query => $merge_length) { $start_cell_column = $sheet->getCellByColumnAndRow($curr_column_index, $row_num + 3)->getColumn(); $end_cell_column = $sheet->getCellByColumnAndRow($curr_column_index + $merge_length - 1, $row_num + 3)->getColumn(); $sheet->mergeCells($start_cell_column . ($row_num + 3) . ":" . $end_cell_column . ($row_num + 3)); $query_admin[] = $query; if ($merge_length - 1 > 0) { // to avoid E_WARNING: array_fill(): Number of elements must be positive - restrictment for php < 5.6 $query_admin = array_merge($query_admin, array_fill(0, $merge_length - 1, "")); } else { $query_admin = array_merge($query_admin, []); } $curr_column_index += $merge_length; } $curr_column_index++; $query_admin[] = ""; } $sheet->appendRow($row_num + 3, $query_admin); $sheet->setHeight($row_num + 3, 20); if (!empty($asis_info['push_to'])) { $sheet->prependRow(1, ["In addition it is strongly recommended" . "\n" . "to add to plain text 'as is' form" . "\n" . "of following queries:" . "\n" . "\n" . implode("\n", $asis_info['push_to'])]); $sheet->cell('A1', function ($cell) { $cell->setFontColor('#ff0000'); }); $sheet->setHeight(1, 70); } }); })->store('xls', $project->storage_path() . "/reports/", true); //store to client file $storagefile = Excel::create($client_filename, function ($excel) use($client_for_storing, $project, $words_client, $refs_per_query, $asis_info) { $excel->sheet("Admin", function ($sheet) use($client_for_storing, $project, $words_client, $refs_per_query, $asis_info) { $sheet->getStyle("C1:C999")->getAlignment()->setWrapText(true); $sheet->freezeFirstRowAndColumn(); $sheet->fromArray($client_for_storing, null, 'A1', false, true); //set fonts to red color for 'dop'-queries //to set red color also for forcibly added native queries //toggle comments from 'dops' to 'push_to' in 'if' and 'foreach' if (isset($asis_info['dops'])) { // if( isset($asis_info['push_to']) ){ foreach ($asis_info['dops'] as $query) { // foreach ($asis_info['push_to'] as $query) { $new_row_num = array_search($query, array_keys($client_for_storing)) + 2; if ($new_row_num !== false) { //вдруг удалили строку где-то по дороге $sheet->cell('A' . $new_row_num, function ($cell) { $cell->setFontColor('#ff0000'); }); $sheet->cell('C' . $new_row_num, function ($cell) { $cell->setFontColor('#ff0000'); }); $sheet->cell('H' . $new_row_num, function ($cell) { $cell->setFontColor('#ff0000'); }); } } } $sheet->prependRow(array($project->dir)); //подсветка измененных данных по юнитам in client report //uncomment to enable // if( isset($asis_info['units']) ){ // $column_zone = [ // 'body'=>'B', // 'body-diff'=>'B', // 'plain'=>'C', // 'fragment'=>'D', // 'a'=>'E', // 'h1'=>'F', // 'title'=>'G', // 'plain-diff'=>'H', // 'fragment-diff'=>'J', // 'a-diff'=>'L', // 'h1-diff'=>'N', // 'title-diff'=>'P', // ]; // foreach($asis_info['units'] as $unit){ // $new_row_num = array_search( $unit[0], array_keys($client_for_storing) ) + 3; // // file_put_contents("/var/www/test.txt", "C".$new_row_num."\n", FILE_APPEND); // $sheet->cell($column_zone[$unit[1]].$new_row_num, function($cell) { // $cell->setBackground('#f4904c'); // }); // $sheet->cell($column_zone[$unit[1].'-diff'].$new_row_num, function($cell) { // $cell->setBackground('#f4904c'); // }); // } // } $row_num = 1; $sheet->setHeight($row_num, 20); $row_num++; $sheet->setHeight($row_num, 20); foreach ($client_for_storing as $unit => $arr) { $row_num++; $sheet->setHeight($row_num, 20); } $sheet->appendRow($row_num + 1, $words_client); $sheet->setHeight($row_num + 1, 20); $queries = implode("\n", array_keys($refs_per_query)); $sheet->prependRow(1, [$queries]); $sheet->setHeight(1, 70); }); })->store('xls', $project->storage_path() . "/reports/", true); }
/** * ShopifyService constructor. */ public function __construct() { $this->api = \App::make('ShopifyAPI'); $this->api->setup(['API_KEY' => config('app.shopify_api_key'), 'API_SECRET' => config('app.shopify_api_secret'), 'SHOP_DOMAIN' => config('app.shopify_shop_domain'), 'ACCESS_TOKEN' => config('app.shopify_access_token')]); $this->api->installURL(['permissions' => array('read_orders', 'read_products')]); }
/** * @param User $user * @param Message $message * @return static */ public function addKarmaTo(User $user, Message $message) { return Karma::create(['room_id' => \App::make(Room::class)->id, 'message_id' => $message->gitter_id, 'user_id' => $this->id, 'user_target_id' => $user->id, 'created_at' => $message->created_at]); }