Example #1
0
 public function actionMap()
 {
     Yii::$app->response->format = Response::FORMAT_RAW;
     $headers = Yii::$app->response->headers;
     $headers->add('Content-Type', 'text/xml');
     $dom = new \DOMDocument("1.0", "utf-8");
     $root = $dom->createElement("urlset");
     $root->setAttribute("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9");
     $dom->appendChild($root);
     $categories = Category::findAll(['is_active' => 1]);
     $articles = Article::findAll(['is_active' => 1]);
     $items = array_merge($categories, $articles);
     foreach ($items as $item) {
         $url = $dom->createElement("url");
         $loc = $dom->createElement("loc");
         if ($item instanceof Article) {
             $loc->appendChild($dom->createTextNode(Url::to(['article/view', 'id' => $item->id], true)));
         } else {
             $loc->appendChild($dom->createTextNode(Url::to(['category/view', 'id' => $item->id], true)));
         }
         $lastmod = $dom->createElement("lastmod");
         $lastmod->appendChild($dom->createTextNode($item->timestamp));
         $changefreq = $dom->createElement("changefreq");
         $changefreq->appendChild($dom->createTextNode("monthly"));
         $priority = $dom->createElement("priority");
         $priority->appendChild($dom->createTextNode("0.5"));
         $url->appendChild($loc);
         $url->appendChild($lastmod);
         $url->appendChild($changefreq);
         $url->appendChild($priority);
         $root->appendChild($url);
     }
     return $dom->saveXML();
 }
Example #2
0
 public function actionIndex()
 {
     $limit = 10;
     // Make Latest Ads
     $latestAds = Ad::find()->where(['status' => Ad::STATUS_ACTIVE])->orderBy(['id' => SORT_DESC])->limit($limit)->all();
     // Most Popular Ads
     $popularAds = Ad::find()->where(['status' => Ad::STATUS_ACTIVE])->orderBy(['view_count' => SORT_DESC])->limit($limit)->all();
     // Random Ads
     $randomAds = Ad::find()->where(['status' => Ad::STATUS_ACTIVE])->orderBy(['rand()' => SORT_DESC])->limit($limit)->all();
     return $this->render('index', ['categories' => Category::findAll(['status' => 1]), 'latestAds' => $latestAds, 'popularAds' => $popularAds, 'randomAds' => $randomAds]);
 }
 public function actionOrder($id)
 {
     $this->layout = 'page';
     $model = new Order();
     $categories = Category::findAll(['status' => Category::STATUS_ENABLED]);
     $product = Product::find()->where(['id' => $id, 'status' => Product::STATUS_ENABLED])->limit(1)->one();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $order = new Order();
         $order->key = strtoupper(Yii::$app->security->generateRandomString(6));
         $order->name = $product->name;
         $order->thumbnail = $product->thumbnail;
         $order->price = $product->price;
         $order->count = $model->count;
         $order->email = $model->email;
         $order->message = $model->message;
         $order->date = time();
         $order->insert();
         Yii::$app->session->set('orderID', $order->id);
         return $this->redirect(['product/confirm']);
     } else {
         return $this->render('order', ['model' => $model, 'categories' => $categories, 'product' => $product]);
     }
 }
Example #4
0
<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use common\widgets\Recursive;
use app\models\Category;
/* @var $this yii\web\View */
/* @var $model app\models\Skill */
/* @var $form yii\widgets\ActiveForm */
$cats = Category::findAll(['state' => 1]);
function cmp($a, $b)
{
    return strcmp($a->parents, $b->parents);
}
usort($cats, "cmp");
$data = Recursive::sortArrayDropDown($cats);
?>

<div class="row-fluid">
    <?php 
$form = ActiveForm::begin(['options' => ['class' => 'form-horizontal', 'enctype' => 'multipart/form-data']]);
?>

    <?php 
echo $form->field($model, 'title', ['template' => '{label}<div class="controls">{input}{error}{hint}</div>'])->textInput(['maxlength' => true, 'class' => 'span6', 'onblur' => 'fillAlias()']);
?>

    <?php 
echo $form->field($model, 'alias', ['template' => '{label}<div class="controls">{input}{error}{hint}</div>'])->textInput(['maxlength' => true, 'class' => 'span6']);
?>
Example #5
0
    <h1><?php 
echo Html::encode($this->title);
?>
</h1>

    <div class="operation-form">

    <?php 
$form = ActiveForm::begin(['id' => 'operation-form', 'options' => ['class' => 'form-horizontal col-lg-5'], 'fieldConfig' => ['template' => "{label}\n<div class=\"col-lg-8\">{input}</div>\n<div class=\"col-lg-1\"></div><div class=\"col-lg-12\">{error}</div>", 'labelOptions' => ['class' => 'col-lg-4 control-label']]]);
?>
	
	<?php 
