本文整理匯總了PHP中ContentModel::relation方法的典型用法代碼示例。如果您正苦於以下問題:PHP ContentModel::relation方法的具體用法?PHP ContentModel::relation怎麽用?PHP ContentModel::relation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ContentModel
的用法示例。
在下文中一共展示了ContentModel::relation方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: push
/**
* 文章推送
*/
public function push()
{
if (IS_POST) {
$id = $this->_post("id");
$modelid = $this->_post('modelid');
$catid = $this->_post("catid");
$action = $this->_get("action");
if (!$id || !$action || !$modelid || !$catid) {
$this->error("參數不正確");
}
switch ($action) {
//推薦位
case "position_list":
$posid = $_POST['posid'];
if ($posid && is_array($posid)) {
$position_data_db = D('Position');
$fields = F("Model_field_" . $modelid);
$tablename = ucwords($this->Model[$modelid]['tablename']);
if (!$tablename) {
$this->error("模型不能為空!");
}
$ids = explode("|", $id);
$Content = new ContentModel($tablename);
foreach ($ids as $k => $aid) {
//取得信息
$re = $Content->relation(true)->where(array("id" => $aid))->find();
if ($re) {
//文章信息
$r = array_merge($re, $re[$tablename . '_data']);
unset($r[$tablename . '_data']);
//推送數據
$textcontent = array();
foreach ($fields as $_key => $_value) {
//判斷字段是否入庫到推薦位字段
if ($_value['isposition']) {
$textcontent[$_key] = $r[$_key];
}
}
//推送到推薦位
$status = $position_data_db->position_update($id, $modelid, $catid, $posid, $textcontent);
if ($status) {
//更新信息推薦位標識
$Content->relation(true)->where(array("id" => $aid))->save(array("posids" => 1));
}
}
}
$this->success("推送到推薦位成功!");
} else {
$this->error("請選擇推薦位!");
}
break;
//同步發布到其他欄目
//同步發布到其他欄目
case "push_to_category":
$ids = explode("|", $id);
$relation = $this->_post("relation");
if (!$relation) {
$this->error("請選擇需要推送的欄目!");
}
$relation = explode("|", $relation);
if (is_array($relation)) {
//過濾相同欄目和自身欄目
foreach ($relation as $k => $classid) {
if ($classid == $catid) {
unset($relation[$k]);
}
}
//去除重複
$relation = array_unique($relation);
if (count($relation) < 1) {
$this->error("請選擇需要推送的欄目!");
}
$tablename = ucwords($this->Model[$modelid]['tablename']);
if (!$tablename) {
$this->error("模型不能為空!");
}
$Content = new ContentModel($tablename);
import('Content');
$ContentAPI = new Content();
foreach ($ids as $k => $aid) {
//取得信息
$r = $Content->relation(true)->where(array("id" => $aid))->find();
$linkurl = $r['url'];
if ($r) {
$ContentAPI->othor_catid($relation, $linkurl, $r, $modelid);
}
}
$this->success("推送其他欄目成功!");
} else {
$this->error("請選擇需要推送的欄目!");
}
break;
default:
$this->error("請選擇操作!");
break;
}
} else {
//.........這裏部分代碼省略.........
示例2: create
public function create()
{
unset($_GET['_URL_']);
if (isset($_GET['start'])) {
//每輪更新數
$pagesize = (int) $this->_get("pagesize");
$_GET['pagesize'] = $pagesize = $pagesize > 1 ? $pagesize : 100;
//模型
$_GET['modelid'] = $modelid = (int) $this->_get("modelid");
//第幾輪更新
$page = $_GET['start'] = (int) $this->_get("start");
//總共幾輪
$pages = (int) $this->_get("pages");
//信息總數
$total = (int) $this->_get("total");
$model = F("Model");
//如果是重建所有模型
if ($modelid) {
$table_name = ucwords($model[$modelid]['tablename']);
if (!$table_name) {
$this->error("該模型不存在!");
}
$ContentDb = new ContentModel($table_name);
if (!in_array($modelid, $this->config['modelid'])) {
$this->error("該模型無需重建!");
}
//取得總數
if (!isset($_GET['total'])) {
$count = $ContentDb->where(array("status" => 99))->count();
//信息總數
$total = $_GET['total'] = $count;
//總共幾輪
$pages = $_GET['pages'] = ceil($_GET['total'] / $pagesize);
//初始第一輪更新
$page = $_GET['start'] = 1;
}
$page = max(intval($page), 1);
$offset = $pagesize * ($page - 1);
$data = $ContentDb->relation(true)->where(array("status" => 99))->order(array("id" => "ASC"))->limit($offset . "," . $pagesize)->select();
if (!$data) {
$data = array();
}
//數據處理
foreach ($data as $r) {
//組合數據
$inputinfo = array();
$inputinfo['system'] = $r;
$inputinfo['model'] = $r[$table_name . "_data"];
$id = $r['id'];
$this->db->search_api($id, $inputinfo, $modelid);
}
if ($pages == $page || $page > $pages) {
$this->success("更新完成! ...", U("Search/create"));
exit;
}
if ($pages > $page) {
$page++;
$_GET['start'] = $page;
$creatednum = $offset + count($data);
$percent = round($creatednum / $total, 2) * 100;
$message = "有 <font color=\"red\">{$total}</font> 條信息 - 已完成 <font color=\"red\">{$creatednum}</font> 條(<font color=\"red\">{$percent}%</font>)";
$forward = U("Search/create", $_GET);
$this->assign("waitSecond", 200);
$this->success($message, $forward);
exit;
}
} else {
//當沒有選擇模型更新時,進行全部可用模型數據更新
$modelArr = $this->config['modelid'];
$autoid = $this->_get("autoid");
$autoid = $_GET['autoid'] ? intval($_GET['autoid']) : 0;
if (!isset($modelArr[$autoid])) {
$this->success("更新完成! ...", U("Search/create"));
exit;
}
$modelid = $modelArr[$autoid];
$table_name = ucwords($model[$modelid]['tablename']);
if (!$table_name) {
$this->error("該模型不存在!");
}
$ContentDb = new ContentModel($table_name);
//取得總數
if (!isset($_GET['total'])) {
$count = $ContentDb->where(array("status" => 99))->count();
//信息總數
$total = $_GET['total'] = $count;
//總共幾輪
$pages = $_GET['pages'] = ceil($_GET['total'] / $pagesize);
//初始第一輪更新
$page = $_GET['start'] = 1;
}
$page = max(intval($page), 1);
$offset = $pagesize * ($page - 1);
$data = $ContentDb->relation(true)->where(array("status" => 99))->order(array("id" => "ASC"))->limit($offset . "," . $pagesize)->select();
if (!$data) {
$data = array();
}
//數據處理
foreach ($data as $r) {
//組合數據
//.........這裏部分代碼省略.........