Completed
Push — master ( 72c0d5...95f58c )
by Laurent
03:20
created

ControllerHelper::getSlug()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
/**
3
 * ControllerHelper Helpers des Controller de l'application GLSR.
4
 *
5
 * PHP Version 5
6
 *
7
 * @author    Quétier Laurent <[email protected]>
8
 * @copyright 2014 Dev-Int GLSR
9
 * @license   http://opensource.org/licenses/gpl-license.php GNU Public License
10
 *
11
 * @version since 1.0.0
12
 *
13
 * @link      https://github.com/Dev-Int/glsr
14
 */
15
namespace AppBundle\Helper;
16
17
use AppBundle\Helper\AbstractEntity;
18
use AppBundle\Entity\Article;
19
use Doctrine\Common\Persistence\ObjectManager;
20
use Symfony\Component\HttpFoundation\Session\Session;
21
22
/**
23
 * Controller helper.
24
 *
25
 * @category Helper
26
 */
27
class ControllerHelper extends AbstractEntity
28
{
29
    private $translator;
30
    private $session;
31
32
    public function __construct($translator, $session)
33
    {
34
        $this->translator = $translator;
35
        $this->session = $session;
36
    }
37
38
    /**
39
     * Tests of creation conditions.
40
     *
41
     * @param array Articles à tester
42
     * @return boolean
43
     */
44
    public function hasSupplierArticles(array $articles)
45
    {
46
        $return = true;
47
48
        // This supplier has no articles!
49
        if (count($articles) < 1) {
50
            $message = $this->translator->trans('settings.no_articles', array(), 'gs_suppliers');
51
            $this->session->getFlashBag()->add('danger', $message);
52
            $return = false;
53
        }
54
55
        return $return;
56
    }
57
58
    /**
59
     * Tests Order in progress for a supplier.
60
     *
61
     * @param \AppBundle\Entity\Article $articles Articles to test
62
     * @param \Doctrine\Common\Persistence\ObjectManager $etm Named object manager
63
     * @return boolean
64
     */
65
    public function isOrderInProgress(Article $articles, ObjectManager $etm)
66
    {
67
        $return = false;
68
        $orders = $etm->getRepository('AppBundle:Orders')->findAll();
69
        // This provider already has an order in progress!
70
        foreach ($orders as $order) {
71
            if ($order->getSupplier() === $articles->getSupplier()) {
72
                $return = true;
73
            }
74
        }
75
        return $return;
76
    }
77
78
    /**
79
     * Array of file (`pdf`) layout.
80
     *
81
     * @param string $date  File date
82
     * @param string $title File title
83
     * @return array
84
     */
85
    protected function getArray($date, $title)
86
    {
87
        $array = array(
88
            'margin-top' => 15,
89
            'header-spacing' => 5,
90
            'header-font-size' => 8,
91
            'header-left' => 'G.L.S.R.',
92
            'header-center' => $title,
93
            'header-right' => $date,
94
            'header-line' => true,
95
            'margin-bottom' => 15,
96
            'footer-spacing' => 5,
97
            'footer-font-size' => 8,
98
            'footer-left' => 'GLSR &copy 2014 and beyond.',
99
            'footer-right' => 'Page [page]/[toPage]',
100
            'footer-line' => true,
101
        );
102
        return $array;
103
    }
104
105
    /**
106
     * Test paramters to return.
107
     *
108
     * @param \AppBundle\Helper\AbstractEntity $entity     Entity to return
109
     * @param string                           $entityName Entity name to test
110
     * @return array Parameters to return
111
     */
112
    protected function testReturnParam(AbstractEntity $entity, $entityName)
113
    {
114
        $entityArray = ['company', 'settings', 'group', 'tva'];
115
        if (in_array($entityName, $entityArray, true)) {
116
            $param = ['id' => $entity->getId()];
117
        } else {
118
            $param = ['slug' => $entity->getSlug()];
119
        }
120
121
        return $param;
122
    }
123
124
    /**
125
     * SetOrder for the SortAction in views.
126
     *
127
     * @param string $name   session name
128
     * @param string $entity entity name
129
     * @param string $field  field name
130
     * @param string $type   sort type ("ASC"/"DESC")
131
     */
132
    protected function setOrder($name, $entity, $field, $type = 'ASC')
133
    {
134
        $session = new Session();
135
136
        $session->set('sort.'.$name, array('entity' => $entity, 'field' => $field, 'type' => $type));
137
    }
138
139
    /**
140
     * GetOrder for the SortAction in views.
141
     *
142
     * @param string $name session name
143
     *
144
     * @return array
145
     */
146
    public function getOrder($name)
147
    {
148
        $session = new Session();
149
150
        return $session->has('sort.' . $name) ? $session->get('sort.' . $name) : null;
151
    }
152
153
    public function getId()
154
    {
155
        
156
    }
157
158
    public function getSlug()
159
    {
160
        
161
    }
162
}
163