static function getCategoryTree($db, $selected_id = null) { if (isset(Category::$cache_tree)) { $tree_root = Category::$cache_tree; } else { $all = Category::select($db, 'viewCategories', null, null, null, null, 'category_name'); $tree_root = new Category(); $tree_root->data['category_name'] = 'MENU'; $tree_root->is_on_selected_path = true; while (count($all) > 0) { foreach ($all as $i => $c) { $parent = null; if ($c->ival('category_parent_id') == null) { $parent = $tree_root; } else { $parent = $tree_root->findInChildren($c->ival('category_parent_id')); } if (isset($parent)) { $parent->addChild($c); unset($all[$i]); } } } Category::$cache_tree = $tree_root; } if (isset($selected_id)) { $sc = $tree_root->findInChildren($selected_id); $sc->is_selected = true; $sc->setSelectedPath(); } return $tree_root; }
/** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit($id) { $p_id = Category::select('*')->where('p_id', '=', 0)->get(); $category = Category::find($id); if (is_null($category)) { return Redirect::route('admin-category.index'); } return View::make('backend.category.edit', compact('category', 'p_id')); }
public function listCategory() { if (!Request::ajax()) { return App::abort(404); } $start = Input::has('start') ? (int) Input::get('start') : 0; $length = Input::has('length') ? Input::get('length') : 10; $search = Input::has('search') ? Input::get('search') : []; $categories = Category::select('categories.id', 'categories.name', 'categories.description', 'categories.order_no', 'parent.name as parent_name', 'categories.active'); if (!empty($search)) { foreach ($search as $key => $value) { if (empty($value)) { continue; } if ($key == 'active') { if ($value == 'yes') { $value = 1; } else { $value = 0; } $categories->where('categories.' . $key, $value); } else { if ($key == 'parent_id') { $categories->where('categories.' . $key, '=', (int) $value); } else { $value = ltrim(rtrim($value)); $categories->where('categories.' . $key, 'like', '%' . $value . '%'); } } } } $order = Input::has('order') ? Input::get('order') : []; if (!empty($order)) { $columns = Input::has('columns') ? Input::get('columns') : []; foreach ($order as $value) { $column = $value['column']; if (!isset($columns[$column]['name']) || empty($columns[$column]['name'])) { continue; } $categories->orderBy($columns[$column]['name'], $value['dir'] == 'asc' ? 'asc' : 'desc'); } } $count = $categories->count(); if ($length > 0) { $categories = $categories->skip($start)->take($length); } $arrcategories = $categories->leftJoin('categories as parent', 'categories.parent_id', '=', 'parent.id')->get()->toArray(); $arrReturn = ['draw' => Input::has('draw') ? Input::get('draw') : 1, 'recordsTotal' => Category::count(), 'recordsFiltered' => $count, 'data' => []]; if (!empty($arrcategories)) { foreach ($arrcategories as $category) { $category['parent_name'] = is_null($category['parent_name']) ? 'No Parent' : $category['parent_name']; $arrReturn['data'][] = [++$start, $category['id'], $category['name'], $category['description'], $category['order_no'], $category['parent_name'], $category['active']]; } } return $arrReturn; }
/** * page() - handles displaying categories * @param string $path - the unique path column from the database * @return View */ public function page($path = '/') { // Attempting to find a category corresponding to the given path try { $this->data['category'] = Category::select('id', 'title', 'slug', 'path')->where('path', $path)->firstOrFail(); } catch (Exception $e) { App::abort(404); } $id = $this->data['category']->id; // If something found, search for contents if (count($id)) { $this->data['order'] = Input::get('sort'); // $by = (Input::get('by') !== null) ? Input::get('by') : 'asc'; if (Input::get('by') == 'asc') { $this->data['by'] = 'desc'; } elseif (Input::get('by') == 'desc') { $this->data['by'] = 'asc'; } else { $this->data['by'] = 'desc'; } $this->data['contents'] = Content::select('id', 'title', 'slug', 'hits', 'created_at', 'created_by_alias')->where('catid', $id)->where('state', 1)->Order($this->data['order'], $this->data['by'])->paginate(40)->appends(Input::only('sort', 'by')); // Let's find our where are exactly in the tree structure of the categories //$node = Category::find($id, array('id', 'title', 'slug', 'path', '_lft', '_rgt')); $node = Category::getCategory($id); $this->data['descendants'] = $node->getDescendants(array('id', 'title', 'slug', 'path')); $this->data['ancestors'] = $node->ancestorsOf($id)->get(); // First item is always root, but 'Начало' looks better, doesn't it? $this->data['ancestors'][0]->title = 'Начало'; // Just to make the active highlight for the menus $this->data['active'] = $id; // Prepare data intended to go within the head tags $this->data['page_title'] = ucfirst($this->data['category']->title); foreach ($this->data['ancestors'] as $k => $v) { // first key (0) will generate the keyword 'начало', nobody needs this! if ($k != 0) { $this->data['page_keywords'] .= $v->title . ', '; } } return View::make('home.page', $this->data); } return Redirect::to('/'); }
/** * 返回更新国家信息 * @access public */ function update() { $id = get_post_value('id'); $field = array('category_1_id', 'category_2_id', 'category_2_cn', 'category_2_th', 'orders', 'status', 'created', 'created_name', 'audit_name', 'category_2_url'); $m = new Category(); $m->clear(); $m->setField($field); $m->setTable('vcb_product_category_2'); $m->setWhere('status', '!=', '60000'); $m->setWhere('category_2_id', '=', $id); $m->setOrderBy('orders'); $data = $m->select(); $this->assign('data', $data); }
<?php $s = new Slug(); $slug_count = $s->like('id', 'category.', 'after')->count(); $c = new Category(); $content_count = $c->count(); if ($slug_count < $content_count) { $slugs = array(); $c = new Category(); foreach ($c->select('slug')->get_iterated() as $content) { $slugs[] = "('category." . $content->slug . "')"; } $slugs = join(', ', $slugs); $this->db->query("INSERT INTO {$s->table}(id) VALUES {$slugs} ON DUPLICATE KEY UPDATE id=id;"); } $done = true;
function build_autos($items, $data, $user) { foreach ($items as $index => &$item) { if (isset($item['auto'])) { if (isset($data['urls'][$item['auto']])) { $item['path'] = $data['urls'][$item['auto']]; } else { if ($item['auto'] === 'set') { $item['path'] = ''; } } if ($item['auto'] === 'profile') { switch ($item['id']) { case 'twitter': $item['path'] = 'https://twitter.com/' . $user->twitter; break; default: $item['path'] = $user->{$item['id']}; if (empty($item['path'])) { unset($items[$index]); continue; } break; } if (!isset($item['label']) || empty($item['label'])) { $item['label'] = ucwords($item['id']) . ($item['id'] === 'google' ? '+' : ''); } } else { if ($item['auto'] === 'rss') { $item['path'] = '/feed/' . $item['id'] . ($item['id'] === 'essay' ? 's' : '') . '/recent.rss'; if (!isset($item['label'])) { $item['label'] = $data['url_data'][$item['id']]['plural'] . ' RSS'; } } else { if (preg_match('/s$/', $item['auto']) || $item['auto'] === 'timeline') { if ($item['auto'] === 'timeline' && isset($item['year'])) { $item['path'] .= $item['year'] . '/'; if (isset($item['month']) && $item['month'] !== false && $item['month'] !== 'any') { $m = str_pad($item['month'], 2, '0', STR_PAD_LEFT); $item['path'] .= $m . '/'; } } if (strpos($item['auto'], '_') !== false) { foreach (array('id', 'slug', 'month', 'year', 'day') as $id) { if ($id === 'month') { if (!isset($item['month']) || $item['month'] === 'any' || $item['month'] === false) { $item['month'] = ''; } else { $item['month'] = str_pad($item['month'], 2, '0', STR_PAD_LEFT); } } if ($id === 'day' && !isset($item['day'])) { $item['day'] = ''; } if ($id === 'slug' && !isset($item['slug']) && isset($item['id'])) { if (strpos($item['auto'], 'tag_') === 0) { $item['slug'] = $item['id']; } else { $c = new Category(); if (is_numeric($item['id'])) { $c->select('slug')->get_by_id($item['id']); $item['slug'] = $c->slug; } else { $item['slug'] = $item['id']; } } } if (isset($item[$id])) { $item['path'] = str_replace(":{$id}", $item[$id], $item['path']); } } } else { if (!isset($item['label'])) { $item['label'] = $data['url_data'][$item['auto'] === 'categories' ? 'category' : rtrim($item['auto'], 's')]['plural']; } } } else { if ($item['auto'] === 'home') { if (!isset($item['label'])) { $item['label'] = $data['url_data']['home']; } $item['path'] = '/home/'; } else { if ($item['auto'] === 'album' || $item['auto'] === 'set') { $a = new Album(); $a->select('id,slug,created_on,title'); if (is_numeric($item['id'])) { $a->where('id', $item['id']); } else { $a->where('slug', $item['id'])->or_where('internal_id', $item['id']); } $a->get(); if (!$a->exists()) { unset($items[$index]); continue; } $item['path'] = str_replace(':id', $a->id, $item['path']); $item['path'] = str_replace(':slug', $a->slug, $item['path']); $item['path'] = str_replace(':year', date('Y', $a->created_on), $item['path']); $item['path'] = str_replace(':month', date('m', $a->created_on), $item['path']); $item['path'] = str_replace(':day', date('d', $a->created_on), $item['path']); if (!isset($item['label'])) { $item['label'] = $a->title; } } else { if ($item['auto'] === 'page' || $item['auto'] === 'essay') { $t = new Text(); $t->select('id,slug,published_on,title'); if (is_numeric($item['id'])) { $t->where('id', $item['id']); } else { $t->where('slug', $item['id']); } $t->get(); if (!$t->exists()) { unset($items[$index]); continue; } $item['path'] = str_replace(':id', $t->id, $item['path']); $item['path'] = str_replace(':slug', $t->slug, $item['path']); $item['path'] = str_replace(':year', date('Y', $t->published_on), $item['path']); $item['path'] = str_replace(':month', date('m', $t->published_on), $item['path']); $item['path'] = str_replace(':day', date('d', $t->published_on), $item['path']); if (!isset($item['label'])) { $item['label'] = $t->title; } } else { if ($item['auto'] === 'content') { $c = new Content(); $c->select('id,slug,captured_on,title'); if (isset($item['album_id'])) { $item['path'] = preg_replace('/:(id|slug)/', ':album_$1', $data['urls']['album']) . substr(str_replace(':year/:month/', '', $data['urls']['content']), 1); $a = new Album(); $a->select('id,slug,created_on,title'); if (is_numeric($item['album_id'])) { $a->where('id', $item['album_id']); } else { $a->where('slug', $item['album_id'])->or_where('internal_id', $item['album_id']); } $a->get(); if (!$a->exists()) { unset($items[$index]); continue; } $item['path'] = str_replace(':album_id', $a->id, $item['path']); $item['path'] = str_replace(':album_slug', $a->slug, $item['path']); $date = $a->created_on; } else { $date = $c->captured_on; } if (is_numeric($item['id'])) { $c->where('id', $item['id']); } else { $c->where('slug', $item['id'])->or_where('internal_id', $item['id']); } $c->get(); if (!$c->exists()) { unset($items[$index]); continue; } $item['path'] = str_replace(':id', $c->id, $item['path']); $item['path'] = str_replace(':slug', $c->slug, $item['path']); $item['path'] = str_replace(':year', date('Y', $date), $item['path']); $item['path'] = str_replace(':month', date('m', $date), $item['path']); $item['path'] = str_replace(':day', date('d', $date), $item['path']); if (!isset($item['label'])) { $item['label'] = $c->title; } if (isset($item['lightbox']) && $item['lightbox']) { $item['path'] .= 'lightbox/'; } } else { if ($item['auto'] === 'tag') { $item['path'] = str_replace(':slug', $item['id'], $item['path']); } } } } } } } } if ($item['auto'] !== 'profile') { $item['path'] = str_replace(array(':year', ':month'), '', $item['path']); $item['path'] = preg_replace('/[\\(\\)\\?\\:]/', '', $item['path']); $item['path'] = preg_replace('~[/]+~', '/', $item['path']); } } } return $items; }
/** *保存增加的三级目录数据 * @access public */ function add_saveCategory3() { $category_3_cn = get_post_value('category_3_cn'); $category_3_th = get_post_value('category_3_th'); $category_3_url = get_post_value('category_3_url'); $category_2_id = get_post_value('category_2_id'); $category_1_id = get_post_value('category_1_id'); $orders = get_post_value('order'); if (!$this->verifyCategory3()) { echo '<br> ' . $category_3_cn . ' 已存在,请核对后重新输入。<a href="javascript:history.go(-1)">返回</a><br>'; return; } $field = array('category_1_cn', 'category_1_th'); $m = new Category(); $m->clear(); $m->setTable('vcb_product_category_1'); $m->setField($field); $m->setWhere('category_1_id', '=', $category_1_id); $dataCategory1 = $m->select(); print_r($dataCategory1); $field = array('category_2_cn', 'category_2_th'); $m->clear(); $m->setTable('vcb_product_category_2'); $m->setField($field); $m->setWhere('category_2_id', '=', $category_2_id); $dataCategory2 = $m->select(); print_r($dataCategory2); $category_1_cn = $dataCategory1[0]['category_1_cn']; $category_1_th = $dataCategory1[0]['category_1_th']; $category_2_cn = $dataCategory2[0]['category_2_cn']; $category_2_th = $dataCategory2[0]['category_2_th']; $field = array('category_1_id' => $category_1_id, 'category_1_cn' => trim($category_1_cn), 'category_1_th' => trim($category_1_th), 'category_2_id' => $category_2_id, 'category_2_cn' => trim($category_2_cn), 'category_2_th' => trim($category_2_th), 'category_3_cn' => trim($category_3_cn), 'category_3_th' => trim($category_3_th), 'category_3_url' => trim($category_3_url), 'orders' => $orders, 'status' => '10000'); $m->clear(); $m->setTable('vcb_product_category_3'); $m->setField($field); $data = $m->insert(); if (!$data) { echo '<br>保存失败<br>'; } else { echo '<br>保存成功,<a href="addCategory3">继续添加</a>,<a href="category3">返回</a><br>'; } }
/** * 返回更新国家信息 * @access public */ function update() { $id = get_post_value('id'); $field = array('category_2.category_1_id', 'category_2.category_2_id', 'category_2.category_2_cn', 'category_2.category_2_th', 'category_3.category_3_id', 'category_3.category_3_cn', 'category_3.category_3_th', 'category_3.category_3_url', 'category_3.orders', 'category_3.status', 'category_3.created', 'category_3.created_name', 'category_3.audit_name', 'category_3.start_time', 'category_3.end_time'); $m = new Category(); $m->clear(); $m->setField($field); $m->setTable('vcb_product_category_3 AS category_3'); $m->setJoin('vcb_product_category_2 as category_2', 'category_2.category_2_id=category_3.category_2_id'); $m->setWhere('category_3.status', '!=', '60000'); $m->setWhere('category_3.category_3_id', '=', $id); $data = $m->select(); $this->assign('data', $data); $data = $m->getCategory_2($data[0]['category_1_id']); $this->assign('category_2', $data); }
<?php /////////////////////////////////// require 'tables.php'; if (isset($_GET['categoryName'])) { $category_new = $_GET['categoryName']; $Categorys = new Category(); $Categorys->categoryName = $category_new; $Categorys->insert(); } $Categorys = new Category(); $data = $Categorys->select(); $response = json_encode($data); echo $response;
public function getListNoteServer($userId, $skip, $lastedUpdate) { if (is_null($lastedUpdate)) { return Category::select('note.noteId', 'note.noteMean', 'note.noteName', 'note.cateId', 'note.type', 'note.updated_at', 'note.idx')->where('userId', $userId)->join('note', 'note.cateId', '=', 'category.categoryId')->skip($skip)->take(100)->get(); } else { return Category::select('note.noteId', 'note.noteMean', 'note.noteName', 'note.cateId', 'note.type', 'note.updated_at', 'note.idx')->where('userId', $userId)->join('note', 'note.cateId', '=', 'category.categoryId')->where('note.updated_at', '>', $lastedUpdate)->skip($skip)->take(100)->get(); } }
public static function getAllNodes() { return Category::select('categories.id as id', 'categories.title as title', 'category_types.title as type')->withoutRoot('id', 'title', 'slug')->withDepth()->join('category_types', 'categories.type', '=', 'category_types.type')->get(); }