public function actionNewDetail($alias = null) { if (!empty($this->arrSystem)) { $this->pageTitle = "Tin tức - " . $this->arrSystem->title; } $new = $newRelated = null; $cateInfo = null; if (!empty($alias)) { // lay tin tuc theo alias $criteria = new CDBCriteria(); $criteria->addCondition("alias = :alias"); $criteria->params = array(":alias" => $alias); $new = News::model()->find($criteria); if (empty($new)) { throw new CHttpException(404, 'Không tìm thấy trang!.'); } else { // lay ten cua danh muc $cateInfo = CategoriesNews::model()->findByPK($new->category_news_id); // lay cac tin lien quan $criteria = new CDBCriteria(); $criteria->addCondition("alias != :alias and category_news_id = {$new->category_news_id} "); $criteria->params = array(":alias" => $alias); $criteria->order = "id DESC"; $criteria->limit = 5; $newRelated = News::model()->findAll($criteria); } } $this->render("newDetail", array('newInfo' => $new, 'newRelated' => $newRelated, 'cateInfo' => $cateInfo)); }
public function init() { $this->arrSystem = System::model()->find(); $this->arrInfo = Informations::model()->find(); $criteria = new CDBCriteria(); $criteria->addCondition("id!=1"); $this->arrCategoryNew = CategoriesNews::model()->findAll($criteria); }
public function loadModel($id) { $model = CategoriesNews::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function actionCreate() { $model = new SubCategoryNews(); if (isset($_POST['SubCategoryNews'])) { $model->attributes = $_POST['SubCategoryNews']; $model->created = time(); $model->alias = alias($_POST['SubCategoryNews']['name']); if ($model->save()) { Yii::app()->user->setFlash('success', translate('Thêm danh mục thành công.')); $this->redirect(PIUrl::createUrl('/admin/subCategoryNews/index')); } } $arrCate = CategoriesNews::model()->getDataCategories(); $this->render('create', array('model' => $model, 'arrCate' => $arrCate)); }
public function actionDetail($category = null, $alias = null) { $categoryNew = CategoriesNews::model()->findByAttributes(array('alias' => $category)); $model = News::model()->findByAttributes(array('alias' => $alias)); if (empty($categoryNew) || empty($model)) { throw new CHttpException(404, 'The requested page does not exist.'); } $this->pageTitle = $model->name . ($categoryNew->title ? ' - ' . $categoryNew->title : ''); $this->description = $model->description; $this->dataSystem->keyword = $categoryNew->keyword; //Related $criRelated = new CDBCriteria(); $criRelated->addCondition("category_news_id = " . $categoryNew['id']); $criRelated->addCondition("alias !=:alias"); $criRelated->params = array(':alias' => $alias); $criRelated->order = "id DESC"; $criRelated->limit = 8; $arrRelated = News::model()->findAll($criRelated); $this->render('detail', array('model' => $model, 'arrRelated' => $arrRelated)); }
/** * Retrieves a list of models based on the current search/filter conditions. * * Typical usecase: * - Initialize the model fields with values from filter form. * - Execute this method to get CActiveDataProvider instance which will filter * models according to data in model fields. * - Pass data provider to CGridView, CListView or any similar widget. * * @return CActiveDataProvider the data provider that can return the models * based on the search/filter conditions. */ public function search($id = null) { // @todo Please modify the following code to remove attributes that should not be searched. $criteria = new CDbCriteria(); $criteria->compare('id', $this->id); $criteria->compare('t.name', $this->name, true); $criteria->compare('alias', $this->alias, true); $criteria->compare('category_news_id', $this->category_news_id); //$criteria->compare('description',$this->description,true); $criteria->compare('content', $this->content, true); //$criteria->compare('image',$this->image,true); //$criteria->compare('created',$this->created); $criteria->with = array('categories'); $criteria->together = true; if ($id != null) { $model1 = CategoriesNews::model()->findByPk($id); $category = $model1->id; $criteria->addCondition("category_news_id = {$category}"); } return new CActiveDataProvider($this, array('criteria' => $criteria, 'sort' => array('defaultOrder' => 't.created DESC'))); }
</li> <li> <a href="<?php echo PIUrl::createUrl('/admin/facilities'); ?> "> <i class="icon-double-angle-right"></i> <span class="menu-text"> Cơ sở vật chất </span> </a> </li> </ul> </li>--> <?php $menus = CategoriesNews::model()->findAll(); if (!empty($menus)) { foreach ($menus as $menu) { ?> <li <?php if (curCA('controller') == 'news' && curCA('action') == 'index' && $_GET['id'] == $menu->id) { echo 'class="active"'; } ?> > <a href="<?php echo PIUrl::createUrl('/admin/news', array('id' => $menu->id)); ?> "> <i class="icon-edit"></i> <span class="menu-text"> <?php
public function actionUpdate($id = null) { $model = News::model()->findByPk($id); $flag = 0; $image_old = $model->attributes['image']; if (!empty($_POST['News'])) { if (!empty(CUploadedFile::getInstance($model, 'image')->name)) { $image_old = $model->attributes['image']; $path = realpath(Yii::app()->basePath . '/../upload/images/' . $image_old); if (file_exists($path) && !empty($image_old)) { unlink($path); } $model->attributes = $_POST['News']; $model->image = CUploadedFile::getInstance($model, 'image'); $image = $model->image; $imageType = explode('.', $model->image->name); $imageType = $imageType[count($imageType) - 1]; $imageName = md5(uniqid()) . '.' . $imageType; $model->image = $imageName; $images_path = Yii::getPathOfAlias('webroot') . '/upload/images/' . $imageName; $flag = 1; } else { $model->attributes = $_POST['News']; $model->image = $image_old; } $model->created = time(); $model->alias = alias($_POST['News']['name']); if ($model->save()) { Yii::app()->user->setFlash('success', translate('Cập nhật thành công.')); if ($flag == 1) { $image->saveAs($images_path); } $this->redirect(PIUrl::createUrl('/admin/news/' . $model->category_news_id)); } } $dataCategories = CategoriesNews::model()->getDataCategories(); $this->render('update', array('model' => $model, 'dataCategories' => $dataCategories)); }
public function linkCategory1($id) { $cate = CategoriesNews::model()->findByPK($id); $criteria = new CDbCriteria(); $criteria->addCondition("parent_id = " . $cate->id); $category = CategoriesNews::model()->find($criteria); if (!empty($category)) { $category = " >> " . $category->name; } else { $category = ''; } $link = $cate->name . $category; return $link; }
<h1>Danh sách tin tức</h1> </div><!--/.page-header--> <div class="row-fluid"> <div class="span12"> <a href="<?php echo PIUrl::createUrl('/admin/news/create/'); ?> " class="btn btn-primary"> <i class="icon-ok bigger-110"></i> <?php echo translate('Thêm'); ?> </a> <form method="post"> <?php $this->widget('zii.widgets.grid.CGridView', array('id' => 'news-grid', 'dataProvider' => $model->search(), 'filter' => $model, 'htmlOptions' => array(), 'itemsCssClass' => 'table table-striped table-bordered table-hover', 'emptyText' => 'Không có kết quả hiển thị', 'selectableRows' => 2, 'summaryText' => 'Hiển thị {start} - {end} của {count} kết quả ', 'columns' => array(array('id' => 'id', 'class' => 'CCheckBoxColumn'), array('header' => 'STT', 'value' => '$this->grid->dataProvider->pagination->currentPage * $this->grid->dataProvider->pagination->pageSize + ($row+1)'), 'image' => array('name' => 'image', 'type' => 'raw', 'filter' => false, 'value' => 'CHtml::image(getImage($data->image,"80", "60" ))', 'htmlOptions' => array("class" => "image")), 'name', 'categories.name' => array('name' => 'category_news_id', 'type' => 'raw', 'value' => 'CategoriesNews::model()->linkCategory($data->category_news_id)', 'filter' => CHtml::dropDownList('News[category_news_id]', ' ', CategoriesNews::model()->getDataCategories1())), 'created' => array('name' => 'created', 'type' => 'raw', 'filter' => false, 'value' => 'date(Yii::app()->params["date"],$data->created)'), array('header' => '<input type="button" name="deleteAll" class="deleteAll btn btn-mini btn-danger icon-trash bigger-120" value="Xóa" />', 'class' => 'CButtonColumn', 'template' => '{update}{delete}', 'buttons' => array('update' => array('options' => array('class' => 'btn btn-mini btn-info icon-edit bigger-120', 'title' => 'Sửa tin tức'), 'imageUrl' => false, 'label' => false, 'url' => 'PIUrl::createUrl("/admin/news/update", array("id"=>$data->id,"type"=>"2"))'), 'delete' => array('label' => false, 'options' => array('class' => 'btn btn-mini btn-danger icon-trash bigger-120', 'title' => 'Xóa tin tức'), 'imageUrl' => false)), 'deleteConfirmation' => 'Bạn có muốn xóa tin tức này không?')))); ?> </form> </div><!--/.span--> </div><!--/.row-fluid--> </div><!--/.page-content--> </div><!--/.main-content--> <style> .grid-view .filters input, .grid-view .filters select { width: 92%; } .image img{ width:80px; height:60px; } .btn-info{margin-right:3px;}
public function actionDeleteAll($id) { $arrIdNew = explode(",", $id); for ($i = 0; $i < count($arrIdNew); $i++) { // Delete all news of category new $model = CategoriesNews::model()->findByPk($arrIdNew[$i]); if (!empty($model)) { // delete news $criteria = new CDBCriteria(); if ($model->parent_id == 0) { $criCate = new CDBCriteria(); $criCate->addCondition("parent_id = " . $model->id); $arrCate = CategoriesNews::model()->findAll($criCate); foreach ($arrCate as $cate) { $criteria->addCondition("category_news_id = {$cate->id}"); $criteria->select = "id"; $arrNewID = News::model()->findAll($criteria); if (!empty($arrNewID)) { foreach ($arrNewID as $newId) { $modelNew = News::model()->find($newId->id); $path = "/../upload/images/"; $name = $modelNew->image; $this->unlink($path, $name); $modelNew->delete(); } } } } else { $criteria->addCondition("category_news_id = {$model->id}"); $criteria->select = "id"; $arrNewID = News::model()->findAll($criteria); if (!empty($arrNewID)) { foreach ($arrNewID as $newId) { $modelNew = News::model()->find($newId->id); $path = "/../upload/images/"; $name = $modelNew->image; $this->unlink($path, $name); $modelNew->delete(); } } } // delete sub category $criteria = new CDBCriteria(); $criteria->addCondition("parent_id = " . $arrIdNew[$i]); $cate = new CategoriesNews(); $cate->deleteAll($criteria); $model->delete(); } // Delete category new } if (!isset($_GET['ajax'])) { $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('index')); } }