/** * Добавление статьи пользователем */ public function actionNew_article() { if (Yii::app()->request->isAjaxRequest) { if (isset($_POST['idMenu'])) { $category1 = array('' => 'Без категории'); $category2 = Categorys::getAllCategories($_POST['idMenu']); $category = $category1 + $category2; $filteredCategory = array(); $i = 0; foreach ($category as $key => $val) { $filteredCategory[$i]['id'] = $key; $filteredCategory[$i]['title'] = $val; $i++; } echo CJSON::encode(array('categorys' => $filteredCategory)); exit; } } // Проверки на доступ к странице if (Yii::app()->user->isGuest) { $this->redirect(Yii::app()->homeUrl); } if (isset($_POST['cancel'])) { $this->redirect(Yii::app()->homeUrl); } $model = new Articles('create'); // Нажата кнопка "Редактировать" или "Добавить" if (isset($_POST['Articles'])) { $oldFile = null; $oldFile = $model->photo; // Генерим имя фото if ('' != $_FILES['Articles']['name']['image']) { $fileName = AuxiliaryFunctions::getUniquNamePhoto($_FILES['Articles']['name']['image']); $_POST['Articles']['photo'] = $fileName; $oldFile = $model->photo; } $model->attributes = $_POST['Articles']; $model->idUser = Yii::app()->user->id; if ($model->validate()) { if ($model->save()) { if ($fileName) { AuxiliaryFunctions::savePhoto($model, $fileName, $oldFile); } if (1 == $model->public && 1 == $model->moderationAppruv) { $this->redirect($this->createAbsoluteUrl('articles/view_article', array('idArticle' => $model->idArticle, 'idMenu' => $model->idMenu))); } $this->redirect($this->createAbsoluteUrl('base/index', array('referrer' => 'new_article'))); } } } $menus = Mainmenu::model()->getDropDownMenu(); $idMenu = !empty($model->idMenu) ? $model->idMenu : key($menus); $category1 = array('' => 'Без категории'); $category2 = Categorys::getAllCategories($idMenu); $category = $category1 + $category2; $this->render('new_article', array('model' => $model, 'menus' => $menus, 'category' => $category)); }
/** * Заполняет ХЛЕБНЫЕ КРОШКИ * @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; }
} ?> <!-- <a href="#" class="textmndichvu">Lời ngỏ</a><br> <a href="#" class="textmndichvu">Giới thiệu chung công ty</a><br> <a href="#" class="textmndichvu">Năng lự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ỳ chũ Bắc Giang</a><br> <a href="#" class="textmndichvu">Miến dong</a><br> <a href="#" class="textmndichvu">Bánh đa nem dán</a><br> <a href="#" class="textmndichvu">Bán đa nem ăn sống</a><br> <a href="#" class="textmndichvu">Đỗ 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_article() { $idArticle = null; // Проверки на доступ к странице if (Yii::app()->user->isGuest) { $this->redirect($this->createAbsoluteUrl('default/index')); } if (isset($_POST['cancel'])) { $this->redirect($this->createAbsoluteUrl('default/list_articles', $_GET)); } if (isset($_POST['delete'])) { $this->actionDelete_article(); $this->redirect($this->createAbsoluteUrl('default/list_articles', $_GET)); } // Автокомплитер тегов if (isset($_GET['q'])) { $lastTag = end(explode(",", $_GET['q'])); $criteria = new CDbCriteria(); $criteria->condition = 'textTag LIKE :tag'; $criteria->params = array(':tag' => '%' . trim(htmlspecialchars($lastTag)) . '%'); if (isset($_GET['limit']) && is_numeric($_GET['limit'])) { $criteria->limit = $_GET['limit']; } $tags = Tags::model()->findAll($criteria); if ($tags) { $resStr = ''; foreach ($tags as $tag) { $resStr .= $tag->textTag . "\n"; } echo $resStr; } exit; } // Редактирование или добавление новой if (isset($_GET['idArticle'])) { $idArticle = $_GET['idArticle']; $model = Articles::model()->findByPk($_GET['idArticle']); $model['tagArray'] = AuxiliaryFunctions::getTagsList($model->tagstoarticles, false); } else { $model = new Articles('create'); } // Нажата кнопка "Редактировать" или "Добавить" if (isset($_POST['Articles'])) { $oldFile = null; $oldFile = $model->photo; $fileName = null; // Генерим имя фото if ('' != $_FILES['Articles']['name']['image']) { $fileName = AuxiliaryFunctions::getUniquNamePhoto($_FILES['Articles']['name']['image']); $_POST['Articles']['photo'] = $fileName; $oldFile = $model->photo; } $model->attributes = $_POST['Articles']; if (empty($model->idUser)) { $model->idUser = Users::getIdUserForAdmin(); } if ($model->validate()) { if ($model->save()) { $idArticle = $model->idArticle; if ($fileName) { AuxiliaryFunctions::savePhoto($model, $fileName, $oldFile); } // Теги для статьи if (isset($_POST['textTag'])) { $tagsArray = explode(",", $_POST['textTag']); $idArray = array(); foreach ($tagsArray as $item) { $tagId = null; if (!empty($item)) { $item = trim(htmlspecialchars($item)); } else { continue; } $tagResult = Tags::model()->findByAttributes(array('textTag' => $item)); if (null === $tagResult) { $newTag = new Tags(); $newTag->textTag = $item; if ($newTag->save()) { $tagId = $newTag->idTag; } } else { $tagId = $tagResult->idTag; } $idArray[] = $tagId; } if ($idArray) { foreach ($idArray as $item) { $item = (int) $item; $idArticle = (int) $idArticle; if (!TagsToArticles::model()->exists('idArticle = :idArticle AND idTag = :idTag', array(':idArticle' => $idArticle, ':idTag' => $item))) { $newTags2Art = new TagsToArticles(); $newTags2Art->idArticle = $idArticle; $newTags2Art->idTag = (int) $item; $newTags2Art->save(); } } } } $this->redirect($this->createAbsoluteUrl('default/list_articles', $_GET)); } } } $menus = Mainmenu::model()->getDropDownMenu(); $idMenu = !empty($model->idMenu) ? $model->idMenu : key($menus); $category1 = array('' => 'Без категории'); $category2 = Categorys::getAllCategories($idMenu); $category = $category1 + $category2; $tags = new Tags(); $this->render('//articles/save_article', array('model' => $model, 'menus' => $menus, 'category' => $category, 'tags' => $tags)); }