change viewDefs

This commit is contained in:
Yuri Kuznetsov
2013-11-28 13:49:17 +02:00
parent eed3da57e8
commit 1f82e1fa6e
13 changed files with 147 additions and 174 deletions
+42 -16
View File
@@ -29,6 +29,26 @@ abstract class Record extends Base
return $entity;
}
public function actionPatch($params, $data)
{
return $this->actionUpdate($params, $data);
}
public function actionCreate($params, $data)
{
if (!$this->getAcl()->check($this->name, 'edit')) {
throw new Forbidden();
}
$service = $this->getService();
if ($entity = $service->createEntity($data)) {
return $entity;
}
throw new Error();
}
public function actionUpdate($params, $data)
{
@@ -39,7 +59,7 @@ abstract class Record extends Base
if (!$this->getAcl()->check($entity, 'edit')) {
throw new Forbidden();
}
if ($service->updateEntity($entity, $data)) {
return $entity;
}
@@ -47,21 +67,6 @@ abstract class Record extends Base
throw new Error();
}
public function actionPost($params, $data)
{
if (!$this->getAcl()->check($this->name, 'edit')) {
throw new Forbidden();
}
$service = $this->getService();
if ($entity = $service->postEntity($data)) {
return $entity;
}
throw new Error();
}
public function actionList($params, $where)
{
if (!$this->getAcl()->check($this->name, 'read')) {
@@ -186,4 +191,25 @@ abstract class Record extends Base
throw new Error();
}
public function actionRemoveLink($params)
{
$id = $params['id'];
$link = $params['link'];
$foreignId = $params['foreignId'];
$service = $this->getService();
$entity = $service->getEntity($id);
$foreignEntityName = $entity->defs['links'][$link]['entity'];
if (!$this->getAcl()->check($entity, 'edit')) {
throw new Forbidden();
}
if ($service->unlinkEntity($entity, $link, $foreignId)) {
return true;
}
throw new Error();
}
}
+13
View File
@@ -32,4 +32,17 @@ class EntityManager extends \Doctrine\ORM\Decorator\EntityManagerDecorator
{
return $this->wrapped;
}
public function createEntity($entityName)
{
$className = $this->metadata->getEntityPath($entityName);
$entity = new $className();
return $entity;
}
public function getEntityName($entity)
{
$className = get_class($entity);
return ltrim($className, '\\');
}
}
@@ -1,8 +1,4 @@
{
"bottomPanels":{
"detail":[
]
},
"sidePanels":{
"detail":[
{
@@ -24,17 +20,5 @@
],
"layout":"listSmall"
}
},
"menu":{
"list":{
"buttons":[
{
"label":"Create Account",
"link":"#Account/create",
"style":"primary",
"acl":"edit"
}
]
}
}
}
@@ -30,17 +30,5 @@
}
}
]
},
"menu":{
"list":{
"buttons":[
{
"label":"Create Call",
"link":"#Call/create",
"style":"primary",
"acl":"edit"
}
]
}
}
}
@@ -16,17 +16,5 @@
"view":"Crm:Record.Panels.History"
}
]
},
"menu":{
"list":{
"buttons":[
{
"label":"Create Case",
"link":"#Case/create",
"style":"primary",
"acl":"edit"
}
]
}
}
}
@@ -1,8 +1,4 @@
{
"bottomPanels":{
"detail":[
]
},
"sidePanels":{
"detail":[
{
@@ -16,17 +12,5 @@
"view":"Crm:Record.Panels.History"
}
]
},
"menu":{
"list":{
"buttons":[
{
"label":"Create Contact",
"link":"#Contact/create",
"style":"primary",
"acl":"edit"
}
]
}
}
}
@@ -1,14 +1 @@
{
"menu":{
"list":{
"buttons":[
{
"label":"Create Inbound Email",
"link":"#InboundEmail/create",
"style":"primary",
"acl":"edit"
}
]
}
}
}
{}
@@ -5,10 +5,6 @@
"recordViewMaps":{
"detail":"Crm:Lead.Record.Detail"
},
"bottomPanels":{
"detail":[
]
},
"sidePanels":{
"detail":[
{
@@ -22,17 +18,5 @@
"view":"Crm:Record.Panels.History"
}
]
},
"menu":{
"list":{
"buttons":[
{
"label":"Create Lead",
"link":"#Lead/create",
"style":"primary",
"acl":"edit"
}
]
}
}
}
@@ -33,17 +33,5 @@
}
}
]
},
"menu":{
"list":{
"buttons":[
{
"label":"Create Meeting",
"link":"#Meeting/create",
"style":"primary",
"acl":"edit"
}
]
}
}
}
@@ -1,8 +1,4 @@
{
"bottomPanels":{
"detail":[
]
},
"sidePanels":{
"detail":[
{
@@ -16,17 +12,5 @@
"view":"Crm:Record.Panels.History"
}
]
},
"menu":{
"list":{
"buttons":[
{
"label":"Create Opportunity",
"link":"#Opportunity/create",
"style":"primary",
"acl":"edit"
}
]
}
}
}
@@ -1,18 +1,5 @@
{
"viewMaps":{
"detail":"Crm:Prospect.Detail"
},
"menu":{
"list":{
"buttons":[
{
"label":"Create Prospect",
"link":"#Prospect/create",
"style":"primary",
"acl":"edit"
}
]
},
"detail":{
"buttons":[
{
@@ -1,14 +1,2 @@
{
"menu":{
"list":{
"buttons":[
{
"label":"Create Task",
"link":"#Task/create",
"style":"primary",
"acl":"edit"
}
]
}
}
}
+91 -19
View File
@@ -2,6 +2,7 @@
namespace Espo\Services;
use \Espo\Core\Exceptions\Error;
class Record extends \Espo\Core\Services\Base
{
@@ -9,45 +10,116 @@ class Record extends \Espo\Core\Services\Base
'entityManager',
'user',
);
private $user;
private $entityManager;
protected $entityName;
public function setEntityName($entityName)
{
$this->entityName = $entityName;
}
}
public function setEntityManager($entityManager)
{
$this->entityManager = $entityManager;
}
public function setUser($user)
{
$this->user = $user;
}
public function getEntityManager()
}
protected function getEntityManager()
{
return $this->entityManager;
}
public function getUser()
protected function getUser()
{
return $this->user;
}
}
public function getEntity($id)
{
return $this->getEntityManager()->find($this->name, $id);
return $this->getEntityManager()->getRepository($this->name)->find($id);
}
public function findEntities($where)
public function findEntities($params)
{
return $this->getEntityManager()->getRepository($this->name)->findBy($where);
}
$collection = $this->getEntityManager()->getRepository($this->name)->findBy();
$criteria = $this->getCriteriaManager()->createCriteria($params);
return $collection->matching($criteria);
}
public function createEntity($data)
{
// TODO validate $data
$entity = $this->getEntityManager()->createEntity($this->name);
$entity->fromArray($data);
$this->getEntityManager()->persist($entity);
$this->getEntityManager()->flush();
return $entity;
}
public function updateEntity($entity, $data)
{
// TODO validate $data
$entity->fromArray($data);
$this->getEntityManager()->persist($entity);
$this->getEntityManager()->flush();
return $entity;
}
public function deleteEntity($entity)
{
$this->getEntityManager()->remove($entity);
$this->getEntityManager()->flush();
return true;
}
public function findLinkedEntities($entity, $link, $params)
{
$criteria = $this->getCriteriaManager()->createCriteria($params);
$methodName = 'get' . ucfirst($link);
$collection = $entity->$methodName();
return $collection->matching($criteria);
}
public function linkEntity($entity, $link, $foreignId)
{
$entityName = $this->getEntityManager()->getEntityName($entity);
$foreignEntityName = $this->getMetadata()->get('entityDefs.' . $entityName . '.links.' . $link . '.entity');
if (empty($foreignEntityName)) {
throw new Error();
}
$methodName = 'get' . ucfirst($link);
$foreignEntity = $this->getEntityManager()->getRepository($foreignEntityName)->find($foreignId);
if (!empty($foreignEntity)) {
$entity->$methodName()->add($foreignEntity);
return true;
}
}
public function unlinkEntity($entity, $link, $foreignId)
{
$entityName = $this->getEntityManager()->getEntityName($entity);
$foreignEntityName = $this->getMetadata()->get('entityDefs.' . $entityName . '.links.' . $link . '.entity');
if (empty($foreignEntityName)) {
throw new Error();
}
$methodName = 'get' . ucfirst($link);
$entity->$methodName()->remove($foreignId);
return true;
}
}