protected function show($slug = false)
 {
     if (isset($sorting)) {
         Model_Category::$sorting = $sorting;
     }
     if ($category = Model_Category::get_by_slug($slug)) {
         // TODO delete this
         srand($category->id);
         $items = null;
         $parent_category = null;
         if ($category->parent_id == 0) {
             $view_file = 'category';
             // Categories
             $items = Model_Category::find(array('where' => array('parent_id' => $category->id, 'status' => 1), 'order_by' => array('sort' => 'asc')));
         } else {
             $view_file = 'subcategory';
             // Products
             $items = $category->products;
             $parent_category = Model_Category::find_one_by_id($category->parent_id);
         }
         \Helper::sorting($items);
         // Reset to empty array if there are no result found by query
         if (is_null($items)) {
             $items = array();
         }
         // Initiate pagination
         $pagination = \Hybrid\Pagination::make(array('total_items' => count($items), 'per_page' => \Input::get('per_page', 15), 'uri_segment' => null));
         // Remove unwanted items, and show only required ones
         $items = array_slice($items, $pagination->offset, $pagination->per_page);
         \Theme::instance()->set_partial('content', $this->view_dir . $view_file)->set('category', $category, false)->set('parent_category', $parent_category, false)->set('items', $items, false)->set('pagination', $pagination, false);
     } else {
         throw new \HttpNotFoundException();
     }
 }
Example #2
0
 public function action_index($orderField = null)
 {
     if (is_null($orderField)) {
         $orderField = 'name';
     }
     $categories_db = Model_Category::find('all', ['order_by' => ['name']]);
     $categories[0] = "-- ALL --";
     foreach ($categories_db as $category) {
         $categories[$category->id] = $category->name;
     }
     $category_id = Input::get('category_id');
     if (!is_null($category_id)) {
         Session::set('displayCategory', $category_id);
         if (strcmp($category_id, "0") == 0) {
             $qualifiers = ['order_by' => [$orderField]];
         } else {
             $qualifiers = ['order_by' => [$orderField], 'where' => array(['category_id', Session::get('displayCategory')])];
         }
     } else {
         $category_id = Session::get('displayCategory');
         if (!isset($category_id)) {
             $qualifiers = ['order_by' => [$orderField]];
         } elseif (strcmp($category_id, "0") == 0) {
             $qualifiers = ['order_by' => [$orderField]];
         } else {
             $qualifiers = ['order_by' => [$orderField], 'where' => array(['category_id', Session::get('displayCategory')])];
         }
     }
     $products = Model_Product::find('all', $qualifiers);
     $data = ['products' => $products, 'categories' => $categories, 'category_id' => $category_id];
     return Response::forge(View::forge('home/index.tpl', $data));
 }
Example #3
0
 /**
  * set common data to template
  * 
  * @author Luvina
  * @access public
  * 
  * @return void
  */
 public function before()
 {
     parent::before();
     $aryMenuList = Model_Category::find('all');
     $this->template->menu = $aryMenuList;
     $this->template->base_url = Config::get('base_url');
 }
