Example #1
0
 /**
  * (non-PHPdoc)
  * @see Tinebase_Controller_Record_Abstract::_inspectCreate()
  */
 protected function _inspectCreate(Tinebase_Record_Interface $_record)
 {
     $_record->__set('order_nr', Tinebase_NumberBase_Controller::getInstance()->getNextNumber('order_nr'));
     if (!$_record->__get('payment_method_id')) {
         $_record->__set('payment_method_id', Billing_Controller_PaymentMethod::getInstance()->getDefaultPaymentMethod()->getId());
     }
 }
 /**
  * update one phone
  *
  * @param Voipmanager_Model_Snom_Phone $_phone
  * @return Voipmanager_Model_Snom_Phone
  * @throws Voipmanager_Exception_Validation
  *
  * @todo do not overwrite update() -> use inspectBefore/After functions
  */
 public function update(Tinebase_Record_Interface $_phone)
 {
     $oldRecord = $this->get($_phone->getId());
     $rights = $this->_backend->getPhoneRights($_phone->getId());
     $currentAccountId = Tinebase_Core::getUser()->getId();
     $hasRight = false;
     foreach ($rights as $right) {
         if ($right->account_id == $currentAccountId) {
             // if  user has the right to dial and read the phone, he or she may edit the lines
             if ($right->dial_right && $right->read_right) {
                 $hasRight = true;
             }
         }
     }
     if (!$hasRight) {
         throw new Tinebase_Exception_AccessDenied('You are not allowed to edit this phone!');
     }
     // user is not allowed to add or remove lines
     $diff = $oldRecord->lines->diff($_phone->lines);
     if (count($diff->added) > 0 || count($diff->removed) > 0) {
         throw new Tinebase_Exception_AccessDenied('You are not allowed to add or remove lines of this phone!');
     }
     // user may just edit the lines and settings of the phone
     $oldRecord->lines = $_phone->lines;
     $oldRecord->settings = $_phone->settings;
     return parent::update($oldRecord);
 }
Example #3
0
 /**
  * 
  * Append dependent records as contact or price_group
  * @param Tinebase_Record_Interface $record
  */
 protected function appendDependentRecords($record)
 {
     if ($record->__get('contact_id')) {
         $this->appendForeignRecordToRecord($record, 'contact_id', 'contact_id', 'id', Addressbook_Backend_Factory::factory(Addressbook_Backend_Factory::SQL));
     }
     if ($record->__get('bank_id')) {
         $this->appendForeignRecordToRecord($record, 'bank_id', 'bank_id', 'id', new Billing_Backend_Bank());
     }
 }
 /**
  * converts record into raw data for adapter
  *
  * @param  Tinebase_Record_Interface $_record
  * @return array
  */
 protected function _recordToRawData(Tinebase_Record_Interface $_record)
 {
     if (is_object($_record->filters)) {
         $_record->filters->removeId();
     }
     $rawData = $_record->toArray();
     $rawData['filters'] = Zend_Json::encode($rawData['filters']);
     return $rawData;
 }
