Edit via SFTP
  1. <?php namespace ferret\data;
  2.  
  3. use ferret\cActionStatus;
  4. use ferret\cObjectPiece;
  5. use ferret\cStaticPiece;
  6.  
  7. /*::::
  8.   PURPOSE: base class for data-operation-results Spaces
  9. */
  10. class cIOResult extends \ferret\cSpace {
  11. use tResult; // SQL, error status
  12. use tTableStatus; // Table()
  13. use tRecordStatus; // Record(), ID()
  14.  
  15. // 2021-08-29 This may cause problems; keep an eye open.
  16. /* 2021-09-05 moved DoPopulate into base class (cSpace)
  17.   public function __construct() {
  18.   parent::__construct();
  19.   $this->DoPopulate();
  20.   }
  21.   */
  22.  
  23. // 2021-08-29 I think now DoPopulate() needs to be called before this... or should this call it?
  24. public function SetResults(string $sql, bool $isOk, cTabloid $t) {
  25. $this->SQL()->SetIt($sql);
  26. $this->Action()->SetOkay($isOk);
  27. $this->Table()->SetIt($t);
  28. }
  29.  
  30. // UNSTUB cSpace
  31. public function DoPopulate() : void {
  32. $this->OnCreate_Table();
  33. $this->OnCreate_Record();
  34. $this->SQL_make();
  35. $this->oAction = new cActionStatus();
  36.  
  37. $htID = \ferret\cEnv::BoldIt(spl_object_id($this));
  38. #echo "SELECT RESULTS (ID $htID) POPULATED<br>";
  39. }
  40.  
  41. private $oAction;
  42. public function Action() : cActionStatus { return $this->oAction; }
  43. }
  44. class cSelectResult extends cIOResult {
  45. public function DoPopulate() : void {
  46. parent::DoPopulate();
  47. $this->SetPiece(new cStaticPiece($this,'rowset'));
  48. }
  49. public function Rowset() : cObjectPiece { return $this->GetPiece('rowset'); }
  50. public function DumpFull() : string {
  51. $s = parent::DumpFull();
  52. if ($this->SQL()->HasIt()) {
  53. $sql = $this->SQL()->GetIt();
  54. $htSQL = \ferret\cEnv::BoldIt($sql);
  55. $s .= "SQL: $htSQL";
  56. }
  57. return $s;
  58. }
  59. }
  60. class cInsertResult extends cIOResult {
  61.  
  62. public function GetRecord() : cSingleRow {
  63. // 2021-04-18 This will need some updating.
  64. if (!$this->HasRecord()) {
  65. // 2021-04-01 could also add HasTable() and HasID() checks here
  66. $t = $this->GetTable();
  67. $id = $this->GetID();
  68. $osrc = $t->GetRow_fromKey($id);
  69. if ($osrc->HasIt()) {
  70. $this->rc = $osrc->GetIt();
  71. }
  72. }
  73. return $this->rc;
  74. }
  75.  
  76. // -- INTERNAL STATE -- //
  77.  
  78. public function Dump() : string {
  79. return parent::Dump().cEnv::NewLine().'Created ID: ['.cEnv::BoldIt($this->ID()->Dump()).']';
  80. }
  81. }
  82. class cUpdateStatus extends cIOResult {}
  83.  
  84. /*::::
  85.   NOTE: It's possible this should descend from a more stripped-down class than cIOResult, because
  86.   that contains some functionality not needed here -- but for now, that seems unnecessarily purist.
  87. */
  88. class cRowKit extends cIOResult {
  89. public function GetActor() : object {
  90. if ($this->Record()->HasIt()) {
  91. $o = $this->Record()->GetIt();
  92. } else {
  93. $o = $this->Table()->GetIt();
  94. }
  95. return $o;
  96. }
  97. }
  98.  
  99. // -- OPERATION RESULTS -- //
  100.