Ferreteria/v2/class/fcMenuOptionLink

from HTYP, the free directory anyone can edit if they can prove to me that they're not a spambot
< Ferreteria‎ | v2‎ | class
Jump to: navigation, search
/*::::
  PURPOSE: menu link that can be one of several mutually-exclusive options
    Designed for headers, but theoretically should work in vertical/hierarchical menus as well.
*/
class fcMenuOptionLink extends fcToggleLink {

    // ++ SETUP ++ //

    public function __construct($sGroupKey,$sKeyValue=TRUE,$sDispOff=NULL,$sDispOn=NULL,$sPopup=NULL) {
	$this->SetPopup($sPopup);
	$this->SetKeyValue($sKeyValue);
	$this->SetKeyName($sGroupKey);
	$this->SetOffDisplay($sDispOff);
	$this->SetOnDisplay($sDispOn);
	$this->SetupDefaults();			// ALWAYS CALL THIS from constructor
	//$this->SetIsAuthorized(TRUE);		// header menus assume access
    }

/* uncomment to see debugging information
    public function Render() {
        $sKeyName = $this->GetKeyName();
        $sKeyValue = $this->GetKeyValue();
        $oPathIn = $this->GetKioskObject()->GetInputObject();

	echo 'RENDERING ['
	  .$sKeyName
	  .']=['
	  .$sKeyValue
	  .'] IS SELECTED=['
	  .$this->GetIsSelected()
	  .'] PATH VALUE=['
	  .$oPathIn->GetBool($sKeyName)
	  .'] SHOULD DISPLAY=['
	  .$this->GetShouldDisplay()
	  //.'] IS AUTH=['
	  //.$this->GetIsAuthorized()
	  .'] REQUIRED PERMIT NULL=['.
	  is_null($this->GetRequiredPrivilege())
	  .']<br>'
	  ;
	return parent::Render();
    }
/**/

      //++values++//

    // NEW
    protected function SetOffDisplay($s) {
	$this->SetValue($s);
    }
    // NEW
    protected function GetOffDisplay() {
	$s = $this->GetValue();
	if (is_null($s)) {
	    $s = $this->GetKeyValue();	// default
	    if ($s === TRUE) {
		// TRUE = special value meaning that the group key should be used without a value, so also display it
		$s = $this->GetKeyName();
	    }
	}
	return $s;
    }
    private $sDispOn;
    // NEW
    protected function SetOnDisplay($s) {
	$this->sDispOn = $s;
    }
    // NEW
    protected function GetOnDisplay() {
	$s = $this->sDispOn;
	if (is_null($s)) {
	    $s = $this->GetOffDisplay();	// default
	}
	return $s;
    }
    protected function HasOnDisplay() {
	return !is_null($this->sDispOn);
    }
    protected function GetDisplayPrefix() {
	if ($this->HasOnDisplay()) {
	    return '';
	} else {
	    return $this->GetIsSelected()?'-':'+';
	}
    }

      //--values--//
      //++calculations++//

    // NEW
    protected function GetLinkText() {
	if ($this->GetIsSelected()) {
	    $s = $this->GetOnDisplay();
	} else {
	    $s = $this->GetOffDisplay();
	}
	return $this->GetDisplayPrefix().$s;
    }
    
    // OVERRIDE
    protected function RenderSelf() {
	$sCSS = $this->GetIsSelected()?'menu-link-active':'menu-link-inactive';
	$sContent = $this->RenderContent();
	return "\n<span class=$sCSS>[$sContent]</span>";
    }
    protected function GetStyleName() {
	return 'ctrl-link-action';
    }

      //--calculations--//
    // -- SETUP -- //

}