Example #4
0
 protected function show($slug = false)
 {
     if (isset($sorting)) {
         Model_Category::$sorting = $sorting;
     }
     if ($category = Model_Category::get_by_slug($slug)) {
         // TODO delete this
         srand($category->id);
         $items = null;
         $parent_category = null;
         if ($category->parent_id == 0) {
             $view_file = 'category';
             // Categories
             $items = Model_Category::find(array('where' => array('parent_id' => $category->id, 'status' => 1), 'order_by' => array('sort' => 'asc')));
             if (!$items) {
                 $view_file = 'subcategory';
                 $items = $category->products;
             }
         } else {
             $view_file = 'subcategory';
             // Products
             $items = $category->products;
             // echo '<pre>';
             // print_r($items);
             // echo '</pre>';
             $parent_category = Model_Category::find_one_by_id($category->parent_id);
         }
         \Helper::sorting($items);
         // Reset to empty array if there are no result found by query
         if (is_null($items)) {
             $items = array();
         }
         // Initiate pagination
         $pagination = \Hybrid\Pagination::make(array('total_items' => count($items), 'per_page' => \Input::get('per_page', 15), 'uri_segment' => null));
         // Remove unwanted items, and show only required ones
         $items = array_slice($items, $pagination->offset, $pagination->per_page);
         $category_parents = false;
         if ($parent_category) {
             $parents = array();
             if ($category_parents_id = Model_Category::find_parents($category->parent_id, $parents, true)) {
                 $category_parents = Model_Category::find(array('where' => array(array('id', 'in', $category_parents_id))));
             }
         }
         $stock_options = \Config::load('stock-option.db');
         \Theme::instance()->set_partial('content', $this->view_dir . $view_file)->set('category', $category, false)->set('parent_category', $parent_category, false)->set('items', $items, false)->set('category_parents', $category_parents, false)->set('pagination', $pagination, false)->set('manage_stock', $stock_options['manage_stock'], false)->set('hide_out_of_stock', $stock_options['hide_out_of_stock'], false);
         \View::set_global('title', $category->seo->meta_title ?: $category->title);
         \View::set_global('meta_description', $category->seo->meta_description ?: '');
         \View::set_global('meta_keywords', $category->seo->meta_keywords ?: '');
         $robots = array('meta_robots_index' => $category->seo->meta_robots_index == 1 ? 'index' : 'noindex', 'meta_robots_follow' => $category->seo->meta_robots_follow == 1 ? 'follow' : 'nofollow');
         \View::set_global('robots', $robots);
         \View::set_global('canonical', $category->seo->canonical_links);
         \View::set_global('h1_tag', $category->seo->h1_tag);
         if ($category->seo->redirect_301) {
             \Response::redirect($category->seo->redirect_301);
         }
     } else {
         throw new \HttpNotFoundException();
     }
 }
Example #5
0
 public static function get_id_by_parent_id($parent_category_id)
 {
     $data = array();
     $categories = Model_Category::find('all', array('where' => array(array('parent_category_id', '=', $parent_category_id))));
     foreach ($categories as $category) {
         $data[] = $category->id;
     }
     return $data;
 }
Example #6
0
 public function action_delete($id = null)
 {
     if ($category = Model_Category::find($id)) {
         $category->delete();
         Session::set_flash('success', e('Deleted category #' . $id));
     } else {
         Session::set_flash('error', e('Could not delete category #' . $id));
     }
     Response::redirect('admin/category');
 }
Example #7
0
 public function newAction()
 {
     $param['category'] = $this->_getParam('category');
     $app = Model_Category::find($param['category']);
     if ($app) {
         throw new Exception("Category '" . $param['category'] . "' already exist.");
     }
     $c = new Model_Category();
     $c->newCategory($param);
     echo json_encode(array('success' => true));
 }
Example #8
0
 public function action_delete($id = null)
 {
     $category = Model_Category::find($id);
     if ($category->delete()) {
         // Delete cache
         \Cache::delete('sidebar');
         \Messages::success(__('backend.category.deleted'));
     } else {
         \Messages::error(__('error'));
     }
     \Response::redirect_back(\Router::get('admin_category'));
 }
Example #9
0
 public static function set_form_fields($form, $instance = null)
 {
     // Call parent for create the fieldset and set default value
     parent::set_form_fields($form, $instance);
     // Add null value for parent categories.
     $form->field('parent_id')->set_options('null', 'None');
     $categories = Model_Category::find('all', array('where' => array(array('parent_id', null))));
     // Set categories
     foreach ($categories as $category) {
         $form->field('parent_id')->set_options($category->id, $category->name);
     }
 }
Example #10
0
 /**
  * Действие для удаления категории
  * 
  * @param integer $id
  */
 public function action_delete($id = null)
 {
     is_null($id) and Response::redirect('admin/categories');
     $category = \Model_Category::find($id, array('related' => 'articles'));
     if (!empty($category) and empty($category->articles)) {
         $category->delete();
         \Session::set_flash('success', 'Категория успешно удалена');
     } else {
         \Session::set_flash('error', 'Невозможно удалить категорию. Скорее всего существуют статьи, принадлежащие к ней.');
     }
     \Response::redirect('admin/categories');
 }
