Completed
Push — master ( ae829f...1d5438 )
by Laurent
23s
created

ControllerHelper::hasSupplierArticles()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 13
rs 9.4285
cc 2
eloc 7
nc 2
nop 1
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\Entity\Article;
18
use Doctrine\Common\Persistence\ObjectManager;
19
20
/**
21
 * Controller helper.
22
 *
23
 * @category Helper
24
 */
25
class ControllerHelper
26
{
27
    /**
28
     * Tests of creation conditions.
29
     *
30
     * @param array Articles à tester
31
     * @return boolean
32
     */
33
    public function hasSupplierArticles(array $articles)
34
    {
35
        $return = true;
36
37
        // This supplier has no articles!
38
        if (count($articles) < 1) {
39
            $message = $this->get('translator')->trans('settings.no_articles', array(), 'gs_suppliers');
0 ignored issues
show
Bug introduced by
The method get() does not seem to exist on object<AppBundle\Helper\ControllerHelper>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
40
            $this->addFlash('danger', $message);
0 ignored issues
show
Bug introduced by
The method addFlash() does not seem to exist on object<AppBundle\Helper\ControllerHelper>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
41
            $return = false;
42
        }
43
44
        return $return;
45
    }
46
47
    /**
48
     * Tests Order in progress for a supplier.
49
     *
50
     * @param \AppBundle\Entity\Article $articles Articles to test
51
     * @param \Doctrine\Common\Persistence\ObjectManager $etm Named object manager
52
     * @return boolean
53
     */
54
    public function isOrderInProgress(Article $articles, ObjectManager $etm)
55
    {
56
        $return = false;
57
        $orders = $etm->getRepository('AppBundle:Orders')->findAll();
58
        // This provider already has an order in progress!
59
        foreach ($orders as $order) {
60
            if ($order->getSupplier() === $articles->getSupplier()) {
61
                $return = true;
62
            }
63
        }
64
        return $return;
65
    }
66
}
67