Want to implement a function: A website invitation activity, then the participant (owner) to the promotion of the website address link to friends, friends click the link after the site registration success, owner's invitation log record number plus 1.
Activity class Activities
Copy CodeThe code is as follows:
Class Activity extends Elggentity {
Private $strategy; Used to save a policy instance
Public Function __construction ($guid) {
...
$this->load ($GUID); Loading entities
}
Public Function Addlog ($data) {
$this->strategy->addlog ($data); Actual is Defaultactivitystrategy::addlog ($data)
}
Public function Load ($guid) {
if (Parent::load ($guid)) {//This procedure assigns all properties of this instance from the database, so $this->strategyname values are already assigned.
if ($this->strategyname! = ") {
$this->strategy = abstractactivitystrategy::getinstance ($this->strategyname); Load Policy class
}
return true;
}
return false;
}
}
Log Class Activitylog
Copy CodeThe code is as follows:
Class Activitylog extends Elggentity {
$private CountValue; Number of invitation Records
...
}
Policy classes
Description: elggentity: All entity base classes. Abstractactivitystrategy: Activity abstract class
First, create an activity:
Copy CodeThe code is as follows:
$activity = new activity ();
$activity->name = ' kknd '; Activity name
$activity->strategyname = ' DEFAULT '; Policy Name
$activity->save (); Save the activity class to the database, and the newly added attributes (such as Strategyname) will also be saved
When someone receives an invitation, click the link and the owner's invitation record entry +1
For example, the invitation URL is http://www.xinwusi.com/KKND/1234
Where/kknd/is the activity name and 1234 is the owner GUID, 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, name of the activity, and so on.
The last 2 lines of code is the process of reading the active entity's policy name, and based on the policy name to generate a policy entity, stored in its own $stragety attribute, and then call the Addlog method in which to increase the logging.
When there is a new activity, the policy name of the activity instance property is changed directly, and the method in the corresponding new policy can be called.
Copy CodeThe code is 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 ();
}
}
http://www.bkjia.com/PHPjc/321487.html www.bkjia.com true http://www.bkjia.com/PHPjc/321487.html techarticle to achieve such a function: to carry out a website invitation activity, and then the participants (owner) will promote the site address link to friends, friends click the link after the site registration success, Owner's ...