コード例 #1
0
ファイル: cars.php プロジェクト: lz1988/stourwebcms
 public function action_index()
 {
     //车型分类
     $cartype = ORM::factory('car_kind')->order_by("displayorder", 'asc')->get_all();
     //租车类型
     $carattr = ORM::factory('car_attr')->where("pid=0 and isopen=1")->order_by("displayorder", 'asc')->get_all();
     if (!empty($carattr)) {
         foreach ($carattr as $key => $value) {
             $carattr[$key]['nextlist'] = ORM::factory('car_attr')->where("pid=" . $value['id'] . " and isopen=1")->order_by("displayorder", 'asc')->get_all();
         }
     }
     //租车价格
     $carpricelist = ORM::factory('car_pricelist')->order_by("id", 'asc')->get_all();
     //推荐租车信息
     //$list = ORM::factory('car')->select(array('id','id'))->where("ishidden=0 and carprice>0")->order_by("displayorder",'asc')->limit("0,4")->get_all();
     $list = DB::select_array(array('id', 'title', 'litpic', 'price'))->from('car')->where("ishidden=0 and price>0")->order_by("displayorder", 'asc')->limit("0,4")->execute()->as_array();
     if (empty($list)) {
         $sql = "SELECT a.id,a.title,a.litpic,min(b.adultprice) as carprice FROM sline_car a LEFT JOIN sline_car_suit_price b ON (b.carid = a.id and b.adultprice!=0) WHERE a.ishidden=0 GROUP BY a.id ORDER BY a.displayorder ASC limit 0,4 ";
         $query = DB::query(Database::SELECT, $sql);
         $list = $query->execute()->as_array();
     }
     foreach ($list as $key => $value) {
         if (empty($value['litpic'])) {
             $list[$key]['litpic'] = Common::getDefaultImage();
         }
     }
     //数据压入
     $this->assign('cartype', $cartype);
     $this->assign('carattr', $carattr);
     $this->assign('carpricelist', $carpricelist);
     $this->assign('list', $list);
     $this->display('cars/index');
 }
コード例 #2
0
ファイル: api.php プロジェクト: uzura8/flockbird
 /**
  * News detail
  * 
  * @access  public
  * @return  Response
  */
 public function get_detail($slug = null)
 {
     $cols = array('news.id', 'news.news_category_id', 'news.title', 'news.body', 'news.format', 'news.published_at', 'news.slug', array('news_category.name', 'news_category_name'), array('news_category.label', 'news_category_label'));
     $query = \DB::select_array($cols)->from('news')->join('news_category', 'LEFT')->on('news_category.id', '=', 'news.news_category_id')->where('slug', $slug)->and_where('is_published', 1);
     if (!($response = $query->execute()->current())) {
         throw new \HttpNotFoundException();
     }
     $response['body'] = convert_body_by_format($response['body'], $response['format']);
     unset($response['format']);
     $cols = array('news_image.name', array('file.name', 'file_name'), array('file.type', 'file_type'));
     $query = \DB::select_array($cols)->from('news_image')->join('file', 'LEFT')->on('file.name', '=', 'news_image.file_name')->where('news_id', $response['id']);
     $response['images'] = self::add_file_options($query->execute()->as_array(), 'img');
     $cols = array('news_file.name', array('file.name', 'file_name'), array('file.original_filename', 'file_original_filename'), array('file.type', 'file_type'));
     $query = \DB::select_array($cols)->from('news_file')->join('file', 'LEFT')->on('file.name', '=', 'news_file.file_name')->where('news_id', $response['id']);
     $response['files'] = self::add_file_options($query->execute()->as_array(), 'file');
     $cols = array('uri', 'label');
     $query = \DB::select_array($cols)->from('news_link')->where('news_id', $response['id']);
     $response['links'] = $query->execute()->as_array();
     if (\Config::get('news.tags.isEnabled')) {
         $cols = array('tag.name');
         $query = \DB::select_array($cols)->from('news_tag')->join('tag', 'LEFT')->on('tag.id', '=', 'news_tag.tag_id')->where('news_id', $response['id']);
         $response['tags'] = $query->execute()->as_array();
     }
     return $this->response($response);
 }
コード例 #3
0
ファイル: role.php プロジェクト: anqh/core
 /**
  * Load role
  *
  * @param  integer|string  $id
  */
 public function __construct($id = null)
 {
     parent::__construct();
     if ($id !== null) {
         $this->load(DB::select_array($this->fields())->where(is_numeric($id) ? 'id' : 'name', '=', $id));
     }
 }
コード例 #4
0
ファイル: dblog.php プロジェクト: nexeck/kohana-dblog
	protected function get_filter_type() {
		$types = DB::select_array(array('type'))
			->distinct(TRUE)
			->from(Kohana::config('dblog.table'))
			->execute()
			->as_array('type', 'type');
		return Arr::merge($types, array('' => __('any')));
	}
