示例#1
0
 /**
  * Отображает блок
  *
  * @param int $pageWidgetId id страничного блока
  */
 public function actionWidget($pageWidgetId)
 {
     $pageWidget = PageWidget::model()->with('widget')->findByPk((int) $pageWidgetId);
     if ($pageWidget) {
         $pageWidget->widget->content->widget($pageWidget->widget->class, array('pageWidget' => $pageWidget));
     }
 }
示例#2
0
 public function beforeDelete()
 {
     $pageWidgets = PageWidget::model()->findAll(array('condition' => '`area` = :area', 'params' => array('area' => 'widget' . $this->widget->id . 'ModelArea_items'), 'with' => array('widget'), 'order' => '`order`'));
     foreach ($pageWidgets as $pageWidget) {
         $pageWidget->widget->delete();
         $pageWidget->delete();
     }
     return parent::beforeDelete();
 }
示例#3
0
 public function getWidgetPageArray()
 {
     $sql = 'SELECT p.* FROM `' . Page::tableName() . '`  as p INNER JOIN `' . PageWidget::tableName() . '` as pu ON pu.page_id = p.id WHERE pu.widget_id = :widget_id ORDER BY pu.id LIMIT 1';
     $command = Yii::app()->db->createCommand($sql);
     $command->bindValue(':widget_id', $this->widget_id, PDO::PARAM_INT);
     $page = $command->queryRow();
     $page['alias'] = $page[Yii::app()->language . '_alias'];
     $page['url'] = $page[Yii::app()->language . '_url'];
     return $page;
 }
示例#4
0
function smarty_function_accessdenied($params, &$smarty)
{
    echo '<h2 class="error">' . Yii::t('cms', 'Error') . '</h2>';
    echo '<p>' . Yii::t('cms', 'Access denied') . '</p>';
    $widgetLogin = ModelLogin::model()->find();
    if ($widgetLogin && $widgetLogin->widget_id) {
        $pageWidget = PageWidget::model()->find('widget_id = :widget_id', array('widget_id' => $widgetLogin->widget_id));
        $widgetLogin->run(array('pageWidget' => $pageWidget));
    }
}
示例#5
0
    public function run()
    {
        $recordExample = new $this->className();
        if (!$this->order) {
            if (method_exists($recordExample, 'listDefaultOrder')) {
                $this->order = call_user_func(array($recordExample, 'listDefaultOrder'));
            } elseif ($recordExample->hasAttribute('create')) {
                $this->order = $recordExample->hasAttribute('create') . ' DESc';
            }
        }
        if ($recordExample->hasAttribute('widget_id')) {
            $dataProvider = new CActiveDataProvider($this->className, array('criteria' => array('condition' => $this->foreignAttribute . ' = :id', 'with' => 'widget', 'params' => array(':id' => $this->model->id)), 'sort' => array('attributes' => array('title' => array('asc' => 'widget.' . Widget::getI18nFieldName('title', 'Widget'), 'desc' => 'widget.' . Widget::getI18nFieldName('title', 'Widget') . ' DESC', 'label' => 'Title'), '*'), 'defaultOrder' => $this->order), 'pagination' => array('pageSize' => Yii::app()->settings->getValue('defaultsPerPage'))));
        } else {
            $config = array('sort' => array('defaultOrder' => $this->order), 'pagination' => array('pageSize' => Yii::app()->settings->getValue('defaultsPerPage')));
            if ($this->hasModel() && $this->foreignAttribute) {
                $config['criteria'] = array('condition' => $this->foreignAttribute . ' = :id', 'params' => array(':id' => $this->model->id));
            }
            $dataProvider = new CActiveDataProvider($this->className, $config);
        }
        if ($this->hasModel()) {
            $id = __CLASS__ . '_' . get_class($this->model) . '_' . $this->model->id;
        } else {
            $id = __CLASS__ . $this->className;
        }
        $pageId = 0;
        $area = '';
        $pageWidgetId = 0;
        $widgetId = 0;
        if ($this->hasModel() && $this->model->hasAttribute('widget_id')) {
            $pageWidget = PageWidget::model()->find('`widget_id` = :widget_id', array(':widget_id' => $this->model->widget_id));
            if ($pageWidget) {
                $pageWidgetId = $pageWidget->id;
                $widgetId = $this->model->widget_id;
                $pageId = $pageWidget->page_id;
                $area = $pageWidget->area;
            }
        }
        $recordsGrid = $this->widget('zii.widgets.grid.CGridView', array('id' => $id, 'dataProvider' => $dataProvider, 'ajaxUpdate' => $id, 'ajaxVar' => $id, 'selectableRows' => 2, 'afterAjaxUpdate' => 'js:function(id, data)' . <<<JS
{
    cmsReloadPageWidget({$pageWidgetId}, '.cms-pagewidget[rev={$widgetId}]');
}
JS
, 'columns' => array_merge(array(array('class' => 'CCheckBoxColumn', 'id' => $id . '_check')), method_exists($recordExample, 'listColumns') ? call_user_func(array($recordExample, 'listColumns')) : ($recordExample->hasAttribute('widget_id') ? array(array('name' => 'title', 'type' => 'raw', 'header' => Yii::t('cms', 'Title'), 'value' => 'CHtml::link(CHtml::encode($data->widget->title), "#", array("onclick" => "js:javascript:cmsRecordEditForm({$data->id}, \'".get_class($data)."\', \'".$data->widget->id."\', \'' . $id . '\');return false; ", "title"=>"' . Yii::t('cms', 'Edit') . '", "ondblclick"=>""))')) : ($recordExample->hasAttribute(Yii::app()->language . '_title') ? array(array('name' => 'title', 'type' => 'raw', 'header' => Yii::t('cms', 'Title'), 'value' => 'CHtml::link(CHtml::encode($data->title), "#", array("onclick" => "js:javascript:cmsRecordEditForm({$data->id}, \'".get_class($data)."\', \'0\', \'' . $id . '\');return false; ", "title"=>"' . Yii::t('cms', 'Edit') . '", "ondblclick"=>""))')) : array())), $this->columns, array(array('class' => 'CButtonColumn', 'template' => '{view} {update} {del}', 'buttons' => array('view' => array('label' => Yii::t('cms', 'Go to page'), 'url' => '"javascript:cmsGotoRecordPage({$data->id}, \'".get_class($data)."\')"', 'visible' => '$data->hasAttribute("widget_id") && isset($data->widget)'), 'update' => array('url' => '"javascript:cmsRecordEditForm({$data->id}, \'".get_class($data)."\', \'".($data->hasAttribute("widget_id") && isset($data->widget) ? $data->widget->id : 0)."\', \'' . $id . '\');"'), 'del' => array('label' => Yii::t('cms', 'Delete'), 'imageUrl' => '/images/delete.png', 'url' => '"javascript:cmsRecordDelete({$data->id}, \'".get_class($data)."\', \'".($data->hasAttribute("widget_id") && isset($data->widget) ? $data->widget->id : 0)."\', \'' . $id . '\')"')))))), true);
        $this->render('RecordsGrid', array('id' => $id, 'foreignAttribute' => $this->foreignAttribute, 'addButtonTitle' => $this->addButtonTitle, 'pageId' => $pageId, 'area' => $area, 'recordExample' => $recordExample, 'className' => $this->className, 'recordsGrid' => $recordsGrid, 'model' => $this->model, 'pageWidgetId' => $pageWidgetId, 'widgetId' => $widgetId));
    }
