public function testForTest()
 {
     TranslateAbility::setLanguageId(1);
     $brand = new \Brand(array('title' => 'Apple'));
     $this->assertEquals('Apple', $brand->title, 'Accessor after creating');
     $brand->save();
     $this->assertEquals('Apple', $brand->title, 'Accessor after saving');
     $brand = \Brand::loadOne(1);
     $this->assertEquals('Apple', $brand->title, 'Accessor after loading');
     $this->assertEquals(array('id_language' => 1, 'id_object' => 1, 'title' => 'Apple'), QC::create('brands_translate')->executeOne(), 'Data stored in DB after saving');
     TranslateAbility::setLanguageId(2);
     $brand->title = 'Яблоко';
     $brand->save();
     $this->assertEquals('Яблоко', $brand->title, 'Accessor after loading');
     $this->assertEquals(array('id_language' => 2, 'id_object' => 1, 'title' => 'Яблоко'), QC::create('brands_translate')->where('id_language = :d', 2)->executeOne(), 'Data stored in DB after saving');
     $brand->loadTranslation(1);
     $this->assertEquals('Apple', $brand->title, 'loadTranslation works');
     $this->assertEquals(array('id' => 1, 'id_object' => 1, 'id_language' => 2, 'title' => 'Яблоко'), $brand->getTranslationForLanguage(2), 'getTranslationForLanguage');
     TranslateAbility::setLanguageId(1);
     $brand2 = new \Brand();
     $brand2->title = 'Samsung';
     $brand2->save();
     $brand2->loadTranslation(2);
     $this->assertEmpty($brand2->title, 'Empty data for not translated item');
     $brands = \Brand::loadList();
     $this->assertEquals(array('Apple', 'Samsung'), $brands->getFieldArray('title'), 'Loaded two translated items');
     $brands->loadTranslation(2);
     $this->assertEquals(array('Яблоко', null), $brands->getFieldArray('title'), 'Loaded two not fully translated items');
     $this->assertEquals(array(1 => array('id' => 1, 'id_object' => 1, 'id_language' => 1, 'title' => 'Apple'), 2 => array('id' => 1, 'id_object' => 1, 'id_language' => 2, 'title' => 'Яблоко')), $brand->getAllTranslations(), 'getAllTranslations()');
 }
 public function run()
 {
     DB::table('brands')->truncate();
     $brand = new Brand();
     $brand->name = "5TheWay";
     $brand->save();
     $brand = new Brand();
     $brand->name = "Nike";
     $brand->save();
     $brand = new Brand();
     $brand->name = "Adidas";
     $brand->save();
     $brand = new Brand();
     $brand->name = "Puma";
     $brand->save();
     $brand = new Brand();
     $brand->name = "Ripcurl";
     $brand->save();
     $brand = new Brand();
     $brand->name = "The Northface";
     $brand->save();
     $brand = new Brand();
     $brand->name = "Overdose";
     $brand->save();
     $brand = new Brand();
     $brand->name = "Kenstyle";
     $brand->save();
     $brand = new Brand();
     $brand->name = "Real Tree";
     $brand->save();
     $brand = new Brand();
     $brand->name = "Game Guard";
     $brand->save();
 }
 public function testImages()
 {
     $brand = new \Brand(array('title' => 'test'));
     $brand->save();
     $brand->attachFileFromPath('avatar', __DIR__ . '/assets/flower.jpg');
     $this->assertEquals('04/4/avatar/small/' . $brand->avatar['full_name'], $brand->avatar['small']['link'], 'Small avatar works');
 }
 public function actionAjax()
 {
     if (Yii::app()->request->isAjaxRequest) {
         if (isset($_POST['Brand']['id']) && !empty($_POST['Brand']['id'])) {
             $model = $this->loadModel($_POST['Brand']['id']);
             $model->attributes = $_POST['Brand'];
             if ($model->validate()) {
                 if (Yii::app()->params['server'] == CAlexHelper::DEVELOPMENT || $_POST['Brand']['id'] > 60) {
                     if ($model->save()) {
                         $this->setNotice('Запись успешно обновлена');
                         $model = new Brand();
                     } else {
                         $this->setNotice('Fail');
                     }
                 } else {
                     $this->setNotice('You cant edit data on this site');
                 }
             }
         } else {
             $model = new Brand();
             $model->attributes = $_POST['Brand'];
             if ($model->validate()) {
                 if ($model->save()) {
                     $this->setNotice('Запись успешно добавлена');
                     $model = new Brand();
                 } else {
                     $this->setNotice('Fail');
                 }
             }
         }
         $this->renderPartial('ajaxForm', array('model' => $model));
     } else {
         throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.');
     }
 }
