PageRenderTime 43ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/library/Bvb/Grid/Source/SourceInterface.php

http://zfdatagrid.googlecode.com/
PHP | 439 lines | 40 code | 68 blank | 331 comment | 0 complexity | ec30505b602f69a5deddc495901f87b3 MD5 | raw file
  1. <?php
  2. /**
  3. * LICENSE
  4. *
  5. * This source file is subject to the new BSD license
  6. * It is available through the world-wide-web at this URL:
  7. * http://www.petala-azul.com/bsd.txt
  8. * If you did not receive a copy of the license and are unable to
  9. * obtain it through the world-wide-web, please send an email
  10. * to geral@petala-azul.com so we can send you a copy immediately.
  11. *
  12. * @package Bvb_Grid
  13. * @author Bento Vilas Boas <geral@petala-azul.com>
  14. * @copyright 2010 ZFDatagrid
  15. * @license http://www.petala-azul.com/bsd.txt New BSD License
  16. * @version $Id: SourceInterface.php 1893 2012-03-06 16:13:47Z ivomonteiro@gmail.com $
  17. * @link http://zfdatagrid.com
  18. */
  19. interface Bvb_Grid_Source_SourceInterface
  20. {
  21. /**
  22. * Should return true|false if this source support
  23. * crud operations
  24. *
  25. * @return bool
  26. */
  27. public function hasCrud ();
  28. /**
  29. * Gets a unique record as a associative array
  30. *
  31. * @param string $table
  32. * @param array $condition
  33. *
  34. * @return array
  35. */
  36. public function getRecord ($table, array $condition);
  37. /**
  38. * builds a key=>value array
  39. *
  40. * they must have two options
  41. * title and field
  42. * field is used to perform queries.
  43. * Must have table name or table alias as a prefix
  44. * ex: user.id | country.population
  45. *
  46. * The key for this array is the output field
  47. * If raw sql is something like
  48. *
  49. * select name as alias, country from users
  50. *
  51. * the return array must be like this:
  52. *
  53. * array('alias'=>array('title'=>'alias','field'=>'users.name'));
  54. *
  55. * its not bad idea to apply this to fields titles
  56. * $title = ucwords(str_replace('_',' ',$title));
  57. *
  58. * @return string
  59. */
  60. public function buildFields ();
  61. /**
  62. * Should return the database server name or source name
  63. *
  64. * Ex: mysql, pgsql, array, xml
  65. *
  66. * @return string
  67. */
  68. public function getSourceName ();
  69. /**
  70. * Runs the query and returns the result as a associative array
  71. *
  72. * @return array
  73. */
  74. public function execute ();
  75. /**
  76. * Get a record detail based the current query
  77. *
  78. * @param array $where
  79. *
  80. * @return array
  81. */
  82. public function fetchDetail (array $where);
  83. /**
  84. * Return the total of records
  85. *
  86. * @return int
  87. */
  88. public function getTotalRecords ();
  89. /**
  90. * Ex: array('c'=>array('tableName'=>'Country'));
  91. * where c is the table alias. If the table as no alias,
  92. * c should be the table name
  93. *
  94. * @return array
  95. */
  96. public function getTableList ();
  97. /**
  98. * Return possible filters values based on field definition
  99. * This is mostly used for enum fields where the possible
  100. * values are extracted
  101. *
  102. * Ex: enum('Yes','No','Empty');
  103. *
  104. * should return
  105. *
  106. * array('Yes'=>'Yes','No'=>'No','Empty'=>'Empty');
  107. *
  108. * @param string $field
  109. *
  110. * @return mixed
  111. */
  112. public function getFilterValuesBasedOnFieldDefinition ($field);
  113. /**
  114. * Return field type
  115. * char, varchar, int
  116. *
  117. * Note: If the field is enum or set,
  118. * the value returned must be set or enum,
  119. * and not the full definition
  120. *
  121. * @param string $field
  122. *
  123. * @return string
  124. */
  125. public function getFieldType ($field);
  126. /**
  127. * Returns the "main" table
  128. * the one after select * FROM {MAIN_TABLE}
  129. *
  130. * @return string
  131. */
  132. public function getMainTable ();
  133. /**
  134. *
  135. * Build the order part from the query.
  136. *
  137. * The first arg is the field to be ordered and the $order
  138. * arg is the correspondent order (ASC|DESC)
  139. *
  140. * If the $reset is set to true, all previous order should be removed
  141. *
  142. * @param string $field
  143. * @param string $order
  144. * @param bool $reset
  145. *
  146. * @return void
  147. */
  148. public function buildQueryOrder ($field, $order, $reset = false);
  149. /**
  150. * Build the query limit clause
  151. *
  152. * @param $start
  153. * @param $offset
  154. *
  155. * @return void
  156. */
  157. public function buildQueryLimit ($start, $offset);
  158. /**
  159. * Returns the select object
  160. *
  161. * @return mixed
  162. */
  163. public function getSelectObject ();
  164. /**
  165. * returns the selected order
  166. * that was defined by the user in the query entered
  167. * and not the one generated by the system
  168. *
  169. *If empty a empty array must be returned.
  170. *
  171. *Else the array must be like this:
  172. *
  173. *Array
  174. * (
  175. * [0] => field
  176. * [1] => ORDER (ASC|DESC)
  177. * )
  178. *
  179. *
  180. * @return array
  181. */
  182. public function getSelectOrder ();
  183. /**
  184. * Should perform a query based on the provided by the user
  185. * select the two fields and return an array $field=>$value
  186. * as result
  187. *
  188. * ex: SELECT $field, $value FROM *
  189. * array('1'=>'Something','2'=>'Number','3'=>'history')....;
  190. *
  191. * @param string $field
  192. * @param string $value
  193. *
  194. * @return array
  195. */
  196. public function getDistinctValuesForFilters ($field, $fieldValue, $order = 'name ASC');
  197. /**
  198. *
  199. *Perform a sqlexp
  200. *
  201. *$value = array ('functions' => array ('AVG'), 'value' => 'Population' );
  202. *
  203. *Should be converted to
  204. *SELECT AVG(Population) FROM *
  205. *
  206. *$value = array ('functions' => array ('SUM','AVG'), 'value' => 'Population' );
  207. *
  208. *Should be converted to
  209. *SELECT SUM(AVG(Population)) FROM *
  210. *
  211. * @param array $value
  212. * @param array $where
  213. *
  214. * @return array
  215. */
  216. public function getSqlExp (array $value, $where = array());
  217. /**
  218. * Adds a fulltext search instead of a addcondition method
  219. *
  220. *$field has an index search
  221. *$field['search'] = array('extra'=>'boolean|queryExpansion','indexes'=>'string|array');
  222. *
  223. *if no indexes provided, use the field name
  224. *
  225. *boolean => IN BOOLEAN MODE
  226. *queryExpansion => WITH QUERY EXPANSION
  227. *
  228. * @param string $filter
  229. * @param string $field
  230. *
  231. * @return mixed
  232. */
  233. public function addFullTextSearch ($filter, $field);
  234. /**
  235. * Adds a new condition to the current query
  236. * $filter is the value to be filtered
  237. * $op is the operand to be used: =,>=, like, llike,REGEX,
  238. * $completeField. use the index $completField['field'] to
  239. * specify the field, to avoid ambiguous
  240. *
  241. * @param string $filter
  242. * @param string $op
  243. * @param array $completeField
  244. */
  245. public function addCondition ($filter, $op, $completeField);
  246. /**
  247. *Insert an array of key=>values in the specified table
  248. * @param string $table
  249. * @param array $post
  250. */
  251. public function insert ($table, array $post);
  252. /**
  253. *Update values in a table using the $condition clause
  254. *
  255. *The condition clause is a $field=>$value array
  256. *that should be escaped by YOU (if your class doesn't do that for you)
  257. * and using the AND operand
  258. *
  259. *Ex: array('user_id'=>'1','id_site'=>'12');
  260. *
  261. *Raw SQL: * WHERE user_id='1' AND id_site='12'
  262. *
  263. * @param string $table
  264. * @param array $post
  265. * @param array $condition
  266. */
  267. public function update ($table, array $post, array $condition);
  268. /**
  269. * Delete a record from a table
  270. *
  271. * The condition clause is a $field=>$value array
  272. * that should be escaped by YOU (if your class doesn't do that for you)
  273. * and using the AND operand
  274. *
  275. * Ex: array('user_id'=>'1','id_site'=>'12');
  276. * Raw SQL: * WHERE user_id='1' AND id_site='12'
  277. *
  278. * @param string $table
  279. * @param array $condition
  280. */
  281. public function delete ($table, array $condition);
  282. /**
  283. * Removes any order in que query
  284. */
  285. public function resetOrder ();
  286. /**
  287. * Removes any offset in que query
  288. */
  289. public function resetLimit ();
  290. /**
  291. * Cache handler.
  292. *
  293. * @param Zend_Cache
  294. */
  295. public function setCache ($cache);
  296. /**
  297. * Build the form based on a Model or query
  298. *
  299. * @param array $inputsType
  300. */
  301. public function buildForm ($inputsType = array());
  302. /**
  303. * Returns tables primary keys separeted by commas ","
  304. * This is necessary for mass actions
  305. *
  306. * @param string $table table to get records from
  307. * @param array $fields Fields to fetch
  308. * @param string $separator Separator for multiple PK's
  309. */
  310. public function getMassActionsIds ($table, $fields, $separator = '-');
  311. /**
  312. *
  313. * Quotes a string
  314. *
  315. * @param string $value Field Value
  316. */
  317. public function quoteValue($value);
  318. /**
  319. * Fetch pairs from a table
  320. *
  321. * @param string $table Table Name
  322. * @param string $field Field Name
  323. * @param string $fieldValue Field Value
  324. * @param string $order Query Order
  325. *
  326. */
  327. public function getValuesForFiltersFromTable ($table, $field, $fieldValue, $order = 'name ASC');
  328. /**
  329. * Returns a JSON encoded array of options to be used by auto-complete operations
  330. *
  331. * @var string $term Term to search
  332. * @var string $field Field to search
  333. * @var string $specialKey Key used by user to improve search (>, <>, *, etc, etc)
  334. * @var string $output Output format. Default json
  335. *
  336. * @return json
  337. *
  338. */
  339. public function getAutoCompleteForFilter( $term, $field, $specialKey='', $output = 'json');
  340. /**
  341. * Defines total records found
  342. *
  343. * @var $total Total records
  344. */
  345. public function setTotalRecords($total);
  346. /**
  347. * Returns an array of table identifier columns or PK's
  348. *
  349. * @param string $table Table where to fetch fields
  350. *
  351. * @return array
  352. *
  353. */
  354. public function getIdentifierColumns($table);
  355. /**
  356. * Starts a transaction
  357. */
  358. public function beginTransaction();
  359. /**
  360. * Commits
  361. */
  362. public function commit();
  363. /**
  364. * Rollbacks
  365. */
  366. public function rollBack();
  367. /**
  368. * Returns curretn connection ID
  369. */
  370. public function getConnectionId();
  371. }