-
Notifications
You must be signed in to change notification settings - Fork 138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add "reward maker" ext #1194
base: develop
Are you sure you want to change the base?
add "reward maker" ext #1194
Changes from all commits
c576b44
ca20b8a
5a2fd33
7bb59c5
49d9626
5c520da
2c7f7e2
8ca39e8
48ae819
e7fe487
099dacb
c86a922
52a4a91
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Models\ObjectReward; | ||
use App\Models\Prompt\PromptReward; | ||
use DB; | ||
use Illuminate\Console\Command; | ||
|
||
class UpdateRewardMaker extends Command { | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'update-reward-maker'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Update reward maker for develop'; | ||
|
||
/** | ||
* Execute the console command. | ||
*/ | ||
public function handle() { | ||
dd(DB::table('prompt_rewards')); | ||
// while this will convert prompt rewards to the new system | ||
// the first half if for those who used the existing ext and have existing data | ||
|
||
$rewards = ObjectReward::all(); | ||
|
||
foreach ($rewards as $reward) { | ||
switch ($reward->object_type) { | ||
case 'Questline': | ||
$objmodel = 'App\Models\Questline\Questline'; | ||
break; | ||
case 'Prompt': | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You also dont need to do this at all and can instead use an object relation on the ObjectReward model |
||
$objmodel = 'App\Models\Prompt\Prompt'; | ||
break; | ||
} | ||
|
||
switch ($reward->recipient_type) { | ||
case 'User': | ||
$key = 'objectRewards'; | ||
break; | ||
case 'Character': | ||
$key = 'objectCharacterRewards'; | ||
break; | ||
} | ||
|
||
$reward->update([ | ||
'rewardable_type' => getAssetModelString(strtolower($reward->rewardable_type)), | ||
'object_type' => $objmodel, | ||
'reward_key' => $key, | ||
]); | ||
} | ||
|
||
foreach (PromptReward::all() as $promptreward) { | ||
$rewardmodel = getAssetModelString(strtolower($promptreward->rewardable_type)); | ||
|
||
$newreward = ObjectReward::create([ | ||
'object_id' => $promptreward->prompt_id, | ||
'object_type' => 'App\Models\Prompt\Prompt', | ||
'rewardable_type' => $rewardmodel, | ||
'rewardable_id' => $promptreward->rewardable_id, | ||
'quantity' => $promptreward->quantity, | ||
'recipient_type' => 'User', | ||
'reward_key' => 'objectRewards', | ||
]); | ||
|
||
if (!$newreward) { | ||
$this->error('Error. Skipping prompt reward for prompt: '.$promptreward->prompt->name); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Admin\Data; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Services\RewardManager; | ||
use Illuminate\Http\Request; | ||
|
||
class RewardController extends Controller { | ||
/* | ||
|-------------------------------------------------------------------------- | ||
| Admin / Reward Maker Controller | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Handles creation/editing of rewards | ||
| | ||
*/ | ||
|
||
/** | ||
* Edit reward. | ||
* | ||
* @param int|null $id | ||
* @param mixed $model | ||
* | ||
* @return \Illuminate\Http\RedirectResponse | ||
*/ | ||
public function editReward(Request $request, RewardManager $service, $model, $id) { | ||
$decodedmodel = urldecode(base64_decode($model)); | ||
// check model + id combo exists | ||
$object = $decodedmodel::find($id); | ||
if (!$object) { | ||
throw new \Exception('Invalid object.'); | ||
} | ||
|
||
$data = $request->only([ | ||
'rewardable_type', 'rewardable_id', 'reward_quantity', 'recipient_type', 'reward_key', | ||
]); | ||
|
||
if ($id && $service->editRewards($object, $data)) { | ||
flash('Rewards updated successfully.')->success(); | ||
} else { | ||
foreach ($service->errors()->getMessages()['error'] as $error) { | ||
flash($error)->error(); | ||
} | ||
} | ||
|
||
return redirect()->back(); | ||
} | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instead of having an object reward model why not just have the stored assets array? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
class ObjectReward extends Model { | ||
/** | ||
* The attributes that are mass assignable. | ||
* | ||
* @var array | ||
*/ | ||
protected $fillable = [ | ||
'object_id', 'object_type', 'rewardable_id', 'rewardable_type', 'quantity', 'recipient_type', 'reward_key', | ||
]; | ||
|
||
/** | ||
* The table associated with the model. | ||
* | ||
* @var string | ||
*/ | ||
protected $table = 'object_rewards'; | ||
|
||
/********************************************************************************************** | ||
RELATIONS | ||
**********************************************************************************************/ | ||
|
||
/** | ||
* Get the object. | ||
*/ | ||
public function object() { | ||
return $this->morphTo(__FUNCTION__, 'object_type', 'object_id'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. whats the purpose of the |
||
} | ||
|
||
/** | ||
* Get the reward attached to the prompt reward. | ||
*/ | ||
public function reward() { | ||
return $this->morphTo(__FUNCTION__, 'rewardable_type', 'rewardable_id'); | ||
} | ||
|
||
/** | ||
* Get the reward type so we don't have to do the no-no of model names in forms. | ||
*/ | ||
public function rewardType() { | ||
return class_basename($this->rewardable_type); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,8 +78,23 @@ public function category() { | |
/** | ||
* Get the rewards attached to this prompt. | ||
*/ | ||
public function rewards() { | ||
return $this->hasMany(PromptReward::class, 'prompt_id'); | ||
public function objectRewards() { | ||
return $this->hasMany('App\Models\ObjectReward', 'object_id')->where([ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ideally this would use the ::class |
||
['object_type', get_class($this)], | ||
['recipient_type', 'User'], | ||
['reward_key', 'objectRewards'], | ||
]); | ||
} | ||
|
||
/** | ||
* Get the rewards attached to this prompt. | ||
*/ | ||
public function objectCharacterRewards() { | ||
return $this->hasMany('App\Models\ObjectReward', 'object_id')->where([ | ||
['object_type', get_class($this)], | ||
['recipient_type', 'Character'], | ||
['reward_key', 'objectCharacterRewards'], | ||
]); | ||
} | ||
|
||
/********************************************************************************************** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
definitely don't include questlines in this in the final PR