コード例 #1
0
 /**
  * getListItems - Phương thức dùng để lấy dữ liệu
  */
 public function getListItems($category_id = null)
 {
     Yii::import('application.modules.news.models.NewsItem');
     $model = new NewsItem('search');
     $model->unsetAttributes();
     $criteria = new CDbCriteria();
     $criteria->order = 'created DESC';
     if ($category_id) {
         Yii::import('application.modules.news.models.NewsCategory');
         $categories = NewsCategory::model()->findByPk($category_id);
         if (!$categories) {
             return null;
         }
         $this->__category = $categories;
         $descendants = $categories->descendants()->findAll('is_active = 1');
         $arrCat = array($category_id);
         foreach ($descendants as $cat) {
             $arrCat[] = $cat->id;
         }
         $criteria->with = array('categoryitem');
         $criteria->together = true;
         foreach ($arrCat as $cat) {
             $criteria->compare('categoryitem.category_id', $cat, false, 'OR');
         }
     }
     $criteria->compare('status', 1);
     $search = new CActiveDataProvider($model, array('criteria' => $criteria, 'pagination' => array('pageSize' => Yii::app()->getModule('news')->entriesLastestShow)));
     $data = $search->getData();
     return $data;
 }
コード例 #2
0
 /**
  * @test
  */
 public function create()
 {
     $model = NewsCategory::model();
     $this->assertInstanceOf('NewsCategory', $model);
     $model = new NewsCategory();
     $model->attributes = array('name' => 'test');
     $this->assertTrue($model->save());
 }
コード例 #3
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 $id the ID of the model to be loaded
  * @return NewsCategory the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = NewsCategory::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
コード例 #4
0
 public function run()
 {
     $criteria = new CDbCriteria();
     $criteria->select = 'name, alt_name, title';
     $criteria->order = 'name';
     $model = NewsCategory::model()->findAll($criteria);
     $this->render('widgetCategories', array('model' => $model));
 }
コード例 #5
0
 /**
  * getData - Phương thức dùng để lấy dữ liệu
  */
 public function getData()
 {
     $arrTrees = array();
     Yii::import('application.modules.news.models.NewsCategory');
     $treeRoot = NewsCategory::model()->roots()->find();
     if ($treeRoot) {
         $descendants = $treeRoot->descendants()->findAll('is_active = 1');
         $tree = $treeRoot->toArray($descendants);
         $arrTrees = $this->__getListChilds($tree);
     }
     return $arrTrees;
 }
コード例 #6
0
ファイル: NewsController.php プロジェクト: Cranky4/npfs
 /**
  * Список новостей
  */
 public function actionIndex($idCategory = null)
 {
     $criteria = new CDbCriteria();
     $criteria->scopes = array('last');
     $newsModule = $this->getModule();
     $category = null;
     $categories = array();
     //Если включено отображение категорий
     if ($newsModule->showCategories) {
         if ($idCategory !== null && ($category = $this->loadModelOr404('NewsCategory', $idCategory))) {
             $criteria->compare('t.id_news_category', $idCategory);
         }
         $categories = NewsCategory::model()->findAll(array('order' => 'seq'));
     }
     $count = News::model()->count($criteria);
     $pages = new CPagination($count);
     $pages->pageSize = $newsModule->itemsCountPerPage;
     $pages->applyLimit($criteria);
     $news = News::model()->findAll($criteria);
     $this->render('/index', array('news' => $news, 'pages' => $pages, 'category' => $category, 'categories' => $categories));
 }
コード例 #7
0
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id the ID of the model to be updated
  * @throws Exception
  */
 public function actionUpdate($id)
 {
     /** @var myWebUser $webUser */
     /** @noinspection PhpUndefinedFieldInspection */
     $webUser = Yii::app()->user;
     /** @var News $model */
     $model = News::model()->findByPk($id);
     $hasErrors = false;
     // Sauvegarde de l'objet News
     if (isset($_POST['News'])) {
         $model->attributes = $_POST['News'];
         if ($model->save()) {
             $webUser->setFlash('success', Yii::t('msg', 'Object saved'));
         } else {
             $webUser->setFlash('error', Yii::t('msg', 'There are errors. Please check the form'));
             $hasErrors = true;
         }
     }
     // Sauvegarde d'une des traductions
     if (isset($_POST['TranslatedNews'])) {
         $fields = array_shift($_POST['TranslatedNews']);
         /** @var $translation TranslatedNews */
         if (!($translation = TranslatedNews::model()->findByPk($fields['id']))) {
             throw new Exception(h::_("Traduction introuvable #" . $fields['id'], __FILE__, __LINE__, __METHOD__));
         }
         $oldTagsString = $translation->tagsString;
         $translation->attributes = $fields;
         if ($translation->save() && $this->saveTranslatedNewsTags($translation, $oldTagsString)) {
             $webUser->setFlash('success', Yii::t('msg', 'Object saved'));
         } else {
             $webUser->setFlash('error', Yii::t('msg', "There are errors in some sub-forms"));
             $hasErrors = true;
         }
         $translations = array();
         foreach ($model->translatedNews as $i => $it) {
             // Dans la liste des traduction de la news, on cherche celle qui est l'objet de la mise à jour
             // et on remplace le modèle chargé initialement par celui qui vient d'être validé,
             // (donc qui a une liste d'erreurs en cas de problèmes)
             if ($it->id == $translation->id) {
                 $translations[$i] = $translation;
             } else {
                 $translations[$i] = $it;
             }
         }
     }
     if (isset($_POST['backToList']) && !$hasErrors) {
         // On a cliqué le bouton 'revenir à la liste' et le formulaire a bien été traité
         $this->redirect(array('admin'));
     }
     /** @noinspection PhpUndefinedMethodInspection */
     $this->render('update', array('model' => $model, 'translations' => isset($translations) ? $translations : $model->translatedNews, 'categories' => NewsCategory::model()->alpha()->findAll(), 'languages' => $this->languages));
 }
