Hello All.
Help me please.
I write new "function formula" for "calculated fields" .
My function is now in list in formula editor, but it's not working.
This function mast do:
Content of function:
In time when call this function not working update fields in front end whith error. And in log this record:
It row is "$entityManager = $this->getEntityManager();"
Help me please.
I write new "function formula" for "calculated fields" .
My function is now in list in formula editor, but it's not working.
This function mast do:
- Current record of entity, where coll this function, have field "offer". This field is link to relayted entity.
- Funtion mast calculated summ field "summ" of curret entity filtered by (offer.id = offer.id of current record) and groupe by offer.id
Content of function:
PHP Code:
<?php
namespace Espo\Custom\Core\Formula\Functions\EntityGroup;
use \Espo\ORM\Entity;
use \Espo\Core\Exceptions\Error;
class OfferSummType extends \Espo\Core\Formula\Functions\Base
{
protected function init()
{
$this->addDependency('entityManager');
$this->addDependency('selectManagerFactory');
}
public function process(\StdClass $item)
{
$entity = $this->getEntity();
$entityManager = $this->getEntityManager();
$offerId = $entity->get('offer');
if (!offerId) {
throw new Error();
}
$selectParams['select'] = [['offer'], 'SUM:' . 'summ'];
$selectParams['whereClause'][] = [
'offer' => $offerId
];
$selectParams['groupBy'] = ['offer'];
$entityManager->getRepository($entity)->handleSelectParams($selectParams);
$sql = $entityManager->getQuery()->createSelectQuery($entity, $selectParams);
$pdo = $entityManager->getPDO();
$sth = $pdo->prepare($sql);
$sth->execute();
$rowList = $sth->fetchAll(\PDO::FETCH_ASSOC);
if (empty($rowList)) {
return 0;
}
return floatval($rowList[0]['SUM:' . 'summ']);
}
}
Code:
[2019-10-13 13:13:23] Espo.ERROR: Uncaught Exception Error: "Call to undefined method Espo\Custom\Core\Formula\Functions\EntityGroup\OfferSummType::getEntityManager()" at /pathToEspocrm/custom/Espo/Custom/Core/Formula/Functions/EntityGroup/OfferSummType.php line 22 {"exception":"[object] (Error(code: 0): Call to undefined method Espo\\Custom\\Core\\Formula\\Functions\\EntityGroup\\OfferSummType::getEntityManager() at /patchToEspocrm/custom/Espo/Custom/Core/Formula/Functions/EntityGroup/OfferSummType.php:22)"} []
Comment