6 changes: 3 additions & 3 deletions api/webservice/ManageConsents/BaseModule/SendEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/**
* Send e-mail.
*
* @package Api
* @package API
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Radosław Skrzypczak <r.skrzypczak@yetiforce.com>
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
*/
Expand Down
6 changes: 3 additions & 3 deletions api/webservice/ManageConsents/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
/**
* Save record.
*
* @package Api
* @package API
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Radosław Skrzypczak <r.skrzypczak@yetiforce.com>
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
/**
* The file contains: Class to handling payment information.
*
* @package Api
* @package API
*
* @copyright YetiForce Sp. z o.o.
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Arkadiusz Adach <a.adach@yetiforce.com>
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
*/
Expand Down
44 changes: 44 additions & 0 deletions api/webservice/SMS/Auth/Basic.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/**
* Basic authorization file.
*
* @package API
*
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Radosław Skrzypczak <r.skrzypczak@yetiforce.com>
*/

namespace Api\SMS\Auth;

/**
* Basic authorization class.
*/
class Basic extends \Api\Core\Auth\Basic
{
/** {@inheritdoc} */
public function authenticate(string $realm): bool
{
if (!$this->api->app) {
$this->api->response->addHeader('WWW-Authenticate', 'Basic realm="' . $realm . '"');
throw new \Api\Core\Exception('Web service - Applications: Unauthorized', 401);
}

return true;
}

/** {@inheritdoc} */
public function setServer(): self
{
$this->api->app = [];
$apiKey = $this->api->request->getByType('x-api-key', \App\Purifier::ALNUM);
$type = $this->api->request->getByType('_container', \App\Purifier::STANDARD);
$query = (new \App\Db\Query())->from('w_#__servers')->where(['type' => $type, 'status' => 1]);
if ($apiKey && $row = $query->andWhere(['api_key' => \App\Encryption::getInstance()->encrypt($apiKey)])->one()) {
$row['id'] = (int) $row['id'];
$this->api->app = $row;
}

return $this;
}
}
70 changes: 70 additions & 0 deletions api/webservice/SMS/BaseAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php
/**
* Api actions.
*
* @package API
*
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Radosław Skrzypczak <r.skrzypczak@yetiforce.com>
*/

namespace Api\SMS;

use OpenApi\Annotations as OA;

/**
* BaseAction class.
*
* @OA\Info(
* title="YetiForce API for SMS. Type: SMS",
* description="",
* version="0.1",
* termsOfService="https://yetiforce.com/",
* @OA\Contact(
* email="devs@yetiforce.com",
* name="Devs API Team",
* url="https://yetiforce.com/"
* ),
* @OA\License(
* name="YetiForce Public License",
* url="https://yetiforce.com/en/yetiforce/license"
* ),
* )
* @OA\Server(
* url="https://gitdeveloper.yetiforce.com",
* description="Demo server of the development version",
* )
* @OA\Server(
* url="https://gitstable.yetiforce.com",
* description="Demo server of the latest stable version",
* )
*/
class BaseAction extends \Api\Core\BaseAction
{
/** {@inheritdoc} */
protected function checkPermission(): void
{
$db = \App\Db::getInstance('webservice');
$userTable = 'w_#__sms_user';
$userData = (new \App\Db\Query())
->from($userTable)
->where([
'server_id' => $this->controller->app['id'],
'token' => $this->controller->request->getByType('x-token', \App\Purifier::ALNUM),
'status' => 1,
])
->limit(1)->one($db);
if (!$userData) {
throw new \Api\Core\Exception('Invalid data access', 401);
}
$this->setAllUserData($userData);
$db->createCommand()->update($userTable, ['login_time' => date('Y-m-d H:i:s')], ['id' => $userData['id']])->execute();
\App\User::setCurrentUserId($userData['user_id']);
}

/** {@inheritdoc} */
public function updateSession(array $data = []): void
{
}
}
112 changes: 112 additions & 0 deletions api/webservice/SMS/SMSAPI/Reception.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?php
/**
* The file contains: Reception operations.
*
* @package API
*
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Radosław Skrzypczak <r.skrzypczak@yetiforce.com>
*/

namespace Api\SMS\SMSAPI;

use OpenApi\Annotations as OA;

/**
* Reception class.
*/
class Reception extends \Api\SMS\BaseAction
{
/** {@inheritdoc} */
public $allowedMethod = ['POST'];

/** @var string Module name */
private $moduleName = 'SMSNotifier';

/** {@inheritdoc} */
protected function checkPermission(): void
{
parent::checkPermission();
if ($this->controller->request->isEmpty('MsgId', true)) {
throw new \Api\Core\Exception('No permission - wrong data', 401);
}
}

/** {@inheritdoc} */
protected function checkPermissionToModule(): void
{
if (!\Api\Core\Module::checkModuleAccess($this->moduleName) || !\App\Privilege::isPermitted($this->moduleName, 'CreateView') || !($provider = \App\Integrations\SMSProvider::getDefaultProvider()) || 'SMSAPI' !== $provider->getName()) {
throw new \Api\Core\Exception('No permissions for module', 403);
}
}

/**
* Add record.
*
* @return array
*
* @OA\Get(
* path="/webservice/SMS/SMSAPI/Reception",
* summary="Receipt of SMS",
* tags={"SMSAPI"},
* externalDocs={
* "description" : "SMSApi Documentation",
* "url" : "https://www.smsapi.pl/docs"
* },
* security={
* {"ApiKeyAuth" : {}, "token" : {}}
* },
* @OA\Response(
* response=200,
* description="Result",
* @OA\JsonContent(ref="#/components/schemas/SMS_SMSAPI_Post_Reception")
* ),
* @OA\Response(
* response=401,
* description="`No sent token` OR `Invalid token` OR `wrong data provided in the request`",
* ),
* @OA\Response(
* response=403,
* description="No permissions for module",
* ),
* @OA\Response(
* response=405,
* description="Method Not Allowed",
* ),
* ),
* @OA\Schema(
* schema="SMS_SMSAPI_Post_Reception",
* title="Response",
* description="Response",
* type="string",
* example="OK"
* ),
*/
public function post()
{
$msgId = $this->controller->request->getByType('MsgId', \App\Purifier::ALNUM);
$message = $this->controller->request->getByType('sms_text', \App\Purifier::HTML);
$smsFrom = $this->controller->request->getByType('sms_from', \App\Purifier::DIGITS);

$provider = \App\Integrations\SMSProvider::getProviderByName('SMSAPI');
$queryGenerator = (new \App\QueryGenerator($this->moduleName));
$recordId = $queryGenerator->setFields(['id'])->addCondition('msgid', $msgId, 'e')->createQuery()->scalar();

if ($recordId && \App\Record::isExists($recordId, $this->moduleName)
&& ($recordModel = \Vtiger_Record_Model::getInstanceById($recordId, $this->moduleName))
&& $smsFrom === $provider->setPhone($recordModel->get('phone'))->get('to')
) {
$newRecordModel = \Vtiger_Record_Model::getCleanInstance($this->moduleName);
$msgField = $newRecordModel->getField('message');
$newRecordModel->set($msgField->getName(), $msgField->getDBValue($message))
->set('parentid', $recordModel->getId())
->set('related_to', $recordModel->get('related_to'))
->set('smsnotifier_status', 'PLL_REPLY')
->set('phone', $recordModel->get('phone'));
$newRecordModel->save();
}

echo 'OK';
}
}
177 changes: 177 additions & 0 deletions api/webservice/SMS/SMSAPI/Report.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
<?php
/**
* The file contains: Report operations.
*
* @package API
*
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Radosław Skrzypczak <r.skrzypczak@yetiforce.com>
*/

namespace Api\SMS\SMSAPI;

use OpenApi\Annotations as OA;

