/** * appends foreign recordSet (1:n relation) to given recordSet * * @param Tinebase_Record_RecordSet $_recordSet Records to append the foreign records to * @param string $_appendTo Property in the records where to append the foreign records to * @param string $_recordKey Property in the records where the foreign key value is in * @param string $_foreignKey Key property in foreign table of the records to append * @param Tinebase_Backend_Sql_Abstract $_foreignBackend Foreign table backend */ public function appendForeignRecordSetToRecordSet($_recordSet, $_appendTo, $_recordKey, $_foreignKey, $_foreignBackend) { $idxRecordKeyMap = $_recordSet->{$_recordKey}; $recordKeyIdxMap = array_flip($idxRecordKeyMap); $allForeignRecords = $_foreignBackend->getMultipleByProperty($idxRecordKeyMap, $_foreignKey); $foreignRecordsClassName = $allForeignRecords->getRecordClassName(); foreach ($_recordSet as $record) { $record->{$_appendTo} = new Tinebase_Record_RecordSet($foreignRecordsClassName); } foreach ($allForeignRecords as $foreignRecord) { $record = $_recordSet->getByIndex($recordKeyIdxMap[$foreignRecord->{$_foreignKey}]); $foreignRecordSet = $record->{$_appendTo}; $foreignRecordSet->addRecord($foreignRecord); } }
/** * appends foreign recordSet (1:n/m:n relation) to given recordSet * * @param Tinebase_Record_RecordSet $_recordSet Records to append the foreign records to * @param string $_appendTo Property in the records where to append the foreign records to * @param string $_recordKey Property in the records where the foreign key value is in * @param string $_foreignKey Key property in foreign table of the records to append * @param Tinebase_Backend_Sql_Abstract $_foreignBackend Foreign table backend */ public function appendForeignRecordSetToRecordSet($_recordSet, $_appendTo, $_recordKey, $_foreignKey, $_foreignBackend) { $allForeignRecords = $_foreignBackend->getMultipleByProperty($_recordSet->{$_recordKey}, $_foreignKey); foreach ($_recordSet as $record) { $record->{$_appendTo} = $allForeignRecords->filter($_foreignKey, $record->{$_recordKey}); } }