Exemplo n.º 1
0
 public function checkEntity($request, $includeDeleted = false, $returnArray = true)
 {
     if ($returnArray) {
         $this->entity = EntityApi::get($request->getParameter('id'), $includeDeleted);
         $this->forward404Unless($this->entity);
         $this->entity = EntityTable::loadPrimaryExtensionFields($this->entity);
     } else {
         $q = LsDoctrineQuery::create()->from('Entity e')->where('e.id = ?', $request->getParameter('id'));
         if ($includeDeleted) {
             $q->andWhere('e.is_deleted IS NOT NULL');
         }
         $this->entity = $q->fetchOne();
         $this->forward404Unless($this->entity);
     }
     //check that the entity has the given name
     $slug = $request->getParameter('slug');
     $primarySlug = LsSlug::convertNameToSlug($this->entity['name']);
     //if the name isn't primary, we redirect to the url with the primary name
     if ($slug != $primarySlug) {
         $params = $request->getParameterHolder()->getAll();
         if ($params['target'] == 'view') {
             $params['target'] = null;
         }
         $url = EntityTable::generateRoute($this->entity, $params['target'], $params);
         $this->redirect($url);
     }
 }