Skip to content

Commit

Permalink
Resolve Ticket 16. Search by ID within mediamanager tag search [#16 s…
Browse files Browse the repository at this point in the history
…tate:resolved]
  • Loading branch information
olafgleba committed Jul 2, 2011
1 parent 503b1ea commit 2e237ec
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 12 deletions.
43 changes: 33 additions & 10 deletions welcompose/admin/mediamanager/mediamanager_local.php
Expand Up @@ -140,16 +140,39 @@
if ($request['mm_include_types_other'] == 1) {
$types[] = 'other';
}

// prepare select params
$select_params = array(
'types' => $types,
'tags' => $request['mm_tags'],
'timeframe' => $request['mm_timeframe'],
'order_macro' => 'DATE_ADDED:DESC',
'start' => $request['mm_start'],
'limit' => (($request['mm_limit'] < 1) ? 8 : $request['mm_limit'])
);

/**
* To switch searching for a object id within the default tag search,
* we differ between the param array by query the input syntax. To
* search for a object id the input syntax have to start
* with the internal prefix "wcom", followed by a colon and the object id.
* No whitespaces are allowed.
*
* Example:
*
* wcom:21
*
*/
if (Base_Cnc::filterRequest($request['mm_tags'], WCOM_REGEX_TAG_SEARCH_ID)) {
// prepare select params
$select_params = array(
'types' => $types,
'id' => substr($request['mm_tags'], 5),
'timeframe' => $request['mm_timeframe'],
'order_macro' => 'DATE_ADDED:DESC',
'start' => $request['mm_start'],
'limit' => (($request['mm_limit'] < 1) ? 8 : $request['mm_limit'])
);
} else {
$select_params = array(
'types' => $types,
'tags' => $request['mm_tags'],
'timeframe' => $request['mm_timeframe'],
'order_macro' => 'DATE_ADDED:DESC',
'start' => $request['mm_start'],
'limit' => (($request['mm_limit'] < 1) ? 8 : $request['mm_limit'])
);
}
$BASE->utility->smarty->assign('objects', $OBJECT->selectObjects($select_params));

// assign currently used media tags
Expand Down
4 changes: 4 additions & 0 deletions welcompose/core/conf/regex.inc.php
Expand Up @@ -90,6 +90,10 @@
// Defines regular expression for non empty strings
define("WCOM_REGEX_NON_EMPTY", "=^.+$=D");

// Defines regular expression for object id search pattern
// within a mediamanager tag search
define("WCOM_REGEX_TAG_SEARCH_ID", "=^(wcom+)\:([0-9]+)$=D");

// Defines regular expression for the help template
// names
define("WCOM_REGEX_HELP", "=^([a-z0-9-_]+)$=Di");
Expand Down
10 changes: 8 additions & 2 deletions welcompose/core/media_classes/object.class.php
Expand Up @@ -271,7 +271,7 @@ public function selectObjects ($params = array())
}

// define some vars
$timeframe = null;
$id = null;
$tags = null;
$order_macro = null;
$types = array();
Expand All @@ -294,6 +294,7 @@ public function selectObjects ($params = array())
break;
case 'start':
case 'limit':
case 'id':
$$_key = (int)$_value;
break;
case 'types':
Expand Down Expand Up @@ -357,7 +358,12 @@ public function selectObjects ($params = array())
$bind_params = array(
'project' => WCOM_CURRENT_PROJECT
);


if (!empty($id) && is_numeric($id)) {
$sql .= " AND `media_objects`.`id` = :id ";
$bind_params['id'] = $id;
}

// add where clauses
if (!empty($timeframe)) {
$sql .= " AND ".$HELPER->_sqlForTimeFrame('`media_objects`.`date_added`',
Expand Down

0 comments on commit 2e237ec

Please sign in to comment.