HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/tandartsmaas.komma.pro/app/Komma/Ratings/RatingService.php
<?php


namespace Komma\Ratings;

use Carbon\Carbon;

class RatingService
{
    /**
     * @var FacebookService
     */
    private $facebookService;

    /**
     * @param FacebookService $facebookService
     */
    public function __construct(FacebookService $facebookService)
    {
        $this->facebookService = $facebookService;
    }

    /*
     * Select all ratings
     * @return array
     */
    public function getRatings()
    {

        $ratingsGraphObject = $this->facebookService->getRatings();

        if($ratingsGraphObject == false ) return \Config::get('ratingsFallback');

        $amount = 0;

        $list = [];
        foreach($ratingsGraphObject as $rating)
        {
            if($amount >= 8) continue;

            if($rating->getField('rating') > 2)
            {
                $list[] = $this->getUpdatedRating($rating);
                $amount++;
            }
        }

        return $list;
    }

    /*
     * Select the latest rating that has a description
     * @return array
     */
    public function getLastWithText()
    {

        $ratingsGraphObject = $this->facebookService->getRatings();

        if($ratingsGraphObject == false ) return \Config::get('ratingsFallback')[0];



        foreach ($ratingsGraphObject as $rating)
        {

            if($rating->getField('rating') > 2 && ! empty($rating->getField('review_text')))
            {
                return $this->getUpdatedRating($rating);
            }
        }

        return false;
    }

    /**
     * @param $rating
     * @return mixed
     */
    private function getUpdatedRating($rating)
    {
        // Put values in new variable
        //$updatedRating = $rating;

        $updatedRating = (object)[];

        // Convert Time
        $updatedRating->created_time = $this->getCreatedTime($rating->getField('created_time'));

        $updatedRating->rating = $rating->getField('rating');
        $updatedRating->review_text = $rating->getField('review_text');

        // Get profile picture
        //$updatedRating->reviewer = $rating->getField('reviewer');
        $updatedRating->reviewer = (object)[];
        $updatedRating->reviewer->id = $rating->getField('reviewer')->getField('id');
        $updatedRating->reviewer->name = $rating->getField('reviewer')->getField('name');


        $profilePic = $this->facebookService->getProfilePicById($updatedRating->reviewer->id);
        $updatedRating->reviewer->profile_pic = $profilePic->getField('url');


        //$updatedRating->reviewer->profile_pic = '';

        return $updatedRating;
    }

    /*
     * Return Dutch time
     */
    private function getCreatedTime($time)
    {
        setlocale(LC_TIME, 'Dutch');

        $time = Carbon::instance($time);
       // $time = Carbon::parse($time);

        return $time->formatLocalized('%d %B %Y');
    }
}