%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /var/www/html/geotechnics/api/app/Models/
Upload File :
Create Path :
Current File : /var/www/html/geotechnics/api/app/Models/ProjectStatus.php

<?php

namespace App\Models;

use Carbon\Carbon;

/**
 * @property integer id
 * @property Project project
 * @property User user
 * @property string action
 * @property mixed when
 */
class ProjectStatus extends BaseModel
{
    const DRAFT = 'DRAFT'; //When clients create a project
    const CREATED = 'CREATED'; //When clients create a project
    const IN_REVIEW = 'IN_REVIEW'; //When clients submit for a quotation
    const CLIENT_REVIEW = 'CLIENT_REVIEW'; //When clients submit for a quotation
    const TODO = 'TODO'; //When Admin accepts the project quotation
    const REJECTED = 'REJECTED'; //When ADMIN rejects the project quotation
    const CANCELED = 'CANCELED'; //When ADMIN rejects the project quotation
    const DOING = 'DOING'; //When first project progress is inserted
    const DONE = 'DONE'; //When project is finished (ADMIN manually marks as done the project). Project might go over budget.
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'when',
        'action',
    ];

    protected $casts = [
        'project_id' => 'integer',
        'user_id'    => 'integer',
        'when'       => 'date',
        'action'     => 'string',
    ];

    protected $guarded = [
        'project_id',
        'user_id',
    ];

    protected $dates = [
        'when',
    ];

    public static function createStatus(Project $project, $user, $action)
    {
        if (!$user) {
            $user = User::query()
                        ->first();
        }
        /** @var ProjectStatus $status */
        $status = $project->statuses()
                          ->make([
                              'when'   => Carbon::now(),
                              'action' => $action,
                          ]);
        $status->user()
               ->associate($user);
        $status->save();
    }

    public function user()
    {
        return $this->belongsTo(User::class);
    }

    public static function getMessageByStatus($status)
    {
        $message = '';
        switch ($status) {
            case self::TODO :
                $message =  'We will be soon starting to work on this project!';
                break;
            case self::DOING :
                $message =  'We started working on this project.';
                break;
            case self::CLIENT_REVIEW :
                $message =  'We are waiting for your review for the progress on this project.';
                break;
            case self::DONE :
                $message =  'This project is finished!';
                break;
        }
        return $message;
    }

    public function project()
    {
        return $this->belongsTo(Project::class);
    }

}

Zerion Mini Shell 1.0