Skip to content

Commit c8ce9d9

Browse files
committed
Updates
1 parent 5b11032 commit c8ce9d9

File tree

10 files changed

+280
-122
lines changed

10 files changed

+280
-122
lines changed

Change Log.txt

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,38 @@
11
/**
22
* Channel Data
33
* Author: Justin Kimbrell (Objective HTML)
4-
* @version 1.0.0-rc1
5-
* @build 2014-12-10=6
4+
* @version 1.0.0-rc3
5+
* @build 2014-03-03
66
* Copyright 2013 - All rights reserved
77
* http://objectivehtml.com
88
*/
99

10-
#### 2014-12-16
10+
#### 2014-03-03
11+
##### 1.0.0-rc3
12+
13+
- Added get() method to QueryResponse
14+
- Added toArray() method to QueryResponse
15+
- Added fixedOrder parameter to entries() method in Channel Response
16+
- Added findByUsername() to Member
17+
- Added label() method to ChannelField
18+
- Added findByName() method to ChannelField
19+
- Added findByName() method to ChannelField
20+
- Added groupBy() method to QueryBuilder
21+
- Added prefix() method to ChannelData
22+
- Added entries() method to ChannelModel
23+
- Added new ChannelEntriesParser class
24+
- Bug fixes in QueryString class
25+
- Bug fixes in QueryBuilder class
26+
- Bug fixes in ChannelEntriesApi class
27+
28+
#### 2013-12-16
1129
##### 1.0.0-rc2
1230

1331
- Decoupled Channel Data into it’s own “module”.
1432
- Added more models and helper methods
1533

1634

17-
#### 2014-12-10
35+
#### 2013-12-10
1836
##### 1.0.0-rc1
1937

2038
- Complete rewrite of entire API. All new docs and syntax based on Eloquent.

channel_data/libraries/Channeldata/base/ChannelModel.php

Lines changed: 59 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
use ChannelData\Base\BaseModel;
44
use ChannelData\Model\Channel;
5+
use ChannelData\Model\ChannelField;
56
use ChannelData\Component\ChannelQueryBuilder;
67
use ChannelData\Component\QueryString;
78
use ChannelData\Component\ChannelEntriesApi;
9+
use ChannelData\Component\ChannelEntriesParser;
810

911
// namespace ChannelData;
1012