Example #5
0
 /**
  * (non-PHPdoc)
  * @see Tinebase_Controller_Record_Abstract::_inspectCreate()
  */
 protected function _inspectCreate(Tinebase_Record_Interface $_record)
 {
     // check whether the article nr is set? -> then do not overwrite: maybe from export...
     if (!$_record->__get('article_nr')) {
         $_record->__set('article_nr', Tinebase_NumberBase_Controller::getInstance()->getNextNumber('article_nr'));
     }
     if (!$_record->__get('price2_vat_id')) {
         $vat0 = Billing_Controller_Vat::getInstance()->getByName(0);
         $_record->__set('price2_vat_id', $vat0->getId());
     }
 }
 /**
  * get special field value
  *
  * @param Tinebase_Record_Interface $_record
  * @param array $_param
  * @param string $_key
  * @param string $_cellType
  * @param array $_resolvedRecords
  * @return string
  */
 public static function getSpecialFieldValue(Tinebase_Record_Interface $_record, $_param, $_key = NULL, &$_cellType = NULL, $_resolvedRecords = NULL)
 {
     if (is_null($_key)) {
         throw new Tinebase_Exception_InvalidArgument('Missing required parameter $key');
     }
     switch ($_param['type']) {
         case 'status':
             $value = $_record->getLeadStatus();
             break;
         case 'source':
             $settings = Crm_Controller::getInstance()->getConfigSettings();
             $source = $settings->getOptionById($_record->leadsource_id, 'leadsources');
             if (isset($source['leadsource'])) {
                 $value = $source['leadsource'];
             } else {
                 Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' Leadsource id not found:' . $_record->leadsource_id);
                 $value = '';
             }
             break;
         case 'type':
             $settings = Crm_Controller::getInstance()->getConfigSettings();
             $type = $settings->getOptionById($_record->leadtype_id, 'leadtypes');
             if (isset($type['leadtype'])) {
                 $value = $type['leadtype'];
             } else {
                 Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' Leadtype id not found:' . $_record->leadtype_id);
                 $value = '';
             }
             break;
         case 'open_tasks':
             $value = 0;
             foreach ($_record->relations as $relation) {
                 // check if is task and open
                 if ($relation->type == 'TASK') {
                     $idx = $_resolvedRecords['tasksStatus']->getIndexById($relation->related_record->status);
                     if ($idx) {
                         $status = $_resolvedRecords['tasksStatus'][$idx];
                         //if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . print_r($status->toArray(), TRUE));
                         if ($status->is_open) {
                             $value++;
                         }
                     }
                 }
             }
             break;
         default:
             $value = '';
     }
     return $value;
 }
Example #7
0
 /**
  * 
  * Append dependent records as contact or price_group
  * @param Tinebase_Record_Interface $record
  */
 protected function appendDependentRecords($record)
 {
     if ($record->__get('contact_id')) {
         $this->appendForeignRecordToRecord($record, 'contact_id', 'contact_id', 'id', Addressbook_Backend_Factory::factory(Addressbook_Backend_Factory::SQL));
     }
     if ($record->__get('price_group_id')) {
         $this->appendForeignRecordToRecord($record, 'price_group_id', 'price_group_id', 'id', new Billing_Backend_PriceGroup());
     }
     if ($record->__get('debitor_group_id')) {
         $this->appendForeignRecordToRecord($record, 'debitor_group_id', 'debitor_group_id', 'id', new Billing_Backend_DebitorGroup());
     }
     if ($record->__get('vat_id')) {
         $this->appendForeignRecordToRecord($record, 'vat_id', 'vat_id', 'id', new Billing_Backend_Vat());
     }
 }
 /**
  * update foreign key values
  * 
  * @param string $_mode create|update
  * @param Tinebase_Record_Interface $_record
  * 
  * @todo support update mode
  */
 protected function _updateForeignKeys($_mode, Tinebase_Record_Interface $_record)
 {
     if ($_mode == 'create') {
         foreach ($this->_foreignTables as $key => $foreign) {
             if (!isset($_record->{$key}) || empty($_record->{$key})) {
                 continue;
             }
             if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
                 Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . $key . ': ' . print_r($_record->{$key}, TRUE));
             }
             foreach ($_record->{$key} as $data) {
                 if ($key == 'flags') {
                     $data = array('flag' => $data, 'folder_id' => $_record->folder_id);
                 } else {
                     // need to filter input as 'name' could contain invalid chars (emojis, ...) here
                     foreach ($data as $field => $value) {
                         $data[$field] = Tinebase_Core::filterInputForDatabase($data[$field]);
                     }
                 }
                 $data['message_id'] = $_record->getId();
                 $this->_db->insert($this->_tablePrefix . $foreign['table'], $data);
             }
         }
     }
 }
 /**
  * Checks if number is unique if manual generated
  * 
  * @param Tinebase_Record_Interface $record
  * @param Boolean $update true if called un update
  * @throws Tinebase_Exception_Duplicate
  * @return boolean
  */
 protected function _checkNumberUniquity($record, $update = FALSE)
 {
     $filterArray = array(array('field' => 'number', 'operator' => 'equals', 'value' => $record->{$this->_numberProperty}));
     if ($update) {
         $filterArray[] = array('field' => 'id', 'operator' => 'notin', 'value' => $record->getId());
     }
     $filterName = $this->_modelName . 'Filter';
     $filter = new $filterName($filterArray);
     $existing = $this->search($filter);
     if (count($existing->toArray()) > 0) {
         $e = new Tinebase_Exception_Duplicate(_('The number you have tried to set is already in use!'));
         $e->setData($existing);
         $e->setClientRecord($record);
         throw $e;
     }
     return true;
 }
