I've been around and around with paging. I started using the Containable behavior, which is fantastic for something like 'view', but is highly problematic for listings, especially with pagination. I discovered the Linkable behavior, and it's much more database efficient, and I actually can get it to work with pagination (except when using GROUP BY). I did have to tweak it though, to handle some of the more complex queries that I intend. This checkin includes a bunch of garbage, but given the amount of time I've spent on this crap, I'm afraid to lose anything that might later be useful information. I'll clean up on the next checkin.
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526/site@49 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -89,18 +89,124 @@ class ContactsController extends AppController {
|
||||
*/
|
||||
|
||||
function past() {
|
||||
$this->Contact->recursive = 0;
|
||||
$this->Contact->bindModel(array('hasOne' => array('ContactsLease',
|
||||
'Lease' => array(
|
||||
'foreignKey' => false,
|
||||
'conditions' => array('Lease.id = ContactsLease.lease_id')
|
||||
))),
|
||||
false);
|
||||
|
||||
/* $this->Contact->contain */
|
||||
/* (array(// Models */
|
||||
/* 'ContactPhone', */
|
||||
/* 'ContactEmail', */
|
||||
/* 'ContactAddress', */
|
||||
/* 'Lease' => */
|
||||
/* array('order' => 'movein_date', */
|
||||
/* 'conditions' => array('Lease.close_date IS NOT NULL', */
|
||||
/* 'ContactsLease.type !=' => 'ALTERNATE'), */
|
||||
/* // Models */
|
||||
/* 'Unit' => */
|
||||
/* array('order' => array('sort_order'), */
|
||||
/* 'fields' => array('id', 'name'), */
|
||||
/* ), */
|
||||
/* /\* 'Charge' => *\/ */
|
||||
/* /\* array('order' => array('charge_date'), *\/ */
|
||||
/* /\* // Models *\/ */
|
||||
/* /\* 'ChargeType', *\/ */
|
||||
/* /\* 'Receipt', *\/ */
|
||||
/* /\* ) *\/ */
|
||||
/* ) */
|
||||
/* ) */
|
||||
/* ); */
|
||||
|
||||
/* $contact = $this->Contact->find('all', */
|
||||
/* array('order' => 'id DESC', */
|
||||
/* 'conditions' => array('Lease.id IS NOT NULL'), */
|
||||
/* 'contain' => */
|
||||
/* array( */
|
||||
/* // Models */
|
||||
/* 'Lease' => */
|
||||
/* array('order' => 'movein_date', */
|
||||
/* 'conditions' => array('Lease.lease_date IS NOT NULL', */
|
||||
/* 'Lease.close_date IS NOT NULL', */
|
||||
/* 'ContactsLease.type !=' => 'ALTERNATE'), */
|
||||
/* ) */
|
||||
/* ) */
|
||||
/* )); */
|
||||
|
||||
/* $contacts = $this->Contact->find */
|
||||
/* ('all', array */
|
||||
/* ('contain' => array */
|
||||
/* ('Lease' => array */
|
||||
/* ('conditions' => array('lease_date >' => "2009-04-01"), */
|
||||
/* ) */
|
||||
/* ), */
|
||||
/* 'order' => 'id DESC', */
|
||||
/* 'conditions' => array('Lease.id IS NOT NULL') */
|
||||
/* )); */
|
||||
|
||||
/* $contacts = $this->Contact->find('all', */
|
||||
/* array('order' => 'id DESC', */
|
||||
/* 'contain' => 'Lease.lease_date > "2009-04-01"' */
|
||||
/* )); */
|
||||
/* pr($contacts); */
|
||||
/* $this->set('contacts', $contacts); */
|
||||
|
||||
/* $this->Contact->Behaviors->attach('Containable'); */
|
||||
/* $this->Contact->contain */
|
||||
/* (array(// Models */
|
||||
/* 'ContactPhone', */
|
||||
/* 'ContactEmail', */
|
||||
/* 'ContactAddress', */
|
||||
/* 'Lease' => */
|
||||
/* array('order' => 'movein_date', */
|
||||
/* 'conditions' => array('Lease.close_date IS NOT NULL', */
|
||||
/* 'ContactsLease.type !=' => 'ALTERNATE'), */
|
||||
/* // Models */
|
||||
/* 'Unit' => */
|
||||
/* array('order' => array('sort_order'), */
|
||||
/* 'fields' => array('id', 'name'), */
|
||||
/* ), */
|
||||
/* /\* 'Charge' => *\/ */
|
||||
/* /\* array('order' => array('charge_date'), *\/ */
|
||||
/* /\* // Models *\/ */
|
||||
/* /\* 'ChargeType', *\/ */
|
||||
/* /\* 'Receipt', *\/ */
|
||||
/* /\* ) *\/ */
|
||||
/* ) */
|
||||
/* ) */
|
||||
/* ); */
|
||||
|
||||
|
||||
$this->paginate =
|
||||
array('link' =>
|
||||
array(// Models
|
||||
'ContactPhone' => array('fields' => array('phone'),
|
||||
//'type' => 'INNER'
|
||||
),
|
||||
//'ContactEmail',
|
||||
//'ContactAddress',
|
||||
'Lease' =>
|
||||
array('fields' => array(),
|
||||
'type' => 'LEFT',
|
||||
// Models
|
||||
'Unit' => array('fields' => array('name'),
|
||||
//'type' => 'INNER',
|
||||
),
|
||||
)
|
||||
),
|
||||
'order' => 'Contact.last_name, Contact.first_name',
|
||||
'conditions' => array(//'ContactsLease.type !=' => 'ALTERNATE',
|
||||
//'Lease.id IS NOT NULL',
|
||||
//'Lease.lease_date IS NOT NULL',
|
||||
//'Lease.close_date IS NOT NULL'
|
||||
),
|
||||
'group' => 'Contact.id',
|
||||
'fields' => array('id', 'first_name', 'last_name', 'company_name', 'comment'),
|
||||
);
|
||||
|
||||
|
||||
$title = 'Past Tenants';
|
||||
$this->set('title', $title); $this->set('heading', $title);
|
||||
$this->set('contacts', $this->paginate(array('Lease.close_date IS NOT NULL',
|
||||
'ContactsLease.type != "ALTERNATE"')));
|
||||
$this->set('contacts', $this->paginate());
|
||||
//$this->set('contacts', $this->Contact->find('all', array('order' => 'id DESC')));
|
||||
//$this->set('contacts', $this->Contact->find('all'));
|
||||
/* $this->set('contacts', $this->Contact->find('all')); */
|
||||
/* $this->set('contacts', $this->Contact->find('all')); */
|
||||
$this->render('index');
|
||||
}
|
||||
|
||||
@@ -131,15 +237,61 @@ class ContactsController extends AppController {
|
||||
function view($id = null) {
|
||||
if (!$id) {
|
||||
$this->Session->setFlash(__('Invalid Item.', true));
|
||||
$this->redirect(array('action'=>''));
|
||||
$this->redirect(array('action'=>'index'));
|
||||
}
|
||||
$this->Contact->recursive = 4;
|
||||
$this->Contact->Lease->LeaseType->unbindModel(array('hasMany' => array('Lease')));
|
||||
$this->Contact->Lease->Charge->unbindModel(array('belongsTo' => array('Lease')));
|
||||
$this->Contact->Lease->Charge->ChargeType->unbindModel(array('hasMany' => array('Charge')));
|
||||
$this->Contact->Lease->Charge->Receipt->unbindModel(array('hasMany' => array('ChargesReceipt')));
|
||||
|
||||
$contact = $this->Contact->read(null, $id);
|
||||
//pr($this->Contact);
|
||||
//pr($this->Contact->ContactPhone);
|
||||
|
||||
$this->Contact->Behaviors->attach('Containable');
|
||||
$this->Contact->contain
|
||||
(array(// Models
|
||||
'ContactPhone',
|
||||
'ContactEmail',
|
||||
'ContactAddress',
|
||||
'Lease' =>
|
||||
array('order' => 'movein_date',
|
||||
'conditions' => array('Lease.lease_date IS NOT NULL',
|
||||
'ContactsLease.type !=' => 'ALTERNATE'),
|
||||
// Models
|
||||
'Unit' =>
|
||||
array('order' => array('sort_order'),
|
||||
'fields' => array('id', 'name'),
|
||||
),
|
||||
'Charge' =>
|
||||
array('order' => array('charge_date'),
|
||||
// Models
|
||||
'ChargeType',
|
||||
'Receipt',
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
$contact = $this->Contact->read(null, $id);
|
||||
|
||||
/* $contact = $this->Contact->find */
|
||||
/* ('first', */
|
||||
/* array('link' => array */
|
||||
/* (// Models */
|
||||
/* 'ContactPhone', */
|
||||
/* 'ContactEmail', */
|
||||
/* 'ContactAddress', */
|
||||
/* 'Lease' => */
|
||||
/* array(// Models */
|
||||
/* 'Unit' => array('fields' => array('id', 'name')), */
|
||||
/* 'Charge' => array(// Models */
|
||||
/* 'ChargeType', */
|
||||
/* 'Receipt', */
|
||||
/* ) */
|
||||
/* ) */
|
||||
/* ), */
|
||||
/* 'order' => 'Lease.movein_date, Unit.sort_order, Charge.charge_date', */
|
||||
/* 'conditions' => array('Lease.lease_date IS NOT NULL', */
|
||||
/* 'ContactsLease.type !=' => 'ALTERNATE'), */
|
||||
/* )); */
|
||||
|
||||
/* pr($contact); */
|
||||
|
||||
$title = $contact['Contact']['display_name'];
|
||||
|
||||
$outstanding_deposit = 0;
|
||||
@@ -163,7 +315,7 @@ class ContactsController extends AppController {
|
||||
$this->sidemenu_links[] =
|
||||
array('name' => 'Move-Out', 'url' => array('controller' => 'units', 'action' => 'move-out'));
|
||||
|
||||
$this->set(compact('contact', 'title', 'mytstval',
|
||||
$this->set(compact('contact', 'title',
|
||||
'outstanding_balance',
|
||||
'outstanding_deposit'));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user