89 lines
3.9 KiB
PHP
89 lines
3.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
use Illuminate\Http\Request;
|
|
use App\Http\Requests\LambdaRequest;
|
|
use DB;
|
|
|
|
class CampaignruleController extends Controller
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->middleware('auth');
|
|
$this->_service = 'competition';
|
|
$this->_module = 'campaignrule';
|
|
$this->_viewname = 'campaignrule';
|
|
$this->_title = 'Campaign Rule';
|
|
$this->_base_url = '/campaignrule';
|
|
}
|
|
|
|
public function list(Request $request) {
|
|
$campaign_id = $request->session()->get('campaign_id');
|
|
if($campaign_id === 0) {
|
|
return redirect('/campaigns')->withError('campaign not found!');
|
|
}
|
|
$response = LambdaRequest::signedrequest('get', $this->_service, $this->_module.'/get_all', ['campaign_id' => $campaign_id]);
|
|
//echo '<pre>'; print_r($response); exit;
|
|
$fields = $this->get_list_fields();
|
|
return $this->view('list')->with([
|
|
'title' => $this->_title,
|
|
'fields' => $fields,
|
|
'base_url' => $this->_base_url,
|
|
'items' => $response->data->items,
|
|
'buttons' => $this->get_list_buttons()
|
|
]);
|
|
}
|
|
|
|
protected function get_list_buttons() {
|
|
return [ ['title' => 'Add New', 'link' => $this->_base_url.'/addnew' ], ['title' => 'Back to Campaigns', 'link' => '/campaigns'] ];
|
|
}
|
|
|
|
protected function get_list_fields(){
|
|
return [
|
|
'actions' => ['title' => 'Actions', 'buttons' => [ 'edit', 'delete' ] ],
|
|
//'media_thumb' => ['title' => 'Media Thumb', 'type' => 'image'],
|
|
'metric_name' => ['title' => 'Metric Name', 'type' => 'text'],
|
|
'block_size' => ['title' => 'Block Size', 'type' => 'text'],
|
|
'points' => ['title' => 'Points', 'type' => 'text'],
|
|
'range_start' => ['title' => 'Range Start', 'type' => 'text'],
|
|
'range_end' => ['title' => 'Range End', 'type' => 'text'],
|
|
'scoring_type' => ['title' => 'Scoring Type', 'type' => 'text'],
|
|
'metric_interval' => ['title' => 'Metric Interval', 'type' => 'text'],
|
|
'status' => ['title' => 'Status', 'type' => 'select'],
|
|
|
|
];
|
|
}
|
|
|
|
protected function get_form_fields($type, $values){
|
|
$metrics = $this->getlambda('get', 'metric', 'metric', 'get_all');
|
|
$metrics_dd = [];
|
|
foreach($metrics->data->items as $metric){
|
|
$metrics_dd[$metric->id] = $metric->name;
|
|
}
|
|
$fields = [
|
|
'metric_id' => ['title' => 'Metric', 'type' => 'select', 'required' => true, 'values' => $metrics_dd ],
|
|
'status' => ['title' => 'Status', 'type' => 'select', 'required' => true, 'values' => ['active' => 'Active', 'disabled' => 'Disabled'] ],
|
|
'range_start' => ['title' => 'Range Start', 'type' => 'number', 'required' => true],
|
|
'range_end' => ['title' => 'Range End', 'type' => 'number', 'required' => true],
|
|
'metric_interval' => ['title' => 'Metric Interval', 'type' => 'select', 'required' => true, 'values' => ['OVERALL' => 'OVERALL', 'MONTHLY' => 'MONTHLY', 'WEEKLY' => 'WEEKLY'] ],
|
|
'scoring_type' => ['title' => 'Scoring Type', 'type' => 'select', 'required' => true, 'values' => ['LINEAR' => 'LINEAR', 'STAGGERED' => 'STAGGERED'] ],
|
|
'block_size' => ['title' => 'Block Size', 'type' => 'number', 'required' => true],
|
|
'points' => ['title' => 'Points', 'type' => 'text', 'required' => true],
|
|
];
|
|
return $fields;
|
|
}
|
|
|
|
protected function _beforesave($type, $request) {
|
|
$data = $request->except('_token');
|
|
$data['campaign_id'] = $request->session()->get('campaign_id');
|
|
$metrics = $this->getlambda('get', 'metric', 'metric', 'get_all');
|
|
$metrics_dd = [];
|
|
foreach($metrics->data->items as $metric){
|
|
$metrics_dd[$metric->id] = $metric->name;
|
|
}
|
|
$data['metric_name'] = $metrics_dd[ $data['metric_id'] ];
|
|
return $data;
|
|
}
|
|
|
|
}
|