Example #11
0
 public static function set_form_fields($form, $instance = null)
 {
     // Call parent for create the fieldset and set default value
     parent::set_form_fields($form, $instance);
     // Set authors
     foreach (\Model_User::find('all') as $user) {
         $form->field('user_id')->set_options($user->id, $user->username);
     }
     // Set categories
     foreach (Model_Category::find('all') as $category) {
         $form->field('category_id')->set_options($category->id, $category->name);
     }
 }
Example #12
0
 public function action_add($id = null)
 {
     $this->data['isUpdate'] = $isUpdate = $id !== null ? true : false;
     // Prepare form fieldset
     $form = \Fieldset::forge('post_form', array('form_attributes' => array('class' => 'form-horizontal')));
     $form->add_model('Model_Post');
     $form->add('add', '', array('type' => 'submit', 'value' => $isUpdate ? __('backend.edit') : __('backend.add'), 'class' => 'btn btn-primary'));
     // Get or create the post
     if ($isUpdate) {
         $this->data['post'] = $post = \Model_Post::find($id);
         $this->dataGlobal['pageTitle'] = __('backend.post.edit');
     } else {
         $this->data['post'] = $post = \Model_Post::forge();
         $this->dataGlobal['pageTitle'] = __('backend.post.add');
     }
     $form->populate($post);
     // If POST submit
     if (\Input::post('add')) {
         $form->validation()->run();
         if (!$form->validation()->error()) {
             // Populate the post
             $post->from_array(array('name' => $form->validated('name'), 'slug' => $form->validated('slug') != '' ? \Inflector::friendly_title($form->validated('slug')) : \Inflector::friendly_title($form->validated('name')), 'category_id' => $form->validated('category_id'), 'user_id' => $form->validated('user_id'), 'content' => $form->validated('content')));
             if ($post->save()) {
                 // Delete cache
                 \Cache::delete('sidebar');
                 // Category Post count update
                 foreach (\Model_Category::find('all') as $category) {
                     $category->post_count = count($category->posts);
                     $category->save();
                 }
                 if ($isUpdate) {
                     \Messages::success(__('backend.post.edited'));
                 } else {
                     \Messages::success(__('backend.post.added'));
                 }
                 \Response::redirect_back(\Router::get('admin_post'));
             } else {
                 \Messages::error(__('error'));
             }
         } else {
             // Output validation errors
             foreach ($form->validation()->error() as $error) {
                 \Messages::error($error);
             }
         }
     }
     $form->repopulate();
     $this->data['form'] = $form;
     $this->theme->set_partial('content', 'backend/post/add')->set($this->data, null, false);
 }
Example #13
0
 /**
  * Get the sidebar view (HMVC Only)
  */
 public function get_sidebar()
 {
     if (\Request::is_hmvc()) {
         // Get sidebar in cache
         try {
             $sidebar = \Cache::get('sidebar');
         } catch (\CacheNotFoundException $e) {
             // If Cache doesn't exist, get data and cache the view
             $this->data['categories'] = \Model_Category::find('all');
             $this->data['lastPosts'] = \Model_Post::query()->order_by('created_at', 'DESC')->limit(5)->get();
             $sidebar = $this->theme->view('frontend/post/sidebar', $this->data);
             \Cache::set('sidebar', $sidebar);
         }
         return $sidebar;
     }
 }
 /**
  * Index page
  * 
  * @access  public
  * @param   $slug
  */
 public function action_index($slug = false, $my_products = null)
 {
     $category_parents = false;
     if ($my_products == 1) {
         Model_Product::$filter_by_pricing_group = 'assigned';
     } else {
         Model_Product::$filter_by_pricing_group = 'not_assigned';
     }
     if ($product = Model_Product::get_by_slug($slug)) {
         // Find main category
         if (!empty($product->categories)) {
             $parents = array();
             if ($category_parents_id = Model_Category::find_parents(key($product->categories), $parents, true)) {
                 $category_parents = Model_Category::find(array('where' => array(array('id', 'in', $category_parents_id))));
             }
         }
         \Theme::instance()->set_partial('content', $this->view_dir . 'product')->set('product', $product, false)->set('category_parents', $category_parents, false)->set('product_data', $product->data, false);
     } else {
         throw new \HttpNotFoundException();
     }
 }
