Example #1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Category();
     $catlist = Category::getDropList(0);
     $model->orderid = 1;
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Category'])) {
         $model->attributes = $_POST['Category'];
         $model->create_uid = Yii::app()->user->id;
         $model->create_time = date('Y-m-d H:i:s');
         $model->orderid = 1;
         if ($model->save()) {
             $id = $model->attributes['id'];
             if ($model->pid == 0) {
                 $model->path = $id;
                 $model->level = 1;
                 $model->save();
             } else {
                 $parent = Category::getParent($model->pid);
                 $model->path = $parent->path . '/' . $id;
                 $model->level = $parent->level + 1;
                 $model->save();
             }
             //$this->redirect(array('view','id'=>$model->id));
             Yii::app()->user->setFlash('success', '信息提交成功!');
         } else {
             Yii::app()->user->setFlash('success', '信息提交失败!');
         }
     }
     $this->render('create', array('model' => $model, 'catlist' => $catlist));
 }
 public function testSaveCustomFile()
 {
     // create custom file first
     $this->request->set('file', 'theme/sometheme/test.tpl');
     $this->request->set('code', 'test code');
     $response = $this->controller->save();
     // edit the file
     $this->request->set('file', 'theme/sometheme/test.tpl');
     $this->request->set('code', 'test code');
     $response = $this->controller->save();
     $template = new Template('test.tpl', 'sometheme');
     $this->assertEquals($template->getCode(), 'test code');
     $this->assertEquals($template->getFileName(), 'theme/sometheme/test.tpl');
     $template->restoreOriginal();
 }
 public function updateCategory()
 {
     if (!Request::ajax()) {
         return App::abort(404);
     }
     if (Input::has('pk')) {
         return self::updateQuickEdit();
     }
     $arrReturn = ['status' => 'error'];
     $category = new Category();
     $category->name = Input::get('name');
     $category->short_name = Str::slug($category->name);
     $category->description = Input::get('description');
     $category->parent_id = (int) Input::get('parent_id');
     $category->order_no = (int) Input::get('order_no');
     $category->active = Input::has('active') ? 1 : 0;
     $pass = $category->valid();
     if ($pass) {
         $category->save();
         $arrReturn = ['status' => 'ok'];
         $arrReturn['message'] = $category->name . ' has been saved';
         $arrReturn['data'] = $category;
     } else {
         $arrReturn['message'] = '';
         $arrErr = $pass->messages()->all();
         foreach ($arrErr as $value) {
             $arrReturn['message'] .= "{$value}\n";
         }
     }
     return $arrReturn;
 }
 /**
  * Создает новую модель категории.
  * Если создание прошло успешно - перенаправляет на просмотр.
  *
  * @return void
  */
 public function actionCreate()
 {
     $model = new Category();
     if (($data = Yii::app()->getRequest()->getPost('Category')) !== null) {
         $model->setAttributes($data);
         if ($model->save()) {
             Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('CategoryModule.category', 'Record was created!'));
             $this->redirect((array) Yii::app()->getRequest()->getPost('submit-type', ['create']));
         }
     }
     $languages = $this->yupe->getLanguagesList();
     //если добавляем перевод
     $id = (int) Yii::app()->getRequest()->getQuery('id');
     $lang = Yii::app()->getRequest()->getQuery('lang');
     if (!empty($id) && !empty($lang)) {
         $category = Category::model()->findByPk($id);
         if (null === $category) {
             Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::ERROR_MESSAGE, Yii::t('CategoryModule.category', 'Targeting category was not found!'));
             $this->redirect(['create']);
         }
         if (!array_key_exists($lang, $languages)) {
             Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::ERROR_MESSAGE, Yii::t('CategoryModule.category', 'Language was not found!'));
             $this->redirect(['create']);
         }
         Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('CategoryModule.category', 'You are adding translate in to {lang}!', ['{lang}' => $languages[$lang]]));
         $model->lang = $lang;
         $model->slug = $category->slug;
         $model->parent_id = $category->parent_id;
         $model->name = $category->name;
     } else {
         $model->lang = Yii::app()->language;
     }
     $this->render('create', ['model' => $model, 'languages' => $languages]);
 }
