| 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 GIT: <git_id> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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 |  |  | use Symfony\Component\HttpFoundation\Session\Session; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  * Controller helper. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  * @category Helper | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | class ControllerHelper | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     private $translator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     private $session; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |     public function __construct($translator, $session) | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |         $this->translator = $translator; | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |         $this->session = $session; | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |      * Tests of creation conditions. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |      * @param array Articles à tester | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      * @return boolean | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     public function hasSupplierArticles(array $articles) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         $return = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         // This supplier has no articles! | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         if (count($articles) < 1) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |             $message = $this->translator->trans('settings.no_articles', array(), 'gs_suppliers'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |             $this->session->getFlashBag()->add('danger', $message); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |             $return = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         return $return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |      * Tests Order in progress for a supplier. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |      * @param \AppBundle\Entity\Article $articles Articles to test | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |      * @param \Doctrine\Common\Persistence\ObjectManager $etm Named object manager | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |      * @return boolean | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     public function isOrderInProgress(Article $articles, ObjectManager $etm) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         $return = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         $orders = $etm->getRepository('AppBundle:Orders')->findAll(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         // This provider already has an order in progress! | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         foreach ($orders as $order) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |             if ($order->getSupplier() === $articles->getSupplier()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |                 $return = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         return $return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |      * Array of file (`pdf`) layout. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |      * @param string $date  File date | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |      * @param string $title File title | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |     public function getArray($date, $title) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         $array = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |             'margin-top' => 15, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |             'header-spacing' => 5, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |             'header-font-size' => 8, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |             'header-left' => 'G.L.S.R.', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |             'header-center' => $title, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |             'header-right' => $date, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |             'header-line' => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |             'margin-bottom' => 15, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |             'footer-spacing' => 5, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |             'footer-font-size' => 8, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |             'footer-left' => 'GLSR © 2014 and beyond.', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |             'footer-right' => 'Page [page]/[toPage]', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |             'footer-line' => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |         return $array; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |      * SetOrder for the SortAction in views. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |      * @param string $name   session name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |      * @param string $entity entity name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |      * @param string $field  field name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |      * @param string $type   sort type ("ASC"/"DESC") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |     public function setOrder($name, $entity, $field, $type = 'ASC') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |         $session = new Session(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |         $session->set('sort.'.$name, array('entity' => $entity, 'field' => $field, 'type' => $type)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |      * GetOrder for the SortAction in views. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |      * @param string $name session name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |     public function getOrder($name) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |         $session = new Session(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |         return $session->has('sort.' . $name) ? $session->get('sort.' . $name) : null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 132 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 133 |  |  |  |