コード例 #5
0
ファイル: api.php プロジェクト: anqh/core
 /**
  * Action: search
  */
 public function action_search()
 {
     $this->data['users'] = array();
     // Search term
     $term = trim(Arr::get($_REQUEST, 'q', ''));
     // Search fields
     $search = explode(':', Arr::get($_REQUEST, 'search', 'username'));
     // Result limit
     $limit = (int) Arr::get($_REQUEST, 'limit', 25);
     // Result order
     $order = Arr::get($_REQUEST, 'order', 'username.asc');
     // Result fields
     $field = explode(':', Arr::get($_REQUEST, 'field', 'id:username'));
     // Term must be at least 2 characters
     if (strlen($term) >= 2) {
         // 500 events max
         $limit = min($limit, 500);
         // Get order
         $orders = $this->_prepare_order($order, self::$_orderable);
         $orders = empty($orders) ? array('username' => 'asc') : $orders;
         // Get fields
         $fields = empty($field) ? self::$_fields : array_intersect($field, self::$_fields);
         $fields = empty($fields) ? array('id', 'username') : $fields;
         // Get search
         $searches = empty($search) ? self::$_searchable : array_intersect($search, self::$_searchable);
         $searches = empty($searches) ? array('username') : $searches;
         // Build query
         $user = new Model_User();
         $users = DB::select_array($user->fields());
         // Find friends first
         if ($user_id = Arr::get($_REQUEST, 'user', 0)) {
             $users->join('friends', 'LEFT')->on('users.id', '=', 'friends.friend_id')->on('friends.user_id', '=', DB::expr((int) $user_id))->order_by('friends.created', 'ASC');
         }
         foreach ($orders as $column => $direction) {
             $users->order_by($column, $direction);
         }
         $users->where_open();
         foreach ($searches as $search) {
             $search_term = $term;
             switch ($search) {
                 case 'city':
                     $search = 'city_name';
                     break;
                 case 'username':
                     $search = 'username_clean';
                     $search_term = Text::clean($term);
                     break;
             }
             $users->or_where($search, 'ILIKE', '%' . $search_term . '%');
         }
         $users->where_close();
         // Build data
         foreach ($user->load($users, $limit) as $user) {
             $this->data['users'][] = $this->_prepare_user($user, $fields);
         }
     }
 }
コード例 #6
0
ファイル: newsfeeditem.php プロジェクト: anqh/core
 /**
  * Find Newsfeed items.
  *
  * @static
  * @param   integer  $limit
  * @param   array    $users  User ids
  * @return  Database_Result
  */
 public static function find_items($limit = 20, array $users = null)
 {
     $newsfeeditem = new Model_NewsfeedItem();
     $query = DB::select_array($newsfeeditem->fields())->order_by('id', 'DESC');
     if (is_array($users)) {
         $query = $query->where('user_id', 'IN', $users);
     }
     return $newsfeeditem->load($query, $limit);
 }
コード例 #7
0
ファイル: web2auth_Test.php プロジェクト: hypayrole/web2auth
 /**
  * メールアドレス、パスワードの整合性テスト
  * 
  * @dataProvider login_user_data_provider
  */
 public function test_validate_user($input, $expected)
 {
     $test = Auth::instance()->validate_user($input['email'], $input['password']);
     if ($expected['id']) {
         $expected = \DB::select_array(\Config::get('web2auth.table_columns', array('*')))->where('id', '=', $expected['id'])->from(\Config::get('web2auth.table_name'))->execute(\Config::get('web2auth.db_connection'))->current();
     } else {
         $expected = false;
     }
     $this->assertEquals($expected, $test);
 }
コード例 #8
0
ファイル: notification.php プロジェクト: anqh/anqh
 /**
  * Find Notifications for user.
  *
  * @static
  * @param   Model_User  $target
  * @return  Model_Notification[]
  */
 public function find_by_target(Model_User $target)
 {
     // User notifications
     $query = DB::select_array($this->fields())->where('target_id', '=', $target->id)->order_by('id', 'DESC');
     // Admin notifications
     if ($target->has_role('admin', 'photo moderator')) {
         $query = $query->or_where_open()->where('class', '=', Notification_Galleries::CLASS_GALLERIES)->and_where('type', '=', Notification_Galleries::TYPE_IMAGE_REPORT)->or_where_close();
     }
     return $this->load($query, 0);
 }
コード例 #9
0
 public function force_login($user_id = '')
 {
     if (empty($user_id)) {
         return false;
     }
     $this->user = \DB::select_array(\Config::get('complexauth.table_columns', array('*')))->from(\Config::get('complexauth.table_name'))->where('id', '=', $user_id)->execute(\Config::get('complexauth.db_connection'))->current();
     if ($this->user == false) {
         $this->user = \Config::get('complexauth.guest_login', true) ? static::$guest_login : false;
         \Session::delete(\Config::get('complexauth.username_post_key'));
         return false;
     }
     \Session::set(\Config::get('complexauth.username_post_key'), $this->user[\Config::get('complexauth.username_post_key')]);
     return true;
 }
