143 lines
6.6 KiB
PHP
143 lines
6.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
use Illuminate\Http\Request;
|
|
use App\Http\Requests\LambdaRequest;
|
|
use DB;
|
|
|
|
class CompetitionController extends Controller
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->middleware('auth');
|
|
$this->_service = 'competition';
|
|
$this->_module = 'contest';
|
|
$this->_viewname = 'competition';
|
|
$this->_title = 'Competition';
|
|
$this->_base_url = '/competition';
|
|
}
|
|
|
|
public function list(Request $request) {
|
|
$response = LambdaRequest::signedrequest('get', $this->_service, $this->_module.'/get_all');
|
|
|
|
foreach($response->data->items as &$item) {
|
|
$item->validity_start = date("m/d/Y", strtotime($item->validity_start));
|
|
$item->validity_end = date("m/d/Y", strtotime($item->validity_end));
|
|
}
|
|
$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_fields(){
|
|
return [
|
|
'actions' => ['title' => 'Actions', 'buttons' => [ 'edit', 'delete', 'score' => ['icon' => 'scoreboard', 'querystring' => 'id={ID}'] ] ],
|
|
'title' => ['title' => 'Title', 'type' => 'text'],
|
|
'validity_start' => ['title' => 'Validity start', 'type' => 'text'],
|
|
'validity_end' => ['title' => 'Validity end', 'type' => 'text'],
|
|
'status' => ['title' => 'Status', 'type' => 'select'],
|
|
|
|
];
|
|
}
|
|
|
|
protected function get_list_buttons() {
|
|
return [ ['title' => 'Add New', 'link' => $this->_base_url.'/addnew' ] ];
|
|
}
|
|
|
|
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;
|
|
}
|
|
// $domain = LambdaRequest::signedrequest('get', 'ums', 'domain/get_one');
|
|
// //echo '<pre>'; print_r($domain); exit;
|
|
// $designations_dd = [];
|
|
// foreach($domain->data->item->designations as $designation){
|
|
// $designations_dd[$designation] = $designation;
|
|
// }
|
|
//echo '<pre>'; print_r($values); exit;
|
|
|
|
$users = $this->getlambda('get', 'ums', 'users', 'dropdown');
|
|
//echo '<pre>'; print_r($users); exit;
|
|
$users_dd = [];
|
|
foreach($users->data->items as $user){
|
|
$users_dd[$user->id] = $user->firstname .' '. $user->lastname . ' ('.$user->employee_code.')';
|
|
}
|
|
|
|
$teams = $this->getlambda('get', 'ums', 'team', 'dropdown');
|
|
//echo '<pre>'; print_r($teams); exit;
|
|
$teams_dd = [];
|
|
foreach($teams->data->items as $team){
|
|
$teams_dd[$team->id] = $team->name;
|
|
}
|
|
|
|
$roles = $this->getlambda('get', 'ums', 'roles', 'dropdown');
|
|
$roles_dd = [];
|
|
foreach($roles->data->items as $role){
|
|
$roles_dd[$role->id] = $role->name;
|
|
}
|
|
|
|
$fields = [
|
|
'title' => ['title' => 'Title', 'type' => 'text', 'required' => true],
|
|
'status' => ['title' => 'Status', 'type' => 'select', 'required' => true, 'values' => ['active' => 'Active', 'disabled' => 'Disabled'] ],
|
|
'display_status' => ['title' => 'Compatition Status', 'type' => 'select', 'required' => true, 'values' => ['-' => '-', 'Ongoing' => 'Ongoing', 'Completed' => 'Completed' ] ],
|
|
'result_text' => ['title' => 'Result Text', 'type' => 'text', 'required' => true],
|
|
'description' => ['title' => 'Description', 'type' => 'textarea', 'required' => true, 'fullwidth' => true ],
|
|
'validity_start' => ['title' => 'Validity start', 'type' => 'date', 'required' => true],
|
|
'validity_end' => ['title' => 'Validity end', 'type' => 'date', 'required' => true],
|
|
'ranking_method' => ['title' => 'Ranking Method', 'type' => 'select', 'required' => true, 'values' => ['Total' => 'Total', 'Average' => 'Average'] ],
|
|
'points_unit' => ['title' => 'Points Units', 'type' => 'text', 'required' => true, ],
|
|
'response_roles' => ['title' => 'Accept Response from Roles', 'type' => 'multiselect', 'values' => $roles_dd, 'required' => true],
|
|
|
|
'cover_image' => ['title' => 'Cover Image', 'type' => 'image', 'required' => true],
|
|
'target_metrics' => ['title' => 'Choose Metric', 'type' => 'multiselect', 'required' => true, 'values' => $metrics_dd, 'fullwidth' => true ],
|
|
'observers' => ['title' => 'Observers', 'type' => 'multiselect', 'values' => $users_dd, 'required' => true, 'fullwidth' => true],
|
|
'participants' => ['title' => 'Participants', 'type' => 'mapping', 'teams' => $teams_dd, 'types' => ['Team', 'Position','User'] , 'required' => true, 'fullwidth' => true],
|
|
|
|
];
|
|
//echo '<pre>'; print_r($fields); exit;
|
|
return $fields;
|
|
}
|
|
|
|
protected function _beforesave($type, $request) {
|
|
$data = $request->except('_token');
|
|
$data['target_metrics'] = implode('#', $data['target_metrics']);
|
|
$data['observers'] = implode('#', $data['observers']);
|
|
$participants = [];
|
|
foreach($data['participants']['type'] as $i => $type) {
|
|
$participants[] = ['type' => $type, 'target' => $type=='Team' ? $data['participants']['team'][$i] : $data['participants']['person'][$i] ];
|
|
}
|
|
$data['participants'] = $participants;
|
|
if( $request->file('cover_image') ) {
|
|
$data['cover_image'] = $this->_uploadMedia($request, 'cover_image', 'competition');
|
|
}
|
|
return $data;
|
|
}
|
|
|
|
protected function _beforeform($type, $values) {
|
|
if ($type == 'edit') {
|
|
$values->target_metrics = explode('#', $values->target_metrics);
|
|
$values->observers = explode('#', $values->observers);
|
|
|
|
//echo '<pre>'; print_r($values->participants); exit;
|
|
$values->validity_start = date("m/d/Y", strtotime($values->validity_start));
|
|
$values->validity_end = date('m/d/Y', strtotime($values->validity_end));
|
|
}
|
|
return $values;
|
|
}
|
|
|
|
public function score(Request $request) {
|
|
$id = $request->input('id', 0);
|
|
$response = LambdaRequest::signedrequest('get', $this->_service, $this->_module.'/score', ['id' => $id]);
|
|
//echo '<pre>'; print_r($response->data->item); exit;
|
|
return view('competition.result')->with(['competition' => $response->data->item]);
|
|
|
|
}
|
|
}
|