Example #15
0
 public function post_create()
 {
     $val = Validation::forge();
     $val->add_callable('MyRules');
     $val->add_field('category_name', Lang::get('label.category_name'), 'required|max_length[255]');
     $val->add_field('id', Lang::get('label.category'), 'trim|valid_numeric|valid_category');
     $val->add_field('parent_category_id', Lang::get('label.parent_category'), 'trim|valid_numeric|valid_category');
     if ($val->run()) {
         DB::start_transaction();
         $category_id = $val->validated('id');
         $parent_category_id = (int) $val->validated('parent_category_id');
         $category_props = array('category_name' => Model_Service_Util::mb_trim($val->validated('category_name')), 'parent_category_id' => $parent_category_id, 'level' => !empty($parent_category_id) ? Model_Category::find($parent_category_id)->level + 1 : 1);
         $create_id = !empty($category_id) ? Model_Base_Category::update($category_id, $category_props) : Model_Base_Category::insert($category_props);
         if ($create_id) {
             $type = !empty($category_id) ? 'update' : 'new';
             $category_id = !empty($category_id) ? $category_id : $create_id;
             $photo_props = array('type' => $type, 'category_id' => $category_id);
             if ($type === 'new' || Input::file('category_photo')) {
                 $upload = Model_Service_Upload::run('category', $photo_props);
             }
             if (empty($upload['error'])) {
                 DB::commit_transaction();
                 $this->data['category'] = array('type' => $type, 'id' => $category_id, 'parent_category_id' => $parent_category_id, 'category_name' => $val->validated('category_name'), 'category_name_display' => Model_Base_Category::get_parent($category_id), 'category_photo_display' => empty($upload['photo_name']) ?: $upload['photo_name'], 'no_image' => _PATH_NO_IMAGE_);
                 $this->data['success'] = true;
                 $this->data['msg'] = Lang::get($this->controller . '.' . $this->action . '.success');
             } else {
                 DB::rollback_transaction();
                 $this->data['msg'] = $upload['error'];
             }
         } else {
             DB::rollback_transaction();
             $this->data['msg'] = Lang::get($this->controller . '.' . $this->action . '.error');
         }
     } else {
         $this->data['errors'] = $val->error_message();
     }
     return $this->response($this->data);
 }
Example #16
0
 /**
  * Index page
  * 
  * @access  public
  * @param   $slug
  */
 public function action_index($slug = false, $my_products = null)
 {
     $category_parents = false;
     if ($my_products == 1) {
         Model_Product::$filter_by_pricing_group = 'assigned';
     } else {
         Model_Product::$filter_by_pricing_group = 'not_assigned';
     }
     if ($product = Model_Product::get_by_slug($slug)) {
         // Find main category
         if (!empty($product->categories)) {
             $parents = array();
             if ($category_parents_id = Model_Category::find_parents(key($product->categories), $parents, true)) {
                 $category_parents = Model_Category::find(array('where' => array(array('id', 'in', $category_parents_id))));
             }
         }
         $stock_options = \Config::load('stock-option.db');
         if ($product->attributes[0]->stock_quantity > 0 || $stock_options['manage_stock'] && $product->attributes[0]->stock_quantity < 1 && $stock_options['hide_out_of_stock'] == 0) {
             \Theme::instance()->set_partial('content', $this->view_dir . 'product')->set('product', $product, false)->set('category_parents', $category_parents, false)->set('product_data', $product->data, false)->set('allow_buy_out_of_stock', $stock_options['allow_buy_out_of_stock']);
         } else {
             \Messages::error('Item is not available.');
             \Response::redirect('page/products');
         }
         \View::set_global('title', $product->seo->meta_title ?: $product->title);
         \View::set_global('meta_description', $product->seo->meta_description ?: '');
         \View::set_global('meta_keywords', $product->seo->meta_keywords ?: '');
         $robots = array('meta_robots_index' => $product->seo->meta_robots_index == 1 ? 'index' : 'noindex', 'meta_robots_follow' => $product->seo->meta_robots_follow == 1 ? 'follow' : 'nofollow');
         \View::set_global('robots', $robots);
         \View::set_global('canonical', $product->seo->canonical_links);
         \View::set_global('h1_tag', $product->seo->h1_tag);
         if ($product->seo->redirect_301) {
             \Response::redirect($product->seo->redirect_301);
         }
     } else {
         throw new \HttpNotFoundException();
     }
 }
