Skip to content

Commit e7b3362

Browse files
committed
* Added common search::DAO functionality to the DevblocksOrmHelper superclass.
* Made URL parsing/writing much more consistent with or without DEVBLOCKS_REWRITE enabled. Instead of showing query string format, URLs will now be written as index.php/path/to when .htaccess/Apache aren't present. * Added search abstract/interface classes for criteria/fields to the Platform to be shared by all apps consistently. git-svn-id: http://svn.webgroupmedia.com/devblocks/devblocks@63 747e5740-6425-0410-825b-f4fe3d30fc61
1 parent 2c8d1f0 commit e7b3362

File tree

4 files changed

+143
-24
lines changed

4 files changed

+143
-24
lines changed

Devblocks.class.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -451,9 +451,16 @@ static function init() {
451451
// [JAS] [MDF]: Automatically determine the relative webpath to Devblocks files
452452
if(!defined('DEVBLOCKS_WEBPATH')) {
453453
$php_self = $_SERVER["PHP_SELF"];
454-
$pos = strrpos($php_self,'/');
455-
$php_self = substr($php_self,0,$pos) . '/';
456-
@define('DEVBLOCKS_WEBPATH',$php_self);
454+
if(DEVBLOCKS_REWRITE) {
455+
$pos = strrpos($php_self,'/');
456+
$php_self = substr($php_self,0,$pos) . '/';
457+
@define('DEVBLOCKS_WEBPATH',$php_self);
458+
} else {
459+
$pos = strrpos($php_self,'index.php/');
460+
if(false === $pos) $pos = strrpos($php_self,'ajax.php');
461+
$php_self = substr($php_self,0,$pos);
462+
@define('DEVBLOCKS_WEBPATH',$php_self);
463+
}
457464
}
458465
}
459466

api/DAO.php

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,68 @@ static protected function _update($id, $table, $fields) {
5252
/**
5353
* [TODO]: Import the searchDAO functionality + combine the extraneous classes
5454
*/
55-
static protected function _search() {
55+
static protected function _parseSearchParams($params,$fields) {
56+
$db = DevblocksPlatform::getDatabaseService();
57+
58+
$tables = array();
59+
$wheres = array();
60+
61+
if(is_array($params))
62+
foreach($params as $param) { /* @var $param DevblocksSearchCriteria */
63+
if(!is_a($param,'DevblocksSearchCriteria')) continue;
64+
$where = "";
65+
66+
// [JAS]: Filter allowed columns (ignore invalid/deprecated)
67+
if(!isset($fields[$param->field]))
68+
continue;
69+
70+
$db_field_name = $fields[$param->field]->db_table . '.' . $fields[$param->field]->db_column;
71+
72+
// [JAS]: Indexes for optimization
73+
$tables[$fields[$param->field]->db_table] = $fields[$param->field]->db_table;
74+
75+
// [JAS]: Operators
76+
switch($param->operator) {
77+
case "=":
78+
$where = sprintf("%s = %s",
79+
$db_field_name,
80+
$db->qstr($param->value)
81+
);
82+
break;
83+
84+
case "!=":
85+
$where = sprintf("%s != %s",
86+
$db_field_name,
87+
$db->qstr($param->value)
88+
);
89+
break;
90+
91+
case "in":
92+
if(!is_array($param->value)) break;
93+
$where = sprintf("%s IN ('%s')",
94+
$db_field_name,
95+
implode("','",$param->value)
96+
);
97+
break;
98+
99+
case "like":
100+
// if(!is_array($param->value)) break;
101+
$where = sprintf("%s LIKE %s",
102+
$db_field_name,
103+
$db->qstr(str_replace('*','%%',$param->value))
104+
);
105+
break;
106+
107+
default:
108+
break;
109+
}
110+
111+
if(!empty($where)) $wheres[] = $where;
112+
}
56113

114+
return array($tables, $wheres);
57115
}
58-
}
116+
};
59117

