Skip to content

Commit

Permalink
Move business logic out of components into extensions
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Poyigi <[email protected]>
  • Loading branch information
sampoyigi committed May 11, 2024
1 parent ec85505 commit 50cccb1
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/Models/Review.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Igniter\Local\Models;

use Igniter\Flame\Database\Model;
use Igniter\Flame\Exception\ApplicationException;
use Igniter\Local\Models\Concerns\Locationable;
use Igniter\System\Models\Concerns\Switchable;
use Illuminate\Database\Eloquent\ModelNotFoundException;
Expand Down Expand Up @@ -81,6 +82,35 @@ public static function findBy($saleType, $saleId)
return $saleTypeModel->find($saleId);
}

public static function leaveReview(Model $reviewable = null, array $data = [])
{
throw_unless($reviewable->isCompleted(), new ApplicationException(

Check failure on line 87 in src/Models/Review.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - Static Analysis

Call to an undefined method Igniter\Flame\Database\Model::isCompleted().

Check failure on line 87 in src/Models/Review.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - Static Analysis

Call to an undefined method Igniter\Flame\Database\Model::isCompleted().
lang('igniter.local::default.review.alert_review_status_history')
));

throw_if($reviewable->customer && self::checkReviewed($reviewable, $reviewable->customer), new ApplicationException(

Check failure on line 91 in src/Models/Review.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - Static Analysis

Access to an undefined property Igniter\Flame\Database\Model::$customer.

Check failure on line 91 in src/Models/Review.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - Static Analysis

Access to an undefined property Igniter\Flame\Database\Model::$customer.
lang('igniter.local::default.review.alert_review_duplicate')
));

$review = new static;

Check failure on line 95 in src/Models/Review.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - Static Analysis

Unsafe usage of new static().

Check failure on line 95 in src/Models/Review.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - Static Analysis

Unsafe usage of new static().
$review->location_id = $reviewable->location_id;

Check failure on line 96 in src/Models/Review.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - Static Analysis

Access to an undefined property Igniter\Flame\Database\Model::$location_id.

Check failure on line 96 in src/Models/Review.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - Static Analysis

Access to an undefined property Igniter\Local\Models\Review::$location_id.

Check failure on line 96 in src/Models/Review.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - Static Analysis

Access to an undefined property Igniter\Flame\Database\Model::$location_id.

Check failure on line 96 in src/Models/Review.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - Static Analysis

Access to an undefined property Igniter\Local\Models\Review::$location_id.
$review->customer_id = $reviewable->customer_id;

Check failure on line 97 in src/Models/Review.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - Static Analysis

Access to an undefined property Igniter\Flame\Database\Model::$customer_id.

Check failure on line 97 in src/Models/Review.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - Static Analysis

Access to an undefined property Igniter\Local\Models\Review::$customer_id.

Check failure on line 97 in src/Models/Review.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - Static Analysis

Access to an undefined property Igniter\Flame\Database\Model::$customer_id.

Check failure on line 97 in src/Models/Review.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - Static Analysis

Access to an undefined property Igniter\Local\Models\Review::$customer_id.
$review->author = $reviewable->customer_name;

Check failure on line 98 in src/Models/Review.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - Static Analysis

Access to an undefined property Igniter\Flame\Database\Model::$customer_name.

Check failure on line 98 in src/Models/Review.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - Static Analysis

Access to an undefined property Igniter\Local\Models\Review::$author.

Check failure on line 98 in src/Models/Review.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - Static Analysis

Access to an undefined property Igniter\Flame\Database\Model::$customer_name.

Check failure on line 98 in src/Models/Review.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - Static Analysis

Access to an undefined property Igniter\Local\Models\Review::$author.
$review->sale_id = $reviewable->getKey();
$review->sale_type = $reviewable->getMorphClass();
$review->quality = array_get($data, 'quality', 0);
$review->delivery = array_get($data, 'delivery', 0);
$review->service = array_get($data, 'service', 0);
$review->review_text = array_get($data, 'review_text', '');

if (!array_get($data, 'review_status') && ReviewSettings::autoApproveReviews())
$review->review_status = true;

$review->save();

return $review;
}

public function getRatingOptions()
{
return ReviewSettings::getHints();
Expand Down

0 comments on commit 50cccb1

Please sign in to comment.