/** * parse ldap result set and update Addressbook_Model_Contact * * @param array $_userData * @param Addressbook_Model_Contact $_contact */ protected function _ldap2Contact($_userData, Addressbook_Model_Contact $_contact) { $rowNameMapping = array('bday' => 'birthdate', 'tel_cell' => 'mobile', 'tel_work' => 'telephonenumber', 'tel_home' => 'homephone', 'tel_fax' => 'facsimiletelephonenumber', 'org_name' => 'o', 'org_unit' => 'ou', 'email_home' => 'mozillasecondemail', 'jpegphoto' => 'jpegphoto', 'adr_two_locality' => 'mozillahomelocalityname', 'adr_two_postalcode' => 'mozillahomepostalcode', 'adr_two_region' => 'mozillahomestate', 'adr_two_street' => 'mozillahomestreet', 'adr_one_locality' => 'l', 'adr_one_postalcode' => 'postalcode', 'adr_one_street' => 'street', 'adr_one_region' => 'st'); foreach ($_userData as $key => $value) { if (is_int($key)) { continue; } $keyMapping = array_search($key, $rowNameMapping); if ($keyMapping !== FALSE) { switch ($keyMapping) { case 'bday': $_contact->{$keyMapping} = Tinebase_DateTime::createFromFormat('Y-m-d', $value[0]); break; default: $_contact->{$keyMapping} = $value[0]; break; } } } }
/** * calculates the vacation days count of a contract for a period given by firstDate and lastDate. * if the period exceeds the contracts' period, the contracts' period will be used * * @param HumanResources_Model_Contract|Tinebase_Record_RecordSet $contracts * @param Tinebase_DateTime $firstDate * @param Tinebase_DateTime $lastDate * @return float */ public function calculateVacationDays($contracts, Tinebase_DateTime $gFirstDate, Tinebase_DateTime $gLastDate) { $contracts = $this->_convertToRecordSet($contracts); $sum = 0; foreach ($contracts as $contract) { $firstDate = $this->_getFirstDate($contract, $gFirstDate); $lastDate = $this->_getLastDate($contract, $gLastDate); // find out how many days the year does have $januaryFirst = Tinebase_DateTime::createFromFormat('Y-m-d H:i:s e', $firstDate->format('Y') . '-01-01 00:00:00 ' . Tinebase_Core::getUserTimezone()); $decemberLast = Tinebase_DateTime::createFromFormat('Y-m-d H:i:s e', $firstDate->format('Y') . '-12-31 23:59:59 ' . Tinebase_Core::getUserTimezone()); $daysOfTheYear = ($decemberLast->getTimestamp() - $januaryFirst->getTimestamp()) / 24 / 60 / 60; // find out how many days the contract does have $daysOfTheContract = ($lastDate->getTimestamp() - $firstDate->getTimestamp()) / 24 / 60 / 60; $correl = $daysOfTheContract / $daysOfTheYear; $sum = $sum + $correl * $contract->vacation_days; } return $sum; }
/** * parse ldap result set and update Addressbook_Model_Contact * * @param array $_userData * @param Addressbook_Model_Contact $_contact */ protected function _ldap2Contact($_userData, Addressbook_Model_Contact $_contact) { $rowNameMapping = array('bday' => 'birthdate', 'tel_cell' => 'mobile', 'tel_work' => 'telephonenumber', 'tel_home' => 'homephone', 'tel_fax' => 'facsimiletelephonenumber', 'org_name' => 'o', 'org_unit' => 'ou', 'email_home' => 'mozillasecondemail', 'jpegphoto' => 'jpegphoto', 'adr_two_locality' => 'mozillahomelocalityname', 'adr_two_postalcode' => 'mozillahomepostalcode', 'adr_two_region' => 'mozillahomestate', 'adr_two_street' => 'mozillahomestreet', 'adr_one_locality' => 'l', 'adr_one_postalcode' => 'postalcode', 'adr_one_street' => 'street', 'adr_one_region' => 'st'); $overwrittenFields = Tinebase_Config::getInstance()->get(Tinebase_Config::LDAP_OVERWRITE_CONTACT_FIELDS); foreach ($rowNameMapping as $tineKey => $ldapKey) { if (isset($_userData[$ldapKey])) { switch ($tineKey) { case 'bday': $_contact->{$tineKey} = Tinebase_DateTime::createFromFormat('Y-m-d', $_userData[$ldapKey][0]); break; default: $_contact->{$tineKey} = $_userData[$ldapKey][0]; break; } } else { if (in_array($tineKey, $overwrittenFields)) { // should empty values in ldap overwrite tine values $_contact->{$tineKey} = ''; } } } }