Inheritance: extends Model
示例#1
0
 protected static function actionActive()
 {
     $category = new CategoryModel($_GET['id']);
     $category->active = $category->active ? '0' : '1';
     $category->save();
     self::redirect(App::getLink('AdminCategories'));
 }
示例#2
0
 public function indexAction()
 {
     $categoryObj = new CategoryModel();
     $list = $categoryObj->getCategoryList();
     var_dump($list);
     // 		exit;
 }
示例#3
0
 public function addAction()
 {
     $model_category = new CategoryModel();
     $category_list = $model_category->getTreeList(0);
     $this->view->assign('category_list', $category_list);
     $this->view->display('add.tpl');
 }
 public function index()
 {
     if (IS_POST) {
         if (empty($_POST['catid'])) {
             $this->error("请选择数据来源");
         }
         $map['catid'] = array('in', $_POST['catid']);
         $map['status'] = array('eq', 1);
         $article = M('Article');
         $articlelist = $article->where($map)->order('create_time desc')->select();
         $download = M('Download');
         $downloadlist = $download->where($map)->order('create_time desc')->select();
         $photo = M('Photo');
         $photolist = $photo->where($map)->order('create_time desc')->select();
         if (isset($_POST['sitemaptype'])) {
             $type = $_POST['sitemaptype'];
         }
         $sitemapstr = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n";
         switch ($type) {
             case 0:
                 $sitemapstr .= "<urlset>\r\n";
                 break;
             case 1:
                 $sitemapstr .= "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\r\n";
                 break;
         }
         foreach ($articlelist as $value) {
             $sitemapstr .= "<url>\r\n";
             $sitemapstr .= "<loc>Article/show?id=" . $value['id'] . "</loc>\r\n";
             $sitemapstr .= "<lastmod>" . toDate(NOW_TIME, 'Y-m-d') . "</lastmod>\r\n";
             $sitemapstr .= "<changefreq>" . $_POST['changefreq'] . "</changefreq>\r\n";
             $sitemapstr .= "<priority>" . $_POST['priority'] . "</priority>\r\n";
             $sitemapstr .= "</url>\r\n\r\n";
         }
         foreach ($downloadlist as $value) {
             $sitemapstr .= "<url>\r\n";
             $sitemapstr .= "<loc>Download/show?id=" . $value['id'] . "</loc>\r\n";
             $sitemapstr .= "<lastmod>" . toDate(NOW_TIME, 'Y-m-d') . "</lastmod>\r\n";
             $sitemapstr .= "<changefreq>" . $_POST['changefreq'] . "</changefreq>\r\n";
             $sitemapstr .= "<priority>" . $_POST['priority'] . "</priority>\r\n";
             $sitemapstr .= "</url>\r\n\r\n";
         }
         foreach ($photolist as $value) {
             $sitemapstr .= "<url>\r\n";
             $sitemapstr .= "<loc>Photo/show?id=" . $value['id'] . "</loc>\r\n";
             $sitemapstr .= "<lastmod>" . toDate(NOW_TIME, 'Y-m-d') . "</lastmod>\r\n";
             $sitemapstr .= "<changefreq>" . $_POST['changefreq'] . "</changefreq>\r\n";
             $sitemapstr .= "<priority>" . $_POST['priority'] . "</priority>\r\n";
             $sitemapstr .= "</url>\r\n\r\n";
         }
         $sitemapstr .= "</urlset>";
         file_put_contents("../sitemap.xml", $sitemapstr);
         $this->success("sitemap在线生成完成");
     } else {
         $cate = new CategoryModel();
         $this->list = $cate->getMyCategory();
         //加载栏目
         $this->display();
     }
 }
 /**
  * ToggleFollow toggles the hidden/unhidden state of categories
  *
  * it has been adopted from function Follow in
  * /applications/vanilla/controllers/class.categorycontroller.php
  * Redirection had to be fixed
  */
 public function CategoryController_ToggleFollow_Create($CategoryID, $Value, $TKey, $Target)
 {
     if (Gdn::Session()->ValidateTransientKey($TKey)) {
         $CategoryModel = new CategoryModel();
         $CategoryModel->SaveUserTree($CategoryID, array('Unfollow' => !(bool) $Value));
         if (!(bool) $Value) {
             // switch to "view only followed" when hiding a category
             $this->CategoriesController_SetToggle_Create(1, $Target);
         } else {
             // and to "view all" when no category is hidden
             $NoFollowing = TRUE;
             $Categories = $CategoryModel::Categories();
             foreach ($Categories as $Category) {
                 if ($Category['Following'] == '') {
                     $NoFollowing = FALSE;
                     break;
                 }
             }
             if ($NoFollowing) {
                 $this->CategoriesController_SetToggle_Create(0, $Target);
             }
         }
     }
     Redirect($Target);
 }
 /**
  * 增加商品跳转动作
  */
 public function addAction()
 {
     //得到所有分类
     $model_category = new CategoryModel();
     $cat_list = $model_category->getList();
     require CURR_VIEW_DIR . 'goodsAdd.html';
 }
