/**
  * Заполняет ХЛЕБНЫЕ КРОШКИ
  * @param $id
  * @param $type (mainMenu, category, article)
  * @return array
  */
 public static function fillingBreadcrumbs($id, $type)
 {
     $breadcrumbs = array();
     switch ($type) {
         case 'mainMenu':
             $modelMenu = Mainmenu::model()->findByPk($id);
             $breadcrumbs = array($modelMenu->title => array('articles/list_articles', 'listType' => 'razdel', 'idMenu' => $modelMenu->idMenu));
             break;
         case 'category':
             $modelCategory = Categorys::model()->findByPk($id);
             $modelMenu = Mainmenu::model()->findByPk($modelCategory->idMenu);
             $breadcrumbs = array($modelMenu->title => array('articles/list_articles', 'listType' => 'razdel', 'idMenu' => $modelMenu->idMenu));
             $breadcrumbs = $breadcrumbs + array($modelCategory->title => array('articles/list_articles', 'listType' => 'category', 'idMenu' => $modelMenu->idMenu, 'idCategory' => $modelCategory->idCategory));
             break;
         case 'article':
             $modelArticle = Articles::model()->findByPk($id);
             $modelMenu = Mainmenu::model()->findByPk($modelArticle->idMenu);
             $breadcrumbs = array($modelMenu->title => array('articles/list_articles', 'listType' => 'razdel', 'idMenu' => $modelMenu->idMenu));
             if (!empty($modelArticle->idCategory)) {
                 $modelCategory = Categorys::model()->findByPk($modelArticle->idCategory);
                 $breadcrumbs = $breadcrumbs + array($modelCategory->title => array('articles/list_articles', 'listType' => 'category', 'idMenu' => $modelMenu->idMenu, 'idCategory' => $modelCategory->idCategory));
             }
             $breadcrumbs = $breadcrumbs + array($modelArticle->title);
             break;
     }
     return $breadcrumbs;
 }
 /**
  * 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
  */
 public function actionUpdate($id)
 {
     $model = $this->loadModel($id);
     $categorys = Categorys::model()->findAll(array('order' => 'name'));
     if (isset($_POST['Products'])) {
         $_POST['Products']['imageLink'] = $model->imageLink;
         $model->attributes = $_POST['Products'];
         $model->update_time = date("Y-m-d H:i:s");
         if (isset($_POST['category'])) {
             $model->category = $_POST['category'];
         }
         $uploadedFile = CUploadedFile::getInstance($model, 'imageLink');
         if ($uploadedFile) {
             $fileExtensionName = $uploadedFile->extensionName;
             $md5FileName = md5($uploadedFile);
             $fileName = "{$md5FileName}.{$fileExtensionName}";
             // random number + file name
             $model->imageLink = $fileName;
         }
         if ($model->save()) {
             //if click checkbox it will insert product_id to newProduct vs hotProduct table in database
             if (isset($_POST['newProduct_check'])) {
                 $product = Products::model()->find('name=:name', array(':name' => $model->name));
                 $id = $product->id;
                 $tableName = 'newproducts';
                 $newProduct = NewProducts::model()->find('product_id=:product_id', array(':product_id' => $id));
                 if (!$newProduct) {
                     $this->insertData($tableName, $id);
                 }
             }
             if (isset($_POST['hotProduct_check'])) {
                 $product = Products::model()->find('name=:name', array(':name' => $model->name));
                 $id = $product->id;
                 $tableName = 'hotproducts';
                 $hotProduct = HotProducts::model()->find('product_id=:product_id', array(':product_id' => $id));
                 if (!$hotProduct) {
                     $this->insertData($tableName, $id);
                 }
             }
             if (!empty($uploadedFile)) {
                 $uploadedFile->saveAs(Yii::app()->basePath . '/../images/Product/' . $model->imageLink);
             }
             $this->redirect(array('admin'));
         }
     }
     $this->render('update', array('model' => $model, 'categorys' => $categorys));
 }
 /**
  * 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 Categorys the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Categorys::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Exemple #4
0
}
?>
		<!-- <a href="#" class="textmndichvu">L&#7901;i ng&#7887;</a><br>
		<a href="#" class="textmndichvu">Gi&#7899;i thi&#7879;u chung công ty</a><br>
		<a href="#" class="textmndichvu">N&#259;ng l&#7921;c công ty</a><br> -->
	</div>
</div>	

<div id="footerbox2">
    <div class="footerheading">
       	<h4 class="footerheading">Sản Phẩm</h4>
    </div>
    <div class="footertxt">

    	<?php 
$categorys = Categorys::model()->findAll(array("limit" => 5));
foreach ($categorys as $key => $value) {
    echo '<li>';
    echo CHtml::link($value->name, array('categorys/view', 'id' => $value->id));
    echo '</li>';
}
?>

		<!-- <a href="#" class="textmndichvu">M&#7923; ch&#361; B&#7855;c Giang</a><br>
		<a href="#" class="textmndichvu">Mi&#7871;n dong</a><br>
		<a href="#" class="textmndichvu">Bánh &#273;a nem dán</a><br>
		<a href="#" class="textmndichvu">Bán &#273;a nem &#259;n s&#7889;ng</a><br>
		<a href="#" class="textmndichvu">&#272;&#7895; xanh</a><br> -->
	</div>
</div>	
 /**
  * Карта сайта
  */
 public function actionSite_map()
 {
     // ITEMS MENUS
     $menus = Mainmenu::model()->findAll(array('condition' => 'type = "middle" AND partSite = "site" AND visible = 1'));
     $itemsArray = array();
     foreach ($menus as $oneMenu) {
         $itemMenu = array('label' => $oneMenu->title, 'url' => array($oneMenu->link, 'listType' => 'razdel', 'idMenu' => $oneMenu->idMenu), 'itemOptions' => array('class' => 'itemMenu'), 'linkOptions' => array('class' => 'linkMenu'));
         // ITEMS CATEGORYS
         $categorys = Categorys::model()->findAll(array('condition' => 'idMenu = :idMenu AND active = 1', 'params' => array(':idMenu' => $oneMenu->idMenu)));
         // ITEMS ARTICLES (MENU)
         $articlesMenu = Articles::model()->findAll(array('condition' => 'moderationAppruv = 1 AND public = 1 AND deleted = 0 AND idMenu = :idMenu AND idCategory = 0', 'params' => array(':idMenu' => $oneMenu->idMenu)));
         $categoryItems = array();
         if (!empty($categorys)) {
             foreach ($categorys as $oneCategory) {
                 $itemCategory = array('label' => $oneCategory->title, 'url' => array('articles/list_articles', 'listType' => 'category', 'idMenu' => $oneCategory->idMenu, 'idCategory' => $oneCategory->idCategory), 'itemOptions' => array('class' => 'itemCategory'), 'linkOptions' => array('class' => 'linkCategory'));
                 // ITEMS ARTICLES (MENU - CATEGORY)
                 $articles = Articles::model()->findAll(array('condition' => 'moderationAppruv = 1 AND public = 1 AND deleted = 0 AND idMenu = :idMenu AND idCategory = :idCategory', 'params' => array(':idMenu' => $oneMenu->idMenu, ':idCategory' => $oneCategory->idCategory)));
                 if (!empty($articles)) {
                     $catMenuArtItem = array();
                     foreach ($articles as $oneArticle) {
                         $catMenuArtItem['items'][] = array('label' => $oneArticle->title, 'url' => array('articles/view_article', 'idArticle' => $oneArticle->idArticle, 'idMenu' => $oneArticle->idMenu), 'itemOptions' => array('class' => 'itemArticle'), 'linkOptions' => array('class' => 'linkArticle'));
                     }
                     $categoryItems['items'][] = $itemCategory + $catMenuArtItem;
                 } else {
                     $categoryItems['items'][] = $itemCategory;
                 }
             }
         }
         if (!empty($articlesMenu)) {
             foreach ($articlesMenu as $oneArticleMenu) {
                 $categoryItems['items'][] = array('label' => $oneArticleMenu->title, 'url' => array('articles/view_article', 'idArticle' => $oneArticleMenu->idArticle, 'idMenu' => $oneArticleMenu->idMenu), 'itemOptions' => array('class' => 'itemArticle'), 'linkOptions' => array('class' => 'linkArticle'));
             }
         }
         if (!empty($categoryItems['items'])) {
             $itemsArray['items'][] = $itemMenu + $categoryItems;
         } else {
             $itemsArray['items'][] = $itemMenu;
         }
     }
     $this->render('site_map', array('itemsArray' => $itemsArray));
 }
 public function actionSave_category()
 {
     // Проверки на доступ к странице
     if (Yii::app()->user->isGuest) {
         $this->redirect($this->createAbsoluteUrl('default/index'));
     }
     if (isset($_POST['cancel'])) {
         $this->redirect($this->createAbsoluteUrl('default/list_categorys', $_GET));
     }
     // Редактирование или добавление новой
     if (isset($_GET['idCategory'])) {
         $model = Categorys::model()->findByPk($_GET['idCategory']);
     } else {
         $model = new Categorys();
     }
     if (isset($_POST['Categorys'])) {
         $fileName = null;
         $oldFile = $model->photo;
         // Генерим имя фото
         if (!empty($_FILES) && '' != $_FILES['Categorys']['name']['image']) {
             $fileName = AuxiliaryFunctions::getUniquNamePhoto($_FILES['Categorys']['name']['image']);
             $_POST['Categorys']['photo'] = $fileName;
             $oldFile = $model->photo;
         }
         $model->attributes = $_POST['Categorys'];
         if ($model->validate()) {
             if ($model->save()) {
                 if ($fileName) {
                     AuxiliaryFunctions::savePhoto($model, $fileName, $oldFile);
                 }
                 if (Yii::app()->request->isAjaxRequest) {
                     echo CJSON::encode(array('result' => array('id' => $model->idCategory, 'title' => $model->title)));
                     exit;
                 } else {
                     $this->redirect($this->createAbsoluteUrl('default/list_categorys', $_GET));
                 }
             } else {
                 if (Yii::app()->request->isAjaxRequest) {
                     echo CJSON::encode(array('error' => 'save'));
                     exit;
                 }
             }
         } else {
             if (Yii::app()->request->isAjaxRequest) {
                 echo CJSON::encode(array('error' => 'validation'));
                 exit;
             }
         }
     }
     $menus = Mainmenu::model()->getDropDownMenu();
     if (isset($_POST['popup'])) {
         $popup = $this->renderPartial('categorys/save_category', array('model' => $model, 'menus' => $menus), true);
         echo CJSON::encode(array('popup' => $popup));
         exit;
     } else {
         $this->render('categorys/save_category', array('model' => $model, 'menus' => $menus));
     }
 }