Example #10
0
 /**
  * (non-PHPdoc)
  * @see Tinebase_Controller_Record_Abstract::_inspectCreate()
  */
 protected function _inspectCreate(Tinebase_Record_Interface $_record)
 {
     $stockLocationId = $_record->__get('stock_location_id');
     $articleId = $_record->__get('article_id');
     try {
         $articleSupply = $this->_articleSupplyController->getByStockLocationArticle($stockLocationId, $articleId);
     } catch (Exception $e) {
         $articleSupply = $this->_articleSupplyController->getEmptyArticleSupply();
         $articleSupply->__set('stock_location_id', $stockLocationId);
         $articleSupply->__set('article_id', $articleId);
         $articleSupply->__set('amount', 0);
         $this->_articleSupplyController->create($articleSupply);
     }
     $stockAmount = (double) $articleSupply->__get('amount');
     $articleSupply->__set('amount', $stockAmount + $this->calculateStockAmountChange($_record));
     $this->_articleSupplyController->update($articleSupply);
 }
Example #11
0
 /**
  * inspect create of one record
  * 
  * @param   Tinebase_Record_Interface $_record      the update record
  * @param   Tinebase_Record_Interface $_oldRecord   the current persistent record
  * @return  void
  */
 protected function _inspectCreate($_record, $_oldRecord)
 {
     $_record->__set('payment_date', new Zend_Date($_record->__get('payment_date')));
     $order = $_record->getForeignRecordBreakNull('order_id', Billing_Controller_Order::getInstance());
     if (!$_record->__get('erp_context_id') && $order) {
         $_record->__set('erp_context_id', $order->__get('erp_context_id'));
     }
     $this->handleReturnDebit($_record);
 }
 /**
  * 
  * Append dependent records as contact or price_group
  * @param Tinebase_Record_Interface $record
  */
 protected function appendDependentRecords($record)
 {
     if ($record->__get('contact_id')) {
         $this->appendForeignRecordToRecord($record, 'contact_id', 'contact_id', 'id', Addressbook_Backend_Factory::factory(Addressbook_Backend_Factory::SQL));
     }
     if ($record->__get('bank_id')) {
         $this->appendForeignRecordToRecord($record, 'bank_id', 'bank_id', 'id', new Billing_Backend_Bank());
     }
     if ($record->__get('bank_account_id')) {
         $this->appendForeignRecordToRecord($record, 'bank_account_id', 'bank_account_id', 'id', new Billing_Backend_BankAccount());
     }
     if ($record->__get('sepa_mandate_id')) {
         $this->appendForeignRecordToRecord($record, 'sepa_mandate_id', 'sepa_mandate_id', 'id', new Billing_Backend_SepaMandate());
     }
     if ($record->__get('membership_id')) {
         $this->appendForeignRecordToRecord($record, 'membership_id', 'membership_id', 'id', new Membership_Backend_SoMember());
     }
     if ($record->__get('regular_donation_id')) {
         $this->appendForeignRecordToRecord($record, 'regular_donation_id', 'regular_donation_id', 'id', new Donator_Backend_RegularDonation());
     }
 }
