/** * Show the application welcome screen to the user. * * @return Response */ public function index() { $preguntas = json_decode(file_get_contents(url("/") . '/preguntas/laravel-feed.php'), true); $preguntas_filtradas = []; foreach ($preguntas as $k => $p) { $preguntas_filtradas[$k] = $p; if (isset($preguntas_filtradas[$k]["respuestas"])) { unset($preguntas_filtradas[$k]["respuestas"]); foreach ($p["respuestas"] as $r) { $u = Medico::where('user_id', '=', $r["userid"])->first(); if ($u) { $r["nombre"] = $u->nombre; $r["apellido"] = $u->apellido; $r["titulo"] = $u->titulo; $preguntas_filtradas[$k]["respuesta"] = $r; } } } } $cuentas = []; $cuentas["profesionales"] = Medico::count(); $cuentas["centros"] = Centro::count(); $cuentas["opiniones"] = Opinion::count(); return view('inicio', ["preguntas" => $preguntas_filtradas, "cuentas" => $cuentas]); }
public function opinar() { $data = Input::all(); unset($data["_token"]); $data["user_id"] = Auth::user()->id; Opinion::create($data); }
public function disagree() { $mecanex_user = Auth::user()->mecanex_user; $mecanex_user_id = $mecanex_user->id; $opinion = Opinion::firstOrNew(['mecanex_user_id' => $mecanex_user_id]); $opinion->opinion = 0; $iteration = $opinion->iteration + 1; $opinion->iteration = $iteration; $opinion->save(); return Redirect::route('home')->with('message', 'Thank you for your participation-dis'); }
function load($opinions, $specs, $log_content, $product_id) { $product = Product::where('ceneo_id', '=', $product_id)->first(); if ($product === null) { $product = new Product(); } //assign values to object $product->name = $specs['name']; $product->ceneo_id = $product_id; $product->producer = $specs['producer']; $product->category = $specs['category']; //this should be in transform + remove whitespace $product->description = strip_tags($specs['desc']); //$product->date = $op_date_date; //add to db?? $product->save(); //get product Model $product2 = App\Product::find(1)->where('ceneo_id', $product_id)->first(); for ($i = 1; $i < sizeof($opinions); $i++) { $auth = $opinions[$i]['author']; $dat = $opinions[$i]['date']; $opinion = Opinion::where('author', '=', $auth)->where('date', '=', $dat)->first(); if ($opinion === null) { $opinion = new Opinion(); } $opinion->author = $opinions[$i]['author']; $opinion->date = $opinions[$i]['date']; $opinion->score = $opinions[$i]['score']; $opinion->text = $opinions[$i]['text']; $opinion->summary = $opinions[$i]['summary']; $opinion->useful = $opinions[$i]['useful']; $opinion->useful_votes = ''; //$opinions[$i]['useful_votes']; //cast should be in transform if (is_array($opinions[$i]['pros'])) { $opinion->pros = implode(',', $opinions[$i]['pros']); $opinion->cons = implode(',', $opinions[$i]['cons']); } else { $opinion->pros = $opinions[$i]['pros']; $opinion->cons = $opinions[$i]['cons']; } $product2->opinions()->save($opinion); } $log_content = "Załadowano produkty do bazy" . PHP_EOL; $log_file = "log_file.txt"; $bytesWritten = File::append($log_file, $log_content); if ($bytesWritten === false) { die("Couldn't write to the file."); } }
<th>Podsumowanie</th> <th>Data</th> <th>Wady</th> <th>Zalety</th> <th>Ocena</th> <th>Treść</th> <th>Pomocna</th> <th>Ilu głosowało</th> </thead> <!-- Table Body --> <tbody> <?php $opinions = Opinion::where('product_id', '=', $product_id)->orderBy('created_at', 'asc')->get(); echo 'liczba opinii: ' . sizeof($opinions); ?> @foreach ($opinions as $opinion) <tr> <td class="table-text"> <div>{{ $opinion->author }}</div> </td> <td> <div>{{ $opinion->summary }}</div> </td>
public function getUpdateAll() { // Fetch all projects in Egypt $ch = curl_init(); $projectsUrl = "https://api.betterplace.org/en/api_v4/projects.json?around=Egypt&scope=location&per_page=100"; curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_URL, $projectsUrl); $projects = json_decode(curl_exec($ch), true); curl_close($ch); foreach ($projects['data'] as $project) { if ($project['country'] == 'Egypt') { $projectData = array('external_id' => $project['id'], 'city' => $project['city'], 'country' => $project['country'], 'title' => $project['title'], 'description' => $project['description'], 'tax_deductible' => $project['tax_deductible'], 'donations_prohibited' => $project['donations_prohibited'], 'completed_at' => $project['completed_at'], 'open_amount_in_cents' => $project['open_amount_in_cents'], 'positive_opinions_count' => $project['positive_opinions_count'], 'negative_opinions_count' => $project['negative_opinions_count'], 'donor_count' => $project['donor_count'], 'progress_percentage' => $project['progress_percentage'], 'incomplete_need_count' => $project['incomplete_need_count'], 'completed_need_count' => $project['completed_need_count']); // Insert new or update existing project $newProject = Project::firstOrNew(array('external_id' => $project['id'])); $newProject->fill($projectData); $newProject->save(); } } // Fetch all opinions for the given project $mh = curl_multi_init(); $curl_arr = array(); $projects = Project::all(); $totalProjects = $projects->count(); for ($i = 0; $i < $totalProjects; $i++) { $opinionsUrl = "https://api.betterplace.org/de/api_v4/projects/" . $projects[$i]['external_id'] . "/opinions.json?per_page=" . $projects[$i]['donor_count']; // Executing requests in parallel $curl_arr[$i] = curl_init($opinionsUrl); curl_setopt($curl_arr[$i], CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl_arr[$i], CURLOPT_RETURNTRANSFER, true); curl_multi_add_handle($mh, $curl_arr[$i]); } do { curl_multi_exec($mh, $running); } while ($running > 0); for ($i = 0; $i < $totalProjects; $i++) { $opinions = json_decode(curl_multi_getcontent($curl_arr[$i]), true); foreach ($opinions['data'] as $opinion) { // Excluding opinions witothout a donation if (isset($opinion['donated_amount_in_cents'])) { $opinionData = array('external_id' => $opinion['id'], 'project_id' => $project['id'], 'donated_amount_in_cents' => $opinion['donated_amount_in_cents'], 'score' => $opinion['score'], 'author' => $opinion['author']['name'], 'message' => $opinion['message'], 'donated_at' => $opinion['created_at']); // Insert new or update existing opinion $newOpinion = Opinion::firstOrNew(array('external_id' => $opinion['id'])); $newOpinion->fill($opinionData); $newOpinion->save(); } } } curl_multi_close($mh); return view('projects.update'); }