示例#7
0
 public function _before_edit()
 {
     $cate = new CategoryModel();
     $menu = $cate->getModelCategory('Article');
     //加载栏目
     $menu1 = arrToMenu($menu, 0);
     $this->categorylist = $menu1;
 }
 public function detailAction()
 {
     $Category = new CategoryModel((int) $this->_request->value);
     $Category->load();
     $View = new DetailView();
     $View->setModel($Category);
     $View->display();
 }
    /**
     * Hack the Base Render in order to achieve our goal
     * 
     * @since 1.0
     * @version 1.7.2
     */
    public function Base_Render_Before(&$Sender)
    {
        // Attach the Plugin's CSS to the site
        $Sender->AddCssFile($this->GetResource('categories2menu.css', FALSE, FALSE));
        $Cat2MenuJQuerySource = '<script type="text/javascript">
var ddmenuitem = 0;
var menustyles = { "visibility":"visible", "display":"block", "z-index":"9"}

function Menu_close()
{  if(ddmenuitem) { ddmenuitem.css("visibility", "hidden"); } }

function Menu_open()
{  Menu_close();
   ddmenuitem = $(this).find("ul").css(menustyles);
}

jQuery(document).ready(function()
{  $("ul#Menu > li").bind("mouseover", Menu_open);
   $("ul#Menu > li").bind("mouseout", Menu_close);
});

document.onclick = Menu_close;</script>
';
        // Add the jQuery JavaScript to the page
        $Sender->Head->AddString($Cat2MenuJQuerySource);
        if ($Sender->Menu) {
            // Set this to FALSE|TRUE whether you want to display the Discussion-Counter next to each Category or not
            $DisplayCounter = TRUE;
            // Build the Categories Model & load Categories Data
            $CategoryModel = new CategoryModel();
            $_CategoryData = $CategoryModel->GetFull();
            // If there are any Categories...
            if ($_CategoryData != FALSE) {
                // Add a link to the Category overview as first menuitem
                $Sender->Menu->AddLink('Discussions', T('→ All Categories'), '/categories/all');
                // If $DisplayCounter is set to TRUE, get Count discussions per Category separately
                $CountDiscussions = 0;
                foreach ($_CategoryData->Result() as $Category) {
                    // (will ignore root node)
                    if ($Category->Name != 'Root') {
                        $CountDiscussions = $CountDiscussions + $Category->CountDiscussions;
                    }
                }
                // Fetch every single Category...
                foreach ($_CategoryData->Result() as $Category) {
                    if ($Category->Name != 'Root') {
                        if ($DisplayCounter == TRUE) {
                            // Build the Categories-Menu with Discussions-Counter
                            $Sender->Menu->AddLink('Discussions', $Category->Name . ' <span>' . $Category->CountDiscussions . '</span>', '/categories/' . $Category->UrlCode, FALSE);
                        } else {
                            // Build the Categories-Menu
                            $Sender->Menu->AddLink('Discussions', $Category->Name, '/categories/' . $Category->UrlCode, FALSE);
                        }
                    }
                }
            }
        }
    }
 /**
  * Get a list of immediate children for the configured category.
  *
  * @return array|null
  */
 public function getChildren()
 {
     $category = $this->getCategory();
     if ($category && !$this->children) {
         $this->children = $this->categoryModel->getTreeAsFlat(val('CategoryID', $category), 0, $this->getLimit(), $this->getFilter());
         $this->categoryModel->joinRecent($this->children);
     }
     return $this->children;
 }