Example #5
0
 public function postCategory()
 {
     $category = new Category();
     $category->name = Input::get('name');
     $category->save();
     return Response::json($category);
 }
Example #6
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $categorize = new Category();
     $categorize->type = Input::get('type');
     $categorize->save();
     return Redirect::to('category');
 }
Example #7
0
 /**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param PropelPDO $con
  * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws PropelException
  * @see        save()
  */
 protected function doSave(PropelPDO $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their corresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aCategory !== null) {
             if ($this->aCategory->isModified() || $this->aCategory->isNew()) {
                 $affectedRows += $this->aCategory->save($con);
             }
             $this->setCategory($this->aCategory);
         }
         if ($this->isNew() || $this->isModified()) {
             // persist changes
             if ($this->isNew()) {
                 $this->doInsert($con);
             } else {
                 $this->doUpdate($con);
             }
             $affectedRows += 1;
             $this->resetModified();
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
Example #8
0
 /**
  * Создание категории
  */
 public function create()
 {
     if (!User::isAdmin()) {
         App::abort('403');
     }
     $category = new Category();
     if (Request::isMethod('post')) {
         $category->token = Request::input('token', true);
         $category->parent_id = Request::input('parent_id');
         $category->name = Request::input('name');
         $category->slug = Request::input('slug');
         $category->description = Request::input('description');
         $category->sort = Request::input('sort');
         if ($category->save()) {
             App::setFlash('success', 'Категория успешно создана!');
             App::redirect('/category');
         } else {
             App::setFlash('danger', $category->getErrors());
             App::setInput($_POST);
         }
     }
     $maxSort = Category::find(['select' => 'max(sort) max']);
     $maxSort = $maxSort->max + 1;
     $categories = Category::getAll();
     App::view('categories.create', compact('category', 'categories', 'maxSort'));
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Category();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Category'])) {
         $model->attributes = $_POST['Category'];
         // if (isset($_POST['Category']['id_parent_category']) && $_POST['Category']['id_parent_category'] == '')
         // $model->id_parent_category = null;
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id_category));
         }
     }
     $categories = $this->getCategories();
     $select = '<select name="Category[id_parent_category]" id="Category_parent_category">';
     $select .= '<option value="">(No Parent Category)</option>';
     foreach ($categories as $parent) {
         $select .= '<option value="' . $parent['id'] . '">' . ucfirst($parent['data']['name']) . '</option>';
         if (isset($parent['children'])) {
             $dash = '--';
             foreach ($parent['children'] as $children) {
                 $select .= '<option value="' . $children['data']->id_category . '">' . $dash . ucfirst($children['data']->name) . '</option>';
                 if (isset($children['children'])) {
                     $dash = '----';
                     foreach ($children['children'] as $child) {
                         $select .= '<option value="' . $child['data']->id_category . '">' . $dash . ucfirst($child['data']->name) . '</option>';
                     }
                 }
             }
         }
     }
     $select .= '</select>';
     $this->render('create', array('model' => $model, 'parent_category' => $select));
 }
 public function store()
 {
     $validator = Validator::make(Input::all(), Issue::$rules, Issue::$messages);
     //if($validator->passes()){
     $issue = new Issue();
     $issue->summary = Input::get('summary');
     $issue->detail = Input::get('detail');
     $issue->budget = 0.0;
     $issue->currentState = "TO-DO";
     $issue->points = Input::get('points');
     $issue->labels = Input::get('labels');
     $issue->iterationid = Input::get('iterationid');
     $categoryId = Input::get('categoryid');
     if ($categoryId == 0) {
         //crear categoria
         $category = new Category();
         $category->name = Input::get('category_name');
         $category->save();
         $issue->categoryid = $category->id;
     } else {
         $issue->categoryid = $categoryId;
     }
     $issue->save();
     return Redirect::to('/iterations/' . $issue->iterationid)->with('message', 'Historia creada con exito');
     /*}else{
     			return Redirect::to('iterations/'. Input::get('iterationid'))
     			->with('error', 'Ocurrieron los siguientes errores')
     			->withErrors($validator)
     			->withInput();
     		}*/
 }
