/** * 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; }
public function action_review($pid) { $this->template->title = "旅ログ"; $ret = Model_Members_General::getPostHeader($pid); $first = array_shift($ret); // ******************************** if (Input::method() == 'POST') { /*-------- ユーザが入力した値とその時の時刻を保持 ------*/ $first['input_title'] = Input::post('title'); $first['input_comment'] = Input::post('comment'); $first['input_rating'] = Input::post('rating'); $time = Date::forge()->get_timestamp(); } /*----------- Validationの準備 -----------*/ //Validationオブジェクトを呼び出す $val = Validation::forge(); //フォームのルール設定 $val->add('title', 'タイトル')->add_rule('required')->add_rule('max_length', 30); $val->add('comment', 'コメント')->add_rule('required'); //コメントの長さ制限いる? $val->add('rating', '評価')->add_rule('required'); //Validationチェック if ($val->run()) { /*------------ postされた各データをDBに保存 ----------------*/ $props = array('uid' => $this->viewer_info['uid'], 'pid' => $pid, 'title' => $first['input_title'], 'comment' => $first['input_comment'], 'rating' => $first['input_rating'], 'datetime' => $time); //モデルオブジェクト作成 $new = Model_Review::forge(); $new->set($props); //データを保存する if (!$new->save()) { //保存失敗 $data['save'] = '正しく投稿できませんでした。'; } else { //保存成功 //$input_title, $input_comment, $input_rating を初期化 $first['input_title'] = ''; $first['input_comment'] = ''; $first['input_rating'] = 5.0; } } //$val->run()ここまで //Validationオブジェクトをビューに渡す $first['val'] = $val; // ******************************** $first['itta'] = Model_Members_General::countItta($pid); $first['ikitai'] = Model_Members_General::countIkitai($pid); $first['reviews'] = Model_Members_General::getReviews($pid); $first['revnum'] = Model_Members_General::countReview($pid); $first['msg'] = $this->msg; $this->template->content = View::forge('members/postlookuprev', $first); }
/** * saves the user review rates recalculating it * @return [type] [description] */ public function recalculate_rate() { if ($this->loaded()) { //get all the rates and divide by them $this->rate = Model_Review::get_user_rate($this); $this->save(); return $this->rate; } return FALSE; }
public function action_index() { $pid = 1; /* 仮 */ $uid = 1; /* 仮 */ /* 本当はレビュー投稿したヒトのuid */ //ビューに渡すデータの配列を初期化 $data = array(); if (Input::method() == 'POST') { /*-------- ユーザが入力した値とその時の時刻を保持 ------*/ $data['input_title'] = Input::post('title'); $data['input_comment'] = Input::post('comment'); $data['input_rating'] = Input::post('rating'); $time = Date::forge()->get_timestamp(); } /*----------- Validationの準備 -----------*/ //Validationオブジェクトを呼び出す $val = Validation::forge(); //フォームのルール設定 $val->add('title', 'タイトル')->add_rule('required')->add_rule('max_length', 30); $val->add('comment', 'コメント')->add_rule('required'); //コメントの長さ制限いる? $val->add('rating', '評価')->add_rule('required'); //Validationチェック if ($val->run()) { /*------------ postされた各データをDBに保存 ----------------*/ $props = array('uid' => $uid, 'pid' => $pid, 'title' => $data['input_title'], 'comment' => $data['input_comment'], 'rating' => $data['input_rating'], 'datetime' => $time); //モデルオブジェクト作成 $new = Model_Review::forge($props); //データを保存する if (!$new->save()) { //保存失敗 $data['save'] = '正しく投稿できませんでした。'; } else { //保存成功 /* 本当はルックアップページのレビュー画面に飛びたい */ Response::redirect('members/top'); } } //$val->run()ここまで //Validationオブジェクトをビューに渡す $data['val'] = $val; return View::forge('members/review', $data, false); }
public function action_index() { //template header $this->template->title = ''; // $this->template->meta_keywords = 'keywords'; $this->template->meta_description = Core::config('general.site_name') . ' ' . __('official homepage for the online store'); $products = new Model_Product(); $products->where('status', '=', Model_Product::STATUS_ACTIVE); switch (core::config('product.products_in_home')) { case 3: $id_products = Model_Review::best_rated(); $array_ids = array(); foreach ($id_products as $id => $id_product) { $array_ids = $id_product; } if (count($id_products) > 0) { $products->where('id_product', 'IN', $array_ids); } break; case 2: $id_products = array_keys(Model_Visit::popular_products()); if (count($id_products) > 0) { $products->where('id_product', 'IN', $id_products); } break; case 1: $products->where('featured', 'IS NOT', NULL)->where('featured', '>', Date::unix2mysql())->order_by('featured', 'desc'); break; case 0: default: $products->order_by('created', 'desc'); break; } $products = $products->limit(Theme::get('num_home_products', 21))->cached()->find_all(); $categs = Model_Category::get_category_count(); $this->template->bind('content', $content); $this->template->content = View::factory('pages/home', array('products' => $products, 'categs' => $categs)); }
/** * * 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')); } }
<?php defined('SYSPATH') or die('No direct script access.'); ?> <script type="application/ld+json"> <?php $structured_data = ['@context' => 'http://schema.org/', '@type' => 'Product', 'name' => $ad->title]; if ($ad->get_first_image() !== NULL) { $structured_data['image'] = $ad->get_first_image(); } if (Core::config('advertisement.description') != FALSE) { $structured_data['description'] = $ad->description; } if ($ad->price > 0) { $structured_data['offers'] = ['@type' => 'Offer', 'priceCurrency' => i18n::get_intl_currency_symbol() ? i18n::get_intl_currency_symbol() : 'USD', 'price' => number_format($ad->price, 2, ".", "")]; if (Core::config('payment.stock') and $ad->stock > 0) { $structured_data['offers']['availability'] = 'http://schema.org/InStock'; } } if (Core::config('advertisement.reviews') == 1 and $ad->rate !== NULL) { $structured_data['aggregateRating'] = ['@type' => 'AggregateRating', 'ratingValue' => $ad->rate, 'ratingCount' => Model_Review::get_ad_count_rates($ad)]; } echo json_encode($structured_data); ?> </script>
/** * 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'))); } }