Completed
Push — master ( f81666...55a9f3 )
by Alexey
05:42
created

Delete::groupAction()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 2
eloc 7
nc 2
nop 3
1
<?php
2
3
/**
4
 * Data manager delete action
5
 *
6
 * @author Alexey Krupskiy <[email protected]>
7
 * @link http://inji.ru/
8
 * @copyright 2016 Alexey Krupskiy
9
 * @license https://github.com/injitools/cms-Inji/blob/master/LICENSE
10
 */
11
12
namespace Ui\DataManager\Action;
13
14
class Delete extends \Ui\DataManager\Action
15
{
16
    public static $name = 'Удалить';
17
    public static $groupAction = true;
18
    public static $rowAction = true;
19
20
    public static function rowButton($dataManager, $item, $params, $actionParams)
21
    {
22
        return '<a href ="#" onclick=\'inji.Ui.dataManagers.get(this).delRow(' . $item->pk() . ');
23
                                      return false;\'><i class="glyphicon glyphicon-remove"></i></a>';
24
    }
25
26
    public static function groupAction($dataManager, $ids, $actionParams)
27
    {
28
        $modelName = $dataManager->modelName;
29
        $models = $modelName::getList(['where' => [['id', $ids, 'IN']]]);
30
        foreach ($models as $model) {
31
            $model->delete();
32
        }
33
        $count = count($models);
34
        return 'Удалено <b>' . $count . '</b> ' . \Tools::getNumEnding($count, ['запись', 'записи', 'записей']);
35
    }
36
37
}
38