示例#1
0
 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.");
     }
 }
示例#2
0
                        <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>