118 lines
4.5 KiB
PHP
118 lines
4.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use App\Http\Requests\LambdaRequest;
|
|
use DB;
|
|
use \stdClass;
|
|
|
|
class CommchannelController extends Controller
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->middleware('auth');
|
|
$this->_service = 'communication';
|
|
$this->_module = 'channel';
|
|
$this->_viewname = 'commchannel';
|
|
$this->_title = 'Communication Channels';
|
|
$this->_base_url = '/communicationchannel';
|
|
}
|
|
|
|
protected function get_list_fields()
|
|
{
|
|
return [
|
|
'actions' => ['title' => 'Actions', 'buttons' => ['edit', 'delete']],
|
|
'name' => ['title' => 'Channel Name', 'type' => 'text'],
|
|
'type' => ['title' => 'Type', 'type' => 'text'],
|
|
'status' => ['title' => 'Status', 'type' => 'select'],
|
|
];
|
|
}
|
|
|
|
protected function get_form_fields($type, $values)
|
|
{
|
|
$bots = $this->getlambda('get', 'communication', 'comm_bot', 'dropdown');
|
|
$bots_dd = [];
|
|
foreach ($bots->data->items as $bot) {
|
|
$bots_dd[$bot->id] = $bot->name;
|
|
}
|
|
|
|
return [
|
|
'name' => ['title' => 'Channel Name', 'type' => 'text', 'required' => true],
|
|
'number' => ['title' => 'Sender Number', 'type' => 'text', 'required' => true],
|
|
'status' => ['title' => 'Status', 'type' => 'select', 'required' => true, 'values' => ['active' => 'Active', 'disabled' => 'Disabled']],
|
|
'type' => ['title' => 'Channel Type', 'type' => 'select', 'required' => true, 'values' => ['whatsapp' => 'Whatsapp', 'email' => 'Email', 'sms' => 'SMS']],
|
|
'bot_id' => ['title' => 'Attached Bot', 'type' => 'select', 'values' => $bots_dd],
|
|
|
|
'credentials' => ['title' => 'Credentials', 'type' => 'textarea', 'required' => true, 'fullwidth' => true],
|
|
//'api_secret' => ['title' => 'API Secret', 'type' => 'text', 'required' => true],
|
|
|
|
'minute' => ['title' => 'Limits in Minutes', 'type' => 'number', 'required' => false],
|
|
'hour' => ['title' => 'Limits in Hours', 'type' => 'number', 'required' => false],
|
|
'day' => ['title' => 'Limits in Days', 'type' => 'number', 'required' => false],
|
|
'week' => ['title' => 'Limits in Weeks', 'type' => 'number', 'required' => false],
|
|
'month' => ['title' => 'Limits in Months', 'type' => 'number', 'required' => false],
|
|
];
|
|
}
|
|
|
|
// public function form($type, $id = null)
|
|
// {
|
|
// $values = [];
|
|
// if ($type == 'edit') {
|
|
// $response = LambdaRequest::signedrequest('get', $this->_service, $this->_module . '/get_one', ['id' => $id]);
|
|
// // echo '<pre>'; print_r($response); exit;
|
|
// $values = $response->data->item;
|
|
// }
|
|
// $data = $this->_beforeform($type, $values);
|
|
// $fields = $this->get_form_fields($type, $values);
|
|
// echo '<pre>'; print_r($data); exit;
|
|
// return $this->view('form')->with([
|
|
// 'title' => $this->_title,
|
|
// 'mode' => $type,
|
|
// 'fields' => $fields,
|
|
// 'base_url' => $this->_base_url,
|
|
// 'item' => $values,
|
|
// ]);
|
|
// }
|
|
|
|
protected function _beforeform($type, $values) {
|
|
if($type == 'edit') {
|
|
$values->credentials = json_encode($values->credentials);
|
|
$values->minute = $values->limits->minute;
|
|
$values->day = $values->limits->day;
|
|
$values->month = $values->limits->month;
|
|
$values->hour = $values->limits->hour;
|
|
$values->week = $values->limits->week;
|
|
}
|
|
return $values;
|
|
}
|
|
|
|
protected function _beforesave($type, $request)
|
|
{
|
|
$data = $request->except('_token');
|
|
|
|
// $credentials = new stdClass();
|
|
// $credentials->api_key = $data["api_key"];
|
|
// $credentials->api_secret = $data["api_secret"];
|
|
// unset($data["api_key"]);
|
|
// unset($data["api_secret"]);
|
|
$data["credentials"] = json_decode($data["credentials"]);
|
|
|
|
$limits = new stdClass();
|
|
$limits->minute = $data["minute"];
|
|
$limits->hour = $data["hour"];
|
|
$limits->day = $data["day"];
|
|
$limits->week = $data["week"];
|
|
$limits->month = $data["month"];
|
|
unset($data["minute"]);
|
|
unset($data["hour"]);
|
|
unset($data["day"]);
|
|
unset($data["week"]);
|
|
unset($data["month"]);
|
|
$data["limits"] = $limits;
|
|
|
|
//echo '<pre>'; print_r($data); exit;
|
|
return $data;
|
|
}
|
|
}
|