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 = 'Workspaces'; // Renamed from private folder to workspaces MSR-5393
  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 $includeDocumentChildren
  476. * @param array $additionalLiAttributes
  477. *
  478. * @return array
  479. */
  480. public function getJsTreeFormattedNode($replacementNodeText = null, $includeChildren = false, $includeDocumentChildren = false, $additionalLiAttributes = [])
  481. {
  482. $node = [
  483. 'text' => $replacementNodeText ?: $this->getName(),
  484. 'type' => 'folder', // we give the node a type because we will be distinguishing between node types on the JS side
  485. // Not passing through an icon will make jstree use it's own
  486. 'icon' => 'mb-icon mb-icon--folder',
  487. 'li_attr' => [
  488. 'data-collection-id' => $this->getId(),
  489. 'data-controller' => 'fullrow-foldertree',
  490. 'data-creator-id' => $this->getCreator() ? $this->getCreator()->getId() : '',
  491. 'title' => $replacementNodeText ?: $this->getName(),
  492. ],
  493. ];
  494. // any additional attributes that have been passed through should be assigned to the node
  495. foreach ($additionalLiAttributes as $key => $value) {
  496. $node['li_attr'][$key] = $value;
  497. }
  498. // only include the children of this node if we want to
  499. if ($includeChildren) {
  500. $node['children'] = $this->getChildrenAsJsTreeFormattedNodes($includeChildren, $includeDocumentChildren, $additionalLiAttributes);
  501. }
  502. return $node;
  503. }
  504. /**
  505. * Returns this collection as a ContextMenu formatted Tree so we can include it as a submenu structure in a context
  506. * menu
  507. *
  508. * @param string $keyPrefix
  509. * @param null|mixed $replacementNodeText
  510. *
  511. * @return array
  512. */
  513. public function getContextMenuFormattedTree($keyPrefix, $replacementNodeText = null)
  514. {
  515. return ['sub-' . $this->getId() => $this->getContextMenuFormattedNode($keyPrefix, $replacementNodeText)];
  516. }
  517. /**
  518. * Returns all this Collection's Children in ContextMenu items format
  519. *
  520. * @param bool $includeDocumentChildren
  521. * @param bool $includeChildren
  522. * @param array $additionalLiAttributes
  523. *
  524. * @return array
  525. */
  526. public function getChildrenAsJsTreeFormattedNodes($includeChildren = false, $includeDocumentChildren = false, $additionalLiAttributes = [])
  527. {
  528. // order the children alphabetically
  529. $criteria = Criteria::create()
  530. ->orderBy(['name' => Criteria::ASC])
  531. ;
  532. $children = null;
  533. foreach ($this->getChildren()->matching($criteria) as $childCollection) {
  534. $children[] = $childCollection->getJsTreeFormattedNode(null, $includeChildren, $includeDocumentChildren, $additionalLiAttributes);
  535. }
  536. // if we want to include the document children
  537. if ($includeDocumentChildren) {
  538. // all document children also get a collection id sent through, so we know what collection
  539. // the document belongs to
  540. $additionalLiAttributes['data-collection-id'] = $this->getId();
  541. foreach ($this->getDocuments() as $document) {
  542. $children[] = $document->getJsTreeFormattedNode(null, $additionalLiAttributes);
  543. }
  544. }
  545. return $children;
  546. }
  547. /**
  548. * Returns this node formatted as a Context Menu item.
  549. *
  550. * @param string $keyPrefix
  551. * @param null|mixed $replacementNodeText
  552. *
  553. * @return array
  554. */
  555. public function getContextMenuFormattedNode($keyPrefix, $replacementNodeText = null)
  556. {
  557. // create an array which represents the node in the format required by jQueryContextMenu
  558. $node = [
  559. 'name' => $replacementNodeText ?: $this->getName(),
  560. // we always have one sub item which with be an clickable endpoint with the name being the key prefix and the word 'Here'
  561. // this is to facilitate the 'Copy Here' and 'Move Here' functionality that this all exists for
  562. 'items' => [$keyPrefix . '-' . $this->getId() => ['name' => ucwords($keyPrefix) . ' Here']],
  563. ];
  564. //if we have some children
  565. if (!$this->getChildren()->isEmpty()) {
  566. // add a separator @todo it might become a problem with these separators all having the same key? 'sep'
  567. $node['items']['sep'] = '------';
  568. // add all the children
  569. $node['items'] = array_merge($node['items'], $this->getChildrenAsContextMenuFormattedNodes($keyPrefix));
  570. }
  571. return $node;
  572. }
  573. /**
  574. * Returns all this Collection's Children in jsTreeNode format
  575. *
  576. * @param mixed $keyPrefix
  577. *
  578. * @return array
  579. */
  580. public function getChildrenAsContextMenuFormattedNodes($keyPrefix)
  581. {
  582. // order the children alphabetically
  583. $criteria = Criteria::create()
  584. ->orderBy(['name' => Criteria::ASC])
  585. ;
  586. $children = null;
  587. foreach ($this->getChildren()->matching($criteria) as $childCollection) {
  588. $children['sub-' . $childCollection->getId()] = $childCollection->getContextMenuFormattedNode($keyPrefix);
  589. }
  590. return $children;
  591. }
  592. /**
  593. * Recursive function to return all the documents in a collection in the
  594. * vertical order that they appear in the folder tree.
  595. * We start with an empty array then add to it as we recurse.
  596. *
  597. * @param array $documents
  598. *
  599. * @return array
  600. */
  601. public function getVerticallyOrderedDocumentList($documents = [])
  602. {
  603. $children = $this->getChildren();
  604. // process children first, then get the documents for the current node.
  605. foreach ($children as $child) {
  606. $documents = $child->getVerticallyOrderedDocumentList($documents);
  607. }
  608. foreach ($this->getDocuments() as $doc) {
  609. // add all the documents attached to the collection if the collection
  610. // is not a root collection.
  611. // if it is a root collection only add documents that are ONLY in
  612. // the root collection. If this is not done we will have duplicates
  613. if ($this->getParent() === null && (is_countable($doc->getCollections()) ? count($doc->getCollections()) : 0) == 1) {
  614. $documents[] = [
  615. 'collectionId' => $this->getId(),
  616. 'document' => $doc,
  617. ];
  618. } elseif ($this->getParent() !== null) {
  619. $documents[] = [
  620. 'collectionId' => $this->getId(),
  621. 'document' => $doc,
  622. ];
  623. }
  624. }
  625. return $documents;
  626. }
  627. /**
  628. * Add documents
  629. *
  630. * @param Document $documents
  631. *
  632. * @return Collection
  633. */
  634. public function addDocument(Document $documents)
  635. {
  636. $this->documents[] = $documents;
  637. return $this;
  638. }
  639. /**
  640. * Remove documents
  641. *
  642. * @param Document $documents
  643. */
  644. public function removeDocument(Document $documents)
  645. {
  646. $this->documents->removeElement($documents);
  647. }
  648. /**
  649. * Get documents
  650. *
  651. * @return \Doctrine\Common\Collections\Collection|Document[]
  652. */
  653. public function getDocuments()
  654. {
  655. return $this->documents;
  656. }
  657. /**
  658. * Get project
  659. *
  660. * @throws \Exception
  661. *
  662. * @return Project
  663. */
  664. public function getProject()
  665. {
  666. // if this Collection has a Medical Records project, then it is a Medical Records collection
  667. $project = $this->getProjectMedicalRecords();
  668. if (!$project) {
  669. $project = $this->getProjectUnsortedRecords();
  670. }
  671. // else we have to assume it is a private collection
  672. if (!$project) {
  673. $project = $this->getProjectPrivate();
  674. }
  675. // Else, it must be a private sandbox collection
  676. if (!$project) {
  677. $project = $this->getProjectPrivateSandbox();
  678. }
  679. return $project;
  680. }
  681. /**
  682. * Set deletedAt
  683. *
  684. * @param \DateTime $deletedAt
  685. *
  686. * @return Collection
  687. */
  688. public function setDeletedAt($deletedAt)
  689. {
  690. $this->deletedAt = $deletedAt;
  691. return $this;
  692. }
  693. /**
  694. * Get deletedAt
  695. *
  696. * @return \DateTime
  697. */
  698. public function getDeletedAt()
  699. {
  700. return $this->deletedAt;
  701. }
  702. /**
  703. * Set disc
  704. *
  705. * @param Disc $disc
  706. *
  707. * @return Collection
  708. */
  709. public function setDisc(?Disc $disc = null)
  710. {
  711. $this->disc = $disc;
  712. return $this;
  713. }
  714. /**
  715. * Get disc
  716. *
  717. * @return Disc
  718. */
  719. public function getDisc()
  720. {
  721. return $this->disc;
  722. }
  723. /**
  724. * Set userPrivateCollection
  725. *
  726. * @param User $userPrivateCollection
  727. *
  728. * @return Collection
  729. */
  730. public function setUserPrivateCollection(?User $userPrivateCollection = null)
  731. {
  732. $this->userPrivateCollection = $userPrivateCollection;
  733. return $this;
  734. }
  735. /**
  736. * Get userPrivateCollection
  737. *
  738. * @return ProjectUser
  739. */
  740. public function getUserPrivateCollection()
  741. {
  742. return $this->userPrivateCollection;
  743. }
  744. /**
  745. * Set projectMedicalRecords
  746. *
  747. * @param Project $projectMedicalRecords
  748. *
  749. * @return Collection
  750. */
  751. public function setProjectMedicalRecords(?Project $projectMedicalRecords = null)
  752. {
  753. $this->projectMedicalRecords = $projectMedicalRecords;
  754. return $this;
  755. }
  756. /**
  757. * Get projectMedicalRecords
  758. *
  759. * @return Project
  760. */
  761. public function getProjectMedicalRecords()
  762. {
  763. return $this->projectMedicalRecords;
  764. }
  765. /**
  766. * Set projectPrivate
  767. *
  768. * @param Project $projectPrivate
  769. *
  770. * @return Collection
  771. */
  772. public function setProjectPrivate(?Project $projectPrivate = null)
  773. {
  774. $this->projectPrivate = $projectPrivate;
  775. return $this;
  776. }
  777. /**
  778. * Get projectPrivate
  779. *
  780. * @return Project
  781. */
  782. public function getProjectPrivate()
  783. {
  784. return $this->projectPrivate;
  785. }
  786. /**
  787. * Checks to see if this collection recursively contains the given collection
  788. * or is the given collection itself
  789. *
  790. * @param Collection $collection
  791. *
  792. * @return bool
  793. */
  794. public function containsCollectionRecursive(Collection $collection)
  795. {
  796. // if this collection is the gien one
  797. if ($this->getId() == $collection->getId()) {
  798. // then return true
  799. return true;
  800. }
  801. // else if the given collection is one of this collection's children
  802. if ($this->getChildren()->contains($collection)) {
  803. // then return true
  804. return true;
  805. }
  806. // otherwise go through each of this Collection's children
  807. foreach ($this->getChildren() as $childCollection) {
  808. // and check if they contain the given collection recursively
  809. if ($childCollection->containsCollectionRecursive($collection)) {
  810. return true;
  811. }
  812. }
  813. // if we get here then the given collection does not reside anywhere within
  814. // this collection
  815. return false;
  816. }
  817. /**
  818. * Checks to see if this collection or any of its children contain this document.
  819. *
  820. * @param Document $document
  821. *
  822. * @return bool
  823. */
  824. public function containsDocumentRecursive(Document $document)
  825. {
  826. // if this collection contains this document
  827. if ($this->getDocuments()->contains($document)) {
  828. return true;
  829. // else loop through each child and return true if any one of them contain it
  830. }
  831. foreach ($this->getChildren() as $child) {
  832. if ($child->containsDocumentRecursive($document)) {
  833. return true;
  834. }
  835. }
  836. // if we get here then this document is not contained in this collection
  837. // or any of its children
  838. return false;
  839. }
  840. /**
  841. * Checks if this collection, or any of it's children, contains documents.
  842. *
  843. * @return bool
  844. */
  845. public function isEmpty(): bool
  846. {
  847. // If this collection contains at least 1 document
  848. if ($this->getDocuments()->count() > 0) {
  849. // It is not empty
  850. return false;
  851. }
  852. // Loop through each child and return false if any one of them contains a document
  853. foreach ($this->getChildren() as $child) {
  854. if (!$child->isEmpty()) {
  855. return false;
  856. }
  857. }
  858. // If we get here and we still haven't found any documents, the collection and all its children are empty.
  859. return true;
  860. }
  861. /**
  862. * Set projectPrivateSandbox
  863. *
  864. * @param Project $projectPrivateSandbox
  865. *
  866. * @return Collection
  867. */
  868. public function setProjectPrivateSandbox(?Project $projectPrivateSandbox = null)
  869. {
  870. $this->projectPrivateSandbox = $projectPrivateSandbox;
  871. return $this;
  872. }
  873. /**
  874. * Get projectPrivateSandbox
  875. *
  876. * @return Project
  877. */
  878. public function getProjectPrivateSandbox()
  879. {
  880. return $this->projectPrivateSandbox;
  881. }
  882. /**
  883. * Set creator
  884. *
  885. * @param User $creator
  886. *
  887. * @return Collection
  888. */
  889. public function setCreator(User $creator)
  890. {
  891. $this->creator = $creator;
  892. return $this;
  893. }
  894. /**
  895. * Get creator
  896. *
  897. * @return User
  898. */
  899. public function getCreator()
  900. {
  901. return $this->creator;
  902. }
  903. /**
  904. * Set userPrivateSandboxCollection
  905. *
  906. * @param ProjectUser $userPrivateSandboxCollection
  907. *
  908. * @return Collection
  909. */
  910. public function setUserPrivateSandboxCollection(?ProjectUser $userPrivateSandboxCollection = null)
  911. {
  912. $this->userPrivateSandboxCollection = $userPrivateSandboxCollection;
  913. return $this;
  914. }
  915. /**
  916. * Get userPrivateSandboxCollection
  917. *
  918. * @return ProjectUser
  919. */
  920. public function getUserPrivateSandboxCollection()
  921. {
  922. return $this->userPrivateSandboxCollection;
  923. }
  924. /**
  925. * Set projectUnsortedRecords.
  926. *
  927. * @param Project|null $projectUnsortedRecords
  928. *
  929. * @return Collection
  930. */
  931. public function setProjectUnsortedRecords(?Project $projectUnsortedRecords = null)
  932. {
  933. $this->projectUnsortedRecords = $projectUnsortedRecords;
  934. return $this;
  935. }
  936. /**
  937. * Get projectUnsortedRecords.
  938. *
  939. * @return Project|null
  940. */
  941. public function getProjectUnsortedRecords()
  942. {
  943. return $this->projectUnsortedRecords;
  944. }
  945. /**
  946. * Returns the display name for the collection.
  947. *
  948. * @return string
  949. */
  950. public function getDisplayName(): string
  951. {
  952. if ($this->getProject()) {
  953. switch (true) {
  954. case $this->getProject()->getMedicalRecordsCollection() === $this:
  955. return self::DISPLAY_NAME_MEDICAL_RECORDS;
  956. case $this->getProject()->getPrivateCollection() === $this:
  957. return self::DISPLAY_NAME_PRIVATE;
  958. case $this->getProject()->getPrivateSandboxCollection() === $this:
  959. return self::DISPLAY_NAME_PRIVATE_SANDBOX;
  960. case $this->getProject()->getUnsortedRecordsCollection() === $this:
  961. return self::DISPLAY_NAME_UNSORTED_RECORDS;
  962. }
  963. }
  964. return $this->getName();
  965. }
  966. }