diff --git a/sources/source-FreePBX_Contactmanager.module b/sources/source-FreePBX_Contactmanager.module new file mode 100644 index 00000000..c9b8dd11 --- /dev/null +++ b/sources/source-FreePBX_Contactmanager.module @@ -0,0 +1,61 @@ + array( + 'description' => 'The format to return any found caller ID in.', + 'type' => 'select', + 'option' => array ( + '1' => 'Display Name', + '2' => 'Company', + '3' => 'Last First', + '4' => 'First Last', + ), + 'default' => '4', + ), + ); + + public function __construct() { + $this->description = _("Searches FreePBX Contact manager for name."); + } + + function get_caller_id($thenumber, $run_param=array()) { + $caller_id = null; + $data = FreePBX::Contactmanager()->lookupByUserID(-1, $thenumber,"/\D/"); + if(empty($data)){ + return null; + } + $first = !empty($data['fname'])?$data['fname']:''; + $last = !empty($data['lname'])?$data['lname']:''; + $company = !empty($data['company'])?$data['company']:'Unknown'; + $displayname = !empty($data['displayname'])?$data['displayname']:'Unknown'; + + if(empty($first) && empty($last)){ + $first = 'Unknown'; + } + $format = isset($run_param['Return_Format'])?$run_param['Return_Format']:'4'; + switch($format){ + case '1': + $caller_id = $displayname; + break; + case '2': + $caller_id = $company; + break; + case '3': + $caller_id = $last .' ' .$first; + break; + case '4': + default: + $caller_id = $first .' ' .$last; + break; + } + + return $caller_id; + } + +} diff --git a/utests/source-FreePBX_ContactmanagerTest.php b/utests/source-FreePBX_ContactmanagerTest.php new file mode 100644 index 00000000..265d9a00 --- /dev/null +++ b/utests/source-FreePBX_ContactmanagerTest.php @@ -0,0 +1,34 @@ +get('AMPWEBROOT'); + include $webroot.'/admin/modules/superfecta/includes/superfecta_base.php'; + include $webroot.'/admin/modules/superfecta/sources/source-FreePBX_Contactmanager.module'; + self::$o = new FreePBX_Contactmanager(); + } + //Stuff before the test + public function setup() {} + //Leave this alone, it test that PHPUnit is working + public function testPHPUnit() { + $this->assertEquals("test", "test", "PHPUnit is broken."); + $this->assertNotEquals("test", "nottest", "PHPUnit is broken."); + } + + //This tests that the the object for your class is an object + public function testCreate() {; + $this->assertTrue(is_object(self::$o), "Did not get an object"); + } + + public function testCnam(){ + $cnam = self::$o->get_caller_id('4805551212',array('Return Format' => 3)); + $this->assertEquals("Jimmy John", $cnam, "The lookup returned an unexpected result for 6305434316"); + } +}