/** * Truncates the specified table. * @param [object] $dbc - The MySqli DB Connection Object. * @param [string] $tableName - The name of the table to be truncated. */ function truncateTable($dbc, $tableName) { $sql = "TRUNCATE TABLE {$tableName}"; if (!$dbc->query($sql)) { throw new Exception("Error truncating the table {$tableName}"); } }
/** * handle current room * * @param [object] $user * @param [object] $room */ private function leaveCurrentRoom($user, $room) { $room->removeUser($user); $this->socket->leave($room->getSlug()); // send users of current room $io = $this->service->get('io'); $io->in($room->getSlug())->emit('room:update', $room); }
/** * 分页函数 * @param [object] $model [模型] * @param boolean $condition [条件] * @param integer $rollPage [分页栏每页显示的页数] * @param string $order [排序条件] * @return [array] [包含结果集(list)和分类(page)的数组] */ function page($model, $rollPage = 10, $order = '', $condition = array()) { import('ORG.Util.Page'); // 导入分页类 // 总记录数 $count = $model->count(); // 实例化分页类,传入总记录数和每页显示的记录数 $Page = new Page($count, $rollPage); // 分页显示输出 foreach ($condition as $key => $value) { $Page->parameter .= "{$key}=" . urlencode($value) . '&'; } $array = array(); $array['show'] = $Page->show(); $array['list'] = $model->where($condition)->order($order)->limit($Page->firstRow . ',' . $Page->listRows)->select(); return $array; }
/** * [destroy deletes the current session id from the database] * @param [string] $id [session_id] * @return [boolean] */ public function destroy($id) { $stmt = $this->_db->prepare("DELETE FROM {$this->_table_name} WHERE session_id = ?"); $session_res = $stmt->execute(array($id)); $_SESSION = array(); $params = session_get_cookie_params(); setcookie(session_name(), '', time() - 42000, $params["path"], $params["domain"], $params["secure"], $params["httponly"] ); if (!$session_res) return false; else return true; }
/** * totalOrder * It is able to return the order total, as items number and price total * @param [object] $items is the order details, which contains the purchase information * @return [array] */ public static function totalOrder($items) { $data = ['qty' => 0, 'total' => 0]; $items->each(function ($item, $key) use(&$data) { $data['qty'] += $item->quantity; $data['total'] += $item->price; }); return $data; }
/** * * Create new WordPress page. * * @param [object] $post Post object, class rebuildPagesMajestic_Post * @param [array] $options Array of plugin options. * @param [string] $home_url Home url of WordPress blog * * @return [int | null] Returnes created post id or null if failed. * */ private function create_post($post, $options, $home_url) { if ($post) { $guid = parse_url($post->getUrl(), PHP_URL_PATH); $guid = ltrim($guid, '/'); if (strlen($guid) > 1) { $post_content = sprintf('Oops. Page not found. Go to <a href="%s">homepage</a>', $home_url); $new_post = array('post_title' => convert_chars($guid), 'post_content' => $post_content, 'post_status' => 'publish', 'post_type' => 'page', 'guid' => $guid, 'post_name' => $guid); $id = wp_insert_post($new_post); update_post_meta($id, 'custom_permalink', $guid); return $id; } } return null; }
/** * scopeLightSelection * Retrieve build the query select as scope * @param [object] $query contains the Laravel query builder */ public function scopeLightSelection($query) { return $query->select('categories.id', 'categories.name', 'categories.category_id'); }
/** * Increase the product counters. * * @param [object] $product is the object which contain the product evaluated * @param [array] $data is the method config that has all the info requeried (table field, amount to be added) * @param [string] $wrapper is the products session array position key. */ public static function setCounters($product = null, $data = [], $wrapper = '') { if (\Auth::user() && $product != '' && count($data) > 0) { $_array = Session::get('products.' . $wrapper); //products already evaluated if (count($_array) == 0 || !in_array($product->id, $_array)) { //looked up to make sure the product is not in $wrapper array already foreach ($data as $key => $value) { if ($key != '' && $data[$key] != '') { $product->{$key} = $product->{$key} + intval($data[$key]); $product->save(); } } Session::push('products.' . $wrapper, $product->id); //build product list to not increase a product more than one time per day Session::save(); } } }
/** * [getParentsId 获取指定id的所有父级分类id] * @param [object] $db [数据库对象] * @param integer $id [description] * @param boolean $map [description] * @param boolean $field [description] * @return [type] [description] */ public function getParentsId($db, $id = 0, $map = true, $field = true) { $id = intval($id); // 获取所有分类 $list = $db->field($field)->where($map)->order('listOrder')->select(); //格式化分类 $list = D('Tool/TreeTool')->getParentsId($list, $id, $pk = 'id', $pid = 'parentId'); return $list; }