SnapshotModel.class.php
2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
/**
* 考试-试卷快照表
* @author: houyingcai
* @email: 594609175@qq.com
* @date : 2017-05-19 18:01:50
*/
namespace Common\Model;
class SnapshotModel extends AbstractModel
{
/**
* 构造方法
*/
public function __construct()
{
parent::__construct();
}
/**
* 获取试题快照列表
*
* @author houyingcai
* @param array $conds 查询条件参数列表
* @param array $page_option 分页参数
* @param array $order_option 排序参数
* @param string $fields 返回字段
*
* @return array|bool
*/
public function conds_snapshot_list($conds, $page_option = null, $order_option = [], $fields = '*')
{
$params = [];
// 条件
$wheres = [];
if (!$this->_parse_where($wheres, $params, $conds)) {
return false;
}
$snapModel = new StatisticsModel();
$table = $snapModel->get_tname();
// 企业标记
$wheres[] = 'a.`domain`=?';
$params[] = QY_DOMAIN;
// 状态条件
$wheres[] = 'a.`status`<?';
$params[] = $this->get_st_delete();
// 排序
$orderby = '';
if (!$this->_order_by($orderby, $order_option)) {
return false;
}
// 分页参数
$limit = '';
if (!$this->_limit($limit, $page_option)) {
return false;
}
$sql = "SELECT $fields, CASE WHEN b.answer_total>0 THEN b.right_num/b.answer_total ELSE 'false' END as probability,CASE WHEN a.et_type=" . self::TOPIC_TYPE_VOICE . " or a.et_type=" . self::TOPIC_TYPE_QUESTION . " THEN 1 ELSE 0 END as ea_sort FROM __TABLE__ a LEFT JOIN $table b on a.es_id =b.esr_id and a.ep_id =b.ep_id WHERE " . implode(' AND ',
$wheres) . " {$orderby} {$limit}";
return $this->_m->fetch_array($sql, $params);
}
/**
* 获取试题快照总数
*
* @author caijainhua
* @param array $conds 查询条件参数列表
*
* @return int
*/
public function conds_snapshot_count($conds)
{
$params = [];
// 条件
$wheres = [];
if (!$this->_parse_where($wheres, $params, $conds)) {
return false;
}
// 企业标记
$wheres[] = 'a.`domain`=?';
$params[] = QY_DOMAIN;
// 状态条件
$wheres[] = 'a.`status`<?';
$params[] = $this->get_st_delete();
$statistics = new StatisticsModel();
$table = $statistics->get_tname();
$sql = "SELECT count(*) as total FROM __TABLE__ a LEFT JOIN $table b ON a.es_id =b.esr_id and a.ep_id = b.ep_id WHERE " . implode(' AND ',
$wheres);
$rel = $this->_m->result($sql, $params);
return $rel;
}
}