Exemplo n.º 1
0
 public function upload()
 {
     if ($this->validate()) {
         $cat = Categories::findOne($this->id);
         $contr = Yii::$app->controllerNamespace . '\\' . ucfirst($cat->handler) . 'Controller';
         $base = $contr::baseStorePath();
         $store_to = $base['real'] . $cat->route;
         foreach ($this->files as $f) {
             $new_fn = $this->newFileName($f->baseName, $f->extension);
             if ($f->saveAs($store_to . $new_fn)) {
                 $res = new Resources();
                 $res->attachBehavior('ImageBehavior', ['class' => ImageBehavior::className()]);
                 $res->category_id = $this->id;
                 $res->title = $res->description = $f->baseName;
                 $res->keywords = $new_fn;
                 //реальное имя файла с расширением
                 $res->alias = str_replace('.' . $f->extension, '', $new_fn);
                 //псевдоним изначально равен имени файла
                 $res->path = $store_to;
                 $res->webroute = $base['web'] . $cat->route;
                 $res->filename = $new_fn;
                 $res->save();
             }
             //TODO обработка ошибки сохранения файла
         }
         return true;
     }
     return false;
 }
Exemplo n.º 2
0
 protected function findModel($id)
 {
     if (($model = Categories::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemplo n.º 3
0
 /**
  * Lists all Apis models that fit in a Category.
  * @param integer $categoryId
  * @return mixed
  */
 public function actionIndexbycategory($categoryId)
 {
     $searchModel = new ApisSearch();
     $queryParams = array_merge(['ApisSearch' => ['cbs' => 0, 'category' => $categoryId]], Yii::$app->request->getQueryParams());
     $dataProvider = $searchModel->search($queryParams);
     $category = Categories::findOne($categoryId);
     return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'category' => $category]);
 }
Exemplo n.º 4
0
 public static function getCategoryID($category)
 {
     if (is_null(\app\models\Categories::findOne(['category' => $category]))) {
         return null;
     } else {
         return \app\models\Categories::findOne(['category' => $category])->id;
     }
 }
Exemplo n.º 5
0
 /**
  * Загружает запись модели текущего контроллера по айдишнику
  * @param $id
  * @return null|static
  * @throws \yii\web\HttpException
  */
 public function loadModel($id)
 {
     $model = Categories::findOne($id);
     if ($model === null) {
         throw new \yii\web\HttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Exemplo n.º 6
0
 public function actionViewall($cid = 2)
 {
     $query = Article::find()->where(['cid' => $cid, 'published' => 1]);
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count()]);
     $models = $query->offset($pages->offset)->limit($pages->limit)->orderBy('ordering')->all();
     $cat = \app\models\Categories::findOne($cid);
     return $this->render('viewall', ['model' => $models, 'cat' => $cat, 'pages' => $pages]);
 }
Exemplo n.º 7
0
 public function actionCategory($id)
 {
     $model = Categories::findOne($id);
     $category = $model->find()->where(['id' => $id])->one();
     $news = new News();
     $data = $news->fromCategory($id, 20, $this->paging(20));
     $datat1 = $news->fromCategory($id, 5, 0);
     $datat2 = $news->fromCategory($id, 4, 5);
     return $this->render('itemcategory', ['data' => $data, 'datat1' => $datat1, 'datat2' => $datat2, 'category' => $category, 'model' => $model]);
 }
Exemplo n.º 8
0
 public static function getHierarchy($id)
 {
     $cat = Categories::findOne($id);
     $hier = [];
     while ($cat !== null) {
         $hier[] = $cat;
         $cat = Categories::findOne($cat->parent_id);
     }
     return $hier;
 }
Exemplo n.º 9
0
 public function actionList($id)
 {
     if ($id == 0) {
         throw new \yii\web\BadRequestHttpException("Неправильный запрос");
     }
     $q = Resources::find()->where(['category_id' => $id]);
     $dataProvider = new ActiveDataProvider(['query' => $q]);
     $uploadModel = new FileUploadModel();
     $uploadModel->id = $id;
     return $this->render('list', ['dataProvider' => $dataProvider, 'album' => Categories::findOne($id), 'uploadModel' => $uploadModel]);
 }
Exemplo n.º 10
0
 /**
  ** Вывод списка страниц. Если задан $id категории - списка страниц категории
  */
 public function actionList($id = 0)
 {
     $q = Resources::find();
     if ($id > 0) {
         $q->where(['category_id' => $id]);
     } else {
         $q->joinWith('category')->where(['categories.handler' => $this->id]);
     }
     $dataProvider = new ActiveDataProvider(['query' => $q, 'pagination' => false]);
     return $this->render('list', ['category' => Categories::findOne($id), 'dataProvider' => $dataProvider, 'category_id' => $id]);
 }
Exemplo n.º 11
0
 private function getStoreInfo()
 {
     $path = [];
     switch ($this->tableId) {
         case Resources::$tableId:
             $model = Resources::findOne($this->id);
             $handler = $model->category->handler;
             $route = $model->route;
             break;
         case Categories::$tableId:
             $model = Categories::findOne($this->id);
             $handler = $model->handler;
             $route = $model->route;
             break;
         default:
             throw new InvalidConfigException('FileUploadModel - неизвестный ID таблицы');
             break;
     }
     $contrClass = Yii::$app->controllerNamespace . '\\' . ucfirst($handler) . 'Controller';
     $path = $contrClass::baseStorePath();
     $path['route'] = $route;
     return $path;
 }
Exemplo n.º 12
0
 public function actionUpdate($id = null)
 {
     $model = new Categories();
     if ($model->load($_POST)) {
         $id = $_POST['Categories']['id'];
         if ($id) {
             $model = Categories::findOne($id);
             $model->attributes = $_POST['Categories'];
         }
         if ($model->save()) {
             return $this->redirect(['index', 'langs' => $_POST['Categories']['langs']]);
         } else {
             print_r($model->getErrors());
             exit;
         }
     }
     if ($id) {
         $model = Categories::findOne($id);
     } else {
         $model->langs = $_REQUEST['langs'];
     }
     return $this->render('update', ['model' => $model]);
 }
Exemplo n.º 13
0
 public function actionUpdate($id = null)
 {
     $model = new Categories();
     if ($model->load(Yii::$app->request->post())) {
         $request = Yii::$app->request->post('Categories');
         $id = $request['id'];
         if ($id) {
             $model = Categories::findOne($id);
             $model->attributes = $request;
         }
         if ($model->save()) {
             return $this->redirect(['index', 'langs' => $request['langs']]);
         } else {
             print_r($model->getErrors());
             exit;
         }
     }
     if ($id) {
         $model = Categories::findOne($id);
     } else {
         $model->langs = Yii::$app->getRequest()->getQueryParam('langs', 'thai');
     }
     return $this->render('update', ['model' => $model]);
 }
Exemplo n.º 14
0
 /**
  * Сделал дело
  * @return string
  */
 public function actionDoneDeal()
 {
     if (Yii::$app->getRequest()->getQueryParam('user')) {
         $start_day = strtotime('now 00:00:00', time() + 7 * 60 * 60);
         $user = MarkUser::findOne(Yii::$app->getRequest()->getQueryParam('user'));
         if (Yii::$app->getRequest()->getQueryParam('deal')) {
             try {
                 $deal = DiaryDeals::find()->where("name like '" . trim(Yii::$app->getRequest()->getQueryParam('deal')) . "'")->one();
             } catch (\ErrorException $e) {
                 $deal = [];
             }
             if (!$deal) {
                 return 'Ошибка!';
             }
             //return var_dump($deal);
             $act = new DiaryActs();
             $act->model_id = 5;
             $act->user_id = $user->id;
             $act->mark = $deal->mark;
             $act->mark_status = 0;
             //return var_dump($act);
             if ($act->save(false)) {
                 $done_deal = new DiaryDoneDeal();
                 $done_deal->deal_id = $deal->id;
                 $done_deal->act_id = $act->id;
                 $done_deal->user_id = $user->id;
                 //return var_dump($done_deal);
                 if ($done_deal->save()) {
                     $today_acts = implode(',', ArrayHelper::map(DiaryActs::find()->where("time > {$start_day} and user_id = " . $user->id)->all(), 'id', 'id'));
                     $deals = [];
                     $sum_mark = 0;
                     $deal_cats = [];
                     $cat_deal = [];
                     if ($today_acts) {
                         $today_deals = DiaryDoneDeal::find()->where("act_id IN (" . $today_acts . ")")->all();
                         $sum_mark = DiaryActs::find()->select('SUM(mark)')->where("time > {$start_day} and user_id = " . $user->id)->scalar();
                         $mark_accumul = DiaryActs::find()->select('SUM(mark)')->where("time > " . mktime(0, 0, 0, 9, 1, 2016) . " and user_id = " . $user->id)->scalar();
                         $users_money = MarkUser::findOne(11)->money;
                         $money = $mark_accumul + $users_money;
                         foreach ($today_deals as $done_deal) {
                             $deals[] = DiaryDeals::findOne($done_deal->deal_id);
                             $deal_cats[Categories::findOne($done_deal->deal->cat_id)->name][] = DiaryDeals::findOne($done_deal->deal_id)->mark;
                             //return var_dump($done_deal->deal->cat_id);
                         }
                         foreach ($deal_cats as $cat => $marks) {
                             $mark = 0;
                             foreach ($marks as $mrk) {
                                 $mark += $mrk;
                             }
                             $cat_deal[$cat][] = $mark;
                         }
                     }
                     $all_deals = DiaryDeals::find()->all();
                     //return var_dump($deals);
                     return $this->renderPartial('deals', ['deal_cats' => $cat_deal, 'sum_mark' => $sum_mark, 'user' => $user, 'money' => $money]);
                 }
                 return $this->renderPartial('error');
             }
         }
     }
 }
Exemplo n.º 15
0
 /**
  * Отображает новости
  * @return string
  * @throws HttpException
  */
 public function actionPosts($category_url = null)
 {
     $this->layout = 'main';
     $query = Posts::find()->where(['active' => 1]);
     if ($category_url) {
         $category = Categories::findOne(['active' => 1, 'url' => $category_url]);
         if (!$category) {
             throw new HttpException(404, 'Категория не существует.');
         }
         $query = $query->andWhere(['category_id' => $category->id]);
     }
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => 5, 'pageParam' => 'pageNum', 'forcePageParam' => false, 'pageSizeParam' => false]);
     $models = $query->offset($pages->offset)->limit($pages->limit)->all();
     return $this->render('posts', ['posts' => $models, 'pages' => $pages]);
 }