Example #17
0
 public function action_edit($id = null)
 {
     $model = $this->find($id);
     $form = $this->form();
     if (\Input::method() == 'POST') {
         $post = \Input::post();
         $validator = $this->validation();
         $result = $validator->run($post);
         if ($result->isValid()) {
             $data = \Arr::filter_keys($post, $result->getValidated());
             $categories = $data['category_id'];
             unset($data['category_id']);
             $model->categories = [];
             foreach ($categories as $category) {
                 $model->categories[] = Model_Category::find($category);
             }
             $model->set($data)->save();
             $context = array('template' => 'success', 'from' => '%item%', 'to' => $this->get_name());
             \Logger::instance('alert')->info(gettext('%item% successfully created.'), $context);
             return $this->redirect($this->url);
         } else {
             $form->repopulate();
             $context = array('errors' => $result->getErrors());
             \Logger::instance('alert')->error(gettext('There were some errors.'), $context);
         }
     } else {
         $data = $model->to_array();
         $data['category_id'] = array_keys($model->categories);
         $form->populate($data);
     }
     $this->set_title(strtr(gettext('Edit %item%'), ['%item%' => $this->get_name()]));
     $this->template->content = $this->view('admin/skeleton/edit');
     $this->template->content->set('model', $model, false);
     $this->template->content->set('form', $form, false);
     isset($errors) and $this->template->content->set('errors', $errors, false);
 }
Example #18
0
 public function action_modifyProduct()
 {
     $product_id = Input::post('product_id');
     $name = Input::post('name');
     $price = Input::post('price');
     $category = Input::post('category');
     $product = Model_Product::find($product_id);
     $description = Input::post('description');
     $image = Input::post('image');
     $doit = Input::post('doit');
     $validator = $this->addModifyValidator();
     $message = '';
     $category_id = $product->category_id;
     //$category = Model_Category::find($product->category_id);
     if (!is_null($doit)) {
         try {
             if (!$validator->run(Input::post())) {
                 throw new Exception();
             }
             //    $product = Model_Product::forge();
             $product->name = $name;
             $valid = (object) $validator->validated();
             $product->category_id = $category_id;
             $product->price = $valid->price;
             $product->description = $description;
             $product->image = $image;
             $product->save();
             return Response::redirect("/home/productInfo/{$product->id}");
         } catch (Exception $ex) {
             $message = $ex->getLine();
         }
     } else {
         $category = Model_Category::find($product->category_id);
         $category = $category->name;
         $name = $product->name;
     }
     $data = array('product' => $product, 'name' => $name, 'message' => $message, 'product_id' => $product_id, 'category' => $category, 'price' => $price, 'description' => $description, 'image' => $image);
     $view = View::forge("admin/modifyProduct.tpl", $data);
     $view->set('validator', $validator, false);
     return Response::forge($view);
 }
