| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * AbstractController controller des méthodes communes. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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\Controller; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use Doctrine\ORM\QueryBuilder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * Abstract controller | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  * @category Controller | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | abstract class AbstractController extends Controller | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      * SetOrder for the SortAction in views. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      * @param string $name  session name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |      * @param string $field field name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |      * @param string $type  sort type ("ASC"/"DESC") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     protected function setOrder($name, $field, $type = 'ASC') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         $this->getRequest()->getSession()->set('sort.' . $name, array('field' => $field, 'type' => $type)); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |      * GetOrder for the SortAction in views. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      * @param  string $name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |      * @return array | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 44 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |     protected function getOrder($name) | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |         $session = $this->getRequest()->getSession(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |         return $session->has('sort.' . $name) ? $session->get('sort.' . $name) : null; | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |      * AddQueryBuilderSort for the SortAction in views. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |      * @param QueryBuilder $qb | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |      * @param string       $name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     protected function addQueryBuilderSort(QueryBuilder $qb, $name) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         $alias = current($qb->getDQLPart('from'))->getAlias(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         if (is_array($order = $this->getOrder($name))) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |             $qb->orderBy($alias . '.' . $order['field'], $order['type']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |      * Create Delete form | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |      * @param integer                       $id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |      * @param string                        $route | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |      * @return \Symfony\Component\Form\Form | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     protected function createDeleteForm($id, $route) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         return $this->createFormBuilder(null, array('attr' => array('id' => 'delete'))) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |             ->setAction($this->generateUrl($route, array('id' => $id))) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |             ->setMethod('DELETE') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |             ->getForm() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |         ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |      * Test Inventory | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |     protected function testInventory() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |         $url = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |         $em = $this->getDoctrine()->getManager(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |         $inventories = $em->getRepository('AppBundle:Inventory')->getInventory(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |         if (empty($inventories)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |             $url = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |             // Go to installActions | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |             foreach ($inventories as $inventory) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |                 if ($inventory->getstatus() === 1 || $inventory->getStatus() === 2) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |                     $message = $this->get('translator') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |                         ->trans('yet', array(), 'gs_inventories'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |                     $this->addFlash('danger', $message); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |                     $url = 'inventory'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |                     break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |         return $url; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 109 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 110 |  |  |  | 
            
                        
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.