本文整理汇总了PHP中Object::model方法的典型用法代码示例。如果您正苦于以下问题:PHP Object::model方法的具体用法?PHP Object::model怎么用?PHP Object::model使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Object
的用法示例。
在下文中一共展示了Object::model方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: renderContent
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));
}
示例2: renderContent
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 '';
}
}
示例3: actionDelete
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));
}
}
示例4: renderContent
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 '';
}
}
示例5: renderContent
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'];
//.........这里部分代码省略.........
示例6: getContentList
/**
* 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;
}
示例7: suggestContent
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();
}
示例8: model
/**
* 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);
}
示例9: loadPublishedModel
/**
* 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.');
}
}
}
示例10: suggestContent
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);
}
}
}
示例11: buildLink
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;
}
}
示例12: array
<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){
示例13: getContentList
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;
}
示例14: beforeSave
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;
}
}