Beispiel #1
0
 public function run()
 {
     $controller = $this->controller;
     $form = new VoteForm();
     $project = $controller->loadModel($_GET['id']);
     if (Yii::app()->request->isPostRequest) {
         $form->vote = $_POST['VoteForm']['vote'];
         $form->project = $project;
         if ($form->validate()) {
             $controller->redirect(array('project/view', 'id' => $project->id));
         }
     }
     $form->project = $project;
     $controller->render('project/vote', array('model' => $form));
 }
Beispiel #2
0
 public function executeVote(sfWebRequest $request)
 {
     $this->forward404Unless($request->isMethod('post'));
     $user = $this->getUser();
     $blog_id = $user->getAttribute('blog_id');
     $vote_form = new VoteForm();
     $bind_value = array('blog_id' => $blog_id, 'value' => $request->getParameter('vote'));
     $vote_form->bind($bind_value);
     if ($vote_form->isValid()) {
         $vote = new Vote();
         $vote->setBlog_id($vote_form->getValue('blog_id'));
         $vote->setValue($vote_form->getValue('value'));
         $vote->save();
         // Update vote_SUM
         Doctrine_Query::create()->update('Blog b')->set('b.vote_sum', 'b.vote_sum + ' . $vote_form->getValue('value'))->where('b.id = ?', $vote_form->getValue('blog_id'))->execute();
         // Update vote_COUNT
         Doctrine_Query::create()->update('Blog b')->set('b.vote_count', 'b.vote_count + 1')->where('b.id = ?', $vote_form->getValue('blog_id'))->execute();
         if (sfConfig::get('sf_exclusion_list')) {
             // Exclusion list!
             $session_list = $user->getAttribute('already_voted_list');
             if (is_array($session_list) && count($session_list) > 0) {
             } else {
                 //No data in the array
                 $session_list = array();
             }
             $session_list[] = $vote_form->getValue('blog_id');
             $user->setAttribute('already_voted_list', $session_list);
         }
         // Check if the vote history is empty it it is initiate an empty list
         $vote_history = $user->getAttribute('vote_history');
         if (is_array($vote_history) && count($vote_history) > 0) {
         } else {
             $vote_history = array();
         }
         // Add the just rated blog to the vote_history
         $voted_blog = Doctrine::getTable('Blog')->find($vote_form->getValue('blog_id'));
         $vote_avg = $voted_blog->getVote_sum() / $voted_blog->getVote_count();
         $vote_info = array('my_vote' => $vote_form->getValue('value'), 'vote_avg' => $vote_avg, 'vote_count' => $voted_blog->getVote_count(), 'vote_sum' => $voted_blog->getVote_sum(), 'blog_url' => $voted_blog->getUrl(), 'blog_thmbnail' => $voted_blog->getThumbnail_url());
         array_unshift($vote_history, $vote_info);
         $user->setAttribute('vote_history', $vote_history);
         $this->redirect('blog/index');
     }
 }
 protected function setupInheritance()
 {
     parent::setupInheritance();
     $this->widgetSchema->setNameFormat('vote_profile[%s]');
 }
 public function subscriptionsAction()
 {
     if (null === $this->_participant) {
         throw new Exception("We don't like trespassers, do you know that? Either knock the door or don't come at all...");
     }
     parent::isParticipanActive();
     $this->view->title = "Votes I'm Subscribed";
     $_voteTable = new VoteTable();
     $_votes = $_voteTable->findVotesSubscribedBy($this->_participant->id);
     $_answers = array();
     $_selectedAnswers = array();
     $_forms = array();
     foreach ($_votes as $_v) {
         $_answers[$_v->id] = $_v->findAnswers();
         $_selectedAnswers[$_v->id] = $_v->isVotedBy($this->_participant->id);
         if (null === $_selectedAnswers[$_v->id]) {
             $_f = new VoteForm();
             $_f->setAnswers($_answers[$_v->id]);
             $_f->setVote($_v->id);
             $_forms[$_v->id] = clone $_f;
         }
     }
     $this->view->votes = $_votes;
     $this->view->answers = $_answers;
     $this->view->selectedAnswers = $_selectedAnswers;
     $this->view->forms = $_forms;
 }