Want to achieve such a function: Launch a website invitation activity, then the participant (owner) will promote the website address link sends the friend, the friend clicks the link to register successfully after the website, owner's invitation log record bar number plus 1.
Activity class Activities
Copy Code code as follows:
Class Activity extends Elggentity {
Private $strategy; To save a policy instance
Public Function __construction ($guid) {
...
$this->load ($GUID); Loading entities
}
Public Function Addlog ($data) {
$this->strategy->addlog ($data); is actually Defaultactivitystrategy::addlog ($data)
}
Public function Load ($guid) {
if (Parent::load ($guid)) {//This procedure assigns all the properties of this instance to the database, so the value of the $this->strategyname is already assigned.
if ($this->strategyname!= ') {
$this->strategy = abstractactivitystrategy::getinstance ($this->strategyname); Load Policy class
}
return true;
}
return false;
}
}
Log Class Activitylog
Copy Code code as follows:
Class Activitylog extends Elggentity {
$private CountValue; Number of invitation Records
...
}
Policy class
Description: elggentity: All entity base classes. Abstractactivitystrategy: Active abstract class
First, create an activity:
Copy Code code as follows:
$activity = new activity ();
$activity->name = ' kknd '; Activity name
$activity->strategyname = ' DEFAULT '; Policy Name
$activity->save (); Save the active class to the database, and the newly added attributes (such as Strategyname) will also be saved
When someone receives an invitation, click on the link, Owner's invitation record entry +1
such as the invitation URL is http://www.xinwusi.com/KKND/1234
Where/kknd/is the active name and 1234 is the GUID of owner, assuming that the activity has a GUID of 8888, the
$activity = new activity (8888); Get active entity
$activity->addlog ($data); Add an invitation record. $data includes the GUID of owner, the GUID of the activity, the activity name, name, and so on.
The process of the last 2 lines of code reads the policy name of the active entity, generates a policy entity based on the policy name, saves it in its own $stragety attribute, and then invokes the Addlog method to increase the logging.
When there is a new activity, the active instance attribute's policy name is changed directly, and the method in the corresponding new policy can be invoked.
Copy Code code as follows:
Class Defaultactivitystrategy extends Abstractactivitystrategy {
...
Public Function Addlog ($data) {
$activityLog = new Activitylog ();
...
$activityLog->save ();
$activityLogAmount = new Activitylogamount (); Count class
...
$activityLogAmount->countvalue + 1;
$activityLogAmount->save ();
}
}