Example #13
0
 /**
  * (non-PHPdoc)
  * @see Tinebase_Controller_Record_Abstract::_inspectCreate()
  */
 protected function _inspectCreate(Tinebase_Record_Interface $_record)
 {
     $type = $_record->__get('type');
     switch ($type) {
         case SPQUERY:
             $_record->__set('supply_request_nr', Tinebase_NumberBase_Controller::getInstance()->getNextNumber('supply_request_nr'));
             break;
         case SPOFFER:
             $_record->__set('supply_offer_nr', Tinebase_NumberBase_Controller::getInstance()->getNextNumber('supply_offer_nr'));
             break;
         case SPORDER:
             $_record->__set('supply_order_nr', Tinebase_NumberBase_Controller::getInstance()->getNextNumber('supply_order_nr'));
             break;
         case SPINVOICE:
             $_record->__set('supply_inc_inv_nr', Tinebase_NumberBase_Controller::getInstance()->getNextNumber('supply_inc_inv_nr'));
             break;
     }
 }
Example #14
0
 /**
  * inspect creation of one record (after create)
  * 
  * @param   Tinebase_Record_Interface $_createdRecord
  * @param   Tinebase_Record_Interface $_record
  * @return  void
  */
 protected function _inspectAfterCreate($_createdRecord, Tinebase_Record_Interface $_record)
 {
     $this->_setTagRights($_record, $_createdRecord->getId());
     Tinebase_Tags::getInstance()->setContexts($_record->contexts, $_createdRecord->getId());
 }
 /**
  * inspect update of one record (before update)
  *
  * @param   Tinebase_Record_Interface $_record      the update record
  * @param   Tinebase_Record_Interface $_oldRecord   the current persistent record
  * @return  void
  */
 protected function _inspectBeforeUpdate($_record, $_oldRecord)
 {
     // protect against file object spoofing
     foreach (array_keys($_record->toArray()) as $property) {
         if (!in_array($property, array('name', 'description', 'relations', 'customfields', 'tags', 'notes'))) {
             $_record->{$property} = $_oldRecord->{$property};
         }
     }
 }
 /**
  * returns message prepared for json transport
  * - overwriten to convert recipients to array
  *
  * @param Tinebase_Record_Interface $_record
  * @return array record data
  */
 protected function _recordToJson($_record)
 {
     if ($_record instanceof Felamimail_Model_Message) {
         foreach (array('to', 'cc', 'bcc') as $type) {
             if (!is_array($_record->{$type})) {
                 if (!empty($_record->{$type})) {
                     $exploded = explode(',', $_record->{$type});
                     $_record->{$type} = $exploded;
                 } else {
                     $_record->{$type} = array();
                 }
             }
         }
         if ($_record->preparedParts instanceof Tinebase_Record_RecordSet) {
             foreach ($_record->preparedParts as $preparedPart) {
                 if ($preparedPart->preparedData instanceof Calendar_Model_iMIP) {
                     try {
                         $iMIPFrontend = new Calendar_Frontend_iMIP();
                         $iMIPFrontend->prepareComponent($preparedPart->preparedData, true);
                     } catch (Exception $e) {
                         Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' Could not prepare calendar iMIP component: ' . $e->getMessage());
                         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . $e->getTraceAsString());
                         }
                         $_record->preparedParts->removeRecord($preparedPart);
                     }
                 }
             }
         }
     } else {
         if ($_record instanceof Felamimail_Model_Account) {
             // add usernames
             $_record->resolveCredentials();
             // imap
             $_record->resolveCredentials(TRUE, FALSE, TRUE);
             // smtp
         } else {
             if ($_record instanceof Felamimail_Model_Sieve_Vacation) {
                 if (!$_record->mime) {
                     $_record->reason = Tinebase_Mail::convertFromTextToHTML($_record->reason, 'felamimail-body-blockquote');
                 }
             }
         }
     }
     return parent::_recordToJson($_record);
 }
 /**
  * get all alarms of given record(s) / adds record_id index to result set
  * 
  * @param  string $_model model to get alarms for
  * @param  string|array|Tinebase_Record_Interface|Tinebase_Record_RecordSet $_recordId record id(s) to get alarms for
  * @param  boolean $_onlyIds
  * @return Tinebase_Record_RecordSet|array of ids
  */
 public function getAlarmsOfRecord($_model, $_recordId, $_onlyIds = FALSE)
 {
     if ($_recordId instanceof Tinebase_Record_RecordSet) {
         $recordId = $_recordId->getArrayOfIds();
     } else {
         if ($_recordId instanceof Tinebase_Record_Interface) {
             $recordId = $_recordId->getId();
         } else {
             $recordId = $_recordId;
         }
     }
     //if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . "  model: '$_model' id:" . print_r((array)$recordId, true));
     $filter = new Tinebase_Model_AlarmFilter(array(array('field' => 'model', 'operator' => 'equals', 'value' => $_model), array('field' => 'record_id', 'operator' => 'in', 'value' => (array) $recordId)));
     $result = $this->_backend->search($filter, NULL, $_onlyIds);
     // NOTE: Adding indices to empty recordsets breaks empty tests
     if (count($result) > 0 && $result instanceof Tinebase_Record_RecordSet) {
         $result->addIndices(array('record_id'));
     }
     return $result;
 }
