PathContentModel.class.php
2.68 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
99
100
101
102
103
104
<?php
/**
* Created by PhpStorm.
* User: zhonglei
* Date: 18/4/24
* Time: 11:57
*/
namespace Common\Model;
class PathContentModel extends AbstractModel
{
/**
* 构造方法
*/
public function __construct()
{
parent::__construct();
}
/**
* 根据应用获取应用数据ID数组
* @author zhonglei
* @param string $app 应用
* @param int $path_id 路径ID
* @return array
*/
public function getAppDataIds($app, $path_id = 0)
{
if (empty($app)) {
return [];
}
$wheres = [];
$params = [];
$this->_parse_where($wheres, $params, ['app' => strtolower($app)]);
// 路径ID
if ($path_id) {
$wheres[] = "`{$this->prefield}path_id`!=?";
$params[] = $path_id;
}
// 企业标记
$wheres[] = "`{$this->prefield}domain`=?";
$params[] = QY_DOMAIN;
// 状态条件
// $wheres[] = "`{$this->prefield}status`<?";
// $params[] = $this->get_st_delete();
$wheres_sql = implode(' AND ', $wheres);
$sql = "SELECT DISTINCT `app_data_id` FROM __TABLE__ WHERE {$wheres_sql}";
$list = $this->_m->fetch_array($sql, $params);
return empty($list) ? [] : array_column($list, 'app_data_id');
}
/**
* 验证学习内容是否已被其他路径使用
* @param array $data 使用的学习内容
* @param int $pathId 路径ID
* @return array
*/
public function getUsePathList($data, $pathId = 0)
{
if (empty($data)) {
return [];
}
$orWhere = [];
foreach ($data as $key => $value) {
// 当为课程是不做筛选
if ($value['app'] == 'course') {
continue;
}
if ($value['app'] && $value['app_data_id']) {
$orWhere[] = "(`{$this->prefield}app`='{$value['app']}' AND `{$this->prefield}app_data_id`={$value['app_data_id']})";
}
}
$orWhere = implode(' OR ', $orWhere);
if (empty($orWhere)) {
return [];
}
// 路径ID
if ($pathId) {
$wheres[] = "`{$this->prefield}path_id`!=?";
$params[] = $pathId;
}
// 企业标记
$wheres[] = "`{$this->prefield}domain`=?";
$params[] = QY_DOMAIN;
// 状态条件
// $wheres[] = "`{$this->prefield}status`<?";
// $params[] = $this->get_st_delete();
$wheres_sql = implode(' AND ', $wheres);
$sql = "SELECT * FROM __TABLE__ WHERE {$wheres_sql} AND ({$orWhere})";
$list = $this->_m->fetch_array($sql, $params);
return $list;
}
}