protected function renderContent() { $model = new ResourceUploadForm(); $is_new = false; $process = true; $types_array = ConstantDefine::fileTypes(); $id = isset($_GET['id']) ? (int) $_GET['id'] : 0; $resource = GxcHelpers::loadDetailModel('Resource', $id); if ($resource) { $model->name = $resource->resource_name; $model->body = $resource->resource_body; $model->where = $resource->where; $model->type = $resource->resource_type; } // if it is ajax validation request if (isset($_POST['ajax']) && $_POST['ajax'] === 'resource-form') { echo CActiveForm::validate($model); Yii::app()->end(); } // collect user input data if (isset($_POST['ResourceUploadForm'])) { $model->attributes = $_POST['ResourceUploadForm']; $resource->resource_name = $model->name; $resource->resource_body = $model->body; $resource->resource_type = $model->type; if ($resource->save()) { user()->setFlash('success', t('cms', 'Update Resource Successfully!')); } } $this->render('cmswidgets.views.resource.resource_form_widget', array('model' => $model, 'is_new' => $is_new, 'types_array' => $types_array)); }
/** * Get the URL of assets. * The base URL that contains all published asset files of yii-debug-toolbar. * @return string */ public function getAssetsUrl() { if (null === $this->_assetsUrl && 'cli' !== php_sapi_name()) { $this->_assetsUrl = GxcHelpers::publishAsset(dirname(__FILE__) . '/assets'); } return $this->_assetsUrl; }
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() { $id = isset($_GET['id']) ? (int) $_GET['id'] : 0; $page = isset($_GET['page']) ? (int) $_GET['page'] : 0; $model = GxcHelpers::loadDetailModel('Comment', $id); $prev_status = $model->comment_approved; if (isset($_POST['Comment'])) { $model->attributes = $_POST['Comment']; if ($model->save()) { if ($prev_status != $model->comment_approved) { if ($model->comment_approved == Comment::STATUS_APPROVED) { $object = Object::model()->findbyPk($model->object_id); if ($object != null) { $tempCommentCount = $object->comment_count; $tempCommentCount++; $object_comment_count = $tempCommentCount; $object->save(); } } else { if ($model->comment_approved == Comment::STATUS_PENDING) { $object = Object::model()->findbyPk($model->object_id); if ($object != null) { $tempCommentCount = $object->comment_count; $tempCommentCount--; $object_comment_count = $tempCommentCount; $object->save(); } } } } user()->setFlash('success', t('cms', 'Updated Successfully!')); } } $this->render('cmswidgets.views.comment.comment_update_widget', array('model' => $model)); }
protected function renderContent() { $settings = GxcHelpers::getAvailableSettings(); $type = isset($_GET['type']) ? strtolower(plaintext($_GET['type'])) : 'general'; if (array_key_exists($type, $settings)) { //Import the Setting Class Yii::import('common.settings.' . $type . '.' . $settings[$type]['class']); $model = new $settings[$type]['class'](); foreach ($model->attributes as $attr => $value) { $model->{$attr} = Yii::app()->settings->get($type, $attr); } settings()->deleteCache(); // if it is ajax validation request if (isset($_POST['ajax']) && $_POST['ajax'] === $type . '-settings-form') { echo CActiveForm::validate($model); Yii::app()->end(); } // collect user input data if (isset($_POST[$settings[$type]['class']])) { settings()->deleteCache(); $model->attributes = $_POST[$settings[$type]['class']]; if ($model->validate()) { foreach ($model->attributes as $key => $value) { Yii::app()->settings->set($type, $key, $value); } user()->setFlash('success', t('cms', 'Settings Updated Successfully!')); } } $this->render('common.settings.' . $type . '.' . $settings[$type]['layout'], array('model' => $model)); } else { throw new CHttpException(404, t('cms', 'The requested page does not exist.')); } }
protected function renderContent() { $content_list_id = isset($_GET['id']) ? (int) $_GET['id'] : 0; $model = GxcHelpers::loadDetailModel('ContentList', $content_list_id); // if it is ajax validation request if (isset($_POST['ajax']) && $_POST['ajax'] === 'contentlist-form') { echo CActiveForm::validate($model); Yii::app()->end(); } // collect user input data if (isset($_POST['ContentList'])) { $model->attributes = $_POST['ContentList']; // If this is a manual list, we will add more information about the // manual list if ($model->type == ConstantDefine::CONTENT_LIST_TYPE_MANUAL) { $model->manual_list = isset($_POST['content_list_id']) && is_array($_POST['content_list_id']) ? $_POST['content_list_id'] : array(); if (empty($model->manual_list)) { $model->addError('type', t('Please add content for manual queue')); } } else { $model->manual_list = array(); } if (!$model->hasErrors()) { if ($model->validate()) { if ($model->save()) { user()->setFlash('success', t('Update Content list Successfully!')); } } } } Yii::app()->controller->layout = isset($_GET['embed']) ? 'clean' : 'main'; $this->render('cmswidgets.views.contentlist.contentlist_form_widget', array('model' => $model)); }
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() { if (isset($this->block) && $this->block != null) { $model = new UserAvatarForm(); if (isset($_POST['UserAvatarForm'])) { $model->attributes = $_POST['UserAvatarForm']; $model->image = CUploadedFile::getInstance($model, 'image'); if ($model->validate()) { //Get the User Id to determine the folder $folder = user()->id >= 1000 ? (string) (round(user()->id / 1000) * 1000) : '1000'; $filename = user()->id . '_' . gen_uuid(); if (!(file_exists(AVATAR_FOLDER . DIRECTORY_SEPARATOR . 'root' . DIRECTORY_SEPARATOR . $folder) && AVATAR_FOLDER . DIRECTORY_SEPARATOR . 'root' . DIRECTORY_SEPARATOR . $folder)) { mkdir(AVATAR_FOLDER . DIRECTORY_SEPARATOR . 'root' . DIRECTORY_SEPARATOR . $folder, 0777, true); } if (file_exists(AVATAR_FOLDER . DIRECTORY_SEPARATOR . 'root' . DIRECTORY_SEPARATOR . $folder . DIRECTORY_SEPARATOR . $filename . '.' . strtolower(CFileHelper::getExtension($model->image->name)))) { $filename .= '_' . time(); } $filename = $filename . '.' . strtolower(CFileHelper::getExtension($model->image->name)); $path = $folder . DIRECTORY_SEPARATOR . $filename; if ($model->image->saveAs(AVATAR_FOLDER . DIRECTORY_SEPARATOR . 'root' . DIRECTORY_SEPARATOR . $path)) { //Generate thumbs // GxcHelpers::generateAvatarThumb($filename, $folder, $filename); //So we will start to check the info from the user $current_user = User::model()->findByPk(user()->id); if ($current_user) { if ($current_user->avatar != null && $current_user->avatar != '') { //We will delete the old avatar here $old_avatar_path = $current_user->avatar; $current_user->avatar = $path; if (file_exists(AVATAR_FOLDER . DIRECTORY_SEPARATOR . 'root' . DIRECTORY_SEPARATOR . $old_avatar_path)) { @unlink(AVATAR_FOLDER . DIRECTORY_SEPARATOR . 'root' . DIRECTORY_SEPARATOR . $old_avatar_path); } //Delete old file Sizes $sizes = AvatarSize::getSizes(); foreach ($sizes as $size) { if (file_exists(AVATAR_FOLDER . DIRECTORY_SEPARATOR . $size['id'] . DIRECTORY_SEPARATOR . $old_avatar_path)) { @unlink(AVATAR_FOLDER . DIRECTORY_SEPARATOR . $size['id'] . DIRECTORY_SEPARATOR . $old_avatar_path); } } } else { //$current_user $current_user->avatar = $path; } $current_user->save(); } } else { throw new CHttpException('503', 'Error while uploading!'); } } } $this->render(BlockRenderWidget::setRenderOutput($this), array('model' => $model)); } else { echo ''; } }
public function __construct($id, $module = null) { parent::__construct($id, $module); if (isset($_POST)) { $_POST = GxcHelpers::xss_clean($_POST); } if (isset($_GET)) { $_GET = GxcHelpers::xss_clean($_GET); } }
protected function renderContent() { $model_name = $this->model_name; if ($model_name != '') { $id = isset($_GET['id']) ? (int) $_GET['id'] : 0; $model = GxcHelpers::loadDetailModel($model_name, $id); $this->render(strtolower($model_name) . '/' . strtolower($model_name) . '_view_widget', array('model' => $model)); } else { throw new CHttpException(404, t('cms', 'The requested page does not exist.')); } }
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)); }
public static function deleteModel($model_name, $id) { if (Yii::app()->request->isPostRequest) { // we only allow deletion via POST request GxcHelpers::loadDetailModel($model_name, $id)->delete(); // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser if (!isset($_GET['ajax'])) { $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin')); } } else { throw new CHttpException(400, t('Invalid request. Please do not repeat this request again.')); } }
/** * Check transfer rights * This is called via AJAX when the user is entering the Send button */ public function checkTransferRights($keyword, $type) { $types = GxcHelpers::getAvailableContentType(); $user = User::findPeople($keyword); if ($user != null) { $params['to_user_id'] = $user->user_id; $data = null; Yii::import('common.content_type.' . $type . '.' . $types[$type]['class']); $permissions = $types[$type]['class']::Permissions(); if (GxcContentPermission::checkTransferTo($params, $data, $permissions)) { return "1"; } } return "0"; }
public function workWithBlocks($blocks) { foreach ($blocks as $page_block) { $block = Yii::app()->cache->get('block-render-' . $page_block->block_id); if ($block === false) { $block = GxcHelpers::loadDetailModel('Block', $page_block->block_id); if ($block) { Yii::app()->cache->set('block-render-' . $page_block->block_id, $block, 300); $this->blockRender($block); } } else { $this->blockRender($block); } } }
protected function renderContent() { $block_id = isset($_GET['id']) ? (int) $_GET['id'] : 0; $model = GxcHelpers::loadDetailModel('Block', $block_id); // if it is ajax validation request if (isset($_POST['ajax']) && $_POST['ajax'] === 'block-form') { echo CActiveForm::validate($model); Yii::app()->end(); } $current_type = $model->type; $block_ini = parse_ini_file(Yii::getPathOfAlias('common.blocks.' . $current_type) . DIRECTORY_SEPARATOR . 'info.ini'); //Include the class Yii::import('common.blocks.' . $current_type . '.' . $block_ini['class']); $block_model = new $block_ini['class'](); //We re-init the params of the attributes $block_model->setParams(b64_unserialize($model->params)); // collect user input data if (isset($_POST['Block'])) { $model->attributes = $_POST['Block']; $model->type = $_POST['Block']['type']; $params = $block_model->params(); $block_params = array(); foreach ($params as $key => $param) { $block_params[$key] = $block_model->{$key} = isset($_POST['Block'][$key]) ? $_POST['Block'][$key] : null; } if ($model->validate()) { if (!$block_model->validate()) { foreach ($block_model->errors as $key => $message) { $model->addError($key, $message); } } else { $block_model->beforeBlockSave(); //Re-set params if needed foreach ($params as $key => $param) { $block_params[$key] = $block_model->{$key}; } $model->params = b64_serialize($block_params); if ($model->save()) { $block_model->afterBlockSave(); user()->setFlash('success', t('cms', 'Update Block Successfully!')); } } } } Yii::app()->controller->layout = isset($_GET['embed']) ? 'clean' : 'main'; $this->render('cmswidgets.views.block.block_form_widget', array('model' => $model, 'type' => $current_type, 'block_model' => $block_model)); }
protected function renderContent() { $model = new Taxonomy(); //The type of the content we want to create $type = isset($_GET['type']) ? strtolower(trim($_GET['type'])) : ''; //If it has guid, it means this is a translated version $guid = isset($_GET['guid']) ? strtolower(trim($_GET['guid'])) : ''; //Get the list of Content Type $types = GxcHelpers::getAvailableContentType(); //List of language that should exclude not to translate $lang_exclude = array(); //List of translated versions $versions = array(); if ($type != '' && !array_key_exists($type, $types)) { throw new CHttpException(404, t('Page Not Found')); } else { // 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 != '') { $taxonomy_object = Taxonomy::model()->findAll('guid=:gid', array(':gid' => $guid)); $langs = GxcHelpers::getAvailableLanguages(); if (count($taxonomy_object) > 0) { foreach ($taxonomy_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'] === 'taxonomy-form') { echo CActiveForm::validate($model); Yii::app()->end(); } // collect user input data if (isset($_POST['Taxonomy'])) { $model->attributes = $_POST['Taxonomy']; if ($model->save()) { user()->setFlash('success', t('cms', 'Create new Taxonomy Successfully!')); $model = new Taxonomy(); Yii::app()->controller->redirect(array('create')); } } $this->render('cmswidgets.views.taxonomy.taxonomy_form_widget', array('model' => $model, 'lang_exclude' => $lang_exclude, 'versions' => $versions, 'type' => $type)); } }
public function prepare() { //$this->encodedLayoutName = $this->encode($this->layoutName); $this->encodedLayoutName = GxcHelpers::encode($this->layoutName, '_', false); //The directory where the new code will be generated to $layoutPath = COMMON_FOLDER . DIRECTORY_SEPARATOR . 'front_layouts' . DIRECTORY_SEPARATOR . $this->encodedLayoutName; //Get all the paths of template files $files = CFileHelper::findFiles($this->templatePath); foreach ($files as $file) { //Get the path of new code to be generated $generatedFilePath = $layoutPath . str_replace($this->templatePath, '', $file); //Get the path of template files (in the folder templates) $templateFile = $this->render($file); //code to be generated $this->files[] = new CCodeFile($generatedFilePath, $templateFile); } }
protected function renderContent() { $term_id = isset($_GET['id']) ? (int) $_GET['id'] : 0; $model = GxcHelpers::loadDetailModel('Term', $term_id); // if it is ajax validation request if (isset($_POST['ajax']) && $_POST['ajax'] === 'term-form') { echo CActiveForm::validate($model); Yii::app()->end(); } // collect user input data if (isset($_POST['Term'])) { $model->attributes = $_POST['Term']; if ($model->save()) { user()->setFlash('success', t('cms', 'Update Term Successfully!')); } } Yii::app()->controller->layout = isset($_GET['embed']) ? 'clean' : 'main'; $this->render('cmswidgets.views.term.term_form_widget', array('model' => $model)); }
public function renderPageSlug($slug) { $connection = Yii::app()->db; $command = $connection->createCommand('SELECT * FROM {{page}} WHERE slug=:slug limit 1'); $command->bindValue(':slug', $slug, PDO::PARAM_STR); $page = $command->queryRow(); if ($page) { //We first need to check if having Ajax Request if (isset($_REQUEST['ajax']) && strpos($_REQUEST['ajax'], ConstantDefine::AJAX_BLOCK_SEPERATOR) !== false) { $ajax = explode(ConstantDefine::AJAX_BLOCK_SEPERATOR, plaintext($_REQUEST['ajax'])); $block_id = $ajax[1]; $id = $ajax[0]; $block_ini = parse_ini_file(Yii::getPathOfAlias('common.blocks.' . $id) . DIRECTORY_SEPARATOR . 'info.ini'); //Include the class Yii::import('common.blocks.' . $id . '.' . $block_ini['class']); $layout_asset = GxcHelpers::publishAsset(Yii::getPathOfAlias('common.layouts.' . $page['layout'] . '.assets')); //Get the Block $command = $connection->createCommand('SELECT b.block_id,b.name,b.type,b.params FROM {{block}} b WHERE b.block_id=:bid Limit 1'); $command->bindValue(':bid', $block_id, PDO::PARAM_INT); $block = $command->queryRow(); if ($block !== false) { $this->widget('common.blocks.' . $id . '.' . $block_ini['class'], array('block' => $block, 'page' => $page, 'layout_asset' => $layout_asset)); } else { echo ''; } Yii::app()->end(); } else { $this->layout = 'main'; $this->pageTitle = $page['title']; $this->description = $page['description']; $this->keywords = $page['keywords']; //depend on the layout of the page, use the corresponding file to render $this->renderPage('common.layouts.' . $page['layout'] . '.' . $page['display_type'], array('page' => $page)); } } else { throw new CHttpException('404', t('cms', 'Oops! Page not found!')); } }
protected function renderContent() { $model = new Menu(); //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 != '') { $menu_object = Menu::model()->findAll('guid=:gid', array(':gid' => $guid)); if (count($menu_object) > 0) { $langs = GxcHelpers::getAvailableLanguages(); foreach ($menu_object as $obj) { $lang_exclude[] = $obj->lang; $versions[] = $obj->menu_name . ' - ' . $langs[$obj->lang]['name']; } } $model->guid = $guid; } // if it is ajax validation request if (isset($_POST['ajax']) && $_POST['ajax'] === 'menu-form') { echo CActiveForm::validate($model); Yii::app()->end(); } // collect user input data if (isset($_POST['Menu'])) { $model->attributes = $_POST['Menu']; if ($model->save()) { user()->setFlash('success', t('cms', 'Create new Menu Successfully!')); $model = new Menu(); Yii::app()->controller->redirect(array('create')); } } $this->render('cmswidgets.views.menu.menu_form_widget', array('model' => $model, 'lang_exclude' => $lang_exclude, 'versions' => $versions)); }
protected function renderContent() { $id = isset($_GET['id']) ? (int) $_GET['id'] : 0; $model = GxcHelpers::loadDetailModel('Taxonomy', $id); //The type of the content we want to create $type = $model->type; //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(); $list_items = array(); //Look for the Term Items belong to this Taxonomy $list_terms = Term::model()->findAll(array('select' => '*', 'condition' => 'taxonomy_id=:id', 'order' => 't.parent ASC, t.order ASC, t.term_id ASC', 'params' => array(':id' => $id))); if ($list_terms) { foreach ($list_terms as $term) { $temp_item['id'] = $term->term_id; $temp_item['name'] = CHtml::encode($term->name); $temp_item['parent'] = $term->parent; //Add Item here to make sure Chrome not change the order of Json Object $list_items['item_' . $term->term_id] = $temp_item; } } // if it is ajax validation request if (isset($_POST['ajax']) && $_POST['ajax'] === 'taxonomy-form') { echo CActiveForm::validate($model); Yii::app()->end(); } // collect user input data if (isset($_POST['Taxonomy'])) { $model->attributes = $_POST['Taxonomy']; if ($model->save()) { user()->setFlash('success', t('cms', 'Update Taxonomy Successfully!')); } } $this->render('cmswidgets.views.taxonomy.taxonomy_form_widget', array('model' => $model, 'lang_exclude' => $lang_exclude, 'versions' => $versions, 'type' => $type, 'list_items' => $list_items)); }
public function prepare() { //get the block ID based on the block name. Ex: 'New Example' -> 'new_example' $this->blockID = GxcHelpers::encode($this->blockName, '_', false); $blockPath = COMMON_FOLDER . DIRECTORY_SEPARATOR . 'front_blocks' . DIRECTORY_SEPARATOR . $this->blockID; //Get the block class based on the block name. Ex: 'New Example' -> 'NewExampleBlock' $this->blockClass = GxcHelpers::encode($this->blockName) . 'Block'; //Get the path of new code to be generated $iniPath = $blockPath . DIRECTORY_SEPARATOR . 'info.ini'; $blockInputPath = $blockPath . DIRECTORY_SEPARATOR . $this->blockID . '_block_input.php'; $blockOutputPath = $blockPath . DIRECTORY_SEPARATOR . $this->blockID . '_block_output.php'; $blockClassPath = $blockPath . DIRECTORY_SEPARATOR . $this->blockClass . '.php'; //Get the path of template files (in the folder templates) $iniFile = $this->render($this->templatepath . DIRECTORY_SEPARATOR . 'info.ini'); $blockInputFile = $this->render($this->templatepath . DIRECTORY_SEPARATOR . 'block_input.php'); $blockOutputFile = $this->render($this->templatePath . DIRECTORY_SEPARATOR . 'block_output.php'); $blockClassFile = $this->render($this->templatePath . DIRECTORY_SEPARATOR . 'Block.php'); //generate code $this->files[] = new CCodeFile($iniPath, $iniFile); $this->files[] = new CCodeFile($blockInputPath, $blockInputFile); $this->files[] = new CCodeFile($blockOutputPath, $blockOutputFile); $this->files[] = new CCodeFile($blockClassPath, $blockClassFile); }
protected function renderContent() { //Get some pre value from URL //The type of the content we want to create $type = isset($_GET['type']) ? strtolower(trim($_GET['type'])) : ''; //If it has guid, it means this is a translated version $guid = isset($_GET['guid']) ? strtolower(trim($_GET['guid'])) : ''; //Get the list of Content Type $types = GxcHelpers::getAvailableContentType(); //List of language that should exclude not to translate $lang_exclude = array(); //List of translated versions $versions = array(); //Available Terms for this Object Type $terms = array(); //Selected Terms $selected_terms = array(); //Get Term Order $term_orders = ConstantDefine::getTermOrder(); //If $type is empty then redirect to choose content type page if ($type != '') { //Check if the type appear in content type Definition if (array_key_exists($type, $types)) { // 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 != '') { $temp_object = Object::model()->findAll('guid=:gid', array(':gid' => $guid)); if (count($temp_object) > 0) { foreach ($temp_object as $obj) { $lang_exclude[] = $obj->lang; $langs = GxcHelpers::getAvailableLanguages(); $versions[] = $obj->object_name . ' - ' . $langs[$obj->lang]['name']; } } } //Import the Content Type Class Yii::import('common.content_type.' . $type . '.' . $types[$type]['class']); //Init the class $typeClassObj = new $types[$type]['class'](); $content_resources = $typeClassObj->Resources(); //We start to implement the checking Permission HERE $param_content_check = array(); $data_content_check = array(); $param_content_check['type'] = $type; if (GxcContentPermission::checkCreatePermission($param_content_check, $data_content_check, $typeClassObj->Permissions())) { $param_content_check['new_content'] = true; $content_status = GxcContentPermission::getContentStatus($param_content_check, $data_content_check, $typeClassObj->Permissions()); $model = new $types[$type]['class'](); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); $model->object_date = date('Y-m-d H:i:s'); $model->person = ''; $model->guid = $guid; $get_languages = GxcHelpers::loadLanguageItems($lang_exclude); $available_languages = array(); foreach ($get_languages as $key => $value) { $available_languages[] = $key; } //Get available Taxonomy and Terms for this Object $available_taxonomy = Taxonomy::model()->findAll(' type = :type AND lang IN (' . implode(',', $available_languages) . ') ', array(':type' => $type)); if ($available_taxonomy) { foreach ($available_taxonomy as $t) { $temp = array(); $temp['id'] = $t->taxonomy_id; $temp['lang'] = $t->lang; $temp['name'] = $t->name; $temp['terms'] = array(); //Look for the Term Items belong to this Taxonomy $list_terms = Term::model()->findAll(array('select' => '*', 'condition' => 'taxonomy_id=:id', 'order' => 't.parent ASC, t.order ASC', 'params' => array(':id' => $t->taxonomy_id))); if ($list_terms) { foreach ($list_terms as $term) { $temp_item['id'] = $term->term_id; $temp_item['name'] = CHtml::encode($term->name); $temp_item['parent'] = $term->parent; $temp['terms']['item_' . $term->term_id] = $temp_item; } } $terms[$t->taxonomy_id] = $temp; } } if (isset($_POST[$types[$type]['class']])) { $model->attributes = $_POST[$types[$type]['class']]; //Convert the date time publish to timestamp $model->object_date = strtotime($model->object_date); $model->object_date_gmt = local_to_gmt($model->object_date); //Check which button the User click To Send to person or group $button = $_POST['which_button']; $trans = new Transfer(); // Get the Terms that the User Choose // $post_terms = isset($_POST['terms']) ? $_POST['terms'] : array(); $selected_terms = array(); if (!empty($post_terms)) { foreach ($post_terms as $t) { $t = explode('_', $t); if (!isset($selected_terms[$t[1]])) { $selected_temp = array(); $selected_temp['id'] = $terms[$t[1]]['id']; $selected_temp['lang'] = $terms[$t[1]]['lang']; $selected_temp['name'] = $terms[$t[1]]['name']; $selected_temp['terms']['item_' . $t[0]]['id'] = $t[0]; $selected_temp['terms']['item_' . $t[0]]['name'] = $terms[$t[1]]['terms']['item_' . $t[0]]['name']; $selected_temp['terms']['item_' . $t[0]]['parent'] = $terms[$t[1]]['terms']['item_' . $t[0]]['parent']; $selected_temp['terms']['item_' . $t[0]]['data'] = $t[2]; $selected_temp['terms']['item_' . $t[0]]['data_name'] = $term_orders[$t[2]]; $selected_terms[$t[1]] = $selected_temp; } else { if (!isset($selected_terms['terms']['item_' . $t[0]])) { $selected_terms[$t[1]]['terms']['item_' . $t[0]]['id'] = $t[0]; $selected_terms[$t[1]]['terms']['item_' . $t[0]]['name'] = $terms[$t[1]]['terms']['item_' . $t[0]]['name']; $selected_terms[$t[1]]['terms']['item_' . $t[0]]['parent'] = $terms[$t[1]]['terms']['item_' . $t[0]]['parent']; $selected_terms[$t[1]]['terms']['item_' . $t[0]]['data'] = $t[2]; $selected_terms[$t[1]]['terms']['item_' . $t[0]]['data_name'] = $term_orders[$t[2]]; } } } } // After having the selected Terms, we need to make sure all parents // of the selected Terms must be added also foreach ($selected_terms as $tx_key => $t) { $array_parent_selected_terms = array(); foreach ($t['terms'] as $key => $st_terms) { $current_term = $st_terms; while ($current_term['parent'] != 0) { if (!isset($array_parent_selected_terms['item_' . $current_term['parent']]) && !isset($t['terms']['item_' . $current_term['parent']])) { $array_parent_selected_terms['item_' . $current_term['parent']] = $terms[$tx_key]['terms']['item_' . $current_term['parent']]; $array_parent_selected_terms['item_' . $current_term['parent']]['data'] = key($term_orders); $array_parent_selected_terms['item_' . $current_term['parent']]['data_name'] = $term_orders[key($term_orders)]; } $current_term = $terms[$tx_key]['terms']['item_' . $current_term['parent']]; } } $selected_terms[$tx_key]['terms'] = CMap::mergeArray($t['terms'], $array_parent_selected_terms); } //Re-Set the Status based on what User Chooose //The content is sent to ROLES OR STATUS if ($button == '1') { //Check if the object_status is number or character if (!is_numeric($model->object_status)) { //Set the status to Pending $trans->note = $model->object_status; $model->object_status = ConstantDefine::OBJECT_STATUS_PENDING; $trans->type = ConstantDefine::TRANS_ROLE; $trans->after_status = ConstantDefine::OBJECT_STATUS_PENDING; } else { $trans->type = ConstantDefine::TRANS_STATUS; $trans->after_status = $model->object_status; } $trans->from_user_id = user()->id; $trans->to_user_id = 0; $trans->before_status = ConstantDefine::OBJECT_STATUS_DRAFT; } //The content is sent to PERSON DIRECTLY if ($button == '2') { $to_user_id = User::findPeople($model->person); //Start to Transfer to the user and set the status to Pending if ($to_user_id) { $model->object_status = ConstantDefine::OBJECT_STATUS_PENDING; $trans->from_user_id = user()->id; $trans->to_user_id = $to_user_id->user_id; $trans->type = ConstantDefine::TRANS_PERSON; $trans->before_status = ConstantDefine::OBJECT_STATUS_PENDING; $trans->after_status = ConstantDefine::OBJECT_STATUS_PENDING; } else { $model->addError('person', t('User not found')); } } //Work with Resource Binding $resource = array(); $resource_upload = array(); foreach ($content_resources as $res) { $resource_upload[] = GxcHelpers::getArrayResourceObjectBinding('resource_upload_' . $res['type']); } $i = 0; $count_resource = 0; foreach ($content_resources as $cres) { $j = 1; foreach ($resource_upload[$i] as $res_up) { $j++; $count_resource++; } $i++; } $model->total_number_resource = $count_resource; if ($model->save()) { user()->setFlash('success', t('cms', 'Create new Content Successfully!')); $trans->object_id = $model->object_id; $trans->save(); // We have all the selected Terms for now // We will add them to Object Terms foreach ($selected_terms as $tx_key => $t) { foreach ($t['terms'] as $key => $st_terms) { $obj_term = new ObjectTerm(); $obj_term->object_id = $model->object_id; $obj_term->term_id = $st_terms['id']; $obj_term->data = $st_terms['data']; $obj_term->save(); unset($obj_term); } } //Update Resource Binding Here $i = 0; $count_resource = 0; foreach ($content_resources as $cres) { $j = 1; foreach ($resource_upload[$i] as $res_up) { $obj_res = new ObjectResource(); $obj_res->resource_id = $res_up['resid']; $obj_res->object_id = $model->object_id; $obj_res->description = ''; $obj_res->type = $cres['type']; $obj_res->resource_order = $j; $obj_res->save(); $j++; $count_resource++; } $i++; } //Re-init new Model $model = new $types[$type]['class'](); $model->object_date = date('Y-m-d H:i:s'); Yii::app()->controller->refresh(); } else { $model->object_date = date('Y-m-d H:i:s', $model->object_date); } } $render_template = 'cmswidgets.views.object.object_form_widget'; if (file_exists(Yii::getPathOfAlias('common.content_type.' . strtolower($type) . '.object_form_widget') . '.php')) { $render_template = 'common.content_type.' . strtolower($type) . '.object_form_widget'; } $this->render($render_template, array('model' => $model, 'versions' => $versions, 'lang_exclude' => $lang_exclude, 'content_status' => $content_status, 'terms' => $terms, 'selected_terms' => $selected_terms, 'type' => $type, 'content_resources' => $content_resources)); } } else { //The type is not in Content Type Definition $this->render('cmswidgets.views.object.object_start_widget', array('types' => $types)); } } else { //There is no Type in $_GET $this->render('cmswidgets.views.object.object_start_widget', array('types' => $types)); } }
echo $form->error($model, 'parent'); ?> <script type="text/javascript"> $('#parent_page_select').change(function() { $('#parent_value').val( $('#parent_page_select').val()); $('#form_suggest_page').val( $('#parent_page_select option:selected:first').html()); }); </script> </div> <div class="row"> <?php echo $form->labelEx($model, 'layout'); ?> <?php echo $form->dropDownList($model, 'layout', GxcHelpers::getAvailableLayouts(true), array('id' => 'layout_select', 'options' => $model->layout === null ? array('default' => array('selected' => true)) : array($model->layout => array('selected' => true)))); ?> <?php echo $form->error($model, 'layout'); ?> </div> <div class="row"> <?php echo $form->labelEx($model, 'display_type', array()); ?> <?php
protected function renderContent() { $id = isset($_GET['id']) ? (int) $_GET['id'] : 0; $model = GxcHelpers::loadDetailModel('Object', $id); //We start to implement the checking Permission HERE $param_content_check = array(); $data_content_check = array(); $param_content_check['type'] = $model->object_type; $param_content_check['new_content'] = false; $param_content_check['content_status'] = $model->object_status; $param_content_check['content_author'] = $model->object_author; //Get current trans_to of the object $trans = Transfer::model()->findAll(array('condition' => ' object_id=:obj ', 'params' => array(':obj' => $model->object_id), 'order' => 'transfer_id DESC')); $param_content_check['check_trans_note'] = false; if ($trans != null && count($trans) > 0) { $latest_trans_to = $trans[0]; $param_content_check['trans_type'] = $latest_trans_to->type; $param_content_check['trans_to'] = $latest_trans_to->to_user_id; $param_content_check['trans_note'] = $latest_trans_to->note; } //Get Types list and type of the Object $types = GxcHelpers::getAvailableContentType(); $type = (string) $model->object_type; //Import the Content Type Class Yii::import('common.content_type.' . $type . '.' . $types[$type]['class']); $typeClassObj = new $types[$type]['class'](); $content_resources = $typeClassObj->Resources(); //Check if the User has the Permission to update the Content if (GxcContentPermission::checkUpdatePermission($param_content_check, $data_content_check, $typeClassObj->Permissions())) { //Convert the object date from timestamp to datetime format $model->object_date = date('Y-m-d H:i:s', $model->object_date); //Get available content Status that the Object can be sent to $content_status = GxcContentPermission::getContentStatus($param_content_check, $data_content_check, $typeClassObj->Permissions()); //If the Object is Pending and being sent to someone, get that person info if ($model->object_status == ConstantDefine::OBJECT_STATUS_PENDING) { if ($latest_trans_to->type == ConstantDefine::TRANS_PERSON) { $send_to_user = User::model()->findbyPk($latest_trans_to->to_user_id); if ($send_to_user == null) { $model->person = ''; } else { $model->person = trim($send_to_user->display_name); } } } //Unset value for Lang Exclude, Version and Guid when updating $lang_exclude = array(); $versions = array(); $guid = $model->guid; // Create new instance Object based on Object Type $object = new $types[$type]['class'](); $object->person = $model->person; $object->setAttributes($model->attributes, false); // Get Extra Info - Object Meta of the Object Type $object_metas = ObjectMeta::model()->findAll('meta_object_id = :obj ', array(':obj' => $model->object_id)); foreach ($object_metas as $object_meta) { $key = (string) $object_meta->meta_key; $object->{$key} = $object_meta->meta_value; } // This is not a new Record $object->isNewRecord = false; //Set current tags for Object $object->_oldTags = $object->tags; $object->scenario = 'updateWithTags'; //Available Terms for this Object Type $terms = array(); //Selected Terms $selected_terms = array(); //Get Term Order $term_orders = ConstantDefine::getTermOrder(); //Get available Taxonomy and Terms for this Object $available_taxonomy = Taxonomy::model()->findAll(' type = :type AND lang IN (' . $object->lang . ') ', array(':type' => $type)); if ($available_taxonomy) { foreach ($available_taxonomy as $t) { $temp = array(); $temp['id'] = $t->taxonomy_id; $temp['lang'] = $t->lang; $temp['name'] = $t->name; $temp['terms'] = array(); $selected_temp = array(); $selected_temp['id'] = $t->taxonomy_id; $selected_temp['lang'] = $t->lang; $selected_temp['name'] = $t->name; $selected_temp['terms'] = array(); //Look for the Term Items belong to this Taxonomy $list_terms = Term::model()->findAll(array('select' => '*', 'condition' => 'taxonomy_id=:id', 'order' => 't.parent ASC, t.order ASC', 'params' => array(':id' => $t->taxonomy_id))); if ($list_terms) { foreach ($list_terms as $term) { $temp_item['id'] = $term->term_id; $temp_item['name'] = CHtml::encode($term->name); $temp_item['parent'] = $term->parent; $temp['terms']['item_' . $term->term_id] = $temp_item; } } $terms[$t->taxonomy_id] = $temp; //Look for selected Terms belong to this Taxonomy $sl_terms = ObjectTerm::model()->findAll(array('select' => '*', 'condition' => 'object_id=:id', 'params' => array(':id' => $object->object_id))); if ($sl_terms) { foreach ($sl_terms as $sl_term) { if (isset($terms[$t->taxonomy_id]['terms']['item_' . $sl_term->term_id])) { $selected_temp['terms']['item_' . $sl_term->term_id] = $terms[$t->taxonomy_id]['terms']['item_' . $sl_term->term_id]; $selected_temp['terms']['item_' . $sl_term->term_id]['data'] = $sl_term->data; $selected_temp['terms']['item_' . $sl_term->term_id]['data_name'] = $term_orders[$sl_term->data]; } } } $selected_terms[$t->taxonomy_id] = $selected_temp; } } //IF having the Post Method - Start to working to save it if (isset($_POST[$types[$type]['class']])) { $object->attributes = $_POST[$types[$type]['class']]; //Convert the date time publish to timestamp $object->object_date = strtotime($object->object_date); $object->object_date_gmt = local_to_gmt($object->object_date); //Check which button the User click To Send to person or group $button = $_POST['which_button']; $trans = new Transfer(); // Get the Terms that the User Choose $post_terms = isset($_POST['terms']) ? $_POST['terms'] : array(); $selected_terms = array(); if (!empty($post_terms)) { foreach ($post_terms as $t) { $t = explode('_', $t); if (!isset($selected_terms[$t[1]])) { $selected_temp = array(); $selected_temp['id'] = $terms[$t[1]]['id']; $selected_temp['lang'] = $terms[$t[1]]['lang']; $selected_temp['name'] = $terms[$t[1]]['name']; $selected_temp['terms']['item_' . $t[0]]['id'] = $t[0]; $selected_temp['terms']['item_' . $t[0]]['name'] = $terms[$t[1]]['terms']['item_' . $t[0]]['name']; $selected_temp['terms']['item_' . $t[0]]['parent'] = $terms[$t[1]]['terms']['item_' . $t[0]]['parent']; $selected_temp['terms']['item_' . $t[0]]['data'] = $t[2]; $selected_temp['terms']['item_' . $t[0]]['data_name'] = $term_orders[$t[2]]; $selected_terms[$t[1]] = $selected_temp; } else { if (!isset($selected_terms['terms']['item_' . $t[0]])) { $selected_terms[$t[1]]['terms']['item_' . $t[0]]['id'] = $t[0]; $selected_terms[$t[1]]['terms']['item_' . $t[0]]['name'] = $terms[$t[1]]['terms']['item_' . $t[0]]['name']; $selected_terms[$t[1]]['terms']['item_' . $t[0]]['parent'] = $terms[$t[1]]['terms']['item_' . $t[0]]['parent']; $selected_terms[$t[1]]['terms']['item_' . $t[0]]['data'] = $t[2]; $selected_terms[$t[1]]['terms']['item_' . $t[0]]['data_name'] = $term_orders[$t[2]]; } } } } // After having the selected Terms, we need to make sure all parents // of the selected Terms must be added also foreach ($selected_terms as $tx_key => $t) { $array_parent_selected_terms = array(); foreach ($t['terms'] as $key => $st_terms) { $current_term = $st_terms; while ($current_term['parent'] != 0) { if (!isset($array_parent_selected_terms['item_' . $current_term['parent']]) && !isset($t['terms']['item_' . $current_term['parent']])) { $array_parent_selected_terms['item_' . $current_term['parent']] = $terms[$tx_key]['terms']['item_' . $current_term['parent']]; $array_parent_selected_terms['item_' . $current_term['parent']]['data'] = key($term_orders); $array_parent_selected_terms['item_' . $current_term['parent']]['data_name'] = $term_orders[key($term_orders)]; } $current_term = $terms[$tx_key]['terms']['item_' . $current_term['parent']]; } } $selected_terms[$tx_key]['terms'] = CMap::mergeArray($t['terms'], $array_parent_selected_terms); } //Re-Set the Status based on what User Chooose //The content is sent to ROLES OR STATUS if ($button == '1') { //Check if the object_status is number or character if (!is_numeric($object->object_status)) { //Set the status to Pending $trans->note = $object->object_status; $object->object_status = ConstantDefine::OBJECT_STATUS_PENDING; $trans->type = ConstantDefine::TRANS_ROLE; $trans->after_status = ConstantDefine::OBJECT_STATUS_PENDING; } else { $trans->type = ConstantDefine::TRANS_STATUS; $trans->after_status = $object->object_status; } $trans->from_user_id = user()->id; $trans->to_user_id = 0; $trans->before_status = ConstantDefine::OBJECT_STATUS_DRAFT; } //The content is sent to PERSON DIRECTLY if ($button == '2') { $to_user_id = User::findPeople($object->person); //Start to Transfer to the user and set the status to Pending if ($to_user_id) { $object->object_status = ConstantDefine::OBJECT_STATUS_PENDING; $trans->from_user_id = user()->id; $trans->to_user_id = $to_user_id->user_id; $trans->type = ConstantDefine::TRANS_PERSON; $trans->before_status = ConstantDefine::OBJECT_STATUS_PENDING; $trans->after_status = ConstantDefine::OBJECT_STATUS_PENDING; } else { $object->addError('person', t('User not found')); } } //Work with Resource Binding $resource = array(); $resource_upload = array(); foreach ($content_resources as $res) { $resource_upload[] = GxcHelpers::getArrayResourceObjectBinding('resource_upload_' . $res['type']); } $i = 0; $count_resource = 0; foreach ($content_resources as $cres) { $j = 1; foreach ($resource_upload[$i] as $res_up) { $j++; $count_resource++; } $i++; } $object->total_number_resource = $count_resource; if ($object->save()) { user()->setFlash('success', t('cms', 'Update content Successfully!')); $trans->object_id = $object->object_id; $trans->save(); //This is the update process, we should delete old //Object Term binding ObjectTerm::model()->deleteAll('object_id = :id', array(':id' => $object->object_id)); // We have all the selected Terms for now // We will add them to Object Terms foreach ($selected_terms as $tx_key => $t) { foreach ($t['terms'] as $key => $st_terms) { $obj_term = new ObjectTerm(); $obj_term->object_id = $object->object_id; $obj_term->term_id = $st_terms['id']; $obj_term->data = $st_terms['data']; $obj_term->save(); unset($obj_term); } } //Re update for Resource ObjectResource::model()->deleteAll('object_id = :id', array(':id' => $object->object_id)); $i = 0; $count_resource = 0; foreach ($content_resources as $cres) { $j = 1; foreach ($resource_upload[$i] as $res_up) { $obj_res = new ObjectResource(); $obj_res->resource_id = $res_up['resid']; $obj_res->object_id = $object->object_id; $obj_res->description = ''; $obj_res->type = $cres['type']; $obj_res->resource_order = $j; $obj_res->save(); $j++; $count_resource++; } $i++; } } $object->object_date = date('Y-m-d H:i:s', $object->object_date); } //Start Render the Form $render_template = 'cmswidgets.views.object.object_form_widget'; if (file_exists(Yii::getPathOfAlias('common.content_type.' . strtolower($type) . '.object_form_widget') . '.php')) { $render_template = 'common.content_type.' . strtolower($type) . '.object_form_widget'; } $this->render($render_template, array('model' => $object, 'versions' => $versions, 'lang_exclude' => $lang_exclude, 'content_status' => $content_status, 'terms' => $terms, 'selected_terms' => $selected_terms, 'type' => $type, 'content_resources' => $content_resources)); } }
/** * Function to Get Remote File **/ public static function getRemoteFile(&$resource, $model, &$process, &$message, $path, $ext, $changeresname = true, $max_size, $min_size, $allow = array()) { if (GxcHelpers::remoteFileExists($path)) { $storages = GxcHelpers::getStorages(true); $upload_handle = new $storages[$model->where]($max_size, $min_size, $allow); if (!$upload_handle->getRemoteFile($resource, $model, $process, $message, $path, $ext, true)) { $model->addError('upload', $message); } else { $process = true; return true; } } else { $process = false; $message = t('cms', 'Remote file not exist'); return false; } }
public static function ajaxDeleteModel($id) { if (Yii::app()->request->isPostRequest) { //First make sure that there is no children category $model = GxcHelpers::loadDetailModel('MenuItem', $id); if ($model->delete()) { echo json_encode(array('result' => t('cms', 'success'), 'message' => '')); } else { echo json_encode(array('result' => t('cms', 'error'), 'message' => t('cms', 'Error while Deleting!'))); } } else { echo json_encode(array('result' => t('cms', 'error'), 'message' => t('cms', 'Error! Invalid Request!'))); } Yii::app()->end(); }
<?php $this->widget('zii.widgets.grid.CGridView', array('id' => 'taxonomy-grid', 'dataProvider' => $model->search(), 'filter' => $model, 'summaryText' => t('cms', 'Displaying') . ' {start} - {end} ' . t('cms', 'in') . ' {count} ' . t('cms', 'results'), 'pager' => array('header' => t('cms', 'Go to page:'), 'nextPageLabel' => t('cms', 'Next'), 'prevPageLabel' => t('cms', 'previous'), 'firstPageLabel' => t('cms', 'First'), 'lastPageLabel' => t('cms', 'Last'), 'pageSize' => Yii::app()->settings->get('system', 'page_size')), 'columns' => array(array('name' => 'taxonomy_id', 'type' => 'raw', 'htmlOptions' => array('class' => 'gridmaxwidth'), 'value' => '$data->taxonomy_id'), array('name' => 'name', 'type' => 'raw', 'htmlOptions' => array('class' => 'gridLeft'), 'value' => 'CHtml::link($data->name,array("' . app()->controller->id . '/view","id"=>$data->taxonomy_id))'), array('name' => 'description', 'type' => 'raw', 'htmlOptions' => array('class' => 'gridLeft'), 'value' => '$data->description'), array('name' => 'type', 'type' => 'raw', 'htmlOptions' => array('class' => 'gridLeft gridmaxwidth'), 'value' => 'Object::convertObjectType($data->type)'), array('name' => 'lang', 'type' => 'raw', 'value' => 'GxcHelpers::convertLanguage($data->lang)'), array('class' => 'CButtonColumn', 'template' => '{translate}', 'visible' => count(GxcHelpers::getAvailableLanguages() > 1), 'buttons' => array('translate' => array('label' => t('cms', 'Translate'), 'imageUrl' => false, 'url' => 'Yii::app()->createUrl("' . app()->controller->id . '/create", array("guid"=>$data->guid,"type"=>$data->type))'))), array('class' => 'CButtonColumn', 'template' => '{update}', 'buttons' => array('update' => array('label' => t('cms', 'Edit'), 'imageUrl' => false, 'url' => 'Yii::app()->createUrl("' . app()->controller->id . '/update", array("id"=>$data->taxonomy_id))'))), array('class' => 'CButtonColumn', 'template' => '{delete}', 'buttons' => array('delete' => array('label' => t('cms', 'Delete'), 'imageUrl' => false))))));
<?php $this->widget('zii.widgets.CDetailView', array('data' => $model, 'attributes' => array(array('name' => 'menu_id', 'type' => 'raw', 'value' => $model->menu_id), array('name' => 'menu_name', 'type' => 'raw', 'value' => CHtml::link($model->menu_name, array("update", "id" => $model->menu_id))), 'menu_description', array('name' => 'lang', 'type' => 'raw', 'value' => GxcHelpers::convertLanguage($model->lang)))));
public static function ajaxDeleteModel($id) { if (Yii::app()->request->isPostRequest) { //First make sure that there is no children category $model = GxcHelpers::loadDetailModel('Term', $id); $model_childs = Term::model()->find('parent = :parent_id', array(':parent_id' => $model->term_id)); if (!$model_childs) { $model->delete(); echo json_encode(array('result' => t('success'), 'message' => '')); } else { echo json_encode(array('result' => t('error'), 'message' => t('Error! Please delete its children first!'))); } } else { echo json_encode(array('result' => t('error'), 'message' => t('Error! Invalid Request!'))); } Yii::app()->end(); }