示例#11
0
 public function viewMainPage()
 {
     $postmodel = new PostModel();
     $categorymodel = new CategoryModel();
     $categories = $categorymodel->getAllPublicCategories();
     $page_title = 'Forums';
     include BASE_URI . 'app/view/template/header.php';
     include BASE_URI . 'app/view/main/public.php';
     include BASE_URI . 'app/view/template/footer.php';
 }
 public function deleteUser($id)
 {
     $db = new Database();
     $db->execute('DELETE FROM accounts WHERE id = ?', array($id));
     $db->execute('DELETE FROM passwords WHERE account = ?', array($id));
     $db->execute('DELETE FROM articlesfavoris WHERE account = ?', array($id));
     $db->execute('DELETE FROM categories WHERE account = ?', array($id));
     $categoryModel = new CategoryModel();
     $categoryModel->deleteAllCategoriesByAccount($id);
 }
 public function deleteAction()
 {
     $category_model = new CategoryModel();
     $result = $category_model->delByID($_GET['id']);
     if (!$result) {
         $this->redirect('category.php?act=list', $category_model->error_info, 3);
     } else {
         $this->redirect('category.php?act=list');
     }
 }
示例#14
0
 public function deleteAction()
 {
     $catmodel = new CategoryModel("category");
     $catmodel = new CategoryModel("category");
     $cat_id = $_GET["cat_id"];
     if ($catmodel->delete($cat_id)) {
         $this->jump("index.php?p=admin&c=Category&a=index", "删除成功", $wait = 1);
     } else {
         $this->jump("index.php?p=admin&c=Category&a=index", "删除失败", $wait = 1);
     }
 }
 public function _before_edit()
 {
     $cate = new CategoryModel();
     //        $this->list=$cate->getMyCategory();//加载栏目
     $menu = $cate->getMyCategory1();
     //加载栏目
     $menu = arrToMenu($menu, 0);
     $this->list = $menu;
     $this->mdldata = $cate->getMyModel();
     //加载模型
 }
示例#16
0
 public function menu()
 {
     $this->checkUser();
     if (isset($_SESSION[C('USER_AUTH_KEY')])) {
         //显示菜单项
         $menu = array();
         if (isset($_SESSION['menu' . $_SESSION[C('USER_AUTH_KEY')]])) {
             //如果已经缓存,直接读取缓存
             $menu = $_SESSION['menu' . $_SESSION[C('USER_AUTH_KEY')]];
         } else {
             //读取数据库模块列表生成菜单项
             $node = M("Node");
             $map['level'] = 2;
             $map['status'] = 1;
             $list = $node->where($map)->field('id,name,pid,title')->order('sort asc')->select();
             $accessList = $_SESSION['_ACCESS_LIST'];
             foreach ($list as $key => $module) {
                 if (isset($accessList[strtoupper(APP_NAME)][strtoupper($module['name'])]) || $_SESSION['administrator']) {
                     //设置模块访问权限
                     $module['access'] = 1;
                     $menu[$key] = $module;
                 }
             }
             //缓存菜单访问
             $_SESSION['menu' . $_SESSION[C('USER_AUTH_KEY')]] = $menu;
         }
         if (isset($_GET['tag'])) {
             $tag = $_GET['tag'];
             if (0 == $tag) {
                 $this->assign('menuTitle', '扩展功能');
             } else {
                 $mapid['id'] = array('eq', $tag);
                 $node = M("Node");
                 $title = $list = $node->where($mapid)->getField('title');
                 $this->assign('menuTitle', $title);
             }
             $this->assign('menuTag', $tag);
         } else {
             $this->assign('menuTitle', '内容管理');
         }
         $this->assign('menu', $menu);
     }
     //显示站点栏目
     $cate = new CategoryModel();
     $this->cate = $list = $cate->getMyCategory();
     //加载栏目
     $menu = $cate->getMyCategory1();
     //加载栏目
     $menu = arrToTree($menu, 0);
     $tree = outMenuNode($menu);
     $this->assign('tree', $tree);
     $this->display();
 }
 public function search($params)
 {
     $category = new CategoryModel();
     $result = $category->request($params);
     $output = "";
     if (!empty($params["output"])) {
         $output = $params["output"];
     }
     $html = Converter::generate($result, $output);
     Header::append($result["status"]["code"]);
     Header::append($output);
     echo $html;
 }
 public function updateAction()
 {
     $data['cat_id'] = $_POST['cat_id'];
     $data['parent_id'] = $_POST['parent_id'];
     $data['sort_order'] = $_POST['sort_order'];
     $data['cat_name'] = $_POST['cat_name'];
     $model_name = new CategoryModel();
     if ($model_name->updateCat($data)) {
         $this->jump('index.php?p=back&c=Category&a=list');
     } else {
         $this->jump('index.php?p=back&c=Category&a=list', '修改失败' . $model_name->error_info);
     }
 }
示例#19
0
文件: Category.php 项目: hopdq/taka
 public function loadData($categoryId)
 {
     $model = new FrontMasterModel();
     $body = new CategoryModel();
     $filter = new FilterSelectedModel();
     $filter->categoryId = $categoryId;
     $sort = 'OLD_NEW';
     $paging = new PagingModel(1, 12);
     $body->init($filter, $sort, $paging);
     $model->setCategoryId($categoryId);
     $model->init($body);
     $result = json_encode($model);
     echo $result;
 }
示例#20
0
 public function delAction()
 {
     $p = $_REQUEST;
     $pId = empty($p['id']) ? die('ID不能为空') : intval($p['id']);
     $tMO = new CategoryModel();
     $tRow = $tMO->field('count(0) c')->where('id = ' . $pId)->fRow();
     if (empty($tRow['c'])) {
         Tool_Fnc::ajaxMsg('分类不存在');
     }
     $tSql = 'delete from ' . $tMO->table . ' where id=' . $pId;
     if (!$tMO->exec($tSql)) {
         Tool_Fnc::ajaxMsg('删除失败');
     }
     Tool_Fnc::ajaxMsg('删除成功', 1);
 }
示例#21
0
 /**
  *  添加新的子菜单,但是要选择是 哪种类型(Article,Category,Section).
  *  从组件中找出存在的组建
  */
 function add()
 {
     //查找出子菜单,并且显示分配在左侧菜单中
     $menus = new MenuModel();
     $menu_list = $menus->select();
     $this->assign('menulist', $menu_list);
     //导入分页类
     import("ORG.Util.Page");
     //查询组件,相当于哪几种类型
     $component = new ComponentModel();
     $where = array('enabled' => 1);
     $list = $component->where($where)->select();
     $this->assign('comlist', $list);
     //得到类型
     $link = strtolower($_REQUEST['link']);
     //查询数据,如果默认为空,则显示文章列表
     if (empty($link) || $link == 'article') {
         $art = new ArticleModel();
         $count = $art->count();
         $page = new Page($count, C("PAGESIZE"));
         //完成分页
         $show = $page->show();
         //查询分页数据
         $list = $art->order('id desc')->limit($page->firstRow . ',' . $page->listRows)->select();
     } else {
         if ($link == 'category') {
             $cat = new CategoryModel();
             $count = $cat->count();
             $page = new Page($count, C("PAGESIZE"));
             //完成分页
             $show = $page->show();
             //查询分页数据
             $list = $cat->order('id desc')->limit($page->firstRow . ',' . $page->listRows)->select();
         } else {
             $sec = new SectionModel();
             $count = $sec->count();
             $page = new Page($count, C("PAGESIZE"));
             //完成分页
             $show = $page->show();
             //查询分页数据
             $list = $sec->order('id desc')->limit($page->firstRow . ',' . $page->listRows)->select();
         }
     }
     $this->assign('show', $show);
     $this->assign('list', $list);
     $this->assign('link', $link);
     $this->display();
 }
示例#22
0
 public function index()
 {
     $vars = array_merge(array('cid' => -1, 'original' => -1, 'order' => 'hot'), $_GET);
     $total = BlogModel::blogs($vars, true);
     $Page = new Newpage($total, 10);
     $this->assign('page', $Page->getPage());
     $this->assign($vars);
     $categories = CategoryModel::categories();
     $this->assign('categories', $categories);
     $blogs = BlogModel::blogs($vars, false, $Page->limit);
     foreach ($blogs as &$row) {
         $row['content'] = strip_tags($row['content']);
         $row['user'] = model('User')->formatForApi($row, $row['uid']);
     }
     $this->assign('blogs', $blogs);
     $hot = BlogModel::hotBlogs(5);
     foreach ($hot as &$row) {
         $row['user'] = model('User')->formatForApi($row, $row['uid']);
     }
     $this->assign('hot_blogs', $hot);
     //$hot_users = UserModel::hotUsers(5);
     $hot_users = BlogModel::hotUsers(5);
     if (is_array($hot_users) and $hot_users) {
         foreach ($hot_users as &$user) {
             $user = model('User')->formatForApi($user, $user['uid']);
         }
     }
     //$this->ajaxReturn($hot_users);
     $this->assign('hot_users', $hot_users);
     $this->display();
 }
