/** * the constructor * * @param array $_config config rules */ public function __construct($_config = array()) { if (!empty($_config)) { $this->_config = new Zend_Config($_config); } else { // read file with Zend_Config_Xml $filename = Addressbook_Config::getInstance()->get(Addressbook_Config::CONTACT_ADDRESS_PARSE_RULES_FILE, dirname(__FILE__) . '/' . self::CONFIG_FILENAME); $this->_config = new Zend_Config_Xml($filename); } }
/** * the constructor * * allowed options: * - modelName * - tableName * - tablePrefix * - modlogActive * * @param Zend_Db_Adapter_Abstract $_dbAdapter (optional) * @param array $_options (optional) * @throws Tinebase_Exception_Backend_Database */ public function __construct($_dbAdapter = NULL, $_options = array()) { parent::__construct($_dbAdapter, $_options); /** * TODO move this code somewhere and make it optionally. Maybe even make it a new controller / frontend action and request the data async */ if (Addressbook_Config::getInstance()->featureEnabled(Addressbook_Config::FEATURE_LIST_VIEW)) { $this->_additionalColumns['emails'] = new Zend_Db_Expr('(' . $this->_db->select()->from($this->_tablePrefix . 'addressbook', array($this->_dbCommand->getAggregate('email')))->where($this->_db->quoteIdentifier('id') . ' IN ?', $this->_db->select()->from(array('addressbook_list_members' => $this->_tablePrefix . 'addressbook_list_members'), array('contact_id'))->where($this->_db->quoteIdentifier('addressbook_list_members.list_id') . ' = ' . $this->_db->quoteIdentifier('addressbook_lists.id'))) . ')'); } }
/** * constructs a new importer from given config * * @param array $_options */ public function __construct(array $_options = array()) { parent::__construct($_options); if (!Addressbook_Config::getInstance()->get(Addressbook_Config::CONTACT_IMPORT_NOMINATIM)) { // don't set geodata for imported contacts as this might be too much traffic for the nominatim server // TODO make this setting overwritable via import definition/options $this->_controller->setGeoDataForContacts(FALSE); } // get container id from default container if not set if (empty($this->_options['container_id'])) { $defaultContainer = $this->_controller->getDefaultAddressbook(); $this->_options['container_id'] = $defaultContainer->getId(); if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Setting default container id: ' . $this->_options['container_id']); } } }
/** * the constructor * * don't use the constructor. use the singleton */ private function __construct() { $this->_applicationName = 'Addressbook'; $this->_modelName = 'Addressbook_Model_Contact'; $this->_backend = Addressbook_Backend_Factory::factory(Addressbook_Backend_Factory::SQL); $this->_currentAccount = Tinebase_Core::getUser(); $this->_purgeRecords = FALSE; $this->_resolveCustomFields = TRUE; $this->_duplicateCheckFields = Addressbook_Config::getInstance()->get(Addressbook_Config::CONTACT_DUP_FIELDS, array(array('n_given', 'n_family', 'org_name'), array('email'))); // fields used for private and company address $this->_addressFields = array('locality', 'postalcode', 'street', 'countryname'); $this->_setGeoDataForContacts = Tinebase_Config::getInstance()->getConfig(Tinebase_Config::MAPPANEL, NULL, TRUE)->value; if (!$this->_setGeoDataForContacts) { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Mappanel/geoext/nominatim disabled with config option.'); } } }
/** * test import data */ public function testImportSalutation() { $myContact = Addressbook_Controller_Contact::getInstance()->getContactByUserId(Tinebase_Core::getUser()->getId()); $salutation = Addressbook_Config::getInstance()->get(Addressbook_Config::CONTACT_SALUTATION)->records->getFirstRecord()->value; $myContact->salutation = $salutation; Addressbook_Controller_Contact::getInstance()->update($myContact); $result = $this->testImportDuplicates(); $found = FALSE; foreach ($result['exceptions'] as $exception) { if ($exception['exception']['clientRecord']['n_fn'] === Tinebase_Core::getUser()->accountFullName) { $found = TRUE; $this->assertTrue(isset($exception['exception']['clientRecord']['salutation']), 'no salutation found: ' . print_r($exception['exception']['clientRecord'], TRUE)); $this->assertEquals($salutation, $exception['exception']['clientRecord']['salutation']); break; } } $this->assertTrue($found, 'did not find user record in import exceptions: ' . print_r($result['exceptions']->toArray(), true)); }
/** * returns a image link * * @param array $contactArray * @return string */ protected function _getImageLink($contactArray) { $link = 'images/empty_photo_blank.png'; if (!empty($contactArray['jpegphoto'])) { $link = Tinebase_Model_Image::getImageUrl('Addressbook', $contactArray['id'], ''); } else { if (isset($contactArray['salutation']) && !empty($contactArray['salutation'])) { $salutations = Addressbook_Config::getInstance()->get(Addressbook_Config::CONTACT_SALUTATION, NULL); if ($salutations && $salutations->records instanceof Tinebase_Record_RecordSet) { $salutationRecord = $salutations->records->getById($contactArray['salutation']); if ($salutationRecord && $salutationRecord->image) { $link = $salutationRecord->image; } } } } return $link; }
/** * get all salutations */ public function testGetSalutations() { $salutations = Addressbook_Config::getInstance()->contactSalutation; $this->assertGreaterThan(2, count($salutations->records)); }
/** * update to 5.3 * - rename cols lon, lat -> adr_one_lon, adr_one_lat * - add cols adr_two_lon, adr_two_lat * - delete addressbook config we don't need anymore */ public function update_2() { $declaration = new Setup_Backend_Schema_Field_Xml(' <field> <name>adr_one_lon</name> <type>float</type> <unsigned>false</unsigned> </field>'); $this->_backend->alterCol('addressbook', $declaration, 'lon'); $declaration = new Setup_Backend_Schema_Field_Xml(' <field> <name>adr_one_lat</name> <type>float</type> <unsigned>false</unsigned> </field>'); $this->_backend->alterCol('addressbook', $declaration, 'lat'); $declaration = new Setup_Backend_Schema_Field_Xml(' <field> <name>adr_two_lon</name> <type>float</type> <unsigned>false</unsigned> </field>'); $this->_backend->addCol('addressbook', $declaration); $declaration = new Setup_Backend_Schema_Field_Xml(' <field> <name>adr_two_lat</name> <type>float</type> <unsigned>false</unsigned> </field>'); $this->_backend->addCol('addressbook', $declaration); $this->setTableVersion('addressbook', 14); // delete config we don't need anymore Addressbook_Config::getInstance()->delete(Tinebase_Config::APPDEFAULTS); $this->setApplicationVersion('Addressbook', '5.3'); }