Ferreteria/archive/admin.php: Difference between revisions
(this should be the latest version, but HG may have some tweaks) |
m (Woozle moved page User:Woozle/admin.php to User:Woozle/Ferreteria/archive/admin.php: this page is obsolete) |
(No difference)
|
Revision as of 19:11, 13 February 2015
About
- Purpose: classes useful for writing administration SpecialPages, i.e. pages that interact heavily with database tables.
- Edits:
- 2013-01-04 This should be the latest version, but copy on HostGator may have some tweaks to be merged.
Code
<php><?php /*
LIBRARY: admin.php - some classes useful for administration functions in MW extensions GLOBALS: $vgOut is usually set in menu.php It must be a descendant of clsRichText, which is defined in richtext.php HISTORY: 2010-04-06
clsAdminTable, clsAdminData, clsAdminData_Logged written (in menu.php)
2010-10-25 clsAdminTable, clsAdminData extracted from menu.php 2012-12-31 clsAdminTable_helper 2013-01-04 restored _AdminLink() to clsAdminData_helper from old copy of menu.php * It was in clsAdminData_helper. * Was there a reason it went away? Need to document replacement functionality, if so.
- /
/*%%%%
CLASS: clsAdminTable NOTES: * TODO: clsAdmin* should be rewritten to use helpers * TODO: $vgOut should be an object field, not a global
- /
class clsAdminTable_helper {
private $objTbl;
public function Table(clsTable_key_single $iTable=NULL) {
if (!is_null($iTable)) { $this->objTbl = $iTable; } return $this->objTbl;
} public static function AdminLink($iID,$iShow=NULL,$iPopup=NULL) {
global $vgOut;
$id = $iID;
$arLink = array( 'page' => 'item', 'id' => $id); $strShow = is_null($iShow)?($id):$iShow; $strPopup = is_null($iPopup)?('view item ID '.$id):$iPopup; $out = $vgOut->SelfLink($arLink,$strShow,$strPopup); return $out;
}
}
class clsAdminData_helper {
private $objRecs; private $strNewTxt; private $strNewKey;
//===== // STATIC section
public static function _AdminLink(clsDataSet $iThis,$iText=NULL,$iPopup=NULL,array $iarArgs=NULL) {
global $vgOut;
$txtShow = is_null($iText)?($iThis->ID):$iText; if (isset($iThis->Table->ActionKey)) { $strKey = $iThis->Table->ActionKey; } else { $strKey = $iThis->Table->Name(); }
$arLink = $iarArgs; $arLink = array( 'page' => $strKey, 'id' => $iThis->KeyValue()); $out = $vgOut->SelfLink($arLink,$txtShow,$iPopup); return $out;
}
//===== // DYNAMIC section
public function __construct() {
$this->strNewTxt = 'new'; $this->strNewKey = ;
}
protected function ActionID() {
$objRecs = $this->Recs(); return $objRecs->IsNew()?($this->NewKey()):$objRecs->KeyString();
} /*---- PURPOSE: r/w access method for the text to display for new record ID links */ public function NewText($iStr=NULL) {
if (!is_null($iStr)) { $this->strNewTxt = $iStr; } return $this->strNewTxt;
} /*---- PURPOSE: r/w access method for the ID value to use for new record ID links RULES:
* If set to an empty string, no link will be generated
*/ public function NewKey($iStr=NULL) {
if (!is_null($iStr)) { $this->strNewKey = $iStr; } return $this->strNewKey;
}
public function Recs(clsRecs_key_single $iRecs=NULL) {
if (!is_null($iRecs)) { $this->objRecs = $iRecs; } return $this->objRecs;
} protected function AdminLink_array($iarArgs=NULL) {
$txtID = $this->ActionID(); $objRecs = $this->Recs(); if (isset($objRecs->Table->ActionKey)) { $strKey = $objRecs->Table->ActionKey; } else { $strKey = $objRecs->Table->Name(); }
$arLink = array( 'page' => $strKey, 'id' => $txtID );
if (is_array($iarArgs)) { // 2010-06-25 This has not been tested -- maybe it's not useful? $arLink = array_merge($arLink,$iarArgs); } return $arLink;
} /*---- HISTORY:
2012-12-31 After moving code to Helper, making this dynamic
*/ public function AdminURL($iarArgs=NULL) {
global $vgPage;
$arLink = $this->AdminLink_array($iarArgs); $out = $vgPage->SelfURL($arLink,TRUE); return $out;
} /*---- USED BY:
* (static) VbzAdmin::clsAdminTopic::AdminLink() -- may need some rewriting * (dynamic) VbzAdmin::VbzAdminStkItems::Listing_forItem()
HISTORY:
2010-10-06 (both) Wasn't sure who is using this, so commented it out (not WorkFerret or AudioFerret) VbzAdmin didn't *seem* to be using it... (dynamic) Thought I checked VbzAdmin, WorkFerret, and AudioFerret 2010-10-13 (static) Found that VbzAdmin uses it Actually, this is the "boilerplate" function used by most clsDataSet descendants. 2010-10-13 (dynamic) VbzAdmin::VbzAdminStkItems::Listing_forItem() calls it 2010-11-19 (static) Added handling of new records. 2012-03-31 (static) If I added handling of new records in 2010, it must have gotten removed somehow. Adding handling of new records again. 2012-12-31 After moving this code to clsAdminData_helper, modifying new-record handling to use object field values. Also, no longer any need for a static function, so merging with dynamic version.
*/ public function AdminLink($iText=NULL,$iPopup=NULL,array $iarArgs=NULL) {
global $vgOut;
$objRecs = $this->Recs();
if (is_object($vgOut)) { $arLink = $this->AdminLink_array($iarArgs); $txtID = $this->ActionID($objRecs); $txtShow = is_null($iText)?($txtID):$iText; $out = $vgOut->SelfLink($arLink,$txtShow,$iPopup);
return $out; } else { throw new exception('Need to initialize vgOut by calling vgPage->Use*()'); }
} /*---- HISTORY:
2012-12-31 After moving code to Helper, making this dynamic
*/ public function AdminRedirect(array $iarArgs=NULL) {
global $vgOut,$vgPage; global $wgOut;
$url = $this->AdminURL($iarArgs); $wgOut->redirect($url);
}
}
/*%%%%
CLASS: clsAdminTable HISTORY: 2010-10-04 Moved ActionKey() back into data.php, because it's useful for logging. No more need for this class; deprecated now. 2010-10-19 ...except for AdminLink() (when did I add that?)
- /
class clsAdminTable extends clsTable_key_single {
/*---- USED BY: VbzAdmin::VbzAdminItems::AdminLink() HISTORY:
Extricated from VbzAdmin::VbzAdminItems
*/ public static function AdminLink($iID,$iShow=NULL,$iPopup=NULL) {
global $vgOut;
$id = $iID;
$arLink = array( 'page' => 'item', 'id' => $id); $strShow = is_null($iShow)?($id):$iShow; $strPopup = is_null($iPopup)?('view item ID '.$id):$iPopup; $out = $vgOut->SelfLink($arLink,$strShow,$strPopup); return $out;
}
} /*=====
HISTORY: 2010-11-23 Added _AdminRedirect(), _AdminLink_array(), _AdminURL(), _ActionID() BOILERPLATES: public function AdminLink($iText=NULL,$iPopup=NULL,array $iarArgs=NULL) {
return clsAdminData::_AdminLink($this,$iText,$iPopup,$iarArgs);
} public function AdminRedirect(array $iarArgs=NULL) {
return clsAdminData::_AdminRedirect($this,$iarArgs);
}
- /
class clsAdminData extends clsRecs_key_single {
/*==== SECTION: static versions of dynamic functions PURPOSE: for classes which inherit from non-Admin classes (fake multiple inheritance) */ static protected function _ActionID(clsRecs_keyed_abstract $iObj) {
return $iObj->IsNew()?'new':$iObj->KeyString();
} /*---- USED BY: VbzAdmin::VbzAdminStkItems::Listing_forItem() HISTORY:
2010-10-06 Disabled, because it wasn't clear if anyone was using it. Thought I checked VbzAdmin, WorkFerret, and AudioFerret 2010-10-13 VbzAdmin::VbzAdminStkItems::Listing_forItem() calls it
*/ public function AdminLink($iText=NULL,$iPopup=NULL,array $iarArgs=NULL) {
return clsAdminData_helper::_AdminLink($this,$iText,$iPopup,$iarArgs);
}
} </php>