Example #18
0
 /**
  * returns all observers of a given observable and event
  * 
  * @param Tinebase_Record_Interface $_observable 
  * @param string _event 
  * @return Tinebase_Record_RecordSet
  */
 protected function getObserversByEvent($_observable, $_event)
 {
     if (!$_observer->getApplication() || !$_observer->getId()) {
         throw new Tinebase_Exception_Record_DefinitionFailure();
     }
     $where = array($this->_db->quoteIdentifier('observable_application') . ' =' . $_observable->getApplication(), $this->_db->quoteIdentifier('observable_identifier') . '  =' . $_observable->getId(), $this->_db->quoteIdentifier('observed_event') . '         =' . $this->_db->getAdapter()->quote($_event));
     return new Tinebase_Record_RecordSet('Tinebase_Model_PersistentObserver', $this->_db->fetchAll($where), true);
 }
 /**
  * delete linked objects (notes, relations, ...) of record
  *
  * @param Tinebase_Record_Interface $_record
  */
 protected function _deleteLinkedObjects(Tinebase_Record_Interface $_record)
 {
     // use textfilter for employee_id
     $eFilter = new Tinebase_Model_Filter_Text(array('field' => 'employee_id', 'operator' => 'equals', 'value' => $_record->getId()));
     // delete free times
     $filter = new HumanResources_Model_FreeTimeFilter(array(), 'AND');
     $filter->addFilter($eFilter);
     HumanResources_Controller_FreeTime::getInstance()->deleteByFilter($filter);
     // delete contracts
     $filter = new HumanResources_Model_ContractFilter(array(), 'AND');
     $filter->addFilter($eFilter);
     HumanResources_Controller_Contract::getInstance()->deleteByFilter($filter);
     // delete costcenters
     if ($_record->has('costcenters')) {
         $filter = new HumanResources_Model_CostCenterFilter(array(), 'AND');
         $filter->addFilter($eFilter);
         HumanResources_Controller_CostCenter::getInstance()->deleteByFilter($filter);
     }
     // delete accounts
     $filter = new HumanResources_Model_AccountFilter(array());
     $filter->addFilter(new Tinebase_Model_Filter_Text(array('field' => 'employee_id', 'operator' => 'equals', 'value' => $_record->getId())));
     HumanResources_Controller_Account::getInstance()->deleteByFilter($filter);
     parent::_deleteLinkedObjects($_record);
 }
 /**
  * getPathsForRecords
  *
  * @param Tinebase_Record_Interface|Tinebase_Record_RecordSet $records
  * @return Tinebase_Record_RecordSet
  * @throws Tinebase_Exception_NotFound
  */
 public function getPathsForRecords($records)
 {
     $ids = $records instanceof Tinebase_Record_Interface ? array($records->getId()) : $records->getArrayOfIds();
     return $this->search(new Tinebase_Model_PathFilter(array(array('field' => 'record_id', 'operator' => 'in', 'value' => $ids))));
 }
 /**
  * inspect creation of one record (after create)
  *
  * @param   Tinebase_Record_Interface $_createdRecord
  * @param   Tinebase_Record_Interface $_record
  * @return  void
  *
  * @todo $_record->contracts should be a Tinebase_Record_RecordSet
  */
 protected function _inspectAfterCreate($_createdRecord, Tinebase_Record_Interface $_record)
 {
     if (!$_createdRecord->start_date) {
         return;
     }
     // find contract before, set end_date one day before the new contracts' start_date, if needed
     $filter = new HumanResources_Model_ContractFilter(array(array('field' => 'start_date', 'operator' => 'before', 'value' => $_createdRecord->start_date)));
     $filter->addFilter(new Tinebase_Model_Filter_Text(array('field' => 'end_date', 'operator' => 'isnull', 'value' => TRUE)));
     $filter->addFilter(new Tinebase_Model_Filter_Text(array('field' => 'id', 'operator' => 'not', 'value' => $_createdRecord->getId())));
     $filter->addFilter(new Tinebase_Model_Filter_Text(array('field' => 'employee_id', 'operator' => 'equals', 'value' => $_createdRecord->employee_id)));
     $contracts = $this->search($filter);
     if ($contracts->count() > 1) {
         throw new Tinebase_Exception_Data('There are more than 1 contracts before the new one without an end_date. Please terminate them before!');
     }
     // if a contract was found, terminate it
     if ($contracts->count()) {
         $contract = $contracts->getFirstRecord();
         $endDate = clone $_createdRecord->start_date;
         $endDate->subDay(1);
         $contract->end_date = $endDate;
         $this->update($contract);
     }
 }
 /**
  * checks cleared state and sets the date to the current date, also sets all billables billed
  * 
  * @param Tinebase_Record_Interface $record
  * @param Tinebase_Record_Interface $oldRecord
  */
 protected function _checkCleared(Tinebase_Record_Interface &$record, Tinebase_Record_Interface $oldRecord = NULL)
 {
     $foundCustomer = NULL;
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Invoice: ' . print_r($record->toArray(), true));
     }
     if (is_array($record->relations)) {
         foreach ($record->relations as $relation) {
             if ($relation['related_model'] == 'Sales_Model_Customer') {
                 $foundCustomer = $relation['related_record'];
                 break;
             }
             if ($relation['related_model'] == 'Sales_Model_Contract') {
                 $foundContractRecord = Sales_Controller_Contract::getInstance()->get($relation['related_record']['id']);
                 if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
                     Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Contract: ' . print_r($foundContractRecord->toArray(), true));
                 }
                 foreach ($foundContractRecord->relations as $relation) {
                     if ($relation['related_model'] == 'Sales_Model_Customer') {
                         $foundCustomer = $relation['related_record'];
                         break;
                     }
                 }
             }
         }
     }
     if (empty($record->address_id) && $foundCustomer) {
         $json = new Sales_Frontend_Json();
         $resolved = $json->getCustomer($foundCustomer->getId());
         if (!empty($resolved['billing'])) {
             $record->address_id = $resolved['billing'][0]['id'];
         } else {
             throw new Tinebase_Exception_Data('You have to set a billing address!');
         }
     }
     // if the record hasn't been cleared before, clear billables
     if ($record->cleared == 'CLEARED' && (!$oldRecord || $oldRecord->cleared != 'CLEARED')) {
         if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
             Tinebase_Core::getLogger()->log(__METHOD__ . '::' . __LINE__ . ' Clearing Invoice ' . print_r($record->toArray(), 1), Zend_Log::INFO);
         }
         if (!$record->date) {
             $record->date = new Tinebase_DateTime();
         }
         $this->_setNextNumber($record, isset($oldRecord));
         $address = Sales_Controller_Address::getInstance()->get(is_string($record->address_id) ? $record->address_id : $record->address_id . id);
         $string = $foundCustomer['name'] . PHP_EOL;
         $string .= $address->prefix1 ? $address->prefix1 . "\n" : '';
         $string .= $address->prefix2 ? $address->prefix2 . "\n" : '';
         $string .= $address->pobox ? $address->pobox . "\n" : '';
         $string .= $address->street ? $address->street . "\n" : '';
         $poloc = $address->postalcode ? $address->postalcode . " " : '';
         $poloc .= $address->locality ? $address->locality : '';
         if (!empty($poloc)) {
             $string .= $poloc . PHP_EOL;
         }
         $string .= $address->countryname ? $address->countryname : '';
         $record->fixed_address = $string;
         // clear all billables
         if (!empty($record->relations)) {
             foreach ($record->relations as $relation) {
                 if (in_array('Sales_Model_Accountable_Interface', class_implements($relation['related_model']))) {
                     if (is_array($relation['related_record'])) {
                         $rr = new $relation['related_model']($relation['related_record']);
                     } else {
                         $rr = $relation['related_record'];
                     }
                     $rr->clearBillables($record);
                     if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
                         Tinebase_Core::getLogger()->log(__METHOD__ . '::' . __LINE__ . ' Clearing billables ' . print_r($rr->toArray(), 1), Zend_Log::INFO);
                     }
                 }
             }
         }
     }
 }
