Got rid of the custom paging functions, since it's no longer used, and added a function to convert dates into SQL format. Added a beforeSave callout to Transaction to convert the date before saving.

git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605/site@171 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-06-19 16:21:16 +00:00
parent 19cee7290f
commit f6d6659d2a
2 changed files with 21 additions and 52 deletions

View File

@@ -110,56 +110,16 @@ class AppModel extends Model {
}
}
// Overriding pagination, since the stupid count mechanism blows.
// This is also a crappy solution, especially if the query returns
// a really large number of rows. However, trying to untagle this
// without changing a bunch of core code is near impossible.
//var $paginate_rows_save;
function paginate($conditions, $fields, $order, $limit, $page = 1, $recursive = null, &$extra = null) {
/* pr("paginate"); */
/* pr(array_merge(compact('conditions', 'fields', 'order', 'limit', 'page', 'recursive', 'extra'))); */
if ($page > 1 && isset($limit))
$offset = ($page - 1) * $limit;
else
$offset = 0;
/**************************************************************************
**************************************************************************
**************************************************************************
* function: dateFormatBeforeSave
* - convert dates to database format
*/
if (!isset($extra['results']))
die("Why isn't results set!?!");
$results = $extra['results'];
unset($extra['results']);
return array_slice($results, $offset, $limit);
}
function paginateCount($conditions = null, $recursive = null, &$extra = null) {
/* pr("paginateCount"); */
/* pr(compact('conditions', 'recursive', 'extra')); */
if (isset($extra['results'])) {
// Beauty! The results are already in!
// This happens if the user sets up a complex query
// and passes us the result to paginate.
$results = $extra['results'];
}
elseif (isset($extra['query'])) {
// Perform the query directly... forget all the find B.S.
$results = $this->query($extra['query']);
}
else {
if (!isset($recursive))
$recursive = $this->recursive;
$parameters = array_merge(compact('conditions', 'recursive'), $extra);
$results = $this->find('all', $parameters);
}
//$this->paginate_rows_save = $results;
//return count($this->paginate_rows_save);
if (!isset($extra['results']))
$extra['results'] = $results;
return count($results);
function dateFormatBeforeSave($dateString) {
return date('Y-m-d', strtotime($dateString));
}
}

View File

@@ -2,10 +2,9 @@
class Transaction extends AppModel {
var $name = 'Transaction';
var $validate = array(
'id' => array('numeric'),
'stamp' => array('time')
);
/* var $validate = array( */
/* 'stamp' => array('date') */
/* ); */
var $belongsTo = array(
'Customer',
@@ -15,5 +14,15 @@ class Transaction extends AppModel {
'LedgerEntry',
);
function beforeSave() {
if(!empty($this->data['Transaction']['stamp'])) {
$this->data['Transaction']['stamp'] =
$this->dateFormatBeforeSave($this->data['Transaction']['stamp']);
}
return true;
}
}
?>