model() public static method

Returns the static model of the specified AR class.
public static model ( $className = __CLASS__ ) : Block
return Block the static model class
 public function loadModel($id)
 {
     if (($model = Block::model()->findByPk($id)) === null) {
         throw new CHttpException(404, 'Страница не найдена');
     }
     return $model;
 }
 public function loadModel($id, $ml = true)
 {
     if (($model = Block::model()->findByPk($id)) === null) {
         throw new CHttpException(404, Yii::t('PageModule.block', 'Page was not found!'));
     }
     return $model;
 }
Example #3
0
 public function run()
 {
     $block = Block::model()->published()->with('children')->findByCode($this->code);
     if ($block === null) {
         if ($this->silent === false) {
             throw new CException(Yii::t('PageModule.block', 'Блок "{code}" не найден!', array('{code}' => $this->code)));
         }
         return;
     }
     $this->view = empty($block->template) ? $this->view : $block->template;
     $this->render($this->view, array('model' => $block, 'title' => $this->title));
 }
Example #4
0
echo $model->hasErrors('parent_id') ? 'error' : '';
?>
">
        <div class="span3">
        <?php 
if (!$model->isNewRecord) {
    ?>
        <?php 
    echo $form->dropDownListRow($model, 'parent_id', array_diff_key(Block::model()->root()->getTabList(), $model->root()->getAssocList()), array('class' => 'span7 popover-help', 'empty' => 'Выберите', 'encode' => false));
    ?>
  
        <?php 
} else {
    ?>
        <?php 
    echo $form->dropDownListRow($model, 'parent_id', Block::model()->root()->getTabList(), array('class' => 'span7 popover-help', 'empty' => 'Выберите', 'encode' => false));
    ?>
          
        <?php 
}
?>
        </div>     
    </div>

    <div class="row-fluid control-group <?php 
echo $model->hasErrors('description') ? 'error' : '';
?>
">
        <?php 
echo $form->textFieldRow($model, 'description', array('size' => 60, 'maxlength' => 150, 'class' => 'span7 popover-help', 'data-original-title' => $model->getAttributeLabel('description'), 'data-content' => $model->getAttributeDescription('description')));
?>
Example #5
0
 public static function suggestBlocks()
 {
     if (isset($_GET['q']) && ($keyword = trim($_GET['q'])) !== '') {
         $limit = 10;
         $blocks = Block::model()->findAll(array('condition' => 'name LIKE :keyword', 'limit' => $limit, 'params' => array(':keyword' => '%' . strtr($keyword, array('%' => '\\%', '_' => '\\_', '\\' => '\\\\')) . '%')));
         $names = array();
         foreach ($blocks as $block) {
             $names[] = $block->name . '|' . $block->block_id;
         }
         if ($names !== array()) {
             echo implode("\n", $names);
         }
     }
     Yii::app()->end();
 }
Example #6
0
         

    }
    
    function initBlocks(){
        
           <?php 
if (is_array($regions_blocks) && !empty($regions_blocks) > 0) {
    ?>
                    //Start to get the content based on the ids
            <?php 
    foreach ($regions_blocks as $key => $obj_blocks) {
        $blocks = array();
        for ($i = 0; $i < count($obj_blocks['id']); $i++) {
            $obj_block = $obj_blocks['id'][$i];
            $temp_block = Block::model()->findByPk($obj_block);
            if ($temp_block) {
                $count = $i + 1;
                $blocks['item_' . $count . '_' . $temp_block->block_id]['region'] = $key;
                $blocks['item_' . $count . '_' . $temp_block->block_id]['id'] = $temp_block->block_id;
                $blocks['item_' . $count . '_' . $temp_block->block_id]['title'] = $temp_block->name;
                $blocks['item_' . $count . '_' . $temp_block->block_id]['status'] = $obj_blocks['status'][$i];
            }
        }
        echo 'var block_list_region_' . $key . ' = ' . json_encode($blocks) . ';';
        echo '$.each(block_list_region_' . $key . ', function(k,v) { 
                             
                             setBlocksForRegion(v.region,v.title,v.id,v.status);              
                        });';
    }
    ?>
 public function actionPaste()
 {
     $className = $this->entity_type . 'Block';
     $id = (int) Yii::app()->user->getState('copiedBlockId');
     if (($model = Block::model()->findByPk($id)) === null) {
         $this->redirect(array('/classroom/blockBackend/index', 'entity_type' => $this->entity_type, 'entity_id' => $this->entity_id));
     }
     $criteria = new CDbCriteria();
     $criteria->select = new CDbExpression('MAX(sort) as sort');
     $criteria->condition = 't.entity_type = :entity_type AND t.entity_id = :entity_id';
     $criteria->params = array(':entity_type' => $this->entity_type, ':entity_id' => $this->entity_id);
     $max = $className::model()->find($criteria);
     $model->duplicate(array('entity_type' => $this->entity_type, 'entity_id' => $this->entity_id, 'sort' => $max->sort + 100));
     Yii::app()->user->setState('copiedBlockId', null);
     $this->redirect(array('/classroom/blockBackend/index', 'entity_type' => $this->entity_type, 'entity_id' => $this->entity_id));
 }
 /**
  * Функция добавления группы изображений
  *
  * @param int $id - id-галереи
  *
  * @return void
  *
  * @throws CHttpException
  **/
 public function actionAddimages($id)
 {
     if (($gallery = Block::model()->findByPk($id)) === null) {
         throw new CHttpException(404, 'Страница не найдена');
     }
     $image = new Image();
     if (Yii::app()->getRequest()->getIsPostRequest() && ($imageData = Yii::app()->getRequest()->getPost('Image')) !== null) {
         $imageData = $imageData[$_FILES['Image']['name']['file']];
         $this->_addImage($image, $imageData, $gallery);
         if ($image->hasErrors()) {
             $data[] = array('error' => $image->getErrors());
         } else {
             $data[] = array('name' => $image->title, 'type' => $_FILES['Image']['type']['file'], 'size' => $_FILES['Image']['size']['file'], 'url' => $image->getImageUrl(), 'thumbnail_url' => $image->getImageUrl(100), 'delete_url' => $this->createUrl('/classroom/imageBackend/delete', array('id' => $image->id, 'method' => 'uploader')), 'delete_type' => 'GET');
         }
         echo json_encode($data);
         Yii::app()->end();
     } else {
         throw new CHttpException(404, 'Страница не найдена');
     }
 }
