171 lines
6.7 KiB
PHP
171 lines
6.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use App\Http\Requests\LambdaRequest;
|
|
|
|
class MetriccampaignController extends Controller
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->middleware('auth');
|
|
$this->_service = 'metric';
|
|
$this->_module = 'campaign_view';
|
|
$this->_viewname = 'metriccampaign';
|
|
$this->_title = 'Campaign management';
|
|
$this->_base_url = '/metriccampaign';
|
|
}
|
|
|
|
protected function get_list_fields()
|
|
{
|
|
return [
|
|
'actions' => ['title' => 'Actions', 'buttons' => ['edit', 'delete']],
|
|
'name' => ['title' => 'Name', 'type' => 'text'],
|
|
'teams_rank' => ['title' => 'Teams Rank', 'type' => 'text'],
|
|
'default_interval' => ['title' => 'Default Interval', 'type' => 'text'],
|
|
'status' => ['title' => 'Status', 'type' => 'select'],
|
|
];
|
|
}
|
|
|
|
protected function get_form_fields($type, $values)
|
|
{
|
|
$roles = $this->getlambda('get', 'ums', 'roles', 'dropdown');
|
|
$roles_dd = [];
|
|
foreach ($roles->data->items as $role) {
|
|
$roles_dd[$role->id] = $role->name;
|
|
}
|
|
|
|
$metrics = $this->getlambda('get', 'metric', 'metric', 'get_all');
|
|
$metrics_dd = [];
|
|
foreach ($metrics->data->items as $metric) {
|
|
$metrics_dd[$metric->id] = $metric->name;
|
|
}
|
|
|
|
$intervalValues = [
|
|
'yearlycy' => 'Calender Year',
|
|
'yearlyfy' => 'Financial Year',
|
|
'monthly' => 'Monthly',
|
|
'weekly' => 'Weekly',
|
|
'daily' => 'Daily',
|
|
];
|
|
|
|
$defaultIntervalValues = [
|
|
'month-0' => 'This Month',
|
|
'month-1' => 'Last Month',
|
|
'month-3' => 'Last 3 Months',
|
|
'month-6' => 'Last 6 Months',
|
|
'month-12' => 'Last 12 Months',
|
|
'day-0' => 'Today',
|
|
'day-1' => 'Yesterday',
|
|
'day-7' => 'Last 7 Days',
|
|
'day-30' => 'Last 30 Days',
|
|
'week-0' => 'This week',
|
|
'week-1' => 'Last week',
|
|
'week-2' => '-2 week',
|
|
'week-3' => '-3 week',
|
|
'week-4' => '-4 week',
|
|
'yearfy-0' => 'This Financial Year',
|
|
'yearfy-1' => 'Last Financial Year',
|
|
'yearcy-0' => 'This Calender Year',
|
|
'yearcy-1' => 'Last Calender Year',
|
|
];
|
|
|
|
$teamsRankValues = [
|
|
'l1manager' => 'L1 Manager',
|
|
'l2manager' => 'L2 Manager',
|
|
'l3manager' => 'L3 Manager',
|
|
'l4manager' => 'L4 Manager',
|
|
];
|
|
|
|
return [
|
|
'name' => ['title' => 'Name', 'type' => 'text', 'required' => true],
|
|
'validity_start' => ['title' => 'Validity Start', 'type' => 'date', 'required' => true],
|
|
'validity_end' => ['title' => 'Validity End', 'type' => 'date', 'required' => true],
|
|
'campaign_visible_roles' => ['title' => 'Campaign Visible Roles', 'type' => 'multiselect', 'values' => $roles_dd, 'required' => true],
|
|
'reporting_roles' => ['title' => 'Reporting Roles', 'type' => 'multiselect', 'values' => $roles_dd, 'required' => true],
|
|
'teams_rank' => ['title' => 'Teams Rank', 'type' => 'select', 'required' => true, 'values' => $teamsRankValues],
|
|
'intervals' => ['title' => 'Intervals', 'type' => 'multiselect', 'required' => true, 'values' => $intervalValues],
|
|
'default_interval' => ['title' => 'Default Interval', 'type' => 'select', 'required' => true, 'values' => $defaultIntervalValues],
|
|
'bg_image' => ['title' => 'Background image', 'type' => 'image', 'required' => false],
|
|
'icon' => ['title' => 'Icon', 'type' => 'image', 'required' => false],
|
|
'gradient_color_dark' => [
|
|
'title' => 'Gradient color (dark)',
|
|
'type' => 'text',
|
|
'required' => false,
|
|
'placeholder' => 'R-G-B-A e.g. 0-0-0-0.85',
|
|
],
|
|
'gradient_color_light' => [
|
|
'title' => 'Gradient color (light)',
|
|
'type' => 'text',
|
|
'required' => false,
|
|
'placeholder' => 'R-G-B-A e.g. 255-255-255-0.2',
|
|
],
|
|
'status' => ['title' => 'Status', 'type' => 'select', 'required' => true, 'values' => ['active' => 'Active', 'disabled' => 'Disabled']],
|
|
'metrics' => ['title' => 'Metrics', 'type' => 'mapping', 'required' => true, 'metrics' => $metrics_dd, 'fullwidth' => true],
|
|
];
|
|
}
|
|
|
|
protected function _beforeform($type, $values)
|
|
{
|
|
if ($type === 'edit' && is_object($values)) {
|
|
foreach (['campaign_visible_roles', 'reporting_roles', 'intervals'] as $k) {
|
|
if (!isset($values->{$k})) {
|
|
$values->{$k} = [];
|
|
continue;
|
|
}
|
|
if (is_string($values->{$k})) {
|
|
$values->{$k} = $values->{$k} === '' ? [] : explode('#', $values->{$k});
|
|
} elseif (!is_array($values->{$k})) {
|
|
$values->{$k} = (array) $values->{$k};
|
|
}
|
|
}
|
|
|
|
if (!isset($values->metrics) || $values->metrics === null) {
|
|
$values->metrics = [];
|
|
} elseif (!is_array($values->metrics)) {
|
|
$values->metrics = (array) $values->metrics;
|
|
}
|
|
}
|
|
return $values;
|
|
}
|
|
|
|
protected function _beforesave($type, $request)
|
|
{
|
|
$data = $request->except('_token');
|
|
|
|
$metricIds = $request->input('metric', []);
|
|
$displayUnits = $request->input('display_unit', []);
|
|
$sortOrders = $request->input('sort_order', []);
|
|
$weights = $request->input('weight', []);
|
|
|
|
$metrics = [];
|
|
if (is_array($metricIds)) {
|
|
foreach ($metricIds as $i => $metricId) {
|
|
if ($metricId === null || $metricId === '') {
|
|
continue;
|
|
}
|
|
$metrics[] = [
|
|
'metric' => $metricId,
|
|
'display' => $displayUnits[$i] ?? '',
|
|
'weight' => isset($weights[$i]) && $weights[$i] !== '' ? (int) $weights[$i] : 1,
|
|
'sort' => isset($sortOrders[$i]) && $sortOrders[$i] !== '' ? (int) $sortOrders[$i] : 0,
|
|
];
|
|
}
|
|
}
|
|
$data['metrics'] = $metrics;
|
|
|
|
if ($request->file('bg_image')) {
|
|
$data['bg_image'] = $this->_uploadMedia($request, 'bg_image', 'metric');
|
|
}
|
|
if ($request->file('icon')) {
|
|
$data['icon'] = $this->_uploadMedia($request, 'icon', 'metric');
|
|
}
|
|
|
|
unset($data['metric'], $data['display_unit'], $data['sort_order'], $data['weight'], $data['list_view']);
|
|
|
|
return $data;
|
|
}
|
|
}
|
|
|