public function action_create() { try { if (is_numeric($id_ad = $this->request->param('id'))) { if (Model_Favorite::favorite($this->user->id_user, $id_ad) === TRUE) { $this->rest_output(__('Favorite')); } else { $this->_error(__('Something went worng'), 501); } } else { $this->_error(__('Ad not provided'), 404); } } catch (Kohana_HTTP_Exception $khe) { $this->_error($khe); } }
public function action_favorites() { $user = Auth::instance()->get_user(); //favs or unfavs if (is_numeric($id_ad = $this->request->param('id'))) { $this->auto_render = FALSE; $this->template = View::factory('js'); $ad = new Model_Ad($id_ad); //ad exists if ($ad->loaded()) { //if fav exists we delete if (Model_Favorite::unfavorite($user->id_user, $id_ad) === TRUE) { //fav existed deleting $this->template->content = __('Deleted'); } else { //create the fav Model_Favorite::favorite($user->id_user, $id_ad); $this->template->content = __('Saved'); } } else { $this->template->content = __('Ad Not Found'); } } else { $this->template->title = __('My Favorites'); Breadcrumbs::add(Breadcrumb::factory()->set_title($this->template->title)); Controller::$full_width = TRUE; $this->template->styles = array('//cdn.jsdelivr.net/sweetalert/1.1.3/sweetalert.css' => 'screen'); $this->template->scripts['footer'][] = '//cdn.jsdelivr.net/sweetalert/1.1.3/sweetalert.min.js'; $this->template->scripts['footer'][] = 'js/oc-panel/favorite.js'; $favorites = new Model_Favorite(); $favorites = $favorites->where('id_user', '=', $user->id_user)->order_by('created', 'desc')->find_all(); $this->template->bind('content', $content); $this->template->content = View::factory('oc-panel/profile/favorites', array('favorites' => $favorites)); } }