00001 <?php
00002
00003
00004
00005 class VotingController extends ControllerBase {
00006
00007
00008
00009 public function get_routes() {
00010 $ret = array(
00011 new InstanceReferenceRoute('http://voting/vote/{instance:inst}%', $this, 'voting_vote', new NoCacheCacheManager()),
00012 );
00013 return $ret;
00014 }
00015
00016
00017
00018
00019 public function action_voting_vote(PageData $page_data, $instance) {
00020 Session::start();
00021 Load::components('referer');
00022 $referer = Referer::current();
00023 if ($referer->is_internal()) {
00024 History::push($referer->build());
00025 }
00026 $instance = InstanceReferenceSerializier::string_to_instance($instance);
00027 if (empty($instance)) {
00028 History::go_to(0, new Status(tr('Instance you voted for not found', 'voting')));
00029 exit;
00030 }
00031
00032 if (!$page_data->has_post_data()) {
00033 History::go_to(0, new Status(tr('No vote submitted', 'voting')));
00034 exit;
00035 }
00036
00037 $created = false;
00038 Load::models('votes');
00039 $status = Votes::create($page_data->get_post()->get_array(), $instance, $created);
00040 if ($status->is_ok()) {
00041 $status = new Message(tr('Your vote has been counted', 'voting'));
00042 }
00043 History::go_to(0, $status);
00044 }
00045 }