Example #19
0
 public function action_index()
 {
     //ビューに渡すデータの配列を初期化
     $data = array();
     //県のセレクト用のオプション配列の作成
     $prefectures = Model_Prefecture::find('all');
     $pref_op = array();
     foreach ($prefectures as $pref) {
         $pref_op[$pref->pref_num] = $pref->pref_name;
     }
     $data['prefs'] = $pref_op;
     //カテゴリのチェックボックス用のオプション配列の作成
     $categories = Model_Category::find('all');
     $catego_op = array();
     foreach ($categories as $catego) {
         $catego_op[$catego->cate_num] = $catego->cate_name;
     }
     $data['categories'] = $catego_op;
     //タグのセレクト用のオプション配列の作成
     $tags = Model_Tag::find('all');
     $tag_op = array();
     foreach ($tags as $tag) {
         $tag_op[$tag->tag_num] = $tag->tag_name;
     }
     $data['tags'] = $tag_op;
     if (Input::method() == 'POST') {
         /*-------
           ユーザが入力した値とその時の時刻を保持
           --------*/
         $data['input_pref'] = Input::post('pref');
         $data['input_place'] = Input::post('place');
         $data['input_title'] = Input::post('title');
         $data['input_content'] = Input::post('content');
         $data['input_category'] = Input::post('category');
         $data['input_tag1'] = Input::post('tag1');
         $data['input_tag2'] = Input::post('tag2');
         $data['input_rating'] = Input::post('rating');
         $time = Date::forge()->get_timestamp();
     }
     /*--------
        Validationの準備
       ---------*/
     //Validationオブジェクトを呼び出す
     $val = Validation::forge();
     //フォームのルール設定
     $val->add('pref', '県名')->add_rule('required');
     $val->add('place', '場所')->add_rule('required');
     $val->add('title', 'タイトル')->add_rule('required');
     //->add_rule('max_length', 30)
     $val->add('content', '記事内容')->add_rule('required');
     //->add_rule('max_length', 200)
     $val->add('category', 'カテゴリ')->add_rule('required');
     $val->add('tag1', 'タグ1')->add_rule('required');
     $val->add('tag2', 'タグ2')->add_rule('required');
     $val->add('rating', '評価')->add_rule('required');
     /*-----------
       画像ファイルの入力があったらアップロード
       ---------------*/
     //データ保存用変数 初期化
     $upload_file = '';
     if (Input::file('upload.name')) {
         //アップロード用初期設定
         $config = array('path' => DOCROOT . DS . '/assets/img/uimg', 'ext_whitelist' => array('img', 'jpg', 'jpeg', 'gif', 'png'));
         //アップロード基本プロセス
         Upload::process($config);
         //検証
         if (Upload::is_valid()) {
             //設定を元に保存
             Upload::save();
             //保存されたファイル名を変数に入れる
             $getfile = Upload::get_files();
             $upload_file = $getfile[0]['name'];
         } else {
             //ファイルがアップロードできなかったとき、
             //メッセージをフラッシュセッションにセット
             Session::set_flash('uerr', 'ファイルが正しくアップできませんでした。');
             //投稿を中断して入力画面にもどる。
             return View::forge('members/post2', $data, false);
             //Response::redirect(View::forge('members/post2', $data, false));
         }
     }
     //Validationチェック
     if ($val->run()) {
         //ファイルがアップロードされてなかったらダメ
         if ($upload_file == '') {
             $data['error'] = 'ファイルを選択してください。';
             return View::forge('members/post2', $data);
         }
         /*------
           postされた各データをDBに保存
           ----------*/
         //各送信データを配列
         $props = array('uid' => 1, 'pref_num' => $data['input_pref'], 'place' => $data['input_place'], 'title' => $data['input_title'], 'contents' => $data['input_content'], 'category' => $data['input_category'], 'tag1' => $data['input_tag1'], 'tag2' => $data['input_tag2'], 'rating' => $data['input_rating'], 'image' => $upload_file, 'datetime' => $time);
         //モデルオブジェクト作成
         $new = Model_Post::forge();
         $new->set($props);
         //データを保存する
         if (!$new->save()) {
             //保存失敗
             $data['save'] = '正しく投稿できませんでした。';
         } else {
             //保存成功
             /* 本当はユーザの投稿りすとページに飛びたい */
             Response::redirect('members/top');
         }
     }
     //$val->run()ここまで
     //validationオブジェクトをviewに渡す
     $data['val'] = $val;
     return View::forge('members/post2', $data, false);
 }
