Files
pmgr/site/controllers/contacts_controller.php

146 lines
4.5 KiB
PHP

<?php
class ContactsController extends AppController {
var $sidemenu_links = array();
/**************************************************************************
**************************************************************************
**************************************************************************
* override: sideMenuLinks
* - Generates controller specific links for the side menu
*/
function sideMenuLinks() {
return array_merge(parent::sideMenuLinks(), $this->sidemenu_links);
}
/**************************************************************************
**************************************************************************
**************************************************************************
* action: index / all
* - Generate a listing of contacts
*/
function index() { $this->all(); }
function all() { $this->jqGridView('All Contacts', 'all'); }
/**************************************************************************
**************************************************************************
**************************************************************************
* virtuals: jqGridData
* - With the application controller handling the jqGridData action,
* these virtual functions ensure that the correct data is passed
* to jqGrid.
*/
function jqGridDataOrder(&$params, &$model, $index, $direction) {
$order = parent::jqGridDataOrder($params, $model, $index, $direction);
if ($index === 'Contact.last_name') {
$order[] = 'Contact.first_name ' . $direction;
}
if ($index === 'Contact.first_name') {
$order[] = 'Contact.last_name ' . $direction;
}
return $order;
}
function jqGridRecordLinks(&$params, &$model, &$records, $links) {
$links['Contact'] = array('id');
return parent::jqGridRecordLinks($params, $model, $records, $links);
}
/**************************************************************************
**************************************************************************
**************************************************************************
* action: view
* - Displays information about a specific contact
*/
function view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid Item.', true));
$this->redirect(array('action'=>'index'));
}
$contact = $this->Contact->find
('first', array
('contain' => array
(// Models
'ContactPhone',
'ContactEmail',
'ContactAddress',
'Customer'),
'conditions' => array('Contact.id' => $id),
));
// Set up dynamic menu items
$this->sidemenu_links[] =
array('name' => 'Operations', 'header' => true);
$this->sidemenu_links[] =
array('name' => 'Edit',
'url' => array('action' => 'edit',
$id));
// Prepare to render.
$title = $contact['Contact']['display_name'];
$this->set(compact('contact', 'title'));
}
/**************************************************************************
**************************************************************************
**************************************************************************
* action: edit
*/
function edit($id = null) {
if (isset($this->data)) {
pr($this->data);
$this->autoRender = false;
return;
}
if (!$id) {
$this->Session->setFlash(__('Invalid Item.', true));
$this->redirect(array('action'=>'index'));
}
$this->data = $this->Contact->find
('first', array
('contain' => array
(// Models
'ContactPhone',
'ContactEmail',
'ContactAddress',
'Customer'),
'conditions' => array('Contact.id' => $id),
));
$phone_types = array_flip($this->Contact->ContactPhone->getEnumValues('type'));
unset($phone_types[0]);
$this->set(compact('phone_types'));
$method_types = array_flip($this->Contact->getEnumValues('type', 'pmgr_contacts_methods'));
unset($method_types[0]);
$this->set(compact('method_types'));
$method_preferences = array_flip($this->Contact->getEnumValues('preference', 'pmgr_contacts_methods'));
unset($method_preferences[0]);
$this->set(compact('method_preferences'));
$contact_phones = $this->Contact->ContactPhone->phoneList();
$this->set(compact('contact_phones'));
// Prepare to render.
//pr($this->data);
$title = $this->data['Contact']['display_name'] . " : Edit";
$this->set(compact('title'));
}
}