public function create()
 {
     $pid = intval(Input::get('id', 0));
     if ($pid != 0) {
         $category = Category::findOrFail($pid);
     } else {
         $category = false;
     }
     $roots = Category::roots()->get();
     return view('admin.pages.category.add', compact('category', 'roots', 'pid'));
 }
Example #2
0
 public function create($category = 0)
 {
     $category = intval($category);
     if ($category > 0) {
         $category = Category::findOrFail($category);
     }
     $categories = Category::roots()->get();
     $user = Auth::user();
     $states = Location::states()->first();
     $regions = $states->children()->first();
     $locations = $regions->children;
     return view('pages.task.create', compact('category', 'categories', 'user', 'locations'));
 }
Example #3
0
 public function getFilters($slug)
 {
     $currentCat = Category::findBySlug($slug);
     if (!$currentCat) {
         $currentCat = Category::findBySlug("shop");
     }
     $filters = ["id" => $currentCat->id, "category" => "Categories", "child" => $currentCat->getDescendants(1, ['id', 'category'])->toHierarchy()];
     $cats = Category::roots()->where("url_key", "!=", 'shop')->where("url_key", "!=", "popular")->get()->toHierarchy();
     foreach ($cats as $cat) {
         $cat->child = $cat->getDescendants(1, ['id', 'category'])->toHierarchy();
     }
     $cats = $cats->toArray();
     array_unshift($cats, $filters);
     return response()->json($cats);
 }
 public function getFill()
 {
     if (!$this->checkProfileType()) {
         return redirect('/profile');
     }
     if ($this->checkProfileFill()) {
         return redirect('/profile');
     }
     $user = $this->user;
     $profile = $this->user->profile;
     $city = $profile->city;
     if ($city) {
         $region = $city->parent;
     } else {
         $region = Location::states()->first()->children()->first();
     }
     $cities = $region->children;
     $categories = Category::roots()->get();
     $subscribePeriods = ['asap', 'hour', 'twice-day', 'day', 'two-days'];
     return view('pages.profile.fill', compact('user', 'profile', 'cities', 'categories', 'subscribePeriods'));
 }
 public function subCategory(Request $request, $category, $format = '')
 {
     if ($format == '' && $request->ajax()) {
         $format = 'json';
     }
     $category = intval($category);
     if ($category == 0) {
         $categories = Category::roots()->get();
     } else {
         $category = Category::findOrFail($category);
         $categories = $category->children;
     }
     $categoriesTranslated = [];
     foreach ($categories as $c) {
         $t = ['title' => trans('categories.' . $c['title'] . '.title'), 'url' => trans('categories.' . $c['title'] . '.url'), 'id' => $c->id, 'pid' => $c->pid];
         $categoriesTranslated[] = $t;
     }
     if ($format = 'json') {
         return $categoriesTranslated;
     }
 }
Example #6
0
<div class="category-index">

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

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

    <?php 
$category = new Category();
$roots = $category->roots()->all();
foreach ($roots as $key => $root) {
    $categories = Category::find()->where(['root' => $root->id])->orderBy('lft')->all();
    $level = 0;
    foreach ($categories as $n => $category) {
        if ($category->level == $level) {
            echo Html::endTag('li') . "\n";
        } elseif ($category->level > $level) {
            echo Html::beginTag('ul') . "\n";
        } else {
            echo Html::endTag('li') . "\n";
            for ($i = $level - $category->level; $i; $i--) {
                echo Html::endTag('ul') . "\n";
                echo Html::endTag('li') . "\n";
            }
        }
Example #7
0
<?php

use yii\helpers\Html;
use yii\helpers\ArrayHelper;
use yii\bootstrap\ActiveForm;
use app\models\Category;
/**
 * @var yii\web\View $this
 * @var app\models\Category $model
 * @var yii\widgets\ActiveForm $form
 */
$category = new Category();
$Categories = $category->roots()->all();
$level = 0;
$items[0] = Yii::t('app', 'Please select the parent node');
foreach ($Categories as $key => $value) {
    $items[$value->attributes['id']] = $value->attributes['name'];
    $children = $value->descendants()->all();
    foreach ($children as $child) {
        $string = '  ';
        $string .= str_repeat('│  ', $child->level - $level - 1);
        if ($child->isLeaf() && !$child->next()->one()) {
            $string .= '└';
        } else {
            $string .= '├';
        }
        $string .= '─' . $child->name;
        $items[$child->id] = $string;
    }
}
if (!$model->isNewRecord) {