Initial commit
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/***********************************************************************************
|
||||
* The contents of this file are subject to the Extension License Agreement
|
||||
* ("Agreement") which can be viewed at
|
||||
* https://www.espocrm.com/extension-license-agreement/.
|
||||
* By copying, installing downloading, or using this file, You have unconditionally
|
||||
* agreed to the terms and conditions of the Agreement, and You may not use this
|
||||
* file except in compliance with the Agreement. Under the terms of the Agreement,
|
||||
* You shall not license, sublicense, sell, resell, rent, lease, lend, distribute,
|
||||
* redistribute, market, publish, commercialize, or otherwise transfer rights or
|
||||
* usage to the software or any modified version or derivative work of the software
|
||||
* created by or for you.
|
||||
*
|
||||
* Copyright (C) 2015-2025 EspoCRM, Inc.
|
||||
*
|
||||
* License ID: 19bc86a68a7bb01f458cb391d43a9212
|
||||
************************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Advanced\Classes\Acl\BpmnFlowNode;
|
||||
|
||||
use Espo\Core\Acl\AccessChecker as AccessCheckerInterface;
|
||||
use Espo\Core\Acl\AccessReadChecker;
|
||||
use Espo\Core\Acl\ScopeData;
|
||||
use Espo\Core\AclManager;
|
||||
use Espo\Entities\User;
|
||||
use Espo\Modules\Advanced\Entities\BpmnProcess;
|
||||
|
||||
class AccessChecker implements AccessCheckerInterface, AccessReadChecker
|
||||
{
|
||||
private AclManager $aclManager;
|
||||
|
||||
public function __construct(AclManager $aclManager)
|
||||
{
|
||||
$this->aclManager = $aclManager;
|
||||
}
|
||||
|
||||
public function check(User $user, ScopeData $data): bool
|
||||
{
|
||||
return $this->aclManager->checkScope($user, BpmnProcess::ENTITY_TYPE);
|
||||
}
|
||||
|
||||
public function checkRead(User $user, ScopeData $data): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace Espo\Modules\Advanced\Classes\Acl\BpmnProcess;
|
||||
|
||||
use Espo\Core\Acl\DefaultOwnershipChecker;
|
||||
use Espo\Core\Acl\OwnershipOwnChecker;
|
||||
use Espo\Core\Acl\OwnershipTeamChecker;
|
||||
use Espo\Core\ORM\Entity as CoreEntity;
|
||||
use Espo\Entities\User;
|
||||
use Espo\Modules\Advanced\Entities\BpmnProcess;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\ORM\EntityManager;
|
||||
|
||||
/**
|
||||
* @implements OwnershipOwnChecker<BpmnProcess>
|
||||
* @implements OwnershipTeamChecker<BpmnProcess>
|
||||
*/
|
||||
class OwnershipChecker implements OwnershipOwnChecker, OwnershipTeamChecker
|
||||
{
|
||||
private DefaultOwnershipChecker $defaultOwnershipChecker;
|
||||
private EntityManager $entityManager;
|
||||
|
||||
public function __construct(
|
||||
DefaultOwnershipChecker $defaultOwnershipChecker,
|
||||
EntityManager $entityManager
|
||||
) {
|
||||
$this->defaultOwnershipChecker = $defaultOwnershipChecker;
|
||||
$this->entityManager = $entityManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param BpmnProcess $entity
|
||||
*/
|
||||
public function checkOwn(User $user, Entity $entity): bool
|
||||
{
|
||||
if (!$entity->getParentProcessId() || $entity->getParentProcessId() === $entity->getId()) {
|
||||
return $this->defaultOwnershipChecker->checkOwn($user, $entity);
|
||||
}
|
||||
|
||||
$parent = $this->entityManager->getEntityById(BpmnProcess::ENTITY_TYPE, $entity->getParentProcessId());
|
||||
|
||||
if (!$parent instanceof CoreEntity) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->defaultOwnershipChecker->checkOwn($user, $parent);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param BpmnProcess $entity
|
||||
*/
|
||||
public function checkTeam(User $user, Entity $entity): bool
|
||||
{
|
||||
if (!$entity->getParentProcessId() || $entity->getParentProcessId() === $entity->getId()) {
|
||||
return $this->defaultOwnershipChecker->checkTeam($user, $entity);
|
||||
}
|
||||
|
||||
$parent = $this->entityManager->getEntityById(BpmnProcess::ENTITY_TYPE, $entity->getParentProcessId());
|
||||
|
||||
if (!$parent instanceof CoreEntity) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->defaultOwnershipChecker->checkTeam($user, $parent);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/***********************************************************************************
|
||||
* The contents of this file are subject to the Extension License Agreement
|
||||
* ("Agreement") which can be viewed at
|
||||
* https://www.espocrm.com/extension-license-agreement/.
|
||||
* By copying, installing downloading, or using this file, You have unconditionally
|
||||
* agreed to the terms and conditions of the Agreement, and You may not use this
|
||||
* file except in compliance with the Agreement. Under the terms of the Agreement,
|
||||
* You shall not license, sublicense, sell, resell, rent, lease, lend, distribute,
|
||||
* redistribute, market, publish, commercialize, or otherwise transfer rights or
|
||||
* usage to the software or any modified version or derivative work of the software
|
||||
* created by or for you.
|
||||
*
|
||||
* Copyright (C) 2015-2025 EspoCRM, Inc.
|
||||
*
|
||||
* License ID: 19bc86a68a7bb01f458cb391d43a9212
|
||||
************************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Advanced\Classes\Acl\Report;
|
||||
|
||||
use Espo\Core\Acl\AccessEntityCREDChecker;
|
||||
use Espo\Core\Acl\DefaultAccessChecker;
|
||||
use Espo\Core\Acl\ScopeData;
|
||||
use Espo\Core\Acl\Traits\DefaultAccessCheckerDependency;
|
||||
use Espo\Core\AclManager;
|
||||
use Espo\Entities\User;
|
||||
use Espo\Modules\Advanced\Entities\Report;
|
||||
use Espo\ORM\Entity;
|
||||
|
||||
/**
|
||||
* @implements AccessEntityCREDChecker<Report>
|
||||
*/
|
||||
class AccessChecker implements AccessEntityCREDChecker
|
||||
{
|
||||
use DefaultAccessCheckerDependency;
|
||||
|
||||
private AclManager $aclManager;
|
||||
|
||||
public function __construct(
|
||||
DefaultAccessChecker $defaultAccessChecker,
|
||||
AclManager $aclManager
|
||||
) {
|
||||
$this->defaultAccessChecker = $defaultAccessChecker;
|
||||
$this->aclManager = $aclManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Report $entity
|
||||
*/
|
||||
public function checkEntityRead(User $user, Entity $entity, ScopeData $data): bool
|
||||
{
|
||||
if (
|
||||
$entity->getTargetEntityType() &&
|
||||
!$this->aclManager->checkScope($user, $entity->getTargetEntityType())
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->defaultAccessChecker->checkEntityRead($user, $entity, $data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Espo\Modules\Advanced\Classes\AclPortal\Report;
|
||||
|
||||
use Espo\Core\Acl\AccessEntityCREDChecker;
|
||||
use Espo\Core\Acl\ScopeData;
|
||||
use Espo\Core\Portal\Acl\DefaultAccessChecker;
|
||||
use Espo\Core\Portal\Acl\Traits\DefaultAccessCheckerDependency;
|
||||
use Espo\Entities\User;
|
||||
use Espo\Modules\Advanced\Entities\Report;
|
||||
use Espo\ORM\Entity;
|
||||
|
||||
/**
|
||||
* @implements AccessEntityCREDChecker<Report>
|
||||
*/
|
||||
class AccessChecker implements AccessEntityCREDChecker
|
||||
{
|
||||
use DefaultAccessCheckerDependency;
|
||||
|
||||
public function __construct(DefaultAccessChecker $defaultAccessChecker)
|
||||
{
|
||||
$this->defaultAccessChecker = $defaultAccessChecker;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Report $entity
|
||||
*/
|
||||
public function checkEntityRead(User $user, Entity $entity, ScopeData $data): bool
|
||||
{
|
||||
if (!$this->defaultAccessChecker->checkEntityRead($user, $entity, $data)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$user->getPortalId()) {
|
||||
$portalIdList = $user->getLinkMultipleIdList('portals');
|
||||
|
||||
return count(
|
||||
array_intersect($portalIdList, $entity->getPortals()->getIdList())
|
||||
) > 0;
|
||||
}
|
||||
|
||||
return in_array($user->getPortalId(), $entity->getPortals()->getIdList());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
/***********************************************************************************
|
||||
* The contents of this file are subject to the Extension License Agreement
|
||||
* ("Agreement") which can be viewed at
|
||||
* https://www.espocrm.com/extension-license-agreement/.
|
||||
* By copying, installing downloading, or using this file, You have unconditionally
|
||||
* agreed to the terms and conditions of the Agreement, and You may not use this
|
||||
* file except in compliance with the Agreement. Under the terms of the Agreement,
|
||||
* You shall not license, sublicense, sell, resell, rent, lease, lend, distribute,
|
||||
* redistribute, market, publish, commercialize, or otherwise transfer rights or
|
||||
* usage to the software or any modified version or derivative work of the software
|
||||
* created by or for you.
|
||||
*
|
||||
* Copyright (C) 2015-2025 EspoCRM, Inc.
|
||||
*
|
||||
* License ID: 19bc86a68a7bb01f458cb391d43a9212
|
||||
************************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Advanced\Classes\AppParams;
|
||||
|
||||
use Espo\Entities\User;
|
||||
use Espo\Modules\Advanced\Entities\Workflow;
|
||||
use Espo\ORM\EntityManager;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* @noinspection PhpUnused
|
||||
*/
|
||||
class ManualWorkflows
|
||||
{
|
||||
private EntityManager $entityManager;
|
||||
private User $user;
|
||||
|
||||
public function __construct(
|
||||
EntityManager $entityManager,
|
||||
User $user
|
||||
) {
|
||||
$this->entityManager = $entityManager;
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return stdClass
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
$data = (object) [];
|
||||
|
||||
$builder = $this->entityManager
|
||||
->getRDBRepositoryByClass(Workflow::class)
|
||||
->where([
|
||||
'type' => Workflow::TYPE_MANUAL,
|
||||
'isActive' => true,
|
||||
]);
|
||||
|
||||
if (!$this->user->isAdmin()) {
|
||||
$builder
|
||||
->distinct()
|
||||
->join('manualTeams')
|
||||
->where(['manualTeams.id' => $this->user->getTeamIdList()]);
|
||||
|
||||
$builder->where(['manualAccessRequired!=' => 'admin']);
|
||||
}
|
||||
|
||||
/** @var Workflow[] $workflows */
|
||||
$workflows = iterator_to_array($builder->find());
|
||||
|
||||
usort($workflows, function (Workflow $a, Workflow $b) {
|
||||
return strcmp($a->getManualLabel() ?? '', $b->getManualLabel() ?? '');
|
||||
});
|
||||
|
||||
foreach ($workflows as $workflow) {
|
||||
$entityType = $workflow->getTargetEntityType();
|
||||
|
||||
if (!property_exists($data, $entityType)) {
|
||||
$data->$entityType = [];
|
||||
}
|
||||
|
||||
$item = (object) [
|
||||
'id' => $workflow->getId(),
|
||||
'label' => $workflow->get('manualLabel'),
|
||||
'accessRequired' => $workflow->get('manualAccessRequired'),
|
||||
'elementType' => $workflow->get('manualElementType'),
|
||||
'dynamicLogic' => $workflow->get('manualDynamicLogic'),
|
||||
'confirmation' => $workflow->get('manualConfirmation'),
|
||||
'confirmationText' => $workflow->get('manualConfirmationText'),
|
||||
'style' => $workflow->get('manualStyle'),
|
||||
];
|
||||
|
||||
$data->$entityType[] = $item;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace Espo\Modules\Advanced\Classes\AssignmentNotificators;
|
||||
|
||||
use Espo\Core\Notification\AssignmentNotificator;
|
||||
use Espo\Core\Notification\AssignmentNotificator\Params;
|
||||
use Espo\Entities\Notification;
|
||||
use Espo\Entities\User;
|
||||
use Espo\Modules\Advanced\Entities\BpmnUserTask as BpmnUserTaskEntity;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\ORM\EntityManager;
|
||||
|
||||
/**
|
||||
* @implements AssignmentNotificator<BpmnUserTaskEntity>
|
||||
*/
|
||||
class BpmnUserTask implements AssignmentNotificator
|
||||
{
|
||||
private EntityManager $entityManager;
|
||||
private User $user;
|
||||
|
||||
public function __construct(EntityManager $entityManager, User $user)
|
||||
{
|
||||
$this->entityManager = $entityManager;
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
public function process(Entity $entity, Params $params): void
|
||||
{
|
||||
if (!$entity->get('assignedUserId')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$entity->isAttributeChanged('assignedUserId')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$assignedUserId = $entity->get('assignedUserId');
|
||||
|
||||
$isNotSelfAssignment = $entity->isNew() ?
|
||||
$assignedUserId !== $entity->get('createdById') :
|
||||
$assignedUserId !== $entity->get('modifiedById');
|
||||
|
||||
if (!$isNotSelfAssignment) {
|
||||
return;
|
||||
}
|
||||
|
||||
$notification = $this->entityManager->getNewEntity(Notification::ENTITY_TYPE);
|
||||
|
||||
$notification->set([
|
||||
'type' => Notification::TYPE_ASSIGN,
|
||||
'userId' => $assignedUserId,
|
||||
'data' => [
|
||||
'entityType' => $entity->getEntityType(),
|
||||
'entityId' => $entity->getId(),
|
||||
'entityName' => $entity->get('name'),
|
||||
'isNew' => $entity->isNew(),
|
||||
'userId' => $this->user->getId(),
|
||||
'userName' => $this->user->get('name')
|
||||
],
|
||||
]);
|
||||
|
||||
$this->entityManager->saveEntity($notification);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/***********************************************************************************
|
||||
* The contents of this file are subject to the Extension License Agreement
|
||||
* ("Agreement") which can be viewed at
|
||||
* https://www.espocrm.com/extension-license-agreement/.
|
||||
* By copying, installing downloading, or using this file, You have unconditionally
|
||||
* agreed to the terms and conditions of the Agreement, and You may not use this
|
||||
* file except in compliance with the Agreement. Under the terms of the Agreement,
|
||||
* You shall not license, sublicense, sell, resell, rent, lease, lend, distribute,
|
||||
* redistribute, market, publish, commercialize, or otherwise transfer rights or
|
||||
* usage to the software or any modified version or derivative work of the software
|
||||
* created by or for you.
|
||||
*
|
||||
* Copyright (C) 2015-2025 EspoCRM, Inc.
|
||||
*
|
||||
* License ID: 19bc86a68a7bb01f458cb391d43a9212
|
||||
************************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Advanced\Classes\FieldProcessing\BpmnFlowNode;
|
||||
|
||||
use Espo\Modules\Advanced\Entities\BpmnUserTask;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\Core\FieldProcessing\Loader;
|
||||
use Espo\Core\FieldProcessing\Loader\Params;
|
||||
use Espo\Core\ORM\EntityManager;
|
||||
|
||||
/**
|
||||
* @implements Loader<BpmnUserTask>
|
||||
*/
|
||||
class UserTaskLoader implements Loader
|
||||
{
|
||||
private EntityManager $entityManager;
|
||||
|
||||
public function __construct(EntityManager $entityManager)
|
||||
{
|
||||
$this->entityManager = $entityManager;
|
||||
}
|
||||
|
||||
public function process(Entity $entity, Params $params): void
|
||||
{
|
||||
if ($entity->getElementType() !== 'taskUser') {
|
||||
return;
|
||||
}
|
||||
|
||||
$userTask = $this->entityManager
|
||||
->getRDBRepository(BpmnUserTask::ENTITY_TYPE)
|
||||
->where(['flowNodeId' => $entity->getId()])
|
||||
->findOne();
|
||||
|
||||
if ($userTask) {
|
||||
$entity->set('userTaskId', $userTask->getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
/***********************************************************************************
|
||||
* The contents of this file are subject to the Extension License Agreement
|
||||
* ("Agreement") which can be viewed at
|
||||
* https://www.espocrm.com/extension-license-agreement/.
|
||||
* By copying, installing downloading, or using this file, You have unconditionally
|
||||
* agreed to the terms and conditions of the Agreement, and You may not use this
|
||||
* file except in compliance with the Agreement. Under the terms of the Agreement,
|
||||
* You shall not license, sublicense, sell, resell, rent, lease, lend, distribute,
|
||||
* redistribute, market, publish, commercialize, or otherwise transfer rights or
|
||||
* usage to the software or any modified version or derivative work of the software
|
||||
* created by or for you.
|
||||
*
|
||||
* Copyright (C) 2015-2025 EspoCRM, Inc.
|
||||
*
|
||||
* License ID: 19bc86a68a7bb01f458cb391d43a9212
|
||||
************************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Advanced\Classes\FieldProcessing\BpmnProcess;
|
||||
|
||||
use Espo\Core\FieldProcessing\Loader;
|
||||
use Espo\Core\FieldProcessing\Loader\Params;
|
||||
use Espo\Modules\Advanced\Entities\BpmnFlowNode;
|
||||
use Espo\Modules\Advanced\Entities\BpmnProcess;
|
||||
use Espo\ORM\Collection;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\ORM\EntityManager;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* @implements Loader<BpmnProcess>
|
||||
*/
|
||||
class FlowchartDataLoader implements Loader
|
||||
{
|
||||
public function __construct(
|
||||
private EntityManager $entityManager
|
||||
) {}
|
||||
|
||||
public function process(Entity $entity, Params $params): void
|
||||
{
|
||||
$flowchartData = $entity->get('flowchartData') ?? (object) [];
|
||||
|
||||
$list = $flowchartData->list ?? [];
|
||||
|
||||
$flowNodes = $this->entityManager
|
||||
->getRDBRepositoryByClass(BpmnFlowNode::class)
|
||||
->where(['processId' => $entity->getId()])
|
||||
->order('number', true)
|
||||
->limit(0, 400)
|
||||
->find();
|
||||
|
||||
foreach ($list as $item) {
|
||||
$this->loadOutlineData($item, $flowNodes);
|
||||
}
|
||||
|
||||
$entity->set('flowchartData', $flowchartData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param stdClass $item
|
||||
* @param Collection<BpmnFlowNode> $flowNodeList
|
||||
*/
|
||||
private function loadOutlineData($item, $flowNodeList): void
|
||||
{
|
||||
$type = $item->type ?? null;
|
||||
$id = $item->id ?? null;
|
||||
|
||||
if (!$type || !$id) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($type === 'flow') {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($type === 'eventSubProcess' || $type === 'subProcess') {
|
||||
$list = $item->dataList ?? [];
|
||||
|
||||
foreach ($flowNodeList as $flowNode) {
|
||||
if ($flowNode->get('elementId') == $id) {
|
||||
$subProcessId = $flowNode->getDataItemValue('subProcessId');
|
||||
|
||||
$spFlowNodeList = $this->entityManager
|
||||
->getRDBRepositoryByClass(BpmnFlowNode::class)
|
||||
->where(['processId' => $subProcessId])
|
||||
->order('number', true)
|
||||
->limit(0, 400)
|
||||
->find();
|
||||
|
||||
foreach ($list as $spItem) {
|
||||
$this->loadOutlineData($spItem, $spFlowNodeList);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($flowNodeList as $flowNode) {
|
||||
$status = $flowNode->get('status');
|
||||
|
||||
if ($flowNode->get('elementId') == $id) {
|
||||
if ($status === BpmnFlowNode::STATUS_PROCESSED) {
|
||||
$item->outline = 3;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($flowNodeList as $flowNode) {
|
||||
$status = $flowNode->get('status');
|
||||
|
||||
if ($flowNode->get('elementId') == $id) {
|
||||
if ($status === BpmnFlowNode::STATUS_IN_PROCESS) {
|
||||
$item->outline = 1;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($flowNodeList as $flowNode) {
|
||||
$status = $flowNode->get('status');
|
||||
|
||||
if ($flowNode->get('elementId') == $id) {
|
||||
if ($status === BpmnFlowNode::STATUS_PENDING) {
|
||||
$item->outline = 2;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($flowNodeList as $flowNode) {
|
||||
$status = $flowNode->get('status');
|
||||
|
||||
if ($flowNode->get('elementId') == $id) {
|
||||
if (
|
||||
$status === BpmnFlowNode::STATUS_FAILED ||
|
||||
$status === BpmnFlowNode::STATUS_INTERRUPTED
|
||||
) {
|
||||
$item->outline = 4;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/***********************************************************************************
|
||||
* The contents of this file are subject to the Extension License Agreement
|
||||
* ("Agreement") which can be viewed at
|
||||
* https://www.espocrm.com/extension-license-agreement/.
|
||||
* By copying, installing downloading, or using this file, You have unconditionally
|
||||
* agreed to the terms and conditions of the Agreement, and You may not use this
|
||||
* file except in compliance with the Agreement. Under the terms of the Agreement,
|
||||
* You shall not license, sublicense, sell, resell, rent, lease, lend, distribute,
|
||||
* redistribute, market, publish, commercialize, or otherwise transfer rights or
|
||||
* usage to the software or any modified version or derivative work of the software
|
||||
* created by or for you.
|
||||
*
|
||||
* Copyright (C) 2015-2025 EspoCRM, Inc.
|
||||
*
|
||||
* License ID: 19bc86a68a7bb01f458cb391d43a9212
|
||||
************************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Advanced\Classes\FieldProcessing\Report;
|
||||
|
||||
use Espo\Core\FieldProcessing\Loader;
|
||||
use Espo\Core\FieldProcessing\Loader\Params;
|
||||
use Espo\Modules\Advanced\Entities\Report ;
|
||||
use Espo\ORM\Entity;
|
||||
|
||||
/**
|
||||
* @implements Loader<Report>
|
||||
*/
|
||||
class ChartOneLoader implements Loader
|
||||
{
|
||||
public function process(Entity $entity, Params $params): void
|
||||
{
|
||||
|
||||
$entity->set('chartOneColumns', []);
|
||||
$entity->set('chartOneY2Columns', []);
|
||||
|
||||
if ($entity->getType() === Report::TYPE_GRID) {
|
||||
$chartDataList = $entity->get('chartDataList');
|
||||
|
||||
if ($chartDataList && count($chartDataList)) {
|
||||
$y = $chartDataList[0]->columnList ?? null;
|
||||
$y2 = $chartDataList[0]->y2ColumnList ?? null;
|
||||
|
||||
$entity->set('chartOneColumns', $y);
|
||||
$entity->set('chartOneY2Columns', $y2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/***********************************************************************************
|
||||
* The contents of this file are subject to the Extension License Agreement
|
||||
* ("Agreement") which can be viewed at
|
||||
* https://www.espocrm.com/extension-license-agreement/.
|
||||
* By copying, installing downloading, or using this file, You have unconditionally
|
||||
* agreed to the terms and conditions of the Agreement, and You may not use this
|
||||
* file except in compliance with the Agreement. Under the terms of the Agreement,
|
||||
* You shall not license, sublicense, sell, resell, rent, lease, lend, distribute,
|
||||
* redistribute, market, publish, commercialize, or otherwise transfer rights or
|
||||
* usage to the software or any modified version or derivative work of the software
|
||||
* created by or for you.
|
||||
*
|
||||
* Copyright (C) 2015-2025 EspoCRM, Inc.
|
||||
*
|
||||
* License ID: 19bc86a68a7bb01f458cb391d43a9212
|
||||
************************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Advanced\Classes\FieldProcessing\Report;
|
||||
|
||||
use Espo\Core\Acl;
|
||||
use Espo\Core\Acl\Table;
|
||||
use Espo\Core\FieldProcessing\Loader;
|
||||
use Espo\Core\FieldProcessing\Loader\Params;
|
||||
use Espo\Modules\Advanced\Entities\Report;
|
||||
use Espo\ORM\Entity;
|
||||
|
||||
/**
|
||||
* @implements Loader<Report>
|
||||
*/
|
||||
class UnsetPortals implements Loader
|
||||
{
|
||||
private Acl $acl;
|
||||
|
||||
public function __construct(
|
||||
Acl $acl
|
||||
) {
|
||||
$this->acl = $acl;
|
||||
}
|
||||
|
||||
public function process(Entity $entity, Params $params): void
|
||||
{
|
||||
if ($this->acl->getPermissionLevel('portalPermission') !== Table::LEVEL_NO) {
|
||||
return;
|
||||
}
|
||||
|
||||
$entity->clear('portalsIds');
|
||||
$entity->clear('portalsNames');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
/***********************************************************************************
|
||||
* The contents of this file are subject to the Extension License Agreement
|
||||
* ("Agreement") which can be viewed at
|
||||
* https://www.espocrm.com/extension-license-agreement/.
|
||||
* By copying, installing downloading, or using this file, You have unconditionally
|
||||
* agreed to the terms and conditions of the Agreement, and You may not use this
|
||||
* file except in compliance with the Agreement. Under the terms of the Agreement,
|
||||
* You shall not license, sublicense, sell, resell, rent, lease, lend, distribute,
|
||||
* redistribute, market, publish, commercialize, or otherwise transfer rights or
|
||||
* usage to the software or any modified version or derivative work of the software
|
||||
* created by or for you.
|
||||
*
|
||||
* Copyright (C) 2015-2025 EspoCRM, Inc.
|
||||
*
|
||||
* License ID: 19bc86a68a7bb01f458cb391d43a9212
|
||||
************************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Advanced\Classes\FieldProcessing\ReportPanel;
|
||||
|
||||
use Espo\Core\Exceptions\Error;
|
||||
use Espo\Core\Exceptions\Forbidden;
|
||||
use Espo\Core\FieldProcessing\Loader;
|
||||
use Espo\Core\FieldProcessing\Loader\Params;
|
||||
use Espo\Modules\Advanced\Entities\Report as ReportEntity;
|
||||
use Espo\Modules\Advanced\Entities\ReportPanel;
|
||||
use Espo\Modules\Advanced\Tools\Report\GridType\Helper;
|
||||
use Espo\Modules\Advanced\Tools\Report\ReportHelper;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\ORM\EntityManager;
|
||||
|
||||
/**
|
||||
* @implements Loader<ReportPanel>
|
||||
*/
|
||||
class Additional implements Loader
|
||||
{
|
||||
public function __construct(
|
||||
private Helper $helper,
|
||||
private EntityManager $entityManager,
|
||||
private ReportHelper $reportHelper
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @throws Forbidden
|
||||
* @throws Error
|
||||
*/
|
||||
public function process(Entity $entity, Params $params): void
|
||||
{
|
||||
if (
|
||||
$entity->get('reportType') === ReportEntity::TYPE_GRID &&
|
||||
$entity->get('reportId')
|
||||
) {
|
||||
/** @var ?ReportEntity $report */
|
||||
$report = $this->entityManager->getEntityById(ReportEntity::ENTITY_TYPE, $entity->get('reportId'));
|
||||
|
||||
if ($report) {
|
||||
$columnList = $report->getColumns();
|
||||
|
||||
$numericColumnList = [];
|
||||
|
||||
$gridData = $this->reportHelper->fetchGridDataFromReport($report);
|
||||
|
||||
foreach ($columnList as $column) {
|
||||
if ($this->helper->isColumnNumeric($column, $gridData)) {
|
||||
$numericColumnList[] = $column;
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
(
|
||||
count($report->getGroupBy()) === 1 ||
|
||||
count($report->getGroupBy()) === 0
|
||||
) &&
|
||||
count($numericColumnList) > 1
|
||||
) {
|
||||
array_unshift($numericColumnList, '');
|
||||
}
|
||||
|
||||
$entity->set('columnList', $numericColumnList);
|
||||
}
|
||||
|
||||
$entity->set('columnsData', $report->getColumnsData());
|
||||
}
|
||||
|
||||
$displayType = $entity->get('displayType');
|
||||
$reportType = $entity->get('reportType');
|
||||
$displayTotal = $entity->get('displayTotal');
|
||||
$displayOnlyTotal = $entity->get('displayOnlyTotal');
|
||||
|
||||
if (!$displayType) {
|
||||
if (
|
||||
$reportType === ReportEntity::TYPE_GRID ||
|
||||
$reportType === ReportEntity::TYPE_JOINT_GRID
|
||||
) {
|
||||
if ($displayOnlyTotal) {
|
||||
$displayType = 'Total';
|
||||
}
|
||||
else if ($displayTotal) {
|
||||
$displayType = 'Chart-Total';
|
||||
}
|
||||
else {
|
||||
$displayType = 'Chart';
|
||||
}
|
||||
}
|
||||
else if ($reportType === ReportEntity::TYPE_LIST) {
|
||||
if ($displayOnlyTotal) {
|
||||
$displayType = 'Total';
|
||||
}
|
||||
else {
|
||||
$displayType = 'List';
|
||||
}
|
||||
}
|
||||
|
||||
$entity->set('displayType', $displayType);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/***********************************************************************************
|
||||
* The contents of this file are subject to the Extension License Agreement
|
||||
* ("Agreement") which can be viewed at
|
||||
* https://www.espocrm.com/extension-license-agreement/.
|
||||
* By copying, installing downloading, or using this file, You have unconditionally
|
||||
* agreed to the terms and conditions of the Agreement, and You may not use this
|
||||
* file except in compliance with the Agreement. Under the terms of the Agreement,
|
||||
* You shall not license, sublicense, sell, resell, rent, lease, lend, distribute,
|
||||
* redistribute, market, publish, commercialize, or otherwise transfer rights or
|
||||
* usage to the software or any modified version or derivative work of the software
|
||||
* created by or for you.
|
||||
*
|
||||
* Copyright (C) 2015-2025 EspoCRM, Inc.
|
||||
*
|
||||
* License ID: 19bc86a68a7bb01f458cb391d43a9212
|
||||
************************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Advanced\Classes\FieldValidators\Workflow\Scheduling;
|
||||
|
||||
use Cron\CronExpression;
|
||||
use Espo\Core\FieldValidation\Validator;
|
||||
use Espo\Core\FieldValidation\Validator\Data;
|
||||
use Espo\Core\FieldValidation\Validator\Failure;
|
||||
use Espo\Modules\Advanced\Entities\Workflow;
|
||||
use Espo\ORM\Entity;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* @implements Validator<Workflow>
|
||||
*/
|
||||
class Valid implements Validator
|
||||
{
|
||||
|
||||
public function validate(Entity $entity, string $field, Data $data): ?Failure
|
||||
{
|
||||
$scheduling = $entity->getScheduling();
|
||||
|
||||
if ($scheduling === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
new CronExpression($scheduling);
|
||||
} catch (Exception) {
|
||||
return Failure::create();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/***********************************************************************************
|
||||
* The contents of this file are subject to the Extension License Agreement
|
||||
* ("Agreement") which can be viewed at
|
||||
* https://www.espocrm.com/extension-license-agreement/.
|
||||
* By copying, installing downloading, or using this file, You have unconditionally
|
||||
* agreed to the terms and conditions of the Agreement, and You may not use this
|
||||
* file except in compliance with the Agreement. Under the terms of the Agreement,
|
||||
* You shall not license, sublicense, sell, resell, rent, lease, lend, distribute,
|
||||
* redistribute, market, publish, commercialize, or otherwise transfer rights or
|
||||
* usage to the software or any modified version or derivative work of the software
|
||||
* created by or for you.
|
||||
*
|
||||
* Copyright (C) 2015-2025 EspoCRM, Inc.
|
||||
*
|
||||
* License ID: 19bc86a68a7bb01f458cb391d43a9212
|
||||
************************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Advanced\Classes\RecordHooks\BpmnProcess;
|
||||
|
||||
use Espo\Core\Record\Hook\UpdateHook;
|
||||
use Espo\Core\Record\UpdateParams;
|
||||
use Espo\Modules\Advanced\Entities\BpmnProcess;
|
||||
use Espo\ORM\Entity;
|
||||
|
||||
/**
|
||||
* @implements UpdateHook<BpmnProcess>
|
||||
*/
|
||||
class BeforeUpdate implements UpdateHook
|
||||
{
|
||||
public function process(Entity $entity, UpdateParams $params): void
|
||||
{
|
||||
$entity->clear('flowchartId');
|
||||
$entity->clear('targetId');
|
||||
$entity->clear('targetType');
|
||||
$entity->clear('startElementId');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/***********************************************************************************
|
||||
* The contents of this file are subject to the Extension License Agreement
|
||||
* ("Agreement") which can be viewed at
|
||||
* https://www.espocrm.com/extension-license-agreement/.
|
||||
* By copying, installing downloading, or using this file, You have unconditionally
|
||||
* agreed to the terms and conditions of the Agreement, and You may not use this
|
||||
* file except in compliance with the Agreement. Under the terms of the Agreement,
|
||||
* You shall not license, sublicense, sell, resell, rent, lease, lend, distribute,
|
||||
* redistribute, market, publish, commercialize, or otherwise transfer rights or
|
||||
* usage to the software or any modified version or derivative work of the software
|
||||
* created by or for you.
|
||||
*
|
||||
* Copyright (C) 2015-2025 EspoCRM, Inc.
|
||||
*
|
||||
* License ID: 19bc86a68a7bb01f458cb391d43a9212
|
||||
************************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Advanced\Classes\RecordHooks\BpmnUserTask;
|
||||
|
||||
use Espo\Core\Exceptions\Forbidden;
|
||||
use Espo\Core\Record\Hook\UpdateHook;
|
||||
use Espo\Core\Record\UpdateParams;
|
||||
use Espo\Entities\User;
|
||||
use Espo\Modules\Advanced\Entities\BpmnUserTask;
|
||||
use Espo\ORM\Entity;
|
||||
|
||||
/**
|
||||
* @implements UpdateHook<BpmnUserTask>
|
||||
*/
|
||||
class BeforeUpdate implements UpdateHook
|
||||
{
|
||||
private User $user;
|
||||
|
||||
public function __construct(
|
||||
User $user
|
||||
) {
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
public function process(Entity $entity, UpdateParams $params): void
|
||||
{
|
||||
if (!$this->user->isAdmin()) {
|
||||
if ($entity->getFetched('isResolved') && $entity->isAttributeChanged('resolution')) {
|
||||
throw new Forbidden("Can't change resolution. Already resolved.");
|
||||
}
|
||||
|
||||
if ($entity->getFetched('isCanceled') && $entity->isAttributeChanged('resolution')) {
|
||||
throw new Forbidden("Can't change resolution. Already canceled.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
/***********************************************************************************
|
||||
* The contents of this file are subject to the Extension License Agreement
|
||||
* ("Agreement") which can be viewed at
|
||||
* https://www.espocrm.com/extension-license-agreement/.
|
||||
* By copying, installing downloading, or using this file, You have unconditionally
|
||||
* agreed to the terms and conditions of the Agreement, and You may not use this
|
||||
* file except in compliance with the Agreement. Under the terms of the Agreement,
|
||||
* You shall not license, sublicense, sell, resell, rent, lease, lend, distribute,
|
||||
* redistribute, market, publish, commercialize, or otherwise transfer rights or
|
||||
* usage to the software or any modified version or derivative work of the software
|
||||
* created by or for you.
|
||||
*
|
||||
* Copyright (C) 2015-2025 EspoCRM, Inc.
|
||||
*
|
||||
* License ID: 19bc86a68a7bb01f458cb391d43a9212
|
||||
************************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Advanced\Classes\RecordHooks\Report;
|
||||
|
||||
use Espo\Core\Acl;
|
||||
use Espo\Core\Acl\Table;
|
||||
use Espo\Core\Exceptions\BadRequest;
|
||||
use Espo\Core\Exceptions\Forbidden;
|
||||
use Espo\Core\Record\CreateParams;
|
||||
use Espo\Core\Record\Hook\CreateHook;
|
||||
use Espo\Modules\Advanced\Entities\Report;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\ORM\EntityManager;
|
||||
|
||||
/**
|
||||
* @implements CreateHook<Report>
|
||||
*/
|
||||
class BeforeCreate implements CreateHook
|
||||
{
|
||||
private Acl $acl;
|
||||
private EntityManager $entityManager;
|
||||
|
||||
public function __construct(
|
||||
Acl $acl,
|
||||
EntityManager $entityManager
|
||||
) {
|
||||
$this->acl = $acl;
|
||||
$this->entityManager = $entityManager;
|
||||
}
|
||||
|
||||
public function process(Entity $entity, CreateParams $params): void
|
||||
{
|
||||
$this->processJointGridBeforeSave($entity);
|
||||
|
||||
if (
|
||||
in_array('applyAcl', $this->acl->getScopeForbiddenFieldList(Report::ENTITY_TYPE, Table::ACTION_EDIT))
|
||||
) {
|
||||
$entity->setApplyAcl();
|
||||
}
|
||||
|
||||
if (!$this->acl->check($entity->getTargetEntityType(), Table::ACTION_READ)) {
|
||||
throw new Forbidden("No 'read' access to target entity type.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws BadRequest
|
||||
* @throws Forbidden
|
||||
*/
|
||||
public function processJointGridBeforeSave(Report $entity): void
|
||||
{
|
||||
if ($entity->getType() !== Report::TYPE_JOINT_GRID) {
|
||||
return;
|
||||
}
|
||||
|
||||
$joinedReportDataList = $entity->get('joinedReportDataList');
|
||||
|
||||
if (!is_array($joinedReportDataList) || !count($joinedReportDataList)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$groupCount = 0;
|
||||
|
||||
foreach ($joinedReportDataList as $i => $item) {
|
||||
if (empty($item->id)) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
|
||||
/** @var ?Report $report */
|
||||
$report = $this->entityManager->getEntityById(Report::ENTITY_TYPE, $item->id);
|
||||
|
||||
if (!$report) {
|
||||
throw new Forbidden('Report not found.');
|
||||
}
|
||||
|
||||
if (!$this->acl->check($report->getTargetEntityType(), Table::ACTION_READ)) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
$groupBy = $report->getGroupBy();
|
||||
|
||||
if (
|
||||
count($groupBy) > 1 ||
|
||||
$report->getType() !== Report::TYPE_GRID
|
||||
) {
|
||||
throw new Forbidden("Sub-report $item->id is not supported in joint report.");
|
||||
}
|
||||
|
||||
if ($i === 0) {
|
||||
$groupCount = count($groupBy);
|
||||
|
||||
$entityType = $report->getTargetEntityType();
|
||||
$entity->set('entityType', $entityType);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($groupCount !== count($groupBy)) {
|
||||
throw new BadRequest("Sub-reports must have the same Group By number.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/***********************************************************************************
|
||||
* The contents of this file are subject to the Extension License Agreement
|
||||
* ("Agreement") which can be viewed at
|
||||
* https://www.espocrm.com/extension-license-agreement/.
|
||||
* By copying, installing downloading, or using this file, You have unconditionally
|
||||
* agreed to the terms and conditions of the Agreement, and You may not use this
|
||||
* file except in compliance with the Agreement. Under the terms of the Agreement,
|
||||
* You shall not license, sublicense, sell, resell, rent, lease, lend, distribute,
|
||||
* redistribute, market, publish, commercialize, or otherwise transfer rights or
|
||||
* usage to the software or any modified version or derivative work of the software
|
||||
* created by or for you.
|
||||
*
|
||||
* Copyright (C) 2015-2025 EspoCRM, Inc.
|
||||
*
|
||||
* License ID: 19bc86a68a7bb01f458cb391d43a9212
|
||||
************************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Advanced\Classes\RecordHooks\Report;
|
||||
|
||||
use Espo\Core\Record\Hook\UpdateHook;
|
||||
use Espo\Core\Record\UpdateParams;
|
||||
use Espo\Modules\Advanced\Entities\Report;
|
||||
use Espo\ORM\Entity;
|
||||
|
||||
/**
|
||||
* @implements UpdateHook<Report>
|
||||
*/
|
||||
class BeforeUpdate implements UpdateHook
|
||||
{
|
||||
private BeforeCreate $beforeCreate;
|
||||
|
||||
public function __construct(
|
||||
BeforeCreate $beforeCreate
|
||||
) {
|
||||
$this->beforeCreate = $beforeCreate;
|
||||
}
|
||||
|
||||
public function process(Entity $entity, UpdateParams $params): void
|
||||
{
|
||||
if ($entity->isAttributeChanged('type')) {
|
||||
$entity->set('type', $entity->getFetched('type'));
|
||||
}
|
||||
|
||||
if (
|
||||
$entity->getType() !== Report::TYPE_JOINT_GRID &&
|
||||
$entity->isAttributeChanged('entityType')
|
||||
) {
|
||||
$entity->set('entityType', $entity->getFetched('entityType'));
|
||||
}
|
||||
|
||||
$this->beforeCreate->processJointGridBeforeSave($entity);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/***********************************************************************************
|
||||
* The contents of this file are subject to the Extension License Agreement
|
||||
* ("Agreement") which can be viewed at
|
||||
* https://www.espocrm.com/extension-license-agreement/.
|
||||
* By copying, installing downloading, or using this file, You have unconditionally
|
||||
* agreed to the terms and conditions of the Agreement, and You may not use this
|
||||
* file except in compliance with the Agreement. Under the terms of the Agreement,
|
||||
* You shall not license, sublicense, sell, resell, rent, lease, lend, distribute,
|
||||
* redistribute, market, publish, commercialize, or otherwise transfer rights or
|
||||
* usage to the software or any modified version or derivative work of the software
|
||||
* created by or for you.
|
||||
*
|
||||
* Copyright (C) 2015-2025 EspoCRM, Inc.
|
||||
*
|
||||
* License ID: 19bc86a68a7bb01f458cb391d43a9212
|
||||
************************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Advanced\Classes\Select\BpmnFlowchart\PrimaryFilters;
|
||||
|
||||
use Espo\Core\Select\Primary\Filter;
|
||||
use Espo\ORM\Query\SelectBuilder as QueryBuilder;
|
||||
|
||||
class Active implements Filter
|
||||
{
|
||||
public function apply(QueryBuilder $queryBuilder): void
|
||||
{
|
||||
$queryBuilder->where(['isActive' => true]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/***********************************************************************************
|
||||
* The contents of this file are subject to the Extension License Agreement
|
||||
* ("Agreement") which can be viewed at
|
||||
* https://www.espocrm.com/extension-license-agreement/.
|
||||
* By copying, installing downloading, or using this file, You have unconditionally
|
||||
* agreed to the terms and conditions of the Agreement, and You may not use this
|
||||
* file except in compliance with the Agreement. Under the terms of the Agreement,
|
||||
* You shall not license, sublicense, sell, resell, rent, lease, lend, distribute,
|
||||
* redistribute, market, publish, commercialize, or otherwise transfer rights or
|
||||
* usage to the software or any modified version or derivative work of the software
|
||||
* created by or for you.
|
||||
*
|
||||
* Copyright (C) 2015-2025 EspoCRM, Inc.
|
||||
*
|
||||
* License ID: 19bc86a68a7bb01f458cb391d43a9212
|
||||
************************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Advanced\Classes\Select\BpmnFlowchart\PrimaryFilters;
|
||||
|
||||
use Espo\Core\Select\Primary\Filter;
|
||||
use Espo\ORM\Query\SelectBuilder as QueryBuilder;
|
||||
|
||||
class ActiveHasNoneStartEvent implements Filter
|
||||
{
|
||||
public function apply(QueryBuilder $queryBuilder): void
|
||||
{
|
||||
$queryBuilder->where([
|
||||
'isActive' => true,
|
||||
'hasNoneStartEvent' => true,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/***********************************************************************************
|
||||
* The contents of this file are subject to the Extension License Agreement
|
||||
* ("Agreement") which can be viewed at
|
||||
* https://www.espocrm.com/extension-license-agreement/.
|
||||
* By copying, installing downloading, or using this file, You have unconditionally
|
||||
* agreed to the terms and conditions of the Agreement, and You may not use this
|
||||
* file except in compliance with the Agreement. Under the terms of the Agreement,
|
||||
* You shall not license, sublicense, sell, resell, rent, lease, lend, distribute,
|
||||
* redistribute, market, publish, commercialize, or otherwise transfer rights or
|
||||
* usage to the software or any modified version or derivative work of the software
|
||||
* created by or for you.
|
||||
*
|
||||
* Copyright (C) 2015-2025 EspoCRM, Inc.
|
||||
*
|
||||
* License ID: 19bc86a68a7bb01f458cb391d43a9212
|
||||
************************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Advanced\Classes\Select\BpmnFlowchart\PrimaryFilters;
|
||||
|
||||
use Espo\Core\Select\Primary\Filter;
|
||||
use Espo\ORM\Query\SelectBuilder as QueryBuilder;
|
||||
|
||||
class IsManuallyStartable implements Filter
|
||||
{
|
||||
public function apply(QueryBuilder $queryBuilder): void
|
||||
{
|
||||
$queryBuilder->where(['isActive' => true]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/***********************************************************************************
|
||||
* The contents of this file are subject to the Extension License Agreement
|
||||
* ("Agreement") which can be viewed at
|
||||
* https://www.espocrm.com/extension-license-agreement/.
|
||||
* By copying, installing downloading, or using this file, You have unconditionally
|
||||
* agreed to the terms and conditions of the Agreement, and You may not use this
|
||||
* file except in compliance with the Agreement. Under the terms of the Agreement,
|
||||
* You shall not license, sublicense, sell, resell, rent, lease, lend, distribute,
|
||||
* redistribute, market, publish, commercialize, or otherwise transfer rights or
|
||||
* usage to the software or any modified version or derivative work of the software
|
||||
* created by or for you.
|
||||
*
|
||||
* Copyright (C) 2015-2025 EspoCRM, Inc.
|
||||
*
|
||||
* License ID: 19bc86a68a7bb01f458cb391d43a9212
|
||||
************************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Advanced\Classes\Select\BpmnProcess\AccessControlFilters;
|
||||
|
||||
use Espo\Core\Select\AccessControl\Filter;
|
||||
use Espo\ORM\Query\SelectBuilder as QueryBuilder;
|
||||
|
||||
class Mandatory implements Filter
|
||||
{
|
||||
public function apply(QueryBuilder $queryBuilder): void
|
||||
{
|
||||
$queryBuilder->where(['parentProcessId' => null]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/***********************************************************************************
|
||||
* The contents of this file are subject to the Extension License Agreement
|
||||
* ("Agreement") which can be viewed at
|
||||
* https://www.espocrm.com/extension-license-agreement/.
|
||||
* By copying, installing downloading, or using this file, You have unconditionally
|
||||
* agreed to the terms and conditions of the Agreement, and You may not use this
|
||||
* file except in compliance with the Agreement. Under the terms of the Agreement,
|
||||
* You shall not license, sublicense, sell, resell, rent, lease, lend, distribute,
|
||||
* redistribute, market, publish, commercialize, or otherwise transfer rights or
|
||||
* usage to the software or any modified version or derivative work of the software
|
||||
* created by or for you.
|
||||
*
|
||||
* Copyright (C) 2015-2025 EspoCRM, Inc.
|
||||
*
|
||||
* License ID: 19bc86a68a7bb01f458cb391d43a9212
|
||||
************************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Advanced\Classes\Select\BpmnProcess\PrimaryFilters;
|
||||
|
||||
use Espo\Core\Select\Primary\Filter;
|
||||
use Espo\Modules\Advanced\Entities\BpmnProcess as BpmnProcessEntity;
|
||||
use Espo\ORM\Query\SelectBuilder as QueryBuilder;
|
||||
|
||||
class Actual implements Filter
|
||||
{
|
||||
public function apply(QueryBuilder $queryBuilder): void
|
||||
{
|
||||
$queryBuilder->where([
|
||||
'status!=' => [
|
||||
BpmnProcessEntity::STATUS_ENDED,
|
||||
BpmnProcessEntity::STATUS_INTERRUPTED,
|
||||
BpmnProcessEntity::STATUS_STOPPED,
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/***********************************************************************************
|
||||
* The contents of this file are subject to the Extension License Agreement
|
||||
* ("Agreement") which can be viewed at
|
||||
* https://www.espocrm.com/extension-license-agreement/.
|
||||
* By copying, installing downloading, or using this file, You have unconditionally
|
||||
* agreed to the terms and conditions of the Agreement, and You may not use this
|
||||
* file except in compliance with the Agreement. Under the terms of the Agreement,
|
||||
* You shall not license, sublicense, sell, resell, rent, lease, lend, distribute,
|
||||
* redistribute, market, publish, commercialize, or otherwise transfer rights or
|
||||
* usage to the software or any modified version or derivative work of the software
|
||||
* created by or for you.
|
||||
*
|
||||
* Copyright (C) 2015-2025 EspoCRM, Inc.
|
||||
*
|
||||
* License ID: 19bc86a68a7bb01f458cb391d43a9212
|
||||
************************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Advanced\Classes\Select\BpmnProcess\PrimaryFilters;
|
||||
|
||||
use Espo\Core\Select\Primary\Filter;
|
||||
use Espo\Modules\Advanced\Entities\BpmnProcess as BpmnProcessEntity;
|
||||
use Espo\ORM\Query\SelectBuilder as QueryBuilder;
|
||||
|
||||
class Ended implements Filter
|
||||
{
|
||||
public function apply(QueryBuilder $queryBuilder): void
|
||||
{
|
||||
$queryBuilder->where(['status' => BpmnProcessEntity::STATUS_ENDED]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/***********************************************************************************
|
||||
* The contents of this file are subject to the Extension License Agreement
|
||||
* ("Agreement") which can be viewed at
|
||||
* https://www.espocrm.com/extension-license-agreement/.
|
||||
* By copying, installing downloading, or using this file, You have unconditionally
|
||||
* agreed to the terms and conditions of the Agreement, and You may not use this
|
||||
* file except in compliance with the Agreement. Under the terms of the Agreement,
|
||||
* You shall not license, sublicense, sell, resell, rent, lease, lend, distribute,
|
||||
* redistribute, market, publish, commercialize, or otherwise transfer rights or
|
||||
* usage to the software or any modified version or derivative work of the software
|
||||
* created by or for you.
|
||||
*
|
||||
* Copyright (C) 2015-2025 EspoCRM, Inc.
|
||||
*
|
||||
* License ID: 19bc86a68a7bb01f458cb391d43a9212
|
||||
************************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Advanced\Classes\Select\BpmnUserTask\PrimaryFilters;
|
||||
|
||||
use Espo\Core\Select\Primary\Filter;
|
||||
use Espo\ORM\Query\SelectBuilder as QueryBuilder;
|
||||
|
||||
class Actual implements Filter
|
||||
{
|
||||
public function apply(QueryBuilder $queryBuilder): void
|
||||
{
|
||||
$queryBuilder->where([
|
||||
'isResolved' => false,
|
||||
'isCanceled' => false,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/***********************************************************************************
|
||||
* The contents of this file are subject to the Extension License Agreement
|
||||
* ("Agreement") which can be viewed at
|
||||
* https://www.espocrm.com/extension-license-agreement/.
|
||||
* By copying, installing downloading, or using this file, You have unconditionally
|
||||
* agreed to the terms and conditions of the Agreement, and You may not use this
|
||||
* file except in compliance with the Agreement. Under the terms of the Agreement,
|
||||
* You shall not license, sublicense, sell, resell, rent, lease, lend, distribute,
|
||||
* redistribute, market, publish, commercialize, or otherwise transfer rights or
|
||||
* usage to the software or any modified version or derivative work of the software
|
||||
* created by or for you.
|
||||
*
|
||||
* Copyright (C) 2015-2025 EspoCRM, Inc.
|
||||
*
|
||||
* License ID: 19bc86a68a7bb01f458cb391d43a9212
|
||||
************************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Advanced\Classes\Select\BpmnUserTask\PrimaryFilters;
|
||||
|
||||
use Espo\Core\Select\Primary\Filter;
|
||||
use Espo\ORM\Query\SelectBuilder as QueryBuilder;
|
||||
|
||||
class Canceled implements Filter
|
||||
{
|
||||
public function apply(QueryBuilder $queryBuilder): void
|
||||
{
|
||||
$queryBuilder->where(['isCanceled' => true]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/***********************************************************************************
|
||||
* The contents of this file are subject to the Extension License Agreement
|
||||
* ("Agreement") which can be viewed at
|
||||
* https://www.espocrm.com/extension-license-agreement/.
|
||||
* By copying, installing downloading, or using this file, You have unconditionally
|
||||
* agreed to the terms and conditions of the Agreement, and You may not use this
|
||||
* file except in compliance with the Agreement. Under the terms of the Agreement,
|
||||
* You shall not license, sublicense, sell, resell, rent, lease, lend, distribute,
|
||||
* redistribute, market, publish, commercialize, or otherwise transfer rights or
|
||||
* usage to the software or any modified version or derivative work of the software
|
||||
* created by or for you.
|
||||
*
|
||||
* Copyright (C) 2015-2025 EspoCRM, Inc.
|
||||
*
|
||||
* License ID: 19bc86a68a7bb01f458cb391d43a9212
|
||||
************************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Advanced\Classes\Select\BpmnUserTask\PrimaryFilters;
|
||||
|
||||
use Espo\Core\Select\Primary\Filter;
|
||||
use Espo\ORM\Query\SelectBuilder as QueryBuilder;
|
||||
|
||||
class Resolved implements Filter
|
||||
{
|
||||
public function apply(QueryBuilder $queryBuilder): void
|
||||
{
|
||||
$queryBuilder->where(['isResolved' => true]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
/***********************************************************************************
|
||||
* The contents of this file are subject to the Extension License Agreement
|
||||
* ("Agreement") which can be viewed at
|
||||
* https://www.espocrm.com/extension-license-agreement/.
|
||||
* By copying, installing downloading, or using this file, You have unconditionally
|
||||
* agreed to the terms and conditions of the Agreement, and You may not use this
|
||||
* file except in compliance with the Agreement. Under the terms of the Agreement,
|
||||
* You shall not license, sublicense, sell, resell, rent, lease, lend, distribute,
|
||||
* redistribute, market, publish, commercialize, or otherwise transfer rights or
|
||||
* usage to the software or any modified version or derivative work of the software
|
||||
* created by or for you.
|
||||
*
|
||||
* Copyright (C) 2015-2025 EspoCRM, Inc.
|
||||
*
|
||||
* License ID: 19bc86a68a7bb01f458cb391d43a9212
|
||||
************************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Advanced\Classes\Select\Common\PrimaryFilters;
|
||||
|
||||
use Espo\Core\Exceptions\BadRequest;
|
||||
use Espo\Core\Exceptions\Error;
|
||||
use Espo\Core\Exceptions\Forbidden;
|
||||
use Espo\Core\Select\Primary\Filter;
|
||||
use Espo\Core\Utils\Metadata;
|
||||
use Espo\Entities\User;
|
||||
use Espo\Modules\Advanced\Entities\Report;
|
||||
use Espo\Modules\Advanced\Entities\ReportFilter as ReportFilterEntity;
|
||||
use Espo\Modules\Advanced\Tools\Report\Service;
|
||||
use Espo\ORM\EntityManager;
|
||||
use Espo\ORM\Query\SelectBuilder as QueryBuilder;
|
||||
use RuntimeException;
|
||||
|
||||
class ReportFilter implements Filter
|
||||
{
|
||||
public function __construct(
|
||||
private string $name,
|
||||
private string $entityType,
|
||||
private EntityManager $entityManager,
|
||||
private Metadata $metadata,
|
||||
private User $user,
|
||||
private Service $service
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @throws BadRequest
|
||||
* @throws Forbidden
|
||||
* @throws Error
|
||||
*/
|
||||
public function apply(QueryBuilder $queryBuilder): void
|
||||
{
|
||||
/** @var ?string $reportFilterId */
|
||||
$reportFilterId = $this->metadata
|
||||
->get(['entityDefs', $this->entityType, 'collection', 'filters', $this->name, 'id']);
|
||||
|
||||
if (!$reportFilterId) {
|
||||
throw new RuntimeException("Report Filter $reportFilterId error.");
|
||||
}
|
||||
|
||||
/** @var ?ReportFilterEntity $reportFilter */
|
||||
$reportFilter = $this->entityManager->getEntityById(ReportFilterEntity::ENTITY_TYPE, $reportFilterId);
|
||||
|
||||
if (!$reportFilter) {
|
||||
throw new RuntimeException("Report Filter $reportFilterId not found.");
|
||||
}
|
||||
|
||||
$teamIdList = $reportFilter->getLinkMultipleIdList('teams');
|
||||
|
||||
if (count($teamIdList) && !$this->user->isAdmin()) {
|
||||
$isInTeam = false;
|
||||
$userTeamIdList = $this->user->getLinkMultipleIdList('teams');
|
||||
|
||||
foreach ($userTeamIdList as $teamId) {
|
||||
if (in_array($teamId, $teamIdList)) {
|
||||
$isInTeam = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$isInTeam) {
|
||||
throw new Forbidden("Access denied to Report Filter $reportFilterId.");
|
||||
}
|
||||
}
|
||||
|
||||
$reportId = $reportFilter->get('reportId');
|
||||
|
||||
if (!$reportId) {
|
||||
throw new RuntimeException('Report Filter error. No report.');
|
||||
}
|
||||
|
||||
/** @var ?Report $report */
|
||||
$report = $this->entityManager->getEntityById(Report::ENTITY_TYPE, $reportId);
|
||||
|
||||
if (!$report) {
|
||||
throw new Error('Report Filter error. Report not found.');
|
||||
}
|
||||
|
||||
$query = $this->service
|
||||
->prepareSelectBuilder($report)
|
||||
->build();
|
||||
|
||||
foreach ($query->getLeftJoins() as $join) {
|
||||
$queryBuilder->leftJoin($join);
|
||||
}
|
||||
|
||||
foreach ($query->getJoins() as $join) {
|
||||
$queryBuilder->join($join);
|
||||
}
|
||||
|
||||
if ($query->getWhere()) {
|
||||
$queryBuilder->where($query->getWhere());
|
||||
}
|
||||
|
||||
if ($query->isDistinct()) {
|
||||
$queryBuilder->distinct();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/***********************************************************************************
|
||||
* The contents of this file are subject to the Extension License Agreement
|
||||
* ("Agreement") which can be viewed at
|
||||
* https://www.espocrm.com/extension-license-agreement/.
|
||||
* By copying, installing downloading, or using this file, You have unconditionally
|
||||
* agreed to the terms and conditions of the Agreement, and You may not use this
|
||||
* file except in compliance with the Agreement. Under the terms of the Agreement,
|
||||
* You shall not license, sublicense, sell, resell, rent, lease, lend, distribute,
|
||||
* redistribute, market, publish, commercialize, or otherwise transfer rights or
|
||||
* usage to the software or any modified version or derivative work of the software
|
||||
* created by or for you.
|
||||
*
|
||||
* Copyright (C) 2015-2025 EspoCRM, Inc.
|
||||
*
|
||||
* License ID: 19bc86a68a7bb01f458cb391d43a9212
|
||||
************************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Advanced\Classes\Select\Report\AccessControlFilters;
|
||||
|
||||
use Espo\Core\Acl\Table;
|
||||
use Espo\Core\AclManager;
|
||||
use Espo\Core\Select\AccessControl\Filter;
|
||||
use Espo\Core\Utils\Metadata;
|
||||
use Espo\Entities\User;
|
||||
use Espo\ORM\Query\SelectBuilder as QueryBuilder;
|
||||
|
||||
class Mandatory implements Filter
|
||||
{
|
||||
public function __construct(
|
||||
private User $user,
|
||||
private Metadata $metadata,
|
||||
private AclManager $aclManager
|
||||
) {}
|
||||
|
||||
public function apply(QueryBuilder $queryBuilder): void
|
||||
{
|
||||
if (!$this->user->getPortalId()) {
|
||||
$forbiddenEntityTypeList = [];
|
||||
|
||||
$scopes = $this->metadata->get('scopes', []);
|
||||
|
||||
foreach ($scopes as $scope => $defs) {
|
||||
if (empty($defs['entity'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($this->aclManager->checkScope($this->user, $scope, Table::ACTION_READ)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$forbiddenEntityTypeList[] = $scope;
|
||||
}
|
||||
|
||||
if ($forbiddenEntityTypeList !== []) {
|
||||
$queryBuilder->where(['entityType!=' => $forbiddenEntityTypeList]);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$queryBuilder
|
||||
->distinct()
|
||||
->leftJoin('portals', 'portalsAccess')
|
||||
->where(['portalsAccess.id' => $this->user->getPortalId()]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/***********************************************************************************
|
||||
* The contents of this file are subject to the Extension License Agreement
|
||||
* ("Agreement") which can be viewed at
|
||||
* https://www.espocrm.com/extension-license-agreement/.
|
||||
* By copying, installing downloading, or using this file, You have unconditionally
|
||||
* agreed to the terms and conditions of the Agreement, and You may not use this
|
||||
* file except in compliance with the Agreement. Under the terms of the Agreement,
|
||||
* You shall not license, sublicense, sell, resell, rent, lease, lend, distribute,
|
||||
* redistribute, market, publish, commercialize, or otherwise transfer rights or
|
||||
* usage to the software or any modified version or derivative work of the software
|
||||
* created by or for you.
|
||||
*
|
||||
* Copyright (C) 2015-2025 EspoCRM, Inc.
|
||||
*
|
||||
* License ID: 19bc86a68a7bb01f458cb391d43a9212
|
||||
************************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Advanced\Classes\Select\Report\PrimaryFilters;
|
||||
|
||||
use Espo\Core\Select\Primary\Filter;
|
||||
use Espo\Modules\Advanced\Entities\Report;
|
||||
use Espo\ORM\Query\SelectBuilder as QueryBuilder;
|
||||
|
||||
class GridType implements Filter
|
||||
{
|
||||
public function apply(QueryBuilder $queryBuilder): void
|
||||
{
|
||||
$queryBuilder->where(['type' => Report::TYPE_GRID]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/***********************************************************************************
|
||||
* The contents of this file are subject to the Extension License Agreement
|
||||
* ("Agreement") which can be viewed at
|
||||
* https://www.espocrm.com/extension-license-agreement/.
|
||||
* By copying, installing downloading, or using this file, You have unconditionally
|
||||
* agreed to the terms and conditions of the Agreement, and You may not use this
|
||||
* file except in compliance with the Agreement. Under the terms of the Agreement,
|
||||
* You shall not license, sublicense, sell, resell, rent, lease, lend, distribute,
|
||||
* redistribute, market, publish, commercialize, or otherwise transfer rights or
|
||||
* usage to the software or any modified version or derivative work of the software
|
||||
* created by or for you.
|
||||
*
|
||||
* Copyright (C) 2015-2025 EspoCRM, Inc.
|
||||
*
|
||||
* License ID: 19bc86a68a7bb01f458cb391d43a9212
|
||||
************************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Advanced\Classes\Select\Report\PrimaryFilters;
|
||||
|
||||
use Espo\Core\Select\Primary\Filter;
|
||||
use Espo\Modules\Advanced\Entities\Report;
|
||||
use Espo\Modules\Crm\Entities\Account;
|
||||
use Espo\ORM\Query\SelectBuilder as QueryBuilder;
|
||||
|
||||
class ListAccounts implements Filter
|
||||
{
|
||||
public function apply(QueryBuilder $queryBuilder): void
|
||||
{
|
||||
$queryBuilder->where([
|
||||
'type' => Report::TYPE_LIST,
|
||||
'entityType' => Account::ENTITY_TYPE,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/***********************************************************************************
|
||||
* The contents of this file are subject to the Extension License Agreement
|
||||
* ("Agreement") which can be viewed at
|
||||
* https://www.espocrm.com/extension-license-agreement/.
|
||||
* By copying, installing downloading, or using this file, You have unconditionally
|
||||
* agreed to the terms and conditions of the Agreement, and You may not use this
|
||||
* file except in compliance with the Agreement. Under the terms of the Agreement,
|
||||
* You shall not license, sublicense, sell, resell, rent, lease, lend, distribute,
|
||||
* redistribute, market, publish, commercialize, or otherwise transfer rights or
|
||||
* usage to the software or any modified version or derivative work of the software
|
||||
* created by or for you.
|
||||
*
|
||||
* Copyright (C) 2015-2025 EspoCRM, Inc.
|
||||
*
|
||||
* License ID: 19bc86a68a7bb01f458cb391d43a9212
|
||||
************************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Advanced\Classes\Select\Report\PrimaryFilters;
|
||||
|
||||
use Espo\Core\Select\Primary\Filter;
|
||||
use Espo\Modules\Advanced\Entities\Report;
|
||||
use Espo\Modules\Crm\Entities\Contact;
|
||||
use Espo\ORM\Query\SelectBuilder as QueryBuilder;
|
||||
|
||||
class ListContacts implements Filter
|
||||
{
|
||||
public function apply(QueryBuilder $queryBuilder): void
|
||||
{
|
||||
$queryBuilder->where([
|
||||
'type' => Report::TYPE_LIST,
|
||||
'entityType' => Contact::ENTITY_TYPE,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/***********************************************************************************
|
||||
* The contents of this file are subject to the Extension License Agreement
|
||||
* ("Agreement") which can be viewed at
|
||||
* https://www.espocrm.com/extension-license-agreement/.
|
||||
* By copying, installing downloading, or using this file, You have unconditionally
|
||||
* agreed to the terms and conditions of the Agreement, and You may not use this
|
||||
* file except in compliance with the Agreement. Under the terms of the Agreement,
|
||||
* You shall not license, sublicense, sell, resell, rent, lease, lend, distribute,
|
||||
* redistribute, market, publish, commercialize, or otherwise transfer rights or
|
||||
* usage to the software or any modified version or derivative work of the software
|
||||
* created by or for you.
|
||||
*
|
||||
* Copyright (C) 2015-2025 EspoCRM, Inc.
|
||||
*
|
||||
* License ID: 19bc86a68a7bb01f458cb391d43a9212
|
||||
************************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Advanced\Classes\Select\Report\PrimaryFilters;
|
||||
|
||||
use Espo\Core\Select\Primary\Filter;
|
||||
use Espo\Modules\Advanced\Entities\Report;
|
||||
use Espo\Modules\Crm\Entities\Lead;
|
||||
use Espo\ORM\Query\SelectBuilder as QueryBuilder;
|
||||
|
||||
class ListLeads implements Filter
|
||||
{
|
||||
public function apply(QueryBuilder $queryBuilder): void
|
||||
{
|
||||
$queryBuilder->where([
|
||||
'type' => Report::TYPE_LIST,
|
||||
'entityType' => Lead::ENTITY_TYPE,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
/***********************************************************************************
|
||||
* The contents of this file are subject to the Extension License Agreement
|
||||
* ("Agreement") which can be viewed at
|
||||
* https://www.espocrm.com/extension-license-agreement/.
|
||||
* By copying, installing downloading, or using this file, You have unconditionally
|
||||
* agreed to the terms and conditions of the Agreement, and You may not use this
|
||||
* file except in compliance with the Agreement. Under the terms of the Agreement,
|
||||
* You shall not license, sublicense, sell, resell, rent, lease, lend, distribute,
|
||||
* redistribute, market, publish, commercialize, or otherwise transfer rights or
|
||||
* usage to the software or any modified version or derivative work of the software
|
||||
* created by or for you.
|
||||
*
|
||||
* Copyright (C) 2015-2025 EspoCRM, Inc.
|
||||
*
|
||||
* License ID: 19bc86a68a7bb01f458cb391d43a9212
|
||||
************************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Advanced\Classes\Select\Report\PrimaryFilters;
|
||||
|
||||
use Espo\Core\Select\Primary\Filter;
|
||||
use Espo\Core\Templates\Entities\Company;
|
||||
use Espo\Core\Templates\Entities\Person;
|
||||
use Espo\Core\Utils\Metadata;
|
||||
use Espo\Entities\User;
|
||||
use Espo\Modules\Advanced\Entities\Report;
|
||||
use Espo\Modules\Crm\Entities\Account;
|
||||
use Espo\Modules\Crm\Entities\Contact;
|
||||
use Espo\Modules\Crm\Entities\Lead;
|
||||
use Espo\Modules\Crm\Entities\TargetList;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\ORM\Query\SelectBuilder as QueryBuilder;
|
||||
|
||||
class ListTargets implements Filter
|
||||
{
|
||||
private Metadata $metadata;
|
||||
|
||||
public function __construct(Metadata $metadata) {
|
||||
$this->metadata = $metadata;
|
||||
}
|
||||
|
||||
public function apply(QueryBuilder $queryBuilder): void
|
||||
{
|
||||
$entityTypeList = [
|
||||
Contact::ENTITY_TYPE,
|
||||
Lead::ENTITY_TYPE,
|
||||
User::ENTITY_TYPE,
|
||||
Account::ENTITY_TYPE,
|
||||
];
|
||||
|
||||
foreach ($this->metadata->get(['entityDefs', TargetList::ENTITY_TYPE, 'links']) as $defs) {
|
||||
$entityType = $defs['entity'] ?? null;
|
||||
$type = $defs['type'] ?? null;
|
||||
|
||||
if ($type !== Entity::HAS_MANY) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!$entityType) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (in_array($entityType, $entityTypeList)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$templateType = $this->metadata->get(['scopes', $entityType, 'type']);
|
||||
|
||||
if (
|
||||
$templateType !== Person::TEMPLATE_TYPE &&
|
||||
$templateType !== Company::TEMPLATE_TYPE
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$entityTypeList[] = $entityType;
|
||||
}
|
||||
|
||||
$queryBuilder->where([
|
||||
'type' => Report::TYPE_LIST,
|
||||
'entityType' => $entityTypeList,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/***********************************************************************************
|
||||
* The contents of this file are subject to the Extension License Agreement
|
||||
* ("Agreement") which can be viewed at
|
||||
* https://www.espocrm.com/extension-license-agreement/.
|
||||
* By copying, installing downloading, or using this file, You have unconditionally
|
||||
* agreed to the terms and conditions of the Agreement, and You may not use this
|
||||
* file except in compliance with the Agreement. Under the terms of the Agreement,
|
||||
* You shall not license, sublicense, sell, resell, rent, lease, lend, distribute,
|
||||
* redistribute, market, publish, commercialize, or otherwise transfer rights or
|
||||
* usage to the software or any modified version or derivative work of the software
|
||||
* created by or for you.
|
||||
*
|
||||
* Copyright (C) 2015-2025 EspoCRM, Inc.
|
||||
*
|
||||
* License ID: 19bc86a68a7bb01f458cb391d43a9212
|
||||
************************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Advanced\Classes\Select\Report\PrimaryFilters;
|
||||
|
||||
use Espo\Core\Select\Primary\Filter;
|
||||
use Espo\Modules\Advanced\Entities\Report;
|
||||
use Espo\ORM\Query\SelectBuilder as QueryBuilder;
|
||||
|
||||
class ListType implements Filter
|
||||
{
|
||||
public function apply(QueryBuilder $queryBuilder): void
|
||||
{
|
||||
$queryBuilder->where(['type' => Report::TYPE_LIST]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/***********************************************************************************
|
||||
* The contents of this file are subject to the Extension License Agreement
|
||||
* ("Agreement") which can be viewed at
|
||||
* https://www.espocrm.com/extension-license-agreement/.
|
||||
* By copying, installing downloading, or using this file, You have unconditionally
|
||||
* agreed to the terms and conditions of the Agreement, and You may not use this
|
||||
* file except in compliance with the Agreement. Under the terms of the Agreement,
|
||||
* You shall not license, sublicense, sell, resell, rent, lease, lend, distribute,
|
||||
* redistribute, market, publish, commercialize, or otherwise transfer rights or
|
||||
* usage to the software or any modified version or derivative work of the software
|
||||
* created by or for you.
|
||||
*
|
||||
* Copyright (C) 2015-2025 EspoCRM, Inc.
|
||||
*
|
||||
* License ID: 19bc86a68a7bb01f458cb391d43a9212
|
||||
************************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Advanced\Classes\Select\Report\PrimaryFilters;
|
||||
|
||||
use Espo\Core\Select\Primary\Filter;
|
||||
use Espo\Entities\User;
|
||||
use Espo\Modules\Advanced\Entities\Report;
|
||||
use Espo\ORM\Query\SelectBuilder as QueryBuilder;
|
||||
|
||||
class ListUsers implements Filter
|
||||
{
|
||||
public function apply(QueryBuilder $queryBuilder): void
|
||||
{
|
||||
$queryBuilder->where([
|
||||
'type' => Report::TYPE_LIST,
|
||||
'entityType' => User::ENTITY_TYPE,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/***********************************************************************************
|
||||
* The contents of this file are subject to the Extension License Agreement
|
||||
* ("Agreement") which can be viewed at
|
||||
* https://www.espocrm.com/extension-license-agreement/.
|
||||
* By copying, installing downloading, or using this file, You have unconditionally
|
||||
* agreed to the terms and conditions of the Agreement, and You may not use this
|
||||
* file except in compliance with the Agreement. Under the terms of the Agreement,
|
||||
* You shall not license, sublicense, sell, resell, rent, lease, lend, distribute,
|
||||
* redistribute, market, publish, commercialize, or otherwise transfer rights or
|
||||
* usage to the software or any modified version or derivative work of the software
|
||||
* created by or for you.
|
||||
*
|
||||
* Copyright (C) 2015-2025 EspoCRM, Inc.
|
||||
*
|
||||
* License ID: 19bc86a68a7bb01f458cb391d43a9212
|
||||
************************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Advanced\Classes\Select\Workflow\AccessControlFilters;
|
||||
|
||||
use Espo\Core\Select\AccessControl\Filter;
|
||||
use Espo\ORM\Query\SelectBuilder as QueryBuilder;
|
||||
|
||||
class Mandatory implements Filter
|
||||
{
|
||||
public function apply(QueryBuilder $queryBuilder): void
|
||||
{
|
||||
$queryBuilder->where(['isInternal' => false]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/***********************************************************************************
|
||||
* The contents of this file are subject to the Extension License Agreement
|
||||
* ("Agreement") which can be viewed at
|
||||
* https://www.espocrm.com/extension-license-agreement/.
|
||||
* By copying, installing downloading, or using this file, You have unconditionally
|
||||
* agreed to the terms and conditions of the Agreement, and You may not use this
|
||||
* file except in compliance with the Agreement. Under the terms of the Agreement,
|
||||
* You shall not license, sublicense, sell, resell, rent, lease, lend, distribute,
|
||||
* redistribute, market, publish, commercialize, or otherwise transfer rights or
|
||||
* usage to the software or any modified version or derivative work of the software
|
||||
* created by or for you.
|
||||
*
|
||||
* Copyright (C) 2015-2025 EspoCRM, Inc.
|
||||
*
|
||||
* License ID: 19bc86a68a7bb01f458cb391d43a9212
|
||||
************************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Advanced\Classes\Select\Workflow\PrimaryFilters;
|
||||
|
||||
use Espo\Core\Select\Primary\Filter;
|
||||
use Espo\ORM\Query\SelectBuilder as QueryBuilder;
|
||||
|
||||
class Active implements Filter
|
||||
{
|
||||
public function apply(QueryBuilder $queryBuilder): void
|
||||
{
|
||||
$queryBuilder->where(['isActive' => true]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
/***********************************************************************************
|
||||
* The contents of this file are subject to the Extension License Agreement
|
||||
* ("Agreement") which can be viewed at
|
||||
* https://www.espocrm.com/extension-license-agreement/.
|
||||
* By copying, installing downloading, or using this file, You have unconditionally
|
||||
* agreed to the terms and conditions of the Agreement, and You may not use this
|
||||
* file except in compliance with the Agreement. Under the terms of the Agreement,
|
||||
* You shall not license, sublicense, sell, resell, rent, lease, lend, distribute,
|
||||
* redistribute, market, publish, commercialize, or otherwise transfer rights or
|
||||
* usage to the software or any modified version or derivative work of the software
|
||||
* created by or for you.
|
||||
*
|
||||
* Copyright (C) 2015-2025 EspoCRM, Inc.
|
||||
*
|
||||
* License ID: 19bc86a68a7bb01f458cb391d43a9212
|
||||
************************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Advanced\Classes\ServiceActions\Meeting;
|
||||
|
||||
use Espo\Core\InjectableFactory;
|
||||
use Espo\Core\ORM\Entity as CoreEntity;
|
||||
use Espo\Entities\User;
|
||||
use Espo\Modules\Advanced\Tools\Workflow\Action\RunAction\ServiceAction;
|
||||
use Espo\Modules\Crm\Business\Event\Invitations;
|
||||
use Espo\Modules\Crm\Entities\Call;
|
||||
use Espo\Modules\Crm\Entities\Meeting;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\ORM\EntityManager;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* @implements ServiceAction<Meeting|Call>
|
||||
*/
|
||||
class SendInvitations implements ServiceAction
|
||||
{
|
||||
private InjectableFactory $injectableFactory;
|
||||
private EntityManager $entityManager;
|
||||
private User $user;
|
||||
|
||||
public function __construct(
|
||||
InjectableFactory $injectableFactory,
|
||||
EntityManager $entityManager,
|
||||
User $user
|
||||
) {
|
||||
$this->injectableFactory = $injectableFactory;
|
||||
$this->entityManager = $entityManager;
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
private function getInvitationManager(): Invitations
|
||||
{
|
||||
return $this->injectableFactory->create(Invitations::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function run(Entity $entity, mixed $data): mixed
|
||||
{
|
||||
if (!$entity instanceof CoreEntity) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
$invitationManager = $this->getInvitationManager();
|
||||
$emailHash = [];
|
||||
|
||||
$users = $this->entityManager
|
||||
->getRDBRepository($entity->getEntityType())
|
||||
->getRelation($entity, 'users')
|
||||
->find();
|
||||
|
||||
foreach ($users as $user) {
|
||||
if ($user->getId() === $this->user->getId()) {
|
||||
if (
|
||||
$entity->getLinkMultipleColumn('users', 'status', $user->getId()) ===
|
||||
Meeting::ATTENDEE_STATUS_ACCEPTED
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if ($user->get('emailAddress') && !array_key_exists($user->get('emailAddress'), $emailHash)) {
|
||||
$invitationManager->sendInvitation($entity, $user, 'users');
|
||||
$emailHash[$user->get('emailAddress')] = true;
|
||||
}
|
||||
}
|
||||
|
||||
$contacts = $this->entityManager
|
||||
->getRDBRepository($entity->getEntityType())
|
||||
->getRelation($entity, 'contacts')
|
||||
->find();
|
||||
|
||||
foreach ($contacts as $contact) {
|
||||
if ($contact->get('emailAddress') && !array_key_exists($contact->get('emailAddress'), $emailHash)) {
|
||||
$invitationManager->sendInvitation($entity, $contact, 'contacts');
|
||||
$emailHash[$contact->get('emailAddress')] = true;
|
||||
}
|
||||
}
|
||||
|
||||
$leads = $this->entityManager
|
||||
->getRDBRepository($entity->getEntityType())
|
||||
->getRelation($entity, 'leads')
|
||||
->find();
|
||||
|
||||
foreach ($leads as $lead) {
|
||||
if ($lead->get('emailAddress') && !array_key_exists($lead->get('emailAddress'), $emailHash)) {
|
||||
$invitationManager->sendInvitation($entity, $lead, 'leads');
|
||||
$emailHash[$lead->get('emailAddress')] = true;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
/***********************************************************************************
|
||||
* The contents of this file are subject to the Extension License Agreement
|
||||
* ("Agreement") which can be viewed at
|
||||
* https://www.espocrm.com/extension-license-agreement/.
|
||||
* By copying, installing downloading, or using this file, You have unconditionally
|
||||
* agreed to the terms and conditions of the Agreement, and You may not use this
|
||||
* file except in compliance with the Agreement. Under the terms of the Agreement,
|
||||
* You shall not license, sublicense, sell, resell, rent, lease, lend, distribute,
|
||||
* redistribute, market, publish, commercialize, or otherwise transfer rights or
|
||||
* usage to the software or any modified version or derivative work of the software
|
||||
* created by or for you.
|
||||
*
|
||||
* Copyright (C) 2015-2025 EspoCRM, Inc.
|
||||
*
|
||||
* License ID: 19bc86a68a7bb01f458cb391d43a9212
|
||||
************************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Advanced\Classes\ServiceActions\Person;
|
||||
|
||||
use Espo\Core\ORM\Entity as CoreEntity;
|
||||
use Espo\Entities\EmailAddress;
|
||||
use Espo\Modules\Advanced\Tools\Workflow\Action\RunAction\ServiceAction;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\ORM\EntityManager;
|
||||
use Espo\Repositories\EmailAddress as EmailAddressRepository;
|
||||
|
||||
/**
|
||||
* @implements ServiceAction<CoreEntity>
|
||||
*/
|
||||
class OptOut implements ServiceAction
|
||||
{
|
||||
private EntityManager $entityManager;
|
||||
|
||||
public function __construct(EntityManager $entityManager)
|
||||
{
|
||||
$this->entityManager = $entityManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @noinspection PhpHierarchyChecksInspection
|
||||
* @noinspection PhpUndefinedClassInspection
|
||||
* @noinspection PhpSignatureMismatchDuringInheritanceInspection
|
||||
*/
|
||||
public function run(Entity $entity, mixed $data): mixed
|
||||
{
|
||||
$targetListId = $data->targetListId ?? null;
|
||||
|
||||
if ($targetListId) {
|
||||
$this->entityManager
|
||||
->getRDBRepository($entity->getEntityType())
|
||||
->getRelation($entity, 'targetLists')
|
||||
->updateColumnsById($targetListId, ['optedOut' => true]);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$emailAddress = $entity->get('emailAddress');
|
||||
|
||||
if (!$emailAddress) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** @var EmailAddressRepository $emailAddressRepository */
|
||||
$emailAddressRepository = $this->entityManager->getRepository(EmailAddress::ENTITY_TYPE);
|
||||
|
||||
$addressEntity = $emailAddressRepository->getByAddress($emailAddress);
|
||||
|
||||
if ($addressEntity) {
|
||||
$addressEntity->set('optOut', true);
|
||||
$this->entityManager->saveEntity($addressEntity);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/***********************************************************************************
|
||||
* The contents of this file are subject to the Extension License Agreement
|
||||
* ("Agreement") which can be viewed at
|
||||
* https://www.espocrm.com/extension-license-agreement/.
|
||||
* By copying, installing downloading, or using this file, You have unconditionally
|
||||
* agreed to the terms and conditions of the Agreement, and You may not use this
|
||||
* file except in compliance with the Agreement. Under the terms of the Agreement,
|
||||
* You shall not license, sublicense, sell, resell, rent, lease, lend, distribute,
|
||||
* redistribute, market, publish, commercialize, or otherwise transfer rights or
|
||||
* usage to the software or any modified version or derivative work of the software
|
||||
* created by or for you.
|
||||
*
|
||||
* Copyright (C) 2015-2025 EspoCRM, Inc.
|
||||
*
|
||||
* License ID: 19bc86a68a7bb01f458cb391d43a9212
|
||||
************************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Advanced\Classes\ServiceActions\User;
|
||||
|
||||
use Espo\Core\InjectableFactory;
|
||||
use Espo\Core\Record\ServiceContainer;
|
||||
use Espo\Entities\User;
|
||||
use Espo\Modules\Advanced\Tools\Workflow\Action\RunAction\ServiceAction;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\Tools\UserSecurity\Password\Service;
|
||||
|
||||
/**
|
||||
* @implements ServiceAction<User>
|
||||
*/
|
||||
class GenerateAndSendPassword implements ServiceAction
|
||||
{
|
||||
private InjectableFactory $injectableFactory;
|
||||
private ServiceContainer $serviceContainer;
|
||||
|
||||
public function __construct(
|
||||
InjectableFactory $injectableFactory,
|
||||
ServiceContainer $serviceContainer
|
||||
) {
|
||||
$this->injectableFactory = $injectableFactory;
|
||||
$this->serviceContainer = $serviceContainer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @noinspection PhpHierarchyChecksInspection
|
||||
* @noinspection PhpUndefinedClassInspection
|
||||
* @noinspection PhpSignatureMismatchDuringInheritanceInspection
|
||||
*/
|
||||
public function run(Entity $entity, mixed $data): mixed
|
||||
{
|
||||
if (class_exists("Espo\\Tools\\UserSecurity\\Password\\Service")) {
|
||||
/** @var Service $service */
|
||||
$service = $this->injectableFactory->create("Espo\\Tools\\UserSecurity\\Password\\Service");
|
||||
|
||||
// @todo Support non-admin users.
|
||||
|
||||
$service->generateAndSendNewPasswordForUser($entity->getId());
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$service = $this->serviceContainer->get(User::ENTITY_TYPE);
|
||||
|
||||
if (method_exists($service, 'generateNewPasswordForUser')) {
|
||||
$service->generateNewPasswordForUser($entity->getId(), true);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user