Example #11
0
function save_website($datas)
{
    global $templatesList;
    load_lib();
    //Etape 1 : sauvegarde du site
    require_once MODELS . DS . 'website.php';
    $websiteModel = new Website();
    $templateId = $datas['template_id'];
    $template = $templatesList[$templateId];
    $datas['tpl_layout'] = $template['layout'];
    $datas['tpl_code'] = $template['code'];
    $datas['search_engine_position'] = 'header';
    $datas['created_by'] = 1;
    $datas['modified_by'] = 1;
    $datas['online'] = 1;
    $websiteModel->save($datas);
    define('CURRENT_WEBSITE_ID', $websiteModel->id);
    //Etape 2 : sauvegarde du menu racine
    require_once MODELS . DS . 'category.php';
    $categoryModel = new Category();
    unset($categoryModel->searches_params);
    ////////////////////////////////////////////////////////
    //   INITIALISATION DE LA CATEGORIE PARENTE DU SITE   //
    $categorie = array('parent_id' => 0, 'type' => 3, 'name' => 'Racine Site ' . $websiteModel->id, 'slug' => 'racine-site-' . $websiteModel->id, 'online' => 1, 'redirect_category_id' => 0, 'display_contact_form' => 0, 'website_id' => $websiteModel->id);
    $categoryModel->save($categorie);
    return $websiteModel->id + $categoryModel->id;
}
 public function doSave($con = null)
 {
     parent::doSave($con);
     if (!$this->getValue('parent')) {
         $treeObject = Doctrine_Core::getTable('Category')->getTree();
         $roots = $treeObject->fetchRoots();
         //If root was deleted, recreate
         if (count($roots) == 0) {
             $rootCategory = new Category();
             $rootCategory->setName("Categories");
             $rootCategory->setActive(true);
             $rootCategory->save();
             $treeObject->createRoot($rootCategory);
             $parent = $rootCategory;
         } else {
             $parent = Doctrine::getTable('Category')->findOneById($roots[0]['id']);
         }
         if ($this->isNew()) {
             $this->getObject()->getNode()->insertAsFirstChildOf($parent);
         } else {
             $this->getObject()->getNode()->moveAsFirstChildOf($parent);
         }
     } elseif ($this->getValue('parent')) {
         $parent = Doctrine::getTable('Category')->findOneById($this->getValue('parent'));
         if ($this->isNew()) {
             $this->getObject()->getNode()->insertAsLastChildOf($parent);
         } else {
             $this->getObject()->getNode()->moveAsLastChildOf($parent);
         }
     }
 }
Example #13
0
 public function add()
 {
     if (Request::isMethod('post')) {
         $rules = array('title' => 'required|min:4', 'link' => "required|unique:categories", 'meta_keywords' => 'required');
         $validator = Validator::make(Input::all(), $rules);
         if ($validator->fails()) {
             return Redirect::to("admin/category/add")->withErrors($validator)->withInput(Input::except(''));
         } else {
             $table = new Category();
             $table->title = Input::get('title');
             $table->link = Input::get('link');
             $table->content = Input::get('content');
             $table->parent_id = Input::get('parent_id') ? Input::get('parent_id') : null;
             $table->meta_title = Input::get('meta_title') ? Input::get('meta_title') : $table->title;
             $table->meta_description = Input::get('meta_description') ? Input::get('meta_description') : $table->title;
             $table->meta_keywords = Input::get('meta_keywords');
             $table->active = Input::get('active', 0);
             if ($table->save()) {
                 $name = trans("name.category");
                 return Redirect::to("admin/category")->with('success', trans("message.add", ['name' => $name]));
             }
             return Redirect::to("admin/category")->with('error', trans('message.error'));
         }
     }
     $categories = array(0 => 'Нет родительской категории') + Category::orderBy('title')->lists('title', 'id');
     return View::make("admin.shop.category.add", ['categories' => $categories, 'action' => $this->action]);
 }
Example #14
0
 public function run()
 {
     DB::table('categories')->delete();
     $jsonCat = json_decode(file_get_contents(url('/categories.json')));
     foreach ($jsonCat as $categoriesParent) {
         $cat = new Category();
         $cat->title = $categoriesParent->title;
         $cat->slug = last(explode('/', $categoriesParent->slug));
         $cat->save();
         foreach ($categoriesParent->children as $catChild1) {
             $cat1 = new Category();
             $cat1->title = $catChild1->title;
             $cat1->slug = last(explode('/', $catChild1->slug));
             $cat1->parent_id = $cat->id;
             $cat1->save();
             foreach ($catChild1->children as $catChild2) {
                 $cat2 = new Category();
                 $cat2->title = $catChild2->title;
                 $cat2->slug = last(explode('/', $catChild2->slug));
                 $cat2->parent_id = $cat1->id;
                 $cat2->save();
             }
         }
     }
 }
Example #15
0
 /**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param      PropelPDO $con
  * @return     int The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws     PropelException
  * @see        save()
  */
 protected function doSave(PropelPDO $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their coresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aCategory !== null) {
             if ($this->aCategory->isModified() || $this->aCategory->isNew()) {
                 $affectedRows += $this->aCategory->save($con);
             }
             $this->setCategory($this->aCategory);
         }
         if ($this->aBook !== null) {
             if ($this->aBook->isModified() || $this->aBook->isNew()) {
                 $affectedRows += $this->aBook->save($con);
             }
             $this->setBook($this->aBook);
         }
         if ($this->isNew()) {
             $this->modifiedColumns[] = ArticlePeer::ID;
         }
         // If this object has been modified, then save it to the database.
         if ($this->isModified()) {
             if ($this->isNew()) {
                 $pk = ArticlePeer::doInsert($this, $con);
                 $affectedRows += 1;
                 // we are assuming that there is only 1 row per doInsert() which
                 // should always be true here (even though technically
                 // BasePeer::doInsert() can insert multiple rows).
                 $this->setId($pk);
                 //[IMV] update autoincrement primary key
                 $this->setNew(false);
             } else {
                 $affectedRows += ArticlePeer::doUpdate($this, $con);
             }
             $this->resetModified();
             // [HL] After being saved an object is no longer 'modified'
         }
         if ($this->collAuthorArticles !== null) {
             foreach ($this->collAuthorArticles as $referrerFK) {
                 if (!$referrerFK->isDeleted()) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->collAttachments !== null) {
             foreach ($this->collAttachments as $referrerFK) {
                 if (!$referrerFK->isDeleted()) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
Example #16
0
 public function AddCategory()
 {
     $category = new Category();
     $cat = Input::get('category');
     $category->category = $cat;
     $category->save();
     return Redirect::route('article.new');
 }
 public function postCreate()
 {
     $posted = Input::all();
     $category = new Category();
     $category->name = $posted['name'];
     $category->save();
     return Redirect::back()->with('success', 'New category has been created');
 }
Example #18
0
 public function setUp()
 {
     parent::setUp();
     // create a new category
     $this->productCategory = Category::getNewInstance(Category::getRootNode());
     $this->productCategory->setValueByLang("name", "en", "Demo category branch");
     $this->productCategory->save();
     // create a product without attributes
     $this->product = Product::getNewInstance($this->productCategory, 'test');
     $this->product->setValueByLang("name", "en", "Test product...");
     $this->product->setValueByLang("name", "lt", "Bandomasis produktas");
     $this->product->setFieldValue("isEnabled", true);
     $this->product->save();
     $this->usd = ActiveRecordModel::getNewInstance('Currency');
     $this->usd->setID('ZZZ');
     $this->usd->save(ActiveRecord::PERFORM_INSERT);
 }
 public function run()
 {
     for ($i = 0; $i < 59; $i++) {
         $style = new Category();
         $style->category_name = "{$i}";
         $style->image = "{$i}";
         $style->save();
     }
 }
Example #20
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $category = new Category();
     $category->name = $request->get('categoryName');
     $category->description = $request->get('categoryDescription');
     $category->save();
     return view('createcategory')->with('success', 1);
     //
 }
Example #21
0
 function approve($id)
 {
     if ($_POST) {
         $rs = new Category($id);
         $rs->from_array($_POST);
         $rs->save();
     }
     // echo $_POST['status'];
 }
Example #22
0
 function approve($id)
 {
     if ($_POST) {
         $categories = new Category($id);
         $_POST['approve_id'] = $this->session->userdata('id');
         $categories->from_array($_POST);
         $categories->save();
     }
 }
Example #23
0
 public function post_add()
 {
     $category = new Category();
     $category->name = Input::get('name');
     $category->short_description = Input::get('short_description');
     $category->slug = Str::slug(Input::get('name'), '_');
     $category->parent = Input::get('parent');
     $category->save();
     return Redirect::to_action('admin.categories@list', array($category->parent))->with('flash', true)->with('flash_type', 'success')->with('flash_msg', 'New category created successfully.');
 }
Example #24
0
 /**
  * Find or create a category
  * 
  * @param string $extendsModel
  * @param string $categoryName
  * @return \Category 
  */
 public function createIfNotExists($extendsModel, $categoryName)
 {
     $category = Category::model()->findSingleByAttributes(array('extends_model' => $extendsModel, 'name' => $categoryName));
     if (!$category) {
         $category = new Category();
         $category->extends_model = $extendsModel;
         $category->name = $categoryName;
         $category->save();
     }
     return $category;
 }
Example #25
0
 function test_find()
 {
     $name = "Wash the dog";
     $name2 = "Home stuff";
     $test_Category = new Category($name);
     $test_Category->save();
     $test_Category2 = new Category($name2);
     $test_Category2->save();
     $result = Category::find($test_Category->getId());
     $this->assertEquals($test_Category, $result);
 }
 public function postCreate()
 {
     $validator = Validator::make(Input::all(), Category::$rules);
     if ($validator->passes()) {
         $category = new Category();
         $category->name = Input::get('name');
         $category->save();
         return Redirect::to('admin/categories')->with('message', 'Wohoo! success!');
     }
     return Redirect::to('admin/categories')->with('message', 'Something Went Wrong')->withErrors($validator)->withInput();
 }
 public function storeCategory()
 {
     $validation = Validator::make(Input::all(), Category::$rules);
     if ($validation->fails()) {
         return Redirect::back()->withInput()->withErrors($validation->messages());
     }
     $category = new Category();
     $category->name = Input::get('name');
     $category->save();
     return Redirect::route('AdminIndex');
 }
Example #28
0
 function save($id = FALSE)
 {
     if ($_POST) {
         $category = new Category($id);
         $_POST['name'] = lang_encode($_POST['name']);
         $category->from_array($_POST);
         $category->save();
         set_notify('success', lang('save_data_complete'));
     }
     redirect('newsletters/admin/categories/member_index');
 }
 /**
  * 添加栏目
  */
 public function actionAdd()
 {
     $categoryModel = new Category();
     if (isset($_POST['Category'])) {
         $categoryModel->attributes = $_POST['Category'];
         if ($categoryModel->save()) {
             $this->redirect(array('index'));
         }
     }
     $this->render('add', array('categoryModel' => $categoryModel));
 }
 public function postCreate()
 {
     $validator = Validator::make(Input::all(), Category::$rules);
     if ($validator->passes()) {
         $category = new Category();
         $category->name = Input::get('name');
         $category->save();
         return Redirect::to('admin/categories/index')->with('message', 'Category Created');
     }
     return Redirect::to('admin/categories/index')->with('message', 'Couldn\'t create category')->withErrors($validator)->withInput();
 }