コード例 #10
0
ファイル: sql.php プロジェクト: notfoundsam/yahooauc
 public static function run()
 {
     try {
         $users = \DB::select_array(['id', 'username'])->from('users')->execute();
         \DB::start_transaction();
         foreach ($users as $user) {
             \DB::update('auctions')->value('won_user', $user['id'])->where('won_user', '=', $user['username'])->execute();
         }
         \DB::commit_transaction();
         \DBUtil::modify_fields('auctions', ['won_user' => ['constraint' => 11, 'type' => 'int', 'name' => 'user_id']]);
     } catch (Exception $e) {
         \DB::rollback_transaction();
     }
 }
コード例 #11
0
ファイル: newsfeeditem.php プロジェクト: anqh/anqh
 /**
  * Find Newsfeed items.
  *
  * @static
  * @param   integer  $limit
  * @param   array    $users  User ids
  * @return  Model_NewsfeedItem[]
  */
 public static function find_items($limit = 20, array $users = null)
 {
     $newsfeeditem = new Model_NewsfeedItem();
     $query = DB::select_array($newsfeeditem->fields())->order_by('stamp', 'DESC');
     if (is_array($users)) {
         $query = $query->where('user_id', 'IN', $users);
         // Include friend events
         $friend_ids = array();
         foreach ($users as $user_id) {
             $friend_ids[] = json_encode(array('friend_id' => $user_id));
         }
         $query = $query->or_where_open()->where('class', '=', 'user')->and_where('type', '=', 'friend')->and_where('data', 'IN', $friend_ids)->or_where_close();
     }
     return $newsfeeditem->load($query, $limit);
 }
コード例 #12
0
ファイル: auth.php プロジェクト: vano00/jobs
 public function action_reset_password()
 {
     if (\Input::post()) {
         $to = trim(\Input::post('email'));
         $user = \DB::select_array(\Config::get('simpleauth.table_columns', array('*')))->where('email', '=', $to)->from(\Config::get('simpleauth.table_name'))->as_object()->execute(\Config::get('simpleauth.db_connection'))->current();
         $data['password'] = \Auth::reset_password($user->username);
         $val = \Validation::forge();
         $val->add_field('email', 'email', 'required|valid_email');
         if ($val->run()) {
             // Create an instance
             $email = \Email::forge();
             // Set the from address
             $email->from('*****@*****.**', 'Les RHs');
             // Set the to address
             $email->to($to);
             // Set a subject
             $email->subject('New password');
             // And set the body.
             $email->html_body(\View::forge('email/template.twig', $data));
             try {
                 $email->send();
             } catch (\EmailValidationFailedException $e) {
                 // The validation failed
             } catch (\EmailSendingFailedException $e) {
                 // The driver could not send the email
             }
             \Session::set_flash('success', 'A new password has been sent');
             \Response::redirect('/');
         } else {
             // repopulate the email field and give some error text back to the view.
             $data['email'] = $to;
             \Session::set_flash('error', $val->error());
         }
     }
     $data['actions'] = ['back' => ['label' => 'Back', 'url' => 'auth']];
     $this->template->title = "Reset password";
     $this->template->content = \View::forge('auth/password.twig', $data);
 }
コード例 #13
0
ファイル: group.php プロジェクト: anqh/forum
 /**
  * Find all groups
  *
  * @return  Model_Forum_Group[]
  */
 public function find_all()
 {
     return $this->load(DB::select_array($this->fields())->where('status', '=', self::STATUS_NORMAL)->order_by('sort', 'ASC'), null);
 }
コード例 #14
0
ファイル: note.php プロジェクト: anqh/core
 /**
  * Get new notes
  *
  * @param   Model_User  $user
  * @return  Database_Result
  */
 public function find_new_notes(Model_User $user)
 {
     return $this->load(DB::select_array($this->fields())->where('user_id', '=', $user->id)->and_where('new_note', '>', 0), null);
 }
コード例 #15
0
ファイル: dbutil.php プロジェクト: wushian/MDD
 /**
  * Checks if given field(s) in a given table exists.
  *
  * @param   string         $table    Table name
  * @param   string|array   $columns  columns to check
  * @return  bool
  */
 public static function field_exists($table, $columns, $db = null)
 {
     if (!is_array($columns)) {
         $columns = array($columns);
     }
     try {
         \DB::select_array($columns)->from($table)->limit(1)->execute($db ? $db : static::$connection);
         return true;
     } catch (\Database_Exception $e) {
         return false;
     }
 }
