-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Исправления и улучшения Добавлено локальное хранилище для SmartApp. Исправлены опечатки и ошибки
- Loading branch information
ma.mochalov
committed
Mar 30, 2021
1 parent
9ecf6e7
commit b782e5b
Showing
31 changed files
with
353 additions
and
35 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
51 changes: 51 additions & 0 deletions
51
demo/skills/userDbConnect/controller/StandardController.php
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,51 @@ | ||
<?php | ||
/** | ||
* Стандартный пример приложения. | ||
* Отвечает на команды: | ||
* - Привет | ||
* - Пока | ||
* - Список | ||
* - Карточка | ||
* | ||
* Class StandardController | ||
*/ | ||
class StandardController extends MM\bot\controller\BotController | ||
{ | ||
public function action($intentName): void | ||
{ | ||
switch ($intentName) { | ||
case WELCOME_INTENT_NAME: | ||
$this->text = 'Привет'; | ||
$this->buttons->btns = ['Пример кнопки галереи']; | ||
$this->buttons->links = ['Пример ссылки для изображения']; | ||
break; | ||
|
||
case HELP_INTENT_NAME: | ||
$this->text = 'Помощь'; | ||
break; | ||
|
||
case 'bigImage': | ||
$this->text = ''; | ||
$this->tts = 'Большая картинка'; | ||
$this->card->add('565656/78878', 'Заголовок изображения', 'Описание изображения'); | ||
break; | ||
|
||
case 'list': | ||
$this->tts = 'Галерея из нескольких изображений'; | ||
$this->card->title = 'Галерея'; | ||
$this->card->add('565656/78878', 'Элемент с картинкой"', 'Описание изображения'); | ||
$this->card->add(null, 'Элемент без изображения', 'Описание изображения'); | ||
$this->card->button->addBtn('Текст в footer'); | ||
break; | ||
|
||
case 'by': | ||
$this->text = 'Пока пока!'; | ||
$this->isEnd = true; | ||
break; | ||
|
||
default: | ||
$this->text = 'Команда не найдена!'; | ||
break; | ||
} | ||
} | ||
} |
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,166 @@ | ||
<?php | ||
|
||
use MM\bot\api\request\Request; | ||
use \MM\bot\models\db\IModelRes; | ||
use MM\bot\models\db\QueryData; | ||
|
||
class DbConnect extends \MM\bot\models\db\DbControllerModel | ||
{ | ||
/** | ||
* Переменная, отвечающая за отправке curl запросов | ||
* @var Request | ||
*/ | ||
private $query; | ||
|
||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
/** | ||
* Будем отправлять запрос на какой-то сервис | ||
*/ | ||
$this->query = new Request(); | ||
$this->query->url = 'https://query.ru/query'; | ||
} | ||
|
||
/** | ||
* Приводим полученный результат из-запроса к требуемому виду. | ||
* В данном случае, ожидаем что полученные данные будут вида: | ||
* [ | ||
* 'key' => 'value' | ||
* ] | ||
* | ||
* @param IModelRes|null $res | ||
* @return mixed|null | ||
*/ | ||
public function getValue(?IModelRes $res) | ||
{ | ||
return $res->data; | ||
} | ||
|
||
/** | ||
* Отправляем запрос на получение данных | ||
* | ||
* @param array $select | ||
* @param bool $isOne | ||
* @return IModelRes | ||
*/ | ||
public function select(array $select, bool $isOne = false): IModelRes | ||
{ | ||
$this->query->post = [ | ||
'type' => 'select', | ||
'table' => $this->tableName, | ||
'select' => $select | ||
]; | ||
$res = $this->query->send(); | ||
if ($res['status']) { | ||
if ($isOne) { | ||
return (new IModelRes(true, $res['data'][0])); | ||
} else { | ||
return (new IModelRes(true, $res['data'])); | ||
} | ||
} | ||
return (new IModelRes(false, null, $res['err'])); | ||
} | ||
|
||
/** | ||
* Отправляем запрос на добавление данных | ||
* | ||
* @param QueryData $insertData | ||
* @return mixed|IModelRes | ||
*/ | ||
public function insert(QueryData $insertData) | ||
{ | ||
$this->query->post = [ | ||
'type' => 'insert', | ||
'table' => $this->tableName, | ||
'data' => $insertData | ||
]; | ||
$res = $this->query->send(); | ||
if ($res['status']) { | ||
return (new IModelRes(true, $res['data'])); | ||
} | ||
return (new IModelRes(false, null, $res['err'])); | ||
} | ||
|
||
/** | ||
* Выполняем запрос на обновление данных | ||
* | ||
* @param QueryData $updateData | ||
* @return mixed|IModelRes | ||
*/ | ||
public function update(QueryData $updateData) | ||
{ | ||
$this->query->post = [ | ||
'type' => 'update', | ||
'table' => $this->tableName, | ||
'data' => $updateData | ||
]; | ||
$res = $this->query->send(); | ||
if ($res['status']) { | ||
return (new IModelRes(true, $res['data'])); | ||
} | ||
return (new IModelRes(false, null, $res['err'])); | ||
} | ||
|
||
/** | ||
* Выполняем запрос на сохранение данных. | ||
* Тут сть в том, что если данных для обновления нет, то будет добавлена новая запись. | ||
* | ||
* @param QueryData $insertData | ||
* @param bool $isNew | ||
* @return mixed|IModelRes | ||
*/ | ||
public function save(QueryData $insertData, bool $isNew = false) | ||
{ | ||
$this->query->post = [ | ||
'type' => 'save', | ||
'table' => $this->tableName, | ||
'data' => $insertData | ||
]; | ||
$res = $this->query->send(); | ||
if ($res['status']) { | ||
return (new IModelRes(true, $res['data'])); | ||
} | ||
return (new IModelRes(false, null, $res['err'])); | ||
} | ||
|
||
/** | ||
* Выполняем запрос на удаление данных | ||
* | ||
* @param QueryData $deleteData | ||
* @return mixed|IModelRes | ||
*/ | ||
public function delete(QueryData $deleteData) | ||
{ | ||
$this->query->post = [ | ||
'type' => 'delete', | ||
'table' => $this->tableName, | ||
'data' => $deleteData | ||
]; | ||
$res = $this->query->send(); | ||
if ($res['status']) { | ||
return (new IModelRes(true, $res['data'])); | ||
} | ||
return (new IModelRes(false, null, $res['err'])); | ||
} | ||
|
||
/** | ||
* Выполняем произвольный запрос | ||
* | ||
* @param string $sql | ||
* @return mixed|IModelRes | ||
*/ | ||
public function query(string $sql) | ||
{ | ||
$this->query->post = [ | ||
'type' => 'query', | ||
'table' => $this->tableName, | ||
'query' => $sql | ||
]; | ||
$res = $this->query->send(); | ||
if ($res['status']) { | ||
return (new IModelRes(true, $res['data'])); | ||
} | ||
return (new IModelRes(false, null, $res['err'])); | ||
} | ||
} |
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,14 @@ | ||
<?php | ||
require_once __DIR__ . '/../../../src/MM/bot/init.php'; | ||
require_once __DIR__ . '/controller/StandardController.php'; | ||
require_once __DIR__ . '/dbConnect/DbConnect.php'; | ||
|
||
$bot = new MM\bot\core\Bot(); | ||
$bot->initTypeInGet(); | ||
$bot->initConfig(include __DIR__ . '/../../config/skillDefaultConfig.php'); | ||
$bot->initParams(include __DIR__ . '/../../config/skillDefaultParam.php'); | ||
$logic = new StandardController(); | ||
\MM\bot\core\mmApp::$userDbController = new DbConnect(); | ||
$bot->initBotController($logic); | ||
//echo $bot->run(); | ||
$bot->test(); |
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
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.