public function find()
 {
     $find = new CategoryModel();
     $find->id = (int) Request::get('find_value');
     $result = $find->getAll();
     $this->set("categorys", $result);
     return View('category.index');
 }
 public function index()
 {
     $category = new CategoryModel();
     $resultCategory = $category->getall();
     $this->set("categorys", $resultCategory);
     $release = new ReleasesModel();
     if (Request::check(['category_id'], "POST")) {
         $release->category_id = (int) Request::get('category_id');
     }
     $result = $release->getall();
     $this->set("releases", $result);
     return View('report.index');
 }
Beispiel #3
0
 public function actionAbout()
 {
     $categories = CategoryModel::getAllUsingColumns();
     $view = new View();
     $view->categories = $categories;
     $view->display('site/about.php');
     return true;
 }
 public function index($categorySlug)
 {
     $data['category'] = CategoryModel::where('slug', $categorySlug)->first();
     if (is_null($data['category'])) {
         abort(404);
     }
     $data['posts'] = $data['category']->post()->orderBy('created_at', 'DESC')->paginate(5);
     return $this->loadView('category', $data);
 }
Beispiel #5
0
 public function actionView($id)
 {
     $categories = CategoryModel::getAllUsingColumns();
     $blog = BlogModel::getById($id);
     $view = new View();
     $view->categories = $categories;
     $view->blog = $blog;
     $view->display('blog/view.php');
     return true;
 }
 public function actionView($id)
 {
     $categories = CategoryModel::getAllUsingColumns();
     $product = ProductModel::getById($id);
     $view = new View();
     $view->categories = $categories;
     $view->product = $product;
     $view->display('product/view.php');
     return true;
 }
Beispiel #7
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = CategoryModel::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'parentId' => $this->parentId]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
 public function edit($id)
 {
     $release = new ReleasesModel();
     $release->id = (int) $id;
     if (Request::check(['value', 'type', 'category_id', 'description'], "POST")) {
         $release = new ReleasesModel();
         $release->id = (int) $id;
         $release->update->type = Request::get('type');
         $release->update->category_id = Request::get('category_id');
         $release->update->description = Request::get('description');
         $release->update->value = Request::get('value');
         $release->update();
         $this->set("success", "Lançamento atualizado com sucesso!");
     }
     $result = $release->get();
     $category = new CategoryModel();
     $resultCategory = $category->getAll();
     $this->set("categorys", $resultCategory);
     $this->set($this->output, $result);
     $this->set("id", $id);
     return View("releases.edit");
 }
Beispiel #9
0
 /**
  * @return array \app\models\CategoryModel
  */
 public static function getCategoriesByParentId($parentId)
 {
     $categories = \Yii::$app->cache->get('categories');
     if ($categories === false) {
         $categories = CategoryModel::find()->all();
         \Yii::$app->cache->add('categories', $categories);
     }
     $result_categories = array();
     foreach ($categories as $category) {
         if ($category->parentId == $parentId) {
             $result_categories[] = $category;
         }
     }
     return $result_categories;
 }
 public function actionCreate()
 {
     $errors = [];
     $categories = CategoryModel::getAll(false, true);
     $product = new ProductModel();
     if (isset($_POST['submit'])) {
         $name = FL::clearStr($_POST['name']);
         $categoryId = FL::clearInt($_POST['category_id']);
         $code = FL::clearInt($_POST['code']);
         $price = FL::clearFloat($_POST['price']);
         $availability = FL::clearInt($_POST['availability']);
         $brand = FL::clearStr($_POST['brand']);
         $description = FL::clearStr($_POST['description']);
         $isNew = FL::clearInt($_POST['is_new']);
         $isRecommended = FL::clearInt($_POST['is_recommended']);
         $status = FL::clearInt($_POST['status']);
         if (!FL::isValue($name)) {
             $errors[] = 'Название не может быть пустым';
         }
         if (empty($errors)) {
             $product->name = $name;
             $product->categoryId = $categoryId;
             $product->code = $code;
             $product->price = $price;
             $product->availability = $availability;
             $product->brand = $brand;
             $product->description = $description;
             $product->isNew = $isNew;
             $product->isRecommended = $isRecommended;
             $product->status = $status;
             $id = $product->save();
             if (!$id) {
                 $errors[] = 'Произошла ошибка';
             } else {
                 FL::redirectTo('/admin/product');
             }
         }
     }
     $view = new View();
     $view->categories = $categories;
     $view->errors = $errors;
     $view->display('admin_product/create.php');
     return true;
 }
