/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Modelo(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Modelo'])) { $model->attributes = $_POST['Modelo']; if ($model->save()) { if (!empty($_POST['yt1'])) { Yii::app()->user->setFlash('modelo-created', "¡El modelo <b><i>"{$model->name}"</i></b> fue creado exitosamente!"); //$this->redirect(array('create')); $modelSaved = $model; $model = new Modelo(); $model->equipment_type_id = $modelSaved->equipment_type_id; $model->brand_id = $modelSaved->brand_id; } else { $this->redirect(array('view', 'id' => $model->id)); } } } if (EquipmentType::model()->count('active = 1') == 0 && Brand::model()->count('active = 1') == 0) { throw new CHttpException('', 'Primero debe ' . CHtml::link('crear un Tipo de Equipo', array('equipmentType/create')) . ' y ' . CHtml::link('crear una Marca', array('brand/create')) . '.'); } else { if (EquipmentType::model()->count('active = 1') == 0) { throw new CHttpException('', 'Primero debe ' . CHtml::link('crear un Tipo de Equipo', array('equipmentType/create')) . '.'); } else { if (Brand::model()->count('active = 1') == 0) { throw new CHttpException('', 'Primero debe ' . CHtml::link('crear una Marca', array('brand/create')) . '.'); } else { $this->render('create', array('model' => $model)); } } } }
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 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 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); }
public function insert(Category $category, Subcategory $subcategory, Brand $brand, Item $item) { // $sql = "INSERT INTO item values (null, 'aalluu', 'asdfasd',true,true, '2015-10-10','asdfasf', 'asdfasd', 1, 1 ,1, 1)"; $sql = "INSERT INTO item values (null, '" . $item->getTitle() . "','" . $item->getDetail() . "',true,false, '" . $item->getDate() . "', '" . $item->getLocation() . "','asfasf'," . $category->getId() . "," . $subcategory->getId() . ", 1 ," . $brand->getId() . ")"; echo $sql; if ($this->conn->query($sql) === TRUE) { echo "Insert operation successful"; } else { echo "Error inserting: "; } }
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(); } }
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()); }
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]); }
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'); }
function __construct() { $this->api_config_arr = (include_once '/protected/config/Api_config.php'); foreach ($this->api_config_arr as $config_key => $config_value) { unset($this->api_config_arr[$config_key]['Tmall']['brandkey']); } $brand_docking_ret = Brand::getbranddocking('*', array('status' => '=1')); if ($brand_docking_ret['status'] == 1) { foreach ($brand_docking_ret['data'] as $value) { $is_bool = false; foreach ($this->api_config_arr as $config_key => $config_value) { if ($value['brandid'] == $config_value['brandid']) { if (!isset($this->api_config_arr[$config_key]['Tmall'])) { $this->api_config_arr[$config_key]['Tmall'] = array(); } $this->api_config_arr[$config_key]['Tmall']['brandkey'] = $value['tamllid']; $is_bool = true; } } if (!$is_bool) { $this->api_config_arr[] = array('brandid' => $value['brandid'], 'Tmall' => array('brandkey' => $value['tamllid'])); } } } }
/** * 返回图文模板 - 多条图文,故采用方法,直接返回格式化后的字符串 * @param String $fromUserName 发送方 * @param String $toUserName 接收方 * @param Array $arr 一维度数组 或 二维数组,代表一个图文消息里多个条目 * @param Integer $brandId 品牌主键 * 注意: * 数组$arr可以是关联数组,且存在键 title, description, pic_url, url * 也可以是索引数组,则0-3对应上述相应的值,不可错乱 * * picUrl限制图片链接的域名需要与开发者填写的基本资料中的Url一致 */ public static function news($fromUserName, $toUserName, $arr, $brandId) { if (ArrayUtil::depth($arr) == 1) { // 一维数组,图文一条条目 if (isset($v['title'])) { return sprintf(PushTemplates::NEWS, $fromUserName, $toUserName, time(), $arr['title'], $arr['description'], Brand::fullPicUrl($arr['pic_url'], $brandId), URLOauth::redirect($brandId, $arr['url'])); } else { return sprintf(PushTemplates::NEWS, $fromUserName, $toUserName, time(), $arr[0], $arr[1], Brand::fullPicUrl($arr[2], $brandId), URLOauth::redirect($brandId, $arr[3])); } } else { // 二维数组,图文多条条目 $item = "<item>\n\t\t\t\t <Title><![CDATA[%s]]></Title> \n\t\t\t\t <Description><![CDATA[%s]]></Description>\n\t\t\t\t <PicUrl><![CDATA[%s]]></PicUrl>\n\t\t\t\t <Url><![CDATA[%s]]></Url>\n\t\t\t\t </item>"; $itemStr = ''; foreach ($arr as $v) { if (isset($v['title'])) { $itemStr .= sprintf($item, $v['title'], $v['description'], Brand::fullPicUrl($v['pic_url'], $brandId), URLOauth::redirect($brandId, $v['url'])); } else { $itemStr .= sprintf($item, $v[0], $v[1], Brand::fullPicUrl($v[2], $brandId), URLOauth::redirect($brandId, $v[3])); } } // 注意,不能在此处 $tbl . $itemStr ."</Articles>...",然后再sprintf因此URLOauth中的网址包含了转义字符%s等,造成sprintf参数太少的错误 $tbl = "<xml>\n\t\t\t\t\t <ToUserName><![CDATA[%s]]></ToUserName>\n\t\t\t\t\t <FromUserName><![CDATA[%s]]></FromUserName>\n\t\t\t\t\t <CreateTime>%s</CreateTime>\n\t\t\t\t\t <MsgType><![CDATA[news]]></MsgType>\n\t\t\t\t\t <ArticleCount>" . count($arr) . "</ArticleCount>\n\t\t\t\t\t <Articles>\n\t\t\t\t\t\t "; $frontPortion = sprintf($tbl, $fromUserName, $toUserName, time()); return $frontPortion . $itemStr . "\n\t\t\t\t\t </Articles>\n\t\t\t\t\t <FuncFlag>1</FuncFlag>\n\t\t\t\t\t </xml>"; } }
public function actionIndex() { $product_id = intval($_REQUEST['id']); $pInfo = Product::model()->getProductInfoById($product_id); if (empty($pInfo)) { $this->redirect('/?from=no_goods'); //跳转到首页 } $brandInfo = ''; if ($pInfo['brand_id']) { $brandInfo = Brand::model()->findByPk($pInfo['brand_id']); } $stock = Product::model()->getProductStock($product_id, $pInfo['is_multiple']); $attrList = ProductAttributes::model()->getProductAttrNameList(); $extendAttrList = ProductExtend::model()->getProductExtendAttrs($product_id); $is_like = Like::model()->getLikeStatus($this->user_id, $product_id); $cake = Category::model()->getCakeLine($pInfo['cat_id']); //获取商品的面包屑 $viewData = array(); $viewData['pInfo'] = $pInfo; $viewData['brandInfo'] = $brandInfo; $viewData['is_like'] = $is_like; $viewData['cake'] = $cake; $viewData['stock'] = $stock; $viewData['attrList'] = $attrList; $viewData['extendAttrList'] = $extendAttrList; $this->render('item/index', $viewData); }
public function scopeBrand($query, $id) { $brands = Brand::lists('name', 'id'); if ($id != "" && isset($brands[$id])) { $query->where('brand_id', $id); } }
/** * 品牌详情页面(带商品列表) */ public function actionDetail() { $_REQUEST['id'] = intval($_REQUEST['id']); if (empty($_REQUEST['id'])) { $this->redirect('/?from=brand_empty'); } $brandInfo = Brand::model()->getBrandInfoForWeb($_REQUEST['id']); if (empty($brandInfo)) { $this->redirect('/?from=brand_empty'); } $result = Brand::model()->getBrandProductByPageForWeb($_REQUEST); if (empty($result) || $result['count'] <= 0) { $this->redirect('/?from=brand_product_empty'); } $filter = $result['filter']; $urlStr = '/brand/' . $_REQUEST['id']; $pages = ''; $pageShort = ''; if ($result['count'] > 0) { $pages = Common::instance()->get_page_list($result['count'], $filter['p'], $filter['page_size'], $urlStr); $pageShort = Common::instance()->get_page_short($result['count'], $filter['p'], $filter['page_size'], $urlStr); } $viewData = array(); $viewData['brandInfo'] = $brandInfo; $viewData['list'] = $result['list']; $viewData['count'] = $result['count']; $viewData['filter'] = $result['filter']; $viewData['pages'] = $pages; $viewData['pageShort'] = $pageShort; $this->render('brand/detail', $viewData); }
public function displayMain() { global $smarty; $results = Brand::getEntity(); $smarty->assign(array('brands' => $results['entitys'])); return $smarty->fetch('brands.tpl'); }
public static function testget() { return function ($request, $response) { $brand = Brand::findById($request->id); echo $brand; }; }
public function startRecalculationAjax() { if (Status::isCalculationInProgress()) { return \BootstrapUI::buttonRemoteResponse()->text('Calculation is already in progress'); } return \BootstrapUI::buttonRemoteResponse()->disableButton()->text('Recalculation is in progress...')->after(function () { set_time_limit(0); \Status::calculationStarted(); \Status::setCalculationStatus('Recalculating brands'); \Brand::recalculate(); \Status::setCalculationStatus('Recalculating countries'); \Country::recalculate(); \Status::setCalculationStatus('Recalculating packages'); \Package::recalculate(); \Status::setCalculationStatus('Recalculating package versions'); \Package\Version::recalculate(); \Status::setCalculationStatus('Recalculating phone models'); \Phone\Model::recalculate(); \Status::setCalculationStatus('Recalculating product names'); \Product::recalculate(); \Status::setCalculationStatus('Recalculating providers'); \Provider::recalculate(); \Status::setCalculationStatus('Recalculating stack traces'); \Stack\Trace::recalculate(); \Status::setCalculationStatus('Recalculating OS versions'); \Version::recalculate(); \Status::calculationFinished('all'); }); }
/** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit($id) { // $product = Product::find($id); $type = ProductType::all(); $brand = Brand::all(); return View::make('product.edit')->withProduct($product)->withBrand($brand)->withType($type); }
public function run() { Yii::import($this->import); $data = CHtml::listData(Brand::model()->findAll(array('order' => 'title')), 'id', 'title'); $data[0] = ''; ksort($data); echo CJavaScript::jsonEncode($data); }
public function loadModel($id) { $model = Brand::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $category = $this->categories->findOrFail($id); if ($category) { $category->delete(); return \Redirect::to('admin/categories')->with('message', 'Category Deleted'); } return \Redirect::to('admin/categories')->with('message', 'Something went wrong, please try again'); }
static function find($searchId) { $brands_returned = Brand::getAll(); foreach ($brands_returned as $brand) { if ($searchId == $brand->getId()) { return $brand; } } }
/** * Get the product ID from database * @param string|int $brand * @param string $productName * @return int */ public static function getId($brand, $productName) { $brandId = is_numeric($brand) ? (int) $brand : \Brand::getId($brand); $product = static::fetchOne(array('brand_id' => $brandId, 'name' => $productName)); if ($product === false) { $product = static::create(array('brand_id' => $brandId, 'name' => $productName)); } return $product->id; }
/** * Get the Phone Model id from database * @param string|int $brand * @param string $phoneModel * @return int */ public static function getId($brand, $phoneModel) { $brandId = is_numeric($brand) ? (int) $brand : \Brand::getId($brand); $model = static::fetchOne(array('brand_id' => $brandId, 'name' => $phoneModel)); if ($model === false) { $model = static::create(array('brand_id' => $brandId, 'name' => $phoneModel)); } return $model->id; }
public function actionIndex() { $brand_id = isset($_GET['brand_id']) ? $_GET['brand_id'] : 0; $productCategoryOptions = ProductCategory::model()->byBrandOptions($brand_id); // 产品 $criteria = new CDbCriteria(); $criteria->compare('t.is_released', 1); $productarr = Product::model()->localized()->findAll($criteria); $brand = array(); if ($brand_id != 0) { $criteria = new CDbCriteria(); $criteria->compare('t.brand_id', $brand_id); $criteria->order = 'sort_order ASC'; $brand = Brand::model()->localized()->find($criteria); $productCategoryOptions = ProductCategory::model()->byBrandOptions($brand_id); // 产品 $criteria = new CDbCriteria(); $criteria->compare('t.brand_id', $brand_id); $productarr = Product::model()->localized()->findAll($criteria); } $products = array(); foreach ($productarr as $model) { $products[] = $model->attributes; } // 广告图 $criteria = new CDbCriteria(); $criteria->compare('t.banner_position_id', 1); $banner = Banner::model()->localized()->find($criteria); $brands = array(); $criteria = new CDbCriteria(); $criteria->select = 'brand_id,title'; $criteria->compare('t.is_released', 1); $brandsarr = Brand::model()->localized()->findAll($criteria); foreach ($brandsarr as $model) { $brands[$model->brand_id] = $model->title; } $series = array(); $criteria = new CDbCriteria(); $criteria->select = 'series_id,title'; $criteria->compare('t.is_released', 1); $seriesarr = ProductSeries::model()->localized()->findAll($criteria); foreach ($seriesarr as $model) { $series[$model->series_id] = $model->title; } $categorys = array(); $criteria = new CDbCriteria(); $criteria->select = 'category_id,name'; $criteria->compare('t.is_released', 1); $categorysarr = ProductCategory::model()->localized()->findAll($criteria); foreach ($categorysarr as $model) { $categorys[$model->category_id] = $model->name; } $this->layout = 'main'; $this->pageTitle = Yii::t('common', '产品中心') . SEPARATOR . Setting::getValueByCode('inside_title', true); $this->render('index', array('brand_id' => $brand_id, 'brand' => $brand, 'products' => $products, 'brands' => $brands, 'series' => $series, 'categorys' => $categorys, 'productCategoryOptions' => $productCategoryOptions, 'banner' => $banner)); }
/** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit($id) { $product = Product::find($id); $departments = Department::all()->lists('name', 'id'); $categories = Category::all()->lists('name', 'id'); $brands = Brand::all()->lists('name', 'id'); $sizes = Size::all()->lists('name', 'id'); $colors = Color::all()->lists('name', 'id'); return View::make('admin::products.edit', compact('product', 'departments', 'categories', 'brands', 'sizes', 'colors')); }
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)); }
public function addProducts($brandid, $catid) { Larasset::start('header')->css('magicsuggest'); Larasset::start('footer')->js('magicsuggest'); $productcat = Productcategory::find($catid)->toArray(); $brand = Brand::find($productcat['brand_id'])->toArray(); $data['productcat'] = $productcat; $data['brand'] = $brand; return View::make('admin.create.addproduct', $data); }