1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- namespace Push\Lib;
- use Dever;
- class Data
- {
- public function get($key, $name, $total = 10, $page = false)
- {
- $info = Dever::db('push/info')->one(array('key' => $key));
- if (!$info) {
- $insert['key'] = $key;
- $insert['name'] = $name;
- $insert['num'] = $total;
- $insert['col'] = '1,3';
- $info['id'] = Dever::db('push/info')->insert($insert);
- $info['num'] = $insert['num'];
- }
- $data = array();
- if ($info) {
- if (!$info['num']) {
- $info['num'] = 20;
- }
- if ($page) {
- $data = Dever::db('push/data')->getAllPage(array('info_id' => $info['id'], 'page' => array($info['num'], 'list')));
- } else {
- $data = Dever::db('push/data')->getAll(array('info_id' => $info['id'], 'limit' => $info['num']));
- }
- if ($data) {
- foreach ($data as $k => $v) {
- $data[$k] = $this->getOne($v);
- }
- }
- }
- return $data;
- }
- private function getOne($info)
- {
- $info['id'] = 0;
- if ($info['type'] < 10) {
- $table = Dever::config('base')->type_table[$info['type']];
- if ($info['type'] == 1) {
- $id = $info['article_id'];
- } elseif ($info['type'] == 2) {
- $id = $info['vod_id'];
- } elseif ($info['type'] == 3) {
- $id = $info['live_id'];
- } elseif ($info['type'] == 4) {
- $id = $info['journal_id'];
- }
- unset($info['article_id']);
- unset($info['vod_id']);
- unset($info['live_id']);
- unset($info['journal_id']);
- if ($id > 0) {
- $info['id'] = $id;
- $data = Dever::db($table)->one($id);
- if (isset($data) && $data) {
- if (isset($data['name']) && $data['name'] && !$info['name']) {
- $info['name'] = $data['name'];
- }
- if (isset($data['pic_cover']) && $data['pic_cover'] && !$info['pic']) {
- $info['pic'] = $data['pic_cover'];
- }
- if (isset($data['pic_view_cover']) && $data['pic_view_cover'] && !$info['pic']) {
- $info['pic'] = $data['pic_view_cover'];
- }
- if (isset($data['pdate']) && $data['pdate']) {
- $info['cdate'] = $data['pdate'];
- }
- }
- }
- } else {
- unset($info['article_id']);
- unset($info['vod_id']);
- unset($info['live_id']);
- unset($info['journal_id']);
- }
- $info['cdate'] = date('Y-m-d', $info['cdate']);
- return $info;
- }
- }
|