예제 #1
0
 public function actionElement($param)
 {
     if (SiteModuleSettings::model()->find('site_module_id = 11 AND `status`=0')) {
         throw new CHttpException(404, 'The page can not be found.');
     }
     $paramArr = explode("/", $param);
     $paramArr = array_pop($paramArr);
     $paramArr = strtolower($paramArr);
     $root = PhotoRubrics::getRoot(new PhotoRubrics());
     $menu_top = array();
     //2
     $root = PhotoRubrics::model()->find('url LIKE "' . $paramArr . '"');
     $param_model = $root->descendants(1, 1)->findAll($root->id);
     //Титл и SEO
     $this->setSEO(Yii::app()->request->requestUri, 'Фотогалерея', $root->level > 1 ? $root : null);
     foreach ($param_model as $data) {
         $menu_top[$data->id]['name'] = $data->name;
         $menu_top[$data->id]['url'] = $data->url;
         $menu_top[$data->id]['image'] = $data->id . "." . $data->image;
     }
     $page = array();
     foreach ($root->ancestors()->findAll() as $data) {
         if ($data->level == 1) {
             continue;
         }
         $page[] = $data->name;
     }
     $page[] = $root->name;
     $model["title"] = $root->name;
     //implode(' / ', $page);
     $param = $root;
     $model['catalogs'] = array();
     $model['elements'] = array();
     $category = PhotoRubrics::model()->findByPk($param->id);
     $tmp_model = $category->descendants(1, 1)->findAll();
     if ($tmp_model = $category->descendants(1, 1)->findAll()) {
         //3 Категорий нет  - получаю картинки в раздела
         //$model['catalogs'] = $tmp_model;
     } else {
         //3 Категорий нет  - получаю картинки в раздела
         $model['elements'] = PhotoElements::model()->findAll('parent_id=' . $param->id . ' AND `status`=1');
     }
     //ФОТОГАЛЕРЕЯ
     //$this->title_page = 'ФОТОГАЛЕРЕЯ'.'<span>'.$page.'</span>';
     $this->render('index', array('model' => $model, 'param' => $param, 'menu_top' => $menu_top));
 }
    /**  Для виджета в редакторе */
    public function actionAjaxalbom()
    {
        if (isset($_POST)) {
            $result = '
            <div id="photogaleryModal" class="modal" tabindex="-1" role="dialog" aria-labelledby="photogaleryModalLabel" aria-hidden="true">
              <div class="modal-header">
                <a href="#" onclick="$(\'#photogaleryModal\').remove();" class="close">×</a>
                <h3 id="myModalLabel">Фотогалерея</h3>
              </div>
              <div class="modal-body">
            ';
            $result .= '<table class="content_table hover_table" cellspacing="0">';
            $result .= '
            <thead>
            <tr>
                <th>Название</th><th>Действие</th>
            </tr>
            </thead>
            ';
            $result .= '<tbody>';
            foreach (PhotoRubrics::model()->findAll('status=1 AND id in (SELECT parent_id FROM {{photo_elements}} WHERE status = 1)') as $data) {
                $result .= '<tr>';
                $result .= '
                <td>
                    <b>' . $data->name . ':</b></br>
                ';
                $i = 0;
                foreach (PhotoElements::model()->findAll('parent_id=' . $data->id) as $dataElements) {
                    ++$i;
                    if ($i > 5) {
                        continue;
                    }
                    $result .= '
                    <img style="max-width:70px;" border="0/" src="/../uploads/filestorage/photo/elements/small-' . $dataElements->id . '.' . $dataElements->image . '">
                    ';
                }
                $result .= '
                </td>
                <td>
                    <a href="#" data-id="' . $data->id . '" data-class="' . $_POST['request'] . '"  class="addMyPhotogalery">Вставить</a>
                </td>
                ';
                $result .= '</tr>';
            }
            $result .= '</tbody>';
            $result .= '</table>';
            $result .= '
              </div>
            </div>
            ';
            //Скрипт обработки нажатия 'Вставить'
            $result .= '
				<script>
                    $(document).on("click",".addMyPhotogalery",function(){
                        var html = "{myphotogalery id="+$(this).data("id")+"}";
                        var className = $(this).data("class");
                        //Вставка галереи
                        $(".redactor-editor").redactor({
                            focus: true
                        });
                        //var body = $(' . '+className).html()+html;
                        //$("."+className).redactor("insert.set", body);
                        $("."+className).redactor("insert.html", html);
                        $("#photogaleryModal").remove();
                        $(".redactor-editor").each(function(index, value){
                            $("#redactor-toolbar-"+(index+2)).remove();
                        });
                        return false;
                    });
				</script>
			';
            echo $result;
            //echo CJavaScript::jsonEncode($result);
        }
        Yii::app()->end();
    }