コード例 #8
0
ファイル: main.php プロジェクト: Vladimirtishenko/val
<?php 
$this->widget('application.components.widgets.FlashWidget');
?>
<!---- End Flash message ---->

<div class="modal-background-pop-up">
	<div class="arhive -drop-down-pop-up" data-attr="arhive">
	    <?php 
$this->beginWidget('CActiveForm', array('id' => 'srhiv', 'method' => 'get', 'action' => array('/site/search')));
?>
		
	    <?php 
echo CHtml::textField('find', '', array('class' => 'form-control', 'placeholder' => Yii::t('main', 'Шукати...')));
?>
	    <?php 
echo CHtml::dropDownList('category', '', CHtml::listData(NewsCategory::model()->findAll(), 'id', Yii::app()->language == 'ru' ? 'name_ru' : 'name_uk') + array('video' => Yii::t('main', 'Відео'), 'photo' => Yii::t('main', 'Фото')), array('class' => 'form-control', 'placeholder' => Yii::t('main', 'Шукати...'), 'empty' => Yii::t('main', 'Всі категорії')));
?>
	    <?php 
$this->widget('zii.widgets.jui.CJuiDatePicker', array('name' => 'publishDate', 'language' => 'uk', 'options' => array('showAnim' => 'fold', 'dateFormat' => 'yy-mm-dd'), 'htmlOptions' => array('class' => 'form-control', 'placeholder' => "Дата...")));
?>
	    <?php 
echo CHtml::tag('button', array('class' => 'btn btn-info'), '<span class="fa fa-search"></span>');
?>
	    <?php 
$this->endWidget();
?>
	</div>



	<div class="logins -drop-down-pop-up" data-attr="login">
コード例 #9
0
 public function loadModel($id)
 {
     $model = NewsCategory::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'Запись не найдена.');
     }
     return $model;
 }
コード例 #10
0
ファイル: _form.php プロジェクト: Vladimirtishenko/val.ua
echo $form->labelEx($model, 'main');
?>
            <?php 
echo $form->dropDownList($model, 'main', array(0 => Yii::t('main', 'Ні'), 1 => Yii::t('main', 'Так')));
?>
            <?php 
echo $form->error($model, 'main');
?>
        </div>

        <div class="row">
            <?php 
echo $form->labelEx($model, 'category_id');
?>
            <?php 
echo $form->dropDownList($model, 'category_id', CHtml::listData(NewsCategory::model()->findAll(array('order' => 'name_uk ASC')), 'id', 'name_uk'), array('empty' => 'Вiбiр категорii'));
?>
            <?php 
echo $form->error($model, 'category_id');
?>
        </div>

        <div class="row">
            <?php 
echo $form->labelEx($model, 'region');
?>
            <?php 
echo $form->dropDownList($model, 'region', array('Прилуки' => Yii::t('main', 'Прилуки'), 'Нежин' => Yii::t('main', 'Нежин'), 'Новгород-Северский' => Yii::t('main', 'Новгород-Северский')), array('empty' => 'додайте регіон, якщо такий є'));
?>
            <?php 
echo $form->error($model, 'region');
コード例 #11
0
 public function actionCDelete($id)
 {
     if (Yii::app()->user->isGuest or Yii::app()->user->access_level < Config::get('access_level_admin')) {
         $this->redirect(Yii::app()->homeUrl);
     }
     $model = NewsCategory::model()->findByPK($id);
     $model->delete();
     $this->redirect(Yii::app()->homeUrl . 'news/categories');
 }
コード例 #12
0
ファイル: news_form.php プロジェクト: noiary/Aion-Core-v4.7.5
				<td width="150px"><?php 
echo $form->labelEx($model, 'title');
?>
</td>
				<td><?php 
echo $form->textField($model, 'title', array('size' => 64, 'maxlength' => 128));
?>
</td>
			</tr>
			<tr>
				<td><?php 