<?php

require "connect.inc.php";
// create a new page widget
require_once '../addon/PageWidget.php';
// widget settings
$entries = 1;
$table = 'users';
// which rows to display
$rows = array('name', 'email');
$widget = new PageWidget($db, 'mysqlLimitQuery', $table, $entries);
echo "<h2>Page {$widget->page}</h2>";
echo $widget->getPageDropdown();
echo "Entries {$widget->start} -  {$widget->end} of {$widget->total}<p>";
echo '[' . $widget->getIndex('] [') . ']<p>';
echo $widget->getOrderDropdown($rows);
echo $widget->getNextLink();
echo '<br>';
echo $widget->getPrevLink();
// get the data
echo DBHelper::dumpAll($widget->get($rows), true);
require "disconnect.inc.php";
////////////////////////////////////////////////////////////////////////
echo '<hr>';
highlight_file(__FILE__);
?>
 
示例#7
0
 public function init()
 {
     parent::init();
     $this->params['areaId'] = 'widget' . $this->params['widget']->id . 'ModelArea_items';
     $this->params['pageWidgets'] = PageWidget::model()->findAll(array('condition' => '`area` = :area', 'params' => array('area' => $this->params['areaId']), 'with' => array('widget'), 'order' => '`order`'));
 }
示例#8
0
    public function run()
    {
        list($name, $id) = $this->resolveNameID();
        if (isset($this->htmlOptions['id'])) {
            $id = $this->htmlOptions['id'];
        } else {
            $this->htmlOptions['id'] = $id;
        }
        if (isset($this->htmlOptions['name'])) {
            $name = $this->htmlOptions['name'];
        } else {
            $this->htmlOptions['name'] = $name;
        }
        if ($this->hasModel()) {
            $areaName = 'widget' . $this->model->widget->id . $id;
            $modelId = $this->model->id;
            if ($this->model->isNewRecord) {
                echo Yii::t('cms', 'Please save before using it.');
                return;
            }
            echo CHtml::activeHiddenField($this->model, $this->attribute, $this->htmlOptions);
        } else {
            $areaName = $name;
            $modelId = $id;
            echo CHtml::hiddenField($name, $this->value, $this->htmlOptions);
        }
        $value = $this->hasModel() ? $this->model->{$this->attribute} : $this->value;
        Yii::app()->controller->widget('Area', array('name' => $areaName, 'pageWidgets' => PageWidget::model()->findAll(array('condition' => '`area` = :area', 'params' => array('area' => $areaName), 'with' => array('widget'), 'order' => '`order`'))));
        ?>
<script type="text/javascript">

            // Настройки и обработчики перещения юнитов на странице
            $('#cms-area-<?php 
        echo $areaName;
        ?>
').sortable({
                placeholder: 'cms-pagewidget-highlight',
                revert: true,
                opacity:1,
                forcePlaceholderSize:true,
                cancel:'.cms-pagewidget-menu,.cms-empty-area-buttons',
                update:function(event, ui) {
                    var pageWidgetId = $(ui.item).attr('id').replace('cms-pagewidget-','');
                    var areaName = cmsGetAreaNameByPageWidget(ui.item);
                    if (!ui.sender) {
                        // Запрос на обновление текущей области
                        cmsAjaxSaveArea(cmsGetAreaByPageWidget(ui.item), areaName, <?php 
        echo intval($modelId);
        ?>
, 'pageWidgetId='+pageWidgetId);
                    }
                },
                start:function(event, ui) {
                    $(ui.helper).find('.cms-panel').hide();
                    $('.cms-area').addClass('cms-potential');
                    $('.cms-area').each(function() {
                        if ($(this).find('.cms-pagewidget').length == 0)
                            $(this).addClass('cms-empty-area');
                    });
                    cmsAreaEmptyCheck();
                },
                stop:function(event, ui) {
                    $('.cms-area').removeClass('cms-potential').removeClass('cms-empty-area');
                    cmsAreaEmptyCheck();
                }
            }).disableSelection();

            $('#cms-area-<?php 
        echo $areaName;
        ?>
 .cms-pagewidget').css('cursor', 'move');

            cmsAreaEmptyCheck();


</script>
<style type="text/css">
    #cms-area-<?php 
        echo $areaName;
        ?>
 #pagewidgetpanel_move_li {
        display:none;
    }
