fix meeting/call attendees

This commit is contained in:
Yuri Kuznetsov
2014-12-03 15:50:00 +02:00
parent 46439ff394
commit 9d316da4e0
3 changed files with 24 additions and 47 deletions
@@ -24,27 +24,8 @@ namespace Espo\Modules\Crm\Repositories;
use Espo\ORM\Entity;
class Call extends \Espo\Core\ORM\Repositories\RDB
{
protected function beforeSave(Entity $entity)
{
parent::beforeSave($entity);
$parentId = $entity->get('parentId');
$parentType = $entity->get('parentType');
if (!empty($parentId) || !empty($parentType)) {
$parent = $this->getEntityManager()->getEntity($parentType, $parentId);
if (!empty($parent)) {
if ($parent->getEntityName() == 'Account') {
$accountId = $parent->id;
} else if ($parent->has('accountId')) {
$accountId = $parent->get('accountId');
}
if (!empty($accountId)) {
$entity->set('accountId', $accountId);
}
}
}
}
class Call extends Meeting
{
}
@@ -18,16 +18,16 @@
*
* You should have received a copy of the GNU General Public License
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
************************************************************************/
************************************************************************/
namespace Espo\Modules\Crm\Repositories;
use Espo\ORM\Entity;
class Meeting extends \Espo\Core\ORM\Repositories\RDB
{
{
protected function beforeSave(Entity $entity)
{
{
parent::beforeSave($entity);
$parentId = $entity->get('parentId');
@@ -44,7 +44,24 @@ class Meeting extends \Espo\Core\ORM\Repositories\RDB
$entity->set('accountId', $accountId);
}
}
}
}
$assignedUserId = $entity->get('assignedUserId');
if ($assignedUserId && $entity->has('usersIds')) {
$usersIds = $entity->get('usersIds');
if (!is_array($usersIds)) {
$usersIds = array();
}
if (!in_array($assignedUserId, $usersIds)) {
$usersIds[] = $assignedUserId;
$entity->set('usersIds', $usersIds);
$hash = $entity->get('usersNames');
if ($hash instanceof \stdClass) {
$hash->$assignedUserId = $entity->get('assignedUserName');
$entity->set('usersNames', $hash);
}
}
}
}
}
@@ -98,26 +98,5 @@ class Meeting extends \Espo\Services\Record
return true;
}
protected function storeEntity(Entity $entity)
{
$assignedUserId = $entity->get('assignedUserId');
if ($assignedUserId && $entity->has('usersIds')) {
$usersIds = $entity->get('usersIds');
if (!is_array($usersIds)) {
$usersIds = array();
}
if (!in_array($assignedUserId, $usersIds)) {
$usersIds[] = $assignedUserId;
$entity->set('usersIds', $usersIds);
$hash = $entity->get('usersNames');
if ($hash instanceof \stdClass) {
$hash->assignedUserId = $entity->get('assignedUserName');
$entity->set('usersNames', $hash);
}
}
}
return parent::storeEntity($entity);
}
}