コード例 #16
0
ファイル: dbutil.php プロジェクト: SainsburysTests/sainsburys
 /**
  * Checks if given field(s) in a given table exists.
  *
  * @param   string          $table      Table name
  * @param   string|array    $columns    columns to check
  * @param   string          $db         the database connection to use
  * @return  bool
  */
 public static function field_exists($table, $columns, $db = null)
 {
     if (!is_array($columns)) {
         $columns = array($columns);
     }
     try {
         \DB::select_array($columns)->from($table)->limit(1)->execute($db ? $db : static::$connection);
         return true;
     } catch (\Database_Exception $e) {
         // check if we have a DB connection at all
         $connection = \Database_Connection::instance($db ? $db : static::$connection)->has_connection();
         // if no connection could be made, re throw the exception
         if (!$connection) {
             throw $e;
         }
         return false;
     }
 }
コード例 #17
0
ファイル: site.php プロジェクト: lz1988/stourwebcms
 public function action_ajax_get()
 {
     $webid = Arr::get($_GET, 'webid');
     $arr = DB::select_array(array('id', 'kindname', 'weburl', 'webroot', 'webprefix'))->from('destinations')->where("iswebsite=1 and isopen=1")->order_by("displayorder", 'asc')->execute()->as_array();
     $out = array();
     foreach ($arr as $row) {
         $tr = '
               <tr>
               <td height="40" align="center">' . $row['id'] . '</td>
               <td class="pl-30">' . $row['kindname'] . '</td>
               <td align="left"><input type="text"  name="weburl[]" class="tb-text text_300 pl-5" value="' . $row['weburl'] . '" /></td>
               <td align="center"><a href="javascript:;" class="row-mod-btn" onclick="addmenu(' . $row['id'] . ',\'' . $row['kindname'] . '\',this);"></a></td>
               <td align="center" onclick="del(' . $row['id'] . ',this);">' . Common::getIco('show') . '<input type="hidden" name="id[]" value="' . $row['id'] . '"/></td>
             </tr>
         ';
         array_push($out, $tr);
     }
     echo json_encode(array('trlist' => $out));
 }
コード例 #18
0
ファイル: api.php プロジェクト: anqh/anqh
 /**
  * Action: search
  */
 public function action_search()
 {
     $this->data['venues'] = array();
     $term = trim(Arr::get($_REQUEST, 'q', ''));
     $search = explode(':', Arr::get($_REQUEST, 'search', 'name'));
     $limit = (int) Arr::get($_REQUEST, 'limit', 25);
     $order = Arr::get($_REQUEST, 'order', 'name.asc');
     $field = explode(':', Arr::get($_REQUEST, 'field', 'id:name:city'));
     // Term must be at least 2 characters
     if (strlen($term) >= 3) {
         // 500 events max
         $limit = min($limit, 500);
         // Get order
         $orders = $this->_prepare_order($order, self::$_orderable);
         $orders = empty($orders) ? array('name' => 'asc') : $orders;
         // Get fields
         $fields = empty($field) ? self::$_fields : array_intersect($field, self::$_fields);
         $fields = empty($fields) ? array('id', 'name') : $fields;
         // Get search
         $searches = empty($search) ? self::$_searchable : array_intersect($search, self::$_searchable);
         $searches = empty($searches) ? array('name') : $searches;
         // Build query
         $venue = new Model_Venue();
         $venues = DB::select_array($venue->fields());
         foreach ($orders as $column => $direction) {
             $venues->order_by($column, $direction);
         }
         $venues->where_open();
         foreach ($searches as $search) {
             if ($search == 'city') {
                 $search .= '_name';
             }
             $venues->or_where($search, 'ILIKE', '%' . $term . '%');
         }
         $venues->where_close();
         // Build data
         foreach ($venue->load($venues, $limit) as $venue) {
             $this->data['venues'][] = $this->_prepare_venue($venue, $fields);
         }
     }
 }
コード例 #19
0
ファイル: entry.php プロジェクト: anqh/blog
 /**
  * Get new blog comments count for user.
  *
  * @param   Model_User  $user
  * @return  Database_Result
  */
 public function find_new_comments(Model_User $user)
 {
     return $this->load(DB::select_array($this->fields())->where('author_id', '=', $user->id)->and_where('new_comment_count', '>', 0), null);
 }
コード例 #20
0
ファイル: image.php プロジェクト: anqh/core
 /**
  * Get image notes
  *
  * @return  Database_Result
  */
 public function notes()
 {
     return $this->find_related('image_notes', DB::select_array(Model_Image_Note::factory()->fields())->order_by('x', 'ASC')->order_by('id', 'ASC'));
 }
