From b174d44b2805585be98834351ebd8786abbd4293 Mon Sep 17 00:00:00 2001 From: Donaschmi Date: Tue, 30 Jul 2019 13:46:46 +0200 Subject: [PATCH] Add image url to achievements --- src/Achievement.php | 25 +++++++++++-------- ...0_00_000000_create_achievements_tables.php | 1 + 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/Achievement.php b/src/Achievement.php index cfa170e..9feb964 100644 --- a/src/Achievement.php +++ b/src/Achievement.php @@ -28,6 +28,11 @@ abstract class Achievement implements CanAchieve */ public $description = ""; + /* + * Image url for the achievement + */ + public $url = ""; + /** * The amount of points required to unlock this achievement. */ @@ -56,7 +61,8 @@ public function __construct() * Wrapper for AchievementDetail::all(); * Conveniently fetches all achievements stored in the database. */ - public static function all(){ + public static function all() + { return AchievementDetails::all(); } @@ -87,7 +93,7 @@ public function getPoints() */ public function getModel() { - if(!is_null($this->modelAttr)){ + if (!is_null($this->modelAttr)) { return $this->modelAttr; } @@ -98,9 +104,10 @@ public function getModel() $model->class_name = $this->getClassName(); } - if(config('achievements.auto_sync') || is_null($model->name)) { + if (config('achievements.auto_sync') || is_null($model->name)) { $model->name = $this->name; $model->description = $this->description; + $model->url = $this->url; $model->points = $this->points; $model->secret = $this->secret; @@ -155,9 +162,9 @@ public function getOrCreateProgressForAchiever($achiever) $achievementId = $this->getModel()->id; $progress = AchievementProgress::where('achiever_type', $className) - ->where('achievement_id', $achievementId) - ->where('achiever_id', $achiever->id) - ->first(); + ->where('achievement_id', $achievementId) + ->where('achiever_id', $achiever->id) + ->first(); if (is_null($progress)) { $progress = new AchievementProgress(); @@ -191,8 +198,7 @@ protected function getAchieverClassName($achiever) * @param $progress */ public function whenUnlocked($progress) - { - } + { } /** * Will be called when progress is made on the achievement. @@ -200,8 +206,7 @@ public function whenUnlocked($progress) * @param $progress */ public function whenProgress($progress) - { - } + { } /** * Triggers the AchievementUnlocked Event. diff --git a/src/Migrations/0000_00_00_000000_create_achievements_tables.php b/src/Migrations/0000_00_00_000000_create_achievements_tables.php index a2634cb..96e4774 100644 --- a/src/Migrations/0000_00_00_000000_create_achievements_tables.php +++ b/src/Migrations/0000_00_00_000000_create_achievements_tables.php @@ -28,6 +28,7 @@ public function up() $table->increments('id'); $table->string('name'); $table->string('description'); + $table->string('url'); $table->unsignedInteger('points')->default(1); $table->boolean('secret')->default(false); $table->string('class_name');