Completed
Push — master ( 337c6f...93368f )
by Alexey
05:37
created

CompleteTransfer::rowButton()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 19
Code Lines 11

Duplication

Lines 19
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 19
loc 19
rs 9.4285
cc 3
eloc 11
nc 2
nop 3
1
<?php
2
/**
3
 * Transfer cancel action
4
 *
5
 * @author Alexey Krupskiy <[email protected]>
6
 * @link http://inji.ru/
7
 * @copyright 2016 Alexey Krupskiy
8
 * @license https://github.com/injitools/cms-Inji/blob/master/LICENSE
9
 */
10
11
namespace Money;
12
13 View Code Duplication
class CompleteTransfer extends \Ui\DataManager\Action
14
{
15
    public static $name = 'Завершить';
16
    public static $groupAction = true;
17
    public static $rowAction = true;
18
19
    public static function rowButton($dataManager, $item, $params)
20
    {
21
        if ($item->canceled || $item->complete) {
22
            return '';
23
        }
24
        ob_start();
25
        ?>
26
        <a onclick="inji.Server.request({
27
                url: '/admin/money/completeTransfer/<?= $item->id; ?>',
28
                success: function () {
29
                  inji.Ui.dataManagers.reloadAll();
30
                }});
31
              return false;
32
           " href ='#' class="btn btn-xs btn-primary">Завершить</a>
33
        <?php
34
        $btn = ob_get_contents();
35
        ob_end_clean();
36
        return $btn;
37
    }
38
39
    public static function groupAction($dataManager, $ids, $actionParams)
40
    {
41
        $transfers = \Money\Transfer::getList(['where' => [['id', $ids, 'IN'], ['canceled', 0], ['complete', 0]]]);
42
        foreach ($transfers as $transfer) {
43
            $transfer->confirm();
44
        }
45
        $count = count($transfers);
46
        return 'Завершено <b>' . $count . '</b> ' . \Tools::getNumEnding($count, ['перевод', 'перевода', 'переводов']);
47
    }
48
49
}
50