Beispiel #11
0
 public function actionEdit($id)
 {
     $id = (int) $id;
     $name = '';
     $password = '';
     $errors = [];
     $user = UserModel::getUser('user');
     if (!$user) {
         FL::redirectTo('/');
     }
     $categories = CategoryModel::getAllUsingColumns();
     if (isset($_POST['submit'])) {
         $name = FL::clearStr($_POST['name']);
         $password = FL::clearStr($_POST['password']);
         if (!FL::isValue($name)) {
             $errors[] = 'Имя не может быть пустым';
         }
         if (!FL::isPassword($password)) {
             $errors[] = 'Пароль должен быть больше 5 символов';
         }
         if (empty($errors)) {
             $user = UserModel::getById($id);
             $user->name = $name;
             $user->password = $password;
             Session::deleteSession('user');
             Cookie::deleteCookie('user');
             $result = $user->save(false, true);
             if ($result) {
                 FL::redirectTo('/cabinet');
             }
         }
     }
     $view = new View();
     $view->categories = $categories;
     $view->id = $id;
     $view->errors = $errors;
     $view->password = $password;
     $view->user = $user;
     $view->display('cabinet/edit.php');
     return true;
 }
Beispiel #12
0
 public function actionCategory($categoryId, $page = 1)
 {
     $limit = FL::fileGetContents('product_count_category_page.txt');
     if (!$limit) {
         $limit = 9;
     }
     $page = (int) $page;
     $categories = CategoryModel::getAllUsingColumns();
     $products = ProductModel::getByCategoryId($categoryId, $limit, $page);
     if (!$products) {
         $products = [];
     }
     $total = ProductModel::getTotal('category_id', $categoryId);
     $pagination = FL::buildPagination($total, $page, $limit, 'page-');
     $view = new View();
     $view->categories = $categories;
     $view->products = $products;
     $view->categoryId = $categoryId;
     if (isset($pagination)) {
         $view->pagination = $pagination;
     }
     $view->display('catalog/category.php');
     return true;
 }
 public function actionDelete($id)
 {
     CategoryModel::delete($id);
     FL::redirectTo('/admin/category');
     return true;
 }
Beispiel #14
0
/* @var $model app\models\CategoryModel */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="category-model-form">

    <?php 
$form = ActiveForm::begin();
?>

    <?php 
echo $form->field($model, 'name')->textInput(['maxlength' => 255]);
?>

    <?php 
$categories = ArrayHelper::map(CategoryModel::find()->all(), 'id', 'name');
$categories[] = '';
asort($categories);
?>

    <?php 
echo $form->field($model, 'parentId')->dropDownList($categories);
?>

    <div class="form-group">
        <?php 
echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
    </div>

    <?php 
Beispiel #15
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     $data['post'] = PostModel::find($id);
     $data['categories'] = CategoryModel::all();
     $data['tags'] = TagModel::all();
     $data['selectedTags'] = array();
     foreach ($data['post']->tag as $tag) {
         $data['selectedTags'][] = $tag->pivot->tag_id;
     }
     return view('admin.post.edit', $data);
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     CategoryModel::find($id)->delete();
     return redirect()->route('admin.category.index')->with('success_msg', 'Succesfully deleted category');
 }
Beispiel #17
0
 /**
  * Finds the CategoryModel model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return CategoryModel the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = CategoryModel::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Beispiel #18
0
 public function actionOrder()
 {
     $userName = '';
     $errors = [];
     $categories = CategoryModel::getAllUsingColumns();
     $productsKeysArray = Session::getSession('products');
     if ($productsKeysArray) {
         $keysArray = array_keys($productsKeysArray);
         $keysString = implode(',', $keysArray);
         if ($keysString) {
             $products = ProductModel::getAll($keysString);
             $amountPrice = CartModel::amountProductsPriceInCart($productsKeysArray, $products);
         }
     }
     $user = UserModel::getUser('user');
     if ($user) {
         $userName = $user->name;
         $userId = $user->id;
     } else {
         $userId = 0;
     }
     if (isset($_POST['submit'])) {
         $name = FL::clearStr($_POST['name']);
         $phone = FL::clearStr($_POST['phone']);
         $comment = FL::clearStr($_POST['comment']);
         if (!FL::isValue($name)) {
             $errors[] = 'Имя не может быть пустым';
         }
         if (!FL::isValue($phone)) {
             $errors[] = 'Телефон не может быть пустым';
         }
         if (!FL::isPhone($phone)) {
             $errors[] = 'Невалидный телефон';
         }
         if (!FL::isValue($comment)) {
             $errors[] = 'Комментарий не может быть пустым';
         }
         if (empty($errors)) {
             $productsKeysArray = Session::getSession('products');
             if ($productsKeysArray) {
                 $products = json_encode($productsKeysArray);
             }
             $cart = new CartModel();
             $cart->user_name = $name;
             $cart->user_phone = $phone;
             $cart->user_comment = $comment;
             $cart->user_id = $userId;
             $cart->products = $products;
             $orderId = $cart->save();
             if ($orderId) {
                 Session::deleteSession('products');
                 Session::createSession('message', 'Заказ оформлен!');
                 FL::redirectTo('/cart');
             }
         }
     } else {
         $countProducts = CartModel::countProductsInCart();
         if ($countProducts <= 0) {
             FL::redirectTo('/');
         }
     }
     $view = new View();
     $view->categories = $categories;
     $view->amountPrice = $amountPrice;
     $view->userName = $userName;
     $view->errors = $errors;
     $view->display('cart/order.php');
     return true;
 }
 public function run()
 {
     CategoryModel::truncate();
     CategoryModel::create(array('name' => 'Uncategories', 'slug' => 'uncategories', 'tag' => 'header'));
 }
Beispiel #20
0
use yii\widgets\ActiveForm;
use app\models\CategoryModel;
use yii\helpers\ArrayHelper;
/* @var $this yii\web\View */
/* @var $model app\models\CharacteristicModel */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="characteristic-model-form">

    <?php 
