*/ class ProposalController extends SessionController { /** * List the proposals by type. * * @remote * @param array $params ['type'] * @return array */ public function listAction($params) { $params = array_merge($params, $this->getEnviroment()); $em = $this->get('doctrine.orm.entity_manager'); $list = $em->getRepository('PropositalBundle:Proposal')->listByType($params); return $this->createList($list); } /** * Change the proposal state. * * @remote * @param array $params ['newState','proposalId'] * @return boolean */ public function changeStateAction($params) { // get entity manager $em = $this->get('doctrine.orm.entity_manager'); // find the proposal $proposal = $em->find('PropositalBundle:Proposal',$params['proposalId']); $proposal->setState($params['newState']); // @todo: notify change // update record $em->persist($proposal); $em->flush(); return true; } /** * Remove a proposal and send it to trash. * * @remote * @param array $params ['proposalId'] * @return boolean */ public function removeAction($params) { // get entity manager $em = $this->get('doctrine.orm.entity_manager'); // find the proposal $proposal = $em->find('PropositalBundle:Proposal',$params['proposalId']); // set the trash state $proposal->setState('T'); // @todo: notify change // update record $em->persist($proposal); $em->flush(); return true; } /** * Generate the pdf document to preview a proposal and return its full * path. * * @remote * @param array $params ['proposalId'] * @return string full path of generated PDF document */ public function previewAction($params) { // @todo: implement the preview proposal method return 'http://localhost/proposital/web/pdf.txt'; } /** * Send the proposal to customer e-mail. * * @remote * @param array $params ['proposalId'] * @return boolean send status */ public function sendAction($params) { // @todo: implement the send proposal method return true; } /** * Save the proposal. * * @remote * @param array $params * @return array the saved proposal */ public function saveAction($params) { // get entity manager $em = $this->get('doctrine.orm.entity_manager'); // get the proposal $proposal = $em->getRepository('PropositalBundle:Proposal')->fromArray($params); $proposal = $this->setBasicValues($proposal, $params); // persist $em->persist($proposal); $em->flush(); // get the proposal to return it $proposal = $em->getRepository('PropositalBundle:Proposal')->getById($proposal->getId()); return $proposal; } /** * Set the basic values of a proposal. * * @param Proposal $proposal * @param array $params * @return Proposal */ private function setBasicValues($proposal, $params) { $orgId = $this->get('session')->get('organization'); // get entity manager $em = $this->get('doctrine.orm.entity_manager'); // get proposal associations $receiver = $em->getRepository('PropositalBundle:Account')->getEntityByName($params['receiver']); $customer = $em->getRepository('PropositalBundle:Organization')->getEntityByName($params['customer'],$receiver); $organization = $em->find('PropositalBundle:Organization', $orgId); // set propoerties if (($params['id']) == 0) { $proposal->setDtCreate(new \DateTime()); $proposal->setState('E'); $proposal->setNumber('2011-03-0006-1'); } // set associations $proposal->setCustomer($customer); $proposal->setReceiver($receiver); $proposal->setOrganization1($organization); return $proposal; } }