Beispiel #5
0
 public function postSave()
 {
     $brand = new Brand();
     $brand->client_id = Input::get('client_id');
     $brand->brand_name = Input::get('brand_name');
     $brand->category_id = Input::get('category_id');
     $brand->save();
     return Response::json($brand);
 }
Beispiel #6
0
 public function executeAddBrand(sfWebRequest $request)
 {
     try {
         $q = new Brand();
         $q->setBrandName($request->getParameter('brand_name'));
         $q->save();
         $this->res = "Brand Added!";
     } catch (Exception $exc) {
         $this->res = $exc->getMessage();
     }
 }
Beispiel #7
0
 function test_delete()
 {
     $name = "Nike";
     $test_brand = new Brand($name, $id);
     $test_brand->save();
     $name2 = "Adidas";
     $test_brand2 = new Brand($name2, $id);
     $test_brand2->save();
     $test_brand->delete();
     $this->assertEquals([$test_brand2], Brand::getAll());
 }
Beispiel #8
0
 function testDelete()
 {
     $name = "Zelds";
     $test_store = new Store($name);
     $test_store->save();
     $name = "Granite";
     $test_brand = new Brand($name);
     $test_brand->save();
     $test_brand->addStore($test_brand);
     $test_brand->delete();
     $this->assertEquals([], $test_brand->getStores());
 }
 public function testBasic()
 {
     $brand = new \Brand(array('title' => 'Apple'));
     $brand->save();
     $this->assertEquals('apple', $brand->getSlug(), 'slug ability for Apple');
     $brand->setTitle('Саша')->save();
     $this->assertEquals('sasha', $brand->getSlug(), 'slug ability for Sasha');
     $brand->setTitle('')->save();
     $this->assertEquals('n-a', $brand->getSlug(), 'slug ability for empty');
     $brand->setTitle('12 -_  s')->save();
     $this->assertEquals('12-s', $brand->getSlug(), 'slug ability for bad string');
 }
Beispiel #10
0
 function testAddBrand()
 {
     $store_name = "Beacons Closet";
     $new_store = new Store($store_name);
     $new_store->save();
     $brand_name = "dr.martens";
     $new_brand = new Brand($brand_name);
     $new_brand->save();
     $new_store->addBrand($new_brand);
     $result = $new_store->getBrands();
     $this->assertEquals($new_brand, $result[0]);
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Brand();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Brand'])) {
         $model->attributes = $_POST['Brand'];
         if ($model->save()) {
             $this->redirect(Yii::app()->request->baseUrl . '/brand/admin');
         }
     }
     $this->render('create', array('model' => $model));
 }
Beispiel #12
0
 public static function add()
 {
     return function ($req, $res) {
         $res->header('Content-Type', 'application/json; charset=utf-8');
         $raw = file_get_contents("php://input");
         $data = json_decode($raw);
         $model = new Brand();
         $model->name = $data->name;
         $model->description = $data->description;
         $model->save();
         echo $model;
     };
 }
 /**
  * Show the form for creating a new resource.
  *
  * @return Response
  */
 public function postCreate()
 {
     $validator = Validator::make(Input::all(), Brand::$rules);
     if ($validator->passes()) {
         $brand = new Brand();
         $brand->brand = Input::get('brand');
         $brand->subcategory_id = Input::get('subcategory_id');
         $brand->save();
         return Redirect::back()->with('success', 'Brand added successfully.');
     } else {
         return Redirect::back()->withErrors($validator);
     }
 }
Beispiel #14
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Brand();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Brand'])) {
         $model->attributes = $_POST['Brand'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->value_id));
         }
     }
     $this->render('create', array('model' => $model));
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     //
     //
     $validation = Validate::BrandValidation(Input::all());
     if ($validation->fails()) {
         return Redirect::to('marca/create')->withErrors($validation)->withInput();
     } else {
         $brand = new Brand();
         $brand->brand = Input::get('brand');
         $brand->save();
         return Redirect::to('admin/marca');
     }
 }
