src/Entity/Collection.php line 26

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\Criteria;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Gedmo\Mapping\Annotation as Gedmo;
  7. use MedBrief\MSR\Repository\CollectionRepository;
  8. /**
  9. * Collection
  10. *
  11. * @ORM\Table(name="collection", indexes={@ORM\Index(name="slug_index", columns={"slug"}), @ORM\Index(name="root_index", columns={"root"})})
  12. *
  13. * @ORM\Entity(repositoryClass=CollectionRepository::class)
  14. *
  15. * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false)
  16. *
  17. * @Gedmo\Tree(type="nested")
  18. *
  19. * @Audit\Auditable
  20. *
  21. * @Audit\Security(view={"ROLE_ALLOWED_TO_AUDIT"})
  22. */
  23. class Collection
  24. {
  25. public const DISPLAY_NAME_MEDICAL_RECORDS = 'Records';
  26. public const DISPLAY_NAME_PRIVATE = 'Case Documentation';
  27. public const DISPLAY_NAME_PRIVATE_SANDBOX = 'Private Folders';
  28. public const DISPLAY_NAME_UNSORTED_RECORDS = 'Unsorted Records';
  29. public const DISPLAY_NAME_MEDBRIEF_INTERNAL = '# MedBrief';
  30. /**
  31. * @var int
  32. *
  33. * @ORM\Column(name="id", type="bigint", nullable=false)
  34. *
  35. * @ORM\Id
  36. *
  37. * @ORM\GeneratedValue(strategy="IDENTITY")
  38. */
  39. private $id;
  40. /**
  41. * @var string
  42. *
  43. * @ORM\Column(name="name", type="string", length=255, nullable=false)
  44. */
  45. private $name;
  46. /**
  47. * @var int
  48. *
  49. * @ORM\Column(name="lft", type="integer")
  50. *
  51. * @Gedmo\TreeLeft
  52. */
  53. private $lft;
  54. /**
  55. * @var int
  56. *
  57. * @ORM\Column(name="rgt", type="integer")
  58. *
  59. * @Gedmo\TreeRight
  60. */
  61. private $rgt;
  62. /**
  63. * @var int|null
  64. *
  65. * @ORM\Column(name="root", type="integer", nullable=true)
  66. *
  67. * @Gedmo\TreeRoot
  68. */
  69. private $root;
  70. /**
  71. * @var int
  72. *
  73. * @ORM\Column(name="lvl", type="integer")
  74. *
  75. * @Gedmo\TreeLevel
  76. */
  77. private $lvl;
  78. /**
  79. * @var string
  80. *
  81. * @ORM\Column(name="slug", type="string")
  82. *
  83. * @Gedmo\Slug(fields={"name"}, unique=false, updatable=false, separator="_")
  84. */
  85. private $slug;
  86. /**
  87. * @var \DateTime
  88. *
  89. * @ORM\Column(name="created", type="datetime")
  90. *
  91. * @Gedmo\Timestampable(on="create")
  92. */
  93. private $created;
  94. /**
  95. * @var \DateTime
  96. *
  97. * @ORM\Column(name="updated", type="datetime")
  98. *
  99. * @Gedmo\Timestampable(on="update")
  100. */
  101. private $updated;
  102. /**
  103. * @var \DateTime|null
  104. *
  105. * @ORM\Column(name="deletedAt", type="datetime", nullable=true)
  106. */
  107. private $deletedAt;
  108. /**
  109. * @var Project
  110. *
  111. * @ORM\OneToOne(targetEntity="MedBrief\MSR\Entity\Project", mappedBy="medicalRecordsCollection")
  112. */
  113. private $projectMedicalRecords;
  114. /**
  115. * @var Project
  116. *
  117. * @ORM\OneToOne(targetEntity="MedBrief\MSR\Entity\Project", mappedBy="unsortedRecordsCollection")
  118. */
  119. private $projectUnsortedRecords;
  120. /**
  121. * @var Project
  122. *
  123. * @ORM\OneToOne(targetEntity="MedBrief\MSR\Entity\Project", mappedBy="privateCollection")
  124. */
  125. private $projectPrivate;
  126. /**
  127. * @var Project
  128. *
  129. * @ORM\OneToOne(targetEntity="MedBrief\MSR\Entity\Project", mappedBy="privateSandboxCollection")
  130. */
  131. private $projectPrivateSandbox;
  132. /**
  133. * @var Disc
  134. *
  135. * @ORM\OneToOne(targetEntity="MedBrief\MSR\Entity\Disc", mappedBy="collection")
  136. */
  137. private $disc;
  138. /**
  139. * @var ProjectUser
  140. *
  141. * @ORM\OneToOne(targetEntity="MedBrief\MSR\Entity\ProjectUser", mappedBy="privateCollection", cascade={"persist","detach","merge","refresh"})
  142. */
  143. private $userPrivateCollection;
  144. /**
  145. * @var ProjectUser
  146. *
  147. * @ORM\OneToOne(targetEntity="MedBrief\MSR\Entity\ProjectUser", mappedBy="privateSandboxCollection", cascade={"persist","detach","merge","refresh"})
  148. */
  149. private $userPrivateSandboxCollection;
  150. /**
  151. * @var \Doctrine\Common\Collections\Collection
  152. *
  153. * @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\Collection", mappedBy="parent")
  154. *
  155. * @ORM\OrderBy({
  156. * "name"="ASC"
  157. * })
  158. */
  159. private $children;
  160. /**
  161. * @var Collection
  162. *
  163. * @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\Collection", inversedBy="children")
  164. *
  165. * @ORM\JoinColumns({
  166. *
  167. * @ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="CASCADE")
  168. * })
  169. *
  170. * @Gedmo\TreeParent
  171. */
  172. private $parent;
  173. /**
  174. * @var User
  175. *
  176. * @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\User")
  177. *
  178. * @ORM\JoinColumns({
  179. *
  180. * @ORM\JoinColumn(name="creator_id", referencedColumnName="id")
  181. * })
  182. */
  183. private $creator;
  184. /**
  185. * @var \Doctrine\Common\Collections\Collection
  186. *
  187. * @ORM\ManyToMany(targetEntity="MedBrief\MSR\Entity\Document", inversedBy="collections")
  188. *
  189. * @ORM\JoinTable(name="collection_document",
  190. * joinColumns={
  191. *
  192. * @ORM\JoinColumn(name="collection_id", referencedColumnName="id", onDelete="CASCADE")
  193. * },
  194. * inverseJoinColumns={
  195. * @ORM\JoinColumn(name="document_id", referencedColumnName="id", onDelete="CASCADE")
  196. * }
  197. * )
  198. *
  199. * @ORM\OrderBy({
  200. * "filename"="ASC"
  201. * })
  202. */
  203. private $documents;
  204. /**
  205. * Constructor
  206. */
  207. public function __construct()
  208. {
  209. $this->children = new \Doctrine\Common\Collections\ArrayCollection();
  210. $this->documents = new \Doctrine\Common\Collections\ArrayCollection();
  211. }
  212. public function __toString()
  213. {
  214. return $this->getName();
  215. }
  216. /**
  217. * Get id
  218. *
  219. * @return int
  220. */
  221. public function getId()
  222. {
  223. return $this->id;
  224. }
  225. /**
  226. * Set name
  227. *
  228. * @param string $name
  229. *
  230. * @return Collection
  231. */
  232. public function setName($name)
  233. {
  234. $this->name = $name;
  235. return $this;
  236. }
  237. /**
  238. * Get name
  239. *
  240. * @return string
  241. */
  242. public function getName()
  243. {
  244. return $this->name;
  245. }
  246. /**
  247. * Get exportFriendlyName
  248. *
  249. * @return string
  250. */
  251. public function getExportFriendly()
  252. {
  253. return str_replace('/', '-', $this->name);
  254. }
  255. /**
  256. * Set lft
  257. *
  258. * @param int $lft
  259. *
  260. * @return Collection
  261. */
  262. public function setLft($lft)
  263. {
  264. $this->lft = $lft;
  265. return $this;
  266. }
  267. /**
  268. * Get lft
  269. *
  270. * @return int
  271. */
  272. public function getLft()
  273. {
  274. return $this->lft;
  275. }
  276. /**
  277. * Set rgt
  278. *
  279. * @param int $rgt
  280. *
  281. * @return Collection
  282. */
  283. public function setRgt($rgt)
  284. {
  285. $this->rgt = $rgt;
  286. return $this;
  287. }
  288. /**
  289. * Get rgt
  290. *
  291. * @return int
  292. */
  293. public function getRgt()
  294. {
  295. return $this->rgt;
  296. }
  297. /**
  298. * Set root
  299. *
  300. * @param int $root
  301. *
  302. * @return Collection
  303. */
  304. public function setRoot($root)
  305. {
  306. $this->root = $root;
  307. return $this;
  308. }
  309. /**
  310. * Get root
  311. *
  312. * @return int
  313. */
  314. public function getRoot()
  315. {
  316. return $this->root;
  317. }
  318. /**
  319. * Set lvl
  320. *
  321. * @param int $lvl
  322. *
  323. * @return Collection
  324. */
  325. public function setLvl($lvl)
  326. {
  327. $this->lvl = $lvl;
  328. return $this;
  329. }
  330. /**
  331. * Get lvl
  332. *
  333. * @return int
  334. */
  335. public function getLvl()
  336. {
  337. return $this->lvl;
  338. }
  339. /**
  340. * Set slug
  341. *
  342. * @param string $slug
  343. *
  344. * @return Collection
  345. */
  346. public function setSlug($slug)
  347. {
  348. $this->slug = $slug;
  349. return $this;
  350. }
  351. /**
  352. * Get slug
  353. *
  354. * @return string
  355. */
  356. public function getSlug()
  357. {
  358. return $this->slug;
  359. }
  360. /**
  361. * Set created
  362. *
  363. * @param \DateTime $created
  364. *
  365. * @return Collection
  366. */
  367. public function setCreated($created)
  368. {
  369. $this->created = $created;
  370. return $this;
  371. }
  372. /**
  373. * Get created
  374. *
  375. * @return \DateTime
  376. */
  377. public function getCreated()
  378. {
  379. return $this->created;
  380. }
  381. /**
  382. * Set updated
  383. *
  384. * @param \DateTime $updated
  385. *
  386. * @return Collection
  387. */
  388. public function setUpdated($updated)
  389. {
  390. $this->updated = $updated;
  391. return $this;
  392. }
  393. /**
  394. * Get updated
  395. *
  396. * @return \DateTime
  397. */
  398. public function getUpdated()
  399. {
  400. return $this->updated;
  401. }
  402. /**
  403. * Add children
  404. *
  405. * @param Collection $children
  406. *
  407. * @return Collection
  408. */
  409. public function addChild(Collection $children)
  410. {
  411. $this->children[] = $children;
  412. return $this;
  413. }
  414. /**
  415. * Remove children
  416. *
  417. * @param Collection $children
  418. */
  419. public function removeChild(Collection $children)
  420. {
  421. $this->children->removeElement($children);
  422. }
  423. /**
  424. * Get children
  425. *
  426. * @return \Doctrine\Common\Collections\Collection
  427. */
  428. public function getChildren()
  429. {
  430. return $this->children;
  431. }
  432. /**
  433. * Set parent
  434. *
  435. * @param Collection $parent
  436. *
  437. * @return Collection
  438. */
  439. public function setParent(?Collection $parent = null)
  440. {
  441. $this->parent = $parent;
  442. return $this;
  443. }
  444. /**
  445. * Get parent
  446. *
  447. * @return Collection
  448. */
  449. public function getParent()
  450. {
  451. return $this->parent;
  452. }
  453. /**
  454. * Returns this collection as a jsTree formatted Array - as per
  455. * http://www.jstree.com/docs/json/
  456. * The results of this function should be json_encoded
  457. *
  458. * @param string $replacementRootNodeText If this is set, the text of the root node
  459. * will be replaced with this text
  460. * @param bool $includeChildren
  461. * @param bool $includeDocumentChildren
  462. * @param array $additionalLiAttributes
  463. *
  464. * @return array
  465. */
  466. public function getJsTreeFormattedTree($replacementRootNodeText = null, $includeChildren = false, $includeDocumentChildren = false, $additionalLiAttributes = [])
  467. {
  468. return [$this->getJsTreeFormattedNode($replacementRootNodeText, $includeChildren, $includeDocumentChildren, $additionalLiAttributes)];
  469. }
  470. /**
  471. * Returns this collection as a jsTree formatted node
  472. *
  473. * @param string $replacementNodeText
  474. * @param bool $includeChildren
  475. * @param bool $includeDocuments
  476. * @param array $additionalLiAttributes
  477. * @param array $insightsIndexNativeFilenames An array of native filenames that are part of the CER index.
  478. *
  479. * @return array
  480. */
  481. public function getJsTreeFormattedNode(
  482. $replacementNodeText = null,
  483. bool $includeChildren = true,
  484. bool $includeDocuments = true,
  485. array $additionalLiAttributes = [],
  486. array $insightsIndexNativeFilenames = []
  487. ) {
  488. // Not passing through an icon will make jstree use it's own
  489. $node = [
  490. 'text' => $replacementNodeText ?: $this->getName(),
  491. 'type' => 'folder',
  492. 'icon' => ' mb-icon mb-icon--folder',
  493. 'valid_children' => true,
  494. 'li_attr' => [
  495. 'data-collection-id' => $this->getId(),
  496. 'data-controller' => 'fullrow-foldertree',
  497. 'data-creator-id' => $this->getCreator() ? $this->getCreator()->getId() : '',
  498. ],
  499. ];
  500. // any additional attributes that have been passed through should be assigned to the node
  501. foreach ($additionalLiAttributes as $key => $value) {
  502. $node['li_attr'][$key] = $value;
  503. }
  504. // only include the children of this node if we want to
  505. if (!$includeChildren && !$includeDocuments) {
  506. return $node;
  507. }
  508. $node['children'] = [];
  509. if ($includeChildren) {
  510. foreach ($this->getChildren() as $childCollection) {
  511. $node['children'][] = $childCollection->getJsTreeFormattedNode(
  512. null,
  513. true,
  514. true,
  515. $additionalLiAttributes,
  516. $insightsIndexNativeFilenames
  517. );
  518. }
  519. }
  520. if ($includeDocuments) {
  521. $documentLiAttributes = $additionalLiAttributes;
  522. $documentLiAttributes['data-collection-id'] = $this->getId();
  523. foreach ($this->getDocuments() as $document) {
  524. $node['children'][] = $document->getJsTreeFormattedNode(
  525. null,
  526. $documentLiAttributes,
  527. $document->getSortingSessionStack() !== null,
  528. $document->isCerIndex($insightsIndexNativeFilenames)
  529. );
  530. }
  531. }
  532. return $node;
  533. }
  534. /**
  535. * Returns this collection as a ContextMenu formatted Tree so we can include it as a submenu structure in a context
  536. * menu
  537. *
  538. * @param string $keyPrefix
  539. * @param null|mixed $replacementNodeText
  540. *
  541. * @return array
  542. */
  543. public function getContextMenuFormattedTree($keyPrefix, $replacementNodeText = null)
  544. {
  545. return ['sub-' . $this->getId() => $this->getContextMenuFormattedNode($keyPrefix, $replacementNodeText)];
  546. }
  547. /**
  548. * Returns all this Collection's Children in ContextMenu items format
  549. *
  550. * @param bool $includeDocumentChildren
  551. * @param bool $includeChildren
  552. * @param array $additionalLiAttributes
  553. *
  554. * @return array
  555. */
  556. public function getChildrenAsJsTreeFormattedNodes($includeChildren = false, $includeDocumentChildren = false, $additionalLiAttributes = [])
  557. {
  558. // order the children alphabetically
  559. $criteria = Criteria::create()
  560. ->orderBy(['name' => Criteria::ASC])
  561. ;
  562. $children = null;
  563. foreach ($this->getChildren()->matching($criteria) as $childCollection) {
  564. $children[] = $childCollection->getJsTreeFormattedNode(null, $includeChildren, $includeDocumentChildren, $additionalLiAttributes);
  565. }
  566. // if we want to include the document children
  567. if ($includeDocumentChildren) {
  568. // all document children also get a collection id sent through, so we know what collection
  569. // the document belongs to
  570. $additionalLiAttributes['data-collection-id'] = $this->getId();
  571. foreach ($this->getDocuments() as $document) {
  572. $children[] = $document->getJsTreeFormattedNode(null, $additionalLiAttributes, $document->getSortingSessionStack() !== null);
  573. }
  574. }
  575. return $children;
  576. }
  577. /**
  578. * Returns this node formatted as a Context Menu item.
  579. *
  580. * @param string $keyPrefix
  581. * @param null|mixed $replacementNodeText
  582. *
  583. * @return array
  584. */
  585. public function getContextMenuFormattedNode($keyPrefix, $replacementNodeText = null)
  586. {
  587. // create an array which represents the node in the format required by jQueryContextMenu
  588. $node = [
  589. 'name' => $replacementNodeText ?: $this->getName(),
  590. // we always have one sub item which with be an clickable endpoint with the name being the key prefix and the word 'Here'
  591. // this is to facilitate the 'Copy Here' and 'Move Here' functionality that this all exists for
  592. 'items' => [$keyPrefix . '-' . $this->getId() => ['name' => ucwords($keyPrefix) . ' Here']],
  593. ];
  594. //if we have some children
  595. if (!$this->getChildren()->isEmpty()) {
  596. // add a separator @todo it might become a problem with these separators all having the same key? 'sep'
  597. $node['items']['sep'] = '------';
  598. // add all the children
  599. $node['items'] = array_merge($node['items'], $this->getChildrenAsContextMenuFormattedNodes($keyPrefix));
  600. }
  601. return $node;
  602. }
  603. /**
  604. * Returns all this Collection's Children in jsTreeNode format
  605. *
  606. * @param mixed $keyPrefix
  607. *
  608. * @return array
  609. */
  610. public function getChildrenAsContextMenuFormattedNodes($keyPrefix)
  611. {
  612. // order the children alphabetically
  613. $criteria = Criteria::create()
  614. ->orderBy(['name' => Criteria::ASC])
  615. ;
  616. $children = null;
  617. foreach ($this->getChildren()->matching($criteria) as $childCollection) {
  618. $children['sub-' . $childCollection->getId()] = $childCollection->getContextMenuFormattedNode($keyPrefix);
  619. }
  620. return $children;
  621. }
  622. /**
  623. * Recursive function to return all the documents in a collection in the
  624. * vertical order that they appear in the folder tree.
  625. * We start with an empty array then add to it as we recurse.
  626. *
  627. * @param array $documents
  628. *
  629. * @return array
  630. */
  631. public function getVerticallyOrderedDocumentList($documents = [])
  632. {
  633. $children = $this->getChildren();
  634. // process children first, then get the documents for the current node.
  635. foreach ($children as $child) {
  636. $documents = $child->getVerticallyOrderedDocumentList($documents);
  637. }
  638. foreach ($this->getDocuments() as $doc) {
  639. // add all the documents attached to the collection if the collection
  640. // is not a root collection.
  641. // if it is a root collection only add documents that are ONLY in
  642. // the root collection. If this is not done we will have duplicates
  643. if ($this->getParent() === null && (is_countable($doc->getCollections()) ? count($doc->getCollections()) : 0) == 1) {
  644. $documents[] = [
  645. 'collectionId' => $this->getId(),
  646. 'document' => $doc,
  647. ];
  648. } elseif ($this->getParent() !== null) {
  649. $documents[] = [
  650. 'collectionId' => $this->getId(),
  651. 'document' => $doc,
  652. ];
  653. }
  654. }
  655. return $documents;
  656. }
  657. /**
  658. * Add documents
  659. *
  660. * @param Document $documents
  661. *
  662. * @return Collection
  663. */
  664. public function addDocument(Document $documents)
  665. {
  666. $this->documents[] = $documents;
  667. return $this;
  668. }
  669. /**
  670. * Remove documents
  671. *
  672. * @param Document $documents
  673. */
  674. public function removeDocument(Document $documents)
  675. {
  676. $this->documents->removeElement($documents);
  677. }
  678. /**
  679. * Get documents
  680. *
  681. * @return \Doctrine\Common\Collections\Collection|Document[]
  682. */
  683. public function getDocuments()
  684. {
  685. return $this->documents;
  686. }
  687. /**
  688. * Get project
  689. *
  690. * @throws \Exception
  691. *
  692. * @return Project
  693. */
  694. public function getProject()
  695. {
  696. // if this Collection has a Medical Records project, then it is a Medical Records collection
  697. $project = $this->getProjectMedicalRecords();
  698. if (!$project) {
  699. $project = $this->getProjectUnsortedRecords();
  700. }
  701. // else we have to assume it is a private collection
  702. if (!$project) {
  703. $project = $this->getProjectPrivate();
  704. }
  705. // Else, it must be a private sandbox collection
  706. if (!$project) {
  707. $project = $this->getProjectPrivateSandbox();
  708. }
  709. return $project;
  710. }
  711. /**
  712. * Set deletedAt
  713. *
  714. * @param \DateTime $deletedAt
  715. *
  716. * @return Collection
  717. */
  718. public function setDeletedAt($deletedAt)
  719. {
  720. $this->deletedAt = $deletedAt;
  721. return $this;
  722. }
  723. /**
  724. * Get deletedAt
  725. *
  726. * @return \DateTime
  727. */
  728. public function getDeletedAt()
  729. {
  730. return $this->deletedAt;
  731. }
  732. /**
  733. * Set disc
  734. *
  735. * @param Disc $disc
  736. *
  737. * @return Collection
  738. */
  739. public function setDisc(?Disc $disc = null)
  740. {
  741. $this->disc = $disc;
  742. return $this;
  743. }
  744. /**
  745. * Get disc
  746. *
  747. * @return Disc
  748. */
  749. public function getDisc()
  750. {
  751. return $this->disc;
  752. }
  753. /**
  754. * Set userPrivateCollection
  755. *
  756. * @param User $userPrivateCollection
  757. *
  758. * @return Collection
  759. */
  760. public function setUserPrivateCollection(?User $userPrivateCollection = null)
  761. {
  762. $this->userPrivateCollection = $userPrivateCollection;
  763. return $this;
  764. }
  765. /**
  766. * Get userPrivateCollection
  767. *
  768. * @return ProjectUser
  769. */
  770. public function getUserPrivateCollection()
  771. {
  772. return $this->userPrivateCollection;
  773. }
  774. /**
  775. * Set projectMedicalRecords
  776. *
  777. * @param Project $projectMedicalRecords
  778. *
  779. * @return Collection
  780. */
  781. public function setProjectMedicalRecords(?Project $projectMedicalRecords = null)
  782. {
  783. $this->projectMedicalRecords = $projectMedicalRecords;
  784. return $this;
  785. }
  786. /**
  787. * Get projectMedicalRecords
  788. *
  789. * @return Project
  790. */
  791. public function getProjectMedicalRecords()
  792. {
  793. return $this->projectMedicalRecords;
  794. }
  795. /**
  796. * Set projectPrivate
  797. *
  798. * @param Project $projectPrivate
  799. *
  800. * @return Collection
  801. */
  802. public function setProjectPrivate(?Project $projectPrivate = null)
  803. {
  804. $this->projectPrivate = $projectPrivate;
  805. return $this;
  806. }
  807. /**
  808. * Get projectPrivate
  809. *
  810. * @return Project
  811. */
  812. public function getProjectPrivate()
  813. {
  814. return $this->projectPrivate;
  815. }
  816. /**
  817. * Checks to see if this collection recursively contains the given collection
  818. * or is the given collection itself
  819. *
  820. * @param Collection $collection
  821. *
  822. * @return bool
  823. */
  824. public function containsCollectionRecursive(Collection $collection)
  825. {
  826. // if this collection is the gien one
  827. if ($this->getId() == $collection->getId()) {
  828. // then return true
  829. return true;
  830. }
  831. // else if the given collection is one of this collection's children
  832. if ($this->getChildren()->contains($collection)) {
  833. // then return true
  834. return true;
  835. }
  836. // otherwise go through each of this Collection's children
  837. foreach ($this->getChildren() as $childCollection) {
  838. // and check if they contain the given collection recursively
  839. if ($childCollection->containsCollectionRecursive($collection)) {
  840. return true;
  841. }
  842. }
  843. // if we get here then the given collection does not reside anywhere within
  844. // this collection
  845. return false;
  846. }
  847. /**
  848. * Checks to see if this collection or any of its children contain this document.
  849. *
  850. * @param Document $document
  851. *
  852. * @return bool
  853. */
  854. public function containsDocumentRecursive(Document $document)
  855. {
  856. // if this collection contains this document
  857. if ($this->getDocuments()->contains($document)) {
  858. return true;
  859. // else loop through each child and return true if any one of them contain it
  860. }
  861. foreach ($this->getChildren() as $child) {
  862. if ($child->containsDocumentRecursive($document)) {
  863. return true;
  864. }
  865. }
  866. // if we get here then this document is not contained in this collection
  867. // or any of its children
  868. return false;
  869. }
  870. /**
  871. * Checks if this collection, or any of it's children, contains documents.
  872. *
  873. * @return bool
  874. */
  875. public function isEmpty(): bool
  876. {
  877. // If this collection contains at least 1 document
  878. if ($this->getDocuments()->count() > 0) {
  879. // It is not empty
  880. return false;
  881. }
  882. // Loop through each child and return false if any one of them contains a document
  883. foreach ($this->getChildren() as $child) {
  884. if (!$child->isEmpty()) {
  885. return false;
  886. }
  887. }
  888. // If we get here and we still haven't found any documents, the collection and all its children are empty.
  889. return true;
  890. }
  891. /**
  892. * Set projectPrivateSandbox
  893. *
  894. * @param Project $projectPrivateSandbox
  895. *
  896. * @return Collection
  897. */
  898. public function setProjectPrivateSandbox(?Project $projectPrivateSandbox = null)
  899. {
  900. $this->projectPrivateSandbox = $projectPrivateSandbox;
  901. return $this;
  902. }
  903. /**
  904. * Get projectPrivateSandbox
  905. *
  906. * @return Project
  907. */
  908. public function getProjectPrivateSandbox()
  909. {
  910. return $this->projectPrivateSandbox;
  911. }
  912. /**
  913. * Set creator
  914. *
  915. * @param User $creator
  916. *
  917. * @return Collection
  918. */
  919. public function setCreator(User $creator)
  920. {
  921. $this->creator = $creator;
  922. return $this;
  923. }
  924. /**
  925. * Get creator
  926. *
  927. * @return User
  928. */
  929. public function getCreator()
  930. {
  931. return $this->creator;
  932. }
  933. /**
  934. * Set userPrivateSandboxCollection
  935. *
  936. * @param ProjectUser $userPrivateSandboxCollection
  937. *
  938. * @return Collection
  939. */
  940. public function setUserPrivateSandboxCollection(?ProjectUser $userPrivateSandboxCollection = null)
  941. {
  942. $this->userPrivateSandboxCollection = $userPrivateSandboxCollection;
  943. return $this;
  944. }
  945. /**
  946. * Get userPrivateSandboxCollection
  947. *
  948. * @return ProjectUser
  949. */
  950. public function getUserPrivateSandboxCollection()
  951. {
  952. return $this->userPrivateSandboxCollection;
  953. }
  954. /**
  955. * Set projectUnsortedRecords.
  956. *
  957. * @param Project|null $projectUnsortedRecords
  958. *
  959. * @return Collection
  960. */
  961. public function setProjectUnsortedRecords(?Project $projectUnsortedRecords = null)
  962. {
  963. $this->projectUnsortedRecords = $projectUnsortedRecords;
  964. return $this;
  965. }
  966. /**
  967. * Get projectUnsortedRecords.
  968. *
  969. * @return Project|null
  970. */
  971. public function getProjectUnsortedRecords()
  972. {
  973. return $this->projectUnsortedRecords;
  974. }
  975. /**
  976. * Returns the display name for the collection.
  977. *
  978. * @return string
  979. */
  980. public function getDisplayName(): string
  981. {
  982. if ($this->getProject()) {
  983. switch (true) {
  984. case $this->getProject()->getMedicalRecordsCollection() === $this:
  985. return self::DISPLAY_NAME_MEDICAL_RECORDS;
  986. case $this->getProject()->getPrivateCollection() === $this:
  987. return self::DISPLAY_NAME_PRIVATE;
  988. case $this->getProject()->getPrivateSandboxCollection() === $this:
  989. return self::DISPLAY_NAME_PRIVATE_SANDBOX;
  990. case $this->getProject()->getUnsortedRecordsCollection() === $this:
  991. return self::DISPLAY_NAME_UNSORTED_RECORDS;
  992. }
  993. }
  994. return $this->getName();
  995. }
  996. }