本文整理汇总了PHP中app\Image::insert方法的典型用法代码示例。如果您正苦于以下问题:PHP Image::insert方法的具体用法?PHP Image::insert怎么用?PHP Image::insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Image
的用法示例。
在下文中一共展示了Image::insert方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save
/**
* Save product to database
*/
public function save()
{
$data = ['item_id' => $this->item_id, 'shop_id' => $this->shop_id] + $this->data;
if (!App\Product::where('shop_id', $this->shop_id)->where('item_id', $this->item_id)->update($this->data) && !App\Product::insert($data)) {
return false;
}
$this->id = App\Product::where('shop_id', $this->shop_id)->where('item_id', $this->item_id)->first()->id;
if (!$this->id) {
return false;
}
foreach ($this->images as $image) {
if (!App\Image::where('url', $image['url'])->update($image) && !App\Image::insert($image + ['product_id' => $this->id])) {
return false;
}
}
/*if( isset( $this->params ) )
{
foreach( $this->params as $param )
{
if( !App\Param::where( 'param', $param['param'] )->update( $param ) &&
!App\Param::insert( $param + [ 'product_id' => $this->id ] ) )
return false;
}
}*/
return true;
}
示例2: uploadProducts
public function uploadProducts($xml)
{
/**
* Formating XML structure of sent file
*/
$doc = new \DOMDocument();
$doc->loadXML($xml);
$elements = $doc->getElementsByTagName('SHOPITEM');
$data = array('IMGURLS' => [], 'SHOP_ID' => 1);
$item_groups = array();
/**
* Getting a data of every shop item in feed
*/
foreach ($elements as $node) {
foreach ($node->childNodes as $child) {
if (trim($child->nodeValue) != '') {
switch ($child->nodeName) {
case 'ITEM_ID':
case 'ITEMGROUP_ID':
case 'PRODUCTNAME':
case 'PRODUCT':
case 'DESCRIPTION':
case 'MANUFACTURER':
case 'URL':
case 'PRICE_VAT':
case 'GIFT':
$data[$child->nodeName] = $child->nodeValue;
break;
/*case 'PARAM':
$main = $child->getElementsByTagName( 'PARAM_NAME' )->item(0)->nodeValue;
$value = $child->getElementsByTagName( 'VAL' )->item(0)->nodeValue;
$data[ $child->nodeName ][] = [ 'param' => $main, 'value' => $value ];
break;*/
/*case 'PARAM':
$main = $child->getElementsByTagName( 'PARAM_NAME' )->item(0)->nodeValue;
$value = $child->getElementsByTagName( 'VAL' )->item(0)->nodeValue;
$data[ $child->nodeName ][] = [ 'param' => $main, 'value' => $value ];
break;*/
case 'IMGURL':
case 'IMGURL_ALTERNATIVE':
if (count($data['IMGURLS'] < 2)) {
$url = $child->childNodes->item(0)->nodeValue;
$m = $child->nodeName == 'IMGURL' ? true : false;
$data['IMGURLS'][] = ['url' => $url, 'main' => $m];
}
break;
case 'CATEGORYTEXT':
$data['CATEGORYTEXT'] = Section::parse(str_replace('Heureka.cz | ', '', $child->nodeValue));
break;
default:
continue;
}
}
}
/**
* IF#1
* Checks if the product has variations
*/
if (isset($data['ITEMGROUP_ID'])) {
/**
* IF#2
* Checks if it is the very first occurence of item group
*/
if (isset($item_groups[$data['ITEMGROUP_ID']])) {
/**
* IF#3
* If there is already one product of this item group in DB
* scripts increments number of variations it has by one.
*/
if (!$item_groups[$data['ITEMGROUP_ID']]['id'] === false) {
$id = App\Product::where('shop_id', $data['SHOP_ID'])->where('item_id', $item_groups[$data['ITEMGROUP_ID']]['id'])->value('id');
App\Product::where('shop_id', $data['SHOP_ID'])->where('item_id', $item_groups[$data['ITEMGROUP_ID']]['id'])->increment('variations');
/**
* IF#4
* Saving new product picture to the DB.
*/
if (isset($data['IMGURLS']) && count($data['IMGURLS']) > 0) {
/**
* IF#5
* We don't want to have multiple rows with same url in our DB
*/
if (App\Image::select('id')->where('product_id', $id)->where('url', $data['IMGURLS'][0]['url'])->count() == 0) {
App\Image::insert(['product_id' => $id, 'url' => $data['IMGURLS'][0]['url'], 'main' => 0]);
}
}
/**
* Since there is not a single product of this
* item group in db, we have to create one.
*/
} else {
/**
* IF#6
* If there is not a single avaible image, we increment group variations.
*/
if (count($data['IMGURLS']) < 1) {
$item_groups[$data['ITEMGROUP_ID']]['count']++;
} else {
$data['VARIATIONS'] = $item_groups[$data['ITEMGROUP_ID']]['count'];
$item_groups[$data['ITEMGROUP_ID']]['id'] = $data['ITEM_ID'];
$this->saveProduct($data);
//.........这里部分代码省略.........