Created
November 17, 2012 01:50
-
-
Save woodworker/4092570 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Acme\ContentBundle\Entity; | |
use Doctrine\ORM\Mapping as ORM; | |
use Acme\BaseBundle\Annotations\RDF as RDF; | |
/** | |
* Acme\ContentBundle\Entity\Article | |
* | |
* @RDF\Type(name="http://schema.org/Article") | |
* @ORM\Table() | |
* @ORM\Entity(repositoryClass="Acme\ContentBundle\Entity\ArticleRepository") | |
*/ | |
class Article | |
{ | |
/** | |
* @var string $title | |
* | |
* @RDF\Property(name="http://schema.org/headline") | |
* @ORM\Column(name="title", type="string", length=255) | |
*/ | |
private $title; | |
/** | |
* @var text $introText | |
* | |
* @RDF\Property(name="http://schema.org/alternativeHeadline") | |
* @ORM\Column(name="introText", type="text") | |
*/ | |
private $introText; | |
/** | |
* @var text $mainText | |
* | |
* @RDF\Property(name="http://schema.org/text") | |
* @ORM\Column(name="mainText", type="text") | |
*/ | |
private $mainText; | |
/** | |
* @var datetime $publishDate | |
* | |
* @RDF\Property(name="http://schema.org/datePublished") | |
* @ORM\Column(name="publishDate", type="datetime") | |
*/ | |
private $publishDate; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Acme\ContentBundle\Controller; | |
use Symfony\Bundle\FrameworkBundle\Controller\Controller; | |
use Symfony\Component\HttpKernel\Exception\HttpException; | |
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | |
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; | |
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; | |
class ArticleController extends Controller | |
{ | |
/** | |
* @Route("/article/{slug}", name="content.article.show") | |
* @Method({"GET"}) | |
* @Template() | |
*/ | |
public function showAction($slug) | |
{ | |
$article = $this->getDoctrine()->getRepository('\Acme\ContentBundle\Entity\Article') | |
->findOneBySlug($slug); | |
return array('article' => $article, 'canEdit'=> true); | |
} | |
/** | |
* @Route("/article/{slug}", name="content.article.update") | |
* @Method({"PUT"}) | |
*/ | |
public function updateAction($slug) | |
{ | |
$article = $$this->getDoctrine()->getRepository('\Acme\ContentBundle\Entity\Article')->findOneBySlug($slug); | |
$json = $this->getRequest()->getContent(); | |
$obj = json_decode($json, true); | |
try { | |
$entityTranslator = new \Acme\BaseBundle\Annotations\RDF\Helper\RDFEntityTranslator($article); | |
$entityTranslator->applyData($obj); | |
/** @var $router \Symfony\Component\Routing\Router */ | |
$router = $this->get('router'); | |
$uri = $router->generate('content.article.show', array('slug' => $article->getSlug()), true); | |
$jsonLd = $entityTranslator->getJsonLdObject( $uri ); | |
$manager = $this->getDoctrine()->getManagerForClass(get_class($article)); | |
$manager->persist($article); | |
$manager->flush(); | |
return new \Symfony\Component\HttpFoundation\JsonResponse($jsonLd); | |
} catch( \Exception $e ) { | |
echo $e->getMessage(); | |
exit; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment