public function loadModel($id)
 {
     if (($model = Category::model()->findByPk($id)) === null) {
         throw new CHttpException(404, 'Страница не найдена');
     }
     return $model;
 }
Beispiel #2
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate($cat_id = null)
 {
     if (Yii::app()->user->checkAccess($this->id . '.' . $this->action->id)) {
         $model = new PaymentType();
         // Uncomment the following line if AJAX validation is needed
         //             $this->performAjaxValidation($model);
         if (isset($_POST['PaymentType'])) {
             $model->attributes = $_POST['PaymentType'];
             $model->category_id = $cat_id;
             if ($model->save()) {
                 if (Yii::app()->request->isAjaxRequest) {
                     echo CJSON::encode(array('status' => 'success', 'div' => 'Payment Type successfully added.'));
                     exit;
                 } else {
                     // Yii::app()->user->setFlash('success', 'Payment Type added successfully!');
                     $this->redirect(Yii::app()->user->returnUrl);
                 }
             }
         }
         //            $model->category_id = $cat_id;
         if (Yii::app()->request->isAjaxRequest) {
             echo CJSON::encode(array('status' => 'failure', 'div' => $this->renderPartial('_form', array('model' => $model), true, true)));
             exit;
         } else {
             $this->render('create', array('model' => $model, 'cat_name' => Category::model()->findByPk($cat_id)->getFullCategory()));
         }
     } else {
         $this->accessDenied();
     }
 }
Beispiel #3
0
 public function init()
 {
     //   Yii::app()->theme = 'forum';
     //   Yii::app()->name = 'ifuckforum';
     $this->isconfig = Sconfig::model()->find();
     $this->controllerId = ucfirst($this->getId());
     if (Yii::app()->user->getState('cplang')) {
         Yii::app()->language = Yii::app()->user->getState('cplang');
     }
     //Yii::app()->language = 'en_us';
     //print_r( Yii::app()->language);
     if (Yii::app()->user->getState('scategory')) {
         //print_r(Yii::app()->user->getState('scategory'));
     } else {
         $_scategory = Category::model()->findAll(array('select' => 'id,name'));
         $__scategory = array();
         foreach ($_scategory as $icat) {
             $__scategory[$icat['id']]['id'] = $icat['name'];
         }
         unset($_scategory);
         Yii::app()->user->setState('scategory', $__scategory);
     }
     if ($this->isconfig && $this->isconfig->is_oops) {
         //echo "oops";
         //exit;
     }
     if (!Yii::app()->user->isGuest) {
         $this->iuser = User::model()->findByPk(Yii::app()->user->id);
     }
 }
 public function run()
 {
     $inn = false;
     $cat = Category::model()->with('categoryDescriptions')->find('categoryDescriptions.link=:link', array(':link' => $this->current));
     if (!empty($cat)) {
         $catName = $cat->getName();
         $categories = $cat->categories;
         if (empty($categories)) {
             $categories = array($cat);
             $inn = true;
         }
         //echo print_r($categories);
     } else {
         $catName = 'All';
         $categories = Category::model()->findAll();
     }
     $products = array();
     $nbrands = $brands = array();
     foreach ($categories as $category) {
         $products = array_merge($products, $category->products);
     }
     foreach ($products as $product) {
         $nbrands[] = $product->manufacturer_id;
     }
     $nbrands = array_unique($nbrands, SORT_NUMERIC);
     foreach ($nbrands as $nbrand) {
         $manu = Manufacturer::model()->findByPk($nbrand);
         if (!empty($manu)) {
             $brands[$nbrand] = $manu->name;
         }
     }
     //$brands = asort($brands);
     $this->render('category_navigation', array('inn' => $inn, 'cat' => $cat, 'name' => $catName, 'categories' => $categories, 'products' => $products, 'brands' => $brands, 'current' => $this->current));
 }
Beispiel #5
0
 private function getAllCategories()
 {
     $criteria = new CDbCriteria();
     $criteria->order = "name asc";
     $categories = Category::model()->findAll($criteria);
     return $categories;
 }
    public function actionAdmin($catPk, $opts = array())
	{
        $cat = Category::model()->findByPk($catPk);

		$model = $this->loadModel($catPk, null, 'search');

        $this->ajaxSetNextValue('published', $model, 'published', array(BaseDataType::PUBLISHED, BaseDataType::NOT_PUBLISHED));
		$model->unsetAttributes();  // clear any default values

        $model = $model->current($cat);

		if (isset($_GET[get_class($model)]))
			$model->attributes=$_GET[get_class($model)];

		$opts['model'] = $model;
        $opts['cat'] = $cat;

        $opts['columns'] = array();
        $opts = Y::hooks()->cmsAdminGetGridColumns($this, &$opts);

		if (isset($_GET['ajax'])) {
			$this->renderPartial('admingrid',$opts);
		} else {
    		$this->render('admin',$opts);
        }
	}
 public function actionEdit($id)
 {
     //var_dump($_POST);
     if ($_POST && $id) {
         if ($_POST['nest-act'] == 'create-parent' && $_POST['name_cat'] !== '') {
             //echo '<script>alert("111")</script>';
             $node = Category::model()->findByPk($id);
             $category = new Category();
             $category->name = CHtml::encode($_POST['name_cat']);
             $category->appendTo($node);
             //$this->actionIndex();
         }
         if ($_POST['nest-act'] == 'delete' && $id !== '11') {
             $node = Category::model()->findByPk($id);
             $node->deleteNode();
         }
         if ($_POST['nest-act'] == 'rename') {
             $node = Category::model()->findByPk($id);
             $node->name = CHtml::encode($_POST['name_cat']);
             $node->saveNode();
         }
         header('Location: /category');
         die;
     }
     $param = Category::model()->findByPk($id);
     $this->render('edit', ['model' => $param]);
 }
 private function loadModel($param = '')
 {
     $status = 'publish';
     $criteria = new CDbCriteria();
     $criteria->condition = "parent=0";
     $this->_labels = Label::model()->findAll($criteria);
     $this->_category = Category::model()->findAll($criteria);
     $criteria->condition = "post_status =:status";
     $criteria->params = array(':status' => $status);
     if ($param == 'post') {
         $criteria->order = "ID desc";
     } elseif ($param == 'populer') {
         $criteria->order = "post_hits desc";
     } else {
         $criteria->order = "ID desc";
     }
     foreach ($this->_labels as $label) {
         if ($label->slug == $param) {
             $criteria->with = array("labels");
             $criteria->together = true;
             $criteria->condition = "labels.slug='{$param}'";
             $criteria->order = "ID desc";
         }
     }
     foreach ($this->_category as $cat) {
         if ($cat->slug == $param) {
             $criteria->with = array("categories");
             $criteria->together = true;
             $criteria->condition = "categories.slug='{$param}'";
             $criteria->order = "ID desc";
         }
     }
     $dataProvider = new CActiveDataProvider('Post', array('criteria' => $criteria, 'pagination' => array('pageSize' => 10)));
     return $dataProvider;
 }
 public function actions()
 {
     if (!($limit = (int) $this->module->rssCount)) {
         throw new CHttpException(404);
     }
     $criteria = new CDbCriteria();
     $criteria->order = 'date DESC';
     $criteria->params = array();
     $criteria->limit = $limit;
     $title = $this->yupe->siteName;
     $description = $this->yupe->siteDescription;
     $categoryId = (int) Yii::app()->getRequest()->getQuery('category');
     if (!empty($categoryId)) {
         $category = Category::model()->cache($this->yupe->coreCacheTime)->published()->findByPk($categoryId);
         if (null === $category) {
             throw new CHttpException(404);
         }
         $title = $category->name;
         $description = $category->description;
         $criteria->addCondition('category_id = :category_id');
         $criteria->params[':category_id'] = $categoryId;
     }
     $data = News::model()->cache($this->yupe->coreCacheTime)->with('user')->published()->public()->findAll($criteria);
     return array('feed' => array('class' => 'yupe\\components\\actions\\YFeedAction', 'data' => $data, 'title' => $title, 'description' => $description, 'itemFields' => array('author_object' => 'user', 'author_nickname' => 'nick_name', 'content' => 'short_text', 'datetime' => 'date', 'link' => '/news/news/show', 'linkParams' => array('title' => 'alias'), 'title' => 'title', 'updated' => 'change_date')));
 }
Beispiel #10
0
 public function actionView()
 {
     $pid = Yii::app()->request->getParam('pid');
     $cid = Yii::app()->request->getParam('cid');
     $id = Yii::app()->request->getParam('id');
     $category = Category::model()->findByPk($pid);
     if ($category->taxonomy_id == $this->root_id) {
         $data = array();
         $data['item'] = Content::model()->findbyPk($id);
         if ($data['item']->category_id == $cid) {
             $data['cat'] = Category::model()->findbyPk($data['item']->category_id);
             $data['root_cat'] = Taxonomy::model()->findbyPk($data['cat']->taxonomy_id);
             $this->title = $data['item']->title;
             Content::model()->updateByPk($id, array('view' => $data['item']->view + 1));
             $data['comment_model'] = Comment::model()->findAll(array('condition' => 'content_id = :cid and state = 1', 'params' => array(':cid' => $id)));
             if ($data['item']->category_id != $cid) {
                 throw new CHttpException(404, 'PAGE NOT FOUND.');
             }
             $this->render('view', $data);
         } else {
             throw new CHttpException(404, 'PAGE NOT FOUND.');
         }
     } else {
         throw new CHttpException(404, 'PAGE NOT FOUND.');
     }
 }
Beispiel #11
0
 /**
  * @return array customized attribute labels (name=>label)
  */
 public function attributeLabels()
 {
     return array('category_id' => 'ID', 'name' => '类目', 'parent_id' => '上一级', 'url' => 'SEO URL', 'pic' => '分类图片', 'sort_order' => '排序', 'is_show' => '显示');
 }
Beispiel #12
0
 public function actionSubmitIdea()
 {
     $model = new SubmitIdeaForm();
     $categories = CHtml::listData(Category::model()->findAll(), 'idCategory', 'category');
     $truthOrDare = array('Truth' => 'Truth', 'Dare' => 'Dare');
     $model->username = Yii::app()->user->name;
     if (isset($_POST['SubmitIdeaForm'])) {
         $model->attributes = $_POST['SubmitIdeaForm'];
         if ($model->validate()) {
             $type = strtolower($model->truthOrDare);
             $modelTruthOrDare = new $type();
             $modelTruthOrDare->idCategory = $model->idCategory;
             $modelTruthOrDare->idUser = Yii::app()->user->getId();
             $modelTruthOrDare->dateSubmit = date('Y-m-d, H:i:s');
             $modelTruthOrDare->anonymous = $model->anonymous;
             $modelTruthOrDare->{$type} = $model->idea;
             if ($modelTruthOrDare->save()) {
                 Yii::app()->user->setFlash('submitIdea', 'Your idea has been submited and will be displayed on the website after validation of the Truth Or Dare Team!');
             } else {
                 Yii::app()->user->setFlash('submitIdea', 'Sorry, there was a problem during the saving process..! Please try again...');
             }
         }
     }
     $this->render('submitIdea', array('model' => $model, 'truthOrDare' => $truthOrDare, 'categories' => $categories));
 }
Beispiel #13
0
 /**
  * 分类页面默认控制器
  */
 public function actionIndex()
 {
     $filter = Category::model()->parseFilter($_REQUEST);
     $result = Category::model()->getCategoryProducts($filter);
     if (empty($result) || empty($result['list']) || $result['count'] <= 0) {
         $this->redirect('/?from=no_list');
         //跳转到首页
     }
     $options = Category::model()->getCategoryOptions($filter);
     $pages = '';
     //正常分页信息
     $pageShort = '';
     //短分页信息
     $urlStr = '/category/' . Common::instance()->getFormatUrl('category', $filter);
     if ($result['count'] > 0) {
         $pages = Common::instance()->get_page_list($result['count'], $filter['p'], $filter['limit'], $urlStr, 'category');
         $pageShort = Common::instance()->get_page_short($result['count'], $filter['p'], $filter['limit'], $urlStr, 'category');
     }
     $cakeInfo = Category::model()->getCakeLine($filter['id']);
     $userId = $this->user_id;
     if ($userId) {
         $result['list'] = Category::model()->getCategoryProductLikeStatus($userId, $result['list']);
     }
     $viewData = array();
     $viewData['list'] = $result['list'];
     $viewData['count'] = $result['count'];
     $viewData['options'] = $options;
     $viewData['filter'] = $filter;
     $viewData['pages'] = $pages;
     $viewData['pageShort'] = $pageShort;
     $viewData['cakeInfo'] = $cakeInfo;
     $this->render('category/index', $viewData);
 }
 public function run()
 {
     $criteria = new CdbCriteria();
     $criteria->limit = $this->data('limit');
     $criteria->offset = $this->data('offset');
     $criteria->condition = "post_status='publish' AND (post_modified <= '" . date('Y-m-d H:i:s') . "' AND post_modified >= '" . $this->data('time') . "')";
     $criteria->order = 'post_hits DESC';
     if ($this->data('autoByTerm')) {
         if (isset($_GET['id'])) {
             $category = Category::model()->findByPK((int) $_GET['id']);
             $label = Label::model()->findByPK((int) $_GET['id']);
             $topic = Topic::model()->findByPK((int) $_GET['id']);
             $tag = Tag::model()->findByPK((int) $_GET['id']);
             if ($category != null) {
                 $criteria = $this->getCriteriaTerm('categories', $criteria);
             } elseif ($label != null) {
                 $criteria = $this->getCriteriaTerm('labels', $criteria);
             } elseif ($topic != null) {
                 $criteria = $this->getCriteriaTerm('topics', $criteria);
             } elseif ($tag != null) {
                 $criteria = $this->getCriteriaTerm('tags', $criteria);
             }
         }
     }
     $model = Post::model()->findAll($criteria);
     if ($model != null) {
         $this->layout($model);
     }
 }
 public function run()
 {
     parent::run();
     $data = array();
     $id_listen_cat = Category::model()->findAll("taxonomy_id = " . $this->_id_bai_hoc . " and state = 1");
     $id_listen_cat_array = array();
     foreach ($id_listen_cat as $k) {
         $id_listen_cat_array[] = $k->id;
     }
     $id_news_cat = Category::model()->findAll("taxonomy_id = " . $this->_id__tintuc . " and state = 1");
     $id_news_cat_array = array();
     foreach ($id_news_cat as $k) {
         $id_news_cat_array[] = $k->id;
     }
     $comment = Comment::model()->findAll(array("condition" => "state = 1", "limit" => 5, "order" => "id desc"));
     $options = array();
     $i = 0;
     foreach ($comment as $k) {
         $options[$i]['content'] = Content::model()->findByPk($k->content_id);
         $options[$i]['category'] = Category::model()->findByPk($options[$i]['content']->category_id);
         $options[$i]['parent'] = '';
         if ($options[$i]['category']->parent != 0) {
             $options[$i]['parent'] = Category::model()->findByPk($options[$i]['category']->parent);
         }
         $options[$i]['taxonomy'] = Taxonomy::model()->findByPk($options[$i]['category']->taxonomy_id);
         $i++;
     }
     $data['comments'] = $comment;
     $data['options'] = $options;
     $data['news'] = Content::model()->findAll(array("condition" => "state = 1 and category_id in (" . implode(",", $id_news_cat_array) . ")", "limit" => 10, "order" => "id desc"));
     $data['listen'] = Content::model()->findAll(array("condition" => "state = 1 and category_id in (" . implode(",", $id_listen_cat_array) . ")", "limit" => 10, "order" => "id desc"));
     $this->render('news_lession_comment', $data);
 }
Beispiel #16
0
 public function actionIndex()
 {
     $product_id = intval($_REQUEST['id']);
     $pInfo = Product::model()->getProductInfoById($product_id);
     if (empty($pInfo)) {
         $this->redirect('/?from=no_goods');
         //跳转到首页
     }
     $brandInfo = '';
     if ($pInfo['brand_id']) {
         $brandInfo = Brand::model()->findByPk($pInfo['brand_id']);
     }
     $stock = Product::model()->getProductStock($product_id, $pInfo['is_multiple']);
     $attrList = ProductAttributes::model()->getProductAttrNameList();
     $extendAttrList = ProductExtend::model()->getProductExtendAttrs($product_id);
     $is_like = Like::model()->getLikeStatus($this->user_id, $product_id);
     $cake = Category::model()->getCakeLine($pInfo['cat_id']);
     //获取商品的面包屑
     $viewData = array();
     $viewData['pInfo'] = $pInfo;
     $viewData['brandInfo'] = $brandInfo;
     $viewData['is_like'] = $is_like;
     $viewData['cake'] = $cake;
     $viewData['stock'] = $stock;
     $viewData['attrList'] = $attrList;
     $viewData['extendAttrList'] = $extendAttrList;
     $this->render('item/index', $viewData);
 }
Beispiel #17
0
 public function actionIndex($key)
 {
     $category = Category::model()->findByPk(3);
     $model = $category->findByAttributes(array('url' => $key));
     if ($model) {
         $childs = $model->descendants()->findAll();
         $ids = array($model->id);
         foreach ($childs as $child) {
             $ids[] = $child->id;
         }
         $cid = implode(',', $ids);
         $criteria = new CDbCriteria(array('condition' => 'category_id in ( ' . $cid . ')', 'order' => 'item_id desc, sort_order desc'));
         $count = Item::model()->count($criteria);
         $pages = new CPagination($count);
         // results per page
         $pages->pageSize = 20;
         $pages->applyLimit($criteria);
         $items = Item::model()->findAll($criteria);
         //	$items = new CActiveDataProvider('Item', array(
         //            'criteria' => $criteria
         //        ));
         $criteria = new CDbCriteria(array('condition' => 'is_hot = 1 and category_id in ( ' . $cid . ')', 'limit' => '4', 'order' => 'item_id desc, sort_order desc'));
         $hotItems = Item::model()->findAll($criteria);
         $this->render('index', array('model' => $model, 'items' => $items, 'pages' => $pages, 'hotItems' => $hotItems, 'key' => $key));
     } else {
         $this->render('index');
     }
 }