Example #23
0
 /**
  * inspect update of system account
  * - only allow to update certain fields of system accounts
  * 
  * @param   Tinebase_Record_Interface $_record      the update record
  * @param   Tinebase_Record_Interface $_oldRecord   the current persistent record
  * @return  void
  */
 protected function _beforeUpdateSystemAccount($_record, $_oldRecord)
 {
     // only allow to update some values for system accounts
     $allowedFields = array('name', 'signature', 'signature_position', 'has_children_support', 'delimiter', 'ns_personal', 'ns_other', 'ns_shared', 'last_modified_time', 'last_modified_by');
     $diff = $_record->diff($_oldRecord);
     foreach ($diff as $key => $value) {
         if (!in_array($key, $allowedFields)) {
             // setting old value
             $_record->{$key} = $_oldRecord->{$key};
         }
     }
 }
Example #24
0
 /**
  * Creates new entry
  *
  * @param   Tinebase_Record_Interface $_record
  * @return  Tinebase_Record_Interface
  * @throws  Tinebase_Exception_InvalidArgument
  * @throws  Tinebase_Exception_UnexpectedValue
  * 
  * @todo    remove autoincremental ids later
  */
 public function create(Tinebase_Record_Interface $_record)
 {
     $folder = $_record->toArray();
     $return = $this->get($this->encodeFolderUid($folder['globalname'], $folder['account_id']));
     return $return;
 }
 /**
  * delete linked objects (notes, relations, ...) of record
  *
  * @param Tinebase_Record_Interface $_record
  */
 protected function _deleteLinkedObjects(Tinebase_Record_Interface $_record)
 {
     // use textfilter for contract_id
     $filter = new Sales_Model_ProductAggregateFilter(array());
     $filter->addFilter(new Tinebase_Model_Filter_Text(array('field' => 'contract_id', 'operator' => 'equals', 'value' => $_record->getId())));
     Sales_Controller_ProductAggregate::getInstance()->deleteByFilter($filter);
     parent::_deleteLinkedObjects($_record);
 }
 /**
  * get special field value
  *
  * @param Tinebase_Record_Interface $_record
  * @param array $_param
  * @param string $_key
  * @param string $_cellType
  * @return string
  */
 protected function _getSpecialFieldValue(Tinebase_Record_Interface $_record, $_param, $_key = NULL, &$_cellType = NULL)
 {
     $customerId = $_record->getId();
     if (!isset($this->_customerAddresses[$customerId])) {
         $all = $this->_addresses->filter('customer_id', $customerId);
         $this->_addresses->removeRecords($all);
         $this->_customerAddresses[$customerId] = array('postal' => $all->filter('type', 'postal')->getFirstRecord(), 'billing' => array('records' => $all->filter('type', 'billing'), 'index' => 0), 'delivery' => array('records' => $all->filter('type', 'delivery'), 'index' => 0));
     }
     switch ($_param['type']) {
         case 'postal':
             $address = $this->_customerAddresses[$customerId]['postal'];
             break;
         case 'address':
             return $this->_contacts->filter('id', $_record->{$_param['identifier']})->getFirstRecord()->n_fn;
         default:
             if (isset($this->_customerAddresses[$customerId][$_param['type']]['records'])) {
                 $address = $this->_customerAddresses[$customerId][$_param['type']]['records']->getByIndex($this->_customerAddresses[$customerId][$_param['type']]['index']);
                 $this->_customerAddresses[$customerId][$_param['type']]['index']++;
             }
     }
     return $address ? $this->_renderAddress($address, $_param['type']) : '';
 }
 /**
  * delete linked objects / timesheets
  *
  * @param Tinebase_Record_Interface $_record
  */
 protected function _deleteLinkedObjects(Tinebase_Record_Interface $_record)
 {
     // delete linked timesheets
     $timesheets = Timetracker_Controller_Timesheet::getInstance()->getTimesheetsByTimeaccountId($_record->getId());
     Timetracker_Controller_Timesheet::getInstance()->delete($timesheets->getArrayOfIds());
     // delete other linked objects
     parent::_deleteLinkedObjects($_record);
 }
 /**
  * Updates existing entry
  *
  * @param Tinebase_Record_Interface $_record
  * @throws Tinebase_Exception_Record_Validation|Tinebase_Exception_InvalidArgument
  * @return Tinebase_Record_Interface Record|NULL
  */
 public function update(Tinebase_Record_Interface $_record)
 {
     $identifier = $_record->getIdProperty();
     if (!$_record instanceof $this->_modelName) {
         throw new Tinebase_Exception_InvalidArgument('invalid model type: $_record is instance of "' . get_class($_record) . '". but should be instance of ' . $this->_modelName);
     }
     /** @var Tinebase_Record_Interface $_record */
     $_record->isValid(TRUE);
     $id = $_record->getId();
     $recordArray = $this->_recordToRawData($_record);
     $recordArray = array_intersect_key($recordArray, $this->getSchema());
     $this->_prepareData($recordArray);
     $where = array($this->_db->quoteInto($this->_db->quoteIdentifier($identifier) . ' = ?', $id));
     $this->_db->update($this->_tablePrefix . $this->_tableName, $recordArray, $where);
     // update custom fields
     if ($_record->has('customfields')) {
         Tinebase_CustomField::getInstance()->saveRecordCustomFields($_record);
     }
     $this->_updateForeignKeys('update', $_record);
     $result = $this->get($id, true);
     return $result;
 }
 /**
  * get option setting string
  * 
  * @deprecated
  * @param Tinebase_Record_Interface $_record
  * @param string $_id
  * @param string $_label
  * @return string
  */
 public static function getOptionString($_record, $_label)
 {
     $controller = Tinebase_Core::getApplicationInstance($_record->getApplication());
     $settings = $controller->getConfigSettings();
     $idField = $_label . '_id';
     $option = $settings->getOptionById($_record->{$idField}, $_label . 's');
     $result = isset($option[$_label]) ? $option[$_label] : '';
     return $result;
 }
 /**
  * get and resolve all alarms of given record(s)
  * 
  * @param  Tinebase_Record_Interface|Tinebase_Record_RecordSet $_record
  */
 public function getAlarms($_record)
 {
     $events = $_record instanceof Tinebase_Record_RecordSet ? $_record->getClone(true) : new Tinebase_Record_RecordSet('Calendar_Model_Event', array($_record));
     foreach ($events as $event) {
         if ($event->exdate instanceof Tinebase_Record_RecordSet) {
             //                 $event->exdate->addIndices(array('is_deleted'));
             $events->merge($event->exdate->filter('is_deleted', 0));
         }
     }
     $this->_eventController->getAlarms($events);
 }