echo $form->labelEx($model, 'category_id');
?>
</td>
				<td><?php 
echo $form->dropDownList($model, 'category_id', CHtml::listData(NewsCategory::model()->findAll(), 'category_id', 'name'));
?>
</td>
			</tr>
			<tr>
				<td><?php 
echo $form->labelEx($model, 'short_story');
?>
</td>
			</tr>
			<tr>
				<td colspan="2"><?php 
echo CHtml::activeTextArea($model, 'short_story');
?>
</td>
			</tr>
コード例 #13
0
 /**
  * Manages all models.
  */
 public function actionAdmin($category = '')
 {
     $baseScriptUrl = Yii::app()->assetManager->publish(dirname(__FILE__) . '/../assets');
     Yii::app()->getClientScript()->registerCssFile($baseScriptUrl . '/news.css');
     if (isset($_POST['product-item-grid_c0'])) {
         foreach ($_POST['product-item-grid_c0'] as $strNewID) {
             $model = $this->loadModel($strNewID);
             $model->delete();
         }
     }
     $model = new NewsItem('search');
     $model->unsetAttributes();
     // clear any default values
     if (isset($_GET['NewsItem'])) {
         $model->attributes = $_GET['NewsItem'];
     }
     if ($category) {
         $arrCat = array($category);
         $categories = NewsCategory::model()->findByPk($category);
         if ($categories) {
             $descendants = $categories->descendants()->findAll('is_active = 1');
             foreach ($descendants as $cat) {
                 $arrCat[] = $cat->id;
             }
         }
         $model->categories = $arrCat;
     }
     $this->render('admin', array('model' => $model));
 }
コード例 #14
0
ファイル: News.php プロジェクト: Aplay/myhistorypark_site
 /**
  * Set organization categories 
  * @param array $categories ids.
  */
 public function setCategories(array $categories, $add = false)
 {
     $dontDelete = array();
     if (!empty($categories)) {
         foreach ($categories as $c) {
             if (empty($c)) {
                 continue;
             }
             $found = NewsCategory::model()->findByAttributes(array('category' => $c, 'news' => $this->id));
             // если не было категории - делаем
             if (!$found) {
                 $record = new NewsCategory();
                 $record->category = (int) $c;
                 $record->news = $this->id;
                 $record->save(false);
             }
             $dontDelete[] = $c;
         }
     }
     if ($add === false) {
         // Удаляем все категории, которых не было в массиве
         if (sizeof($dontDelete) > 0) {
             $cr = new CDbCriteria();
             $cr->addNotInCondition('category', $dontDelete);
             NewsCategory::model()->deleteAllByAttributes(array('news' => $this->id), $cr);
         } else {
             // удаляем все категории, т.к. пустой массив
             // Delete all relations
             NewsCategory::model()->deleteAllByAttributes(array('news' => $this->id));
         }
     }
 }
コード例 #15
0
 /**
  * @param $alias
  */
 public function actionCategory($alias)
 {
     $mostViewed = News::model()->with(array('category' => array('condition' => 'category.alias = :alias', 'select' => false, 'params' => array(':alias' => $alias))))->findAll(array('order' => 'date DESC', 'limit' => 6));
     $notIn = '';
     foreach ($mostViewed as $i => $model) {
         if ($i == 5) {
             $notIn .= $model->id;
         } else {
             $notIn .= $model->id . ',';
         }
     }
     $dataProvider = new CActiveDataProvider('News', array('criteria' => array('condition' => 'category.alias = :alias AND t.id NOT IN(' . trim($notIn, ',') . ')', 'params' => array(':alias' => $alias), 'with' => array('category'), 'order' => 'date DESC'), 'sort' => false, 'pagination' => array('pageSize' => 30)));
     $category = NewsCategory::model()->findByAttributes(array('alias' => $alias));
     $this->rightReclameId = 'rightColumnCategory' . ucfirst($category->alias);
     $this->render('category', array('dataProvider' => $dataProvider, 'category' => $category, 'mostViewed' => $mostViewed));
 }
コード例 #16
0
ファイル: _form.php プロジェクト: KEFIR4UK/yii
$form = $this->beginWidget('CActiveForm', array('id' => 'news-form', 'enableAjaxValidation' => false));
?>

	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<?php 
echo $form->errorSummary($model);
?>

	<div class="row">
		<?php 
echo $form->labelEx($model, 'category_id');
?>

		<?php 
$list = CHtml::listData(NewsCategory::model()->findAll(), 'id', 'title');
?>
		<?php 
echo $form->dropDownList($model, 'category_id', $list, array('empty' => '(Select Category)'));
?>
		<?php 
echo $form->error($model, 'category_id');
?>
	</div>

	<div class="row">
		<?php 
echo $form->labelEx($model, 'title');
?>
		<?php 
echo $form->textField($model, 'title', array('size' => 60, 'maxlength' => 255));