コード例 #21
0
ファイル: product.php プロジェクト: EdgeCommerce/edgecommerce
 /**
  * Get product data (code, price, attributes, images)
  * 
  * @access  public
  * @param   $product   object
  * @return  
  */
 public static function product_data($product = false, $attributes_json = null, $post_select = false, $attributeid = false)
 {
     if (!$product) {
         return;
     }
     $out['current_attributes'] = null;
     $out['code'] = null;
     $out['images'] = null;
     $out['select'] = null;
     $out['select_name'] = null;
     $out['sx'] = null;
     // select (attribute) order
     $out['retail_price'] = null;
     $out['sale'] = null;
     $out['price'] = 0;
     $out['price_type'] = null;
     $current_attributes = array();
     $select = array();
     $select_name = array();
     $sx = array();
     $options = array();
     if (json_decode($attributes_json) != null) {
         $current_attributes = Model_Attribute::find(array('where' => array('attributes' => $attributes_json, 'product_id' => $product->id, 'active' => 1), 'limit' => 1));
     }
     //get attributes per product
     $prod_attributes = \Product\Model_Attribute::find_by_product_id($product->id);
     $a_attribute_ids = array();
     if ($prod_attributes) {
         foreach ($prod_attributes as $attr_id) {
             array_push($a_attribute_ids, $attr_id->id);
         }
     }
     // NRB-Gem: if current URL is Pricing Group -> Products
     // Get pricing_attribute_price from current Pricing Group
     // Products can belong to multiple Pricing Groups
     $a_groups = \Sentry::user()->groups();
     if ($a_attribute_ids) {
         if (\Sentry::check()) {
             $a_cond = array(array('product_attribute_id', 'in', $a_attribute_ids));
             if (\Uri::segment(2) != 'admin' && \Sentry::user()->groups() && $a_groups[0]) {
                 $a_cond['user_group_id'] = $a_groups[0]['id'];
             }
             if (\Uri::segment(3) == 'group' && \Uri::segment(4) == 'products') {
                 $a_cond['pricing_group_id'] = \Uri::segment(5);
             }
             $product_sale_price = \Product\Model_Attribute_Price::find(array('where' => $a_cond));
         }
     }
     // NRB-Gem: check if logged in user can buy product for discounted rate
     if (\Uri::segment(2) != 'admin' && \Sentry::user()->groups() && !\Sentry::user()->is_admin() && $a_groups[0]) {
         $o_product_group_options = \DB::select_array(array('able_to_buy'))->from('product_group_options')->join('product_to_groups')->on('product_group_options.product_group_id', '=', 'product_to_groups.group_id')->where('product_group_options.user_group_id', $a_groups[0]['id'])->where('able_to_buy', 1)->where('product_to_groups.product_id', $product->id)->execute();
         $a_result = $o_product_group_options->as_array();
         $product_sale_price = $a_result && $a_result[0]['able_to_buy'] ? $product_sale_price : false;
     }
     // Get all product attributes
     $product_attributes = Model_Product::get_product_attributes($product);
     // Product with attributes
     if ($product_attributes) {
         // Set current attribute
         if ($current_attributes && isset($product_attributes[$current_attributes[0]->id])) {
             $current_attributes = $product_attributes[$current_attributes[0]->id];
         } elseif ($post_select && count($post_select) > 1) {
             foreach ($post_select as $sk => $sv) {
                 if (!isset($post_select_pop)) {
                     $post_select_pop = $post_select;
                     array_pop($post_select_pop);
                 }
                 $count = count($post_select_pop);
                 foreach ($product_attributes as $pk => $pv) {
                     $i = 0;
                     $not_exists = array();
                     foreach ($pv as $pkk => $pvv) {
                         if ($i >= $count) {
                             continue;
                         }
                         if (!isset($post_select_pop[$pvv->attribute->id]) || $post_select_pop[$pvv->attribute->id] != $pvv->option->id) {
                             $not_exists[] = true;
                         }
                         $i++;
                     }
                     if (empty($not_exists)) {
                         $current_attributes = $product_attributes[$pk];
                         break 2;
                     }
                 }
                 if (empty($current_attributes) && $count > 1) {
                     array_pop($post_select_pop);
                 }
             }
             if (empty($current_attributes)) {
                 $current_attributes = reset($product_attributes);
             }
         } elseif ($product->default_attributes) {
             $current_attributes = $product_attributes[reset($product->default_attributes)->id];
         } else {
             $current_attributes = reset($product_attributes);
         }
         foreach ($current_attributes as $k => $v) {
             $options[] = $v->option->id;
         }
         foreach ($product_attributes as $k => $v) {
             if (is_array($v)) {
                 foreach ($v as $kk => $vv) {
                     $select_name[$vv->attribute->id] = $vv->attribute->name != '' ? $vv->attribute->name : $vv->attribute->title;
                     $select_tmp[$k][$vv->attribute->id][$vv->option->id] = $vv->option->title;
                     foreach ($options as $option_key => $option_value) {
                         if ($kk == $option_key) {
                             $select[$vv->attribute->id][$vv->option->id] = $vv->option->title;
                             if ($vv->option->id != $option_value) {
                                 continue 3;
                             }
                         }
                     }
                 }
             }
         }
         if ($select) {
             $sx = array_keys($select_name);
         }
         $b_use_original_price = false;
         if (!empty($current_attributes)) {
             $attr_obj = $current_attributes[0]->product_attribute;
             $out['current_attributes'] = $current_attributes;
             $out['code'] = $attr_obj->product_code;
             if (!empty($attr_obj->images)) {
                 $out['images'] = $attr_obj->images;
             }
             $out['select'] = $select;
             $out['select_name'] = $select_name;
             $out['sx'] = $sx;
             $out['stock_quantity'] = $attr_obj->stock_quantity;
             $out['retail_price'] = $attr_obj->retail_price;
             // NRB-Gem: changed condition from: (!empty($product_sale_price) && $product_sale_price[0]->price != 0)
             // fix for attributes with sale price are not displayed
             if (!empty($product_sale_price)) {
                 $out['with_attr'] = array('attribute' => array());
                 foreach ($product_sale_price as $with_attr) {
                     $out['with_attr']['able_discount'][$with_attr->product_attribute_id] = $with_attr->able_discount;
                     if ($out['with_attr']['able_discount'][$with_attr->product_attribute_id]) {
                         $out['with_attr']['discount'][$with_attr->product_attribute_id] = $with_attr->discount;
                         $out['with_attr']['price'][$with_attr->product_attribute_id] = $with_attr->price;
                     }
                     $out['with_attr']['attribute'][$with_attr->product_attribute_id] = '';
                     foreach ($product_attributes as $o_prod_attr) {
                         $a_attr = array();
                         foreach ($o_prod_attr as $o_attr) {
                             if ($with_attr->product_attribute_id == $o_attr->product_attribute->id) {
                                 $a_attr[] = $o_attr->option->title;
                             }
                         }
                         $out['with_attr']['attribute'][$with_attr->product_attribute_id] .= implode(' | ', $a_attr);
                     }
                     // NRB-Gem: do not display inactive attribute
                     if (empty($out['with_attr']['attribute'][$with_attr->product_attribute_id])) {
                         unset($out['with_attr']['attribute'][$with_attr->product_attribute_id]);
                         unset($out['with_attr']['able_discount'][$with_attr->product_attribute_id]);
                         unset($out['with_attr']['discount'][$with_attr->product_attribute_id]);
                         unset($out['with_attr']['price'][$with_attr->product_attribute_id]);
                     }
                 }
                 // NRB-Gem: get default prices
                 foreach ($prod_attributes as $attr) {
                     if (isset($out['with_attr']['discount'][$attr->id]) && $out['with_attr']['discount'][$attr->id] > 0) {
                         $out['with_attr']['price'][$attr->id] = $attr->retail_price - $attr->retail_price * ($out['with_attr']['discount'][$attr->id] / 100);
                     } else {
                         if (isset($out['with_attr']['price'][$attr->id]) && !$out['with_attr']['price'][$attr->id]) {
                             $out['with_attr']['price'][$attr->id] = $attr->sale_price ? $attr->sale_price : $attr->retail_price;
                         }
                     }
                 }
                 $out['sale'] = \Product\Model_Product::calculate_discount($product, $product_sale_price[0]->discount);
                 $out['price'] = \Product\Model_Product::calculate_discount($product, $product_sale_price[0]->price);
                 $out['price_type'] = 'sale_price';
                 // NRB-Gem: Set discounted rate from product_attribute_price Product attributes
                 if ($attributes_json) {
                     foreach ($current_attributes as $o_attribute) {
                         if ($o_attribute->product_attribute->attributes == $attributes_json) {
                             if ($out['with_attr']['able_discount'][$o_attribute->product_attribute->id]) {
                                 if ($out['with_attr']['discount'][$o_attribute->product_attribute->id] > 0) {
                                     $out['price'] = $out['retail_price'] - $out['retail_price'] * ($out['with_attr']['discount'][$o_attribute->product_attribute->id] / 100);
                                 } else {
                                     $out['price'] = $out['with_attr']['price'][$o_attribute->product_attribute->id];
                                 }
                             } else {
                                 $b_use_original_price = true;
                             }
                         }
                     }
                 }
             } else {
                 $out['price'] = \Product\Model_Product::calculate_discount($product, $attr_obj->retail_price);
                 $out['price_type'] = 'retail_price';
                 $b_use_original_price = true;
             }
             // NRB-Gem: Display original price if Discount price is not enabled (used by non-ajax request)
             if (\Uri::segment(1) == 'product' && !$attributes_json) {
                 $a_prod_attr_keys = array_keys($product_attributes);
                 $attr_id = $a_prod_attr_keys[0];
                 if (isset($out['with_attr']['able_discount'][$attr_id])) {
                     if (isset($out['with_attr']['discount']) && $out['with_attr']['discount'][$attr_id] > 0) {
                         $out['price'] = $out['retail_price'] - $out['retail_price'] * ($out['with_attr']['discount'][$attr_id] / 100);
                     } else {
                         $out['price'] = isset($out['with_attr']['price']) ? $out['with_attr']['price'][$attr_id] : '';
                     }
                 } else {
                     $b_use_original_price = true;
                     $attributes_json = true;
                 }
             }
             // NRB-Gem: Set original discounted rate for Product attributes
             if ($b_use_original_price && $attributes_json) {
                 if ($attr_obj->sale_price > 0) {
                     $out['price'] = $attr_obj->sale_price;
                     $out['price_type'] = 'sale_price';
                 } else {
                     $out['price'] = $attr_obj->retail_price;
                     unset($out['price_type']);
                 }
             }
         }
     } else {
         $p = $product->attributes[0];
         $out['current_attributes'] = null;
         $out['code'] = $p->product_code;
         $out['images'] = $p->images;
         $out['retail_price'] = $p->retail_price;
         $out['stock_quantity'] = $p->stock_quantity;
         $out['able_discount'] = isset($product_sale_price[0]) ? $product_sale_price[0]->able_discount : 0;
         if (!empty($product_sale_price) && $product_sale_price[0]->price != 0) {
             if ($out['able_discount']) {
                 $out['sale'] = \Product\Model_Product::calculate_discount($p, $product_sale_price[0]->discount);
                 $out['price'] = \Product\Model_Product::calculate_discount($p, $product_sale_price[0]->price);
             }
             $out['price_type'] = 'sale_price';
         } else {
             $out['sale'] = isset($product_sale_price[0]) ? $product_sale_price[0]->discount : 0;
             $out['price'] = \Product\Model_Product::calculate_discount($product, $p->retail_price);
             $out['price_type'] = 'retail_price';
         }
         // NRB-Gem: Display original price if Discount price is not enabled
         if ($out['able_discount']) {
             if ($product_sale_price[0]->discount > 0) {
                 $out['price'] = $p->retail_price - $p->retail_price * ($product_sale_price[0]->discount / 100);
             }
         } else {
             if ($p->sale_price > 0) {
                 $out['price'] = $p->sale_price;
                 $out['price_type'] = 'sale_price';
             } else {
                 unset($out['price_type']);
                 $out['price'] = $p->retail_price;
             }
         }
     }
     $prod_category = Model_Product_To_Categories::find_by_product_id($product->id);
     $category = \Product\Model_Category::find_one_by_id($prod_category[0]->category_id);
     $out['category_id'] = $prod_category ? $prod_category[0]->category_id : null;
     $out['category'] = $category ? $category->title : null;
     // Product without attributes
     if (empty($out['current_attributes'])) {
         $out['code'] = $product->code;
     }
     // Set images from product if there is no images in product attribute
     if (empty($out['images']) && !empty($product->images)) {
         $out['images'] = $product->images;
     }
     return $out;
 }