$form = ActiveForm::begin();
?>

    <?php 
echo $form->field($model, 'idCategory')->dropDownList(ArrayHelper::map(CategoryModel::find()->all(), 'id', 'name'));
?>

    <?php 
echo $form->field($model, 'name')->textInput(['maxlength' => 255]);
?>

    <?php 
echo $form->field($model, 'value')->textInput(['maxlength' => 50]);
?>

    <div class="form-group">
        <?php 
echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
    </div>
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getIdCategory0()
 {
     return $this->hasOne(CategoryModel::className(), ['id' => 'idCategory']);
 }
Beispiel #22
0
    <?php 
echo $form->field($model, 'idCategory')->dropDownList(ArrayHelper::map(CategoryModel::find()->all(), 'id', 'name'), ['readonly' => isset($model['idCategory'])]);
?>

    <?php 
if (isset($model['idCategory']) && isset($model['id'])) {
    if (isset($model->idCategory)) {
        $characteristics = CharacteristicModel::find()->where(['idCategory' => $model['idCategory']])->all();
        $category = CategoryModel::find()->where(['id' => $model['idCategory']])->one();
        while ($category['parentId'] != null) {
            $temp = CharacteristicModel::find()->where(['idCategory' => $category['parentId']])->all();
            foreach ($temp as $temp_char) {
                $characteristics[] = $temp_char;
            }
            $category = CategoryModel::find()->where(['id' => $category['parentId']])->one();
        }
    }
    $counter = 0;
    foreach ($characteristics as $characteristic) {
        $char_model = CharacteristicValueModel::find()->where(['idProduct' => $model['id'], 'idCharacteristic' => $characteristic->id])->one();
        if ($char_model == null) {
            $char_model = new CharacteristicValueModel();
            $char_model->idProduct = $model['id'];
            $char_model->idCharacteristic = $characteristic->id;
        }
        echo Html::activeHiddenInput($char_model, "[{$counter}]idProduct");
        echo Html::activeHiddenInput($char_model, "[{$counter}]idCharacteristic");
        echo $form->field($char_model, "[{$counter}]value", ['labelOptions' => ['label' => $characteristic->name . ' (' . $characteristic->value . ')']])->textInput();
        $counter++;
    }
Beispiel #23
0
 public function actionLogin()
 {
     $email = '';
     $password = '';
     $remember = '';
     $errors = [];
     if (isset($_POST['submit'])) {
         $email = FL::clearStr($_POST['email']);
         $password = FL::clearStr($_POST['password']);
         if (isset($_POST['remember'])) {
             $remember = $_POST['remember'];
         }
         if (!FL::isEmail($email)) {
             $errors[] = 'Некорректный email';
         }
         if (!FL::isValue($password)) {
             $errors[] = 'Пароль не может быть пустым';
         }
         if (empty($errors)) {
             $user = UserModel::checkRegister($email, $password, $remember);
             if ($user) {
                 Session::createSession('user', $user, true);
                 FL::redirectTo('/cabinet');
             } else {
                 $errors[] = 'Неправильные данные для входа на сайт';
             }
         }
     }
     $categories = CategoryModel::getAllUsingColumns();
     $view = new View();
     $view->categories = $categories;
     $view->email = $email;
     $view->password = $password;
     $view->errors = $errors;
     $view->display('user/login.php');
     return true;
 }