src/Entity/Document.php line 66

Open in your IDE?
  1. <?php
  2. namespace MedBrief\MSR\Entity;
  3. use DH\Auditor\Provider\Doctrine\Auditing\Annotation as Audit;
  4. use Doctrine\Common\Collections\Collection as DoctrineCollection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Gedmo\Mapping\Annotation as Gedmo;
  7. use JsonSerializable;
  8. use MedBrief\MSR\Repository\DocumentRepository;
  9. use MedBrief\MSR\Service\File\FileHandler\FileHandledInterface;
  10. use MedBrief\MSR\Service\MimeTypes;
  11. use MedBrief\MSR\Service\ProjectClosure\RemoveRecords\RemovableRecordInterface;
  12. use MedBrief\MSR\Service\VirusScan\Async\VirusScannableInterface;
  13. use MedBrief\MSR\Service\VirusScan\Async\Visitor\VirusScannerPathVisitorInterface;
  14. /**
  15. * Document
  16. *
  17. * @ORM\Table(name="Document", indexes={@ORM\Index(name="created_index", columns={"created"}), @ORM\Index(name="deletedAt_index", columns={"deletedAt"}), @ORM\Index(name="convertedToSwfStatus_index", columns={"convertedToSwfStatus"}), @ORM\Index(name="convertedToOptimizedPdfStatus_index", columns={"convertedToOptimizedPdfStatus"}), @ORM\Index(name="convertedToXodStatus_index", columns={"convertedToXodStatus"}), @ORM\Index(name="convertedToOcrStatus_index", columns={"convertedToOcrStatus"}), @ORM\Index(name="convertedToWebAVStatus_index", columns={"convertedToWebAVStatus"}), @ORM\Index(name="orthanc_store_response_id_index", columns={"orthanc_store_response_id"}), @ORM\Index(name="orthanc_parent_series_id_index", columns={"orthanc_parent_series_id"})})
  18. *
  19. * @\ApiPlatform\Core\Annotation\ApiResource(
  20. * collectionOperations={},
  21. * itemOperations={
  22. * "project_document_get_data"={
  23. * "method"="GET",
  24. * "path"="/matter/{id}/documents/{documentId}/get-data",
  25. * "controller"="MedBrief\MSR\Controller\ProjectDocumentController::getDataAction",
  26. * "read"=false,
  27. * "deserialize"=false,
  28. * "output"="MedBrief\MSR\Dto\ProjectDocument\ProjectDocumentDetailsDto",
  29. * "normalization_context"={"groups"={"project_document:get_data"}},
  30. * "defaults"={"_api_receive"=false},
  31. * "openapi_context"={
  32. * "summary"="Get project document details",
  33. * "description"="Returns aggregate project-document details (core Document fields plus DocumentMetadata when available).",
  34. * "parameters"={
  35. * {
  36. * "name"="id",
  37. * "in"="path",
  38. * "required"=true,
  39. * "schema"={"type"="integer"},
  40. * "description"="Project ID"
  41. * },
  42. * {
  43. * "name"="documentId",
  44. * "in"="path",
  45. * "required"=true,
  46. * "schema"={"type"="integer"},
  47. * "description"="Document ID"
  48. * }
  49. * }
  50. * }
  51. * }
  52. * }
  53. * )
  54. *
  55. * @ORM\Entity(repositoryClass=DocumentRepository::class)
  56. *
  57. * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false)
  58. *
  59. * @Audit\Auditable
  60. *
  61. * @Audit\Security(view={"ROLE_ALLOWED_TO_AUDIT"})
  62. */
  63. class Document implements JsonSerializable, RemovableRecordInterface, VirusScannableInterface, FileHandledInterface
  64. {
  65. public const ORTHANC_STORAGE_STATUS_PENDING = 1;
  66. public const ORTHANC_STORAGE_STATUS_STORED = 2;
  67. public const ORTHANC_STORAGE_STATUS_FAILED = 3;
  68. public const ORTHANC_STORAGE_STATUS_DELETED = 4;
  69. public const CONVERSION_TO_SWF_PENDING = 0;
  70. public const CONVERSION_TO_SWF_COMPLETE = 1;
  71. public const CONVERSION_TO_SWF_FAILED = 2;
  72. public const CONVERSION_TO_SWF_CURRENT = 3;
  73. public const CONVERSION_TO_SWF_SKIPPED = 4;
  74. // These statuses control the Archive state of the Document,
  75. // which applies to SWF conversion.
  76. public const CONVERSION_TO_SWF_ARCHIVE_PENDING = 5;
  77. public const CONVERSION_TO_SWF_ARCHIVE_CURRENT = 6;
  78. public const CONVERSION_TO_SWF_ARCHIVED = 7;
  79. public const CONVERSION_TO_SWF_ARCHIVE_FAILED = 8;
  80. public const FILE_TYPE_PDF = 'pdf';
  81. public const FILE_TYPE_AUDIO = 'audio';
  82. public const FILE_TYPE_VIDEO = 'video';
  83. public const FILE_TYPE_DICOM = 'dicom';
  84. public const FILE_TYPE_MSWORD = 'msword';
  85. public const FILE_TYPE_MSEXCEL = 'msexcel';
  86. public const FILE_TYPE_MSPOWERPOINT = 'mspowerpoint';
  87. public const FILE_TYPE_FILE = 'generic';
  88. public const FILE_TYPE_IMAGE = 'image';
  89. public const FILE_TYPE_TEXT_HTML = 'text/html';
  90. public const FILE_TYPE_EML_MSG = 'email';
  91. // Converted to OptimizedPDF statuses.
  92. public const CONVERSION_TO_OPTIMIZED_PDF_PENDING = 1;
  93. public const CONVERSION_TO_OPTIMIZED_PDF_COMPLETE = 2;
  94. public const CONVERSION_TO_OPTIMIZED_PDF_FAILED = 3;
  95. public const CONVERSION_TO_OPTIMIZED_PDF_CURRENT = 4;
  96. public const CONVERSION_TO_OPTIMIZED_PDF_SKIPPED = 5;
  97. // Converted to XOD statuses.
  98. public const CONVERSION_TO_XOD_PENDING = 1;
  99. public const CONVERSION_TO_XOD_COMPLETE = 2;
  100. public const CONVERSION_TO_XOD_FAILED = 3;
  101. public const CONVERSION_TO_XOD_CURRENT = 4;
  102. public const CONVERSION_TO_XOD_SKIPPED = 5;
  103. public const CONVERSION_TO_XOD_ENCRYPTED = 6;
  104. // Converted to WEBAV statuses.
  105. public const CONVERSION_TO_WEBAV_PENDING = 1;
  106. public const CONVERSION_TO_WEBAV_COMPLETE = 2;
  107. public const CONVERSION_TO_WEBAV_FAILED = 3;
  108. public const CONVERSION_TO_WEBAV_CURRENT = 4;
  109. public const CONVERSION_TO_WEBAV_SKIPPED = 5;
  110. // Converted to OCR statuses.
  111. public const CONVERSION_TO_OCR_PENDING = 1;
  112. public const CONVERSION_TO_OCR_COMPLETE = 2;
  113. public const CONVERSION_TO_OCR_FAILED = 3;
  114. public const CONVERSION_TO_OCR_FAILED_AUTH = 31;
  115. public const CONVERSION_TO_OCR_FAILED_HTTP_TRANSPORT = 32;
  116. public const CONVERSION_TO_OCR_FAILED_NO_PDF_PATH = 33;
  117. public const CONVERSION_TO_OCR_CURRENT = 4;
  118. public const CONVERSION_TO_OCR_SKIPPED = 5;
  119. public const CONVERSION_TO_OCR_REQUEUED = 6;
  120. public const FILE_FIELD_LIST = [
  121. 'nativeFile',
  122. 'optimizedPdfFile',
  123. 'xodBlobFile',
  124. 'ocrFile',
  125. 'ocrXodBlobFile',
  126. 'webAVFile',
  127. ];
  128. public static $fileIcons = [
  129. 'afl' => ['iconClass' => 'mb-icon--video', 'type' => self::FILE_TYPE_VIDEO],
  130. 'aif' => ['iconClass' => 'mb-icon--audio', 'type' => self::FILE_TYPE_AUDIO],
  131. 'aifc' => ['iconClass' => 'mb-icon--audio', 'type' => self::FILE_TYPE_AUDIO],
  132. 'aiff' => ['iconClass' => 'mb-icon--audio', 'type' => self::FILE_TYPE_AUDIO],
  133. 'asf' => ['iconClass' => 'mb-icon--video', 'type' => self::FILE_TYPE_VIDEO],
  134. 'asx' => ['iconClass' => 'mb-icon--video', 'type' => self::FILE_TYPE_VIDEO],
  135. 'au' => ['iconClass' => 'mb-icon--audio', 'type' => self::FILE_TYPE_AUDIO],
  136. 'avi' => ['iconClass' => 'mb-icon--video', 'type' => self::FILE_TYPE_VIDEO],
  137. 'avs' => ['iconClass' => 'mb-icon--video', 'type' => self::FILE_TYPE_VIDEO],
  138. 'dif' => ['iconClass' => 'mb-icon--video', 'type' => self::FILE_TYPE_VIDEO],
  139. 'dl' => ['iconClass' => 'mb-icon--video', 'type' => self::FILE_TYPE_VIDEO],
  140. 'dv' => ['iconClass' => 'mb-icon--video', 'type' => self::FILE_TYPE_VIDEO],
  141. 'dvr-ms' => ['iconClass' => 'mb-icon--video', 'type' => self::FILE_TYPE_VIDEO],
  142. 'fli' => ['iconClass' => 'mb-icon--video', 'type' => self::FILE_TYPE_VIDEO],
  143. 'fmf' => ['iconClass' => 'mb-icon--video', 'type' => self::FILE_TYPE_VIDEO],
  144. 'funk' => ['iconClass' => 'mb-icon--audio', 'type' => self::FILE_TYPE_AUDIO],
  145. 'gl' => ['iconClass' => 'mb-icon--video', 'type' => self::FILE_TYPE_VIDEO],
  146. 'gsd' => ['iconClass' => 'mb-icon--audio', 'type' => self::FILE_TYPE_AUDIO],
  147. 'gsm' => ['iconClass' => 'mb-icon--audio', 'type' => self::FILE_TYPE_AUDIO],
  148. 'isu' => ['iconClass' => 'mb-icon--video', 'type' => self::FILE_TYPE_VIDEO],
  149. 'it' => ['iconClass' => 'mb-icon--audio', 'type' => self::FILE_TYPE_AUDIO],
  150. 'jam' => ['iconClass' => 'mb-icon--audio', 'type' => self::FILE_TYPE_AUDIO],
  151. 'kar' => ['iconClass' => 'mb-icon--audio', 'type' => self::FILE_TYPE_AUDIO],
  152. 'la' => ['iconClass' => 'mb-icon--audio', 'type' => self::FILE_TYPE_AUDIO],
  153. 'lam' => ['iconClass' => 'mb-icon--audio', 'type' => self::FILE_TYPE_AUDIO],
  154. 'lma' => ['iconClass' => 'mb-icon--audio', 'type' => self::FILE_TYPE_AUDIO],
  155. 'm1v' => ['iconClass' => 'mb-icon--video', 'type' => self::FILE_TYPE_VIDEO],
  156. 'm2a' => ['iconClass' => 'mb-icon--audio', 'type' => self::FILE_TYPE_AUDIO],
  157. 'm2v' => ['iconClass' => 'mb-icon--video', 'type' => self::FILE_TYPE_VIDEO],
  158. 'm3u' => ['iconClass' => 'mb-icon--audio', 'type' => self::FILE_TYPE_AUDIO],
  159. 'mid' => ['iconClass' => 'mb-icon--audio', 'type' => self::FILE_TYPE_AUDIO],
  160. 'midi' => ['iconClass' => 'mb-icon--audio', 'type' => self::FILE_TYPE_AUDIO],
  161. 'mjf' => ['iconClass' => 'mb-icon--audio', 'type' => self::FILE_TYPE_AUDIO],
  162. 'mjpg' => ['iconClass' => 'mb-icon--video', 'type' => self::FILE_TYPE_VIDEO],
  163. 'mkv' => ['iconClass' => 'mb-icon--video', 'type' => self::FILE_TYPE_VIDEO],
  164. 'mod' => ['iconClass' => 'mb-icon--audio', 'type' => self::FILE_TYPE_AUDIO],
  165. 'moov' => ['iconClass' => 'mb-icon--video', 'type' => self::FILE_TYPE_VIDEO],
  166. 'mov' => ['iconClass' => 'mb-icon--video', 'type' => self::FILE_TYPE_VIDEO],
  167. 'movie' => ['iconClass' => 'mb-icon--video', 'type' => self::FILE_TYPE_VIDEO],
  168. 'mp2' => ['iconClass' => 'mb-icon--audio', 'type' => self::FILE_TYPE_AUDIO],
  169. 'mp3' => ['iconClass' => 'mb-icon--audio', 'type' => self::FILE_TYPE_AUDIO],
  170. 'mp4' => ['iconClass' => 'mb-icon--video', 'type' => self::FILE_TYPE_VIDEO],
  171. 'mpa' => ['iconClass' => 'mb-icon--audio', 'type' => self::FILE_TYPE_AUDIO],
  172. 'mpe' => ['iconClass' => 'mb-icon--video', 'type' => self::FILE_TYPE_VIDEO],
  173. 'mpeg' => ['iconClass' => 'mb-icon--video', 'type' => self::FILE_TYPE_VIDEO],
  174. 'mpg' => ['iconClass' => 'mb-icon--audio', 'type' => self::FILE_TYPE_AUDIO],
  175. 'mpga' => ['iconClass' => 'mb-icon--audio', 'type' => self::FILE_TYPE_AUDIO],
  176. 'mv' => ['iconClass' => 'mb-icon--video', 'type' => self::FILE_TYPE_VIDEO],
  177. 'my' => ['iconClass' => 'mb-icon--audio', 'type' => self::FILE_TYPE_AUDIO],
  178. 'pfunk' => ['iconClass' => 'mb-icon--audio', 'type' => self::FILE_TYPE_AUDIO],
  179. 'qcp' => ['iconClass' => 'mb-icon--audio', 'type' => self::FILE_TYPE_AUDIO],
  180. 'qt' => ['iconClass' => 'mb-icon--video', 'type' => self::FILE_TYPE_VIDEO],
  181. 'qtc' => ['iconClass' => 'mb-icon--video', 'type' => self::FILE_TYPE_VIDEO],
  182. 'ra' => ['iconClass' => 'mb-icon--audio', 'type' => self::FILE_TYPE_AUDIO],
  183. 'ram' => ['iconClass' => 'mb-icon--audio', 'type' => self::FILE_TYPE_AUDIO],
  184. 'rm' => ['iconClass' => 'mb-icon--audio', 'type' => self::FILE_TYPE_AUDIO],
  185. 'rmi' => ['iconClass' => 'mb-icon--audio', 'type' => self::FILE_TYPE_AUDIO],
  186. 'rmm' => ['iconClass' => 'mb-icon--audio', 'type' => self::FILE_TYPE_AUDIO],
  187. 'rmp' => ['iconClass' => 'mb-icon--audio', 'type' => self::FILE_TYPE_AUDIO],
  188. 'rpm' => ['iconClass' => 'mb-icon--audio', 'type' => self::FILE_TYPE_AUDIO],
  189. 'rv' => ['iconClass' => 'mb-icon--video', 'type' => self::FILE_TYPE_VIDEO],
  190. 's3m' => ['iconClass' => 'mb-icon--audio', 'type' => self::FILE_TYPE_AUDIO],
  191. 'scm' => ['iconClass' => 'mb-icon--video', 'type' => self::FILE_TYPE_VIDEO],
  192. 'sid' => ['iconClass' => 'mb-icon--audio', 'type' => self::FILE_TYPE_AUDIO],
  193. 'snd' => ['iconClass' => 'mb-icon--audio', 'type' => self::FILE_TYPE_AUDIO],
  194. 'tsi' => ['iconClass' => 'mb-icon--audio', 'type' => self::FILE_TYPE_AUDIO],
  195. 'tsp' => ['iconClass' => 'mb-icon--audio', 'type' => self::FILE_TYPE_AUDIO],
  196. 'vdo' => ['iconClass' => 'mb-icon--video', 'type' => self::FILE_TYPE_VIDEO],
  197. 'viv' => ['iconClass' => 'mb-icon--video', 'type' => self::FILE_TYPE_VIDEO],
  198. 'vivo' => ['iconClass' => 'mb-icon--video', 'type' => self::FILE_TYPE_VIDEO],
  199. 'voc' => ['iconClass' => 'mb-icon--audio', 'type' => self::FILE_TYPE_AUDIO],
  200. 'vos' => ['iconClass' => 'mb-icon--video', 'type' => self::FILE_TYPE_VIDEO],
  201. 'vox' => ['iconClass' => 'mb-icon--audio', 'type' => self::FILE_TYPE_AUDIO],
  202. 'vqe' => ['iconClass' => 'mb-icon--audio', 'type' => self::FILE_TYPE_AUDIO],
  203. 'vqf' => ['iconClass' => 'mb-icon--audio', 'type' => self::FILE_TYPE_AUDIO],
  204. 'vql' => ['iconClass' => 'mb-icon--audio', 'type' => self::FILE_TYPE_AUDIO],
  205. 'wav' => ['iconClass' => 'mb-icon--audio', 'type' => self::FILE_TYPE_AUDIO],
  206. 'xdr' => ['iconClass' => 'mb-icon--video', 'type' => self::FILE_TYPE_VIDEO],
  207. 'xm' => ['iconClass' => 'mb-icon--audio', 'type' => self::FILE_TYPE_AUDIO],
  208. 'xsr' => ['iconClass' => 'mb-icon--video', 'type' => self::FILE_TYPE_VIDEO],
  209. 'wma' => ['iconClass' => 'mb-icon--audio', 'type' => self::FILE_TYPE_AUDIO],
  210. // PDF file
  211. 'pdf' => ['iconClass' => 'mb-icon--pdf', 'type' => self::FILE_TYPE_PDF],
  212. // generic file
  213. 'xps' => ['iconClass' => 'mb-icon--file', 'type' => self::FILE_TYPE_FILE],
  214. 'rtf' => ['iconClass' => 'mb-icon--file', 'type' => self::FILE_TYPE_FILE],
  215. 'csv' => ['iconClass' => 'mb-icon--file', 'type' => self::FILE_TYPE_FILE],
  216. 'vsd' => ['iconClass' => 'mb-icon--file', 'type' => self::FILE_TYPE_FILE],
  217. 'pub' => ['iconClass' => 'mb-icon--file', 'type' => self::FILE_TYPE_FILE],
  218. // Word files
  219. 'doc' => ['iconClass' => 'mb-icon--ms-word', 'type' => self::FILE_TYPE_MSWORD],
  220. 'dot' => ['iconClass' => 'mb-icon--ms-word', 'type' => self::FILE_TYPE_MSWORD],
  221. 'docx' => ['iconClass' => 'mb-icon--ms-word', 'type' => self::FILE_TYPE_MSWORD],
  222. 'dotx' => ['iconClass' => 'mb-icon--ms-word', 'type' => self::FILE_TYPE_MSWORD],
  223. // Excel files
  224. 'xls' => ['iconClass' => 'mb-icon--ms-excel', 'type' => self::FILE_TYPE_MSEXCEL],
  225. 'xlt' => ['iconClass' => 'mb-icon--ms-excel', 'type' => self::FILE_TYPE_MSEXCEL],
  226. 'xla' => ['iconClass' => 'mb-icon--ms-excel', 'type' => self::FILE_TYPE_MSEXCEL],
  227. 'xlsx' => ['iconClass' => 'mb-icon--ms-excel', 'type' => self::FILE_TYPE_MSEXCEL],
  228. 'ods' => ['iconClass' => 'mb-icon--ms-excel', 'type' => self::FILE_TYPE_MSEXCEL],
  229. // PowerPoint files
  230. 'ppt' => ['iconClass' => 'mb-icon--ms-powerpoint', 'type' => self::FILE_TYPE_MSPOWERPOINT],
  231. 'pot' => ['iconClass' => 'mb-icon--ms-powerpoint', 'type' => self::FILE_TYPE_MSPOWERPOINT],
  232. 'pps' => ['iconClass' => 'mb-icon--ms-powerpoint', 'type' => self::FILE_TYPE_MSPOWERPOINT],
  233. 'ppa' => ['iconClass' => 'mb-icon--ms-powerpoint', 'type' => self::FILE_TYPE_MSPOWERPOINT],
  234. 'pptx' => ['iconClass' => 'mb-icon--ms-powerpoint', 'type' => self::FILE_TYPE_MSPOWERPOINT],
  235. // Image files
  236. 'jpg' => ['iconClass' => 'mb-icon--image', 'type' => self::FILE_TYPE_IMAGE],
  237. 'jpeg' => ['iconClass' => 'mb-icon--image', 'type' => self::FILE_TYPE_IMAGE],
  238. 'tiff' => ['iconClass' => 'mb-icon--image', 'type' => self::FILE_TYPE_IMAGE],
  239. 'tif' => ['iconClass' => 'mb-icon--image', 'type' => self::FILE_TYPE_IMAGE],
  240. 'png' => ['iconClass' => 'mb-icon--image', 'type' => self::FILE_TYPE_IMAGE],
  241. // Html/Text files
  242. 'html' => ['iconClass' => 'mb-icon--html', 'type' => self::FILE_TYPE_TEXT_HTML],
  243. 'htm' => ['iconClass' => 'mb-icon--html', 'type' => self::FILE_TYPE_TEXT_HTML],
  244. 'txt' => ['iconClass' => 'mb-icon--text', 'type' => self::FILE_TYPE_TEXT_HTML],
  245. // eml/msg files
  246. 'eml' => ['iconClass' => 'mb-icon--mail', 'type' => self::FILE_TYPE_EML_MSG],
  247. 'msg' => ['iconClass' => 'mb-icon--mail', 'type' => self::FILE_TYPE_EML_MSG],
  248. ];
  249. /**
  250. * @var int
  251. *
  252. * @ORM\Column(name="id", type="integer")
  253. *
  254. * @ORM\Id
  255. *
  256. * @ORM\GeneratedValue(strategy="IDENTITY")
  257. */
  258. private $id;
  259. /**
  260. * @var \DateTime|null
  261. *
  262. * @ORM\Column(name="deletedAt", type="datetime", nullable=true)
  263. */
  264. private $deletedAt;
  265. /**
  266. * @var string
  267. *
  268. * @ORM\Column(name="filename", type="string")
  269. */
  270. private $filename;
  271. /**
  272. * @var string
  273. *
  274. * @ORM\Column(name="original_filename", type="string")
  275. */
  276. private $original_filename;
  277. /**
  278. * @var string
  279. *
  280. * @ORM\Column(name="mime_type", type="string")
  281. */
  282. private $mime_type;
  283. /**
  284. * @var string
  285. *
  286. * @ORM\Column(name="filesize", type="string")
  287. */
  288. private $filesize;
  289. /**
  290. * @var int|null
  291. *
  292. * @ORM\Column(name="orthanc_storage_status", type="integer", nullable=true)
  293. */
  294. private $orthanc_storage_status;
  295. /**
  296. * @var string|null
  297. *
  298. * @ORM\Column(name="orthanc_store_response_id", type="string", length=255, nullable=true)
  299. */
  300. private $orthanc_store_response_id;
  301. /**
  302. * @var string|null
  303. *
  304. * @ORM\Column(name="orthanc_store_response_path", type="string", length=255, nullable=true)
  305. */
  306. private $orthanc_store_response_path;
  307. /**
  308. * @var string|null
  309. *
  310. * @ORM\Column(name="orthanc_store_response_status", type="string", length=255, nullable=true)
  311. */
  312. private $orthanc_store_response_status;
  313. /**
  314. * @var string|null
  315. *
  316. * @ORM\Column(name="orthanc_parent_series_id", type="string", length=255, nullable=true)
  317. */
  318. private $orthanc_parent_series_id;
  319. /**
  320. * Used as the primary determinant in ordering a sequence of dicom files
  321. *
  322. * @var int|null
  323. *
  324. * @ORM\Column(name="orthanc_instance_number", type="integer", nullable=true)
  325. */
  326. private $orthanc_instance_number;
  327. /**
  328. * @var string
  329. *
  330. * @ORM\Column(name="status", type="string")
  331. */
  332. private $status;
  333. /**
  334. * @var \DateTime
  335. *
  336. * @ORM\Column(name="created", type="datetime")
  337. *
  338. * @Gedmo\Timestampable(on="create")
  339. */
  340. private $created;
  341. /**
  342. * @var \DateTime
  343. *
  344. * @ORM\Column(name="updated", type="datetime")
  345. *
  346. * @Gedmo\Timestampable(on="update")
  347. */
  348. private $updated;
  349. /**
  350. * @var int|null
  351. *
  352. * @ORM\Column(name="convertedToSwfStatus", type="integer", nullable=true)
  353. */
  354. private $convertedToSwfStatus;
  355. /**
  356. * @var string|null
  357. *
  358. * @ORM\Column(name="nativeFilename", type="string", length=255, nullable=true)
  359. */
  360. private $nativeFilename;
  361. /**
  362. * @var string|null
  363. *
  364. * @ORM\Column(name="swfFilename", type="string", length=255, nullable=true)
  365. */
  366. private $swfFilename;
  367. /**
  368. * @var int|null
  369. *
  370. * @ORM\Column(name="convertedToOptimizedPdfStatus", type="integer", nullable=true)
  371. */
  372. private $convertedToOptimizedPdfStatus;
  373. /**
  374. * @var string|null
  375. *
  376. * @ORM\Column(name="optimizedPdfFilename", type="string", length=255, nullable=true)
  377. */
  378. private $optimizedPdfFilename;
  379. /**
  380. * @var int|null
  381. *
  382. * @ORM\Column(name="convertedToXodStatus", type="integer", nullable=true)
  383. */
  384. private $convertedToXodStatus;
  385. /**
  386. * @var string|null
  387. *
  388. * @ORM\Column(name="xodFilename", type="string", length=255, nullable=true)
  389. */
  390. private $xodFilename;
  391. /**
  392. * @var int|null
  393. *
  394. * @ORM\Column(name="convertedToWebAVStatus", type="integer", nullable=true)
  395. */
  396. private $convertedToWebAVStatus;
  397. /**
  398. * @var string|null
  399. *
  400. * @ORM\Column(name="webAVFilename", type="string", length=255, nullable=true)
  401. */
  402. private $webAVFilename;
  403. /**
  404. * @var int|null
  405. *
  406. * @ORM\Column(name="convertedToOcrStatus", type="integer", nullable=true)
  407. */
  408. private $convertedToOcrStatus;
  409. /**
  410. * @var string|null
  411. *
  412. * @ORM\Column(name="ocrFilename", type="string", length=255, nullable=true)
  413. */
  414. private $ocrFilename;
  415. /**
  416. * @var string|null
  417. *
  418. * @ORM\Column(name="ocrXodFilename", type="string", length=255, nullable=true)
  419. */
  420. private $ocrXodFilename;
  421. /**
  422. * @var string
  423. *
  424. * @ORM\Column(name="md5hash", type="string", length=40, nullable=false)
  425. */
  426. private $md5hash;
  427. /**
  428. * @var string|null
  429. *
  430. * @ORM\Column(name="documentTypeFamily", type="string", length=255, nullable=true)
  431. */
  432. private $documentTypeFamily;
  433. /**
  434. * @var Upload
  435. *
  436. * @ORM\OneToOne(targetEntity="MedBrief\MSR\Entity\Upload")
  437. *
  438. * @ORM\JoinColumns({
  439. *
  440. * @ORM\JoinColumn(name="upload_id", referencedColumnName="id", unique=true)
  441. * })
  442. */
  443. private $upload;
  444. /**
  445. * @var DoctrineCollection
  446. *
  447. * @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\OrthancTransaction", mappedBy="document", cascade={"all"})
  448. */
  449. private $orthancTransactions;
  450. /**
  451. * @var Project
  452. *
  453. * @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\Project", inversedBy="documents")
  454. *
  455. * @ORM\JoinColumns({
  456. *
  457. * @ORM\JoinColumn(name="project_id", referencedColumnName="id")
  458. * })
  459. */
  460. private $project;
  461. /**
  462. * @var DocumentType
  463. *
  464. * @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\DocumentType")
  465. *
  466. * @ORM\JoinColumns({
  467. *
  468. * @ORM\JoinColumn(name="documentType_id", referencedColumnName="id")
  469. * })
  470. */
  471. private $documentType;
  472. /**
  473. * @var User
  474. *
  475. * @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\User", inversedBy="documents")
  476. *
  477. * @ORM\JoinColumns({
  478. *
  479. * @ORM\JoinColumn(name="creator_id", referencedColumnName="id", nullable=false)
  480. * })
  481. */
  482. private $creator;
  483. /**
  484. * @var DoctrineCollection
  485. *
  486. * TODO: This is the inverse side of the ManyToMany with Collection::$documents (owning side,
  487. * inversedBy="collections"). Doctrine only persists the join table from the owning side, and
  488. * Collection::addDocument()/removeDocument() only update Collection::$documents — they never
  489. * call $document->addCollection()/removeCollection() to keep this inverse side in sync.
  490. * As a result, calling $collection->addDocument($document) will NOT make the new Collection
  491. * show up in $document->getCollections() until the Document is reloaded (e.g. via
  492. * $em->clear() or a fresh query). Callers currently work around this by manually calling both
  493. * $collection->addDocument($document) and $document->addCollection($collection).
  494. * Fix: update Collection::addDocument()/removeDocument() to also sync this inverse side.
  495. *
  496. * @ORM\ManyToMany(targetEntity="MedBrief\MSR\Entity\Collection", mappedBy="documents")
  497. */
  498. private $collections;
  499. /**
  500. * @var string
  501. */
  502. private $orthanc_response_raw_json;
  503. /**
  504. * @var string
  505. */
  506. private $orthanc_response_id;
  507. /**
  508. * @var string
  509. */
  510. private $orthanc_response_path;
  511. /**
  512. * @var string
  513. */
  514. private $orthanc_response_status;
  515. /**
  516. * @var int
  517. */
  518. private $orthanc_submission_status;
  519. /**
  520. * The below properties are unmapped and used by the VichUploader bundle
  521. * when utilising File injection.
  522. */
  523. /**
  524. * @var string
  525. */
  526. private $nativeFile;
  527. /**
  528. * @var string
  529. */
  530. private $optimizedPdfFile;
  531. /**
  532. * @var string
  533. */
  534. private $swfFile;
  535. /**
  536. * @var string
  537. */
  538. private $webAVFile;
  539. /**
  540. * @var string
  541. */
  542. private $xodFile;
  543. /**
  544. * @var string
  545. */
  546. private $xodBlobFile;
  547. /**
  548. * @var string
  549. */
  550. private $ocrXodFile;
  551. /**
  552. * @var string
  553. */
  554. private $ocrXodBlobFile;
  555. /**
  556. * @var string
  557. */
  558. private $ocrFile;
  559. /**
  560. * @ORM\OneToOne(targetEntity=VirusScanItem::class, mappedBy="document")
  561. */
  562. private ?VirusScanItem $virusScanItem = null;
  563. /**
  564. * @ORM\OneToOne(targetEntity="MedBrief\MSR\Entity\SortingSessionStack", mappedBy="document")
  565. */
  566. private $sortingSessionStack;
  567. /**
  568. * @var bool|null
  569. *
  570. * @ORM\Column(name="hasCERIndex", type="boolean", nullable=true)
  571. */
  572. private ?bool $hasCERIndex = null;
  573. /**
  574. * Constructor
  575. */
  576. public function __construct()
  577. {
  578. $this->orthancTransactions = new \Doctrine\Common\Collections\ArrayCollection();
  579. $this->collections = new \Doctrine\Common\Collections\ArrayCollection();
  580. }
  581. public function __clone()
  582. {
  583. if ($this->id) {
  584. $this->project = null;
  585. $this->orthancTransactions = new \Doctrine\Common\Collections\ArrayCollection();
  586. $this->collections = new \Doctrine\Common\Collections\ArrayCollection();
  587. }
  588. }
  589. public function __toString()
  590. {
  591. return (string) $this->getFilename();
  592. }
  593. /**
  594. * Get id
  595. *
  596. * @return int
  597. */
  598. public function getId(): ?int
  599. {
  600. return $this->id;
  601. }
  602. /**
  603. * Set filename
  604. *
  605. * @param string $filename
  606. *
  607. * @return Document
  608. */
  609. public function setFilename($filename)
  610. {
  611. $this->filename = $filename;
  612. return $this;
  613. }
  614. /**
  615. * Get filename
  616. *
  617. * @return string
  618. */
  619. public function getFilename()
  620. {
  621. return $this->filename;
  622. }
  623. /**
  624. * Get filename with PDF extension.
  625. *
  626. * @return string
  627. */
  628. public function getFilenameAsPdf()
  629. {
  630. $filename = pathinfo($this->getFilename(), PATHINFO_FILENAME);
  631. if (isset($filename)) {
  632. return $filename . '.pdf';
  633. }
  634. return $this->filename . '.pdf';
  635. }
  636. /**
  637. * Set mime_type
  638. *
  639. * @param string $mimeType
  640. *
  641. * @return Document
  642. */
  643. public function setMimeType($mimeType)
  644. {
  645. $this->mime_type = $mimeType;
  646. return $this;
  647. }
  648. /**
  649. * Get mime_type
  650. *
  651. * @return string
  652. */
  653. public function getMimeType()
  654. {
  655. return $this->mime_type;
  656. }
  657. /**
  658. * Set filesize
  659. *
  660. * @param string $filesize
  661. *
  662. * @return Document
  663. */
  664. public function setFilesize($filesize)
  665. {
  666. $this->filesize = $filesize;
  667. return $this;
  668. }
  669. /**
  670. * Get filesize
  671. *
  672. * @return string
  673. */
  674. public function getFilesize()
  675. {
  676. return $this->filesize;
  677. }
  678. /**
  679. * Set status
  680. *
  681. * @param string $status
  682. *
  683. * @return Document
  684. */
  685. public function setStatus($status)
  686. {
  687. $this->status = $status;
  688. return $this;
  689. }
  690. /**
  691. * Get status
  692. *
  693. * @return string
  694. */
  695. public function getStatus()
  696. {
  697. return $this->status;
  698. }
  699. /**
  700. * Set created
  701. *
  702. * @param \DateTime $created
  703. *
  704. * @return Document
  705. */
  706. public function setCreated($created)
  707. {
  708. $this->created = $created;
  709. return $this;
  710. }
  711. /**
  712. * Get created
  713. *
  714. * @return \DateTime
  715. */
  716. public function getCreated()
  717. {
  718. return $this->created;
  719. }
  720. /**
  721. * Set updated
  722. *
  723. * @param \DateTime $updated
  724. *
  725. * @return Document
  726. */
  727. public function setUpdated($updated)
  728. {
  729. $this->updated = $updated;
  730. return $this;
  731. }
  732. /**
  733. * Get updated
  734. *
  735. * @return \DateTime
  736. */
  737. public function getUpdated()
  738. {
  739. return $this->updated;
  740. }
  741. /**
  742. * Set upload
  743. *
  744. * @param Upload $upload
  745. *
  746. * @return Document
  747. */
  748. public function setUpload(?Upload $upload = null)
  749. {
  750. $this->upload = $upload;
  751. return $this;
  752. }
  753. /**
  754. * Get upload
  755. *
  756. * @return Upload
  757. */
  758. public function getUpload()
  759. {
  760. return $this->upload;
  761. }
  762. /**
  763. * Set project
  764. *
  765. * @param Project $project
  766. *
  767. * @return Document
  768. */
  769. public function setProject(?Project $project = null)
  770. {
  771. $this->project = $project;
  772. return $this;
  773. }
  774. /**
  775. * Get project
  776. *
  777. * @return Project
  778. */
  779. public function getProject()
  780. {
  781. return $this->project;
  782. }
  783. /**
  784. * Set documentType
  785. *
  786. * @param DocumentType $documentType
  787. *
  788. * @return Document
  789. */
  790. public function setDocumentType(?DocumentType $documentType = null)
  791. {
  792. $this->documentType = $documentType;
  793. return $this;
  794. }
  795. /**
  796. * Get documentType
  797. *
  798. * @return DocumentType
  799. */
  800. public function getDocumentType()
  801. {
  802. return $this->documentType;
  803. }
  804. /**
  805. * Add collections
  806. *
  807. * @param \MedBrief\MSR\Entity\Collection $collections
  808. *
  809. * @return Document
  810. */
  811. public function addCollection(Collection $collections)
  812. {
  813. $this->collections[] = $collections;
  814. return $this;
  815. }
  816. /**
  817. * Remove collections
  818. *
  819. * @param \MedBrief\MSR\Entity\Collection $collections
  820. */
  821. public function removeCollection(Collection $collections)
  822. {
  823. $this->collections->removeElement($collections);
  824. }
  825. /**
  826. * Get collections
  827. *
  828. * Note: not a real union - DoctrineCollection is the actual runtime return type; Collection[]
  829. * is a conventional IDE/static-analysis hint indicating the element type when iterated.
  830. *
  831. * @return DoctrineCollection|Collection[]
  832. */
  833. public function getCollections()
  834. {
  835. return $this->collections;
  836. }
  837. /**
  838. * Set creator
  839. *
  840. * @param User $creator
  841. *
  842. * @return Document
  843. */
  844. public function setCreator(User $creator)
  845. {
  846. $this->creator = $creator;
  847. return $this;
  848. }
  849. /**
  850. * Get creator
  851. *
  852. * @return User
  853. */
  854. public function getCreator()
  855. {
  856. return $this->creator;
  857. }
  858. /**
  859. * Set nativeFilename
  860. *
  861. * @param string $nativeFilename
  862. *
  863. * @return Document
  864. */
  865. public function setNativeFilename($nativeFilename)
  866. {
  867. $this->nativeFilename = $nativeFilename;
  868. return $this;
  869. }
  870. /**
  871. * Get nativeFilename
  872. *
  873. * @return string
  874. */
  875. public function getNativeFilename()
  876. {
  877. return $this->nativeFilename;
  878. }
  879. /**
  880. * Set nativeFile
  881. *
  882. * @param string $nativeFile
  883. *
  884. * @return Document
  885. */
  886. public function setNativeFile($nativeFile)
  887. {
  888. $this->nativeFile = $nativeFile;
  889. return $this;
  890. }
  891. /**
  892. * Get nativeFile
  893. *
  894. * @return string
  895. */
  896. public function getNativeFile()
  897. {
  898. return $this->nativeFile;
  899. }
  900. /**
  901. * Returns an array of this documents data
  902. *
  903. * @return array
  904. *
  905. *@todo add more data Of maybe even just use the symfony serializer component
  906. *
  907. */
  908. public function jsonSerialize(): mixed
  909. {
  910. return [
  911. 'created' => $this->getCreated()->format('j F Y, H:ia'),
  912. 'filename' => $this->getFilename(),
  913. 'filesize' => number_format($this->getFilesize(), 0),
  914. ];
  915. }
  916. /**
  917. * Given the orthancTransaction (which is assumed to be of type STORE)
  918. * We update the appropriate values on this Document to indicate the various
  919. * orthanc data returned by the storage transaction
  920. *
  921. * @param OrthancTransaction $orthancTransaction
  922. */
  923. public function processOrthancStoreTransaction(OrthancTransaction $orthancTransaction)
  924. {
  925. // first - set the submissions status to pending at the outset
  926. $this->setOrthancStorageStatus(self::ORTHANC_STORAGE_STATUS_PENDING);
  927. // if the given transaction wasn't a success, the storage status of this
  928. // document is automatically also a fail
  929. if ($orthancTransaction->getTransactionStatus() != OrthancTransaction::TRANSACTION_STATUS_SUCCESS) {
  930. $this->setOrthancStorageStatus(self::ORTHANC_STORAGE_STATUS_FAILED);
  931. return false;
  932. }
  933. // if we get here, then everything is in order!
  934. $jsonObject = json_decode($orthancTransaction->getTransactionResponse());
  935. // set the individual values on the document
  936. $orthancStoreResponseId = $jsonObject->ID;
  937. $orthancStoreResponsePath = $jsonObject->Path;
  938. $orthancStoreResponseStatus = $jsonObject->Status;
  939. $this->setOrthancStoreResponseId($orthancStoreResponseId);
  940. $this->setOrthancStoreResponsePath($orthancStoreResponsePath);
  941. $this->setOrthancStoreResponseStatus($orthancStoreResponseStatus);
  942. // set the status as successful
  943. $this->setOrthancStorageStatus(self::ORTHANC_STORAGE_STATUS_STORED);
  944. }
  945. /**
  946. * Given the orthancTransaction (which is assumed to be of type INSTANCE_DETAILS) we
  947. * update the parent series id of this document
  948. *
  949. * @param OrthancTransaction $orthancTransaction
  950. *
  951. * @return void
  952. */
  953. public function processOrthancInstanceDetailsTransaction(OrthancTransaction $orthancTransaction): void
  954. {
  955. if ($orthancTransaction->getTransactionStatus() == OrthancTransaction::TRANSACTION_STATUS_SUCCESS) {
  956. $jsonObject = json_decode($orthancTransaction->getTransactionResponse());
  957. $this->setOrthancParentSeriesId($jsonObject->ParentSeries);
  958. // we anticipate that InstanceNumbers from Othanc will always be
  959. // integers (we hope) we cast them to Ints because our database
  960. // field is an integer. We have to use an integer field for
  961. // ordering purposes (varchar doesnt order correctly)
  962. if (isset($jsonObject->MainDicomTags) && isset($jsonObject->MainDicomTags->InstanceNumber)) {
  963. $this->setOrthancInstanceNumber(intval($jsonObject->MainDicomTags->InstanceNumber));
  964. }
  965. }
  966. }
  967. /**
  968. * Given the orthancTransaction (which is assumed to be of type DELETE) we
  969. * update the orthancStorage status of this document
  970. *
  971. * @param OrthancTransaction $orthancTransaction
  972. *
  973. * @return bool
  974. */
  975. public function processOrthancDeleteTransaction(OrthancTransaction $orthancTransaction): bool
  976. {
  977. // first - set the submissions status to pending at the outset
  978. $this->setOrthancStorageStatus(self::ORTHANC_STORAGE_STATUS_PENDING);
  979. // if the transaction status is not SUCCESS then set this status as FAILED
  980. if ($orthancTransaction->getTransactionStatus() != OrthancTransaction::TRANSACTION_STATUS_SUCCESS) {
  981. $this->setOrthancStorageStatus(self::ORTHANC_STORAGE_STATUS_FAILED);
  982. return false;
  983. }
  984. // set the status as successful
  985. $this->setOrthancStorageStatus(self::ORTHANC_STORAGE_STATUS_DELETED);
  986. return true;
  987. }
  988. /**
  989. * Add orthancTransaction. When a orthancTransaction is assigned to this
  990. * Document using this function, then the associated orthanc values on this
  991. * Document will be updated with th assumption that this transaction is the
  992. * latest one to have run on the document
  993. *
  994. * @param OrthancTransaction $orthancTransaction
  995. *
  996. * @return Document
  997. */
  998. public function addOrthancTransaction(OrthancTransaction $orthancTransaction)
  999. {
  1000. $this->orthancTransactions[] = $orthancTransaction;
  1001. // based on the type of the transaction, we run the appropriate function
  1002. // on this document
  1003. switch ($orthancTransaction->getType()) {
  1004. case OrthancTransaction::TYPE_STORE_INSTANCE:
  1005. $this->processOrthancStoreTransaction($orthancTransaction);
  1006. break;
  1007. case OrthancTransaction::TYPE_DELETE_INSTANCE:
  1008. $this->processOrthancDeleteTransaction($orthancTransaction);
  1009. break;
  1010. case OrthancTransaction::TYPE_INSTANCE_DETAILS:
  1011. $this->processOrthancInstanceDetailsTransaction($orthancTransaction);
  1012. break;
  1013. default:
  1014. throw new \Exception('Invalid OrthancTransaction Type: ' . $orthancTransaction->getType());
  1015. }
  1016. return $this;
  1017. }
  1018. /**
  1019. * Remove orthancTransaction
  1020. *
  1021. * @param OrthancTransaction $orthancTransaction
  1022. */
  1023. public function removeOrthancTransaction(OrthancTransaction $orthancTransaction)
  1024. {
  1025. $this->orthancTransactions->removeElement($orthancTransaction);
  1026. }
  1027. /**
  1028. * Get orthancTransactions
  1029. *
  1030. * @return DoctrineCollection
  1031. */
  1032. public function getOrthancTransactions()
  1033. {
  1034. return $this->orthancTransactions;
  1035. }
  1036. /**
  1037. * Set orthancStorageStatus
  1038. *
  1039. * @param int $orthancStorageStatus
  1040. *
  1041. * @return Document
  1042. */
  1043. public function setOrthancStorageStatus($orthancStorageStatus)
  1044. {
  1045. $this->orthanc_storage_status = $orthancStorageStatus;
  1046. return $this;
  1047. }
  1048. /**
  1049. * Get orthancStorageStatus
  1050. *
  1051. * @return int
  1052. */
  1053. public function getOrthancStorageStatus()
  1054. {
  1055. return $this->orthanc_storage_status;
  1056. }
  1057. /**
  1058. * Set orthancStoreResponseId
  1059. *
  1060. * @param string $orthancStoreResponseId
  1061. *
  1062. * @return Document
  1063. */
  1064. public function setOrthancStoreResponseId($orthancStoreResponseId)
  1065. {
  1066. $this->orthanc_store_response_id = $orthancStoreResponseId;
  1067. return $this;
  1068. }
  1069. /**
  1070. * Get orthancStoreResponseId
  1071. *
  1072. * @return string
  1073. */
  1074. public function getOrthancStoreResponseId()
  1075. {
  1076. return $this->orthanc_store_response_id;
  1077. }
  1078. /**
  1079. * Set orthancStoreResponsePath
  1080. *
  1081. * @param string $orthancStoreResponsePath
  1082. *
  1083. * @return Document
  1084. */
  1085. public function setOrthancStoreResponsePath($orthancStoreResponsePath)
  1086. {
  1087. $this->orthanc_store_response_path = $orthancStoreResponsePath;
  1088. return $this;
  1089. }
  1090. /**
  1091. * Get orthancStoreResponsePath
  1092. *
  1093. * @return string
  1094. */
  1095. public function getOrthancStoreResponsePath()
  1096. {
  1097. return $this->orthanc_store_response_path;
  1098. }
  1099. /**
  1100. * Set orthancStoreResponseStatus
  1101. *
  1102. * @param string $orthancStoreResponseStatus
  1103. *
  1104. * @return Document
  1105. */
  1106. public function setOrthancStoreResponseStatus($orthancStoreResponseStatus)
  1107. {
  1108. $this->orthanc_store_response_status = $orthancStoreResponseStatus;
  1109. return $this;
  1110. }
  1111. /**
  1112. * Get orthancStoreResponseStatus
  1113. *
  1114. * @return string
  1115. */
  1116. public function getOrthancStoreResponseStatus()
  1117. {
  1118. return $this->orthanc_store_response_status;
  1119. }
  1120. /**
  1121. * Set deletedAt
  1122. *
  1123. * @param \DateTime $deletedAt
  1124. *
  1125. * @return Document
  1126. */
  1127. public function setDeletedAt($deletedAt)
  1128. {
  1129. $this->deletedAt = $deletedAt;
  1130. return $this;
  1131. }
  1132. /**
  1133. * Get deletedAt
  1134. *
  1135. * @return \DateTime
  1136. */
  1137. public function getDeletedAt()
  1138. {
  1139. return $this->deletedAt;
  1140. }
  1141. /**
  1142. * Set orthancParentSeriesId
  1143. *
  1144. * @param string $orthancParentSeriesId
  1145. *
  1146. * @return Document
  1147. */
  1148. public function setOrthancParentSeriesId($orthancParentSeriesId)
  1149. {
  1150. $this->orthanc_parent_series_id = $orthancParentSeriesId;
  1151. return $this;
  1152. }
  1153. /**
  1154. * Get orthancParentSeriesId
  1155. *
  1156. * @return string
  1157. */
  1158. public function getOrthancParentSeriesId()
  1159. {
  1160. return $this->orthanc_parent_series_id;
  1161. }
  1162. /**
  1163. * Set md5hash
  1164. *
  1165. * @param string $md5hash
  1166. *
  1167. * @return Document
  1168. */
  1169. public function setMd5hash($md5hash)
  1170. {
  1171. $this->md5hash = $md5hash;
  1172. return $this;
  1173. }
  1174. /**
  1175. * Get md5hash
  1176. *
  1177. * @return string
  1178. */
  1179. public function getMd5hash()
  1180. {
  1181. return $this->md5hash;
  1182. }
  1183. /**
  1184. * Returns this Document as a jsTree formatted node
  1185. *
  1186. * @param string $replacementNodeText
  1187. * @param array $additionalLiAttributes
  1188. * @param bool $sorted
  1189. * @param bool $isCerIndex
  1190. *
  1191. * @return array
  1192. */
  1193. public function getJsTreeFormattedNode($replacementNodeText = null, $additionalLiAttributes = [], bool $sorted = false, bool $isCerIndex = false)
  1194. {
  1195. if ($this->isWebAV()) {
  1196. $dataConversionProgress = $this->getConvertedToWebAVStatusLabel(true);
  1197. } else {
  1198. $dataConversionProgress = $this->getConvertedToXodStatusLabel(true);
  1199. }
  1200. $node = [
  1201. 'text' => $replacementNodeText ?: $this->getFilename(),
  1202. 'type' => 'file',
  1203. 'icon' => ' mb-icon ' . $this->getIconClassName(),
  1204. 'valid_children' => null,
  1205. 'li_attr' => [
  1206. 'data-document-id' => $this->getId(),
  1207. 'data-native-filename' => $this->getNativeFilename(),
  1208. 'data-controller' => 'fullrow-foldertree',
  1209. 'data-creator-id' => $this->getCreator() ? $this->getCreator()->getId() : '',
  1210. 'data-conversion-progress' => $dataConversionProgress,
  1211. 'data-document-type-family' => $this->getDocumentTypeFamily(),
  1212. 'data-document-mime-type' => $this->getMimeType(),
  1213. 'data-sorted' => $sorted,
  1214. 'data-cer-index' => $isCerIndex,
  1215. 'data-has-cer-index' => $this->hasCERIndex(),
  1216. ],
  1217. ];
  1218. foreach ($additionalLiAttributes as $key => $value) {
  1219. $node['li_attr'][$key] = $value;
  1220. }
  1221. return $node;
  1222. }
  1223. /**
  1224. * Set originalFilename
  1225. *
  1226. * @param string $originalFilename
  1227. *
  1228. * @return Document
  1229. */
  1230. public function setOriginalFilename($originalFilename)
  1231. {
  1232. $this->original_filename = $originalFilename;
  1233. return $this;
  1234. }
  1235. /**
  1236. * Get originalFilename
  1237. *
  1238. * @return string
  1239. */
  1240. public function getOriginalFilename()
  1241. {
  1242. return $this->original_filename;
  1243. }
  1244. /**
  1245. * Set swfFilename
  1246. *
  1247. * @param string $swfFilename
  1248. *
  1249. * @return Document
  1250. */
  1251. public function setSwfFilename($swfFilename)
  1252. {
  1253. $this->swfFilename = $swfFilename;
  1254. return $this;
  1255. }
  1256. /**
  1257. * Get swfFilename
  1258. *
  1259. * @return string
  1260. */
  1261. public function getSwfFilename()
  1262. {
  1263. return $this->swfFilename;
  1264. }
  1265. /**
  1266. * Set swfFile
  1267. *
  1268. * @param string $swfFile
  1269. *
  1270. * @return Document
  1271. */
  1272. public function setSwfFile($swfFile)
  1273. {
  1274. $this->swfFile = $swfFile;
  1275. return $this;
  1276. }
  1277. /**
  1278. * Get swfFile
  1279. *
  1280. * @return string
  1281. */
  1282. public function getSwfFile()
  1283. {
  1284. return $this->swfFile;
  1285. }
  1286. /**
  1287. * Set convertedToSwfStatus
  1288. *
  1289. * @param string $convertedToSwfStatus
  1290. *
  1291. * @return Document
  1292. */
  1293. public function setConvertedToSwfStatus($convertedToSwfStatus)
  1294. {
  1295. $this->convertedToSwfStatus = $convertedToSwfStatus;
  1296. return $this;
  1297. }
  1298. /**
  1299. * Get convertedToSwfStatus
  1300. *
  1301. * @return string
  1302. */
  1303. public function getConvertedToSwfStatus()
  1304. {
  1305. return $this->convertedToSwfStatus;
  1306. }
  1307. /**
  1308. * Set orthancInstanceNumber
  1309. *
  1310. * @param string $orthancInstanceNumber
  1311. *
  1312. * @return Document
  1313. */
  1314. public function setOrthancInstanceNumber($orthancInstanceNumber)
  1315. {
  1316. $this->orthanc_instance_number = $orthancInstanceNumber;
  1317. return $this;
  1318. }
  1319. /**
  1320. * Get orthancInstanceNumber
  1321. *
  1322. * @return string
  1323. */
  1324. public function getOrthancInstanceNumber()
  1325. {
  1326. return $this->orthanc_instance_number;
  1327. }
  1328. // @Todo remove getIconClassName function once all aspects of font-awesome has been removed.
  1329. /**
  1330. * returns fa icon class
  1331. */
  1332. public function getIconClassName()
  1333. {
  1334. // determine file extension
  1335. $extension = strtolower(pathinfo($this->getFilename(), PATHINFO_EXTENSION));
  1336. // If the file extension on the filename is empty, check the native filename.
  1337. if (!$extension) {
  1338. $extension = strtolower(pathinfo($this->getNativeFilename(), PATHINFO_EXTENSION));
  1339. }
  1340. return 'mb-icon ' . (array_key_exists($extension, self::$fileIcons) ? self::$fileIcons[$extension]['iconClass'] : 'mb-icon--file');
  1341. }
  1342. /**
  1343. * determines the file type using a convoluted route of checking the file's
  1344. * fa icon class.
  1345. */
  1346. public function getFileFamilyType()
  1347. {
  1348. // determine file extension
  1349. $extension = strtolower(pathinfo($this->getFilename(), PATHINFO_EXTENSION));
  1350. // If the file extension on the filename is empty, check the native filename.
  1351. if (!$extension) {
  1352. $extension = strtolower(pathinfo($this->getNativeFilename(), PATHINFO_EXTENSION));
  1353. }
  1354. return self::guessFileFamilyType($extension);
  1355. }
  1356. /**
  1357. * Guesses the fileFamilyType fiven an extension.
  1358. *
  1359. * @param string $extension
  1360. *
  1361. * @return string
  1362. */
  1363. public static function guessFileFamilyType($extension)
  1364. {
  1365. return (array_key_exists($extension, self::$fileIcons) ? self::$fileIcons[$extension]['type'] : 'false');
  1366. }
  1367. /**
  1368. * Helper function to return if the file is a pdf.
  1369. */
  1370. public function isPdf()
  1371. {
  1372. return $this->getFileFamilyType() === self::FILE_TYPE_PDF;
  1373. }
  1374. /**
  1375. * Helper function to return true if the file is a Image.
  1376. */
  1377. public function isImage()
  1378. {
  1379. return $this->getFileFamilyType() === self::FILE_TYPE_IMAGE;
  1380. }
  1381. /**
  1382. * Helper function to return true if the file is Text or Html.
  1383. */
  1384. public function isTextOrHtml()
  1385. {
  1386. return $this->getFileFamilyType() === self::FILE_TYPE_TEXT_HTML;
  1387. }
  1388. /**
  1389. * Helper function to return true if the file is Msg or Eml.
  1390. */
  1391. public function isEmlOrMsg()
  1392. {
  1393. return $this->getFileFamilyType() === self::FILE_TYPE_EML_MSG;
  1394. }
  1395. /**
  1396. * Helper function to return if the file is an ms office document.
  1397. */
  1398. public function isMSOffice()
  1399. {
  1400. return in_array($this->getFileFamilyType(), [
  1401. self::FILE_TYPE_MSWORD,
  1402. self::FILE_TYPE_MSEXCEL,
  1403. self::FILE_TYPE_MSPOWERPOINT,
  1404. ]);
  1405. }
  1406. /**
  1407. * Helper function to return if the file is a WebAV.
  1408. */
  1409. public function isWebAV()
  1410. {
  1411. return in_array($this->getFileFamilyType(), [self::FILE_TYPE_AUDIO, self::FILE_TYPE_VIDEO]);
  1412. }
  1413. /**
  1414. * Returns true if we support viewing of this document type.
  1415. *
  1416. * @return bool
  1417. */
  1418. public function supportsViewing()
  1419. {
  1420. $allowedTypes = self::getSupportedViewingTypes();
  1421. return in_array($this->getDocumentTypeFamily(), $allowedTypes);
  1422. }
  1423. /**
  1424. * Returns true if we support webAV playback of this document type
  1425. *
  1426. * @return bool
  1427. */
  1428. public function supportsWebAVPlayback()
  1429. {
  1430. $allowedTypes = self::getSupportedWebAVPlaybackTypes();
  1431. $allowedMimeTypes = self::getSupportedWebAVMimeTypes();
  1432. return
  1433. in_array($this->getDocumentTypeFamily(), $allowedTypes)
  1434. && in_array($this->getMimeType(), $allowedMimeTypes);
  1435. }
  1436. /**
  1437. * Returns the documentFamilyTypes we support for viewing.
  1438. *
  1439. * @return array
  1440. */
  1441. public static function getSupportedViewingTypes()
  1442. {
  1443. return [
  1444. self::FILE_TYPE_MSEXCEL,
  1445. self::FILE_TYPE_MSPOWERPOINT,
  1446. self::FILE_TYPE_MSWORD,
  1447. self::FILE_TYPE_PDF,
  1448. self::FILE_TYPE_IMAGE,
  1449. self::FILE_TYPE_TEXT_HTML,
  1450. self::FILE_TYPE_EML_MSG,
  1451. ];
  1452. }
  1453. /**
  1454. * Returns the documentFamilyTypes we support for viewing.
  1455. *
  1456. * @return array
  1457. */
  1458. public static function getSupportedWebAVPlaybackTypes()
  1459. {
  1460. return [
  1461. self::FILE_TYPE_AUDIO,
  1462. self::FILE_TYPE_VIDEO,
  1463. ];
  1464. }
  1465. /**
  1466. * Returns the mime types we support for playing webAV.
  1467. *
  1468. * @return array
  1469. */
  1470. public static function getSupportedWebAVMimeTypes()
  1471. {
  1472. return [
  1473. 'video/mp4',
  1474. //'video/dvr-ms', This is not the actual mime type for DVR, video/x-ms-asf is.
  1475. 'video/x-ms-asf',
  1476. 'audio/mpeg',
  1477. 'audio/x-wav',
  1478. ];
  1479. }
  1480. /**
  1481. * Set documentTypeFamily
  1482. *
  1483. * @param string $documentTypeFamily
  1484. *
  1485. * @return Document
  1486. */
  1487. public function setDocumentTypeFamily($documentTypeFamily)
  1488. {
  1489. $this->documentTypeFamily = $documentTypeFamily;
  1490. return $this;
  1491. }
  1492. /**
  1493. * Get documentTypeFamily
  1494. *
  1495. * @return string
  1496. */
  1497. public function getDocumentTypeFamily()
  1498. {
  1499. return $this->documentTypeFamily;
  1500. }
  1501. /**
  1502. * Set convertedToOptimizedPdfStatus
  1503. *
  1504. * @param int $convertedToOptimizedPdfStatus
  1505. *
  1506. * @return Document
  1507. */
  1508. public function setConvertedToOptimizedPdfStatus($convertedToOptimizedPdfStatus)
  1509. {
  1510. $this->convertedToOptimizedPdfStatus = $convertedToOptimizedPdfStatus;
  1511. return $this;
  1512. }
  1513. /**
  1514. * Get convertedToOptimizedPdfStatus
  1515. *
  1516. * @return int
  1517. */
  1518. public function getConvertedToOptimizedPdfStatus()
  1519. {
  1520. return $this->convertedToOptimizedPdfStatus;
  1521. }
  1522. /**
  1523. * Get ConvertedToOptimizedPdfStatus options
  1524. *
  1525. * @return array
  1526. */
  1527. public static function getConvertedToOptimizedPdfStatusOptions()
  1528. {
  1529. return [
  1530. self::CONVERSION_TO_OPTIMIZED_PDF_PENDING => 'Pending',
  1531. self::CONVERSION_TO_OPTIMIZED_PDF_COMPLETE => 'Complete',
  1532. self::CONVERSION_TO_OPTIMIZED_PDF_FAILED => 'Failed',
  1533. self::CONVERSION_TO_OPTIMIZED_PDF_CURRENT => 'Current',
  1534. self::CONVERSION_TO_OPTIMIZED_PDF_SKIPPED => 'Skipped',
  1535. ];
  1536. }
  1537. /**
  1538. * Get ConvertedToOptimizedPdfStatus label
  1539. *
  1540. * @param bool $markupFriendly - If the label returned should be markup friendly.
  1541. * Used for when you want to use the label as a CSS class.
  1542. *
  1543. * @return string
  1544. */
  1545. public function getConvertedToOptimizedPdfStatusLabel($markupFriendly = false)
  1546. {
  1547. $options = self::getConvertedToOptimizedPdfStatusOptions();
  1548. $label = $options[$this->getConvertedToOptimizedPdfStatus()] ?? '';
  1549. if ($markupFriendly) {
  1550. return strtolower(str_replace(' ', '-', $label));
  1551. }
  1552. return $label;
  1553. }
  1554. /**
  1555. * Returns true if the Document's ConvertedToOptimizedPdf status is Pending.
  1556. *
  1557. * @return bool
  1558. */
  1559. public function isConvertedToOptimizedPdfPending()
  1560. {
  1561. return $this->getConvertedToOptimizedPdfStatus() === self::CONVERSION_TO_OPTIMIZED_PDF_PENDING;
  1562. }
  1563. /**
  1564. * Returns true if the Document's ConvertedToOptimizedPdf status is Complete.
  1565. *
  1566. * @return bool
  1567. */
  1568. public function isConvertedToOptimizedPdfComplete()
  1569. {
  1570. return $this->getConvertedToOptimizedPdfStatus() === self::CONVERSION_TO_OPTIMIZED_PDF_COMPLETE;
  1571. }
  1572. /**
  1573. * Returns true if the Document's ConvertedToOptimizedPdf status is Failed.
  1574. *
  1575. * @return bool
  1576. */
  1577. public function isConvertedToOptimizedPdfFailed()
  1578. {
  1579. return $this->getConvertedToOptimizedPdfStatus() === self::CONVERSION_TO_OPTIMIZED_PDF_FAILED;
  1580. }
  1581. /**
  1582. * Returns true if the Document's ConvertedToOptimizedPdf status is Current.
  1583. *
  1584. * @return bool
  1585. */
  1586. public function isConvertedToOptimizedPdfCurrent()
  1587. {
  1588. return $this->getConvertedToOptimizedPdfStatus() === self::CONVERSION_TO_OPTIMIZED_PDF_CURRENT;
  1589. }
  1590. /**
  1591. * Returns true if the Document's ConvertedToOptimizedPdf status is Skipped.
  1592. *
  1593. * @return bool
  1594. */
  1595. public function isConvertedToOptimizedPdfSkipped()
  1596. {
  1597. return $this->getConvertedToOptimizedPdfStatus() === self::CONVERSION_TO_OPTIMIZED_PDF_SKIPPED;
  1598. }
  1599. /**
  1600. * Set optimizedPdfFilename
  1601. *
  1602. * @param string $optimizedPdfFilename
  1603. *
  1604. * @return Document
  1605. */
  1606. public function setOptimizedPdfFilename($optimizedPdfFilename)
  1607. {
  1608. $this->optimizedPdfFilename = $optimizedPdfFilename;
  1609. return $this;
  1610. }
  1611. /**
  1612. * Get optimizedPdfFilename
  1613. *
  1614. * @return string
  1615. */
  1616. public function getOptimizedPdfFilename()
  1617. {
  1618. return $this->optimizedPdfFilename;
  1619. }
  1620. /**
  1621. * Set optimizedPdfFile
  1622. *
  1623. * @param string $optimizedPdfFile
  1624. *
  1625. * @return Document
  1626. */
  1627. public function setOptimizedPdfFile($optimizedPdfFile)
  1628. {
  1629. $this->optimizedPdfFile = $optimizedPdfFile;
  1630. return $this;
  1631. }
  1632. /**
  1633. * Get optimizedPdfFile
  1634. *
  1635. * @return string
  1636. */
  1637. public function getOptimizedPdfFile()
  1638. {
  1639. return $this->optimizedPdfFile;
  1640. }
  1641. /**
  1642. * Set convertedToXodStatus
  1643. *
  1644. * @param int $convertedToXodStatus
  1645. *
  1646. * @return Document
  1647. */
  1648. public function setConvertedToXodStatus($convertedToXodStatus)
  1649. {
  1650. $this->convertedToXodStatus = $convertedToXodStatus;
  1651. return $this;
  1652. }
  1653. /**
  1654. * Get convertedToXodStatus
  1655. *
  1656. * @return int
  1657. */
  1658. public function getConvertedToXodStatus()
  1659. {
  1660. return $this->convertedToXodStatus;
  1661. }
  1662. /**
  1663. * Get ConvertedToXodStatus options
  1664. *
  1665. * @return array
  1666. */
  1667. public static function getConvertedToXodStatusOptions()
  1668. {
  1669. return [
  1670. self::CONVERSION_TO_XOD_PENDING => 'Pending',
  1671. self::CONVERSION_TO_XOD_COMPLETE => 'Complete',
  1672. self::CONVERSION_TO_XOD_FAILED => 'Failed',
  1673. self::CONVERSION_TO_XOD_CURRENT => 'Current',
  1674. self::CONVERSION_TO_XOD_SKIPPED => 'Skipped',
  1675. self::CONVERSION_TO_XOD_ENCRYPTED => 'Encrypted',
  1676. ];
  1677. }
  1678. /**
  1679. * Get ConvertedToXodStatus label
  1680. *
  1681. * @param bool $markupFriendly - If the label returned should be markup friendly.
  1682. * Used for when you want to use the label as a CSS class.
  1683. *
  1684. * @return string
  1685. */
  1686. public function getConvertedToXodStatusLabel($markupFriendly = false)
  1687. {
  1688. $options = self::getConvertedToXodStatusOptions();
  1689. $label = $options[$this->getConvertedToXodStatus()] ?? '';
  1690. if ($markupFriendly) {
  1691. return strtolower(str_replace(' ', '-', $label));
  1692. }
  1693. return $label;
  1694. }
  1695. /**
  1696. * Get ConvertedToWebAVStatus options
  1697. *
  1698. * @return array
  1699. */
  1700. public static function getConvertedToWebAVStatusOptions()
  1701. {
  1702. return [
  1703. self::CONVERSION_TO_WEBAV_PENDING => 'Pending',
  1704. self::CONVERSION_TO_WEBAV_COMPLETE => 'Complete',
  1705. self::CONVERSION_TO_WEBAV_FAILED => 'Failed',
  1706. self::CONVERSION_TO_WEBAV_CURRENT => 'Current',
  1707. self::CONVERSION_TO_WEBAV_SKIPPED => 'Skipped',
  1708. ];
  1709. }
  1710. /**
  1711. * Get ConvertedToWebAVStatus label
  1712. *
  1713. * @param bool $markupFriendly - If the label returned should be markup friendly.
  1714. * Used for when you want to use the label as a CSS class.
  1715. *
  1716. * @return string
  1717. */
  1718. public function getConvertedToWebAVStatusLabel($markupFriendly = false)
  1719. {
  1720. $options = self::getConvertedToWebAVStatusOptions();
  1721. $label = $options[$this->getConvertedToWebAVStatus()] ?? '';
  1722. if ($markupFriendly) {
  1723. return strtolower(str_replace(' ', '-', $label));
  1724. }
  1725. return $label;
  1726. }
  1727. /**
  1728. * Returns true if the Document's ConvertedToXod status is Pending.
  1729. *
  1730. * @return bool
  1731. */
  1732. public function isConvertedToXodPending()
  1733. {
  1734. return $this->getConvertedToXodStatus() === self::CONVERSION_TO_XOD_PENDING;
  1735. }
  1736. /**
  1737. * Returns true if the Document's ConvertedToXod status is Complete.
  1738. *
  1739. * @return bool
  1740. */
  1741. public function isConvertedToXodComplete()
  1742. {
  1743. return $this->getConvertedToXodStatus() === self::CONVERSION_TO_XOD_COMPLETE;
  1744. }
  1745. /**
  1746. * Returns true if the Document's ConvertedToXod status is Failed.
  1747. *
  1748. * @return bool
  1749. */
  1750. public function isConvertedToXodFailed()
  1751. {
  1752. return $this->getConvertedToXodStatus() === self::CONVERSION_TO_XOD_FAILED;
  1753. }
  1754. /**
  1755. * Returns true if the Document's ConvertedToXod status is Current.
  1756. *
  1757. * @return bool
  1758. */
  1759. public function isConvertedToXodCurrent()
  1760. {
  1761. return $this->getConvertedToXodStatus() === self::CONVERSION_TO_XOD_CURRENT;
  1762. }
  1763. /**
  1764. * Returns true if the Document's ConvertedToXod status is Skipped.
  1765. *
  1766. * @return bool
  1767. */
  1768. public function isConvertedToXodSkipped()
  1769. {
  1770. return $this->getConvertedToXodStatus() === self::CONVERSION_TO_XOD_SKIPPED;
  1771. }
  1772. /**
  1773. * Returns true if the Document's ConvertedToXod status is Encrypted.
  1774. *
  1775. * @return bool
  1776. */
  1777. public function isConvertedToXodEncrypted()
  1778. {
  1779. return $this->getConvertedToXodStatus() === self::CONVERSION_TO_XOD_ENCRYPTED;
  1780. }
  1781. /**
  1782. * Set xodFilename
  1783. *
  1784. * @param string $xodFilename
  1785. *
  1786. * @return Document
  1787. */
  1788. public function setXodFilename($xodFilename)
  1789. {
  1790. $this->xodFilename = $xodFilename;
  1791. return $this;
  1792. }
  1793. /**
  1794. * Get xodFilename
  1795. *
  1796. * @return string
  1797. */
  1798. public function getXodFilename()
  1799. {
  1800. return $this->xodFilename;
  1801. }
  1802. /**
  1803. * Set xodFile
  1804. *
  1805. * @param string $xodFile
  1806. *
  1807. * @return Document
  1808. */
  1809. public function setXodFile($xodFile)
  1810. {
  1811. $this->xodFile = $xodFile;
  1812. return $this;
  1813. }
  1814. /**
  1815. * Set WebAVFile
  1816. *
  1817. * @param string $webAVFile
  1818. *
  1819. * @return Document
  1820. */
  1821. public function setWebAVFile($webAVFile)
  1822. {
  1823. $this->webAVFile = $webAVFile;
  1824. return $this;
  1825. }
  1826. /**
  1827. * Get WebAVFile
  1828. *
  1829. * @return string
  1830. */
  1831. public function getWebAVFile()
  1832. {
  1833. return $this->webAVFile;
  1834. }
  1835. /**
  1836. * Get xodFile
  1837. *
  1838. * @return string
  1839. */
  1840. public function getXodFile()
  1841. {
  1842. return $this->xodFile;
  1843. }
  1844. /**
  1845. * Set ocrFilename
  1846. *
  1847. * @param string $ocrFilename
  1848. *
  1849. * @return Document
  1850. */
  1851. public function setOcrFilename($ocrFilename)
  1852. {
  1853. $this->ocrFilename = $ocrFilename;
  1854. return $this;
  1855. }
  1856. /**
  1857. * Get ocrFilename
  1858. *
  1859. * @return string
  1860. */
  1861. public function getOcrFilename()
  1862. {
  1863. return $this->ocrFilename;
  1864. }
  1865. /**
  1866. * Set ocrFile
  1867. *
  1868. * @param string $ocrFile
  1869. *
  1870. * @return Document
  1871. */
  1872. public function setOcrFile($ocrFile)
  1873. {
  1874. $this->ocrFile = $ocrFile;
  1875. return $this;
  1876. }
  1877. /**
  1878. * Get ocrFile
  1879. *
  1880. * @return string
  1881. */
  1882. public function getOcrFile()
  1883. {
  1884. return $this->ocrFile;
  1885. }
  1886. /**
  1887. * Set convertedToOcrStatus
  1888. *
  1889. * @param int $convertedToOcrStatus
  1890. *
  1891. * @return Document
  1892. */
  1893. public function setConvertedToOcrStatus($convertedToOcrStatus)
  1894. {
  1895. $this->convertedToOcrStatus = $convertedToOcrStatus;
  1896. return $this;
  1897. }
  1898. /**
  1899. * Get convertedToOcrStatus
  1900. *
  1901. * @return int
  1902. */
  1903. public function getConvertedToOcrStatus()
  1904. {
  1905. return $this->convertedToOcrStatus;
  1906. }
  1907. /**
  1908. * Get ConvertedToOcrStatus options
  1909. *
  1910. * @return array
  1911. */
  1912. public static function getConvertedToOcrStatusOptions()
  1913. {
  1914. return [
  1915. self::CONVERSION_TO_OCR_PENDING => 'Pending',
  1916. self::CONVERSION_TO_OCR_COMPLETE => 'Complete',
  1917. self::CONVERSION_TO_OCR_FAILED => 'Failed',
  1918. self::CONVERSION_TO_OCR_CURRENT => 'In Progress',
  1919. self::CONVERSION_TO_OCR_SKIPPED => 'Skipped',
  1920. ];
  1921. }
  1922. /**
  1923. * Get ConvertedToOcrStatus label
  1924. *
  1925. * @param bool $markupFriendly - If the label returned should be markup friendly.
  1926. * Used for when you want to use the label as a CSS class.
  1927. *
  1928. * @return string
  1929. */
  1930. public function getConvertedToOcrStatusLabel($markupFriendly = false)
  1931. {
  1932. $options = self::getConvertedToOcrStatusOptions();
  1933. $label = $options[$this->getConvertedToOcrStatus()] ?? '';
  1934. if ($markupFriendly) {
  1935. return strtolower(str_replace(' ', '-', $label));
  1936. }
  1937. return $label;
  1938. }
  1939. /**
  1940. * Returns true if the Document's ConvertedToOcr status is Pending.
  1941. *
  1942. * @return bool
  1943. */
  1944. public function isConvertedToOcrPending()
  1945. {
  1946. return $this->getConvertedToOcrStatus() === self::CONVERSION_TO_OCR_PENDING;
  1947. }
  1948. /**
  1949. * Returns true if the Document's ConvertedToOcr status is Complete.
  1950. *
  1951. * @return bool
  1952. */
  1953. public function isConvertedToOcrComplete()
  1954. {
  1955. return $this->getConvertedToOcrStatus() === self::CONVERSION_TO_OCR_COMPLETE;
  1956. }
  1957. /**
  1958. * Returns true if the Document's ConvertedToOcr status is Failed.
  1959. *
  1960. * @return bool
  1961. */
  1962. public function isConvertedToOcrFailed()
  1963. {
  1964. return $this->getConvertedToOcrStatus() === self::CONVERSION_TO_OCR_FAILED;
  1965. }
  1966. /**
  1967. * Returns true if the Document's ConvertedToOcr status is Current.
  1968. *
  1969. * @return bool
  1970. */
  1971. public function isConvertedToOcrCurrent()
  1972. {
  1973. return $this->getConvertedToOcrStatus() === self::CONVERSION_TO_OCR_CURRENT;
  1974. }
  1975. /**
  1976. * Returns true if the Document's ConvertedToOcr status is Skipped.
  1977. *
  1978. * @return bool
  1979. */
  1980. public function isConvertedToOcrSkipped()
  1981. {
  1982. return $this->getConvertedToOcrStatus() === self::CONVERSION_TO_OCR_SKIPPED;
  1983. }
  1984. /**
  1985. * Returns true if we support OCR on this document type.
  1986. *
  1987. * @return bool
  1988. */
  1989. public function supportsOCR()
  1990. {
  1991. $allowedTypes = self::getSupportedTypesForOCR();
  1992. return in_array($this->getMimeType(), $allowedTypes);
  1993. }
  1994. /**
  1995. * Returns the MIME types we support for OCR.
  1996. *
  1997. * @return array
  1998. */
  1999. public static function getSupportedTypesForOCR()
  2000. {
  2001. return MimeTypes::PDF_MIME_TYPES;
  2002. }
  2003. /**
  2004. * Returns true if the Document can go ahead with OCR
  2005. *
  2006. * @return bool
  2007. */
  2008. public function ocrCanContinue()
  2009. {
  2010. return (!$this->isConvertedToOcrSkipped()
  2011. && !$this->isConvertedToOcrFailed()
  2012. && !$this->isConvertedToOcrCurrent()
  2013. );
  2014. }
  2015. /**
  2016. * Set ocrXodFilename
  2017. *
  2018. * @param string $ocrXodFilename
  2019. *
  2020. * @return Document
  2021. */
  2022. public function setOcrXodFilename($ocrXodFilename)
  2023. {
  2024. $this->ocrXodFilename = $ocrXodFilename;
  2025. return $this;
  2026. }
  2027. /**
  2028. * Get ocrXodFilename
  2029. *
  2030. * @return string|null
  2031. */
  2032. public function getOcrXodFilename()
  2033. {
  2034. return $this->ocrXodFilename;
  2035. }
  2036. /**
  2037. * Set ocrXodFile
  2038. *
  2039. * @param string $ocrXodFile
  2040. *
  2041. * @return Document
  2042. */
  2043. public function setOcrXodFile($ocrXodFile)
  2044. {
  2045. $this->ocrXodFile = $ocrXodFile;
  2046. return $this;
  2047. }
  2048. /**
  2049. * Get ocrXodFile
  2050. *
  2051. * @return string|null
  2052. */
  2053. public function getOcrXodFile()
  2054. {
  2055. return $this->ocrXodFile;
  2056. }
  2057. /**
  2058. * Set convertedToWebAVStatus.
  2059. *
  2060. * @param int|null $convertedToWebAVStatus
  2061. *
  2062. * @return Document
  2063. */
  2064. public function setConvertedToWebAVStatus($convertedToWebAVStatus = null)
  2065. {
  2066. $this->convertedToWebAVStatus = $convertedToWebAVStatus;
  2067. return $this;
  2068. }
  2069. /**
  2070. * Get convertedToWebAVStatus.
  2071. *
  2072. * @return int|null
  2073. */
  2074. public function getConvertedToWebAVStatus()
  2075. {
  2076. return $this->convertedToWebAVStatus;
  2077. }
  2078. /**
  2079. * Set webAVFilename.
  2080. *
  2081. * @param string|null $webAVFilename
  2082. *
  2083. * @return Document
  2084. */
  2085. public function setWebAVFilename($webAVFilename = null)
  2086. {
  2087. $this->webAVFilename = $webAVFilename;
  2088. return $this;
  2089. }
  2090. /**
  2091. * Get webAVFilename.
  2092. *
  2093. * @return string|null
  2094. */
  2095. public function getWebAVFilename()
  2096. {
  2097. return $this->webAVFilename;
  2098. }
  2099. /**
  2100. * Set xodBlobFile
  2101. *
  2102. * @param string $xodBlobFile
  2103. *
  2104. * @return Document
  2105. */
  2106. public function setXodBlobFile($xodBlobFile): self
  2107. {
  2108. $this->xodBlobFile = $xodBlobFile;
  2109. return $this;
  2110. }
  2111. /**
  2112. *
  2113. * @return VirusScanItem|null
  2114. */
  2115. public function getVirusScanItem(): ?VirusScanItem
  2116. {
  2117. return $this->virusScanItem;
  2118. }
  2119. /**
  2120. * @param VirusScanItem|null $virusScanItem
  2121. *
  2122. * @return self
  2123. */
  2124. public function setVirusScanItem(?VirusScanItem $virusScanItem): self
  2125. {
  2126. // unset the owning side of the relation if necessary
  2127. if ($virusScanItem === null && $this->virusScanItem !== null) {
  2128. $this->virusScanItem->setDocument(null);
  2129. }
  2130. // set the owning side of the relation if necessary
  2131. if ($virusScanItem !== null && $virusScanItem->getDocument() !== $this) {
  2132. $virusScanItem->setDocument($this);
  2133. }
  2134. $this->virusScanItem = $virusScanItem;
  2135. return $this;
  2136. }
  2137. /**
  2138. * @return SortingSessionStack|null
  2139. */
  2140. public function getSortingSessionStack()
  2141. {
  2142. return $this->sortingSessionStack;
  2143. }
  2144. /**
  2145. * @param SortingSessionStack|null $sortingSessionStack
  2146. *
  2147. * @return self
  2148. */
  2149. public function setSortingSessionStack($sortingSessionStack): self
  2150. {
  2151. if ($sortingSessionStack !== null && $sortingSessionStack->getDocument() !== $this) {
  2152. $sortingSessionStack->setDocument($this);
  2153. }
  2154. $this->sortingSessionStack = $sortingSessionStack;
  2155. return $this;
  2156. }
  2157. /**
  2158. * @param VirusScannerPathVisitorInterface $virusScannerPathVisitor
  2159. *
  2160. * @return VirusScannerVisitorInterface
  2161. */
  2162. public function acceptVirusScannerPathVisitor(VirusScannerPathVisitorInterface $virusScannerPathVisitor): string
  2163. {
  2164. return $virusScannerPathVisitor->visitDocument($this);
  2165. }
  2166. /**
  2167. * Get xodBlobFile
  2168. *
  2169. * @return string
  2170. */
  2171. public function getXodBlobFile()
  2172. {
  2173. return $this->xodBlobFile;
  2174. }
  2175. /**
  2176. * We return the xodFilename, as the file is mapped to the same filename field.
  2177. *
  2178. * @return string
  2179. */
  2180. public function getXodBlobFilename()
  2181. {
  2182. return $this->xodFilename;
  2183. }
  2184. /**
  2185. * Set ocrXodBlobFile
  2186. *
  2187. * @param string $ocrXodBlobFile
  2188. *
  2189. * @return Document
  2190. */
  2191. public function setOcrXodBlobFile($ocrXodBlobFile): self
  2192. {
  2193. $this->ocrXodBlobFile = $ocrXodBlobFile;
  2194. return $this;
  2195. }
  2196. /**
  2197. * Get ocrXodBlobFile
  2198. *
  2199. * @return string
  2200. */
  2201. public function getOcrXodBlobFile()
  2202. {
  2203. return $this->ocrXodBlobFile;
  2204. }
  2205. /**
  2206. * We return the xodFilename, as the file is mapped to the same filename field.
  2207. *
  2208. * @return string
  2209. */
  2210. public function getOcrXodBlobFilename()
  2211. {
  2212. return $this->ocrXodFilename;
  2213. }
  2214. /**
  2215. * Returns true if this Document has a CER Index, false otherwise.
  2216. *
  2217. * @return bool|null
  2218. */
  2219. public function hasCERIndex(): ?bool
  2220. {
  2221. return $this->hasCERIndex;
  2222. }
  2223. /**
  2224. * Sets the CER Index status for this Document.
  2225. *
  2226. * @param bool|null $hasCERIndex
  2227. *
  2228. * @return self
  2229. */
  2230. public function setHasCERIndex(?bool $hasCERIndex): self
  2231. {
  2232. $this->hasCERIndex = $hasCERIndex;
  2233. return $this;
  2234. }
  2235. /**
  2236. * Check if the document is part of the CER index.
  2237. *
  2238. * @param array $insightsIndexNativeFilenames
  2239. *
  2240. * @return bool
  2241. */
  2242. public function isCerIndex(array $insightsIndexNativeFilenames): bool
  2243. {
  2244. $nativeFilename = $this->getNativeFilename();
  2245. if ($nativeFilename === null || trim($nativeFilename) === '') {
  2246. return false;
  2247. }
  2248. return in_array($nativeFilename, $insightsIndexNativeFilenames, true);
  2249. }
  2250. }