Exemple #1
0
 public function loadFromForm(CreateVoteForm $f)
 {
     $this->name = $f->getVname();
     $this->desc = $f->getDesc();
     $this->begin_date = $f->getBegindate();
     $this->expire_date = $f->getExpiredate();
 }
 public function voteeditAction()
 {
     $this->view->title = "Create New/Change";
     $_action = $this->getRequest()->getParam("act");
     $_vid = $this->getRequest()->getParam("vid");
     $_t = new VoteTable();
     $_form = new CreateVoteForm();
     $this->view->answers = array();
     $this->view->answerEditingEnabled = false;
     if ($_action === "del") {
         $_t->deleteById($_vid);
         $this->_redirect(APPLICATION_BASEURL_INDEX . "/admin/vote");
     } else {
         if ($_action === "edit") {
             //TODO: fill the form with actual values...
             $_vote = $_t->findById($_vid);
             $_form->loadFromModel($_vote);
             $this->view->answers = $_vote->findAnswers();
         } else {
             if ($_action === "create") {
                 $this->view->answerEditingEnabled = true;
             } else {
                 if ($_action === "save") {
                     $_vote = null;
                     if ($_vid != "") {
                         $_vote = $_t->findById($_vid);
                         $_form->loadFromModel($_vote);
                     }
                     if ($_form->isValid($_POST)) {
                         if ($_vid == "") {
                             $_vote = $_t->createRow();
                             $_vote->loadFromForm($_form);
                             $_newVid = $_vote->insert();
                             //Now Let's go for the answers...
                             $_answerList = $_form->getAnswersAsArray();
                             $_answerTable = new AnswersTable();
                             foreach ($_answerList as $_text) {
                                 $_answerRow = $_answerTable->createRow();
                                 $_answerRow->vote_id = $_newVid;
                                 $_answerRow->text = $_text;
                                 $_answerRow->vote_count = 0;
                                 $_answerRow->insert();
                             }
                         } else {
                             $_vote->loadFromForm($_form);
                             $_vote->save();
                         }
                         $this->_redirect(APPLICATION_BASEURL_INDEX . "/admin/vote");
                     } else {
                         $this->view->errorMsg = "Correct the errors below...";
                     }
                 }
             }
         }
     }
     $this->view->form = $_form;
 }