forked from corowne/lorekeeper
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'extension/referral-rewards' of https://github.com/AW000…
…5/lorekeeper-extensions into extension/referral-rewards # Conflicts: # app/Helpers/AssetHelpers.php # app/Http/Controllers/Auth/RegisterController.php # app/Models/Notification.php # app/Models/User/User.php # app/Services/LinkService.php # app/Services/UserService.php # config/lorekeeper/admin_sidebar.php # resources/views/auth/register.blade.php
- Loading branch information
Showing
20 changed files
with
481 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Admin\Data; | ||
|
||
use Illuminate\Http\Request; | ||
|
||
use Auth; | ||
|
||
use App\Models\Item\Item; | ||
use App\Models\Currency\Currency; | ||
use App\Models\Loot\LootTable; | ||
use App\Models\Raffle\Raffle; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Models\Referral; | ||
use Illuminate\Support\Facades\DB; | ||
|
||
class ReferralController extends Controller { | ||
/* | ||
|-------------------------------------------------------------------------- | ||
| Admin / Referral Controller | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Handles creation/editing of referral conditions | ||
| | ||
*/ | ||
|
||
/** | ||
* Shows the prompt category index. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return \Illuminate\Contracts\Support\Renderable | ||
*/ | ||
public function getIndex(Request $request) { | ||
|
||
return view('admin.referrals.referrals', [ | ||
'referrals' => Referral::orderBy('referral_count')->get()->paginate(20) | ||
]); | ||
} | ||
|
||
/** | ||
* Shows the create referral page. | ||
* | ||
* @return \Illuminate\Contracts\Support\Renderable | ||
*/ | ||
public function getCreate() { | ||
return view('admin.referrals.create_edit', [ | ||
'referral' => new Referral, | ||
'items' => Item::orderBy('name')->pluck('name', 'id'), | ||
'currencies' => Currency::where('is_user_owned', 1)->orderBy('name')->pluck('name', 'id'), | ||
'tables' => LootTable::orderBy('name')->pluck('name', 'id'), | ||
'raffles' => Raffle::where('rolled_at', null)->where('is_active', 1)->orderBy('name')->pluck('name', 'id'), | ||
]); | ||
} | ||
|
||
/** | ||
* Shows the edit referral page. | ||
* | ||
* @param int $id | ||
* @return \Illuminate\Contracts\Support\Renderable | ||
*/ | ||
public function getEdit($id) { | ||
$referral = Referral::find($id); | ||
if (!$referral) abort(404); | ||
return view('admin.referrals.create_edit', [ | ||
'referral' => $referral, | ||
'items' => Item::orderBy('name')->pluck('name', 'id'), | ||
'currencies' => Currency::where('is_user_owned', 1)->orderBy('name')->pluck('name', 'id'), | ||
'tables' => LootTable::orderBy('name')->pluck('name', 'id'), | ||
'raffles' => Raffle::where('rolled_at', null)->where('is_active', 1)->orderBy('name')->pluck('name', 'id'), | ||
]); | ||
} | ||
|
||
/** | ||
* Creates or edits a referral. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @param App\Services\PromptService $service | ||
* @param int|null $id | ||
* @return \Illuminate\Http\RedirectResponse | ||
*/ | ||
public function postCreateEdit(Request $request, $id = null) { | ||
|
||
$data = $request->only([ | ||
'referral_count', 'days_active' | ||
]); | ||
$data['data'] = encodeForDataColumn($request->only(['rewardable_type', 'rewardable_id', 'quantity'])); | ||
$data['is_active'] = $request->get('is_active') !== null; | ||
$data['on_every'] = $request->get('on_every') !== null; | ||
|
||
DB::beginTransaction(); | ||
try { | ||
if ($id) $referral = Referral::find($id)->update($data); | ||
else $referral = Referral::create($data); | ||
DB::commit(); | ||
|
||
flash('Referral saved successfully.')->success(); | ||
return redirect()->to('admin/data/referrals/edit/' . ($id ?? $referral->id)); | ||
} catch (\Exception $e) { | ||
DB::rollback(); | ||
flash($e->getMessage())->error(); | ||
return redirect()->back(); | ||
} | ||
} | ||
|
||
/** | ||
* Gets the prompt deletion modal. | ||
* | ||
* @param int $id | ||
* @return \Illuminate\Contracts\Support\Renderable | ||
*/ | ||
public function getDelete($id) { | ||
$referral = Referral::find($id); | ||
return view('admin.referrals._delete', [ | ||
'referral' => $referral, | ||
]); | ||
} | ||
|
||
/** | ||
* Deletes a prompt. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @param App\Services\PromptService $service | ||
* @param int $id | ||
* @return \Illuminate\Http\RedirectResponse | ||
*/ | ||
public function postDelete(Request $request, $id) { | ||
try { | ||
Referral::find($id)->delete(); | ||
DB::commit(); | ||
flash('Prompt deleted successfully.')->success(); | ||
} catch (\Exception $e) { | ||
DB::rollback(); | ||
flash($e->getMessage())->error(); | ||
} | ||
return redirect()->to('admin/data/referrals'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Config; | ||
use App\Models\Model; | ||
|
||
use App\Traits\Commentable; | ||
|
||
class Referral extends Model { | ||
use Commentable; | ||
|
||
/** | ||
* The attributes that are mass assignable. | ||
* | ||
* @var array | ||
*/ | ||
protected $fillable = [ | ||
'referral_count', 'data', 'is_active', 'days_active', 'on_every' | ||
]; | ||
|
||
/** | ||
* The table associated with the model. | ||
* | ||
* @var string | ||
*/ | ||
protected $table = 'referrals'; | ||
|
||
public function getDataAttribute($data) { | ||
$rewards = []; | ||
if ($data) { | ||
$assets = parseAssetData(json_decode($data)); | ||
foreach ($assets as $type => $a) { | ||
$class = getAssetModelString($type, false); | ||
foreach ($a as $id => $asset) { | ||
$rewards[] = (object)[ | ||
'rewardable_type' => $class, | ||
'rewardable_id' => $id, | ||
'quantity' => $asset['quantity'] | ||
]; | ||
} | ||
} | ||
} | ||
return $rewards; | ||
} | ||
|
||
public function getParsedDataAttribute() { | ||
return json_decode($this->attributes['data']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.