|
|
| (12 intermediate revisions by 7 users not shown) |
| Line 1: |
Line 1: |
| | {{Howto|Advanced|[[Ivo Jansch]] <ivo@achievo.org>}} |
| | |
| There are many ways in which attributes can be extended. Below are a few examples of attributes that extend other attributes, but add some logic. | | There are many ways in which attributes can be extended. Below are a few examples of attributes that extend other attributes, but add some logic. |
|
| |
|
| Custom attributes can be placed in the attributes/ subdirectory of your modules, and then used by putting | | Custom attributes can be placed in the attributes/ subdirectory of your modules, and then used by putting |
| <pre> | | |
| | <syntaxhighlight lang="php"> |
| useattrib("yourmodule.yourattrib"); | | useattrib("yourmodule.yourattrib"); |
| </pre> | | </syntaxhighlight> |
| | |
| in the node file. If you do that, in the node constructor it's only a matter of: | | in the node file. If you do that, in the node constructor it's only a matter of: |
| <pre> | | |
| | <syntaxhighlight lang="php"> |
| $this->add(new yourCustomAttribute(.......)); | | $this->add(new yourCustomAttribute(.......)); |
| </pre> | | </syntaxhighlight> |
| | |
| ==Display override== | | ==Display override== |
| <pre> | | |
| | <syntaxhighlight lang="php"> |
| class boldAttribute extends atkAttribute | | class boldAttribute extends atkAttribute |
| { | | { |
| Line 19: |
Line 26: |
| } | | } |
| } | | } |
| </pre> | | </syntaxhighlight> |
| | |
| ==Custom label== | | ==Custom label== |
| <pre> | | |
| class clickableLableAttribute extends atkAttribute | | <syntaxhighlight lang="php"> |
| | class clickableLabelAttribute extends atkAttribute |
| { | | { |
| function getLabel() | | function getLabel() |
| Line 31: |
Line 40: |
| } | | } |
| } | | } |
| </pre> | | </syntaxhighlight> |
| | |
| ==Edit override== | | ==Edit override== |
|
| |
|
| todo..
| | Override the edit() function to alter what the user sees in add and edit modes, the function should return the HTML to be used to edit this attribute. This example is from the existing attribute atkIpAttribute - four input boxes are generated and used as the return value. |
| | |
| | <syntaxhighlight lang="php"> |
| | function edit($record, $fieldprefix="") |
| | { |
| | if ($this->hasFlag(AF_IP_SINGLEFIELD)) |
| | return parent::edit($record, $fieldprefix); |
| | |
| | $inputs = array(); |
| | $values = empty($record[$this->fieldName()]) ? NULL : explode('.', $record[$this->fieldName()]); |
| | |
| | for ($i = 0; $i < 4; $i++) |
| | { |
| | $name = $fieldprefix.$this->fieldName().'['.$i.']'; |
| | $value = isset($values[$i]) ? $values[$i] : ''; |
| | $inputs[] = '<input type="text" name="'.$name.'" value="'.$value.'" maxlength="3" size="3" />'; |
| | } |
| | |
| | return implode('.', $inputs); |
| | } |
| | </syntaxhighlight> |
| | |
| | In the same way, you can override the edit function of the new attribute to return whatever input is needed. Note the call to the parent::edit() function too - this can be really helpful when you want to slightly alter or wrap the output rather than duplicate it. |
|
| |
|
| ==Data conversion== | | ==Data conversion== |
|
| |
|
| Converting data right before it goes in the db, or right after it's loaded from the db: | | Converting data right before it goes in the db, or right after it's loaded from the db: |
| <pre> | | |
| | <syntaxhighlight lang="php"> |
| class encryptedAttribute extends atkAttribute | | class encryptedAttribute extends atkAttribute |
| { | | { |
| Line 56: |
Line 89: |
| } | | } |
| } | | } |
| </pre> | | </syntaxhighlight> |
| | |
| ==Custom load/save== | | ==Custom load/save== |
|
| |
|
| todo.. | | todo.. |
|
| |
| Original Poster: Ivo
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
| <div style="display:none">
| |
| [We are delicate. We do not delete your content.]
| |
| [l_sp21]
| |
|
| |
|
| |
| [http://www.buddyprofile.com/viewprofile.php?username=waterfordcrystal waterford crystal]
| |
| [http://www.buddyprofile.com/viewprofile.php?username=swarovskicrystal swarovski crystal bead]
| |
| [http://www.buddyprofile.com/viewprofile.php?username=mesotheliomalawsuits mesothelioma lawsuits]
| |
| [http://www.buddyprofile.com/viewprofile.php?username=mesotheliomasymptoms mesothelioma symptoms]
| |
| [http://www.buddyprofile.com/viewprofile.php?username=mesotheliomadiag mesothelioma diagnosis]
| |
| [http://www.buddyprofile.com/viewprofile.php?username=wacoalbras wacoal bras]
| |
| [http://www.buddyprofile.com/viewprofile.php?username=teenbra teen bra]
| |
| [http://www.buddyprofile.com/viewprofile.php?username=unsecuredloan unsecured signature loan]
| |
| [http://www.buddyprofile.com/viewprofile.php?username=homeloans Countrywide Home Loans]
| |
| [http://blog.moddingplanet.it/?w=formalpromdresses Formal Prom Dresses]
| |
| [http://blog.moddingplanet.it/?w=sexypromdress Sexy Prom Dress]
| |
| [http://blog.moddingplanet.it/?w=cocktaildresses cocktail dresses]
| |
| [http://www.buddyprofile.com/viewprofile.php?username=telmobile TMobile]
| |
| [http://www.buddyprofile.com/viewprofile.php?username=watersoftener water softener]
| |
| [http://www.buddyprofile.com/viewprofile.php?username=tanklesswaterheater tankless water heater]
| |
| [http://www.buddyprofile.com/viewprofile.php?username=rockportshoes rockport shoes]
| |
| [http://www.buddyprofile.com/viewprofile.php?username=osmosiswaterfilter reverse osmosis water filter]
| |
| [http://www.buddyprofile.com/viewprofile.php?username=merrellshoes merrell shoes]
| |
| [http://www.buddyprofile.com/viewprofile.php?username=oscardresses oscar dresses]
| |
| [http://www.buddyprofile.com/viewprofile.php?username=easterdresses easter dresses]
| |
| [http://flyfone.blox.pl/resource/flyfonevoip.htm flyfone voip]
| |
| [http://www.buddyprofile.com/viewprofile.php?username=plussizepromdresses plus size prom dresses]
| |
| [http://www.buddyprofile.com/viewprofile.php?username=discountpromdresses discount prom dresses]
| |
| [http://blog.moddingplanet.it/?w=hooterscasinolas Hooters Casino Las Vegas]
| |
| [http://blog.moddingplanet.it/?w=grandcasinomille grand casino mille lacs]
| |
| [http://blog.moddingplanet.it/?w=lasvegascasino las vegas casino coupons]
| |
| [http://blog.moddingplanet.it/?w=onlinepokeraide online poker aide]
| |
| [http://www.donx.de/blog/pechangacasino pechanga casino]
| |
| [http://www.donx.de/blog/grandvictoriacasino/ grand victoria casino]
| |
| [http://www.donx.de/blog/ballgowns/ ball gowns]
| |
| [http://www.privetparis.com/blog/rtgcasinobonus/ rtg casino bonus]
| |
|
| |
| [http://blog.moddingplanet.it/?w=rtgcasinobonus rtg casino bonus]
| |
| [http://blog.moddingplanet.it/?w=grandcasinocoushat grand casino coushatta]
| |
| [http://blog.moddingplanet.it/?w=grandcasinohinckle grand casino hinckley]
| |
| [http://blog.moddingplanet.it/?w=isleofcapricasino isle of capri casino]
| |
| [http://blog.moddingplanet.it/?w=mohegansuncasino mohegan sun casino]
| |
| [http://blog.moddingplanet.it/?w=palacasino pala casino]
| |
| [http://blog.moddingplanet.it/?w=roulettewheels roulette wheels]
| |
| [http://blog.moddingplanet.it/?w=winstarcasino winstar casino]
| |
| [http://blog.moddingplanet.it/?w=cheappromdresses Cheap Prom Dresses]
| |
| [http://blog.moddingplanet.it/?w=informalweddingdre informal wedding dresses]
| |
| [http://blog.moddingplanet.it/?w=oscardresses oscar dresses]
| |
| [http://blog.moddingplanet.it/?w=eveninggowns evening gowns]
| |
|
| |
| [http://vvvvvv.blox.pl/resource/throat_pokers.htm throat pokers]
| |
| [http://vvvvvv.blox.pl/resource/online_poker_assistant.htm online poker assistant]
| |
| [http://vvvvvv.blox.pl/resource/online_poker_tracker.htm online poker tracker]
| |
| [http://vvvvvv.blox.pl/resource/online_poker_aide.htm online poker aide]
| |
| [http://vvvvvv.blox.pl/resource/party_poker_bonus.htm party poker bonus]
| |
| [http://vvvvvv.blox.pl/resource/party_poker_bonus_code.htm party poker bonus code]
| |
| [http://vvvvvv.blox.pl/resource/bonus_code_party_poker.htm bonus code party poker]
| |
| [http://vvvvvv.blox.pl/resource/bonus_code_deposit_party_poker.htm bonus code deposit party poker]
| |
| [http://vvvvvv.blox.pl/resource/party_poker_bonus_codes.htm party poker bonus codes]
| |
| [http://vvvvvv.blox.pl/resource/carnival_cruises.htm carnival cruises]
| |
| [http://vvvvvv.blox.pl/resource/carnival_game_rentals.htm carnival game rentals]
| |
| [http://vvvvvv.blox.pl/resource/fuzzydice.htm fuzzy dice]
| |
| [http://vvvvvv.blox.pl/resource/bingodaubers.htm bingo daubers]
| |
| [http://vvvvvv.blox.pl/resource/bingoblowers.htm bingo blowers]
| |
| [http://vvvvvv.blox.pl/resource/motor_scooters.htm motor scooters]
| |
| [http://vvvvvv.blox.pl/resource/mini_harley_chopper_scooter.htm mini harley chopper scooter]
| |
| [http://blog.moddingplanet.it/?w=fakerolex fake rolex]
| |
|
| |
| [http://blog.moddingplanet.it/?w=bextravioxx bextra vioxx]
| |
| [http://blog.moddingplanet.it/?w=zocor zocor]
| |
| [http://blog.moddingplanet.it/?w=zithromax zithromax]
| |
| [http://blog.moddingplanet.it/?w=bextralawyernew bextra lawyer new hampshire]
| |
| [http://blog.moddingplanet.it/?w=akanesoma akane soma]
| |
| [http://blog.moddingplanet.it/?w=kyosoma kyo soma]
| |
| [http://blog.moddingplanet.it/?w=prozacnation prozac nation]
| |
| [http://blog.moddingplanet.it/?w=prozacwithdrawal prozac withdrawal]
| |
| [http://blog.moddingplanet.it/?w=simslots sim slots]
| |
| [http://blog.moddingplanet.it/?w=pachisloslotmachine pachislo slot machines]
| |
| [http://blog.moddingplanet.it/?w=programcherries program cherries wild slot machine]
| |
| [http://blog.moddingplanet.it/?w=slotcarracing slot car racing]
| |
| [http://blog.moddingplanet.it/?w=hoslotcars ho slot cars]
| |
|
| |
| [http://blog.moddingplanet.it/?w=bingocages bingo cages]
| |
| [http://blog.moddingplanet.it/?w=bingodaubers bingo daubers]
| |
| [http://blog.moddingplanet.it/?w=bingoblowers bingo blowers]
| |
| [http://blog.moddingplanet.it/?w=bingobags bingo bags]
| |
| [http://blog.moddingplanet.it/?w=baccaratcrystal baccarat crystal]
| |
| [http://blog.moddingplanet.it/?w=nexium nexium]
| |
| [http://blog.moddingplanet.it/?w=onlinepaigowpoker online pai gow poker]
| |
| [http://blog.moddingplanet.it/?w=leighkeno leigh keno]
| |
|
| |
| [http://www.privetparis.com/blog/tramadol50mg/ tramadol 50mg]
| |
| [http://www.privetparis.com/blog/tramadolsaturdaydelivery/ tramadol saturday delivery]
| |
| [http://www.privetparis.com/blog/tramadoler/ tramadol er]
| |
| [http://www.privetparis.com/blog/tramadolsales/ tramadol sales]
| |
| [http://www.privetparis.com/blog/tramadolhcl50mg/ tramadol hcl 50 mg]
| |
| [http://www.privetparis.com/blog/120tramadoll/ 120 tramadol]
| |
| [http://www.privetparis.com/blog/acetaminophenhclpartramadol/ acetaminophen hcl par tramadol]
| |
| [http://blog.moddingplanet.it/?w=plussizemother plus size mother of the bride dresses]
| |
| [http://blog.moddingplanet.it/?w=cheapflowergirl cheap flower girl dresses]
| |
| [http://blog.moddingplanet.it/?w=discountflowergirl discount flower girl dresses]
| |
| [http://blog.moddingplanet.it/?w=infantflowergirl infant flower girl dresses]
| |
| [http://blog.moddingplanet.it/?w=bridalflowergirl bridal flower girl dresses]
| |
| </div>
| |
There are many ways in which attributes can be extended. Below are a few examples of attributes that extend other attributes, but add some logic.
Custom attributes can be placed in the attributes/ subdirectory of your modules, and then used by putting
useattrib("yourmodule.yourattrib");
in the node file. If you do that, in the node constructor it's only a matter of:
$this->add(new yourCustomAttribute(.......));
Display override
class boldAttribute extends atkAttribute
{
function display($record, $mode="")
{
$org = parent::display($record, $mode);
return '<b>'.$org.'</b>';
}
}
Custom label
class clickableLabelAttribute extends atkAttribute
{
function getLabel()
{
$label = parent::getLabel();
$url = "http://www.achievo.org/atk";
return href($url, $label);
}
}
Edit override
Override the edit() function to alter what the user sees in add and edit modes, the function should return the HTML to be used to edit this attribute. This example is from the existing attribute atkIpAttribute - four input boxes are generated and used as the return value.
function edit($record, $fieldprefix="")
{
if ($this->hasFlag(AF_IP_SINGLEFIELD))
return parent::edit($record, $fieldprefix);
$inputs = array();
$values = empty($record[$this->fieldName()]) ? NULL : explode('.', $record[$this->fieldName()]);
for ($i = 0; $i < 4; $i++)
{
$name = $fieldprefix.$this->fieldName().'['.$i.']';
$value = isset($values[$i]) ? $values[$i] : '';
$inputs[] = '<input type="text" name="'.$name.'" value="'.$value.'" maxlength="3" size="3" />';
}
return implode('.', $inputs);
}
In the same way, you can override the edit function of the new attribute to return whatever input is needed. Note the call to the parent::edit() function too - this can be really helpful when you want to slightly alter or wrap the output rather than duplicate it.
Data conversion
Converting data right before it goes in the db, or right after it's loaded from the db:
class encryptedAttribute extends atkAttribute
{
function value2db($record)
{
$value = parent::value2db($record);
$value = someEncryptionMethod($value);
return $value;
}
function db2value($record)
{
$value = parent::db2value($record);
$value = someDescryptionMethod($value);
return $value;
}
}
Custom load/save
todo..