18 require_once SQ_PACKAGES_PATH.
'/cms/listing_engine/listing_engine.inc';
43 parent::__construct($assetid);
66 $group_by = $this->
attr(
'group_by');
73 $wanted_types = $this->
attr(
'types');
74 if (empty($wanted_types)) {
75 trigger_localised_error(
'CMS0010', E_USER_NOTICE);
84 $group_by = $this->
attr(
'group_by');
88 $letter_sort_by =
'name';
89 if ($group_by ==
'letter') {
90 if (!empty($sort_info) && ($sort_info[
'type'] ==
'field') && ($sort_info[
'params'][
'field'] ==
'short_name')) {
91 $letter_sort_by =
'short_name';
96 $base_bind_vars = Array();
99 $field = $this->
attr(
'date_field');
100 $ranges = $this->
attr(
'date_ranges');
102 $link_value_wanted = NULL;
103 if ($this->
attr(
'link_value_filter_enabled')) {
105 $link_value_wanted = htmlentities($this->
attr(
'link_value_filter'));
110 require_once SQ_ATTRIBUTES_PATH.
'/datetime/datetime.inc';
112 if (!empty($ranges) && isset($_REQUEST[
'asset_'.$this->
id.
'_date_range']) && isset($ranges[$_REQUEST[
'asset_'.$this->
id.
'_date_range']])) {
113 $id = $_REQUEST[
'asset_'.$this->id.
'_date_range'];
116 if ($ranges[$id][
'range_type'] !==
'default') {
117 switch ($ranges[$id][
'range_type']) {
125 if ((
int)date(
'w') === 1) {
144 $from->value = $ranges[$id][
'oldest_date'];
147 $to->value = $ranges[$id][
'newest_date'];
149 }
else if ($this->
attr(
'range_type') !==
'default') {
150 switch ($this->
attr(
'range_type')) {
158 if ((
int)date(
'w') === 1) {
180 $from = $from->getISO8601();
181 $from_date = iso8601_date_component($from);
182 if (!empty($from_date)) {
184 if (!preg_match_all(
'|^\d{4}-\d{2}-\d{2}$|', $from_date, $matches)) {
185 trigger_localised_error(
'CMS0053', E_USER_WARNING, $from_date);
189 $from_time = iso8601_time_component($from);
190 if (empty($from_time)) $from_time =
'00:00:00';
193 if (!preg_match_all(
'|^\d{2}:\d{2}:\d{2}$|', $from_time, $matches)) {
194 trigger_localised_error(
'CMS0054', E_USER_WARNING, $from_time);
197 $where .=
' AND a.'.$field.
' >= '.db_extras_todate(
MatrixDAL::getDbType(),
':wn_from_date', FALSE);
198 $base_bind_vars[
'wn_from_date'] = $from_date.
' '.$from_time;
201 $to = $to->getISO8601();
202 $to_date = iso8601_date_component($to);
203 if (!empty($to_date)) {
205 if (!preg_match_all(
'|^\d{4}-\d{2}-\d{2}$|', $to_date, $matches)) {
206 trigger_localised_error(
'CMS0055', E_USER_WARNING, $to_date);
210 $to_time = iso8601_time_component($to);
211 if (empty($to_time)) $to_time =
'23:59:59';
214 if (!preg_match_all(
'|^\d{2}:\d{2}:\d{2}$|', $to_time, $matches)) {
215 trigger_localised_error(
'CMS0056', E_USER_WARNING, $to_time);
218 $where .=
' AND a.'.$field.
' <= '.db_extras_todate(
MatrixDAL::getDbType(),
':wn_to_date', FALSE);
219 $base_bind_vars[
'wn_to_date'] = $to_date.
' '.$to_time;
224 trigger_localised_error(
'CMS0011', E_USER_NOTICE);
228 if (!is_null($link_value_wanted)) {
229 $link_value_wanted = Array(
230 'link_value' => Array($link_value_wanted),
231 'equal' => $this->
attr(
'link_value_filter_logic'),
235 if ($this->
attr(
'subs_only')) {
238 foreach ($root_asset_ids as $root_asset_id) {
239 $links_query = $GLOBALS[
'SQ_SYSTEM']->am->generateGetLinksQuery($root_asset_id, $this->
attr(
'link_types'), array_keys($wanted_types), FALSE,
'major', $link_value_wanted, NULL, NULL, $letter_sort_by, SQ_PERMISSION_READ);
240 $query = $links_query[
'sql_array'];
241 $bind_vars = array_merge($base_bind_vars, $links_query[
'bind_vars']);
244 $where = str_replace(
'a.'.$field,
'l.'.$field, $where);
245 $query[
'where'] .= $where;
248 if ($group_by ==
'letter') {
249 $query[
'select'] .=
', SUBSTR(l.'.$letter_sort_by.
', 1, 1) AS first_letter';
255 foreach($bind_vars as $bind_var => $bind_value) {
259 }
catch (Exception $e) {
260 throw new Exception($e->getMessage());
263 $links = array_merge($links, $new_links);
269 foreach ($links as $link_info) {
270 $children[$link_info[
'minorid']] = Array( 0 => Array(
271 'type_code' => $link_info[
'minor_type_code'],
272 'first_letter' => $link_info[
'first_letter'],
280 foreach ($links as $link_info) {
281 $children[$link_info[
'minorid']] = Array( 0 => Array(
'type_code' => $link_info[
'minor_type_code']));
289 foreach ($root_asset_ids as $root_asset_id) {
290 $root_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($root_asset_id);
291 $child_query = $GLOBALS[
'SQ_SYSTEM']->am->generateGetChildrenQuery($root_asset, array_keys($wanted_types), FALSE, NULL, $letter_sort_by, SQ_PERMISSION_READ, TRUE, TRUE, NULL, NULL, TRUE, $link_value_wanted);
292 $sql_array = $child_query[
'sql_array'];
293 $bind_vars = array_merge($base_bind_vars, $child_query[
'bind_vars']);
295 $sql_array[
'where'] .= $where;
298 if ($group_by ==
'letter') {
299 $sql_array[
'select'] .=
', SUBSTR(a.'.$letter_sort_by.
', 1, 1) AS first_letter';
300 $sql_array[
'union_select'] .=
', NULL AS first_letter';
307 foreach($bind_vars as $bind_var => $bind_value) {
312 }
catch (Exception $e) {
313 throw new Exception($e->getMessage());
317 foreach ($new_kids as $kid_key => $kid_value) {
318 $children[$kid_key] = $kid_value;
321 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($root_asset);
327 if ($group_by !=
'letter') {
328 foreach ($children as $child_id => $child_datas) {
329 $child_data = $child_datas[0];
330 $children[$child_id] = Array( 0 => Array(
'type_code' => $child_data[
'type_code']));
336 if ($group_by ==
'number') {
353 $cache_key = parent::_getCacheKey();
355 $ranges = $this->
attr(
'date_ranges');
356 if (!empty($ranges) && isset($_REQUEST[
'asset_'.$this->
id.
'_date_range']) && isset($ranges[$_REQUEST[
'asset_'.$this->
id.
'_date_range']])) {
358 $cache_key .=
':'.$_REQUEST[
'asset_'.$this->id.
'_date_range'];
384 $keywords = parent::_getContentsKeywords();
385 $keywords[
'date_range_list'] = translate(
'cms_whats_new_date_range_list');
386 $keywords[
'date_range_list_linked'] = translate(
'cms_whats_new_date_range_list_linked');
404 $ranges = $this->
attr(
'date_ranges');
405 if (empty($ranges))
return;
407 $prefix =
'asset_'.$this->id;
409 foreach ($ranges as $id => $info) {
410 $names[$id] = $info[
'name'];
413 $selected = (isset($_REQUEST[$prefix.
'_date_range']) ? $_REQUEST[$prefix.
'_date_range'] :
'');
414 $url = $_SERVER[
'PHP_SELF'];
417 combo_box($prefix.
'_date_range', $names, FALSE, $selected);
419 $extras =
'var select = document.getElementById("'.$prefix.
'_date_range"); document.location.href="'.$url.
'?'.$prefix.
'_date_range=" + select.selectedIndex;';
420 normal_button($prefix.
'_date_range_submit', translate(
'go'), $extras);
422 $replacement = ob_get_contents();
438 $ranges = $this->
attr(
'date_ranges');
439 if (empty($ranges))
return;
441 $prefix =
'asset_'.$this->id;
443 foreach ($ranges as $id => $info) {
444 $names[$id] = $info[
'name'];
447 $selected = (isset($_REQUEST[$prefix.
'_date_range']) ? $_REQUEST[$prefix.
'_date_range'] :
'');
448 $url = $_SERVER[
'PHP_SELF'];
452 <div
id=
"date_range_list">
455 foreach ($names as $id => $name) {
457 <li<?php echo ($selected == $id) ?
' id="current"' :
'';?>>
458 <a href=
"<?php echo $url.'?'.$prefix.'_date_range='.$id; ?>"><?php echo $name; ?></a>
466 $replacement = ob_get_contents();