teams
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Espo\Controllers;
|
||||
|
||||
class Team extends \Espo\Core\Controllers\Record
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
@@ -10,6 +10,7 @@ class Repository extends \Espo\ORM\Repository
|
||||
$nowString = date('Y-m-d H:i:s', time());
|
||||
$restoreData = array();
|
||||
|
||||
|
||||
if ($entity->isNew()) {
|
||||
if ($entity->hasField('createdAt')) {
|
||||
$entity->set('createdAt', $nowString);
|
||||
@@ -54,10 +55,10 @@ class Repository extends \Espo\ORM\Repository
|
||||
{
|
||||
foreach ($entity->getRelations() as $name => $defs) {
|
||||
if ($defs['type'] == $entity::HAS_MANY || $defs['type'] == $entity::MANY_MANY) {
|
||||
$fieldName = $name . 'Ids';
|
||||
if ($entity->has($fieldName)) {
|
||||
$fieldName = $name . 'Ids';
|
||||
if ($entity->has($fieldName)) {
|
||||
$specifiedIds = $entity->get($fieldName);
|
||||
if (is_array($ids)) {
|
||||
if (is_array($specifiedIds)) {
|
||||
$toRemoveIds = array();
|
||||
$existingIds = array();
|
||||
foreach ($entity->get($name) as $foreignEntity) {
|
||||
@@ -67,7 +68,8 @@ class Repository extends \Espo\ORM\Repository
|
||||
if (!in_array($id, $specifiedIds)) {
|
||||
$toRemoveIds[] = $id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($specifiedIds as $id) {
|
||||
if (!in_array($id, $existingIds)) {
|
||||
$this->relate($entity, $name, $id);
|
||||
|
||||
@@ -504,7 +504,12 @@ abstract class Mapper implements IMapper
|
||||
|
||||
$wherePart =
|
||||
$this->toDb($nearKey) . " = " . $this->pdo->quote($entity->id) . " ".
|
||||
"AND " . $this->toDb($distantKey) . " = " . $this->pdo->quote($relEntity->id);
|
||||
"AND " . $this->toDb($distantKey) . " = " . $this->pdo->quote($relEntity->id);
|
||||
if (!empty($relOpt['conditions']) && is_array($relOpt['conditions'])) {
|
||||
foreach ($relOpt['conditions'] as $f => $v) {
|
||||
$wherePart .= " AND " . $this->toDb($f) . " = " . $this->pdo->quote($v);
|
||||
}
|
||||
}
|
||||
|
||||
$sql = $this->composeSelectQuery($relTable, '*', '', $wherePart);
|
||||
|
||||
|
||||
@@ -80,13 +80,13 @@ class Record extends \Espo\Core\Services\Base
|
||||
$entity = $this->getRepository()->get($id);
|
||||
|
||||
if (!empty($id)) {
|
||||
if ($entity->hasRelation('teams')) {
|
||||
if ($entity->hasRelation('teams') && $entity->hasField('teamsIds')) {
|
||||
$teams = $entity->get('teams');
|
||||
$ids = array();
|
||||
$names = array();
|
||||
foreach ($teams as $team) {
|
||||
$ids[] = $team->id;
|
||||
$names[$team->id] = $team->name;
|
||||
$names[$team->id] = $team->get('name');
|
||||
}
|
||||
$entity->set('teamsIds', $ids);
|
||||
$entity->set('teamsNames', $names);
|
||||
@@ -123,7 +123,7 @@ class Record extends \Espo\Core\Services\Base
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
$entity->set($data);
|
||||
$entity->set($data);
|
||||
|
||||
$this->getRepository()->save($entity);
|
||||
return $entity;
|
||||
|
||||
Reference in New Issue
Block a user