Example #1
0
 public static function update($id, ParameterBag $params)
 {
     $em = self::getEntityManager();
     $author = Author::find($id);
     if ($author == null) {
         throw new ResourceNotFoundException();
     }
     $author->name = $params->get('name');
     $author->updated_at = new \DateTime("now");
     $em->persist($author);
     $em->flush();
     return $this;
 }
 function delete($id)
 {
     $this->respondTo('html', function () use($id) {
         $response = $this->getResponse();
         $flash = $this->getSession()->getFlashBag();
         try {
             Author::delete($id);
             $response->redirect('App\\Admin\\Controllers\\AuthorController', 'index');
         } catch (ResourceNotFoundException $e) {
             $flash->add('errors', "Cannot find Author #{$id}");
             $response->redirect('App\\Admin\\Controllers\\AuthorController', 'index');
         } catch (\Exception $e) {
             $flash->add('errors', 'Cannot delete Author #' . $id . ' (' . $e->getMessage() . ')');
             $response->redirect('App\\Admin\\Controllers\\AuthorController', 'index');
         }
     });
 }
 public function removeAuthor($product_id, $author_id)
 {
     $this->respondTo('html', function () use($product_id, $author_id) {
         $response = $this->getResponse();
         $product = Product::find($product_id);
         $flash = $this->getSession()->getFlashBag();
         if ($product == null) {
             $flash->add('errors', "Product #{$product_id} not found");
             $response->redirect('App\\Admin\\Controllers\\ProductController', 'index');
             return;
         }
         $author = Author::find($author_id);
         if ($author == null) {
             $flash->add('errors', "Author #{$author_id} not found");
             $response->redirect('App\\Admin\\Controllers\\ProductController', 'editAuthors', [$product_id]);
             return;
         }
         if (!$product->removeAuthor($author)) {
             $flash->add('errors', "Author #{$author_id} not associated with this book");
         }
         $response->redirect('App\\Admin\\Controllers\\ProductController', 'editAuthors', [$product_id]);
     });
 }