Beispiel #16
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->aBrand !== null) {
             if ($this->aBrand->isModified() || $this->aBrand->isNew()) {
                 $affectedRows += $this->aBrand->save($con);
             }
             $this->setBrand($this->aBrand);
         }
         if ($this->isNew()) {
             $this->modifiedColumns[] = SeriesPeer::ID;
         }
         // If this object has been modified, then save it to the database.
         if ($this->isModified()) {
             if ($this->isNew()) {
                 $pk = SeriesPeer::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 += SeriesPeer::doUpdate($this, $con);
             }
             $this->resetModified();
             // [HL] After being saved an object is no longer 'modified'
         }
         if ($this->collModels !== null) {
             foreach ($this->collModels as $referrerFK) {
                 if (!$referrerFK->isDeleted()) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
Beispiel #17
0
 public function actionAdd()
 {
     if (empty($_POST)) {
         $viewData = array();
         $this->render('add', $viewData);
         exit;
     }
     $res = array('statusCode' => 200, 'message' => '添加成功!');
     try {
         $brand_name = '';
         $image = CUploadedFile::getInstanceByName('brand_logo');
         if ($image) {
             $dir = Yii::getPathOfAlias('webroot') . '/images/brand';
             $extension = $image->getExtensionName();
             $brand_name = time() . '_0.' . $extension;
             $imagePath = $dir . '/' . $brand_name;
             $image->saveAs($imagePath, true);
         }
         $m = new Brand();
         $m->brand_name = $_REQUEST['brand_name'];
         $m->english_name = $_REQUEST['english_name'];
         $m->brand_logo = $brand_name;
         $m->from_city = $_REQUEST['from_city'];
         $m->address = $_REQUEST['address'];
         $m->mobile = $_REQUEST['mobile'];
         $m->tel = $_REQUEST['tel'];
         $m->site_url = $_REQUEST['site_url'];
         $m->keywords = $_REQUEST['keywords'];
         $m->describtion = $_REQUEST['describtion'];
         $m->sort = $_REQUEST['sort'];
         $m->title = $_REQUEST['title'];
         $m->is_show = $_REQUEST['is_show'];
         $m->add_time = time();
         $flag = $m->save();
         if (!$flag) {
             throw new exception('添加失败');
         }
     } catch (Exception $e) {
         $res['statusCode'] = 300;
         $res['message'] = '失败【' . $e->getMessage() . '】';
     }
     $res['navTabId'] = 'bannerList';
     $res['callbackType'] = 'closeCurrent';
     $res['forwardUrl'] = '/manage/brand/index';
     $this->ajaxDwzReturn($res);
 }
Beispiel #18
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Brand();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Brand'])) {
         $model->attributes = $_POST['Brand'];
         if ($model->save()) {
             if (!empty($_POST['yt1'])) {
                 Yii::app()->user->setFlash('brand-created', "¡La marca <b><i>&quot;{$model->name}&quot;</i></b> fue creada exitosamente!");
                 $this->redirect(array('create'));
             } else {
                 $this->redirect(array('view', 'id' => $model->id));
             }
         }
     }
     $this->render('create', array('model' => $model));
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Brand();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['buttonCancel'])) {
         $this->redirect(array('admin'));
     }
     if (isset($_POST['Brand'])) {
         $model->attributes = $_POST['Brand'];
         /*GARENTE QUE O NOME DA MARCA SEMPRE SEJA SALVO EM MAIÚSCULO*/
         $model->brand_name = strtoupper($model->brand_name);
         if ($model->save()) {
             $this->redirect(array('admin', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
Beispiel #20
0
 public static function createAndSaveRawModelWithOneToManyRelation()
 {
     $testBrand = new \Brand();
     $testBrand->nameBrand = 'AcmeMult';
     $testBrand->noteBrand = 10;
     $testBrand->save();
     $car = new \Car();
     $car->nameCar = 'AcmeCar1';
     $car->noteCar = '10';
     $car2 = new \Car();
     $car2->nameCar = 'AcmeCar2';
     $car2->noteCar = '12';
     $car3 = new \Car();
     $car3->nameCar = 'AcmeCar3';
     $car3->noteCar = '15';
     $cars = array($car, $car2, $car3);
     $testBrand->setCar($cars);
     return array(array($testBrand, $cars));
 }
Beispiel #21
0
 function testGetStores()
 {
     $brand_name = "Air Jordan";
     $test_brand = new Brand($brand_name);
     $test_brand->save();
     $name = "Foot Locker";
     $phone_number = "555-555-5555";
     $address = "123 ABC Street";
     $test_store = new Store($name, $phone_number, $address);
     $test_store->save();
     $name2 = "Nike Outlet";
     $phone_number2 = "444-444-4444";
     $address2 = "456 CBA Ave.";
     $test_store2 = new Store($name2, $phone_number2, $address2);
     $test_store2->save();
     $test_brand->addStore($test_store);
     $test_brand->addStore($test_store2);
     $result = $test_brand->getStores();
     $this->assertEquals([$test_store, $test_store2], $result);
 }
 public function save()
 {
     //validation call
     $valid = $this->_validate_submission();
     if ($valid == false) {
         $data['content_view'] = "brandname_add_v";
         $this->base_params($data);
     } else {
         $drugid = $this->input->post("drugid");
         $brandname = $this->input->post("brandname");
         $brand = new Brand();
         $brand->Drug_Id = $drugid;
         $brand->Brand = $brandname;
         $brand->save();
         //$this -> session -> set_userdata('message_counter', '1');
         $this->session->set_userdata('msg_success', $this->input->post('brandname') . ' was Added');
         $this->session->set_flashdata('filter_datatable', $this->input->post('brandname'));
         //Filter datatable
         redirect("settings_management");
     }
 }
 public function actionIndex($id)
 {
     $model = ModelCategory::model()->findAll('category_id = :num', array(':num' => $id));
     $modelBrand = new Brand();
     $modelCategory = new ModelCategory();
     if (isset($_POST['ids'])) {
         ModelCategory::model()->deleteAll('brand_id = :brand_id', array(':brand_id' => $_POST['ids']));
         Brand::model()->findByPk($_POST['ids'])->delete();
         $this->refresh();
     }
     if (isset($_POST['yt0'])) {
         $modelBrand->attributes = $_POST['Brand'];
         $modelBrand->save();
         $modelCategory->category_id = $id;
         $modelCategory->brand_id = $modelBrand->id;
         if ($modelCategory->save()) {
             Yii::app()->user->setFlash('status', 'Бренд добавлен');
         }
         $this->refresh();
     }
     $this->render('index', array('model' => $model, 'modelBrand' => $modelBrand, 'idkey' => $id));
 }
 /**
  * 品牌创建
  */
 public function actionCreate()
 {
     if ($_POST) {
         $Brand = new Brand();
         $Brand->attributes = $this->post('Brand');
         $type_attributes = $this->post('GoodsType');
         if (!$Brand->save()) {
             $Brand = new Brand();
             $this->message('error', CHtml::errorSummary($Brand), $this->createUrl('index'));
         }
         if ($type_attributes) {
             $brand_id = Yii::app()->db->getLastInsertID();
             $TypeBrand = new TypeBrand();
             $result = $TypeBrand->type_brand_insert($brand_id, $type_attributes);
             if (!$result) {
                 $this->message('error', CHtml::errorSummary($TypeBrand), $this->createUrl('index'));
             }
         }
         $this->referrer();
     }
     $model['type_list'] = GoodsType::model()->findAll('disabled = :disabled', array(':disabled' => 'false'));
     $this->render('create', array('model' => $model));
 }
Beispiel #25
0
 /**
  * 添加品牌
  */
 public function ActionAddBrand()
 {
     $brand_model = new Brand();
     if (isset($_POST['Brand'])) {
         // 填充模型
         $brand_model->attributes = $_POST['Brand'];
         // 执行添加
         if ($brand_model->save()) {
             // 添加操作日志 [S]
             $log = Yii::app()->user->name . '于 ' . date('Y-m-d H:i:s', time()) . ' 添加了一个名为 【' . $_POST['Brand']['BrandName'] . '】 的品牌';
             OperationLogManage::AddOperationLog($log);
             // 添加日志
             // 添加操作日志 [E]
             Yii::app()->user->setFlash('save_sign', '添加成功');
             $this->redirect(Yii::app()->createUrl('Brand/ListBrand'));
         } else {
             Yii::app()->user->setFlash('save_sign', '添加失败');
             $this->renderPartial('add_brand', array('brand_model' => $brand_model));
         }
     } else {
         // 跳转至添加页
         $this->renderPartial('add_brand', array('brand_model' => $brand_model));
     }
 }
Beispiel #26
0
});
$app->get("/stores", function () use($app) {
    return $app['twig']->render('stores.html.twig', array('stores' => Store::getAll()));
});
$app->get("/brands", function () use($app) {
    return $app['twig']->render('brands.html.twig', array('brands' => Brand::getAll()));
});
//POSTS
$app->post("/stores", function () use($app) {
    $store = new Store($_POST['store_name']);
    $store->save();
    return $app['twig']->render('stores.html.twig', array('stores' => Store::getAll()));
});
$app->post("/brands", function () use($app) {
    $brand = new Brand($_POST['brand_name']);
    $brand->save();
    return $app['twig']->render('brands.html.twig', array('brands' => Brand::getAll()));
});
//EDIT GETS
$app->get("/stores/{id}", function ($id) use($app) {
    $store = Store::find($id);
    return $app['twig']->render('store.html.twig', array('store' => $store, 'brands' => $store->getBrands(), 'all_brands' => Brand::getAll()));
});
$app->get("/brands/{id}", function ($id) use($app) {
    $brand = Brand::find($id);
    return $app['twig']->render('brand.html.twig', array('brand' => $brand, 'stores' => $brand->getStores(), 'all_stores' => Store::getAll()));
});
//DELETES
$app->post("/delete_stores", function () use($app) {
    Store::deleteAll();
    return $app['twig']->render('stores.html.twig', array('stores' => Store::getAll()));
Beispiel #27
0
$app->post('/add_store', function () use($app) {
    $id = null;
    $store_name = $_POST['store_name'];
    $new_store = new Store($store_name, $id);
    $new_store->save();
    return $app['twig']->render('index.html.twig', array('stores' => Store::getAll(), 'brands' => Brand::getAll()));
});
$app->post('/delete_stores', function () use($app) {
    Store::deleteAll();
    return $app['twig']->render('index.html.twig', array('stores' => Store::getAll(), 'brands' => Brand::getAll()));
});
$app->post('/add_brand', function () use($app) {
    $id = null;
    $name = $_POST['brand_name'];
    $new_brand = new Brand($name, $id);
    $new_brand->save();
    return $app['twig']->render('index.html.twig', array('stores' => Store::getAll(), 'brands' => Brand::getAll()));
});
$app->post('/delete_brands', function () use($app) {
    Brand::deleteAll();
    return $app['twig']->render('index.html.twig', array('stores' => Store::getAll(), 'brands' => Brand::getAll()));
});
$app->get('/stores/{id}', function ($id) use($app) {
    $store = Store::find($id);
    $brands = $store->getBrands();
    $all_brands = Brand::getAll();
    return $app['twig']->render('stores.html.twig', array('store' => $store, 'brands' => $brands, 'all_brands' => $all_brands));
});
$app->post('/add_brands', function () use($app) {
    $store = Store::find($_POST['store_id']);
    $brand = Brand::find($_POST['brand_id']);
Beispiel #28
0
 function testGetStores()
 {
     //Arrange
     $brand_name = "Sketchers";
     $id = null;
     $test_brand = new Brand($brand_name, $id);
     $test_brand->save();
     $another_brand = "Doc Martin";
     $test_brand2 = new Brand($another_brand, $id);
     $test_brand2->save();
     $store_name = "Norstrom";
     $test_store = new Store($store_name, $id);
     $test_store->save();
     //Act
     $test_store->addBrand($test_brand);
     $test_store->addBrand($test_brand2);
     $result = $test_store->getBrands();
     //Assert
     $this->assertEquals([$test_brand, $test_brand2], $result);
 }
 function testFind()
 {
     // Arrange
     $name = "Babbling Brooks";
     $test_Brand = new Brand($name);
     $test_Brand->save();
     $name2 = "Old Balance";
     $test_Brand2 = new Brand($name2);
     $test_Brand2->save();
     // Act
     $result = Brand::find($test_Brand2->getId());
     // Assert
     $this->assertEquals($test_Brand2, $result);
 }
Beispiel #30
0
 function testGetStores()
 {
     //Arrange
     $store_name = "Happy Lemon";
     $test_store = new Store($store_name, $id = null);
     $test_store->save();
     $store_name2 = "Chatime";
     $test_store2 = new Store($store_name2, $id = null);
     $test_store2->save();
     $brand_name = "Feiyue";
     $test_brand = new Brand($brand_name, $id = null);
     $test_brand->save();
     //Act
     $test_brand->addStore($test_store);
     $test_brand->addStore($test_store2);
     //Assert
     $this->assertEquals($test_brand->getStores(), [$test_store, $test_store2]);
 }