Skip to content

Commit

Permalink
ref
Browse files Browse the repository at this point in the history
  • Loading branch information
yurikuzn committed Nov 27, 2023
1 parent 4782bf5 commit 200fa4d
Show file tree
Hide file tree
Showing 22 changed files with 243 additions and 181 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,4 @@

class Contact extends \Espo\Modules\Crm\Controllers\Contact
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,4 @@

class Opportunity extends \Espo\Modules\Crm\Controllers\Opportunity
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@

namespace Espo\Modules\RealEstate\Controllers;

class RealEstateLocation extends \Espo\Core\Templates\Controllers\CategoryTree
{
use Espo\Core\Templates\Controllers\CategoryTree;

class RealEstateLocation extends CategoryTree
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,44 @@

namespace Espo\Modules\RealEstate\Controllers;

use \Espo\Core\Exceptions\Forbidden;
use \Espo\Core\Exceptions\BadRequest;
use \Espo\Core\Exceptions\NotFound;
use Espo\Core\Api\Request;
use Espo\Core\DataManager;
use Espo\Core\Exceptions\Error;
use Espo\Core\Exceptions\Forbidden;
use Espo\Core\ServiceFactory;
use Espo\Entities\User;

class RealEstateMatchingConfiguration extends \Espo\Core\Controllers\Base
class RealEstateMatchingConfiguration
{
protected function checkControllerAccess()
{
if (!$this->getUser()->isAdmin()) {
/**
* @throws Forbidden
*/
public function __construct(
private ServiceFactory $serviceFactory,
private User $user,
private DataManager $dataManager
) {

if (!$this->user->isAdmin()) {
throw new Forbidden();
}
}

public function putActionUpdate($params, $data, $request)
/**
* @throws Forbidden
* @throws Error
*/
public function putActionUpdate(Request $request): bool
{
$this->getServiceFactory()->create('RealEstateMatchingConfiguration')->setMatchingParameters($data);
if (!$this->user->isAdmin()) {
throw new Forbidden();
}

$data = $request->getParsedBody();

$this->serviceFactory->create('RealEstateMatchingConfiguration')->setMatchingParameters($data);

$this->getContainer()->get('dataManager')->rebuild();
$this->dataManager->rebuild();

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,40 @@

namespace Espo\Modules\RealEstate\Controllers;

use Espo\Core\Api\Request;
use Espo\Core\Controllers\Record;
use Espo\Core\Exceptions\BadRequest;

class RealEstateProperty extends \Espo\Core\Templates\Controllers\Base
class RealEstateProperty extends Record
{
public function postActionSetNotInterested($params, $data, $request)
/**
* @throws BadRequest
*/
public function postActionSetNotInterested(Request $request): bool
{
$data = $request->getParsedBody();

if (empty($data->requestId) || empty($data->propertyId)) {
throw new BadRequest();
}

$this->getRecordService()->setNotIntereseted($data->propertyId, $data->requestId);
$this->getRecordService()->setNotInterested($data->propertyId, $data->requestId);

return true;
}

public function postActionUnsetNotInterested($params, $data, $request)
/**
* @throws BadRequest
*/
public function postActionUnsetNotInterested(Request $request): bool
{
$data = $request->getParsedBody();

if (empty($data->requestId) || empty($data->propertyId)) {
throw new BadRequest();
}

$this->getRecordService()->unsetNotIntereseted($data->propertyId, $data->requestId);
$this->getRecordService()->unsetNotInterested($data->propertyId, $data->requestId);

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,40 @@

namespace Espo\Modules\RealEstate\Controllers;

use Espo\Core\Api\Request;
use Espo\Core\Controllers\Record;
use Espo\Core\Exceptions\BadRequest;

class RealEstateRequest extends \Espo\Core\Templates\Controllers\Base
class RealEstateRequest extends Record
{
public function postActionSetNotInterested($params, $data, $request)
/**
* @throws BadRequest
*/
public function postActionSetNotInterested(Request $request): bool
{
$data = $request->getParsedBody();

if (empty($data->requestId) || empty($data->propertyId)) {
throw new BadRequest();
}

$this->getRecordService()->setNotIntereseted($data->requestId, $data->propertyId);
$this->getRecordService()->setNotInterested($data->requestId, $data->propertyId);

return true;
}

public function postActionUnsetNotInterested($params, $data, $request)
/**
* @throws BadRequest
*/
public function postActionUnsetNotInterested(Request $request): bool
{
$data = $request->getParsedBody();

if (empty($data->requestId) || empty($data->propertyId)) {
throw new BadRequest();
}

$this->getRecordService()->unsetNotIntereseted($data->requestId, $data->propertyId);
$this->getRecordService()->unsetNotInterested($data->requestId, $data->propertyId);

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@ class EmailRequester
{
public static $order = 16;

private $config;

private $metadata;

private $entityManager;
private Config $config;
private Metadata $metadata;
private EntityManager $entityManager;

public function __construct(Config $config, Metadata $metadata, EntityManager $entityManager)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@ class EmailRequester
{
public static $order = 16;

private $config;

private $metadata;

private $entityManager;
private Config $config;
private Metadata $metadata;
private EntityManager $entityManager;

public function __construct(Config $config, Metadata $metadata, EntityManager $entityManager)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

class PropertyMatchingUpdate implements JobDataLess
{
private $serviceFactory;
private ServiceFactory $serviceFactory;

public function __construct(ServiceFactory $serviceFactory)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

class SendPropertyMatches implements JobDataLess
{
protected $serviceFactory;
private ServiceFactory $serviceFactory;

public function __construct(ServiceFactory $serviceFactory)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,4 @@

class Contact extends \Espo\Modules\Crm\Repositories\Contact
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@

namespace Espo\Modules\RealEstate\Repositories;

class RealEstateLocation extends \Espo\Core\Repositories\CategoryTree
{
use Espo\Core\Repositories\CategoryTree;

class RealEstateLocation extends CategoryTree
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,19 @@

namespace Espo\Modules\RealEstate\Repositories;

use Espo\Core\Repositories\Database;
use Espo\ORM\Entity;

class RealEstateProperty extends \Espo\Core\Templates\Repositories\Base
class RealEstateProperty extends Database
{
protected function init()
{
parent::init();

$this->addDependency('serviceFactory');
}

public function beforeSave(Entity $entity, array $options = [])
{
$propertyType = $entity->get('type');

$fieldList = $this->getMetadata()
$fieldList = $this->metadata
->get(['entityDefs', 'RealEstateProperty', 'propertyTypes', $propertyType, 'fieldList'], []);

$fieldDefs = $this->getMetadata()->get(['entityDefs', 'RealEstateProperty', 'fields'], []);
$fieldDefs = $this->metadata->get(['entityDefs', 'RealEstateProperty', 'fields'], []);

foreach ($fieldDefs as $field => $defs) {
if (empty($defs['isMatching'])) {
Expand Down Expand Up @@ -80,6 +74,6 @@ public function beforeSave(Entity $entity, array $options = [])

$entity->set('name', $name);

return parent::beforeSave($entity, $options);
parent::beforeSave($entity, $options);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,19 @@

namespace Espo\Modules\RealEstate\Repositories;

use Espo\Core\Repositories\Database;
use Espo\ORM\Entity;

class RealEstateRequest extends \Espo\Core\Templates\Repositories\Base
class RealEstateRequest extends Database
{
public function beforeSave(Entity $entity, array $options = [])
{
$propertyType = $entity->get('propertyType');

$fieldList = $this->getMetadata()
$fieldList = $this->metadata
->get(['entityDefs', 'RealEstateProperty', 'propertyTypes', $propertyType, 'fieldList'], []);

$fieldDefs = $this->getMetadata()->get(['entityDefs', 'RealEstateProperty', 'fields'], []);
$fieldDefs = $this->metadata->get(['entityDefs', 'RealEstateProperty', 'fields'], []);

foreach ($fieldDefs as $field => $defs) {
if (empty($defs['isMatching'])) {
Expand All @@ -53,31 +54,32 @@ public function beforeSave(Entity $entity, array $options = [])
}
}

return parent::beforeSave($entity, $options);
parent::beforeSave($entity, $options);
}

public function afterSave(Entity $entity, array $options = [])
{
$result = parent::afterSave($entity, $options);
parent::afterSave($entity, $options);

$this->handleAfterSaveContacts($entity, $options);
$this->handleAfterSaveContacts($entity);

if ($entity->isNew() && !$entity->get('name')) {
$e = $this->get($entity->getId());
$e = $this->getById($entity->getId());

$name = strval($e->get('number'));
$name = str_pad($name, 6, '0', STR_PAD_LEFT);
$name = 'R ' . $name;

$e->set('name', $name);

$this->save($e);

$entity->set('name', $name);
$entity->set('number', $e->get('number'));
}

return $result;
}

protected function handleAfterSaveContacts(Entity $entity, array $options = [])
private function handleAfterSaveContacts(Entity $entity): void
{
$contactIdChanged =
$entity->has('contactId') && $entity->get('contactId') != $entity->getFetched('contactId');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,33 +29,29 @@

namespace Espo\Modules\RealEstate\Services;

use Espo\Core\Exceptions\BadRequest;
use Espo\Core\Exceptions\Error;
use Espo\Core\Exceptions\Forbidden;
use Espo\ORM\Entity;
use Espo\ORM\Query\Select;
use Espo\ORM\Query\SelectBuilder;

use Espo\Core\Select\SelectManagerFactory;
use Espo\Core\Select\SelectBuilderFactory;

use Espo\Core\Utils\Metadata;

class ActivitiesRealEstateProperty
{
protected $metadata;

protected $selectManagerFactory;

private $selectBuilderFactory;
private SelectBuilderFactory $selectBuilderFactory;

public function __construct(
Metadata $metadata,
SelectManagerFactory $selectManagerFactory,
SelectBuilderFactory $selectBuilderFactory
) {
$this->metadata = $metadata;
$this->selectManagerFactory = $selectManagerFactory;
$this->selectBuilderFactory = $selectBuilderFactory;
}

/**
* @throws BadRequest
* @throws Forbidden
* @throws Error
*/
public function getActivitiesMeetingQuery(Entity $entity, array $statusList): Select
{
$builder = $this->selectBuilderFactory
Expand Down Expand Up @@ -109,6 +105,11 @@ public function getActivitiesMeetingQuery(Entity $entity, array $statusList): Se
return $builder->build();
}

/**
* @throws BadRequest
* @throws Forbidden
* @throws Error
*/
public function getActivitiesCallQuery(Entity $entity, array $statusList): Select
{
$builder = $this->selectBuilderFactory
Expand Down
Loading

0 comments on commit 200fa4d

Please sign in to comment.