public function post_rate() { $this->requiresLogin(); $this->check_input(); $event_id = $this->id + 0; if (!$event_id) { return $this->error(31); } $this->event()->get($event_id); if ($this->event()->id != $event_id) { return $this->error(31); } if ($this->event()->d_event_start > Bootstrap::$main->now) { return $this->error(59); } if ($this->event()->user == Bootstrap::$main->user['id']) { return $this->error(51); } if (!$this->event()->active) { return $this->error(62); } if ($this->event()->active == -1) { return $this->error(61); } if (!Tools::userHasAccessToEvent($event_id)) { return $this->error(19); } $model = new rateModel(); if ($model->user_has_rated_event($event_id)) { return $this->error(52); } $overall = 0; foreach (['food', 'cleanliness', 'atmosphere'] as $rate) { if (!$this->data($rate)) { return $this->error(53, $rate); } if (round($this->data($rate)) < 1 || round($this->data($rate)) > 5) { return $this->error(54, $rate); } $model->{$rate} = round($this->data($rate)); $overall += $model->{$rate}; } $model->description = $this->data('description'); $model->title = $this->data('title'); $model->user = Bootstrap::$main->user['id']; $model->event = $event_id; $model->host = $this->event()->user; $model->overall = round($overall / 3, 1); $model->d_create = Bootstrap::$main->now; $model->save(); if ($model->id) { $this->rate($model->event, true, false); $this->rate($model->event, true, true); return $this->status($model->data(), true, 'rate'); } return $this->status(null, false); }