Example #20
0
 public static function my_categories()
 {
     $products = static::filter_by_group();
     $categories = array();
     if (!empty($products['assigned'])) {
         $categories = Model_Product_To_Categories::find(array('where' => array(array('product_id', 'in', array_keys($products['assigned'])))), 'category_id');
         if ($categories) {
             $categories = Model_Category::find(array('where' => array(array('id', 'in', array_keys($categories)))), 'id');
         }
     }
     return $categories;
 }
Example #21
0
 public static function run($type = null, $options = array())
 {
     $data = array();
     $photo_name = array();
     try {
         Upload::process();
     } catch (Exception $e) {
         $data['error'] = Lang::get('notice.upload.no_file');
         return $data;
     }
     if (Upload::is_valid()) {
         Upload::save();
     }
     foreach (Upload::get_errors() as $file) {
         $data['error'] = $file['errors']['0']['message'];
         return $data;
     }
     foreach (Upload::get_files() as $file) {
         $resize = self::resize_photo($file['saved_to'], $file['saved_as'], $type);
         $photo_name[] = $file['saved_as'];
     }
     if ($resize) {
         switch ($type) {
             case 'icon':
                 if (Model_Base_User::update($options['user_id'], array('user_photo' => $photo_name[0]))) {
                     $old_photo = $file['saved_to'] . $type . '/' . $options['user_photo'];
                     if (File::exists($old_photo)) {
                         File::delete($old_photo);
                     }
                     $data['photo_name'] = _PATH_ICON_ . $photo_name[0];
                 } else {
                     $data['error'] = Lang::get('notice.upload.save_icon_error');
                 }
                 break;
             case 'category':
                 $old_photo = $options['type'] === 'new' ?: $file['saved_to'] . $type . '/' . Model_Category::find($options['category_id'])->category_photo;
                 if (Model_Base_Category::update($options['category_id'], array('category_photo' => $photo_name[0]))) {
                     if (File::exists($old_photo)) {
                         File::delete($old_photo);
                     }
                     $data['photo_name'] = _PATH_CATEGORY_ . $photo_name[0];
                 } else {
                     $data['error'] = Lang::get('notice.upload.save_category_error');
                 }
                 break;
             case 'product':
                 $old_photo = $file['saved_to'] . $type . '/' . Model_Product::find($options['product_id'])->product_photo;
                 if (Model_Base_Product::update($options['product_id'], array('product_photo' => $photo_name[0]))) {
                     if (File::exists($old_photo)) {
                         File::delete($old_photo);
                     }
                     $data['photo_name'] = _PATH_PRODUCT_ . $photo_name[0];
                 } else {
                     $data['error'] = Lang::get('notice.upload.save_product_error');
                 }
                 break;
             case 'photo':
                 if ($options['type'] === 'sub_product_photo') {
                     $photo_props = array('product_id' => $options['product_id'], 'photo_name' => $photo_name[0]);
                     if ($photo_id = Model_Base_Photo::insert($photo_props)) {
                         $data['photo_id'] = $photo_id;
                         $data['photo_name'] = _PATH_PHOTO_ . $photo_name[0];
                     } else {
                         $data['error'] = Lang::get('notice.upload.save_photo_error');
                     }
                 }
                 break;
             default:
                 $data['error'] = Lang::get('system_error');
                 break;
         }
     } else {
         $data['error'] = Lang::get('system_error');
     }
     return $data;
 }
