static function copyEntityFile($oldEntityTable, $oldEntityId, $newEntityTable, $newEntityId) { $oldEntityFile = new CRM_Core_DAO_EntityFile(); $oldEntityFile->entity_id = $oldEntityId; $oldEntityFile->entity_table = $oldEntityTable; $oldEntityFile->find(); while ($oldEntityFile->fetch()) { $newEntityFile = new CRM_Core_DAO_EntityFile(); $newEntityFile->entity_id = $newEntityId; $newEntityFile->entity_table = $newEntityTable; $newEntityFile->file_id = $oldEntityFile->file_id; $newEntityFile->save(); } }
/** * Returns all files assigned to a single entity instance. * * @param object $entityID id of the supported entity. * @param string $entity_table * * @return array nested array of entity-file property values. * @access public */ function civicrm_files_by_entity_get($entityID, $entityTable = 'civicrm_contact', $fileID = NULL) { if (!$entityID) { return civicrm_create_error('Required parameters missing'); } require_once 'CRM/Core/DAO/EntityFile.php'; require_once 'CRM/Core/DAO/File.php'; $entityFileDAO = new CRM_Core_DAO_EntityFile(); $entityFileDAO->entity_table = $entityTable; $entityFileDAO->entity_id = $entityID; if ($fileID) { $entityFileDAO->file_id = $fileID; } if ($entityFileDAO->find()) { $entityFile = array(); while ($entityFileDAO->fetch()) { _civicrm_object_to_array($entityFileDAO, $entityFile); $files[$entityFileDAO->file_id] = $entityFile; if (array_key_exists('file_id', $files[$entityFileDAO->file_id])) { $fileDAO = new CRM_Core_DAO_File(); $fileDAO->id = $entityFile['file_id']; $fileDAO->find(TRUE); _civicrm_object_to_array($fileDAO, $files[$entityFileDAO->file_id]); } if (CRM_Utils_Array::value('file_type_id', $files[$entityFileDAO->file_id])) { $files[$entityFileDAO->file_id]['file_type'] = CRM_Core_OptionGroup::getLabel('file_type', $files[$entityFileDAO->file_id]['file_type_id']); } } } else { return civicrm_create_error('Exact match not found'); } return $files; }