Returns the static model of the specified AR class.
public static model ( $className = __CLASS__ ) : PageBlock | ||
return | PageBlock | the static model class |
protected function renderContent() { if (isset($this->page)) { //get all blocks of current region, order by 'order' $blocks = PageBlock::model()->findAll(array('condition' => 'page_id=:paramId and region=:regionId and status=:status', 'params' => array(':paramId' => $this->page->page_id, ':regionId' => $this->region, ':status' => ConstantDefine::PAGE_BLOCK_ACTIVE), 'order' => 'block_order ASC')); if ($blocks) { foreach ($blocks as $page_block) { $block = GxcHelpers::loadDetailModel('Block', $page_block->block_id); if ($block) { $block_ini = parse_ini_file(Yii::getPathOfAlias('common.front_blocks.' . $block->type) . DIRECTORY_SEPARATOR . 'info.ini'); //Include the class Yii::import('common.front_blocks.' . $block->type . '.' . $block_ini['class']); if ($this->data != null) { $this->widget('common.front_blocks.' . $block->type . '.' . $block_ini['class'], array('block' => $block, 'page' => $this->page, 'layout_asset' => $this->layout_asset, 'data' => $this->data)); } else { $this->widget('common.front_blocks.' . $block->type . '.' . $block_ini['class'], array('block' => $block, 'page' => $this->page, 'layout_asset' => $this->layout_asset)); } } else { echo ''; } } } else { echo ''; } } }
protected function renderContent() { $model = new Page(); //If it has guid, it means this is a translated version $guid = isset($_GET['guid']) ? strtolower(trim($_GET['guid'])) : ''; //List of language that should exclude not to translate $lang_exclude = array(); //List of translated versions $versions = array(); // If the guid is not empty, it means we are creating a translated version of a content // We will exclude the translated language and include the name of the translated content to $versions if ($guid != '') { $page_object = Page::model()->findAll('guid=:gid', array(':gid' => $guid)); if (count($page_object) > 0) { $langs = GxcHelpers::getAvailableLanguages(); foreach ($page_object as $obj) { $lang_exclude[] = $obj->lang; $versions[] = $obj->name . ' - ' . $langs[$obj->lang]['name']; } } $model->guid = $guid; } // if it is ajax validation request if (isset($_POST['ajax']) && $_POST['ajax'] === 'page-form') { echo CActiveForm::validate($model); Yii::app()->end(); } //Define Blocks in Regions $regions_blocks = array(); // collect user input data if (isset($_POST['Page'])) { $regions_blocks = isset($_POST['Page']['regions']) ? $_POST['Page']['regions'] : array(); $model->attributes = $_POST['Page']; if ($model->save()) { if (!empty($regions_blocks)) { //Delete All Page Block Before PageBlock::model()->deleteAll('page_id = :id', array(':id' => $model->page_id)); foreach ($regions_blocks as $key => $blocks) { $order = 1; for ($i = 0; $i < count($blocks['id']); $i++) { $block = $blocks['id'][$i]; $temp_page_block = new PageBlock(); $temp_page_block->page_id = $model->page_id; $temp_page_block->block_id = $block; $temp_page_block->region = $key; $temp_page_block->block_order = $order; $temp_page_block->status = $blocks['status'][$i]; $temp_page_block->save(); $order++; } } } //Start to save the Page Block user()->setFlash('success', t('cms', 'Create new Page Successfully!')); $model = new Page(); Yii::app()->controller->redirect(array('create')); } } $this->render('cmswidgets.views.page.page_form_widget', array('model' => $model, 'lang_exclude' => $lang_exclude, 'versions' => $versions, 'regions_blocks' => $regions_blocks)); }
protected function renderContent() { $id = isset($_GET['id']) ? (int) $_GET['id'] : 0; $model = GxcHelpers::loadDetailModel('Page', $id); //Guid of the Object $guid = $model->guid; //List of language that should exclude not to translate $lang_exclude = array(); //List of translated versions $versions = array(); // if it is ajax validation request if (isset($_POST['ajax']) && $_POST['ajax'] === 'page-form') { echo CActiveForm::validate($model); Yii::app()->end(); } //Define Blocks in Regions $regions_blocks = array(); //Find all the Page Blocks of this current Page $page_blocks = PageBlock::model()->findAll(array('condition' => 'page_id = :pid', 'params' => array(':pid' => $model->page_id), 'order' => 'region ASC, block_order ASC')); foreach ($page_blocks as $pb) { $regions_blocks[$pb->region]['id'][] = $pb->block_id; $regions_blocks[$pb->region]['status'][] = $pb->status; } // collect user input data if (isset($_POST['Page'])) { $regions_blocks = isset($_POST['Page']['regions']) ? $_POST['Page']['regions'] : array(); $model->attributes = $_POST['Page']; if ($model->save()) { if (!empty($regions_blocks)) { //Delete All Page Block Before PageBlock::model()->deleteAll('page_id = :id', array(':id' => $model->page_id)); foreach ($regions_blocks as $key => $blocks) { $order = 1; for ($i = 0; $i < count($blocks['id']); $i++) { $block = $blocks['id'][$i]; $temp_page_block = new PageBlock(); $temp_page_block->page_id = $model->page_id; $temp_page_block->block_id = $block; $temp_page_block->region = $key; $temp_page_block->block_order = $order; $temp_page_block->status = $blocks['status'][$i]; $temp_page_block->save(); $order++; } } } //Start to save the Page Block user()->setFlash('success', t('Update Page Successfully!')); } } $this->render('cmswidgets.views.page.page_form_widget', array('model' => $model, 'lang_exclude' => $lang_exclude, 'versions' => $versions, 'regions_blocks' => $regions_blocks)); }
protected function renderContent() { if (isset($this->page)) { $blocks = Yii::app()->cache->get($this->page->page_id . '-' . $this->region); if ($blocks === false) { //var_dump($this->page->page_id.'-'.$this->region); //get all blocks of current region, order by 'order' $blocks = PageBlock::model()->findAll(array('condition' => 'page_id=:paramId and region=:regionId and status=:status', 'params' => array(':paramId' => $this->page->page_id, ':regionId' => $this->region, ':status' => ConstantDefine::PAGE_BLOCK_ACTIVE), 'order' => 'block_order ASC')); if ($blocks) { Yii::app()->cache->set($this->page->page_id . '-' . $this->region, $blocks, 300); $this->workWithBlocks($blocks); } else { echo ''; } } else { $this->workWithBlocks($blocks); } } }
protected function afterDelete() { PageBlock::model()->deleteAll('block_id = :id', array(':id' => $this->block_id)); }
public static function inheritParent() { $parent = isset($_POST['parent']) ? (int) $_POST['parent'] : 0; $region = isset($_POST['region']) ? (int) $_POST['region'] : null; $layout = isset($_POST['layout']) ? (int) $_POST['layout'] : ''; $result = array(); $result['blocks'] = array(); if ($parent && $region !== null) { $page = Page::model()->findByPk($parent); if ($page) { //We now find all blocks of this parent $page_blocks = PageBlock::model()->with('block')->findAll(array('condition' => 'page_id = :pid and region = :rid', 'params' => array(':pid' => $parent, ':rid' => $region), 'order' => 'region ASC, block_order ASC')); foreach ($page_blocks as $pb) { $temp['region'] = $pb->region; $temp['id'] = $pb->block_id; $temp['status'] = $pb->status; $temp['title'] = $pb->block->name; $result['blocks'][] = $temp; } } } echo json_encode($result); }