Beispiel #18
0
 {
     parent::init();
 }
 public function run()
 {
     $key = $_REQUEST['key'];
     $model = Category::model()->findByAttributes(array('url' => $key));
Beispiel #19
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = Category::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
 private function loadCategory($id, $slug)
 {
     $model = Category::model()->findByAttributes(array('term_id' => (int) $id, 'slug' => $slug));
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Beispiel #21
0
 public function actionCategory($alias)
 {
     $category = Category::model()->getByAlias($alias);
     if (null === $category) {
         throw new CHttpException(404, Yii::t('BlogModule.blog', 'Page was not found!'));
     }
     $this->render('category-post', array('target' => $category, 'posts' => Post::model()->getForCategory($category->id)));
 }
Beispiel #22
0
 public function actionView($id)
 {
     $category = Category::model()->findByPk($id);
     if (is_null($category)) {
         die('Invalid category');
     }
     $this->render('index', array('products' => $category->activeProducts));
 }
Beispiel #23
0
 /**
  * 获取分类信息
  * @param int $id
  * @return CActiveRecord|mixed
  */
 public function showCategory($id = 0)
 {
     $data = Yii::app()->cache->get('category-' . $id);
     if (empty($data)) {
         $data = Category::model()->findByPk($id);
         Yii::app()->cache->set('category-' . $id, $data);
     }
     return $data;
 }
Beispiel #24
0
 public function run()
 {
     $cat = isset($_GET['cat']) ? $_GET['cat'] : 3;
     $model = Category::model()->findByAttributes(array('url' => $cat, 'root' => 3));
     $childs = $model->children()->findAll();
     //        foreach($childs as $child)
     //            $ids[] = $child->id;
     $this->render('left_menu', array('childs' => $childs, 'model' => $model));
 }
Beispiel #25
0
 public static function GetCategories()
 {
     $cats = Category::model()->findAll();
     $lookup = array();
     foreach ($cats as $cat) {
         $lookup[$cat->Category_ID] = $cat->Name;
     }
     return $lookup;
 }
Beispiel #26
0
 public function actionView($slug = null)
 {
     $category = Category::model()->getByAlias($slug);
     if (is_null($category)) {
         throw new CHttpException(404, Yii::t('GalleryModule.gallery', 'Requested page was not found.'));
     }
     $dataProvider = new CActiveDataProvider('Gallery', ['criteria' => ['condition' => 'category_id = :category_id', 'scopes' => 'published', 'params' => [':category_id' => $category->id]], 'sort' => ['defaultOrder' => 'id DESC']]);
     $this->render('view', ['dataProvider' => $dataProvider, 'category' => $category]);
 }
Beispiel #27
0
  */
 public $layout = '//layouts/column2';
 public $parent;
 function init()
 {
     parent::init();
     //上一级 可支持无限级 分类
     //上一级 可支持无限级 分类
     $data = Category::model()->findAll(array('order' => 'sort_order asc, cate_id asc'));
Beispiel #28
0
 /**
  * Returns an array with the hierarchy of cid's
  * (100 (CLS)? => (1 (Automovil), 50 (Mercedes), 100 (CLS)
  */
 public static function getCategoryHierarchy($cid = null)
 {
     if (isset($cid) && $cid > 0) {
         $category = Category::model()->findByPk($cid);
         return array_merge(self::getCategoryHierarchy($category->parentcid), array($category->cid));
     } else {
         return array();
     }
 }
Beispiel #29
0
 public function actionPortfolio($cat_id = 0)
 {
     if ($cat_id) {
         $model = Category::model()->findByPk(intval($cat_id));
     } else {
         $model = Category::model()->find();
     }
     //        $model = Category::model()->findAll();
     $this->render('portfolio', array('model' => $model));
 }
 public function categoriesListData()
 {
     $categoriesTree = Category::model()->roots()->findAll();
     $categories = array();
     foreach ($categoriesTree as $category) {
         //$categories[$category->name] = CHtml::listData($category->children()->findAll(), 'id', 'name');
         $categories[$category->id] = $category->name;
     }
     return $categories;
 }