public function run()
 {
     if (empty($this->model) || empty($this->type)) {
         return;
     }
     // Определяем тип товара для поиска товаров данного типа
     $productType = ProductType::model()->published()->findByAlias($this->type);
     if (!$productType) {
         return;
     }
     // Определяем товар данного типа с таким же названием, как заданный
     $relatedProduct = Stone::model()->published()->type($productType->id)->with('series')->findByAttributes(array('title' => $this->model->title));
     // Получаем список рандомных товаров данного типа, похожих на заданный по цвету и виду камня
     $criteria = new CDbCriteria();
     $criteria->compare('t.series_id', $this->model->series_id);
     $criteria->compare('t.color_id', $this->model->color_id);
     $notSearchIds = array($this->model->id);
     if ($relatedProduct !== null) {
         $notSearchIds[] = $relatedProduct->id;
     }
     $criteria->addNotInCondition('t.id', $notSearchIds);
     $criteria->order = 'RAND()';
     $criteria->limit = 7;
     $models = Stone::model()->published()->type($productType->id)->with('series')->findAll($criteria);
     if ($relatedProduct !== null) {
         $models = array($relatedProduct) + $models;
     }
     $this->render($this->view, array('productType' => $productType, 'models' => $models, 'model' => $this->model));
 }
 public function loadModel($id)
 {
     if (($model = Stone::model()->findByPk($id)) === null) {
         throw new CHttpException(404, 'Страница не найдена');
     }
     return $model;
 }
Beispiel #3
0
 public function stone()
 {
     $stone_id = $this->stone;
     if (empty($stone_id)) {
         $stone = Stone::create();
         $stone_id = $stone->id;
         $this->edit('stone', $stone_id);
         $this->stone = $stone_id;
         return $stone;
     }
     return new Stone($this->stone);
 }
 protected function beforeAction($action)
 {
     $actions = array('index', 'create');
     if (in_array($action->id, $actions)) {
         $this->item_id = (int) Yii::app()->getRequest()->getParam('item_id');
         if (!$this->item_id) {
             throw new CHttpException(400, 'Не установлен ID товара');
         }
         if (($this->item = Stone::model()->findByPk($this->item_id)) === null) {
             throw new CHttpException(404, 'Товар не найден');
         }
     }
     return parent::beforeAction($action);
 }
 public function run()
 {
     if (empty($this->model)) {
         return;
     }
     if (empty($this->model->relatedStones)) {
         // Получаем список рандомных товаров данного типа, похожих на заданный по цвету и виду камня
         $criteria = new CDbCriteria();
         $criteria->compare('t.series_id', $this->model->series_id);
         $criteria->compare('t.color_id', $this->model->color_id);
         $criteria->addCondition('t.id <> :id');
         $criteria->params[':id'] = $this->model->id;
         $criteria->order = 'RAND()';
         if ($this->limit > 0) {
             $criteria->limit = (int) $this->limit;
         } elseif ($this->limit == '') {
             $criteria->limit = 4;
         }
         $models = Stone::model()->published()->with('series')->type($this->model->type_id)->findAll($criteria);
     } else {
         $models = $this->model->relatedStones(array('scopes' => 'published'));
     }
     $this->render($this->view, array('models' => $models, 'model' => $this->model));
 }
Beispiel #6
0
    </div> 

    <div class="row-fluid control-group <?php 
echo $model->hasErrors('relatedStonesArray') ? 'error' : '';
?>
">       
        <?php 
echo $form->labelEx($model, 'relatedStonesArray');
?>
        <?php 
$selected = CHtml::listData($model->relatedStones, 'id', 'title');
$options = array();
foreach ($selected as $key => $value) {
    $options[$key] = array('selected' => true);
}
$this->widget('bootstrap.widgets.TbSelect2', array('asDropDownList' => true, 'model' => $model, 'attribute' => 'relatedStonesArray', 'data' => CHtml::listData(Stone::model()->findAll(array('order' => 't.title ASC')), 'id', 'title'), 'htmlOptions' => array('multiple' => 'multiple', 'options' => $options), 'options' => array('minimumInputLength' => 3, 'placeholder' => 'Введите список камней', 'width' => '100%', 'allowClear' => true)));
?>
    </div> 

    <?php 