/**
* Report class.
*/
class Report extends \Api\SMS\BaseAction
{
/** {@inheritdoc} */
public $allowedMethod = ['GET', 'POST'];

/** @var string Module name */
private $moduleName = 'SMSNotifier';

/**
* Get status for record by code.
*
* Statuses from api:
* 402 => 'EXPIRED',
* 403 => 'SENT',
* 404 => 'DELIVERED',
* 405 => 'UNDELIVERED',
* 406 => 'FAILED',
* 407 => 'REJECTED',
* 408 => 'UNKNOWN',
* 409 => 'QUEUE',
* 410 => 'ACCEPTED',
* 411 => 'RENEWAL',
* 412 => 'STOP'.
*/
private const STATUSES = [
402 => 'PLL_FAILED',
403 => 'PLL_SENT',
404 => 'PLL_DELIVERED',
405 => 'PLL_FAILED',
406 => 'PLL_FAILED',
407 => 'PLL_FAILED',
408 => 'PLL_SENT',
410 => 'PLL_DELIVERED',
];

/** {@inheritdoc} */
protected function checkPermission(): void
{
parent::checkPermission();
if (!$this->controller->request->getExploded('MsgId', ',', \App\Purifier::ALNUM) || !$this->controller->request->getExploded('status', ',', \App\Purifier::INTEGER) || !$this->controller->request->getExploded('to', ',', \App\Purifier::ALNUM)) {
throw new \Api\Core\Exception('No permission - wrong data', 401);
}
}

/** {@inheritdoc} */
protected function checkPermissionToModule(): void
{
if (!\Api\Core\Module::checkModuleAccess($this->moduleName) || !\App\Privilege::isPermitted($this->moduleName, 'EditView') || !($provider = \App\Integrations\SMSProvider::getDefaultProvider()) || 'SMSAPI' !== $provider->getName()) {
throw new \Api\Core\Exception('No permissions for module', 403);
}
}

/**
* Update record status.
*
* @return void
*
* @OA\Get(
* path="/webservice/SMS/SMSAPI/Report",
* summary="Report for sms",
* tags={"SMSAPI"},
* externalDocs={
* "description" : "SMSApi Documentation",
* "url" : "https://www.smsapi.pl/docs"
* },
* security={
* {"ApiKeyAuth" : {}, "token" : {}}
* },
* @OA\Response(
* response=200,
* description="Result",
* @OA\JsonContent(ref="#/components/schemas/SMS_SMSAPI_Get_Report")
* ),
* @OA\Response(
* response=401,
* description="`No sent token` OR `Invalid token` OR `wrong data provided in the request`",
* ),
* @OA\Response(
* response=403,
* description="No permissions for module",
* ),
* @OA\Response(
* response=405,
* description="Method Not Allowed",
* ),
* ),
* @OA\Schema(
* schema="SMS_SMSAPI_Get_Report",
* title="Response",
* description="Response",
* type="string",
* example="OK"
* ),
*/
public function get()
{
$recordIds = $this->controller->request->getExploded('idx', ',', \App\Purifier::INTEGER);
$msgIds = $this->controller->request->getExploded('MsgId', ',', \App\Purifier::ALNUM);
$statuses = $this->controller->request->getExploded('status', ',', \App\Purifier::INTEGER);
foreach ($recordIds as $key => $recordId) {
if (\App\Record::isExists($recordId, $this->moduleName)
&& ($recordModel = \Vtiger_Record_Model::getInstanceById($recordId, $this->moduleName))->isEditable()
&& !$recordModel->isEmpty('msgid') && \in_array($recordModel->get('msgid'), $msgIds)
&& $recordModel->set('smsnotifier_status', static::STATUSES[$statuses[$key]] ?? 'PLL_UNDEFINED')->getPreviousValue()
) {
$recordModel->save();
}
}

echo 'OK';
}

/**
* Update record status.
*
* @return void
*
* @OA\Post(
* path="/webservice/SMS/SMSAPI/Report",
* summary="Report for sms",
* tags={"SMSAPI"},
* externalDocs={
* "description" : "SMSApi Documentation",
* "url" : "https://www.smsapi.pl/docs"
* },
* security={
* {"ApiKeyAuth" : {}, "token" : {}}
* },
* @OA\Response(
* response=200,
* description="Result",
* @OA\JsonContent(ref="#/components/schemas/SMS_SMSAPI_Post_Report")
* ),
* @OA\Response(
* response=401,
* description="`No sent token` OR `Invalid token` OR `wrong data provided in the request`",
* ),
* @OA\Response(
* response=403,
* description="No permissions for module",
* ),
* @OA\Response(
* response=405,
* description="Method Not Allowed",
* ),
* ),
* @OA\Schema(
* schema="SMS_SMSAPI_Post_Report",
* title="Response",
* description="Response",
* type="string",
* example="OK"
* ),
*/
public function post()
{
$this->get();
}
}
4 changes: 2 additions & 2 deletions api/webservice/WebservicePremium/BaseAction/Files.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* @package API
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
* @author Radosław Skrzypczak <r.skrzypczak@yetiforce.com>
*/
Expand Down
4 changes: 2 additions & 2 deletions api/webservice/WebservicePremium/BaseAction/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* @package API
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Tomasz Kur <t.kur@yetiforce.com>
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
*/
Expand Down
4 changes: 2 additions & 2 deletions api/webservice/WebservicePremium/BaseAction/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* @package API
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Tomasz Kur <t.kur@yetiforce.com>
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
*/
Expand Down
4 changes: 2 additions & 2 deletions api/webservice/WebservicePremium/BaseAction/Modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*
* @package API
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
*/

Expand Down
4 changes: 2 additions & 2 deletions api/webservice/WebservicePremium/BaseModule/CustomView.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* @package API
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Radosław Skrzypczak <r.skrzypczak@yetiforce.com>
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
*/
Expand Down
14 changes: 9 additions & 5 deletions api/webservice/WebservicePremium/BaseModule/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* @package API
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Tomasz Kur <t.kur@yetiforce.com>
* @author Radosław Skrzypczak <r.skrzypczak@yetiforce.com>
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
Expand Down Expand Up @@ -79,14 +79,18 @@ class Dashboard extends \Api\Core\BaseAction
public function get(): array
{
$moduleName = $this->controller->request->getModule();
$dashboardInstance = \Api\WebservicePremium\Dashboard::getInstance($moduleName, 0, $this->controller->app['id']);
$tabs = $dashboardInstance->getTabs();
if ($this->controller->request->isEmpty('record', true)) {
$dashBoardId = \Settings_WidgetsManagement_Module_Model::getDefaultDashboard();
$defaultDbId = \Settings_WidgetsManagement_Module_Model::getDefaultDashboard();
$dashBoardId = isset($tabs[$defaultDbId]) ? $defaultDbId : (int) array_key_first($tabs);
} else {
$dashBoardId = $this->controller->request->getInteger('record');
}
$dashboardInstance = \Api\WebservicePremium\Dashboard::getInstance($moduleName, $dashBoardId, $this->controller->app['id']);
$dashboardInstance->setDashboard($dashBoardId);

return [
'types' => $dashboardInstance->getTabs(),
'types' => $tabs,
'widgets' => $dashboardInstance->getData(),
];
}
Expand Down
4 changes: 2 additions & 2 deletions api/webservice/WebservicePremium/BaseModule/Fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*
* @package API
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
*/

Expand Down
6 changes: 3 additions & 3 deletions api/webservice/WebservicePremium/BaseModule/Hierarchy.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*
* @package API
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
* @author Radosław Skrzypczak <r.skrzypczak@yetiforce.com>
*/
Expand Down Expand Up @@ -85,7 +85,7 @@ protected function checkPermission(): void
* type="object",
* @OA\Property(property="id", type="integer", example=117),
* @OA\Property(property="parent", type="integer", example=0),
* @OA\Property(property="name", type="string", example="YetiForce Sp. z o.o."),
* @OA\Property(property="name", type="string", example="YetiForce S.A."),
* ),
* ),
* ),
Expand Down
18 changes: 6 additions & 12 deletions api/webservice/WebservicePremium/BaseModule/Pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
/**
* Webservice premium container - Generates and downloads a PDF file from a template file.
*
* @package Api
* @package API
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Radosław Skrzypczak <r.skrzypczak@yetiforce.com>
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
*/
Expand Down Expand Up @@ -107,19 +107,13 @@ public function get(): array
$file = $pdfFiles = $increment = [];
$recordId = $this->controller->request->getInteger('record');
foreach ($this->controller->request->getArray('templates', 'Integer') as $templateId) {
$template = \Vtiger_PDF_Model::getInstanceById($templateId);
$pdf = \App\Pdf\Pdf::getInstanceByTemplateId($templateId);
$template = $pdf->getTemplate();
if (!$template || !$template->isVisible('Detail') || !$template->checkFiltersForRecord($recordId) || !$template->checkUserPermissions()) {
continue;
}
$template->setVariable('recordId', $recordId);
$pdf = new \App\Pdf\YetiForcePDF();
$pdf->setPageSize($template->getFormat(), $template->getOrientation())
->setWatermark($pdf->getTemplateWatermark($template))
->setFileName($template->parseVariables($template->get('filename')))
->parseParams($template->getParameters())
->loadHtml($template->parseVariables($template->getBody()))
->setHeader($template->parseVariables($template->getHeader()))
->setFooter($template->parseVariables($template->getFooter()));
$pdf->loadTemplateData();

$fileName = ($pdf->getFileName() ?: time());
$increment[$fileName] = $increment[$fileName] ?? 0;
Expand Down
6 changes: 3 additions & 3 deletions api/webservice/WebservicePremium/BaseModule/PdfTemplates.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
/**
* Webservice premium container - Gets a list of PDF templates file.
*
* @package Api
* @package API
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Radosław Skrzypczak <r.skrzypczak@yetiforce.com>
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
*/
Expand Down
4 changes: 2 additions & 2 deletions api/webservice/WebservicePremium/BaseModule/Privileges.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*
* @package API
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
* @author Radosław Skrzypczak <r.skrzypczak@yetiforce.com>
*/
Expand Down
45 changes: 37 additions & 8 deletions api/webservice/WebservicePremium/BaseModule/Record.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
*
* @package API
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
* @author Radosław Skrzypczak <r.skrzypczak@yetiforce.com>
*/

namespace Api\WebservicePremium\BaseModule;
Expand All @@ -19,17 +20,19 @@
class Record extends \Api\WebserviceStandard\BaseModule\Record
{
/** {@inheritdoc} */
public $allowedHeaders = ['x-parent-id', 'x-header-fields'];
public $allowedHeaders = ['x-parent-id', 'x-header-fields', 'x-fields-params'];

/**
* Get record detail.
*
* @api
*
* @return array
*
* @OA\Get(
* path="/webservice/WebservicePremium/{moduleName}/Record/{recordId}",
* summary="Data for the record",
* description="Gets the details of a record",
* summary="Data for the record",
* tags={"BaseModule"},
* security={{"basicAuth" : {}, "ApiKeyAuth" : {}, "token" : {}}},
* operationId="getRecord",
Expand All @@ -38,6 +41,9 @@ class Record extends \Api\WebserviceStandard\BaseModule\Record
* @OA\Parameter(name="X-ENCRYPTED", in="header", @OA\Schema(ref="#/components/schemas/Header-Encrypted"), required=true),
* @OA\Parameter(name="x-raw-data", in="header", @OA\Schema(type="integer", enum={0, 1}), description="Gets raw data", required=false, example=1),
* @OA\Parameter(name="x-parent-id", in="header", @OA\Schema(type="integer"), description="Parent record id", required=false, example=5),
* @OA\Parameter(name="x-fields-params", in="header", description="JSON array - list of fields to be returned in the specified way", required=false,
* @OA\JsonContent(ref="#/components/schemas/Fields-Settings"),
* ),
* @OA\Parameter(
* name="x-header-fields",
* description="Get header fields",
Expand All @@ -64,6 +70,13 @@ class Record extends \Api\WebserviceStandard\BaseModule\Record
* @OA\XmlContent(ref="#/components/schemas/Exception"),
* ),
* ),
* @OA\Schema(
* schema="Fields-Settings",
* title="Custom field settings",
* description="A list of custom parameters that can affect the return value of a given field.",
* type="object",
* example={"password" : {"showHiddenData" : true}}
* ),
* @OA\Schema(
* schema="BaseModule_Get_Record_Response",
* title="Base module - Response body for Record",
Expand Down Expand Up @@ -177,6 +190,8 @@ public function get(): array
/**
* Delete record.
*
* @api
*
* @return bool
*
* @OA\Delete(
Expand Down Expand Up @@ -213,6 +228,8 @@ public function delete(): bool
/**
* Edit record.
*
* @api
*
* @return array
*
* @OA\Put(
Expand All @@ -230,11 +247,17 @@ public function delete(): bool
* @OA\Parameter(name="moduleName", in="path", @OA\Schema(type="string"), description="Module name", required=true, example="Contacts"),
* @OA\Parameter(name="recordId", in="path", @OA\Schema(type="integer"), description="Record id", required=true, example=116),
* @OA\Parameter(name="X-ENCRYPTED", in="header", @OA\Schema(ref="#/components/schemas/Header-Encrypted"), required=true),
* @OA\Response(response=200, description="Contents of the response contains only id",
* @OA\Response(
* response=200, description="Contents of the response contains only id",
* @OA\JsonContent(ref="#/components/schemas/BaseModule_Put_Record_Response"),
* @OA\XmlContent(ref="#/components/schemas/BaseModule_Put_Record_Response"),
* @OA\Link(link="GetRecordById", ref="#/components/links/GetRecordById")
* ),
* @OA\Response(
* response=406, description="No input data",
* @OA\JsonContent(ref="#/components/schemas/Exception"),
* @OA\XmlContent(ref="#/components/schemas/Exception"),
* ),
* ),
* @OA\Schema(
* schema="BaseModule_Put_Record_Response",
Expand Down Expand Up @@ -280,11 +303,13 @@ public function put(): array
/**
* Create record.
*
* @api
*
* @return array
*
* @OA\Post(
* path="/webservice/WebservicePremium/{moduleName}/Record",
* description="Gets data to save record",
* description="Create new record",
* summary="Create record",
* tags={"BaseModule"},
* security={{"basicAuth" : {}, "ApiKeyAuth" : {}, "token" : {}}},
Expand All @@ -297,12 +322,16 @@ public function put(): array
* @OA\Parameter(name="moduleName", in="path", @OA\Schema(type="string"), description="Module name", required=true, example="Contacts"),
* @OA\Parameter(name="X-ENCRYPTED", in="header", @OA\Schema(ref="#/components/schemas/Header-Encrypted"), required=true),
* @OA\Response(
* response=200,
* description="Contents of the response contains only id",
* response=200, description="Contents of the response contains only id",
* @OA\JsonContent(ref="#/components/schemas/BaseModule_Post_Record_Response"),
* @OA\XmlContent(ref="#/components/schemas/BaseModule_Post_Record_Response"),
* @OA\Link(link="GetRecordById", ref="#/components/links/GetRecordById")
* ),
* @OA\Response(
* response=406, description="No input data",
* @OA\JsonContent(ref="#/components/schemas/Exception"),
* @OA\XmlContent(ref="#/components/schemas/Exception"),
* ),
* ),
* @OA\Schema(
* schema="BaseModule_Post_Record_Response",
Expand Down
4 changes: 2 additions & 2 deletions api/webservice/WebservicePremium/BaseModule/RecordHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* @package API
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
* @author Radosław Skrzypczak <r.skrzypczak@yetiforce.com>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* @package API
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
* @author Radosław Skrzypczak <r.skrzypczak@yetiforce.com>
*/
Expand Down
4 changes: 2 additions & 2 deletions api/webservice/WebservicePremium/BaseModule/RecordsList.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* @package API
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
* @author Radosław Skrzypczak <r.skrzypczak@yetiforce.com>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* @package API
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
*/

Expand Down
21 changes: 17 additions & 4 deletions api/webservice/WebservicePremium/BaseModule/SaveInventory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
/**
* Webservice premium container - A store functionality - creates a record in an advanced module (orders) file.
*
* @package Api
* @package API
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Arkadiusz Adach <a.adach@yetiforce.com>
* @author Tomasz Kur <t.kur@yetiforce.com>
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
Expand Down Expand Up @@ -188,12 +188,25 @@ private function checkBeforeSave(): array
],
];
}
$this->inventory = new \Api\WebservicePremium\Inventory($this->moduleName, $this->controller->request->getArray('inventory'), $this->getUserStorageId(), $this->getParentCrmId());
$this->inventory = new \Api\WebservicePremium\Inventory($this->moduleName, $this);
if ($this->getCheckStockLevels() && !$this->inventory->validate()) {
return [
'errors' => $this->inventory->getErrors(),
];
}
return [];
}

/**
* Get information, whether to check inventory levels.
*
* @return bool
*/
public function getCheckStockLevels(): bool
{
if (\Api\WebservicePremium\Privilege::USER_PERMISSIONS !== $this->getPermissionType() && ($parentId = $this->getParentCrmId())) {
return (bool) \Vtiger_Record_Model::getInstanceById($parentId)->get('check_stock_levels');
}
return false;
}
}
12 changes: 6 additions & 6 deletions api/webservice/WebservicePremium/BaseModule/SourceBasedData.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* @package API
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
*/

Expand Down Expand Up @@ -80,14 +80,14 @@ public function put(): array
$raw = $data = [];
foreach ($recordModel->getModule()->getValuesFromSource($this->controller->request) as $fieldName => $value) {
$recordModel->set($fieldName, $value);
$raw[$fieldName] = $value;
$raw[$fieldName] = $recordModel->getRawValue($fieldName);
}
foreach ($raw as $fieldName => $value) {
$data[$fieldName] = $recordModel->getModule()->getFieldByName($fieldName)->getUITypeModel()->getApiDisplayValue($value, $recordModel);
foreach (array_keys($raw) as $fieldName) {
$data[$fieldName] = $recordModel->getModule()->getFieldByName($fieldName)->getUITypeModel()->getApiDisplayValue($recordModel->get($fieldName), $recordModel);
}
return [
'data' => $data,
'rawData' => $raw,
'rawData' => $raw
];
}
}
4 changes: 2 additions & 2 deletions api/webservice/WebservicePremium/BaseModule/Widgets.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* @package API
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Radosław Skrzypczak <r.skrzypczak@yetiforce.com>
*/

