public function delofferAction() { $this->view->disable(); $user_id = $this->session->get('user_id'); if ($this->request->isAjax()) { $offer = Offers::findFirst($this->request->getPost('offer_id')); foreach ($offer->dannoffers as $dann) { $dann->delete(); } foreach ($offer->comments as $comment) { $comment->delete(); } foreach ($offer->favorites as $fav) { foreach (OffersHasFavorites::find(array('favorites_id = "' . $fav->id . '"')) as $favs) { $favs->delete(); } $fav->delete(); } $offer->delete(); $el = new Elements(); if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/public/upload/users/user-' . $user_id . '/offers/offer-' . $this->request->getPost('offer_id'))) { $el->delete($_SERVER['DOCUMENT_ROOT'] . '/public/upload/users/user-' . $user_id . '/offers/offer-' . $this->request->getPost('offer_id')); } } }
public function commentsAction() { $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); if ($this->request->hasPost('comm') && $this->request->hasPost('offer') && $this->request->isAjax()) { $comments = new Comments(); $comments->offers_id = $this->request->getPost('offer'); $comments->reciever_id = $this->session->get('user_id'); $comments->text = $this->request->getPost('comm'); $comments->creation_date = date("Y-m-d-H-i-s"); $comments->save(); $offer = Offers::findFirst($this->request->getPost('offer')); foreach ($offer->comments as $comm) { $com[$comm->id] = array($comm->user->first_name, $comm->text, $comm->creation_date); } $this->view->setVars(array('comm' => $com)); } }