protected function _getRelation($contract, $ipnet) { $r = new Tinebase_Model_Relation(); $ra = array('own_model' => 'Sales_Model_Coustomer', 'own_backend' => 'Sql', 'own_id' => $ipnet->getId(), 'own_degree' => 'sibling', 'remark' => 'phpunit test', 'related_model' => 'Sales_Model_Contract', 'related_backend' => 'Sql', 'related_id' => $contract->getId(), 'type' => 'CONTRACT'); $r->setFromArray($ra); return $r; }
/** * iterate relations * * @param Tinebase_Record_Abstract $currentRecord * @return array */ protected function _iterateRelations($currentRecord) { if (!$currentRecord->relations || get_class($currentRecord->relations) != 'Tinebase_Record_RecordSet') { $currentRecord->relations = new Tinebase_Record_RecordSet('Tinebase_Model_Relation'); } $be = new Tinebase_Relation_Backend_Sql(); // handle relations to remove if ($this->_removeRelations) { if ($currentRecord->relations->count()) { foreach ($this->_removeRelations as $remRelation) { $removeRelations = $currentRecord->relations->filter('type', $remRelation['type'])->filter('related_model', $remRelation['related_model']); $currentRecord->relations->removeRecords($removeRelations); } } } // handle new relations if ($this->_newRelations) { $removeRelations = NULL; foreach ($this->_newRelations as $newRelation) { $removeRelations = $currentRecord->relations->filter('type', $newRelation['type'])->filter('related_model', $newRelation['related_model']); $already = $removeRelations->filter('related_id', $newRelation['related_id']); if ($already->count() > 0) { $removeRelations = NULL; } else { $newRelation['own_id'] = $currentRecord->getId(); $rel = new Tinebase_Model_Relation(); $rel->setFromArray($newRelation); if ($removeRelations) { $currentRecord->relations->removeRecords($removeRelations); } $currentRecord->relations->addRecord($rel); } } } return $currentRecord->relations->toArray(); }
/** * iterate relations * * @param Tinebase_Record_Interface $currentRecord * @return array */ protected function _iterateRelations($currentRecord) { if (!$currentRecord->relations || get_class($currentRecord->relations) != 'Tinebase_Record_RecordSet') { $currentRecord->relations = new Tinebase_Record_RecordSet('Tinebase_Model_Relation'); } // handle relations to remove if ($this->_removeRelations) { if ($currentRecord->relations->count()) { foreach ($this->_removeRelations as $remRelation) { $removeRelations = $currentRecord->relations->filter('type', $remRelation['type'])->filter('related_model', $remRelation['related_model']); $currentRecord->relations->removeRecords($removeRelations); } } } // handle new relations if ($this->_newRelations) { foreach ($this->_newRelations as $newRelation) { // convert duplicate to update (remark / degree) $duplicate = $currentRecord->relations->filter('related_model', $newRelation['related_model'])->filter('related_id', $newRelation['related_id'])->filter('type', $newRelation['type'])->getFirstRecord(); if ($duplicate) { $currentRecord->relations->removeRecord($duplicate); } $newRelation['own_id'] = $currentRecord->getId(); $rel = new Tinebase_Model_Relation(); $rel->setFromArray($newRelation); $currentRecord->relations->addRecord($rel); } } return $currentRecord->relations->toArray(); }