Example #9
0
 public static function model($className = __CLASS__)
 {
     return parent::model($className);
 }
 public function actionSave()
 {
     $user = Yii::app()->user->getProfile();
     $quoteText = Yii::app()->getRequest()->getParam('text', null);
     if (!$quoteText === null) {
         return false;
     }
     $blockId = Yii::app()->getRequest()->getParam('blockId', null);
     if ($blockId !== null) {
         $arr = explode('-', $blockId);
         $blockId = key_exists(0, $arr) ? (int) $arr[0] : 0;
         $block = Block::model()->published()->findByPK($blockId);
         if ($block === false) {
             return false;
         }
     } else {
         return false;
     }
     // Создаем и сохраняем цитату
     $quote = new Quote();
     $quote->user_id = $user->id;
     $quote->block_id = $block->id;
     $quote->content = $quoteText;
     if ($quote->save()) {
         // Общее кол-во цитат
         $totalCount = Quote::model()->user($user->id)->program($quote->course_type_id)->count();
         // Возвращаем ответ
         $resp = array('status' => 1, 'data' => array('id' => $quote->id, 'text' => $quote->getContent(), 'url' => $quote->getUrl(), 'totalCount' => $totalCount));
         Yii::app()->ajax->raw($resp);
     } else {
         $resp = array('status' => 0, 'error' => 'Ошибка сохранения.');
         Yii::app()->ajax->raw($resp);
     }
 }
Example #11
0
echo Yii::t('PageModule.block', 'Fields with');
?>
    <span class="required">*</span>
    <?php 
echo Yii::t('PageModule.block', 'are required.');
?>
</div>

<?php 
echo $form->errorSummary($model);
?>

<div class="row">
    <div class="col-sm-3">
        <?php 
$parents = !$model->isNewRecord ? array_diff_key(Block::model()->root()->page($model->page_id)->getTabList(0, false), $model->root()->page($model->page_id)->getAssocList(0, false)) : Block::model()->root()->page($model->page_id)->getTabList();
echo $form->dropDownListGroup($model, 'parent_id', ['widgetOptions' => ['data' => $parents, 'htmlOptions' => ['class' => 'popover-help', 'empty' => Yii::t('PageModule.block', '--choose--'), 'data-original-title' => $model->getAttributeLabel('parent_id'), 'data-content' => $model->getAttributeDescription('parent_id'), 'encode' => false]]]);
?>
    </div>
    <div class="col-sm-3">
        <?php 
echo $form->dropDownListGroup($model, 'status', ['widgetOptions' => ['data' => $model->statusList, 'htmlOptions' => ['class' => 'popover-help', 'empty' => Yii::t('PageModule.block', '--choose--'), 'data-original-title' => $model->getAttributeLabel('status'), 'data-content' => $model->getAttributeDescription('status')]]]);
?>
    </div>
    <div class="col-sm-3">
        <?php 
echo $form->dropDownListGroup($model, 'template', ['widgetOptions' => ['data' => $this->getModule()->getBlockTemplatesList(), 'htmlOptions' => ['class' => 'popover-help', 'empty' => Yii::t('PageModule.block', '--choose--'), 'data-original-title' => $model->getAttributeLabel('template'), 'data-content' => $model->getAttributeDescription('template')]]]);
?>
    </div>
</div>
<div class="row">
Example #12
0
 public function loadModel($id)
 {
     $model = Block::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, Yii::t('app', 'The requested page does not exist.'));
     }
     return $model;
 }