public static function addNew($values) { $intrebare = new Intrebare(); $intrebare->question = $values['question']; $intrebare->user = Zend_Auth::getInstance()->getIdentity(); $intrebare->added = time(); if (!empty($values['location'])) { $localitate = Doctrine_Core::getTable('Localitate')->findOneByName(strtolower($values['location'])); if ($localitate) { $intrebare->localitate = $localitate; } else { $localitate = new Localitate(); $localitate->name = strtolower($values['location']); $localitate->save(); $intrebare->localitate = $localitate; } } $intrebare->save(); }
public function adaugaAction() { if (empty($this->view->user)) { throw new Exception("You have to be logged in to post a new question."); } $form = new Gasestema_Form_Intrebare_Adauga(); if ($this->getRequest()->isPost()) { if ($form->isValid($_POST)) { Intrebare::addNew($form->getValues()); $this->view->success = 1; } else { $form->populate($form->getValues()); } } $this->view->form = $form; }