Ferreteria/v0.3/class/tKeyedRow

From Woozle Writes Code
< Ferreteria‎ | v0.3‎ | class
Revision as of 16:43, 22 May 2022 by Woozle (talk | contribs) (3 revisions imported: moving this project here)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Template:Page/code/class

trait tKeyedRow {

    protected function GetKeyName() {
	$tbl = $this->GetSourceObject();
	if (method_exists($tbl,'GetKeyName')) {
	    $sKey = $tbl->GetKeyName();
	} else {
	    $sKey = NULL;
	}
	return $sKey;
    }
    public function GetKeyField() {
	$sKey = $this->GetKeyName();
	$oField = $this->GetExistingField($sKey);
	return $oField;
    }
    public function GetKeyValue() {
	$sKey = $this->GetKeyName();
	if (is_null($sKey)) {
	    throw new exception('Ferreteria error: Could not retrieve key value because no key name is available.');
	} else {
	    $v = $this->GetValueNz($sKey);
	    return $v;
	}
    }
    public function SetKeyValue($id) {
	$sKey = $this->GetSourceObject()->GetKeyName();
	$this->SetValue($sKey,$id);
    }
    public function IsNew() {
	return is_null($this->GetKeyValue());
    }
}