public function getTimeContentStatistics($filter, $days_count) { $days_count = intval($days_count); $days_count = 20; if (!$days_count) { return; } $start_time = date('Y-m-d', strtotime("-" . $days_count . "day")); $end_time = date('Y-m-d', time()); $field = 'count(id) as count, date_format(create_time, "%Y-%m-%d") as start_time'; $filter['parent_id'] = array('gt', 0); $filter['create_time'] = array('gt', $start_time); $map['group'] = 'start_time'; $cateogry_ids = explode(',', $filter['category_id']); foreach ($cateogry_ids as $category_id) { $filter['category_id'] = $category_id; $pages = D('Content')->getContentStatistics($filter, $map, $field); //获取文章在统计天数前的总量 $filter['create_time'] = array('lt', $start_time); $content_count_before_start = D('Content')->where($filter)->count(); $pages = ass_column($pages, "start_time"); for ($i = 1; $i <= $days_count; $i++) { $current_time = date('Y-m-d', strtotime($end_time)); $times[] = array('create_time' => $current_time, 'child_content_count' => intval($pages[$current_time]['count'])); $end_time = date('Y-m-d', strtotime("-" . $i . "day")); } $result[$category_id] = $times; } return $result; }
public function getTagsWeight($object_type) { settype($object_type, 'array'); $object_type_str = implode(',', $object_type); $sql = 'SELECT tag_id tag_id, name, COUNT(*) count FROM jxdrcms_tag t, jxdrcms_tag_mapping tm WHERE t.id = tm.tag_id and tm.object_type in (' . $object_type_str . ') GROUP BY tag_id order by count desc'; $rs = ass_column($this->query($sql, true), 'tag_id'); return $rs; }
public function getRelatedContents($content, $size = 6, $exclude_category_ids = array()) { if (!$content) { return; } //获取tag中的文章 $tag_ids = array_keys($content['tags']); if ($tag_ids) { $tag_cond['tag_id'] = array('in', $tag_ids); $tag_mappings = D('TagMapping')->where($tag_cond)->page(1, $rsize)->select(); $content_ids = get_column($tag_mappings, 'object_id'); $condition['id'] = array('in', $content_ids); unset($content_ids[array_search($content['id'], $content_ids)]); if (count($content_ids) > $size) { unset($content_ids[count($content_ids) - 1]); } $tcontents = $this->getPages($condition, 1, $size); if ($tcontents) { $tcontents = ass_column($tcontents); } if (count($tcontents) == $size) { return $tcontents; } } //获取父相关文章 if ($content['parent_id']) { $parent_cond['parent_id'] = $content['parent_id']; $tcontents = $this->_mergeMoreRelatedContent($parent_cond, $tcontents, $content['id'], $size); if (count($tcontents) == $size) { return $tcontents; } } //获取当前栏目下相关文章 if ($content['category_id']) { $category_cond['category_id'] = $content['category_id']; $tcontents = $this->_mergeMoreRelatedContent($category_cond, $tcontents, $content['id'], $size); if (count($tcontents) == $size) { return $tcontents; } //获取当前栏目的父栏目文章 $category = D('Category')->where('id=%d', $content['category_id'])->find(); if ($category['pid']) { $pcategory_cond['category_id'] = $content['category_id']; } $tcontents = $this->_mergeMoreRelatedContent($pcategory_cond, $tcontents, $content['id'], $size); if (count($tcontents) == $size) { return $tcontents; } } //排除部分栏目下的文章 if ($exclude_category_ids) { $exclude_cond['category_id'] = array('not in', $exclude_category_ids); } //获取所有栏目的id return $this->_mergeMoreRelatedContent($exclude_cond, $tcontents, $content['id'], $size); }