Edit via SFTP
  1. <?php namespace ferret\data;
  2. /*
  3.   PURPOSE: revised table-class structure: basics
  4.   HISTORY:
  5.   2019-09-13 started -- rewriting tables class structure from scratch (again)
  6.   2019-09-28 ifEmitsRows: Removed GetAllRows() because it isn't always needed; classes shouldn't be required to define it
  7.   was: function GetAllRows() : \fcDataRow;
  8.   (return value would need to be a cRowType now)
  9.   2019-11-28 ifEmitsRows: Added optional $sClass parameter to SpawnRowsWrapper for use with dropins admin classes
  10.   Sometimes an existing rowset object needs to be handled by a descendant class, and since PHP
  11.   doesn't let us typecast classes, we have to copy the data.
  12.   ...and then realized that actually, it doesn't solve the problem I was trying to solve.
  13.   2020-02-23 moved Status classes to db/status.php
  14.   2020-07-31 making all rowsets drivable (see base.php for concurrent changes):
  15.   * removed ifEmitsRowsDrivable (and fx SpawnDrivableRowsWrapper())
  16.   2021-08-29 Removed ifEmitsRows because it was just confusing things and not clearly needed.
  17. */
  18. use ferret\cEnv;
  19. /*::::
  20.   PURPOSE: minimum basic table functions
  21.   LOCAL
  22.   HISTORY:
  23.   2019-09-12 renamed ftRecords_forTable to ftRecords_forDBTable
  24.   2019-09-13 created cTabloid based on ftRecords_forDBTable
  25.   2019-10-06 now implements ifDatabase*, though it's not always needed (see ::SetDatabase())
  26.   * presumably this was the original name for ifHasDatabase
  27.   2020-10-19 no no, that's a problem. For one thing, causes a circular module-loading dependency.
  28.   For another, this level of the class isn't supposed to expect a database.
  29.   Moving [S/G]etDatabase() into table-db.php:tHasDatabase and removing ifHasDatabase
  30.   2021-03-14 re-consolidating cTabloidFx into cTabloid
  31.   2021-08-29 Apparently at some point I changed my mind again and made this class db-dependent.
  32.   After some hemming and hawing, I decided:
  33.   1. Everyone uses Spaces now.
  34.   2. Tabloid objects create their workspace on construction.
  35.   3. Caller needs to fill in any info it wants to pass (e.g. database object).
  36.   Made Space() public so caller could pass info.
  37.   2021-09-05 Once again, this is a problem because of Tables ending up with Spaces
  38.   that somehow never got a Database added. I'm thinking we should go back to Tables
  39.   requiring a Database if they need one, although that may pose problems for
  40.   constructor uniformity.
  41.   NOTE that Dropin Tables do *not* need to have a Database, because that it set via other means
  42.   (it can be diffeent on a per-menu-item basis, for one thing).
  43.  
  44. */
  45. abstract class cTabloid {
  46.  
  47. // ++ SETUP ++ //
  48.  
  49. public function __construct() { $this->CreateWorkSpace(); }
  50.  
  51. // -- SETUP -- //
  52. // ++ CONFIG ++ //
  53.  
  54. // class names for emitted objects
  55.  
  56. abstract protected function SingleRowClass() : string;
  57. abstract protected function MultiRowClass() : string;
  58. // DEFAULT, might not ever need overriding? (2021-08-28)
  59. protected function WorkSpaceClass() : string { return cTableWorkSpace::class; }
  60.  
  61. // -- CONFIG -- //
  62. // ++ SPAWNERS ++ //
  63.  
  64. public function SpawnRows() : cMultiRow {
  65. $sClass = $this->MultiRowClass();
  66. $of = $this->Space();
  67. $rs = new $sClass($of);
  68. $rs->RequireSpace();
  69. return $rs;
  70. }
  71. public function SpawnRow() : cSingleRow {
  72. $sClass = $this->SingleRowClass();
  73. $of = $this->Space();
  74. return new $sClass($of);
  75. }
  76.  
  77. // -- SPAWNERS -- //
  78. // ++ WORKSPACE ++ //
  79.  
  80. private $ospWork;
  81. protected function CreateWorkSpace() {
  82. #$htDbg = '<hr>Table '.$this->DumpLine().' is creating workspace.<br>';
  83. $sClass = $this->WorkSpaceClass();
  84. $osp = new $sClass;
  85. #$htDbg .= '<ul><li>TABLE WORKSPACE CREATED: '.$osp->DumpLine();
  86. $this->ospWork = $osp;
  87.  
  88. $osp->DoPopulate(); // make all the status-Pieces
  89. #$htDbg .= '<li>TABLE WORKSPACE POPULATED: '.$osp->DumpLine();
  90.  
  91. $osp->Table()->SetIt($this);
  92. #$htDbg .= '<li>TABLE WORKSPACE HAS SELF: '.$osp->DumpLine();
  93. #$htDbg .= '</ul>';
  94. #$htDbg .= cEnv::HideDrop('Table Workspace details',$osp->DumpFull());
  95. }
  96. /*
  97.   protected function MakeWorkSpace(cDatabase $db) {
  98.   $sClass = $this->WorkSpaceClass();
  99.   $osp = new $sClass($db);
  100.   $this->ospWork = $osp;
  101.  
  102.   // tell the workspace to populate itself:
  103.   $osp->DoPopulate();
  104.  
  105.   // provision the workspace with what we have so far:
  106.   $osp->Database()->SetIt($db);
  107.   $osp->Table()->SetIt($this);
  108.   }
  109.   */
  110. public function Space() : cTableWorkSpace { return $this->ospWork; }
  111.  
  112. // -- WORKSPACE -- //
  113. // ++ DEBUGGING ++ //
  114.  
  115. public function DumpLine() : string {
  116. $htClass = cEnv::BoldIt(get_class($this));
  117. $htID = cEnv::BoldIt(spl_object_id($this));
  118. return "TABLOID class $htClass (ID $htID)";
  119. }
  120.  
  121. // -- DEBUGGING -- //
  122. }
  123.  
  124.