Returns the static model of the specified AR class.
public static model ( $className = __CLASS__ ) : Object | ||
리턴 | Object | the static model class |
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() { if (isset($this->block) && $this->block != null) { //Set Params from Block Params $params = unserialize($this->block->params); $this->setParams($params); $post_id = (int) $_GET['id']; if ($post_id) { $post = Object::model()->findByPk($post_id); if ($post) { Yii::app()->controller->pageTitle = CHtml::encode($post->object_name); Yii::app()->controller->description = CHtml::encode($post->object_description); Yii::app()->controller->keywords = CHtml::encode($post->object_keywords); Yii::app()->controller->change_title = true; $this->render(BlockRenderWidget::setRenderOutput($this), array('post' => $post)); } else { throw new CHttpException('404', t('Page not found')); } } else { throw new CHttpException('404', t('Page not found')); } } else { echo ''; } }
public function actionDelete($id, $page) { $model = $this->loadModel($id); if (isset($model) && $model->delete()) { if ($model->comment_approved == Comment::STATUS_APPROVED) { $object = Object::model()->findbyPk($model->object_id); if ($object != null) { $temp_comment_count = $object->comment_count; $temp_comment_count--; $object->comment_count = $temp_comment_count; $object->save(); } } $this->redirect(array('admin?comments_page=' . $page . '#comment_id_' . $id)); } }
protected function renderContent() { if (isset($this->block) && $this->block != null) { //Set Params from Block Params $params = unserialize($this->block->params); $this->setParams($params); $post_id = (int) $_GET['id']; if ($post_id) { $post = Object::model()->findByPk($post_id); if ($post) { $this->render(BlockRenderWidget::setRenderOutput($this), array('post' => $post)); } else { throw new CHttpException('404', t('Page not found')); } } else { throw new CHttpException('404', t('Page not found')); } } else { echo ''; } }
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)); } }
/** * Function to get Object Content List **/ public static function getContentList($cl_id, $max = null, $paging = null, $return_type = ConstantDefine::CONTENT_LIST_RETURN_ACTIVE_RECORD) { $model = ContentList::model()->findByPk($cl_id); //Find the content list model first $condition = 't.object_status = :status and t.object_date < :time'; $params = array(':status' => ConstantDefine::OBJECT_STATUS_PUBLISHED, ':time' => time()); if ($paging == 0) { $page_number = 1; } else { $page_number = $model->paging; } if (isset($model)) { if ($model->type == ConstantDefine::CONTENT_LIST_TYPE_AUTO) { //auto $criteria_field = 'object_date DESC'; //object_type if (isset($model->content_type)) { $content_types = $model->content_type; if ($content_types[0] != 'all') { $condition .= ' AND (0'; foreach ($content_types as $type) { $condition .= ' or object_type="' . $type . '"'; } $condition .= ')'; } } //terms if (isset($model->terms)) { $content_terms = $model->terms; if ($content_terms[0] != '0') { $condition .= ' AND (0'; foreach ($content_terms as $term) { $condition .= ' or (object_id in (select object_id from `{{object_term}}` where term_id=' . $term . '))'; } $condition .= ')'; } } //tags if (isset($model->tags) && $model->tags != '') { $tags = $model->tags; $tag_list = explode(',', $tags); $tag_id_list = ''; foreach ($tag_list as $k => $tag_name) { if ($tag_name == ' ') { unset($tag_list[$k]); } } foreach ($tag_list as $k => $tag_name) { if ($tag_name != ' ') { $id = Yii::app()->db->createCommand()->select('id')->from('gxc_tag')->where('name=:name', array(':name' => trim($tag_name)))->queryRow(); $tag_id_list .= $id['id']; if ($k != sizeof($tag_list) - 1) { $tag_id_list .= ','; } } } $condition .= ' or (object_id in (select object_id from `{{tag_relationships}}` where tag_id in (' . $tag_id_list . ')))'; } //criteria not newest if ($model->criteria != ConstantDefine::CONTENT_LIST_CRITERIA_NEWEST) { $criteria_field = 'object_view DESC'; } if ($return_type == ConstantDefine::CONTENT_LIST_RETURN_DATA_PROVIDER && $model->number >= 1) { $sort = new CSort('Object'); $sort->defaultOrder = 't.object_date DESC'; $sort->attributes = array('object_view' => array('asc' => 'object_view ASC', 'desc' => 'object_view DESC'), 'object_date' => array('asc' => 't.object_date ASC', 'desc' => 't.object_date DESC')); return new CActiveDataProvider('Object', array('criteria' => array('condition' => $condition, 'order' => $criteria_field, 'params' => $params, 'limit' => isset($max) ? $max : $model->number), 'pagination' => array('pageSize' => isset($max) ? $max : $model->number * $page_number, 'pageVar' => 'page'), 'sort' => $sort)); } return Object::model()->findAll(array('condition' => $condition, 'params' => $params, 'order' => $criteria_field, 'limit' => isset($max) ? $max : $model->number)); } else { //manual if (isset($model->manual_list)) { $condition = ''; $manual_list = $model->manual_list; $count = 0; $max = count($manual_list); foreach ($manual_list as $manual_id) { if ($count == 0) { $condition_string = $manual_id; } else { $condition_string .= ',' . $manual_id; } if (isset($max) && $count == $max) { break; } $count++; } $condition = 'object_id IN (' . $condition_string . ')'; if ($return_type == ConstantDefine::CONTENT_LIST_RETURN_DATA_PROVIDER && count($manual_list) >= 1) { return new CActiveDataProvider('Object', array('criteria' => array('condition' => $condition, 'params' => $params, 'order' => 'FIELD(t.object_id, ' . $condition_string . ')'), 'pagination' => array('pageSize' => isset($max) ? $max : $model->number * $page_number, 'pageVar' => 'page'))); } return Object::model()->findAll(array('condition' => $condition, 'params' => $params, 'order' => 'FIELD(t.object_id, ' . $condition_string . ')')); } } } return null; }
public static function suggestContent() { $keyword = ''; if (isset($_GET['q']) && ($keyword = trim($_GET['q'])) !== '') { $names = Object::model()->suggestContent($keyword); if ($names !== array()) { echo implode("\n", $names); } } Yii::app()->end(); }
/** * Returns the static model of the specified AR class. * @return Object the static model class */ public static function model($className = __CLASS__) { return parent::model($className); }
/** * Load Object that has been published and time is <= time() * @param type $id * @return type */ public static function loadPublishedModel($id) { $model = Object::model()->findByPk((int) $id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } else { if ($model->object_status == ConstantDefine::OBJECT_STATUS_PUBLISHED && $model->object_date <= time()) { return $model; } else { throw new CHttpException(404, 'The requested page does not exist.'); } } }
public static function suggestContent() { if (isset($_GET['q']) && ($keyword = trim($_GET['q'])) !== '') { $type = isset($_GET['type']) ? trim($_GET['type']) : ''; $tags = Object::model()->suggestContent($keyword, $type); if ($tags !== array()) { echo implode("\n", $tags); } } }
public static function buildLink($item) { switch ($item->type) { case ConstantDefine::MENU_TYPE_URL: return $item->value; break; case ConstantDefine::MENU_TYPE_PAGE: $page = Page::model()->findByPk(array($item->value)); if ($page) { return FRONT_SITE_URL . '/' . $page->slug; } else { return 'javascript:void(0);'; } break; case ConstantDefine::MENU_TYPE_CONTENT: $content = Object::model()->findByPk($item->value); if ($content) { return $content->getObjectLink(); } else { return 'javascript:void(0);'; } break; case ConstantDefine::MENU_TYPE_TERM: break; case ConstantDefine::MENU_TYPE_STRING: return $item->value; break; default: return $item->value; break; } }
<div class="clear"></div> </div> <ul id="content_list_manual"> </ul> <script type="text/javascript"> <?php if (is_array($model->manual_list) && !empty($model->manual_list) > 0) { ?> //Start to get the content based on the ids <?php $content_items = array(); foreach ($model->manual_list as $obj_id) { $temp_object = Object::model()->findByPk($obj_id); if ($temp_object) { $content_items['item_' . $temp_object->object_id]['id'] = $temp_object->object_id; $content_items['item_' . $temp_object->object_id]['title'] = $temp_object->object_name; } } echo 'var manual_content_list = ' . json_encode($content_items) . ';'; ?> $.each(manual_content_list, function(k,v) { setContentList(v.title,v.id); }); <?php } ?> function setContentList(linkTitle,linkId){
public static function getContentList($content_list_id, $max = null, $pagination = null, $return_type = ConstantDefine::CONTENT_LIST_RETURN_ACTIVE_RECORD) { //Find the content list model first $model = ContentList::model()->findbyPk($content_list_id); $condition = 't.object_status = :status and t.object_date < :time'; $params = array(':status' => ConstantDefine::OBJECT_STATUS_PUBLISHED, ':time' => time()); if (isset($model)) { if ($model->type == ConstantDefine::CONTENT_LIST_TYPE_AUTO) { //auto $criteria_field = 'object_date DESC'; //object_type if (isset($model->content_type)) { $content_types = $model->content_type; if ($content_types[0] != 'all') { $condition .= ' AND (0'; foreach ($content_types as $type) { $condition .= ' or object_type="' . $type . '"'; } $condition .= ')'; } } //terms if (isset($model->terms)) { $content_terms = $model->terms; if ($content_terms[0] != '0') { $condition .= ' AND (0'; foreach ($content_terms as $term) { $condition .= ' or (ID in (select object_id from `{{object_term}}` where term_id=' . $term . '))'; } $condition .= ')'; } } //criteria not newest if ($model->criteria != ConstantDefine::CONTENT_LIST_CRITERIA_NEWEST) { $criteria_field = 'object_view DESC'; } if ($return_type == ConstantDefine::CONTENT_LIST_RETURN_DATA_PROVIDER && $model->number > 1) { $sort = new CSort('Object'); $sort->defaultOrder = 't.object_date DESC'; $sort->attributes = array('object_view' => array('asc' => 'object_view ASC', 'desc' => 'object_view DESC'), 'object_date' => array('asc' => 't.object_date ASC', 'desc' => 't.object_date DESC')); return new CActiveDataProvider('Object', array('criteria' => array('condition' => $condition, 'order' => $criteria_field, 'params' => $params, 'limit' => isset($max) ? $max : $model->number), 'pagination' => array('pageSize' => isset($max) ? $max : $model->number * $model->paging, 'pageVar' => 'page'), 'sort' => $sort)); } return Object::model()->findAll(array('condition' => $condition, 'params' => $params, 'order' => $criteria_field, 'limit' => isset($max) ? $max : $model->number)); } //manual if (isset($model->manual_list_id)) { $condition = ''; $manual_list = explode(',', $model->manual_list_id); $count = 0; foreach ($manual_list as $manual_id) { //$condition .= ' OR ID = '.$manual_id; if ($count == 0) { $condition = 'ID =' . $manual_id; } else { $condition .= ' union select * from {{object}} where id=' . $manual_id; } if (isset($max) && $count == $max) { break; } $count++; } if ($return_type == ConstantDefine::CONTENT_LIST_RETURN_DATA_PROVIDER && count($manual_list) > 1) { return new CActiveDataProvider('Object', array('criteria' => array('condition' => $condition, 'params' => $params), 'pagination' => array('pageSize' => isset($max) ? $max : $model->number * $model->paging, 'pageVar' => 'page'))); } return Object::model()->findAll(array('condition' => $condition, 'params' => $params)); } } return null; }
protected function beforeSave() { if (parent::beforeSave()) { if ($this->isNewRecord) { //Update the create_time, status and object_id $this->create_time = time(); $this->status = ConstantDefine::COMMENT_STATUS_PENDING; $this->object_id = (int) $_GET['id']; //Increase the object's comment_count by 1 $object = Object::model()->findByPk($this->object_id); if ($object != null) { $object->increaseCommentCount(); } else { return false; } } return true; } else { return false; } }