60118
class DAO_Platform {
61119

api/Engine.php

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,21 @@ static protected function _readPluginManifest($dir) {
157157
*/
158158
static function readRequest() {
159159
$url = DevblocksPlatform::getUrlService();
160+
161+
$parts = $url->parseURL($_SERVER['REQUEST_URI']);
162+
$query = $_SERVER['QUERY_STRING'];
160163

161-
if(DEVBLOCKS_REWRITE) {
162-
$parts = $url->parseURL($_SERVER['REQUEST_URI']);
163-
$query = $_SERVER['QUERY_STRING'];
164-
165-
} else {
166-
$argc = $url->parseQueryString($_SERVER['QUERY_STRING']);
167-
$parts = array_values($argc);
168-
$query = '';
169-
}
164+
// if(DEVBLOCKS_REWRITE) {
165+
// $parts = $url->parseURL($_SERVER['REQUEST_URI']);
166+
// $query = $_SERVER['QUERY_STRING'];
167+
//
168+
// } else {
169+
//// echo $_SERVER['REQUEST_URI'];
170+
// $parts = $url->parseURL($_SERVER['REQUEST_URI']);
171+
//// $argc = $url->parseQueryString($_SERVER['QUERY_STRING']);
172+
//// $parts = array_values($argc);
173+
// $query = $_SERVER['QUERY_STRING'];
174+
// }
170175

171176
if(empty($parts)) {
172177
// Overrides (Form POST, etc.)
@@ -599,17 +604,21 @@ function parseURL($url) {
599604
// [JAS]: Use the index.php page as a reference to deconstruct the URI
600605
$pos = stripos($_SERVER['PHP_SELF'],'index.php',0);
601606
if($pos === FALSE) return null;
602-
607+
603608
// [JAS]: Extract the basedir of the path
604609
$basedir = substr($url,0,$pos);
605-
610+
606611
// [JAS]: Remove query string
607612
$pos = stripos($url,'?',0);
608613
if($pos !== FALSE) {
609614
$url = substr($url,0,$pos);
610-
}
611-
612-
$request = substr($url,strlen($basedir));
615+
}
616+
617+
$len = strlen($basedir);
618+
if(!DEVBLOCKS_REWRITE) $len += strlen("index.php/");
619+
620+
$request = substr($url, $len);
621+
613622
if(empty($request)) return array();
614623

615624
$parts = split('/', $request);
@@ -623,7 +632,7 @@ function write($sQuery='') {
623632
$c = @$args['c'];
624633

625634
// [JAS]: Internal non-component URL (images/css/js/etc)
626-
if(empty($c)) {
635+
if(empty($c)) {
627636
$contents = sprintf("%s%s",
628637
DEVBLOCKS_WEBPATH,
629638
$sQuery
@@ -637,10 +646,11 @@ function write($sQuery='') {
637646
(!empty($args) ? implode('/',array_values($args)) : '')
638647
);
639648

640-
} else {
641-
$contents = sprintf("%sindex.php?",
649+
} else {
650+
$contents = sprintf("%sindex.php/%s",
642651
DEVBLOCKS_WEBPATH,
643-
(!empty($args) ? $args : '')
652+
(!empty($args) ? implode('/',array_values($args)) : '')
653+
// (!empty($args) ? $sQuery : '')
644654
);
645655
}
646656
}

api/Model.php

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,48 @@
1-
<?php
1+
<?php
2+
interface IDevblocksSearchFields {
3+
static function getFields();
4+
}
5+
class DevblocksSearchCriteria {
6+
const OPER_EQ = '=';
7+
const OPER_NEQ = '!=';
8+
const OPER_IN = 'in';
9+
const OPER_NIN = 'not in';
10+
const OPER_LIKE = 'like';
11+
const OPER_GT = '>';
12+
const OPER_LT = '<';
13+
const OPER_GTE = '>=';
14+
const OPER_LTE = '<=';
15+
16+
public $field;
17+
public $operator;
18+
public $value;
19+
20+
/**
21+
* Enter description here...
22+
*
23+
* @param string $field
24+
* @param string $oper
25+
* @param mixed $value
26+
* @return DevblocksSearchCriteria
27+
*/
28+
public function DevblocksSearchCriteria($field,$oper,$value) {
29+
$this->field = $field;
30+
$this->operator = $oper;
31+
$this->value = $value;
32+
}
33+
};
34+
class DevblocksSearchField {
35+
public $token;
36+
public $db_table;
37+
public $db_column;
38+
39+
function __construct($token, $db_table, $db_column) {
40+
$this->token = $token;
41+
$this->db_table = $db_table;
42+
$this->db_column = $db_column;
43+
}
44+
}
45+
246
class DevblocksExtensionPoint {
347
var $id = '';
448
var $extensions = array();

0 commit comments

Comments
 (0)