Created
January 7, 2012 12:08
-
-
Save vittore/1574588 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
Resources/config/doctrine | |
Fam\DiaBundle\Entity\Discussione: | |
type: entity | |
repositoryClass: Fam\DiaBundle\Repository\DiscussioneRepository | |
table: discussione | |
id: | |
id: | |
type: integer | |
generator: { strategy: AUTO } | |
fields: | |
titolo: | |
type: string | |
length: 255 | |
abilitato: | |
type: boolean | |
default: false | |
nullable: true | |
<?php | |
// Entity/Discussione | |
namespace Fam\DiaBundle\Entity; | |
use Doctrine\ORM\Mapping as ORM; | |
/** | |
* Fam\DiaBundle\Entity\Discussione | |
*/ | |
class Discussione | |
{ | |
/** | |
* @var integer $id | |
*/ | |
private $id; | |
/** | |
* @var string $titolo | |
*/ | |
private $titolo; | |
/** | |
* Get id | |
* | |
* @return integer | |
*/ | |
public function getId() | |
{ | |
return $this->id; | |
} | |
/** | |
* Set titolo | |
* | |
* @param string $titolo | |
*/ | |
public function setTitolo($titolo) | |
{ | |
$this->titolo = $titolo; | |
} | |
/** | |
* Get titolo | |
* | |
* @return string | |
*/ | |
public function getTitolo() | |
{ | |
return $this->titolo; | |
} | |
/** | |
* @var boolean $abilitato | |
*/ | |
private $abilitato; | |
/** | |
* Set abilitato | |
* | |
* @param boolean $abilitato | |
*/ | |
public function setAbilitato($abilitato) | |
{ | |
$this->abilitato = $abilitato; | |
} | |
/** | |
* Get abilitato | |
* | |
* @return boolean | |
*/ | |
public function getAbilitato() | |
{ | |
return $this->abilitato; | |
} | |
} | |
<?php | |
//Repository/DiscussioneRepository.php | |
namespace Fam\DiaBundle\Repository; | |
use Doctrine\ORM\EntityRepository; | |
use Fam\DiaBundle\Entity\Voto; | |
/** | |
* DiscussioneRepository | |
* | |
* This class was generated by the Doctrine ORM. Add your own custom | |
* repository methods below. | |
*/ | |
class DiscussioneRepository extends EntityRepository { | |
public function ricalcolaVoti($discussione_id, $voto) { | |
$em = $this->getDoctrine()->getEntityManager(); | |
$criteria = array( | |
'livello' => 1, | |
'voto' => $voto, | |
'discussione_id' => $discussione_id | |
); | |
$voti = $em->getRepository('FamDiaBundle:Voto')->findBy($criteria); | |
return sizeof($voti); | |
} | |
} | |
<?php | |
//Controller/DiscussioneController.php | |
namespace Fam\DiaBundle\Controller; | |
use Symfony\Component\HttpFoundation\Response; | |
use Symfony\Bundle\FrameworkBundle\Controller\Controller; | |
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | |
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache; | |
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; | |
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; | |
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; | |
use Symfony\Component\DependencyInjection\ContainerAware; | |
use Symfony\Component\Security\Core\SecurityContext; | |
use Symfony\Component\Security\Core\Exception\AuthenticationException; | |
use Fam\DiaBundle\Entity\Discussione; | |
use Fam\DiaBundle\Entity\Voto; | |
class DiscussioneController extends Controller { | |
/** | |
* @Route("/votaDiscussione", name="votaDiscussione") | |
* @Template | |
*/ | |
public function votaDiscussioneAction() { | |
$em = $this->getDoctrine()->getEntityManager(); | |
$repo = $em->getRepository('FamDiaBundle:Discussione'); | |
$voti=$repo->ricalcolaVoti($id,$votoDato); | |
$response = new Response(json_encode(array('voto' => $votoDato, 'voti' => $voti))); | |
$response->headers->set('Content-Type', 'application/json'); | |
return $response; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment