Example #1
0
 /**
  * Automatically executed before the widget action. Can be used to set
  * class properties, do authorization checks, and execute other custom code.
  *
  * @return  void
  */
 public function before()
 {
     $review = new Model_Review();
     $review->where('status', '=', Model_Review::STATUS_ACTIVE)->order_by('created', 'desc');
     if ($this->reviews_limit != NULL or $this->reviews_limit != '') {
         $review = $review->limit($this->reviews_limit)->cached()->find_all();
     } else {
         $review = $review->cached()->find_all();
     }
     //die(print_r($review));
     $this->review = $review;
 }
 /**
  * 
  * Display reviews advert. 
  * @throws HTTP_Exception_404
  * 
  */
 public function action_reviews()
 {
     $seotitle = $this->request->param('seotitle', NULL);
     if ($seotitle !== NULL and Core::config('advertisement.reviews') == 1) {
         $ad = new Model_Ad();
         $ad->where('seotitle', '=', $seotitle)->where('status', '!=', Model_Ad::STATUS_SPAM)->limit(1)->cached()->find();
         if ($ad->loaded()) {
             $errors = NULL;
             //adding a new review
             if ($this->request->post() and Auth::instance()->logged_in()) {
                 $user = Auth::instance()->get_user();
                 //only able to review if bought the product
                 if (Core::config('advertisement.reviews_paid') == 1) {
                     $order = new Model_Order();
                     $order->where('id_ad', '=', $ad->id_ad)->where('id_user', '=', $user->id_user)->where('id_product', '=', Model_Order::PRODUCT_AD_SELL)->where('status', '=', Model_Order::STATUS_PAID)->find();
                     if (!$order->loaded()) {
                         Alert::set(Alert::ERROR, __('You can only add a review if you bought this product'));
                         $this->redirect(Route::url('ad-review', array('seotitle' => $ad->seotitle)));
                     }
                 }
                 //not allowing to review to yourself
                 if ($user->id_user == $ad->id_user) {
                     Alert::set(Alert::ERROR, __('You can not review yourself.'));
                     $this->redirect(Route::url('ad-review', array('seotitle' => $ad->seotitle)));
                 }
                 $review = new Model_Review();
                 $review->where('id_ad', '=', $ad->id_ad)->where_open()->or_where('id_user', '=', $user->id_user)->or_where('ip_address', '=', ip2long(Request::$client_ip))->where_close()->find();
                 //d($review);
                 if (!$review->loaded()) {
                     if (captcha::check('review')) {
                         $validation = Validation::factory($this->request->post())->rule('rate', 'numeric')->rule('description', 'not_empty')->rule('description', 'min_length', array(':value', 5))->rule('description', 'max_length', array(':value', 1000));
                         if ($validation->check()) {
                             $rate = core::post('rate');
                             if ($rate > Model_Review::RATE_MAX) {
                                 $rate = Model_Review::RATE_MAX;
                             } elseif ($rate < 0) {
                                 $rate = 0;
                             }
                             $review = new Model_Review();
                             $review->id_user = $user->id_user;
                             $review->id_ad = $ad->id_ad;
                             $review->description = core::post('description');
                             $review->status = Model_Review::STATUS_ACTIVE;
                             $review->ip_address = ip2long(Request::$client_ip);
                             $review->rate = $rate;
                             $review->save();
                             //email product owner?? notify him of new review
                             $ad->user->email('ad-review', array('[AD.TITLE]' => $ad->title, '[RATE]' => $review->rate, '[DESCRIPTION]' => $review->description, '[URL.QL]' => $ad->user->ql('ad-review', array('seotitle' => $ad->seotitle))));
                             $ad->recalculate_rate();
                             $ad->user->recalculate_rate();
                             Alert::set(Alert::SUCCESS, __('Thanks for your review!'));
                         } else {
                             $errors = $validation->errors('ad');
                             foreach ($errors as $f => $err) {
                                 Alert::set(Alert::ALERT, $err);
                             }
                         }
                     } else {
                         Alert::set(Alert::ERROR, __('Wrong Captcha'));
                     }
                 } else {
                     Alert::set(Alert::ERROR, __('You already added a review'));
                 }
             }
             $this->template->scripts['footer'][] = 'js/jquery.raty.min.js';
             $this->template->scripts['footer'][] = 'js/review.js';
             Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Home'))->set_url(Route::url('default')));
             Breadcrumbs::add(Breadcrumb::factory()->set_title($ad->title)->set_url(Route::url('ad', array('seotitle' => $ad->seotitle, 'category' => $ad->category->seoname))));
             $this->template->title = $ad->title . ' - ' . __('Reviews');
             Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Reviews')));
             $this->template->meta_description = text::removebbcode($ad->description);
             $permission = TRUE;
             //permission to add hit to advert and give access rights.
             $auth_user = Auth::instance();
             if (!$auth_user->logged_in() or $auth_user->get_user()->id_user != $ad->id_user and ($auth_user->get_user()->id_role != Model_Role::ROLE_ADMIN and $auth_user->get_user()->id_role != Model_Role::ROLE_MODERATOR) or $auth_user->get_user()->id_role != Model_Role::ROLE_ADMIN and $auth_user->get_user()->id_role != Model_Role::ROLE_MODERATOR) {
                 $permission = FALSE;
                 $user = NULL;
             } else {
                 $user = $auth_user->get_user()->id_user;
             }
             $captcha_show = core::config('advertisement.captcha');
             if ($ad->get_first_image() !== NULL) {
                 Controller::$image = $ad->get_first_image();
             }
             $reviews = new Model_Review();
             $reviews = $reviews->where('id_ad', '=', $ad->id_ad)->where('status', '=', Model_Review::STATUS_ACTIVE)->find_all();
             $this->template->bind('content', $content);
             $this->template->content = View::factory('pages/ad/reviews', array('ad' => $ad, 'permission' => $permission, 'captcha_show' => $captcha_show, 'user' => $user, 'reviews' => $reviews, 'errors' => $errors));
         } else {
             //throw 404
             throw HTTP_Exception::factory(404, __('Page not found'));
         }
     } else {
         //throw 404
         throw HTTP_Exception::factory(404, __('Page not found'));
     }
 }