Expand Down
24 changes: 19 additions & 5 deletions api/webservice/WebservicePremium/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
/**
* Dashboard model file.
*
* @package Api
* @package API
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Tomasz Kur <t.kur@yetiforce.com>
* @author Radosław Skrzypczak <r.skrzypczak@yetiforce.com>
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
Expand Down Expand Up @@ -55,6 +55,19 @@ public static function getInstance(string $moduleName, int $dashboardType, int $
return $instance;
}

/**
* Set dashboard ID.
*
* @param int $dashboardType
*
* @return $this
*/
public function setDashboard(int $dashboardType): self
{
$this->dashboardType = $dashboardType;
return $this;
}

/**
* Gets tabs.
*
Expand All @@ -68,9 +81,10 @@ public function getTabs(): array
->where(['vtiger_module_dashboard_blocks.authorized' => $this->application])
->distinct()->createCommand()->query();
while ($dashboard = $dataReader->read()) {
$tabs[] = [
$dbId = $dashboard['dashboard_id'];
$tabs[$dbId] = [
'name' => \App\Language::translate($dashboard['name'], $this->moduleName),
'id' => $dashboard['dashboard_id'],
'id' => $dbId,
'system' => $dashboard['system'],
];
}
Expand Down
91 changes: 29 additions & 62 deletions api/webservice/WebservicePremium/Inventory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
/**
* The file contains: SaveInventory class.
*
* @package Api
* @package API
*
* @copyright YetiForce Sp. z o.o.
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Arkadiusz Adach <a.adach@yetiforce.com>
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
*/

