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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
|
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter RSS Model
*
* A basic model for Newsbeuter Rssfeeds config table
*
* @package CodeIgniter
* @subpackage Models
* @category Models
* @author V.Krishn
* @license MIT
* @link https://github.com/insteps/nbreader
*/
/*
| -------------------------------------------------------------------
| RSS REST API DATA MODELS
| -------------------------------------------------------------------
| This file will contain the settings needed to access your api.
|
| -------------------------------------------------------------------
| EXPLANATION OF VARIABLES
| -------------------------------------------------------------------
|
*/
class Newsbeuter_rss_url_model extends CI_Model
{
public function __construct()
{
// Call the CI_Model constructor
parent::__construct();
//$this->load->database('newsbeuter');
}
public function get_max_rss_url_id()
{
$this->db->select_max('rssurl', 'rssurl');
$q = $this->db->get('rss_url');
$result = $q->result_array();
$result = $result[0];
if($result['rssurl'] == null)
{
$rssurl = 1;
}
else
{
$rssurl = $result['rssurl']+1;
}
return $rssurl;
}
private function get_rss_url_result($search_options = array(), $limit = 0, $offset = 0)
{
$this->db->select("
ru.rssurl
, ru.tags
, ru.dbname
, ru.lastmodified
, ru.lastfetch
, ru.sha1sum
, ru.icon
");
$this->db->from('rss_url ru');
if(isset($search_options['rssurl']))
{
$this->db->where('ru.rssurl', $search_options['rssurl']);
}
if(isset($search_options['tags']))
{
$this->db->where('ru.tags', $search_options['tags']);
}
if(isset($search_options['dbname']))
{
$this->db->where('ru.dbname', $search_options['dbname']);
}
if(isset($search_options['lastmodified']))
{
$this->db->where('ru.lastmodified', $search_options['lastmodified']);
}
if(isset($search_options['lastfetch']))
{
$this->db->where('ru.lastfetch', $search_options['lastfetch']);
}
if(isset($search_options['sha1sum']))
{
$this->db->where('ru.sha1sum', $search_options['sha1sum']);
}
if(isset($search_options['order_by']))
{
$this->db->order_by($search_options['order_by']);
}
else
{
$this->db->order_by('ru.rssurl DESC');
}
if($limit != 0)
{
if($offset == 0)
{
$this->db->limit($limit);
}
else
{
$this->db->limit($limit, $offset);
}
}
$q = $this->db->get();
return $q;
}
public function get_rss_url($search_options = array(), $limit = 0, $offset = 0, $total_rows = 0)
{
//if(empty($search_options)){ return array(); }
$search_options['limit'] = $limit;
$search_options['offset'] = $offset;
$search_options['total_rows'] = $total_rows;
$result = array();
$q = $this->get_rss_url_result($search_options, $limit, $offset);
if($q->num_rows() > 0)
{
$row_num = $total_rows - $offset;
foreach($q->result_array() as $row)
{
$row['row_num'] = $row_num;
$row_num--;
$result[] = $row;
}
}
return $result;
}
private function _store_rss_url($rss_url_info)
{
$result = false;
if(!empty($rss_url_info))
{
$this->db->set($rss_url_info);
$result = $this->db->insert('rss_url');
}
return $result;
}
private function _update_rss_url($rss_url_info)
{
$result = false;
$has_condition = false;
if(!empty($rss_url_info))
{
if(isset($rss_url_info['rssurl']) && $rss_url_info['rssurl'] != '')
{
$this->db->where('rssurl', $rss_url_info['rssurl']);
unset($rss_url_info['rssurl']);
$has_condition = true;
}
if($has_condition == false){ return false; }
$this->db->set($rss_url_info);
$result = $this->db->update('rss_url');
}
return $result;
}
private function _delete_rss_url($search_options = array())
{
$result = false;
$has_condition = false;
if(!empty($search_options))
{
if(isset($search_options['rssurl']) && $search_options['rssurl'] != '')
{
$this->db->where('rssurl', $search_options['rssurl']);
unset($search_options['rssurl']);
$has_condition = true;
}
if($has_condition == false){ return false; }
$result = $this->db->delete('rss_url');
}
return $result;
}
}
|