Example #3
0
 /**
  * user ads a new review
  * @return [type] [description]
  */
 public function action_review()
 {
     $id_order = $this->request->param('id');
     $user = Auth::instance()->get_user();
     $order = new Model_Order();
     $order->where('id_user', '=', $user->id_user)->where('id_order', '=', $id_order)->where('status', '=', Model_Order::STATUS_PAID)->limit(1)->find();
     if ($order->loaded()) {
         $product = $order->product;
         Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Purchases'))->set_url(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'orders'))));
         Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Review') . ' ' . $product->title));
         $this->template->title = __('Review product') . ' ' . $product->title;
         $this->template->scripts['footer'][] = 'js/jquery.raty.min.js';
         $this->template->scripts['footer'][] = 'js/oc-panel/review.js';
         //lets see if we had the review already done..
         $review = new Model_Review();
         $review->where('id_user', '=', $user->id_user)->where('id_product', '=', $product->id_product)->where('id_order', '=', $order->id_order)->where('status', '=', Model_Review::STATUS_ACTIVE)->limit(1)->find();
         $this->template->bind('content', $content);
         $errors = NULL;
         if ($this->request->post() and !$review->loaded()) {
             $validation = Validation::factory($this->request->post())->rule('rate', 'numeric')->rule('description', 'not_empty')->rule('description', 'min_length', array(':value', 5))->rule('description', 'max_length', array(':value', 1000));
             if ($validation->check()) {
                 $rate = core::post('rate');
                 if ($rate > Model_Review::RATE_MAX) {
                     $rate = Model_Review::RATE_MAX;
                 } elseif ($rate < 0) {
                     $rate = 0;
                 }
                 $review = new Model_Review();
                 $review->id_user = $user->id_user;
                 $review->id_order = $order->id_order;
                 $review->id_product = $product->id_product;
                 $review->description = core::post('description');
                 $review->status = Model_Review::STATUS_ACTIVE;
                 $review->ip_address = ip2long(Request::$client_ip);
                 $review->rate = $rate;
                 $review->save();
                 //email product owner?? notify him of new review
                 $product->user->email('review-product', array('[TITLE]' => $product->title, '[RATE]' => $review->rate, '[DESCRIPTION]' => $review->description, '[URL.QL]' => $product->user->ql('product-review', array('seotitle' => $product->seotitle, 'category' => $product->category->seoname))));
                 $product->recalculate_rate();
                 Alert::set(Alert::SUCCESS, __('Thanks for your review!'));
                 $this->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'orders')));
             } else {
                 $errors = $validation->errors('ad');
                 foreach ($errors as $f => $err) {
                     Alert::set(Alert::ALERT, $err);
                 }
             }
         }
         $this->template->content = View::factory('oc-panel/profile/review', array('order' => $order, 'product' => $product, 'errors' => $errors, 'review' => $review));
     } else {
         $this->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'orders')));
     }
 }