</style>
<?php 
    }
示例#9
0
    echo '<br>';
    echo $db->error;
    echo '<hr>';
    // get a column
    $query = "select {$tableKey} from {$table} where {$tableKey}<10";
    $db->query($query);
    echo 'getColumn(): ' . $query;
    echo '<br>';
    echo DBHelper::dumpColumn($db->getColumn(), true);
    echo '<br>';
    echo $db->error;
    echo '<hr>';
    // show widget
    echo 'new PageWidget() :';
    echo '<br>';
    $p = new PageWidget($db, $limitFunction, $table, $pageLimit);
    echo '<br>';
    echo $p->getPageDropDown();
    echo DBHelper::dumpAll($p->get());
    $prev = $p->getPrevLink();
    $next = $p->getNextLink();
    echo ($prev ? $prev : 'Previous') . ' - ' . ($next ? $next : 'Next');
    echo '<p>';
    echo $p->getIndex();
    echo '<hr>';
    $db->free();
    $db->disconnect();
} else {
    echo $db->error;
}
/////////////////////////////////////////////////////////////
示例#10
0
 /**
  * Обрабатывает перемещение блока
  * @param string название области 
  * @param array массив идентификаторов pageWidget'ов размещенных на странице, где делается перемещение
  * @param integer идентификатор перемещаемого pageWidget'а
  * @return boolean true в случае удачной операции, false - в обратном случае
  */
 public function move($area, $pageWidgetIds, $pageWidgetId)
 {
     $transaction = Yii::app()->db->beginTransaction();
     try {
         $pageWidget = PageWidget::model()->findByPk($pageWidgetId);
         $isNewArea = $pageWidget->area != $area;
         // Переносим блок в нужное место и сбрасываем сортировку
         $sql = 'UPDATE `' . PageWidget::tableName() . '` SET `area` = :area, `order` = 0
                 WHERE `widget_id` = :widget_id';
         $command = Yii::app()->db->createCommand($sql);
         $command->bindValue(':area', $area, PDO::PARAM_STR);
         $command->bindValue(':widget_id', $this->id, PDO::PARAM_INT);
         $command->execute();
         // Двигаем блоки на освободившееся место
         $sql = 'UPDATE `' . PageWidget::tableName() . '` as pu
                 INNER JOIN ( SELECT `page_id` FROM `' . PageWidget::tableName() . '`
                             WHERE `widget_id` = :widget_id ) as pu2
                 ON pu.`page_id` = pu2.`page_id`
                 SET pu.`order`= pu.`order`-1
                 WHERE
                     pu.`area` = :area
                     AND pu.`order` > :order';
         $command = Yii::app()->db->createCommand($sql);
         $command->bindValue(':widget_id', $this->id, PDO::PARAM_INT);
         $command->bindValue(':area', $pageWidget->area, PDO::PARAM_STR);
         $command->bindValue(':order', $pageWidget->order, PDO::PARAM_INT);
         $command->execute();
         // Выделяем списки блоков, которые идут перед и после перемещаемого блока
         $pageWidgetOrder = -1;
         foreach ($pageWidgetIds as $i => $id) {
             $pageWidgetIds[$i] = intval($id);
             if ($pageWidgetId == $id) {
                 $pageWidgetOrder = $i;
             }
         }
         $ids = array_flip($pageWidgetIds);
         $sql = 'SELECT `widget_id`, `id` FROM `' . PageWidget::tableName() . '`
                 WHERE `id` IN (' . implode(', ', $pageWidgetIds) . ')';
         $result = Yii::app()->db->createCommand($sql)->queryAll();
         $widgetIds = array();
         foreach ($result as $row) {
             $widgetIds[intval($ids[$row['id']])] = $row['widget_id'];
         }
         ksort($widgetIds);
         $preIds = array();
         $postIds = array();
         foreach ($widgetIds as $i => $id) {
             if ($i < $pageWidgetOrder) {
                 $preIds[] = $id;
             } elseif ($i > $pageWidgetOrder) {
                 $postIds[] = $id;
             }
         }
         $preIds = array_reverse($preIds);
         $co = max(count($preIds), count($postIds));
         $_ids = array();
         for ($i = 0; $i < $co; $i++) {
             $_ids[] = array('id' => isset($preIds[$i]) ? $preIds[$i] : 0, 'pre' => true);
             $_ids[] = array('id' => isset($postIds[$i]) ? $postIds[$i] : 0, 'pre' => false);
         }
         // Находим страницы, где нужно правильно разместить перемещаемый блок
         $sql = 'SELECT * FROM `' . PageWidget::tableName() . '`
                 WHERE
                     `page_id` IN  ( SELECT `page_id` FROM `' . PageWidget::tableName() . '`
                                     WHERE `widget_id` = :widget_id )
                      AND `area` = :area
                      AND `widget_id` != :widget_id
                 ORDER BY `order`';
         $command = Yii::app()->db->createCommand($sql);
         $command->bindValue(':area', $area, PDO::PARAM_STR);
         $command->bindValue(':widget_id', $this->id, PDO::PARAM_INT);
         $result = $command->queryAll();
         $pages = array();
         $pageWidgets = array();
         foreach ($result as $row) {
             $pages[$row['page_id']][] = $row['widget_id'];
             $pageWidgets[$row['widget_id']][] = $row['id'];
             $widgets[$row['widget_id']][] = $row['page_id'];
         }
         // Отделяем страницы, где размещение пройдет просто, а где надо подумать
         $simplePages = $pages;
         foreach ($simplePages as $id => $page) {
             if (count(array_intersect($page, $widgetIds)) == 0) {
                 unset($pages[$id]);
             } else {
                 unset($simplePages[$id]);
             }
         }
         // Страницы, где в нужной области нету блоков вообще,
         // дополнительно обрабатывать нету нужды.
         // Обработка страниц, у которых нету тех блоков, которые есть на текущей
         if (!empty($simplePages) && is_array($simplePages)) {
             $onTop = count($preIds) < count($postIds);
             $this->setOnPagesTopOrBottom(array_keys($simplePages), $onTop, $area);
         }
         // Обработка страниц, которые кроме своих блоков имеют также те блоки, которые
         // присутствуют на текущей странице. Самый сложный вариант.
         if (!empty($pages) && is_array($pages)) {
             // Обходим массив с идентификаторами юнитов, которые размещены
             // вокруг перемещаемого блока
             $pageIds = array_keys($pages);
             foreach ($_ids as $k => $r) {
                 $id = $r['id'];
                 if (empty($pageIds)) {
                     break;
                 }
                 if (isset($widgets[$id]) && !empty($widgets[$id]) && is_array($widgets[$id])) {
                     $widgets[$id] = array_intersect($pageIds, $widgets[$id]);
                 }
                 // Если юнит размещен на какой-то странице
                 if (isset($widgets[$id]) && !empty($widgets[$id]) && is_array($widgets[$id])) {
                     // Подвинем соседей
                     $sql = 'UPDATE `' . PageWidget::tableName() . '` as pu
                             INNER JOIN (SELECT `order`, `page_id` FROM `' . PageWidget::tableName() . '`
                                         WHERE
                                             `page_id` IN (' . implode(', ', $widgets[$id]) . ')
                                         AND `widget_id` = :sibling_widget_id
                                         GROUP BY `page_id` ) as pu2
                             ON pu.`page_id` = pu2.`page_id`
                             SET pu.`order` = pu.`order`+1
                             WHERE
                                 pu.`area` = :area
                                 AND pu.`widget_id` != :widget_id
                                 AND pu.`order` ' . ($r['pre'] ? '>' : '>=') . ' pu2.`order`';
                     $command = Yii::app()->db->createCommand($sql);
                     $command->bindValue(':area', $area, PDO::PARAM_STR);
                     $command->bindValue(':widget_id', $this->id, PDO::PARAM_INT);
                     $command->bindValue(':sibling_widget_id', $id, PDO::PARAM_INT);
                     $command->execute();
                     // Установка перемещаемого блока в нужное место
                     $sql = 'UPDATE `' . PageWidget::tableName() . '` as pu
                             INNER JOIN (SELECT `order`, `page_id` FROM `' . PageWidget::tableName() . '`
                                         WHERE
                                             `page_id` IN (' . implode(', ', $widgets[$id]) . ')
                                         AND `widget_id` = :sibling_widget_id
                                         GROUP BY `page_id` ) as pu2
                             ON pu.`page_id` = pu2.`page_id`
                             SET pu.`order` = pu2.`order`' . ($r['pre'] ? '+1' : '-1') . '
                             WHERE
                                 pu.`widget_id` = :widget_id';
                     $command = Yii::app()->db->createCommand($sql);
                     $command->bindValue(':widget_id', $this->id, PDO::PARAM_INT);
                     $command->bindValue(':sibling_widget_id', $id, PDO::PARAM_INT);
                     $command->execute();
                     // Из массива страниц убираем уже обработанные
                     $pageIds = array_diff($pageIds, $widgets[$id]);
                 } elseif ($id == 0 && $k < 2) {
                     $this->setOnPagesTopOrBottom($pageIds, $r['pre'], $area);
                     $pageIds = array();
                 }
             }
         }
         $transaction->commit();
         return true;
     } catch (Exception $e) {
         $transaction->rollBack();
         return false;
     }
 }
