Ferreteria/v2/class/fcPageContent: Difference between revisions

From Woozle Writes Code
< Ferreteria‎ | v2‎ | class
Jump to navigation Jump to search
No edit summary
m (3 revisions imported: moving this project here)
 
(One intermediate revision by one other user not shown)
Line 2: Line 2:
* '''file''': {{l/version|file|page/page.php}}
* '''file''': {{l/version|file|page/page.php}}
* '''extends''': {{l/version|class|fcpeSimple}}
* '''extends''': {{l/version|class|fcpeSimple}}
* '''uses''':
** {{l/version|class|ftExecutableTree}}
** {{l/version|class|ftRenderableTree}}
* '''extended by''':
* '''extended by''':
** {{l/version|class|gcPageContent|project=Greenmine|version=v1}}
** {{l/version|class|gcPageContent|project=Greenmine|version=v1}}
Line 7: Line 10:
==Calls==
==Calls==
* <s>{{l/version/method|fcPageContent|AddString}}($s)</s> is redundant; call {{l/version/method|fcTreeNode|AddText}}($s) instead
* <s>{{l/version/method|fcPageContent|AddString}}($s)</s> is redundant; call {{l/version/method|fcTreeNode|AddText}}($s) instead
==Code==
<source lang=php>
abstract class fcPageContent extends fcpeSimple {
    use ftExecutableTree, ftRenderableTree;
   
    // ++ RECORDS ++ //
   
    protected function GetSessionRecord() {
return fcApp::Me()->GetSessionRecord();
    }
   
    // -- RECORDS -- //
    // ++ THRUPUT ++ //
   
    /*----
      PURPOSE: Adds a string to the main content.
If the page is redirected before rendering, the content will be saved with the Session record
and displayed after the redirect.
    */
    protected function AddString($s) {
$sSaved = $this->GetValue();
$sSaved .= $s;
$this->SetValue($sSaved);
    }
   
    // -- THRUPUT -- //
    // ++ OUTPUT ++ //
    /*----
      NOTE: We shouldn't ever need to have RenderBefore()/RenderAfter() methods here.
The only time this has come up so far, it turned out they belong in the page header.
If we want to wrap the content in, say, <span> tags, then add a tag element node.
    */
    public function Render() {
return
  $this->RenderStashed()
  .$this->RenderNodes()
  .$this->GetValue()
  ;
    }
    // PURPOSE: Render any content that was stashed for a redirect (typically result-status messages)
    protected function RenderStashed() {
$rcSess = $this->GetSessionRecord();
$out = $rcSess->PullStashValue('page contents');
// 2017-05-25 At this point, I totally don't get why this is being called here:
//$rcSess->Save(); maybe it should actually LOAD the data?
return $out;
    }
    /*----
      ACTION: Save anything which should be preserved across a redirect, and then do the redirect.
      PUBLIC so linkable objects can redirect without losing content
      NEW
      HISTORY:
2017-05-25 I previously did $rcSess->Save() after $rcSess->SetStashValue(), but this has proven to be
  awkward since we don't have storage objects (at this level) to do the translation. I'm hoping this
  is unnecessary in the short term; in the long term, it looks like we need a way to have storage objects
  without a form.
    */
    public function DoStashedRedirect($url) {
// save the current page contents for redisplay after redirect
$s = $this->GetValue(); // get content that won't be displayed because we're redirecting
$rcSess = $this->GetSessionRecord();
$rcSess->SetStashValue('page contents',$s);
//fcApp::Me()->ThrowCookies();
//$rcSess->Save(); // write to persistent storage
// now actually redirect
fcHTTP::Redirect($url);
die(); // stop doing stuff; we're redirecting
    }
    /*----
      ACTION: Redirect the browser to the same page (path only; no domain, ?query, or #fragment)
      PUBLIC so widgets (so far, just the login widget) can call it
      HISTORY:
2017-02-04 written as a companion to RedirectToDefaultPage()
    */
    public function RedirectToSamePage() {
$url = fcURL::GetCurrentString();
$this->DoStashedRedirect($url);
    }
    /*----
      ACTION: Redirect the browser to a sensible default URL (currently the base page).
Later we might try to figure out where we were before, and go back there.
      PUBLIC so widgets (so far, just the login widget) can call it
      HISTORY:
2016-12-25 moved here from the login widget, because this is the content we want to save
2017-02-04 renamed from RedirectToEraseRequest() -> RedirectToDefaultPage()
    */
    public function RedirectToDefaultPage() {
$url = fcApp::Me()->GetKioskObject()->GetBasePath(); // until we can come up with something more fine-tuned
$this->DoStashedRedirect($url);
    }
}</source>

Latest revision as of 16:45, 22 May 2022