예제 #3
0
    } else {
        //подчиненная категория - вывожу со смещением относительно родительской
        $repeat_prefix = $data->level == 3 ? $data->level : $data->level + 1;
        $return = '<a href="/admin/photo/photo/index?PhotoElements[parent_id]=' . $data->id . '"><b>' . str_repeat('&nbsp&nbsp', $repeat_prefix) . $data->name . '</b></a>';
    }
    return $return;
}, 'filter' => ''), array('header' => 'url', 'name' => "url", 'type' => 'raw', 'value' => function ($data) {
    return $data->url;
    /*return '
                      <a href="'.SITE_NAME_FULL.'/'.$data->url.'" target="_blank">
                          '.$data->url.'
                      </a>
                  ';
    		*/
}, 'filter' => ''), array('header' => 'Альбомов', 'type' => 'raw', 'value' => function ($data) {
    $count = PhotoRubrics::getCountTree($data->left_key, $data->right_key);
    return '
                    <a href="/admin/photo/photorubrics/index?id=' . $data->id . '">
                        <b>' . $count . '</b>
                    </a>
                ';
}, 'filter' => ''), array('header' => 'Статус', 'name' => "status", 'type' => 'raw', 'value' => function ($data) {
    return '
                    <a href="#" class="on-off-product" data-id="' . $data->id . '" data-status="' . $data->status . '">
                        <div style="margin-left:20px; width: 13px; height: 13px; border-radius: 3px; background:' . ($data->status == 1 ? 'green' : 'red') . '"></div>
                    </a>
                ';
}, 'filter' => ''), array('class' => 'bootstrap.widgets.TbButtonColumn', 'template' => '{move_up}  {move_down}  {update}  {delete}', 'buttons' => array('move_up' => array('label' => '', 'visible' => '($row==0)?false:true', 'url' => '"/admin/photo/photorubrics/move?id=$data->id&move=1"', 'options' => array('class' => 'icon-arrow-up', 'data-original-title' => 'Переместить выше')), 'move_down' => array('label' => '', 'visible' => '(($row+1)==PhotoRubrics::model()->count("level=$data->level"))?false:true', 'url' => '"/admin/photo/photorubrics/move?id=$data->id&move=2"', 'options' => array('class' => 'icon-arrow-down', 'data-original-title' => 'Переместить ниже')), 'update' => array('label' => yii::t('Bootstrap', 'PHRASE.UPDATE'), 'url' => 'CHtml::normalizeUrl(array("update", "id" => $data->id))', 'options' => array()), 'delete' => array('label' => yii::t('Bootstrap', 'PHRASE.DELETE'), 'options' => array())), 'htmlOptions' => array('style' => 'white-space: nowrap')))));
?>

예제 #4
0
 /**
  * Manages all models.
  */
 public function actionIndex()
 {
     $this->breadcrumbs = array('Список альбомов' => array('/photo/photorubrics/index'), 'Просмотр альбома');
     $model = new PhotoElements('search');
     $model->attachBehavior('dateComparator', array('class' => 'DateComparator'));
     $model->unsetAttributes();
     // clear any default values
     $parent_id = 0;
     // set attributes from get
     if (isset($_GET['PhotoElements'])) {
         $model->attributes = $_GET['PhotoElements'];
         $parent_id = $_GET['PhotoElements']['parent_id'];
     }
     $dmp = var_export($_POST, true);
     file_put_contents($_SERVER["DOCUMENT_ROOT"] . "/log.txt", $dmp);
     // если это мультизагрузка, значит должен быть файл...
     if (isset($_POST['ASPSESSID'])) {
         file_put_contents($_SERVER["DOCUMENT_ROOT"] . "/log.txt", "request");
         $model_el = new PhotoElements();
         $root = PhotoRubrics::getRoot(new PhotoRubrics());
         $catalog = $root->descendants()->findAll($root->id);
         // set attributes from get
         if (isset($_GET['PhotoElements'])) {
             $model_el->attributes = $_GET['PhotoElements'];
         }
         $model_el->attributes = $_POST['PhotoElements'];
         $model_el->imagefile = CUploadedFile::getInstance($model_el, 'Filedata');
         if (isset($model_el->imagefile)) {
             $ext = pathinfo($model_el->imagefile);
             $model_el->image = $ext['extension'];
         }
         if ($model_el->save()) {
             if (isset($model_el->imagefile) && ($modelSettings = SiteModuleSettings::model()->find('site_module_id = 11'))) {
                 $filename = $model_el->id . '.' . $model_el->image;
                 $filepatch = '/../uploads/filestorage/photo/elements/';
                 $model_el->imagefile->saveAs(YiiBase::getPathOfAlias('webroot') . $filepatch . $filename);
                 //Обработка изображения
                 SiteModuleSettings::model()->chgImgModel($modelSettings, 'GD', 2, $model_el->id);
             }
         }
     }
     $param = array();
     $data['sort'] = array('defaultOrder' => 'id DESC');
     $data['Pagination'] = array('PageSize' => 100);
     if ($settingsModel = SiteModuleSettings::model()->find('site_module_id = 11')) {
         $data['Pagination'] = array('PageSize' => (int) $settingsModel->elements_page_admin > 0 ? $settingsModel->elements_page_admin : 100);
     }
     $provider = new CActiveDataProvider('PhotoElements', $data);
     $param = implode(" AND ", $param);
     $provider->criteria = $model->search($param);
     $root = PhotoRubrics::getRoot(new PhotoRubrics());
     $catalog = $root->descendants()->findAll($root->id);
     $this->render('list', array('model' => $model, 'provider' => $provider, 'root' => $root, 'parent_id' => $parent_id, 'catalog' => $catalog));
 }
예제 #5
0
 /**
  * Получить количество элементов в узле
  */
 public static function getCountTree($left_key, $right_key)
 {
     $model = Yii::app()->db->createCommand()->select('count(id) as count')->from(PhotoRubrics::model()->tableName())->where('left_key>=' . (int) $left_key . ' AND right_key<=' . (int) $right_key . '')->queryRow();
     $result = current($model) - 1;
     //вычитае из резуьтата сам узел
     return $result;
 }