Files
pmgr/site/models/contact_phone.php

46 lines
1.1 KiB
PHP

<?php
class ContactPhone extends AppModel {
var $validate = array(
'id' => array('numeric'),
//'type' => array('inlist'),
'phone' => array('phone'),
'ext' => array('numeric')
);
var $hasMany = array(
'ContactsMethod' => array(
'foreignKey' => 'method_id',
'conditions' => "method = 'PHONE'",
)
);
var $hasAndBelongsToMany = array(
'Contact' => array(
'className' => 'Contact',
'joinTable' => 'contacts_methods',
'foreignKey' => 'method_id',
'associationForeignKey' => 'contact_id',
'unique' => true,
'conditions' => "method = 'PHONE'",
)
);
function phoneList() {
$results = $this->find('all',
array('contain' => false,
'fields' => array('id', 'phone', 'ext'),
'order' => array('phone', 'ext')));
App::Import('Helper', 'Format');
$list = array();
foreach ($results as $key => $val) {
$list[$val['ContactPhone']['id']]
= FormatHelper::phone($val['ContactPhone']['phone'],
$val['ContactPhone']['ext']);
}
return $list;
}
}
?>