コード例 #22
0
ファイル: Common.php プロジェクト: shumeiko/dtapi
 /**
  * Select one record from database
  *
  * @param int $record_id - primary key of $this->tableName table
  * @return mysql_object - record object
  */
 public function getRecord($record_id)
 {
     $query = DB::select_array($this->fieldNames)->from($this->tableName)->where($this->fieldNames[0], "=", $record_id);
     $result = $query->as_object()->execute();
     return $result;
 }
コード例 #23
0
ファイル: forum.php プロジェクト: anqh/anqh
 /**
  * Find new private messages
  *
  * @static
  * @param   Model_User $user
  * @return  Model_Forum_Private_Recipient[]
  */
 public static function find_new_private_messages(Model_User $user)
 {
     $recipient = Model_Forum_Private_Recipient::factory();
     return $recipient->load(DB::select_array($recipient->fields())->where('user_id', '=', $user->id)->where('unread', '>', 0), null);
 }
コード例 #24
0
ファイル: area.php プロジェクト: anqh/forum
 /**
  * Find private message topics
  *
  * @static
  * @param   Model_User  $user
  * @param   integer     $offset
  * @param   integer     $limit
  * @return  Model_Forum_Private_Topic[]
  */
 public static function find_topics(Model_User $user, $offset = 0, $limit = 10)
 {
     $topic = new Model_Forum_Private_Topic();
     return $topic->load(DB::select_array($topic->fields())->join('forum_private_recipients')->on('forum_private_topics.id', '=', 'forum_private_recipients.forum_topic_id')->where('user_id', '=', $user->id)->order_by('last_post_id', 'DESC')->offset($offset), $limit);
 }