Exemplo n.º 16
0
 /**
  * Finds the Categories model based on its slugUrl value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $alias
  * @return Categories the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModelBySlugUrl($alias)
 {
     if (($model = Categories::findOne(['slugUrl' => $alias])) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemplo n.º 17
0
 /**
  * Updates an existing Race model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $sports = Sport::findAll(['status' => 'ACTIVE']);
     $categories = Category::find()->all();
     $c = [];
     foreach ($categories as $category) {
         $c[$category->id] = $category->name;
     }
     $picture = UploadedFile::getInstance($model, 'picture');
     $sponsor = UploadedFile::getInstance($model, 'sponsor');
     $attachment1 = UploadedFile::getInstance($model, 'attachment1');
     $attachment2 = UploadedFile::getInstance($model, 'attachment2');
     $last_picture = $model->picture;
     $last_attachment1 = $model->attachment1;
     $last_attachment2 = $model->attachment2;
     if ($model->load(Yii::$app->request->post())) {
         if ($_POST['pictureChanged'] == 'true') {
             // unlink('images/'.$last_picture);
             if ($picture != NULL) {
                 $name = date('Y_m_d_H_i_s_') . $picture->baseName . '.' . $picture->extension;
                 $model->picture = $name;
             }
         } else {
             $model->picture = $last_picture;
         }
         if ($_POST['sponsorChanged'] == 'true') {
             if ($sponsor != NULL) {
                 if ($picture != NULL) {
                     $model->sponsor = $name;
                 } else {
                     $model->sponsor = $last_picture;
                 }
             }
         } else {
             $model->sponsor = $last_picture;
         }
         if ($_POST['attachment1Changed'] == 'true') {
             if ($attachment1 != NULL) {
                 $name1 = date('Y_m_d_H_i_s_') . $attachment1->baseName . '.' . $attachment1->extension;
                 $model->attachment1 = $name1;
             }
         } else {
             $model->attachment1 = $last_attachment1;
         }
         if ($_POST['attachment2Changed'] == 'true') {
             if ($attachment2 != NULL) {
                 $name2 = date('Y_m_d_H_i_s_') . $attachment2->baseName . '.' . $attachment2->extension;
                 $model->attachment2 = $name2;
             }
         } else {
             $model->attachment2 = $last_attachment2;
         }
         if ($_POST['Race']['categories'] != '') {
             foreach ($model->categories as $i => $category) {
                 if (!array_search($category->id, $_POST['Race']['categories'])) {
                     $nt = Category::findOne($category->id);
                     $model->unlink('categories', $nt, true);
                 }
             }
             foreach ($_POST['Race']['categories'] as $i => $category) {
                 if (!Categories::findOne(['race_id' => $model->id, 'category_id' => $category])) {
                     $nt = Category::findOne($category);
                     $model->link('categories', $nt);
                 }
             }
         } else {
             $model->unlinkAll('categories', true);
         }
         if ($model->save()) {
             if ($picture != NULL) {
                 $picture->saveAs('img/carrera/' . $name);
             }
             if ($sponsor != NULL) {
                 if ($picture != NULL) {
                     $sponsor->saveAs('img/carrera/auspiciante/' . $name);
                 } else {
                     $sponsor->saveAs('img/carrera/auspiciante/' . $last_picture);
                 }
             }
             if ($attachment1 != NULL) {
                 $attachment1->saveAs('img/carrera/adjunto/' . $name1);
             }
             if ($attachment2 != NULL) {
                 $attachment2->saveAs('img/carrera/adjunto/' . $name2);
             }
             return $this->redirect(['view', 'id' => $model->id]);
         }
     } else {
         return $this->render('update', ['model' => $model, 'sports' => $sports, 'categories' => $c]);
     }
 }
Exemplo n.º 18
0
use yii\widgets\DetailView;
use app\models\UserFrontend;
use app\models\Categories;
/* @var $this yii\web\View */
/* @var $model app\models\Task */
$this->title = $model->name;
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Tasks'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="task-view">

    <h1><?php 
