slavkluev /
yii2-job-progress
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace slavkluev\JobProgress\models; |
||
| 6 | |||
| 7 | use yii\db\ActiveRecord; |
||
| 8 | |||
| 9 | class JobProgress extends ActiveRecord |
||
| 10 | { |
||
| 11 | 9 | public static function tableName() |
|
| 12 | { |
||
| 13 | 9 | return '{{%job_progress}}'; |
|
| 14 | } |
||
| 15 | |||
| 16 | 9 | public function rules() |
|
| 17 | { |
||
| 18 | return [ |
||
| 19 | 9 | [['progress_max', 'progress_now'], 'required'], |
|
| 20 | [['progress_max', 'progress_now'], 'integer'], |
||
| 21 | ]; |
||
| 22 | } |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @return int |
||
| 26 | */ |
||
| 27 | 6 | public function getProgressMax(): int |
|
| 28 | { |
||
| 29 | 6 | return $this->progress_max; |
|
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 30 | } |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @return int |
||
| 34 | */ |
||
| 35 | 6 | public function getProgressNow(): int |
|
| 36 | { |
||
| 37 | 6 | return $this->progress_now; |
|
|
0 ignored issues
–
show
The property
progress_now does not exist on slavkluev\JobProgress\models\JobProgress. Since you implemented __get, consider adding a @property annotation.
Loading history...
|
|||
| 38 | } |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @return float |
||
| 42 | */ |
||
| 43 | 6 | public function getPercent(): float |
|
| 44 | { |
||
| 45 | 6 | return $this->getProgressMax() !== 0 ? ($this->getProgressNow() / $this->getProgressMax()) * 100 : 0; |
|
| 46 | } |
||
| 47 | |||
| 48 | 9 | public static function findByJobId($jobId): ?JobProgress |
|
| 49 | { |
||
| 50 | 9 | return static::findOne(['job_id' => $jobId]); |
|
| 51 | } |
||
| 52 | } |
||
| 53 |