Edit via SFTP
  1. <?php namespace ferret\data\bank;
  2. /*
  3.   FILE: fields/bank/host.php
  4.   PURPOSE: traits for hosting a field bank
  5.   HISTORY:
  6.   2021-03-12 created
  7. */
  8. use ferret\data\cPortBank;
  9.  
  10. /*::::
  11.   HOSTING:
  12.   declare:
  13.   __construct(cPortBank $o) { $this->PortBank()->SetIt($o); }
  14. */
  15. trait tUser {
  16. protected function PortBankPieceName() : string { return 'ferret.fields'; }
  17. protected function PortBank() : \ferret\cObjectPiece { return $this->Space()->GetPiece($this->PortBankPieceName()); }
  18. }
  19. /*::::
  20.   HOSTING: Host must call CreatePortBank() before calling PortBank().
  21. */
  22. trait tMaker {
  23. use tUser;
  24. abstract protected function Call_CreatePortBank(); // a reminder
  25. protected function CreatePortBank() {
  26. $sClass = $this->PortBankClass();
  27. $os = $this->Space();
  28. $op = $os->MakePiece($this->PortBankPieceName());
  29. $of = new $sClass($os);
  30. $op->SetIt($of);
  31. }
  32. abstract protected function PortBankClass() : string;
  33. }
  34.  
  35. trait tComponent {
  36. /* 2021-05-06 it doesn't make sense to have all types of Bank components use the same constructor
  37.   public function __construct(cSpacePortBank $o) {
  38.   $this->SetBank($o);
  39.   #$this->OnCreate();
  40.   }
  41. */
  42. #protected function OnCreate() : void {} // STUB
  43.  
  44. private $oBank;
  45. protected function SetBank(cPortBank $o) { $this->oBank = $o; }
  46. public function GetBank() : cPortBank { return $this->oBank; }
  47. }
  48.  
  49. // -- METHODS -- //
  50. // ++ ASSIGNS ++ //
  51.  
  52. trait tForTable {
  53. use tMaker;
  54.  
  55. // OVERRIDE to also create PortBank
  56. protected function CreateWorkSpace() {
  57. parent::CreateWorkSpace();
  58. $this->CreatePortBank();
  59. }
  60. protected function Call_CreatePortBank() {} // REMINDER FULFILLED
  61. }
  62. trait tForRowset { use tUser; }
  63. trait tForRecord {
  64. use tUser;
  65.  
  66. /*----
  67.   OVERRIDE: When we read in a record, we want to also translate it to native.
  68.   NOTE: This *only* sets the value stored in each Unit
  69.   HISTORY:
  70.   2021-06-01 Let's actually implement that bit of translation, shall we? Yes, let's do shall.
  71.   2021-08-23 Now uses GetValuesSet() instead of GetValues(). Not sure if this should be necessary,
  72.   but hopefully it will be easier to determine once this is no longer stopping execution.
  73.   */
  74. public function SetValues_fromStorage(array $arvStor) {
  75.  
  76. //[+DEBUG]
  77. #echo 'CLASS '.get_class($this).' setting values from storage<br>';
  78. #echo '<hr>GOT TO '.__FILE__.' line '.__LINE__.'<br>';
  79. #echo 'SETTING FROM STORAGE: '.\fcArray::Render($arvStor);
  80. //[-DEBUG]
  81.  
  82. #$osp = $this->Space();
  83. #$osb = $osp->GetBank();
  84. $osb = $this->PortBank()->GetIt();
  85.  
  86. ////
  87. // 1. convert Storage input to native format
  88.  
  89. // get the Storage bank, for conversion
  90. $oprStor = $osb->GetStorage();
  91. // convert storage-format input to native
  92. $oprStor->FromInputArray($arvStor);
  93.  
  94. ////
  95. // 2. copy from Unit values to Record values
  96.  
  97. // get the Native Row
  98. $oprNat = $osb->GetNative();
  99. // get any Native values that have been set
  100. $arvNat = $oprNat->GetValuesSet();
  101. // store them in the Record
  102. $this->SetCells($arvNat);
  103. #echo 'BANK CLASS: '.get_class($this->PortBank()).'<br>';
  104. }
  105. }
  106.  
  107. // -- ASSIGNS -- //
  108.