コード例 #25
0
ファイル: topic.php プロジェクト: anqh/anqh
 /**
  * Find topic posts by page.
  *
  * @param   integer  $offset
  * @param   integer  $limit
  * @return  Model_Forum_Post[]
  */
 public function posts($offset, $limit)
 {
     $post = Model_Forum_Private_Post::factory();
     $query = DB::select_array($post->fields())->where('forum_topic_id', '=', $this->id)->order_by('created', 'ASC');
     if ($offset || $limit) {
         return $post->load($query->offset($offset), $limit);
     } else {
         return $post->load($query, null);
     }
 }
コード例 #26
0
ファイル: venue.php プロジェクト: anqh/venues
 /**
  * Find updated venues.
  *
  * @param   integer  $limit
  * @return  Database_Result
  */
 public function find_updated($limit = 20)
 {
     return $this->load(DB::select_array($this->fields())->where('modified', 'IS NOT', null)->order_by('modified', 'DESC'), $limit);
 }
コード例 #27
0
 /**
  * Update a user's properties
  * Note: Username cannot be updated, to update password the old password must be passed as old_password
  *
  * @param   Array  properties to be updated including profile fields
  * @param   string
  * @return  bool
  */
 public function update_user($values, $username = null)
 {
     $username = $username ?: $this->user['username'];
     $current_values = \DB::select_array(\Config::get('simpleauth.table_columns', array('*')))->where('username', '=', $username)->from(\Config::get('simpleauth.table_name'))->execute(\Config::get('simpleauth.db_connection'));
     if (empty($current_values)) {
         throw new \SimpleUserUpdateException('Username not found', 4);
     }
     $update = array();
     if (array_key_exists('username', $values)) {
         throw new \SimpleUserUpdateException('Username cannot be changed.', 5);
     }
     if (array_key_exists('password', $values)) {
         if (empty($values['old_password']) or $current_values->get('password') != $this->hash_password(trim($values['old_password']))) {
             throw new \SimpleUserWrongPassword('Old password is invalid');
         }
         $password = trim(strval($values['password']));
         if ($password === '') {
             throw new \SimpleUserUpdateException('Password can\'t be empty.', 6);
         }
         $update['password'] = $this->hash_password($password);
         unset($values['password']);
     }
     if (array_key_exists('old_password', $values)) {
         unset($values['old_password']);
     }
     if (array_key_exists('email', $values)) {
         $email = filter_var(trim($values['email']), FILTER_VALIDATE_EMAIL);
         if (!$email) {
             throw new \SimpleUserUpdateException('Email address is not valid', 7);
         }
         $update['email'] = $email;
         unset($values['email']);
     }
     if (array_key_exists('group', $values)) {
         if (is_numeric($values['group'])) {
             $update['group'] = (int) $values['group'];
         }
         unset($values['group']);
     }
     if (!empty($values)) {
         $profile_fields = @unserialize($current_values->get('profile_fields')) ?: array();
         foreach ($values as $key => $val) {
             if ($val === null) {
                 unset($profile_fields[$key]);
             } else {
                 $profile_fields[$key] = $val;
             }
         }
         $update['profile_fields'] = serialize($profile_fields);
     }
     $update['updated_at'] = \Date::forge()->get_timestamp();
     $affected_rows = \DB::update(\Config::get('simpleauth.table_name'))->set($update)->where('username', '=', $username)->execute(\Config::get('simpleauth.db_connection'));
     // Refresh user
     if ($this->user['username'] == $username) {
         $this->user = \DB::select_array(\Config::get('simpleauth.table_columns', array('*')))->where('username', '=', $username)->from(\Config::get('simpleauth.table_name'))->execute(\Config::get('simpleauth.db_connection'))->current();
     }
     return $affected_rows > 0;
 }
