Passed
Push — master ( 918fe4...07100e )
by Alexey
09:39
created

showOptions.php ➔ sortToggler()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 2
nc 4
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
$query = $_GET;
3
$path = Controller::$cur->method != 'itemList' ? '/ecommerce/itemList' : '';
4
$limit = !empty(App::$cur->Ecommerce->config['default_limit']) ? App::$cur->Ecommerce->config['default_limit'] : 18;
5
6
function sortDirectionIcon($type) {
7
    if (!empty($_GET['sort'][$type])) {
8
        return ' <small class = "glyphicon glyphicon-triangle-' . ($_GET['sort'][$type] == 'asc' ? 'top' : 'bottom') . '"></small>';
9
    }
10
}
11
12
function sortToggler($type, $default) {
13
    return empty($_GET['sort'][$type]) ? $default : ($_GET['sort'][$type] == 'desc' ? 'asc' : 'desc');
14
}
15
?>
16
<div class="ecommerce-showoptions">
17
    <div class="row">
18
        <div class="col-xs-6 ecommerce-showoptions-sort">
19
            <span class="caption">Сортировка:</span>
20
            <a href="<?= $path; ?>?<?= http_build_query(array_merge($query, ['sort' => ['price' => sortToggler('price','asc')]])); ?>">По цене<?= sortDirectionIcon('price'); ?></a> 
21
            <a href="<?= $path; ?>?<?= http_build_query(array_merge($query, ['sort' => ['sales' => sortToggler('sales','desc')]])); ?>">По популярности<?= sortDirectionIcon('sales'); ?></a>
22
            <?php
23
            if (!empty(App::$cur->ecommerce->config['isset_sort'])) {
24
                ?>
25
                <a href="<?= $path; ?>?<?= http_build_query(array_merge($query, ['sort' => ['isset' => sortToggler('isset','desc')]])); ?>">По наличию<?= sortDirectionIcon('isset'); ?></a>
26
                <?php
27
            }
28
            ?>
29
        </div>
30
        <div class="col-xs-6 text-right ecommerce-showoptions-view">
31
            <span class="caption">Вид:</span>
32
            <span class="group">
33
              <?php
34
              for ($i = 2; $i < 5; $i++) {
35
                  $curLimit = $limit * $i;
36
                  $curQuery = http_build_query(array_merge($query, ['limit' => $curLimit]));
37
                  echo " <a href='{$path}?{$curQuery}'>";
38
                  echo!empty($_GET['limit']) && $_GET['limit'] == $curLimit ? '<b>' : '';
39
                  echo $curLimit;
40
                  echo!empty($_GET['limit']) && $_GET['limit'] == $curLimit ? '</b>' : '';
41
                  echo "</a> ";
42
              }
43
              if (!empty(App::$cur->ecommerce->config['list_all'])) {
44
                  $curLimit = 'all';
45
                  $curQuery = http_build_query(array_merge($query, ['limit' => $curLimit]));
46
                  echo " <a href='{$path}?{$curQuery}'>";
47
                  echo!empty($_GET['limit']) && $_GET['limit'] == $curLimit ? '<b>' : '';
48
                  echo 'Все';
49
                  echo!empty($_GET['limit']) && $_GET['limit'] == $curLimit ? '</b>' : '';
50
                  echo "</a> ";
51
              }
52
              ?>
53
            </span>
54
            <span class="group">
55
                <a href ='#' onclick="inji.onLoad(function () {
56
                        $('.items-icons').show();
57
                        $('.items-table').hide();
58
                      });
59
                      return false;" class="glyphicon glyphicon-th-large"></a>
60
                <a href ='#' onclick="inji.onLoad(function () {
61
                        $('.items-table').show();
62
                        $('.items-icons').hide();
63
                      });
64
                      return false;" class="glyphicon glyphicon-th-list"></a>
65
            </span>
66
        </div>
67
    </div>
68
</div>