@@ -65,7 +67,7 @@ class ChannelModel extends BaseModel {
6567
public function __construct($data = array())
6668
{
6769
ee()->lang->loadfile('content');
68-
70+
6971
$this->uidField = $this->prefix.'uid';
7072
$this->required[] = $this->prefix.'uid';
7173

@@ -111,6 +113,11 @@ public function hasErrors()
111113

112114
public function channel()
113115
{
116+
if(!$this->channel)
117+
{
118+
return FALSE;
119+
}
120+
114121
$channel = Channel::findByName($this->channel);
115122

116123
if(!$channel)
@@ -137,7 +144,7 @@ public function delete()
137144
}
138145

139146
protected function _createRecord($data = array())
140-
{
147+
{
141148
if(count($data))
142149
{
143150
$this->fill($data);
@@ -150,6 +157,10 @@ protected function _createRecord($data = array())
150157
{
151158
$this->errors = $this->apiResponse;
152159
}
160+
else
161+
{
162+
$this->exists = TRUE;
163+
}
153164

154165
return $this;
155166
}
@@ -160,9 +171,9 @@ protected function _updateRecord($data)
160171
{
161172
$this->fill($data);
162173
}
163-
174+
164175
$this->apiResponse = ChannelEntriesApi::update_entry($this->channel_id, $this->entry_id, $this->data());
165-
176+
166177
if(!is_int($this->apiResponse))
167178
{
168179
$this->errors = $this->apiResponse;
@@ -182,10 +193,14 @@ public function data()
182193
if(isset($data[$row->field_name]) && $value = $data[$row->field_name])
183194
{
184195
unset($data[$row->field_name]);
185-
186-
$data['field_id_'.$row->field_id] = $value;
187-
$data['field_ft_'.$row->field_id] = $row->field_fmt;
188196
}
197+
else
198+
{
199+
$value = NULL;
200+
}
201+
202+
$data['field_id_'.$row->field_id] = $value;
203+
$data['field_ft_'.$row->field_id] = $row->field_fmt;
189204
}
190205

191206
return $data;
@@ -206,14 +221,32 @@ public function fields()
206221
return $this->fields;
207222
}
208223

209-
foreach($this->channel()->fields()->items() as $field)
224+
if($channel = $this->channel())
210225
{
211-
$this->fields[$field->field_id] = $field->field_name;
226+
foreach($channel->fields()->items() as $field)
227+
{
228+
$this->fields[$field->field_id] = $field->field_name;
229+
}
230+
}
231+
else
232+
{
233+
foreach(ChannelField::all()->items() as $field)
234+
{
235+
$this->fields[$field->field_id] = $field->field_name;
236+
}
212237
}
213238

214239
return $this->fields;
215240
}
216241

242+
public static function findOpen($entry_id)
243+
{
244+
return self::where('channel_data.entry_id', '=', $entry_id)
245+
->where('status', '=', 'open')
246+
->get()
247+
->first();
248+
}
249+
217250
public static function findByAuthorId($author_id)
218251
{
219252
return self::where('author_id', '=', $author_id)->get();
@@ -233,6 +266,11 @@ public static function channelId()
233266
{
234267
$class = new static;
235268

269+
if(!$class->channel)
270+
{
271+
return FALSE;
272+
}
273+
236274
return Channel::findByName($class->channel)->id();
237275
}
238276

@@ -250,28 +288,27 @@ public static function query()
250288

251289
$query->from('channel_titles');
252290
$query->leftJoin('channel_data', 'channel_titles.entry_id', '=', 'channel_data.entry_id');
253-
$query->select(array(
254-
'entry_id',
255-
'site_id',
256-
'channel_id',
257-
'author_id',
258-
'title',
259-
'url_title',
260-
'status',
261-
'entry_date',
262-
'expiration_date',
263-
), NULL, 'channel_titles');
291+
$query->select('*', NULL, 'channel_titles');
264292

265293
foreach($class->fields() as $field_id => $field_name)
266294
{
267295
$query->select('field_id_'.$field_id, $field_name, 'channel_data');
268296
}
269297

270-
if($class->channelId())
298+
if($class->channelId())
271299
{
272300
$query->where('channel_data.channel_id', '=', $class->channelId());
273301
}
274302

275303
return $query;
276304
}
277-
}
305+
306+
public function entries()
307+
{
308+
$parser = new ChannelEntriesParser();
309+
310+
return $parser->entries(array(
311+
'entry_id' => $this->id()
312+
));
313+
}
314+
}

channel_data/libraries/Channeldata/channeldata.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,45 @@ public function directories()
104104

105105
return $this->directories;
106106
}
107+
108+
public static function prefix($prefix, $data, $delimeter = ':')
109+
{
110+
$new_data = array();
111+
112+
if(!empty($prefix))
113+
{
114+
foreach($data as $data_index => $data_value)
115+
{
116+
if(is_array($data_value) && preg_match('/\d/', $data_index))
117+
{
118+
if(isset($data_value[0]) && !is_array($data_value[0]))
119+
{
120+
$new_row = array();
121+
122+
foreach($data_value as $inner_index => $inner_value)
123+
{
124+
$new_row[$prefix . $delimeter . $inner_index] = $inner_value;
125+
}
126+
127+
$new_data[$data_index] = $new_row;
128+
}
129+
else
130+
{
131+
$new_data[$data_index] = self::prefix($prefix, $data_value, $delimeter);
132+
}
133+
134+
}
135+
else
136+
{
137+
$new_data[$prefix . $delimeter . $data_index] = $data_value;
138+
}
139+
}
140+
}
141+
else
142+
{
143+
$new_data = $data;
144+
}
145+
146+
return $new_data;
147+
}
107148
}

channel_data/libraries/Channeldata/components/ChannelEntriesApi.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,15 @@ public static function update_entry($channel_id, $entry_id, $data)
4343
{
4444
ee()->load->library('api');
4545
ee()->api->instantiate('channel_entries');
46+
ee()->api->instantiate('channel_fields');
4647

4748
$data['entry_id'] = $entry_id;
4849
$data['channel_id'] = $channel_id;
4950

5051
ee()->session->userdata['group_id'] = 1;
5152

53+
ee()->api_channel_fields->setup_entry_settings($channel_id, $data);
54+
5255
ee()->api_channel_entries->update_entry($entry_id, $data);
5356

5457
if(count(ee()->api_channel_entries->errors) > 0)

0 commit comments

Comments
 (0)