$currencies = Currency::find()->all();
$currency_items = ArrayHelper::map($currencies, 'id', 'iso');
$operation_type = $t === 'income' ? 0 : 1;
$categories = Category::findAll(['type' => $operation_type]);
$category_items = ArrayHelper::map($categories, 'id', 'name');
$category_label = $t === 'income' ? 'Статья доходов' : 'Статья расходов';
?>
	
	<?php 
echo $form->field($model, 'currency_id')->dropDownList($currency_items)->label('Валюта');
?>
	<?php 
echo $form->field($model, 'summ');
?>
	<?php 
echo $form->field($model, 'category_id')->dropDownList($category_items)->label($category_label);
?>
	<?php 
echo $form->field($model, 'description');
 /**
  * Delete multiple existing Category model.
  * For ajax request will return json object
  * and for non-ajax request if deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionBulkDelete()
 {
     $request = Yii::$app->request;
     $pks = $request->post('pks');
     // Array or selected records primary keys
     foreach (Category::findAll(json_decode($pks)) as $model) {
         $model->delete();
     }
     if ($request->isAjax) {
         /*
          *   Process for ajax request
          */
         Yii::$app->response->format = Response::FORMAT_JSON;
         return ['forceClose' => true, 'forceReload' => '#crud-datatable-pjax'];
     } else {
         /*
          *   Process for non-ajax request
          */
         return $this->redirect(['index']);
     }
 }
Example #7
0
 public function actionLoadProducts()
 {
     $categories = Category::findAll(['status' => 'ACTIVE']);
     $return = [];
     foreach ($categories as $i => $category) {
         $cat = [];
         $cat['name'] = $category->name;
         foreach ($category->subcategories as $j => $subcategory) {
             $subcat = [];
             $subcat['name'] = $subcategory->name;
             foreach ($subcategory->products as $k => $product) {
                 $prod = [];
                 $prod['id'] = $product->id;
                 $prod['name'] = $product->name;
                 $prod['description'] = $product->description;
                 $prod['stock'] = $product->stock;
                 $prod['image1'] = $product->image1;
                 $prod['image2'] = $product->image2;
                 $prod['image3'] = $product->image3;
                 $prod['price'] = $product->price;
                 $subcat[$product->id] = $prod;
             }
             $cat[$subcategory->id] = $subcat;
         }
         $return[$category->id] = $cat;
     }
     return json_encode($return);
 }
Example #8
0
 /**
  * Deletes an existing Category model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     if (Yii::$app->user->can("category/delete")) {
         $child = Category::findAll(['parent' => $id]);
         $products = Product::find()->where(['category_id' => $id])->all();
         for ($i = 0; $i < sizeof($products); $i++) {
             $products[$i]->category_id = NULL;
             $products[$i]->save();
         }
         for ($i = 0; $i < sizeof($child); $i++) {
             $products_child = Product::find()->where(['category_id' => $child[$i]->id])->all();
             for ($j = 0; $i < sizeof($products_child); $j++) {
                 $products_child[$j]->category_id = NULL;
                 $products_child[$j]->save();
             }
             $child[$i]->delete();
         }
         $this->findModel($id)->delete();
         return $this->redirect(['index']);
     } else {
         Yii::$app->session->setFlash('error', 'Нет доступа!');
         $this->redirect('/');
     }
 }
Example #9
0
 /**
  * @inheritdoc
  */
 public function beforeValidate()
 {
     if (!parent::beforeValidate()) {
         return false;
     }
     if ($this->scenario == 'create' || $this->scenario == 'update') {
         $this->categoriesValid = Category::findAll($this->categories);
         $this->usersValid = User::findAll($this->users);
     }
     return true;
 }
Example #10
0
<?php

use yii\helpers\Html;
use yii\bootstrap\Nav;
use yii\bootstrap\NavBar;
use yii\widgets\Breadcrumbs;
use app\assets\AppAsset;
use app\models\Product;
use app\models\Category;
use app\models\Subcategory;
/* @var $this \yii\web\View */
/* @var $content string */
AppAsset::register($this);
$categories = Category::findAll(['status' => 'ACTIVE']);
$subs = [];
foreach ($categories as $i => $category) {
    $subs[] = $category->subcategories[0]->id;
}
$this->beginPage();
?>
<!DOCTYPE html>
<html lang="<?php 
echo Yii::$app->language;
?>
">
<head>
    <meta charset="<?php 
echo Yii::$app->charset;
?>
"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">