namespace Api\WebservicePremium;
Expand All @@ -16,87 +17,53 @@
*/
class Inventory
{
/**
* Module name.
*
* @var string
*/
/** @var string Module name. */
protected $moduleName;

/**
* Inventory items passed from request.
*
* @var array
*/
/** @var array Inventory items passed from request. */
protected $inventory;

/**
* Field mapping.
*
* @var array|null
*/
/** @var array|null Field mapping. */
private $fieldMapping;

/**
* Storage.
*
* @var int
*/
/** @var int Storage ID */
protected $storage;

/**
* Products.
*
* @var array
*/
/** @var array Products */
protected $products = [];

/**
* Arrays with errors.
*
* @var array
*/
/** @var array Arrays with errors. */
protected $errors = [];

/**
* Pricebook id.
*
* @var int|null
*/
protected $pricebookId;
/** @var int|null Price book id. */
protected $priceBookId;

/**
* Undocumented variable.
*
* @var \Vtiger_Record_Model
*/
/** @var \Vtiger_Record_Model Parent record model */
protected $parentRecordModel;

/**
* Sequence.
*
* @var int
*/
/** @var int Sequence. */
protected $seq;

/** @var int Permission type. */
protected $permissionType;

/**
* Construct.
*
* @param string $moduleName
* @param array $inventory
* @param int $storage
* @param int|null $accountId
* @param string $moduleName
* @param \Api\Core\BaseAction $actionModel
*/
public function __construct(string $moduleName, array $inventory, int $storage, ?int $accountId)
public function __construct(string $moduleName, \Api\Core\BaseAction $actionModel)
{
$this->moduleName = $moduleName;
$this->inventory = $inventory;
$this->storage = $storage;
$this->inventory = $actionModel->controller->request->getArray('inventory');
$this->storage = $actionModel->getUserStorageId();
$this->permissionType = $actionModel->getPermissionType();
$accountId = $actionModel->getParentCrmId();
if (!empty($accountId)) {
$this->parentRecordModel = \Vtiger_Record_Model::getInstanceById($accountId, 'Accounts');
$this->pricebookId = $this->parentRecordModel->get('pricebook_id');
$this->priceBookId = $this->parentRecordModel->get('pricebook_id');
}

$this->getProductsByInventory();
}

Expand Down Expand Up @@ -270,9 +237,9 @@ private function getProductsByInventory()
if (!empty($this->storage)) {
$queryService->addSelect(['quantity' => new \yii\db\Expression('0')]);
}
if (!$isUserPermissions && !empty($this->pricebookId)) {
if (!$isUserPermissions && !empty($this->priceBookId)) {
$queryService->addSelect(['vtiger_pricebookproductrel.listprice']);
$queryService->leftJoin('vtiger_pricebookproductrel', "vtiger_pricebookproductrel.pricebookid={$this->pricebookId} AND vtiger_pricebookproductrel.productid = vtiger_service.serviceid");
$queryService->leftJoin('vtiger_pricebookproductrel', "vtiger_pricebookproductrel.pricebookid={$this->priceBookId} AND vtiger_pricebookproductrel.productid = vtiger_service.serviceid");
}
$query = (new \App\Db\Query())
->select([
Expand All @@ -290,9 +257,9 @@ private function getProductsByInventory()
$query->addSelect(['quantity' => 'u_#__istorages_products.qtyinstock']);
$query->leftJoin('u_#__istorages_products', "u_#__istorages_products.crmid={$this->storage} AND u_#__istorages_products.relcrmid = vtiger_products.productid");
}
if (!$isUserPermissions && !empty($this->pricebookId)) {
if (!$isUserPermissions && !empty($this->priceBookId)) {
$query->addSelect(['vtiger_pricebookproductrel.listprice']);
$query->leftJoin('vtiger_pricebookproductrel', "vtiger_pricebookproductrel.pricebookid={$this->pricebookId} AND vtiger_pricebookproductrel.productid = vtiger_products.productid");
$query->leftJoin('vtiger_pricebookproductrel', "vtiger_pricebookproductrel.pricebookid={$this->priceBookId} AND vtiger_pricebookproductrel.productid = vtiger_products.productid");
}
$dataReader = $query->createCommand()->query();
$multiCurrencyUiType = new \Vtiger_MultiCurrency_UIType();
Expand Down
6 changes: 3 additions & 3 deletions api/webservice/WebservicePremium/ModComments/Record.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
/**
* Webservice premium container - ModComments record detail file.
*
* @package Api
* @package API
*
* @copyright YetiForce Sp. z o.o.
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Radosław Skrzypczak <r.skrzypczak@yetiforce.com>
*/

Expand Down
6 changes: 3 additions & 3 deletions api/webservice/WebservicePremium/Privilege.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
/**
* Privilege file for client portal.
*
* @package Api
* @package API
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Tomasz Kur <t.kur@yetiforce.com>
* @author Radosław Skrzypczak <r.skrzypczak@yetiforce.com>
*/
Expand Down
6 changes: 3 additions & 3 deletions api/webservice/WebservicePremium/PrivilegeQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
/**
* Privilege File for client portal.
*
* @package Api
* @package API
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Tomasz Kur <t.kur@yetiforce.com>
* @author Radosław Skrzypczak <r.skrzypczak@yetiforce.com>
*/
Expand Down
15 changes: 9 additions & 6 deletions api/webservice/WebservicePremium/Products/Record.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
/**
* Webservice premium container - Loads the details of a product file.
*
* @package Api
* @package API
*
* @copyright YetiForce Sp. z o.o.
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Arkadiusz Adach <a.adach@yetiforce.com>
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
* @author Radosław Skrzypczak <r.skrzypczak@yetiforce.com>
Expand Down Expand Up @@ -89,11 +89,13 @@ class Record extends \Api\WebservicePremium\BaseModule\Record
* schema="Products_Get_Record_Response",
* title="Base module - Response body for Record",
* type="object",
* required={"status", "result"},
* @OA\Property(property="status", type="integer", enum={0, 1}, description="A numeric value of 0 or 1 that indicates whether the communication is valid. 1 - success , 0 - error"),
* @OA\Property(
* property="result",
* description="Record data",
* title="Record data",
* type="object",
* required={"name", "id", "fields", "data"},
* @OA\Property(property="name", description="Record name", type="string", example="Driving school"),
* @OA\Property(property="id", description="Record Id", type="integer", example=152),
* @OA\Property(property="fields", type="object", title="System field names and field labels", example={"field_name_1" : "Field label 1", "field_name_2" : "Field label 2", "assigned_user_id" : "Assigned user", "createdtime" : "Created time"},
Expand All @@ -107,8 +109,9 @@ class Record extends \Api\WebservicePremium\BaseModule\Record
* ),
* @OA\Property(
* property="privileges",
* description="Parameters determining checking of editing rights and moving to the trash",
* title="Parameters determining checking of editing rights and moving to the trash",
* type="object",
* required={"isEditable", "moveToTrash"},
* @OA\Property(property="isEditable", description="Check if record is editable", type="boolean", example=true),
* @OA\Property(property="moveToTrash", description="Permission to delete", type="boolean", example=false),
* ),
Expand Down Expand Up @@ -215,7 +218,7 @@ private function getProductBundles(): array
$productRelationModel = \Vtiger_Relation_Model::getInstance($this->recordModel->getModule(), $this->recordModel->getModule());
$productRelationModel->set('parentRecord', $this->recordModel);
$queryGenerator = $productRelationModel->getQuery();
$queryGenerator->setField(['ean', 'taxes', 'imagename']);
$queryGenerator->setField('ean')->setField('taxes')->setField('imagename');
if ($this->isUserPermissions) {
$availableTaxes = 'LBL_GROUP_TAX';
$regionalTaxes = '';
Expand Down
6 changes: 3 additions & 3 deletions api/webservice/WebservicePremium/Products/RecordsTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
/**
* Webservice premium container - A store functionality - gets a list of products for orders file.
*
* @package Api
* @package API
*
* @copyright YetiForce Sp. z o.o.
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Arkadiusz Adach <a.adach@yetiforce.com>
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
* @author Radosław Skrzypczak <r.skrzypczak@yetiforce.com>
Expand Down
6 changes: 3 additions & 3 deletions api/webservice/WebservicePremium/Record.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
/**
* The file contains: Record class.
*
* @package Api
* @package API
*
* @copyright YetiForce Sp. z o.o.
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
*/

Expand Down
6 changes: 3 additions & 3 deletions api/webservice/WebservicePremium/SSingleOrders/Delivery.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
/**
* Returns price of delivery.
*
* @package Api
* @package API
*
* @copyright YetiForce Sp. z o.o.
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Tomasz Kur <t.kur@yetiforce.com>
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* @package API
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
* @author Radosław Skrzypczak <r.skrzypczak@yetiforce.com>
*/
Expand Down
4 changes: 2 additions & 2 deletions api/webservice/WebservicePremium/Users/ChangePassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* @package API
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
*/

Expand Down
6 changes: 3 additions & 3 deletions api/webservice/WebservicePremium/Users/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
/**
* Webservice premium container - Users Login action file.
*
* @package Api
* @package API
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
*/

Expand Down
4 changes: 2 additions & 2 deletions api/webservice/WebservicePremium/Users/Logout.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* @package API
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
*/

Expand Down
4 changes: 2 additions & 2 deletions api/webservice/WebservicePremium/Users/Preferences.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* @package API
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
*/

Expand Down
4 changes: 2 additions & 2 deletions api/webservice/WebservicePremium/Users/Record.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* @package API
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
*/

Expand Down
4 changes: 2 additions & 2 deletions api/webservice/WebservicePremium/Users/RecordsList.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* @package API
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
* @author Radosław Skrzypczak <r.skrzypczak@yetiforce.com>
*/
Expand Down
4 changes: 2 additions & 2 deletions api/webservice/WebservicePremium/Users/ResetPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* @package API
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
*/

Expand Down
4 changes: 2 additions & 2 deletions api/webservice/WebservicePremium/Users/TwoFactorAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* @package API
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
*/

Expand Down
10 changes: 4 additions & 6 deletions api/webservice/WebserviceStandard/BaseAction/Files.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* @package API
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Tomasz Kur <t.kur@yetiforce.com>
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
* @author Radosław Skrzypczak <r.skrzypczak@yetiforce.com>
Expand Down Expand Up @@ -56,10 +56,6 @@
* description="Access to user methods"
* )
* @OA\Tag(
* name="Products",
* description="Products methods"
* )
* @OA\Tag(
* name="Users",
* description="Access to user methods"
* )
Expand All @@ -75,6 +71,8 @@ class Files extends \Api\Core\BaseAction
/**
* Put method.
*
* @api
*
* @throws \Api\Core\Exception
*
* @return \App\Fields\File
Expand Down
6 changes: 4 additions & 2 deletions api/webservice/WebserviceStandard/BaseAction/Modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*
* @package API
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
*/

Expand All @@ -25,6 +25,8 @@ class Modules extends \Api\Core\BaseAction
/**
* Get permitted modules.
*
* @api
*
* @return array
*
* @OA\Get(
Expand Down
6 changes: 4 additions & 2 deletions api/webservice/WebserviceStandard/BaseModule/CustomView.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* @package API
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Radosław Skrzypczak <r.skrzypczak@yetiforce.com>
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
*/
Expand Down Expand Up @@ -47,6 +47,8 @@ protected function checkPermission(): void
/**
* Get custom view list method.
*
* @api
*
* @return array
*
* @OA\Get(
Expand Down
13 changes: 5 additions & 8 deletions api/webservice/WebserviceStandard/BaseModule/Fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
*
* @package API
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
* @author Radosław Skrzypczak <r.skrzypczak@yetiforce.com>
*/

namespace Api\WebserviceStandard\BaseModule;
Expand Down Expand Up @@ -189,9 +190,7 @@ public function get(): array
$block = $fieldModel->get('block');
if ($returnBlocks && !isset($blocks[$block->id])) {
$blockProperties = get_object_vars($block);
$blocks[$block->id] = array_filter($blockProperties, function ($v) {
return !\is_object($v);
});
$blocks[$block->id] = array_filter($blockProperties, fn ($v) => !\is_object($v));
$blocks[$block->id]['name'] = \App\Language::translate($block->label, $moduleName);
}
$fieldInfo = $fieldModel->getFieldInfo();
Expand All @@ -214,9 +213,7 @@ public function get(): array
$fieldInfo['dbStructure'] = $fieldModel->getDBColumnType(false);
}
if ($returnQueryOperators) {
$fieldInfo['queryOperators'] = array_map(function ($value) use ($moduleName) {
return \App\Language::translate($value, $moduleName);
}, $fieldModel->getQueryOperators());
$fieldInfo['queryOperators'] = array_map(fn ($value) => \App\Language::translate($value, $moduleName), $fieldModel->getQueryOperators());
}
if (isset($fieldInfo['picklistvalues']) && $fieldModel->isEmptyPicklistOptionAllowed()) {
$fieldInfo['isEmptyPicklistOptionAllowed'] = $fieldModel->isEmptyPicklistOptionAllowed();
Expand Down
6 changes: 4 additions & 2 deletions api/webservice/WebserviceStandard/BaseModule/Privileges.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*
* @package API
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
* @author Radosław Skrzypczak <r.skrzypczak@yetiforce.com>
*/
Expand All @@ -26,6 +26,8 @@ class Privileges extends \Api\Core\BaseAction
/**
* Get privileges for module.
*
* @api
*
* @return array
*
* @OA\Get(
Expand Down
62 changes: 47 additions & 15 deletions api/webservice/WebserviceStandard/BaseModule/Record.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* @package API
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
* @author Radosław Skrzypczak <r.skrzypczak@yetiforce.com>
* @author Arkadiusz Adach <a.adach@yetiforce.com>
Expand All @@ -24,7 +24,7 @@ class Record extends \Api\Core\BaseAction
public $allowedMethod = ['GET', 'DELETE', 'PUT', 'POST'];

/** {@inheritdoc} */
public $allowedHeaders = ['x-parent-id'];
public $allowedHeaders = ['x-parent-id', 'x-fields-params'];

/** @var \Vtiger_Record_Model Record model instance. */
public $recordModel;
Expand Down Expand Up @@ -75,6 +75,8 @@ protected function checkPermission(): void
/**
* Get record detail.
*
* @api
*
* @return array
*
* @OA\Get(
Expand All @@ -89,6 +91,9 @@ protected function checkPermission(): void
* @OA\Parameter(name="X-ENCRYPTED", in="header", @OA\Schema(ref="#/components/schemas/Header-Encrypted"), required=true),
* @OA\Parameter(name="x-raw-data", in="header", @OA\Schema(type="integer", enum={0, 1}), description="Gets raw data", required=false, example=1),
* @OA\Parameter(name="x-parent-id", in="header", @OA\Schema(type="integer"), description="Parent record id", required=false, example=5),
* @OA\Parameter(name="x-fields-params", in="header", description="JSON array - list of fields to be returned in the specified way", required=false,
* @OA\JsonContent(ref="#/components/schemas/Fields-Settings"),
* ),
* @OA\Response(
* response=200,
* description="Gets data for the record",
Expand All @@ -109,6 +114,13 @@ protected function checkPermission(): void
* ),
* ),
* @OA\Schema(
* schema="Fields-Settings",
* title="Custom field settings",
* description="A list of custom parameters that can affect the return value of a given field.",
* type="object",
* example={"password" : {"showHiddenData" : true}}
* ),
* @OA\Schema(
* schema="BaseModule_Get_Record_Response",
* title="Base module - Response body for Record",
* type="object",
Expand Down Expand Up @@ -142,19 +154,19 @@ protected function checkPermission(): void
*/
public function get(): array
{
$displayData = $fieldsLabel = [];
$moduleName = $this->controller->request->get('module');
$rawData = $this->recordModel->getData();
$setRawData = 1 === (int) ($this->controller->headers['x-raw-data'] ?? 0);
$displayData = $fieldsLabel = [];
$fields = $this->recordModel->getModule()->getFields();
\Api\WebserviceStandard\Fields::loadWebserviceFields($fields, $this);
foreach ($fields as $fieldModel) {
$fieldParams = \App\Json::decode($this->controller->request->getHeader('x-fields-params')) ?: [];

\Api\WebserviceStandard\Fields::loadWebserviceFields($this->recordModel->getModule(), $this);
foreach ($this->recordModel->getModule()->getFields() as $fieldModel) {
if (!$fieldModel->isActiveField() || !$fieldModel->isViewable()) {
continue;
}
$uiTypeModel = $fieldModel->getUITypeModel();
$value = $this->recordModel->get($fieldModel->getName());
$displayData[$fieldModel->getName()] = $uiTypeModel->getApiDisplayValue($value, $this->recordModel);
$displayData[$fieldModel->getName()] = $uiTypeModel->getApiDisplayValue($value, $this->recordModel, $fieldParams[$fieldModel->getName()] ?? []);
$fieldsLabel[$fieldModel->getName()] = \App\Language::translate($fieldModel->get('label'), $moduleName);
}
$response = [
Expand Down Expand Up @@ -191,6 +203,12 @@ public function get(): array
}
}
if ($setRawData) {
$rawData = [];
foreach ($this->recordModel->getData() as $key => $value) {
if ('id' === $key || 'record_module' === $key || (($fieldModel = $this->recordModel->getField($key)) && $fieldModel->isViewable())) {
$rawData[$key] = $this->recordModel->getRawValue($key);
}
}
$response['rawData'] = $rawData;
}
return $response;
Expand All @@ -199,6 +217,8 @@ public function get(): array
/**
* Delete record.
*
* @api
*
* @return bool
*
* @OA\Delete(
Expand Down Expand Up @@ -236,6 +256,8 @@ public function delete(): bool
/**
* Edit record.
*
* @api
*
* @return array
*
* @OA\Put(
Expand All @@ -254,12 +276,16 @@ public function delete(): bool
* @OA\Parameter(name="recordId", in="path", @OA\Schema(type="integer"), description="Record id", required=true, example=116),
* @OA\Parameter(name="X-ENCRYPTED", in="header", @OA\Schema(ref="#/components/schemas/Header-Encrypted"), required=true),
* @OA\Response(
* response=200,
* description="Contents of the response contains only id",
* response=200, description="Contents of the response contains only id",
* @OA\JsonContent(ref="#/components/schemas/BaseModule_Put_Record_Response"),
* @OA\XmlContent(ref="#/components/schemas/BaseModule_Put_Record_Response"),
* @OA\Link(link="GetRecordById", ref="#/components/links/GetRecordById")
* ),
* @OA\Response(
* response=406, description="No input data",
* @OA\JsonContent(ref="#/components/schemas/Exception"),
* @OA\XmlContent(ref="#/components/schemas/Exception"),
* ),
* ),
* @OA\Schema(
* schema="BaseModule_Put_Record_Response",
Expand Down Expand Up @@ -299,7 +325,7 @@ public function delete(): bool
*/
public function put(): array
{
\Api\WebserviceStandard\Fields::loadWebserviceFields($this->recordModel->getModule()->getFields(), $this);
\Api\WebserviceStandard\Fields::loadWebserviceFields($this->recordModel->getModule(), $this);
$saveModel = new \Api\WebserviceStandard\Save();
$saveModel->init($this);
$saveModel->saveRecord($this->controller->request);
Expand All @@ -316,11 +342,13 @@ public function put(): array
/**
* Create record.
*
* @api
*
* @return array
*
* @OA\Post(
* path="/webservice/WebserviceStandard/{moduleName}/Record",
* description="Gets data to save record",
* description="Create new record",
* summary="Create record",
* tags={"BaseModule"},
* security={{"basicAuth" : {}, "ApiKeyAuth" : {}, "token" : {}}},
Expand All @@ -333,12 +361,16 @@ public function put(): array
* @OA\Parameter(name="moduleName", in="path", @OA\Schema(type="string"), description="Module name", required=true, example="Contacts"),
* @OA\Parameter(name="X-ENCRYPTED", in="header", @OA\Schema(ref="#/components/schemas/Header-Encrypted"), required=true),
* @OA\Response(
* response=200,
* description="Contents of the response contains only id",
* response=200, description="Contents of the response contains only id",
* @OA\JsonContent(ref="#/components/schemas/BaseModule_Post_Record_Response"),
* @OA\XmlContent(ref="#/components/schemas/BaseModule_Post_Record_Response"),
* @OA\Link(link="GetRecordById", ref="#/components/links/GetRecordById")
* ),
* @OA\Response(
* response=406, description="No input data",
* @OA\JsonContent(ref="#/components/schemas/Exception"),
* @OA\XmlContent(ref="#/components/schemas/Exception"),
* ),
* ),
* @OA\Schema(
* schema="BaseModule_Post_Record_Response",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* @package API
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
* @author Radosław Skrzypczak <r.skrzypczak@yetiforce.com>
*/
Expand Down Expand Up @@ -48,6 +48,8 @@ public function checkAction(): void
/**
* Get related record list method.
*
* @api
*
* @return array
* @OA\Get(
* path="/webservice/WebserviceStandard/{moduleName}/RecordHistory/{recordId}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* @package API
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
* @author Radosław Skrzypczak <r.skrzypczak@yetiforce.com>
*/
Expand Down Expand Up @@ -48,6 +48,8 @@ public function checkAction(): void
/**
* Get related record list method.
*
* @api
*
* @throws \Api\Core\Exception
*
* @return array
Expand Down Expand Up @@ -200,7 +202,7 @@ public function get(): array
$value = $relatedRecordModel->get($fieldName);
$response['records'][$id][$fieldName] = $fieldModel->getUITypeModel()->getApiDisplayValue($value, $relatedRecordModel);
if ($isRawData) {
$response['rawData'][$id][$fieldName] = $value;
$response['rawData'][$id][$fieldName] = $relatedRecordModel->getRawValue($fieldName);
}
}
}
Expand Down
42 changes: 36 additions & 6 deletions api/webservice/WebserviceStandard/BaseModule/RecordsList.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* @package API
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
* @author Radosław Skrzypczak <r.skrzypczak@yetiforce.com>
*/
Expand Down Expand Up @@ -40,6 +40,8 @@ class RecordsList extends \Api\Core\BaseAction
/**
* Get record list method.
*
* @api
*
* @return array
*
* @OA\Get(
Expand Down Expand Up @@ -175,7 +177,7 @@ public function createQuery(): void
}
$this->queryGenerator->initForCustomViewById($cvId);
} else {
$this->queryGenerator->initForDefaultCustomView();
$this->queryGenerator->initForDefaultCustomView(false, true);
}

$limit = 100;
Expand All @@ -188,7 +190,7 @@ public function createQuery(): void
}
$this->queryGenerator->setLimit($limit);
$this->queryGenerator->setOffset($offset);
\Api\WebserviceStandard\Fields::loadWebserviceFields($this->queryGenerator->getModuleModel()->getFields(), $this);
\Api\WebserviceStandard\Fields::loadWebserviceFields($this->queryGenerator->getModuleModel(), $this);
if ($requestFields = $this->controller->request->getHeader('x-fields')) {
if (!\App\Json::isJson($requestFields)) {
throw new \Api\Core\Exception('Incorrect json syntax: x-fields', 400);
Expand Down Expand Up @@ -291,10 +293,17 @@ protected function getRecordFromRow(array $row): array
protected function getColumnNames(): array
{
$headers = [];
$selectedColumnsList = [];
if ($cvId = $this->controller->request->getHeader('x-cv-id')) {
$customViewModel = \CustomView_Record_Model::getInstanceById($cvId);
$selectedColumnsList = $customViewModel->getSelectedFields();
}
if ($this->fields) {
foreach ($this->fields as $fieldName => $fieldModel) {
if ($fieldModel->isViewable()) {
$headers[$fieldName] = \App\Language::translate($fieldModel->getFieldLabel(), $fieldModel->getModuleName());
$moduleName = $fieldModel->getModuleName();
$fieldLabel = empty($selectedColumnsList[$fieldName . ':' . $moduleName]) ? $fieldModel->getFieldLabel() : $selectedColumnsList[$fieldName . ':' . $moduleName];
$headers[$fieldName] = \App\Language::translate($fieldLabel, $moduleName);
}
}
}
Expand All @@ -304,7 +313,9 @@ protected function getColumnNames(): array
foreach ($field as $relatedFieldName) {
$fieldModel = \Vtiger_Module_Model::getInstance($relatedModuleName)->getFieldByName($relatedFieldName);
if ($fieldModel->isViewable()) {
$headers[$sourceField . $relatedModuleName . $relatedFieldName] = \App\Language::translate($fieldModel->getFieldLabel(), $relatedModuleName);
$selectedColumnKey = $relatedFieldName . ':' . $relatedModuleName . ':' . $sourceField;
$fieldLabel = empty($selectedColumnsList[$selectedColumnKey]) ? $fieldModel->getFieldLabel() : $selectedColumnsList[$selectedColumnKey];
$headers[$sourceField . $relatedModuleName . $relatedFieldName] = \App\Language::translate($fieldLabel, $relatedModuleName);
}
}
}
Expand All @@ -322,6 +333,25 @@ protected function getColumnNames(): array
*/
protected function getRawDataFromRow(array $row): array
{
foreach ($this->fields as $fieldName => $fieldModel) {
if (\array_key_exists($fieldName, $row)) {
$row[$fieldName] = $fieldModel->getUITypeModel()->getRawValue($row[$fieldName]);
}
}
if ($this->relatedFields) {
foreach ($this->relatedFields as $relatedModuleName => $fields) {
foreach ($fields as $sourceField => $field) {
foreach ($field as $relatedFieldName) {
$key = $sourceField . $relatedModuleName . $relatedFieldName;
if (\array_key_exists($key, $row)) {
$fieldModel = \Vtiger_Module_Model::getInstance($relatedModuleName)->getFieldByName($relatedFieldName);
$row[$key] = $fieldModel->getUITypeModel()->getRawValue($row[$key]);
}
}
}
}
}

return $row;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* @package API
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
*/

Expand All @@ -24,6 +24,8 @@ class RelatedModules extends \Api\Core\BaseAction
/**
* Get related modules list method.
*
* @api
*
* @return array
*
* @OA\Get(
Expand Down
35 changes: 19 additions & 16 deletions api/webservice/WebserviceStandard/Fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
/**
* File with custom functionality for fields.
*
* @package Api
* @package API
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
*/

Expand All @@ -22,14 +22,15 @@ class Fields
/**
* Load custom fields data for the webservice app.
*
* @param \Vtiger_Field_Model[] $fields
* @param \Api\Core\BaseAction $actionModel
* @param \Vtiger_Module_Model $moduleModel
* @param \Api\Core\BaseAction $actionModel
*
* @return void
*/
public static function loadWebserviceFields(array $fields, \Api\Core\BaseAction $actionModel): void
public static function loadWebserviceFields(\Vtiger_Module_Model $moduleModel, \Api\Core\BaseAction $actionModel): void
{
foreach (self::getFields($actionModel->controller->app['id']) as $fieldName => $fieldData) {
$fields = $moduleModel->getFields();
foreach (self::getFields($actionModel->controller->app['id'], $moduleModel->getId()) as $fieldName => $fieldData) {
if (isset($fields[$fieldName])) {
self::loadWebserviceByField($fields[$fieldName], $actionModel, $fieldData);
}
Expand All @@ -48,7 +49,7 @@ public static function loadWebserviceFields(array $fields, \Api\Core\BaseAction
public static function loadWebserviceByField(\Vtiger_Field_Model $fieldModel, \Api\Core\BaseAction $actionModel, ?array $fieldData = null): void
{
if (null === $fieldData) {
$fieldData = self::getFields($actionModel->controller->app['id'])[$fieldModel->getName()] ?? [];
$fieldData = self::getFields($actionModel->controller->app['id'], $fieldModel->getModuleId())[$fieldModel->getName()] ?? [];
}
if ($fieldData) {
if (1 !== $actionModel->getUserData('type') && !empty($fieldData['is_default'])) {
Expand All @@ -64,24 +65,26 @@ public static function loadWebserviceByField(\Vtiger_Field_Model $fieldModel, \A
* Get fields for current webservice app.
*
* @param int $serverId
* @param int $moduleId
*
* @return array
*/
public static function getFields(int $serverId): array
public static function getFields(int $serverId, int $moduleId): array
{
if (isset(self::$webserviceAppsFields[$serverId])) {
return self::$webserviceAppsFields[$serverId];
$cacheKey = "{$serverId}_{$moduleId}";
if (isset(self::$webserviceAppsFields[$cacheKey])) {
return self::$webserviceAppsFields[$cacheKey];
}
if (\App\Cache::has('WebserviceAppsFields', $serverId)) {
return \App\Cache::get('WebserviceAppsFields', $serverId);
if (\App\Cache::has('WebserviceAppsFields', $cacheKey)) {
return \App\Cache::get('WebserviceAppsFields', $cacheKey);
}
self::$webserviceAppsFields[$serverId] = $response = (new \App\Db\Query())->select(['vtiger_field.fieldname', 'w_#__fields_server.*'])
self::$webserviceAppsFields[$cacheKey] = $response = (new \App\Db\Query())->select(['vtiger_field.fieldname', 'w_#__fields_server.*'])
->from('w_#__fields_server')
->where(['w_#__fields_server.serverid' => $serverId])
->where(['w_#__fields_server.serverid' => $serverId, 'vtiger_field.tabid' => $moduleId])
->innerJoin('vtiger_field', 'w_#__fields_server.fieldid = vtiger_field.fieldid')
->indexBy('fieldname')
->all(\App\Db::getInstance('webservice')) ?: [];
\App\Cache::save('WebserviceAppsFields', $serverId, $response);
\App\Cache::save('WebserviceAppsFields', $cacheKey, $response);
return $response;
}

Expand Down
14 changes: 9 additions & 5 deletions api/webservice/WebserviceStandard/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
/**
* Action file to save record.
*
* @package Api
* @package API
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Tomasz Kur <t.kur@yetiforce.com>
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
*/
Expand All @@ -19,6 +19,7 @@ class Save extends \Vtiger_Save_Action
{
/** @var int ID of application. */
protected $appId;

/** @var array Skipped value. */
public $skippedData = [];

Expand All @@ -32,11 +33,11 @@ public function __construct()
/**
* Initialization with API data.
*
* @param BaseModule\Record $record
* @param BaseModule\Record|Users\Record $record
*
* @return void
*/
public function init(BaseModule\Record $record): void
public function init(\Api\Core\BaseAction $record): void
{
$this->appId = $record->controller->app['id'];
$this->record = $record->recordModel;
Expand All @@ -48,6 +49,9 @@ protected function getRecordModelFromRequest(\App\Request $request)
$fieldModelList = $this->record->getModule()->getFields();
$requestKeys = $request->getAllRaw();
unset($requestKeys['module'],$requestKeys['action'],$requestKeys['record']);
if (empty($requestKeys)) {
throw new \Api\Core\Exception('No input data', 406);
}
foreach ($fieldModelList as $fieldName => $fieldModel) {
if (!$fieldModel->isWritable()) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* @package API
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
*/

Expand All @@ -32,6 +32,8 @@ protected function checkPermissionToModule(): void
/**
* Get user history of access activity.
*
* @api
*
* @return array
*
* @OA\Get(
Expand Down Expand Up @@ -95,7 +97,7 @@ public function get(): array
while ($row = $dataReader->read()) {
$rows[] = [
'time' => \App\Fields\DateTime::formatToDisplay($row['time']),
'status' => \App\Language::translate($row['status'], 'Settings.WebserviceUsers'),
'status' => \App\Language::translate($row['status'], 'Settings:WebserviceUsers'),
'agent' => $row['agent'],
'ip' => $row['ip'],
];
Expand Down
6 changes: 4 additions & 2 deletions api/webservice/WebserviceStandard/Users/ChangePassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* @package API
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
*/

Expand All @@ -31,6 +31,8 @@ protected function checkPermissionToModule(): void
/**
* Put method.
*
* @api
*
* @return bool
*
* @OA\Put(
Expand Down
10 changes: 6 additions & 4 deletions api/webservice/WebserviceStandard/Users/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* @package API
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
*/

Expand Down Expand Up @@ -39,6 +39,8 @@ protected function checkPermissionToModule(): void
/**
* Post method.
*
* @api
*
* @throws \Api\Core\Exception
*
* @return array|null
Expand Down Expand Up @@ -356,7 +358,7 @@ protected function createSession(): void
'params' => \App\Json::encode($params),
'ip' => $this->controller->request->getServer('REMOTE_ADDR'),
'last_method' => $this->controller->request->getServer('REQUEST_URI'),
'agent' => \App\TextParser::textTruncate($this->controller->request->getServer('HTTP_USER_AGENT', '-'), 100, false),
'agent' => \App\TextUtils::textTruncate($this->controller->request->getServer('HTTP_USER_AGENT', '-'), 100, false),
])->execute();
}

Expand All @@ -371,7 +373,7 @@ protected function checkAccess(): void
{
$db = \App\Db::getInstance('webservice');
$userData = (new \App\Db\Query())->from($this->controller->app['tables']['user'])
->where(['user_name' => $this->controller->request->get('userName'), 'status' => 1])
->where(['server_id' => $this->controller->app['id'], 'user_name' => $this->controller->request->get('userName'), 'status' => 1])
->limit(1)->one($db);
if (!$userData) {
$this->saveLoginHistory([
Expand Down
6 changes: 4 additions & 2 deletions api/webservice/WebserviceStandard/Users/Logout.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* @package API
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
*/

Expand All @@ -30,6 +30,8 @@ protected function checkPermissionToModule(): void
/**
* Put method.
*
* @api
*
* @return bool
*
* @OA\Put(
Expand Down
122 changes: 106 additions & 16 deletions api/webservice/WebserviceStandard/Users/Record.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
*
* @package API
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
* @author Radosław Skrzypczak <r.skrzypczak@yetiforce.com>
*/

namespace Api\WebserviceStandard\Users;
Expand All @@ -19,33 +20,37 @@
class Record extends \Api\Core\BaseAction
{
/** {@inheritdoc} */
public $allowedMethod = ['GET'];
public $allowedMethod = ['GET', 'POST'];

/** @var \Users_Record_Model User record model. */
public $recordModel;

/**
* Check permission to method, access for administrators only.
*
* @throws \Api\Core\Exception
*
* @return bool
*/
/** {@inheritdoc} */
protected function checkPermission(): void
{
parent::checkPermission();
if ($this->controller->request->isEmpty('record', true) || !\App\User::isExists($this->controller->request->getInteger('record'), false)) {
throw new \Api\Core\Exception('User doesn\'t exist', 404);
}
if (!\App\User::getCurrentUserModel()->isAdmin()) {
throw new \Api\Core\Exception('Access denied, access for administrators only', 403);
$moduleName = $this->controller->request->getModule();
if ('POST' === $this->controller->method) {
$this->recordModel = \Users_Record_Model::getCleanInstance($moduleName);
if (!$this->recordModel->isCreateable()) {
throw new \Api\Core\Exception('No permissions to create user', 403);
}
} else {
if ($this->controller->request->isEmpty('record', true) || !\App\User::isExists($this->controller->request->getInteger('record'), false)) {
throw new \Api\Core\Exception('User doesn\'t exist', 404);
}
if (!\App\User::getCurrentUserModel()->isAdmin()) {
throw new \Api\Core\Exception('Access denied, access for administrators only', 403);
}
$this->recordModel = \Users_Record_Model::getInstanceById($this->controller->request->getInteger('record'), 'Users');
}
$this->recordModel = \Users_Record_Model::getInstanceById($this->controller->request->getInteger('record'), 'Users');
}

/**
* Get user detail.
*
* @api
*
* @return array
*
* @OA\Get(
Expand All @@ -54,6 +59,7 @@ protected function checkPermission(): void
* summary="Data for the user",
* tags={"Users"},
* security={{"basicAuth" : {}, "ApiKeyAuth" : {}, "token" : {}}},
* operationId="getUser",
* @OA\Parameter(
* name="userId",
* description="User id",
Expand Down Expand Up @@ -146,4 +152,88 @@ public function get(): array
}
return $response;
}

/**
* Create record.
*
* @api
*
* @return array
*
* @OA\Post(
* path="/webservice/WebserviceStandard/Users/Record",
* description="Create new user",
* summary="Create user",
* tags={"Users"},
* security={{"basicAuth" : {}, "ApiKeyAuth" : {}, "token" : {}}},
* @OA\RequestBody(required=true, description="Contents of the request contains an associative array with the user data.",
* @OA\JsonContent(ref="#/components/schemas/User_Create_Details"),
* @OA\XmlContent(ref="#/components/schemas/User_Create_Details"),
* ),
* @OA\Parameter(name="X-ENCRYPTED", in="header", @OA\Schema(ref="#/components/schemas/Header-Encrypted"), required=true),
* @OA\Response(
* response=200, description="Contents of the response contains only id",
* @OA\JsonContent(ref="#/components/schemas/User_Post_Record_Response"),
* @OA\XmlContent(ref="#/components/schemas/User_Post_Record_Response"),
* @OA\Link(link="GetUserById", ref="#/components/links/GetUserById")
* ),
* @OA\Response(
* response=406, description="No input data",
* @OA\JsonContent(ref="#/components/schemas/Exception"),
* @OA\XmlContent(ref="#/components/schemas/Exception"),
* ),
* ),
* @OA\Schema(
* schema="User_Post_Record_Response",
* title="User - Created user",
* description="Contents of the response contains only id and name",
* type="object",
* required={"status", "result"},
* @OA\Property(property="status", type="integer", enum={0, 1}, description="A numeric value of 0 or 1 that indicates whether the communication is valid. 1 - success , 0 - error"),
* @OA\Property(property="result", type="object", title="User data", description="Created user id and name.",
* required={"id", "name"},
* @OA\Property(property="id", type="integer", description="Id of the newly created user", example=22),
* @OA\Property(property="name", type="string", description="Id of the newly created user", example="YetiForce Name"),
* @OA\Property(property="skippedData", type="object", description="List of parameters passed in the request that were skipped in the write process"),
* ),
* ),
* @OA\Schema(
* schema="User_Create_Details",
* title="General - User create details",
* description="User data in user format for create view",
* type="object",
* example={"user_name" : "tom", "first_name" : "Tom", "last_name" : "Kowalski", "roleid" : "H38", "password" : "MyFunP@ssword", "confirm_password" : "MyFunP@ssword", "email1" : "my@email.com", "language" : "en-US"},
* ),
* @OA\Link(
* link="GetUserById",
* description="The `id` value returned in the response can be used as the `userId` parameter in `GET /webservice/Users/Record/{userId}`.",
* operationId="getUser",
* parameters={
* "recordId" = "$response.body#/result/id"
* }
* )
*/
public function post(): array
{
if (1 !== $this->getUserData('type')) {
foreach ($this->recordModel->getModule()->getFieldsByType('serverAccess') as $fieldName => $fieldModel) {
if ($fieldModel->getFieldParams() == $this->getUserData('server_id')) {
$this->recordModel->set($fieldName, 1);
break;
}
}
}
\Api\WebserviceStandard\Fields::loadWebserviceFields($this->recordModel->getModule(), $this);
$saveModel = new \Api\WebserviceStandard\Save();
$saveModel->init($this);
$saveModel->saveRecord($this->controller->request);
$return = [
'id' => $this->recordModel->getId(),
'name' => $this->recordModel->getName(),
];
if ($saveModel->skippedData) {
$return['skippedData'] = $saveModel->skippedData;
}
return $return;
}
}
12 changes: 10 additions & 2 deletions api/webservice/WebserviceStandard/Users/RecordsList.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* @package API
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
* @author Radosław Skrzypczak <r.skrzypczak@yetiforce.com>
*/
Expand Down Expand Up @@ -37,6 +37,8 @@ class RecordsList extends \Api\Core\BaseAction
/**
* Get users list method.
*
* @api
*
* @return array
*
* @OA\Get(
Expand Down Expand Up @@ -250,6 +252,12 @@ protected function getColumnNames(): array
*/
protected function getRawDataFromRow(array $row): array
{
foreach ($this->fields as $fieldName => $fieldModel) {
if (\array_key_exists($fieldName, $row)) {
$row[$fieldName] = $fieldModel->getUITypeModel()->getRawValue($row[$fieldName]);
}
}

return $row;
}
}
8 changes: 6 additions & 2 deletions api/webservice/WebserviceStandard/Users/ResetPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* @package API
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
*/

Expand Down Expand Up @@ -36,6 +36,8 @@ protected function checkPermissionToModule(): void
/**
* Post method.
*
* @api
*
* @return bool
*
* @OA\Post(
Expand Down Expand Up @@ -138,6 +140,8 @@ public function post(): array
/**
* Put method.
*
* @api
*
* @return bool
*
* @OA\Put(
Expand Down
10 changes: 8 additions & 2 deletions api/webservice/WebserviceStandard/Users/TwoFactorAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* @package API
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
*/

Expand All @@ -31,6 +31,8 @@ protected function checkPermissionToModule(): void
/**
* Get two factor authentication details.
*
* @api
*
* @return array
*
* @OA\Get(
Expand Down Expand Up @@ -99,6 +101,8 @@ public function get(): array
/**
* Post method.
*
* @api
*
* @throws \Api\Core\Exception
*
* @return array
Expand Down Expand Up @@ -175,6 +179,8 @@ public function post(): string
/**
* Delete record.
*
* @api
*
* @return bool
*
* @OA\Delete(
Expand Down
6 changes: 3 additions & 3 deletions app/Anonymization.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* @package App
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
* @author Radosław Skrzypczak <r.skrzypczak@yetiforce.com>
*/
Expand Down Expand Up @@ -42,7 +42,7 @@ public static function getTypes(): array
* @var array Word map for anonymization.
*/
const MAPS = [
'password' => ['pass', 'password', 'oldPassword'],
'password' => ['pass', 'password', 'oldPassword', 'retype_password', 'db_password'],
];
/**
* @var string Map name
Expand Down
18 changes: 9 additions & 9 deletions app/AutoAssign.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
*
* @package App
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Radosław Skrzypczak <r.skrzypczak@yetiforce.com>
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
*/
Expand Down Expand Up @@ -40,9 +40,9 @@ class AutoAssign extends Base
public const MODE_WORKFLOW = 4;

/** @var int Load balance method */
private const METHOD_LOAD_BALANCE = 0;
public const METHOD_LOAD_BALANCE = 0;
/** @var int Round robin method */
private const METHOD_ROUND_ROBIN = 1;
public const METHOD_ROUND_ROBIN = 1;

/**
* Get all auto assign entries for module.
Expand Down Expand Up @@ -207,14 +207,14 @@ public function isActive(int $mode): bool
*
* @return int
*/
public function getOwner(): int
public function getOwner(): ?int
{
switch ($this->get('method')) {
case self::METHOD_LOAD_BALANCE:
$owner = $this->getQueryByLoadBalance()->scalar();
$owner = $this->getQueryByLoadBalance()->scalar() ?: null;
break;
case self::METHOD_ROUND_ROBIN:
$owner = $this->getQueryByRoundRobin()->scalar();
$owner = $this->getQueryByRoundRobin()->scalar() ?: null;
break;
default:
$owner = null;
Expand All @@ -239,7 +239,7 @@ public function getOwners(): array
$owner = $this->getQueryByRoundRobin()->all();
break;
default:
$owner = [];
$owner = [];
break;
}

Expand Down Expand Up @@ -417,7 +417,7 @@ public function postProcess(int $userId)
$isExists = (new Db\Query())->from(self::ROUND_ROBIN_TABLE)->where($params)->exists();
if ($isExists) {
$dbCommand->update(self::ROUND_ROBIN_TABLE, ['datetime' => (new \DateTime())->format('Y-m-d H:i:s.u')], $params)->execute();
} else {
} elseif (\App\User::isExists($userId, false)) {
$params['datetime'] = (new \DateTime())->format('Y-m-d H:i:s.u');
$dbCommand->insert(self::ROUND_ROBIN_TABLE, $params)->execute();
}
Expand Down
4 changes: 2 additions & 2 deletions app/Automatic/RecordFlowUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* @package App
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Arkadiusz Adach <a.adach@yetiforce.com>
*/

Expand Down
4 changes: 2 additions & 2 deletions app/Automatic/Rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* @package App
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Arkadiusz Adach <a.adach@yetiforce.com>
*/

Expand Down
4 changes: 2 additions & 2 deletions app/Automatic/RulesPicklist.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* @package App
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Arkadiusz Adach <a.adach@yetiforce.com>
*/

Expand Down
4 changes: 2 additions & 2 deletions app/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* @package App
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
*/

Expand Down
4 changes: 2 additions & 2 deletions app/BatchMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* @package App
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Radosław Skrzypczak <r.skrzypczak@yetiforce.com>
*/

Expand Down
22 changes: 11 additions & 11 deletions app/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* @package App
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
* @author Radosław Skrzypczak <r.skrzypczak@yetiforce.com>
*/
Expand Down Expand Up @@ -58,7 +58,7 @@ public static function init()
*
* @return mixed
*/
public static function get($nameSpace, $key)
public static function get(string $nameSpace, string $key)
{
return static::$pool->get("$nameSpace-$key");
}
Expand All @@ -71,7 +71,7 @@ public static function get($nameSpace, $key)
*
* @return bool
*/
public static function has($nameSpace, $key): bool
public static function has(string $nameSpace, string $key): bool
{
return static::$pool->has("$nameSpace-$key");
}
Expand All @@ -86,7 +86,7 @@ public static function has($nameSpace, $key): bool
*
* @return bool
*/
public static function save($nameSpace, $key, $value = null, $duration = self::MEDIUM)
public static function save(string $nameSpace, string $key, $value = null, $duration = self::MEDIUM)
{
if (!static::$pool->save("$nameSpace-$key", $value, $duration)) {
Log::warning("Error writing to cache. Key: $nameSpace-$key | Value: " . var_export($value, true));
Expand All @@ -102,7 +102,7 @@ public static function save($nameSpace, $key, $value = null, $duration = self::M
*
* @return bool
*/
public static function delete($nameSpace, $key)
public static function delete(string $nameSpace, string $key)
{
static::$pool->delete("$nameSpace-$key");
}
Expand All @@ -125,7 +125,7 @@ public static function clear(): bool
*
* @return mixed
*/
public static function staticGet($nameSpace, $key)
public static function staticGet(string $nameSpace, string $key = '')
{
return static::$staticPool->get("$nameSpace-$key");
}
Expand All @@ -138,7 +138,7 @@ public static function staticGet($nameSpace, $key)
*
* @return bool
*/
public static function staticHas($nameSpace, $key = '')
public static function staticHas(string $nameSpace, string $key = '')
{
return static::$staticPool->has("$nameSpace-$key");
}
Expand All @@ -153,7 +153,7 @@ public static function staticHas($nameSpace, $key = '')
*
* @return bool
*/
public static function staticSave($nameSpace, $key, $value = null)
public static function staticSave(string $nameSpace, string $key, $value = null)
{
return static::$staticPool->save("$nameSpace-$key", $value);
}
Expand All @@ -166,7 +166,7 @@ public static function staticSave($nameSpace, $key, $value = null)
*
* @return bool
*/
public static function staticDelete($nameSpace, $key)
public static function staticDelete(string $nameSpace, string $key)
{
static::$staticPool->delete("$nameSpace-$key");
}
Expand Down Expand Up @@ -262,7 +262,7 @@ public static function clearTemporaryFiles(string $days = '-30 day'): array
}
foreach ([ROOT_DIRECTORY . '/cache', \App\Fields\File::getTmpPath()] as $dir) {
foreach ((new \DirectoryIterator($dir)) as $item) {
if ($item->isFile() && 'index.html' !== $item->getBasename()) {
if ($item->isFile() && 'index.html' !== $item->getBasename() && $item->getMTime() < $time && $item->getATime() < $time) {
$s += $item->getSize();
unlink($item->getPathname());
++$i;
Expand Down
4 changes: 2 additions & 2 deletions app/Cache/Apcu.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* @package App
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
*/

Expand Down
4 changes: 2 additions & 2 deletions app/Cache/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* @package App
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
* @author Radosław Skrzypczak <r.skrzypczak@yetiforce.com>
*/
Expand Down
4 changes: 2 additions & 2 deletions app/Cache/XCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* @package App
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
*/

Expand Down
10 changes: 4 additions & 6 deletions app/Chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*
* @package App
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Arkadiusz Adach <a.adach@yetiforce.com>
* @author Tomasz Poradzewski <t.poradzewski@yetiforce.com>
* @author Radosław Skrzypczak <r.skrzypczak@yetiforce.com>
Expand Down Expand Up @@ -142,7 +142,7 @@ public static function setCurrentRoomDefault()
/**
* Get current room ID, type.
*
* @return []|false
* @return array|false
*/
public static function getCurrentRoom()
{
Expand Down Expand Up @@ -698,9 +698,7 @@ public static function getNumberOfNewMessages(?array $roomInfo = null): array
}
}

$lastMessage = 1 === \count($lastMessagesData) ? current($lastMessagesData) : array_reduce($lastMessagesData, function ($a, $b) {
return $a['created'] > $b['created'] ? $a : $b;
});
$lastMessage = 1 === \count($lastMessagesData) ? current($lastMessagesData) : array_reduce($lastMessagesData, fn ($a, $b) => $a['created'] > $b['created'] ? $a : $b);
if (!empty($lastMessage)) {
$lastMessage['messages'] = static::decodeNoHtmlMessage($lastMessage['messages'], false);
$lastMessage['userData'] = static::getUserInfo($lastMessage['userid']);
Expand Down
6 changes: 3 additions & 3 deletions app/Cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* @package App
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
*/

Expand Down Expand Up @@ -67,7 +67,7 @@ public function exec($command, $full = false)
$this->climate->white('Version: ' . Version::get() . ' | CRM URL: ' . \Config\Main::$site_URL);
$this->climate->lightGreen()->border('─', 200);
\App\User::setCurrentUserId(\Users::getActiveAdminId());
\App\Language::setTemporaryLanguage('en_US');
\App\Language::setTemporaryLanguage('en-US');

$this->climate->arguments->add([
'module' => [
Expand Down
6 changes: 3 additions & 3 deletions app/Cli/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
/**
* Base cli file.
*
* @package App
* @package Cli
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
*/

Expand Down
6 changes: 3 additions & 3 deletions app/Cli/Cleaner.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
/**
* Cleaner cli file.
*
* @package App
* @package Cli
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
*/

Expand Down
16 changes: 6 additions & 10 deletions app/Cli/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
/**
* Environment cli file.
*
* @package App
* @package Cli
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
*/

Expand Down Expand Up @@ -81,7 +81,7 @@ public function confReportAll(): void
$value = \is_array($value) ? \App\Json::encode($value) : $value;
$table[] = [
'Parameter' => $item['status'] ? $name : "<light_red>{$name}</light_red>",
'Recommended' => $item['recommended'] ? print_r($item['recommended'], true) : '-',
'Recommended' => empty($item['recommended']) ? '-' : print_r($item['recommended'], true),
'Value' => $item['status'] ? $value : ("<light_red>{$value}</light_red>"),
];
}
Expand All @@ -104,14 +104,10 @@ public function confReportAll(): void
public function htmlToText(array &$item): void
{
if (false !== strpos($item['val'], '<b class="text-danger">')) {
$item['val'] = preg_replace_callback("'<b class=\"text-danger\">(.*?)</b>'si", function ($match) {
return "<light_red>{$match['1']}</light_red>";
}, $item['val']);
$item['val'] = preg_replace_callback("'<b class=\"text-danger\">(.*?)</b>'si", fn ($match) => "<light_red>{$match['1']}</light_red>", $item['val']);
}
if (false !== strpos($item['recommended'], '<b class="text-danger">')) {
$item['recommended'] = preg_replace_callback("'<b class=\"text-danger\">(.*?)</b>'si", function ($match) {
return "<light_red>{$match['1']}</light_red>";
}, $item['recommended']);
$item['recommended'] = preg_replace_callback("'<b class=\"text-danger\">(.*?)</b>'si", fn ($match) => "<light_red>{$match['1']}</light_red>", $item['recommended']);
}
}
}
70 changes: 70 additions & 0 deletions app/Cli/Roundcube.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php
/**
* Roundcube cli file.
*
* @package Cli
*
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
*/

namespace App\Cli;

/**
* Roundcube cli class.
*/
class Roundcube extends Base
{
/** {@inheritdoc} */
public $moduleName = 'Roundcube';

/** @var string[] Methods list */
public $methods = [
'clearUsersPreferences' => 'Clear users preferences',
'clearUsersCache' => 'Clear users cache',
'clearUsersSession' => 'Clear users session',
];

/**
* Clear users preferences.
*
* @return void
*/
public function clearUsersPreferences(): void
{
\App\Db::getInstance()->createCommand()->update('roundcube_users', ['preferences' => ''])->execute();
if (!$this->climate->arguments->defined('action')) {
$this->cli->actionsList('Roundcube');
}
}

/**
* Clear users cache.
*
* @return void
*/
public function clearUsersCache(): void
{
$createCommand = \App\Db::getInstance()->createCommand();
foreach (['roundcube_cache', 'roundcube_cache_index', 'roundcube_cache_messages', 'roundcube_cache_shared', 'roundcube_cache_thread'] as $table) {
$createCommand->truncateTable($table)->execute();
}
if (!$this->climate->arguments->defined('action')) {
$this->cli->actionsList('Roundcube');
}
}

/**
* Clear users session.
*
* @return void
*/
public function clearUsersSession(): void
{
\App\Db::getInstance()->createCommand()->truncateTable('roundcube_session')->execute();
if (!$this->climate->arguments->defined('action')) {
$this->cli->actionsList('Roundcube');
}
}
}
12 changes: 6 additions & 6 deletions app/Cli/System.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
/**
* System cli file.
*
* @package App
* @package Cli
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
*/

Expand Down Expand Up @@ -168,7 +168,7 @@ private function updateByPackage(array $package): void
if ($packageInstance->_errorText) {
$this->climate->lightRed($packageInstance->_errorText);
} else {
echo $response;
echo $response . PHP_EOL;
}
} catch (\Throwable $th) {
$this->climate->lightRed($th->__toString());
Expand All @@ -183,8 +183,8 @@ private function updateByPackage(array $package): void
*/
public function checkRegStatus(): void
{
$status = \App\YetiForce\Register::check(true);
$this->climate->bold('Status: ' . \App\Language::translate(\App\YetiForce\Register::STATUS_MESSAGES[$status], 'Settings::Companies'));
\App\YetiForce\Register::check(true);
$this->climate->bold('Status: ' . \App\Language::translate(\App\YetiForce\Register::STATUS_MESSAGES[\App\YetiForce\Register::getStatus()], 'Settings::Companies'));
$this->climate->border('─', 200);
$this->climate->bold('APP ID: ' . \App\YetiForce\Register::getInstanceKey());
$this->climate->border('─', 200);
Expand Down
6 changes: 3 additions & 3 deletions app/Cli/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
/**
* Users cli file.
*
* @package App
* @package Cli
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @copyright YetiForce S.A.
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
*/

Expand Down
Loading