This commit is contained in:
Yuri Kuznetsov
2014-01-03 15:33:56 +02:00
parent 1918265ca5
commit a8feead8de
6 changed files with 104 additions and 7 deletions
+2 -2
View File
@@ -55,9 +55,9 @@ class ControllerManager
if (!class_exists($controllerClassName)) {
throw new NotFound("Controller '$controllerName' is not found");
}
$controller = new $controllerClassName($this->container, $this->serviceFactory);
if ($actionName == 'index') {
$actionName = $controller->defaultAction;
}
+38 -3
View File
@@ -82,7 +82,7 @@ abstract class Record extends Base
throw new Error();
}
public function actionList($params, $where, $request)
public function actionList($params, $data, $request)
{
if (!$this->getAcl()->check($this->name, 'read')) {
throw new Forbidden();
@@ -142,17 +142,52 @@ abstract class Record extends Base
}
throw new Error();
}
public function actionExport($params, $data, $request)
{
if (!$this->getAcl()->check($this->name, 'read')) {
throw new Forbidden();
}
$ids = $request->get('ids');
$where = $request->get('where');
if (!empty($ids)) {
$where = array(
array(
'type' => 'in',
'field' => 'id',
'value' => $ids
)
);
}
$result = $this->getRecordService()->findEntities(array('where' => $where));
$arr = $result['collection']->toArray();
header('Content-Type: text/csv');
header('Content-Disposition: filename=' . $this->name . '.csv');
$fp = fopen('php://output', 'w');
fputcsv($fp, array_keys($arr[0]));
foreach ($arr as $row) {
fputcsv($fp, $row);
}
fclose($fp);
die;
}
public function actionMassUpdate($params, $data)
{
if (!$this->getAcl()->check($this->name, 'edit')) {
throw new Forbidden();
}
}
$ids = $data['ids'];
$where = $data['where'];
$attributes = $data['attributes'];
$idsUpdated = $this->getRecordService()->massUpdate($ids, $where);
$idsUpdated = $this->getRecordService()->massUpdate($attributes, $ids, $where);
return $idsUpdated;
}
+1 -1
View File
@@ -12,7 +12,7 @@ class EntityCollection implements \Iterator, \Countable, \ArrayAccess, \Seekable
protected $container = array();
public function __construct($data, $seed = null, EntityFactory $entityFactory = null)
public function __construct($data = array(), $seed = null, EntityFactory $entityFactory = null)
{
$this->container = $data;
+7
View File
@@ -88,5 +88,12 @@ class EntityManager
{
return $name;
}
public function createCollection($entityName, $data = array())
{
$seed = $this->getEntity($entityName);
$collection = new EntityCollection($data, $seed, $this->entityFactory);
return $collection;
}
}
+27
View File
@@ -40,6 +40,33 @@
"controller":"Settings"
}
},
{
"route":"/:controller/action/:action",
"method":"post",
"params":{
"controller":":controller",
"action":":action"
}
},
{
"route":"/:controller/action/:action",
"method":"put",
"params":{
"controller":":controller",
"action":":action"
}
},
{
"route":"/:controller/action/:action",
"method":"get",
"params":{
"controller":":controller",
"action":":action"
}
},
{
"route":"/:controller/layout/:name",
+29 -1
View File
@@ -11,7 +11,8 @@ class Record extends \Espo\Core\Services\Base
'entityManager',
'user',
'metadata',
'acl'
'acl',
'config'
);
protected $entityName;
@@ -36,6 +37,11 @@ class Record extends \Espo\Core\Services\Base
return $this->injections['acl'];
}
protected function getConfig()
{
return $this->injections['config'];
}
protected function getMetadata()
{
return $this->injections['metadata'];
@@ -240,6 +246,28 @@ class Record extends \Espo\Core\Services\Base
return true;
}
}
public function massUpdate($attributes = array(), $ids = array(), $where = array())
{
$idsUpdated = array();
$repository = $this->getRepository();
if (!empty($ids)) {
foreach ($ids as $id) {
$entity = $this->getEntity($id);
if ($this->getAcl()->check($entity, 'edit')) {
$entity->set($attributes);
if ($repository->save($entity)) {
$idsUpdated[] = $id;
}
}
}
}
return $idsUpdated;
// TODO update $where
}
}