$collapse = $this->beginWidget('bootstrap.widgets.TbCollapse');
?>
    <div class="accordion-group">
        <div class="accordion-heading">
            <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseOne">
                Данные для SEO
            </a>
        </div>
        <div id="collapseOne" class="accordion-body collapse">
            <div class="accordion-inner">
                <div class="row-fluid control-group <?php 
Beispiel #7
0
 public function customizeOrder($info)
 {
     $prd_info = array();
     if (isset($info['images'])) {
         $images = $info['images'];
         for ($i = 0; $i < count($images); $i++) {
             if ($i > 2) {
                 break;
             }
             // maybe we should make image here
             $prd_info['image' . ($i + 1)] = $images[$i];
             $prd_info['image' . ($i + 1) . '_400'] = $images[$i];
             $prd_info['image' . ($i + 1) . '_thumb'] = $images[$i];
         }
     }
     $product = Product::addCustomized($prd_info);
     $stone = Stone::add(array('weight' => $info['stone']));
     $order = Order::addCustomized(array('order_no' => Order::makeOrderSn(), 'customer' => $this->id, 'product' => $product->id, 'material' => $info['material'], 'stone' => $stone->id, 'size' => $info['size'], 'carve_text' => $info['carve_text'], 'customer_remark' => $info['remark']));
     if (isset($info['images'])) {
         CustomizeImage::add(array('order' => $order->id, 'images' => $info['images']));
     }
     $order->submit();
 }
 protected function refreshRelatedStones()
 {
     $relatedStones = $this->relatedStonesArray;
     ProjectStoneRelation::model()->deleteAllByAttributes(array('entity_id' => $this->id, 'entity_name' => 'Project'));
     if (is_array($relatedStones)) {
         foreach ($relatedStones as $id) {
             if (Stone::model()->exists('t.id = :id', array(':id' => $id))) {
                 $relation = new ProjectStoneRelation();
                 $relation->entity_id = $this->id;
                 $relation->stone_id = $id;
                 $relation->save();
             }
         }
     }
 }
 /**
  * Список серий:
  **/
 public function getItemsList()
 {
     return CHtml::listData(Stone::model()->findAll(), 'id', 'title');
 }
 public function actionIndex()
 {
     exit;
     // prepare logger to dump logs every time one comes in
     Yii::getLogger()->autoFlush = 1;
     Yii::getLogger()->autoDump = true;
     function getNewFileName($fileName)
     {
         $ext = pathinfo($fileName, PATHINFO_EXTENSION);
         $oldName = pathinfo($fileName, PATHINFO_FILENAME);
         return md5(uniqid($fileName)) . '.' . $ext;
     }
     function getmicrotime()
     {
         list($usec, $sec) = explode(" ", microtime());
         return (double) $usec + (double) $sec;
     }
     function logParse($message)
     {
         Yii::log($message, CLogger::LEVEL_TRACE, 'parse');
         Yii::getLogger()->flush(true);
     }
     logParse("Begin");
     $begin = getmicrotime();
     $regexpArray = array('p' => '~^p\\..+~iU', 'pl' => '~^pl\\..+~iU', 'plx' => '~^plx\\..+~iU');
     $titlesArray = array('p' => '', 'pl' => 'Плитка из камня', 'plx' => 'Плитка из камня с подсветкой');
     $parsePath = Yii::app()->uploadManager->getBasePath() . DIRECTORY_SEPARATOR . $this->module->uploadPath . DIRECTORY_SEPARATOR . 'parse_tile';
     $seriesList = glob($parsePath . DIRECTORY_SEPARATOR . '*', GLOB_BRACE | GLOB_ONLYDIR);
     $stones = array();
     $imagesFiles = array();
     // Обработка серий
     foreach ($seriesList as $skey => $seriesPath) {
         //if($skey > 1) break;
         $seriesAlias = basename($seriesPath);
         if ($seriesAlias == '.' || $seriesAlias == '..') {
             continue;
         }
         $series = Series::model()->findByAlias($seriesAlias);
         if (is_null($series)) {
             logParse("Серия " . $seriesAlias . " не найдена");
             echo "Серия " . $seriesAlias . " не найдена<br />";
             exit;
         }
         echo '<h1>' . $series->title . '</h1>';
         logParse("Series " . $series->title);
         $stonesList = glob($seriesPath . DIRECTORY_SEPARATOR . '*', GLOB_BRACE | GLOB_ONLYDIR);
         $stonesCounter = 0;
         $stoneImagesCounter = 0;
         $sort = 0;
         foreach ($stonesList as $stonePath) {
             $stoneTitle = basename($stonePath);
             if ($stoneTitle == '.' || $stoneTitle == '..') {
                 continue;
             }
             //echo '<h3>' . $stoneTitle . '</h3>';
             $stonesCounter++;
             $sort += 100;
             $stone = new Stone();
             $stone->type_id = 2;
             $stone->series_id = $series->id;
             $stone->title = $stoneTitle;
             $stone->metatitle = $stone->keywords = $stone->description = $stone->title;
             // Генерация алиаса
             $alias = \yupe\helpers\YText::translit($stone->title) . '-tile';
             if ($stone->findByAlias($alias) !== null) {
                 $alias = $alias . '-' . mt_rand(10000, 99999);
             }
             $stone->alias = $alias;
             $stone->sort = $sort;
             $imagesList = array();
             foreach ($regexpArray as $key => $regexp) {
                 foreach (CFileHelper::findFiles($stonePath) as $file) {
                     //echo $file . '<br />';
                     if (preg_match($regexp, basename($file))) {
                         $imagesList[$key] = $file;
                     }
                 }
             }
             $stoneImages = array();
             foreach ($imagesList as $key => $item) {
                 $itemName = basename($item);
                 $newName = getNewFileName($item);
                 $imagesFiles[] = array('fullPath' => $item, 'name' => $itemName, 'newName' => $newName);
                 if (preg_match($regexpArray['p'], $itemName)) {
                     $stone->image = $newName;
                     //echo $itemName . '<br />';
                 } else {
                     $image = new StoneImage();
                     $image->title = $titlesArray[$key];
                     $image->image = $newName;
                     $stoneImages[] = $image;
                 }
                 //echo $itemName . '<br />';
                 $stoneImagesCounter++;
             }
             $stone->images = $stoneImages;
             $stones[] = $stone;
         }
         echo 'Камней: ' . $stonesCounter . '<br />';
         echo 'Изображений: ' . $stoneImagesCounter . '<br />';
         echo '<hr>';
     }
     // Сохраняем камни и изображения в БД
     foreach ($stones as $stone) {
         logParse($stone->title);
         if ($stone->save(false)) {
             $imagesCounter = 0;
             foreach ($stone->images as $image) {
                 $imagesCounter += 100;
                 $image->item_id = $stone->id;
                 $image->sort = $imagesCounter;
                 if (!$image->save(false)) {
                     logParse($image->image . ' - error');
                     echo $image->image . ' - error<br />';
                 }
             }
             logParse('success');
         } else {
             logParse('error');
             //echo $stone->title . ' - error<br />';
             //var_dump($stone->getErrors());
         }
     }
     // Копируем изображения
     foreach ($imagesFiles as $image) {
         copy($image['fullPath'], Yii::app()->uploadManager->getBasePath() . DIRECTORY_SEPARATOR . $this->module->getStonesUploadPath() . DIRECTORY_SEPARATOR . $image['newName']);
     }
     $end = getmicrotime();
     $time = $end - $begin;
     echo "Время выполнения скрипта: " . $time . "с.";
     logParse("Время выполнения скрипта: " . $time . "с.");
     echo '<hr>';
 }
}
spl_autoload_register();
spl_autoload_register('Philosopher\\classLoader');
spl_autoload_register('Philosopher\\interfaceLoader');
//------------------------------------------------------------------------------
try {
    ob_start();
    session_start();
    if (isset($_GET['reset'])) {
        unset($_SESSION['stone']);
    }
    // test
    if (isset($_SESSION['stone'])) {
        $stone = $_SESSION['stone'];
    } else {
        $stone = new Stone();
        $_SESSION['stone'] = $stone;
        $stone->registerComponent(new RenderHTML5());
        $stone->registerComponent(new DatabaseConnection());
        $stone->registerComponent(new Auth());
        $stone->registerComponent(new AuthLocal());
        $stone->registerComponent(new Session());
        $stone->registerComponent(new Wizard());
        $stone->registerComponent(new Page());
        //    $stone->registerComponent(new Form()); // Form is not to be a component class ...
        $stone->registerComponent(new Address());
        $stone->registerComponent(new KvK());
        $stone->registerComponent(new VIES());
        $stone->registerComponent(new Organisation());
        $stone->registerComponent(new Person());
        $stone->registerComponent(new Customer());
 public function actionAjaxstones($term)
 {
     if (Yii::app()->request->isAjaxRequest) {
         $criteria = new CDbCriteria();
         $criteria->select = 't.id, t.title';
         $criteria->condition = "t.title LIKE '{$term}%' " . "AND t.id IN (SELECT `stone_id` FROM " . InteriorStoneRelation::model()->tableName() . " WHERE `entity_name` = 'interior')";
         $criteria->group = 't.title';
         $criteria->order = 't.title ASC';
         $items = array();
         foreach (Stone::model()->findAll($criteria) as $item) {
             $items[] = array('id' => $item->id, 'label' => $item->title, 'value' => $item->title);
         }
         echo CJSON::encode($items);
         Yii::app()->end();
     }
 }
 public function actionIndex()
 {
     // prepare logger to dump logs every time one comes in
     Yii::getLogger()->autoFlush = 1;
     Yii::getLogger()->autoDump = true;
     function getNewFileName($fileName)
     {
         $ext = pathinfo($fileName, PATHINFO_EXTENSION);
         $oldName = pathinfo($fileName, PATHINFO_FILENAME);
         return md5(uniqid($fileName)) . '.' . $ext;
     }
     function getmicrotime()
     {
         list($usec, $sec) = explode(" ", microtime());
         return (double) $usec + (double) $sec;
     }
     function logParse($message)
     {
         Yii::log($message, CLogger::LEVEL_TRACE, 'parse');
         Yii::getLogger()->flush(true);
     }
     logParse("Begin");
     $begin = getmicrotime();
     /*
             $regexpArray = array(
        'mm'    => '~^mm[^x]*\..+~iU',
        'fr1'   => '~^fr[\d]{0,2}[^x]*\..+~iU',
        'sl'    => '~^sl[\d]{0,2}[^x]*\..+~iU',
        'b1'    => '~^b1[^x]*\..+~iU',
        'b2'    => '~^b2[^x]*\..+~iU',
        'frx'   => '~^fr[\d]{0,2}x.*\..+~iU',
        'slx'   => '~^slx.*\..+~iU',
        'b1x'   => '~^b1x.*\..+~iU',
        'b2x'   => '~^b2x.*\..+~iU',
             );
     *
     */
     $regexpArray = array('mm' => '~^mm\\..+~iU', 'fr' => '~^fr\\..+~iU', 'fr2' => '~^fr2\\..+~iU', 'sl' => '~^sl\\..+~iU', 'b1' => '~^b1\\..+~iU', 'b2' => '~^b2\\..+~iU', 'frx' => '~^frx.*\\..+~iU', 'slx' => '~^slx.*\\..+~iU', 'b1x' => '~^b1x.*\\..+~iU', 'b2x' => '~^b2x.*\\..+~iU');
     $titlesArray = array('mm' => '', 'fr' => 'Фрагмент', 'fr2' => 'Фрагмент 2', 'sl' => 'Слеб', 'b1' => 'Bookmatch 1', 'b2' => 'Bookmatch 2', 'frx' => 'Фрагмент с подсветкой', 'slx' => 'Слеб с подсветкой', 'b1x' => 'Bookmatch 1 с подсветкой', 'b2x' => 'Bookmatch 2 с подсветкой');
     $parsePath = Yii::app()->uploadManager->getBasePath() . DIRECTORY_SEPARATOR . $this->module->geParsePath();
     $seriesList = glob($parsePath . DIRECTORY_SEPARATOR . '*', GLOB_BRACE | GLOB_ONLYDIR);
     $stones = array();
     $imagesFiles = array();
     // Обработка серий
     foreach ($seriesList as $seriesPath) {
         $seriesAlias = basename($seriesPath);
         if ($seriesAlias == '.' || $seriesAlias == '..') {
             continue;
         }
         $series = Series::model()->findByAlias($seriesAlias);
         if (is_null($series)) {
             logParse("Серия " . $seriesAlias . " не найдена");
             echo "Серия " . $seriesAlias . " не найдена<br />";
             exit;
         }
         echo '<h1>' . $series->title . '</h1>';
         logParse("Series " . $series->title);
         $stonesList = glob($seriesPath . DIRECTORY_SEPARATOR . '*', GLOB_BRACE | GLOB_ONLYDIR);
         $stonesCounter = 0;
         $stoneImagesCounter = 0;
         $sort = 0;
         foreach ($stonesList as $stonePath) {
             $stoneTitle = basename($stonePath);
             if ($stoneTitle == '.' || $stoneTitle == '..') {
                 continue;
             }
             //echo '<h3>' . $stoneTitle . '</h3>';
             $stonesCounter++;
             $sort += 100;
             $stone = new Stone();
             $stone->series_id = $series->id;
             $stone->title = $stoneTitle;
             $stone->metatitle = $stone->keywords = $stone->description = $stone->title;
             $stone->generateAlias();
             $stone->sort = $sort;
             $imagesList = array();
             foreach ($regexpArray as $key => $regexp) {
                 foreach (CFileHelper::findFiles($stonePath) as $file) {
                     if (preg_match($regexp, basename($file))) {
                         $imagesList[$key] = $file;
                     }
                 }
             }
             $stoneImages = array();
             foreach ($imagesList as $key => $item) {
                 $itemName = basename($item);
                 $newName = getNewFileName($item);
                 $imagesFiles[] = array('fullPath' => $item, 'name' => $itemName, 'newName' => $newName);
                 if (preg_match($regexpArray['mm'], $itemName)) {
                     $stone->image = $newName;
                     //echo $itemName . '<br />';
                 } else {
                     $image = new StoneImage();
                     $image->title = $titlesArray[$key];
                     $image->image = $newName;
                     $stoneImages[] = $image;
                 }
                 //echo $itemName . '<br />';
                 $stoneImagesCounter++;
             }
             $stone->images = $stoneImages;
             $stones[] = $stone;
         }
         echo 'Камней: ' . $stonesCounter . '<br />';
         echo 'Изображений: ' . $stoneImagesCounter . '<br />';
         echo '<hr>';
     }
     // Сохраняем камни и изображения в БД
     foreach ($stones as $stone) {
         logParse($stone->title);
         if ($stone->save(false)) {
             $imagesCounter = 0;
             foreach ($stone->images as $image) {
                 $imagesCounter += 100;
                 $image->item_id = $stone->id;
                 $image->sort = $imagesCounter;
                 if (!$image->save(false)) {
                     logParse($image->image . ' - error');
                     echo $image->image . ' - error<br />';
                 }
             }
             logParse('success');
         } else {
             logParse('error');
             //echo $stone->title . ' - error<br />';
             //var_dump($stone->getErrors());
         }
     }
     // Копируем изображения
     foreach ($imagesFiles as $image) {
         copy($image['fullPath'], Yii::app()->uploadManager->getBasePath() . DIRECTORY_SEPARATOR . $this->module->getStonesUploadPath() . DIRECTORY_SEPARATOR . $image['newName']);
     }
     $end = getmicrotime();
     $time = $end - $begin;
     echo "Время выполнения скрипта: " . $time . "с.";
     logParse("Время выполнения скрипта: " . $time . "с.");
     echo '<hr>';
 }
 public function actionRemove_from_favorite($id)
 {
     $id = (int) $_GET['id'];
     $model = Stone::model()->findByPk($id);
     if ($model !== null) {
         Yii::app()->favorite->remove($model->getId());
     }
     if (Yii::app()->getRequest()->getIsAjaxRequest()) {
         Yii::app()->ajax->success();
     } else {
         $this->redirect($model->url);
     }
 }
 protected function _buildColorCountrySeoArray()
 {
     $stones = Stone::model()->resetScope()->findAll(array('order' => 't.sort ASC'));
     $seoArray = array();
     foreach ($stones as $stone) {
         if ($stone->color_id == null || $stone->country_id == null) {
             continue;
         }
         $key = $stone->type_id . '_' . $stone->series_id . '_' . $stone->color_id . '_' . $stone->country_id;
         if (!in_array($key, $seoArray)) {
             $seoArray[] = $key;
         }
     }
     return $seoArray;
 }
 public function actionAjaxstones($term)
 {
     if (Yii::app()->request->isAjaxRequest) {
         $criteria = new CDbCriteria();
         $criteria->select = 't.id, t.title';
         $criteria->condition = "t.title LIKE '{$term}%'";
         $criteria->group = 't.title';
         $criteria->order = 't.title ASC';
         $items = array();
         foreach (Stone::model()->findAll($criteria) as $item) {
             $items[] = array('id' => $item->id, 'label' => $item->title, 'value' => $item->title);
         }
         echo CJSON::encode($items);
         Yii::app()->end();
     }
 }