当前位置: 首页>>代码示例>>PHP>>正文


PHP Helper::trimPlain方法代码示例

本文整理汇总了PHP中app\components\Helper::trimPlain方法的典型用法代码示例。如果您正苦于以下问题:PHP Helper::trimPlain方法的具体用法?PHP Helper::trimPlain怎么用?PHP Helper::trimPlain使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\components\Helper的用法示例。


在下文中一共展示了Helper::trimPlain方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: up

 public function up()
 {
     mb_internal_encoding(Yii::$app->getModule('core')->internalEncoding);
     $data = (include __DIR__ . DIRECTORY_SEPARATOR . 'demo-data.php');
     $productObject = Object::getForClass(Product::className());
     /** @var PropertyHandler $handler */
     $handler = PropertyHandler::findOne(['handler_class_name' => 'app\\properties\\handlers\\text\\TextProperty']);
     if (!is_null($handler)) {
         $this->textHandlerId = $handler->id;
     }
     $handler = PropertyHandler::findOne(['handler_class_name' => 'app\\properties\\handlers\\select\\SelectProperty']);
     if (!is_null($handler)) {
         $this->selectHandlerId = $handler->id;
     }
     $this->insert(PropertyGroup::tableName(), ['object_id' => $productObject->id, 'name' => 'Общая группа свойств']);
     $commonGroupId = $this->db->lastInsertID;
     $this->insert(Property::tableName(), ['property_group_id' => $commonGroupId, 'name' => 'Производитель', 'key' => 'vendor', 'property_handler_id' => $this->selectHandlerId, 'handler_additional_params' => '{}', 'has_static_values' => 1, 'has_slugs_in_values' => 1]);
     $this->properties['vendor'] = $this->db->lastInsertID;
     $staticProperties = ['Тип крепления бура', 'Макс. энергия удара', 'Количество скоростей работы', 'Питание', 'Тип процессора', 'Тип памяти', 'Частота памяти: 1600 МГц', 'Количество слотов памяти', 'Максимальный размер памяти', 'Размер экрана: 15.6 "', 'Тип экрана', 'Тип видеоадаптера'];
     foreach ($data as $category) {
         $this->insert(Category::tableName(), ['category_group_id' => 1, 'parent_id' => 1, 'name' => $category['name'], 'h1' => $category['name'], 'title' => $category['name'] . ' с доставкой в любой город России и СНГ', 'breadcrumbs_label' => $category['name'], 'slug' => Helper::createSlug($category['name']), 'announce' => $category['content'], 'content' => $category['content']]);
         $categoryId = $this->db->lastInsertID;
         $this->insert(PropertyGroup::tableName(), ['object_id' => $productObject->id, 'name' => $category['name']]);
         $groupId = $this->db->lastInsertID;
         foreach ($category['products'] as $product) {
             // product
             $slug = Helper::createSlug($product['name']);
             if (isset($this->products[$slug])) {
                 $slug = mb_substr($slug, 0, 66) . '-' . uniqid();
             }
             $this->insert(Product::tableName(), ['parent_id' => 0, 'measure_id' => 1, 'currency_id' => 1, 'sku' => $product['id'], 'main_category_id' => $categoryId, 'name' => $product['name'], 'title' => $product['name'], 'breadcrumbs_label' => $product['name'], 'h1' => $product['name'], 'slug' => $slug, 'announce' => Helper::trimPlain($product['description']), 'content' => $product['description'], 'price' => $product['prices']['min'], 'old_price' => $product['prices']['max']]);
             $productId = $this->db->lastInsertID;
             $this->products[$slug] = $productId;
             // categories
             $this->batchInsert('{{%product_category}}', ['category_id', 'object_model_id'], [[1, $productId], [$categoryId, $productId]]);
             // property groups
             $this->batchInsert(ObjectPropertyGroup::tableName(), ['object_id', 'object_model_id', 'property_group_id'], [[$productObject->id, $productId, $commonGroupId], [$productObject->id, $productId, $groupId]]);
             // properties
             if (isset($product['vendor'])) {
                 $this->saveStatic($productId, 'vendor', $product['vendor']);
             }
             foreach ($product['details']['modelDetails'] as $group) {
                 foreach ($group['params'] as $property) {
                     $property['name'] = trim($property['name'], '/ ');
                     if (in_array($property['name'], $staticProperties)) {
                         $key = $this->getKey($property['name']);
                         if (!isset($this->properties[$key])) {
                             $this->insert(Property::tableName(), ['property_group_id' => $groupId, 'name' => $property['name'], 'key' => $key, 'property_handler_id' => $this->selectHandlerId, 'handler_additional_params' => '{}', 'has_static_values' => 1, 'has_slugs_in_values' => 1]);
                             $this->properties[$key] = $this->db->lastInsertID;
                         }
                         $this->saveStatic($productId, $this->getKey($property['name']), str_replace($property['name'] . ': ', '', $property['value']));
                     } else {
                         $this->saveEav($productId, $groupId, $property['name'], str_replace($property['name'] . ': ', '', $property['value']));
                     }
                 }
             }
             // images
             $prodPhotos = [];
             if (isset($product['photos'])) {
                 foreach ($product['photos'] as $photo) {
                     $prodPhotos[] = [$productObject->id, $productId, $photo['name'], $product['name'], $product['name']];
                 }
             }
             if (isset($product['mainPhoto']['name'])) {
                 $prodPhotos[] = [$productObject->id, $productId, $product['mainPhoto']['name'], $product['name'], $product['name']];
             }
             if (count($prodPhotos) > 0) {
                 $this->batchInsert(Image::tableName(), ['object_id', 'object_model_id', 'filename', 'image_alt', 'image_title'], $prodPhotos);
             }
         }
     }
     srand();
     $cdnNumber = rand(1, 2);
     $imgUrl = "http://static-{$cdnNumber}.dotplant.ru/demo-photos.zip";
     $imagesPath = Yii::getAlias('@webroot/files/');
     $imgsFile = $imagesPath . DIRECTORY_SEPARATOR . 'imgs.zip';
     if (file_exists($imgsFile) === false) {
         $fp = fopen($imgsFile, 'w+');
         $ch = curl_init($imgUrl);
         curl_setopt($ch, CURLOPT_TIMEOUT, 600);
         curl_setopt($ch, CURLOPT_FILE, $fp);
         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
         curl_exec($ch);
         curl_close($ch);
         fclose($fp);
     }
     if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
         echo "\n\nWow! You are running windows! Please unzip {$imgsFile} to {$imagesPath} \n\n";
     } else {
         passthru('/usr/bin/env unzip -n "' . $imgsFile . '" -d "' . $imagesPath . '"');
     }
 }
开发者ID:tqsq2005,项目名称:dotplant2,代码行数:92,代码来源:m150605_094805_demo_data.php


注:本文中的app\components\Helper::trimPlain方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。