Example #22
0
 public function post_edit($id = null)
 {
     $post = Model_Post::find($id);
     $val = Model_Post::validate('edit');
     if ($val->run()) {
         $post->slug = Input::post('slug');
         $post->title = Input::post('title');
         $post->body = Input::post('body');
         $post->user_id = Input::post('user_id');
         $post->active = Input::post('active');
         $categories = array();
         $categories = Input::post('category_id');
         //exit(var_dump(Input::post('category_id')));
         unset($post->categories);
         foreach ($categories as $category_id) {
             $post->categories[] = Model_Category::find($category_id);
         }
         if ($post->save()) {
             Session::set_flash('success', e('Updated post #' . $id));
             Response::redirect('admin/posts');
         } else {
             Session::set_flash('error', e('Could not update post #' . $id));
         }
     } else {
         if (Input::method() == 'POST') {
             $post->slug = $val->validated('slug');
             $post->title = $val->validated('title');
             $post->body = $val->validated('body');
             $post->user_id = $val->validated('user_id');
             $post->active = $val->validated('active');
             Session::set_flash('error', $val->error());
         }
         $this->template->set_global('post', $post, false);
     }
     $this->template->title = "Posts";
     $this->template->content = View::forge('admin/posts/edit');
 }
Example #23
0
 public function get_navSectionCategories()
 {
     return $this->response = Model_Category::find('all', array('where' => array(array('parent_id', null))));
 }
Example #24
0
 public function action_delete($id = null, $save = null)
 {
     if ($save) {
         if ($category = Model_Category::find($id)) {
             $category->delete();
             $data['status'] = "success";
             $data['msg'] = "successfully Deleted category";
         } else {
             $data['status'] = "fales";
             $data['msg'] = "Category not found";
         }
         $data1['response'] = json_encode($data);
         $view = View::forge('admin/response', $data1, false);
     } else {
         $view = View::forge('admin/modal/delete', array('control' => 'category', 'ajaxload' => 'loadCategoryGrid', 'url' => Uri::create("admin/category/delete/" . $id . '/save')), false);
     }
     $this->template = $view;
 }
Example #25
0
 public function view()
 {
     $this->categories = Model_Category::find('all');
 }
Example #26
0
 public function action_make_active($id = null)
 {
     if ($article = Model_Category::find($id)) {
         $article->deleted = 0;
         $article->save();
         $data['status'] = "success";
         $data['msg'] = "successfully Active Article";
     } else {
         $data['status'] = "fales";
         $data['msg'] = "Articles not found";
     }
     $data1['response'] = json_encode($data);
     $view = View::forge('admin/response', $data1, false);
     $this->template = $view;
 }
Example #27
0
 public function get_search_items($category_id = 0)
 {
     // Override category_id if its a search
     $category_id = \Input::get('category_id', $category_id);
     // Reset $parent_id if its invalid value
     is_numeric($category_id) or $category_id = 0;
     if ($category_id) {
         $category = \Product\Model_Category::find_one_by_id($category_id);
         if ($category) {
             \View::set_global('category', $category);
         }
     }
     /************ Start generating query ***********/
     $items = Model_Category::find(function ($query) use($category_id) {
         // Select only root pages
         $query->where('parent_id', $category_id);
         // Get search filters
         foreach (\Input::get() as $key => $value) {
             if (!empty($value) || $value == '0') {
                 switch ($key) {
                     case 'title':
                         $query->where($key, 'like', "%{$value}%");
                         break;
                     case 'status':
                         if (is_numeric($value)) {
                             $query->where($key, $value);
                         }
                         break;
                     case 'active_from':
                         $date = strtotime($value);
                         if ($date) {
                             $query->where($key, '>=', $date);
                         }
                         break;
                     case 'active_to':
                         $date = strtotime($value);
                         if ($date) {
                             $query->where($key, '<=', $date);
                         }
                         break;
                 }
             }
         }
         // Order query
         $query->order_by('sort', 'asc');
         $query->order_by('id', 'asc');
     });
     /************ End generating query ***********/
     // Reset to empty array if there are no result found by query
     if (is_null($items)) {
         $items = array();
     }
     // Initiate pagination
     $pagination = \Hybrid\Pagination::make(array('total_items' => count($items), 'per_page' => \Input::get('per_page', 10), 'uri_segment' => null));
     // Remove unwanted items, and show only required ones
     $items = array_slice($items, $pagination->offset, $pagination->per_page);
     $status = array('false' => 'Select', '1' => 'Active', '0' => 'Inactive', '2' => 'Active in period');
     return array('items' => $items, 'pagination' => $pagination, 'status' => $status);
 }