示例#23
0
 /**
  * Check whether all condition are met for this plugin to do its magic.
  *
  * @param Gdn_Request $request
  * @param int|bool $categoryID Category ID of the welcome category if it exists and this function return true
  * @return bool
  */
 protected function isWelcomePostActive($request, &$categoryID)
 {
     static $cachedCategoryID = null;
     if ($cachedCategoryID === null) {
         $isWelcomePost = true;
         if ($request->get('welcomepost', false) !== "true") {
             $cachedCategoryID = false;
             return false;
         }
         if (!Gdn::session()->isValid()) {
             $cachedCategoryID = false;
             return false;
         }
         $category = (array) CategoryModel::instance()->getByCode('welcome');
         $cachedCategoryID = val('CategoryID', $category, false);
         if (!$cachedCategoryID) {
             return false;
         }
         $categoryID = $cachedCategoryID;
     } else {
         $isWelcomePost = (bool) $cachedCategoryID;
         $categoryID = $cachedCategoryID;
     }
     return $isWelcomePost;
 }
示例#24
0
 /**
  * updates ad title, price, description, image, and date_posted
  * will NOT update user_id or category_id!
  */
 public function save()
 {
     if ($this->id != '') {
         // there is an id, so lets update
         // store id to use and put back later
         $id = $this->id;
         $this->id = '';
         $query = "UPDATE ads SET title = :title, price = :price, \n                        description = :description, image = :image, \n                        date_posted = :date_posted\n                        WHERE id={$id}";
         $stmt = static::$dbc->prepare($query);
         $stmt->bindValue(":title", $this->title, PDO::PARAM_STR);
         $stmt->bindValue(":price", $this->price, PDO::PARAM_STR);
         $stmt->bindValue(":description", $this->description, PDO::PARAM_STR);
         $stmt->bindValue(":image", $this->image, PDO::PARAM_STR);
         $stmt->bindValue(":date_posted", $this->date_posted, PDO::PARAM_STR);
         $stmt->execute();
         $this->id = $id;
     } else {
         // no id, lets insert
         $categoryId = CategoryModel::getCategoryId($this->category);
         $query = "INSERT INTO ads (title, price, description, image, \n                        date_posted, category_id, users_id) VALUES \n                        (:title, :price, :description, :image, :date_posted, \n                        :category_id, :users_id)";
         $stmt = static::$dbc->prepare($query);
         $stmt->bindValue(":title", $this->title, PDO::PARAM_STR);
         $stmt->bindValue(":price", $this->price, PDO::PARAM_STR);
         $stmt->bindValue(":description", $this->description, PDO::PARAM_STR);
         $stmt->bindValue(":image", $this->image, PDO::PARAM_STR);
         $stmt->bindValue(":date_posted", $this->date_posted, PDO::PARAM_STR);
         $stmt->bindValue(":category_id", $categoryId, PDO::PARAM_STR);
         $stmt->bindValue(":users_id", $this->users_id, PDO::PARAM_STR);
         $stmt->execute();
         $this->id = static::$dbc->lastInsertId();
     }
 }