コード例 #28
0
ファイル: flyer.php プロジェクト: anqh/anqh
 /**
  * Get a random flyer
  *
  * @param   boolean  $unknown  Limit to unknown fliers (not linked to an event)
  * @return  Model_Flyer
  */
 public function find_random($unknown = false)
 {
     $query = DB::select_array($this->fields())->order_by(DB::expr('RANDOM()'));
     if ($unknown) {
         $query = $query->where('event_id', 'IS', null);
     }
     return $this->load($query);
 }
コード例 #29
0
ファイル: event.php プロジェクト: anqh/events
 /**
  * Find events happening now.
  *
  * @return  Model_Event[]
  */
 public function find_now()
 {
     return $this->load(DB::select_array($this->fields())->where(DB::expr(time()), 'BETWEEN', DB::expr('stamp_begin AND stamp_end'))->order_by('city_name', 'ASC'), null);
 }
コード例 #30
0
ファイル: area.php プロジェクト: anqh/anqh
 /**
  * Get area by bind.
  *
  * @param   string  $bind
  * @return  Model_Forum_Area
  */
 public function find_by_bind($bind)
 {
     return $this->load(DB::select_array($this->fields())->where('area_type', '=', Model_Forum_Area::TYPE_BIND)->where('is_hidden', '=', false)->where('bind', '=', $bind));
 }