예제 #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;
 }
예제 #2
0
 function edit($id)
 {
     $this->respondTo('html', function () use($id) {
         try {
             $author = Author::find($id);
             $session = $this->getSession();
             $inputs = $session->getOldInputBag();
             $errors = $session->getErrorBag();
             $this->render(new TwigView('admin/author/edit.html', compact('author', 'inputs', 'errors')));
         } catch (ResourceNotFoundException $e) {
             $this->getResponse()->redirect('App\\Admin\\Controllers\\AuthorController', 'index');
         }
     });
 }
예제 #3
0
 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]);
     });
 }