示例#25
0
    function renderXml()
    {
        //$this->id_lang
        $list = dibi::fetchAll('
				SELECT 
				product.id_product
				FROM 
					`product`					
					JOIN category_product USING (id_product)					
					JOIN category USING (id_category)
				WHERE 
					product.active = 1 AND					
					product.added = 1 AND
					category.active = 1				
				
				GROUP BY (id_product)');
        $this->template->baseUri = 'http://' . $_SERVER['HTTP_HOST'];
        $this->id_lang = 1;
        $this->template->items = array();
        foreach ($list as $k => $l) {
            $this->template->items[$k] = ProductModel::getProductWithParams($l['id_product'], $this->id_lang, NULL);
            $this->template->items[$k]['url'] = $this->link(':Front:Product:default', array('id' => $l['id_product'], 'id_category' => $this->template->items[$k]['main_category']));
            //zisti nazvy kategorii
            $category = array();
            foreach ($this->template->items[$k]['categories'] as $cat) {
                $tmp = CategoryModel::get($cat['id_category'], $this->id_lang);
                $category[] = $tmp['name'];
            }
            $this->template->items[$k]['categories_name'] = implode(" | ", $category);
        }
        //		dde($this->template->items);
    }
示例#26
0
 public function renderDefault($id, $id_category)
 {
     if (!$id) {
         throw new NBadRequestException('Product neexistuje');
     }
     $this->template->id_category = $id_category;
     $this->template->category_parents = CategoryModel::getParents($this->template->id_category, $this->id_lang);
     $this->template->product = ProductModel::getProductWithParams($id, $this->id_lang, $this->user);
     $this['productNewsSaleAvaiableTable']->setIdProduct($id);
     $this['productNewsSaleAvaiableTable']->setIdCategory($id_category);
     $this['productNewsSaleAvaiableTable']->setIdLang($this->id_lang);
     $this['productNewsSaleAvaiableTable']->setUser($this->user);
     /*
      * META INFO
      */
     if ($this->template->product) {
         if ($this->template->product['meta_title'] == '') {
             $this['header']->addTitle($this->template->product['name']);
         } else {
             $this['header']->addTitle($this->template->product['meta_title']);
         }
         if ($this->template->product['meta_description'] == '') {
             $this['header']->setDescription($this->template->product['name']);
         } else {
             $this['header']->setDescription($this->template->product['meta_description']);
         }
         $this['header']->addKeywords($this->template->product['meta_keywords']);
     }
     $this['header']['js']->addFile('jquery/bubblepopup/jquery.bubblepopup.v2.3.1.min.js');
     $this['header']['css']->addFile('../jscripts/jquery/bubblepopup/jquery.bubblepopup.v2.3.1.css');
 }
 /**
  * Create a discussion.
  * @param int The category id to add the discussion to.
  */
 public function Discussions()
 {
     $CategoryID = 1;
     $Session = Gdn::Session();
     $DiscussionID = isset($this->Discussion) ? $this->Discussion->DiscussionID : '';
     $this->CategoryID = isset($this->Discussion) ? $this->Discussion->CategoryID : $CategoryID;
     if (Gdn::Config('Vanilla.Categories.Use') === TRUE) {
         $CategoryModel = new CategoryModel();
         // Filter to categories that this user can add to
         $CategoryModel->SQL->Distinct()->Join('Permission _p2', '_p2.JunctionID = c.CategoryID', 'inner')->Join('UserRole _ur2', '_p2.RoleID = _ur2.RoleID', 'inner')->BeginWhereGroup()->Where('_ur2.UserID', $Session->UserID)->Where('_p2.`Vanilla.Discussions.Add`', 1)->EndWhereGroup();
         $this->CategoryData = $CategoryModel->GetFull();
     }
     if (isset($this->Discussion)) {
         if ($this->Discussion->InsertUserID != $Session->UserID) {
             $this->Permission('Vanilla.Discussions.Edit', $this->Discussion->CategoryID);
         }
     } else {
         $this->Permission('Vanilla.Discussions.Add');
     }
     // Set the model on the form.
     $this->Form->SetModel($this->DiscussionModel);
     if ($this->Form->AuthenticatedPostBack() === TRUE) {
         $FormValues = $this->Form->FormValues();
         // Check category permissions
         if ($this->Form->GetFormValue('Announce', '') != '' && !$Session->CheckPermission('Vanilla.Discussions.Announce', $this->CategoryID)) {
             $this->Form->AddError('You do not have permission to announce in this category', 'Announce');
         }
         if ($this->Form->GetFormValue('Close', '') != '' && !$Session->CheckPermission('Vanilla.Discussions.Close', $this->CategoryID)) {
             $this->Form->AddError('You do not have permission to close in this category', 'Close');
         }
         if ($this->Form->GetFormValue('Sink', '') != '' && !$Session->CheckPermission('Vanilla.Discussions.Sink', $this->CategoryID)) {
             $this->Form->AddError('You do not have permission to sink in this category', 'Sink');
         }
         if (!$Session->CheckPermission('Vanilla.Discussions.Add', $this->CategoryID)) {
             $this->Form->AddError('You do not have permission to start discussions in this category', 'CategoryID');
         }
         if ($this->Form->ErrorCount() == 0) {
             $DiscussionID = $this->DiscussionModel->Save($FormValues, $this->CommentModel);
             $this->Form->SetValidationResults($this->DiscussionModel->ValidationResults());
         }
     }
     if ($this->Form->ErrorCount() > 0) {
         // Return the form errors
         $this->SetJSON("errors", $this->Form->Errors());
     }
     $this->Render();
 }
示例#28
0
 public function goodsByCate($cateID, $n = null, $start = null)
 {
     $cateObj = new CategoryModel();
     $allCates = $cateObj->select();
     $cateList = $cateObj->getCatTree($allCates, $cateID);
     $cateIDList = array($cateID);
     foreach ($cateList as $v) {
         $cateIDList[] = $v['cat_id'];
     }
     $instring = implode(',', $cateIDList);
     $sql = 'select goods_id,goods_name, shop_price, market_price, thumb_img, add_time, goods_img from ' . $this->table . ' where cat_id in (' . $instring . ') order by add_time desc';
     if (is_numeric($n) && is_numeric($start)) {
         $sql .= ' limit ' . $start . ',' . $n;
     }
     $data = $this->db->getAll($sql);
     return $data;
 }
 /**
  * Show all categories and few discussions from each.
  *
  * @param string $Category The url code of the parent category.
  * @since 2.0.0
  * @access public
  */
 public function discussions($Category = '')
 {
     // Setup head
     $this->addJsFile('discussions.js');
     $this->Menu->highlightRoute('/discussions');
     if (!$this->title()) {
         $Title = c('Garden.HomepageTitle');
         if ($Title) {
             $this->title($Title, '');
         } else {
             $this->title(t('All Categories'));
         }
     }
     if (!$Category) {
         $this->Description(c('Garden.Description', null));
     }
     Gdn_Theme::section('CategoryDiscussionList');
     // Set the category follow toggle before we load category data so that it affects the category query appropriately.
     $CategoryFollowToggleModule = new CategoryFollowToggleModule($this);
     $CategoryFollowToggleModule->SetToggle();
     $this->CategoryModel->Watching = !Gdn::session()->GetPreference('ShowAllCategories');
     if ($Category) {
         $Subtree = CategoryModel::GetSubtree($Category, false);
         $CategoryIDs = consolidateArrayValuesByKey($Subtree, 'CategoryID');
         $Categories = $this->CategoryModel->GetFull($CategoryIDs)->resultArray();
     } else {
         $Categories = $this->CategoryModel->GetFull()->resultArray();
     }
     $this->setData('Categories', $Categories);
     // Get category data and discussions
     $this->DiscussionsPerCategory = c('Vanilla.Discussions.PerCategory', 5);
     $DiscussionModel = new DiscussionModel();
     $this->CategoryDiscussionData = array();
     foreach ($this->CategoryData->result() as $Category) {
         if ($Category->CategoryID > 0) {
             $this->CategoryDiscussionData[$Category->CategoryID] = $DiscussionModel->get(0, $this->DiscussionsPerCategory, array('d.CategoryID' => $Category->CategoryID, 'Announce' => 'all'));
         }
     }
     // Add modules
     $this->addModule('NewDiscussionModule');
     $this->addModule('DiscussionFilterModule');
     $this->addModule('CategoriesModule');
     $this->addModule('BookmarkedModule');
     $this->addModule($CategoryFollowToggleModule);
     // Set view and render
     $this->View = 'discussions';
     $this->canonicalUrl(url('/categories', true));
     $Path = $this->fetchViewLocation('helper_functions', 'discussions', false, false);
     if ($Path) {
         include_once $Path;
     }
     // For GetOptions function
     $Path2 = $this->fetchViewLocation('helper_functions', 'categories', false, false);
     if ($Path2) {
         include_once $Path2;
     }
     $this->render();
 }
示例#30
0
 static function getCategoryArrayWithLanguages($category_id, $language_id = null)
 {
     $categoryObj = CategoryModel::find_by_id($category_id);
     if ($categoryObj != null) {
         $cat = Activerecord::returnArrayWithLang($categoryObj, $language_id);
         return $cat;
     }
     return null;
 }