echo Html::encode($this->title);
?>
</h1>

    <p>
        <?php 
echo Html::a(Yii::t('app', 'Update'), ['update', 'id' => $model->id], ['class' => 'btn btn-primary']);
?>
        <?php 
echo Html::a(Yii::t('app', 'Delete'), ['delete', 'id' => $model->id], ['class' => 'btn btn-danger', 'data' => ['confirm' => Yii::t('app', 'Are you sure you want to delete this item?'), 'method' => 'post']]);
?>
    </p>

    <?php 
echo DetailView::widget(['model' => $model, 'attributes' => ['id', ['label' => 'Kategoria', 'value' => Categories::findOne(['id' => $model->category_id])->name], ['label' => 'Użytkownik', 'value' => UserFrontend::findOne(['id' => $model->user_id])->username], 'name', ['label' => 'Zadanie wykonane', 'value' => $model->status == 1 ? 'Tak' : 'Nie']]]);
?>

</div>
Exemplo n.º 19
0
 protected function findGallery($id)
 {
     if (($model = Categories::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('Ресурс не найден');
     }
 }
Exemplo n.º 20
0
<?php

//VAR_DEF
$content_vars = ['slideshow' => 'Слайд-шоу'];
$param_vars = ['title' => 'Заголовок страницы', 'keywords' => 'Ключевые слова (для поисковиков)', 'description' => 'Описание (для поисковиков)', 'album_id' => 'ID альбома для слайд-шоу'];
//
//VAR_VAL
$title = 'Мини-трактор МТМ-10';
$keywords = 'МТМ-10, трактор, мини-трактор, ооо мобиль, ЖКХ, фермер, личное, хозяйство';
$description = 'МТМ-10 - недорогой универсальный малогабаритный трактор. Трактор МТМ-10 построен из отечественных комплектующих, что обеспечивает высокую ремонтопригодность и низкую стоимость запасных частей. Широкий выбор навесных и прицепных агрегатов позволяет выполнять обширный спектр работ в фермерских и личных подсобных хозяйствах, в жилищно-коммунальном хозяйстве и на малых производственных площадках';
$album_id = 51;
//
//VAR_IMPLEMENT
$this->title = $title;
//
$album = \app\models\Categories::findOne(['id' => $album_id, 'handler' => 'album']);
if ($album == null) {
    $slideshow = '#Альбом_не_найден';
} else {
    $img_list = [];
    foreach ($album->resources as $img) {
        $img->attachBehavior('ImageBehavior', ['class' => \app\components\ImageBehavior::className()]);
        $img_list[] = ['title' => $img->title, 'href' => $img->imageUrl, 'thumbnail' => $img->thumbnailUrl];
    }
    $slideshow = \app\widgets\blueimp\BlueimpGallery::widget(['items' => $img_list, 'mode' => 2]);
}
//
?>

<h2>Мини-трактор МТМ-10</h2><p><?php 
echo $slideshow;
Exemplo n.º 21
0
 public static function genText($news)
 {
     $files = Files::find()->where(['news_id' => $news->id])->all();
     $files_in_text = '';
     if (!empty($files)) {
         foreach ($files as $file) {
             $files_in_text .= sprintf("<a style='color:blue; font-weight:bold;' target='_blank' href='http://%s/%s/%s/%s/%s/%s.%s'>%s.%s</a><br />", $_SERVER['SERVER_NAME'], Files::SUB_DIR, Files::UPLOAD_DIR, Files::UPLOAD_FILE_DIR, $file->dir, $file->file_name, $file->ext, $file->origin_file_name, $file->ext);
         }
     }
     if (!empty($news->start_date)) {
         $start_date = Yii::$app->formatter->asDate($news->start_date, 'php:d.m.Y');
         $date_in_text = sprintf('<u>Дата ввода в действие</u>: %s <br />', $start_date);
         if ($news->type == \app\models\News::NT_CAMPAIGN) {
             $stop_date = Yii::$app->formatter->asDate($news->stop_date, 'php:d.m.Y');
             $date_in_text = sprintf('<u>Срок действия акции</u>: %s - %s <br />', $start_date, $stop_date);
         }
     } else {
         $date_in_text = '';
     }
     // ----------------------------
     // Документ, регламентирующий изменения --------------------
     if (!empty($news->document)) {
         $document_in_text = sprintf('<u>Документ, регламентирующий изменения</u>: %s <br />', $news->document);
     } else {
         $document_in_text = '';
     }
     if (!empty($news->product)) {
         $product_in_text = sprintf('<u>Продукт</u>: %s <br />', $news->product);
     } else {
         $product_in_text = '';
     }
     $category_title_in_text = sprintf('<u>Сегмент</u>: %s <br />', Categories::findOne($news->category_id)->title);
     $textGen = sprintf("<div style='font-size:10pt;font-family:Arial,serif;'><br />\n                %s\n                %s\n                %s\n                %s\n                <br />%s\n                %s\n            </div>", $date_in_text, $category_title_in_text, $document_in_text, $product_in_text, $news->text, $files_in_text);
     return $textGen;
 }
Exemplo n.º 22
0
 public function getCatName($cid)
 {
     $cat = Categories::findOne($cid);
     return $cat->title;
 }
Exemplo n.º 23
0


    </div>
    <div id="nav" class="row">

        <?php 
foreach ($cats as $cat) {
    ?>


            <div class="col-md-2 col-sm-12 col-xs-12 col-lg-2" >


            <?php 
    $items = \app\models\Categories::findOne(['name' => $cat->name]);
    $leaves = $items->leaves()->all();
    if ($leaves) {
        ?>
                    <div id="<?php 
        echo $cat->cssclass;
        ?>
" class="root" ><a href="#"><b><?php 
        echo $cat->title;
        ?>
</b></a>

                    <div class="inside">
                    <?php 
        foreach ($leaves as $leave) {
            ?>
Exemplo n.º 24
0
$this->title = Yii::t('app', 'Zadania');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="task-index">

    <h1><?php 
echo Html::encode($this->title);
?>
</h1>
    <?php 
// echo $this->render('_search', ['model' => $searchModel]);
?>

    <p>
        <?php 
echo Html::a(Yii::t('app', 'Create Task'), ['create'], ['class' => 'btn btn-success']);
?>
    </p>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'id', ['label' => 'Kategoria', 'value' => function ($model) {
    return Categories::findOne(['id' => $model->category_id])->name;
}], ['label' => 'Użytkownik', 'value' => function ($model) {
    return UserFrontend::findOne(['id' => $model->user_id])->username;
}], 'name', ['label' => 'Zadanie wykonane', 'value' => function ($model) {
    return $model->status == 1 ? 'Tak' : 'Nie';
}], ['class' => 'yii\\grid\\ActionColumn']]]);
?>

</div>