示例#11
0
 /**
  * Возвращает размещения блоков по id блока
  *
  * @param int $widgetId id блока
  */
 public function actionGetPageWidgetsByWidgetId($widgetId)
 {
     $widgetId = (int) $widgetId;
     $sql = 'SELECT `id` FROM `' . PageWidget::tableName() . '` WHERE `widget_id` = :widget_id';
     $command = Yii::app()->db->createCommand($sql);
     $command->bindValue(':widget_id', $widgetId, PDO::PARAM_INT);
     echo CJavaScript::jsonEncode($command->queryColumn());
 }
示例#12
0
文件: Page.php 项目: rosko/Tempo-CMS
 public function fill()
 {
     $sql = 'SELECT * FROM `' . PageWidget::tableName() . '` WHERE `page_id` = :page_id AND `area` NOT LIKE "main%"';
     $command = Yii::app()->db->createCommand($sql);
     $command->bindValue(':page_id', $this->parent_id, PDO::PARAM_INT);
     $pus = $command->queryAll();
     if ($pus && is_array($pus)) {
         $sql = 'INSERT INTO `' . PageWidget::tableName() . '` (`page_id`, `widget_id`, `order`, `area`) VALUES ';
         $sql_arr = array();
         foreach ($pus as $pu) {
             $sql_arr[] = '(' . intval($this->id) . ', ' . intval($pu['widget_id']) . ', ' . intval($pu['order']) . ', "' . $pu['area'] . '")';
         }
         $sql .= implode(',', $sql_arr);
         $command = Yii::app()->db->createCommand($sql);
         $command->execute();
     }
 }