The Subscription Class
Subscription creation and manipulation
Functions
Subscription::addSubscription
Definition
- Name
- addSubscription
- Syntax
- Array|False = Subscription::addSubscription( Array $action );
Description
Add subscription to item for current user.
Will only add paid subscription if order_id is passed.
Will not add subscription if subscription already exists, but returns existing subscription instead.
/#controller#/addSubscription/
Parameters
- $action
-
Array Action array.
Action parameters
Parameters in $_POST
Return values
Array|false Subscription object. False on error.
Examples
Add subscription to free item (without price)
$SubscriptionClass = new Subscription();
$_POST["item_id"] = $item_id;
$subscription = $SubscriptionClass->addSubscription($action);
Add paid subscription
$SubscriptionClass = new Subscription();
$_POST["item_id"] = $item_id;
$_POST["order_id"] = $order_id;
$subscription = $SubscriptionClass->addSubscription($action);
Dependencies
PHP
- count
- unset
Janitor
- Model::getPostedEntities
- Model::validateList
- Model::getProperty
- Subscription::getSubscriptions
- Subscription::updateSubscriptions
- Subscription::calculateSubscriptionExpiry
- Member::getMembership
- Items::getItem
- Items::typeObject
- Type#ItemType#::subscribed
- Shop::getOrders
- Query::sql
- Page::addLog
Subscription::getSubscriptions
Definition
- Name
- getSubscriptions
- Syntax
- Array|False = Subscription::getSubscriptions( [ Array $_options ] );
Description
Get subscriptions for current user.
Passing no parameters in $_options will return all the current user's subscriptions.
Parameters
- $_options
-
Array|false Optional parameters.
Options
Return values
Array|false One or several subscription objects. False on error.
Examples
Get all subscriptions for current user.
$SubscriptionClass = new Subscription();
$subscriptions = $SubscriptionClass->getSubscriptions();
Check if user has specific subscription.
$SubscriptionClass = new Subscription();
$subscription = $SubscriptionClass->getSubscriptions(["subscription_id"]);
Dependencies
Janitor
- Member::getMembership
- Query::sql
- Page::addLog
Subscription::updateSubscription
Definition
- Name
- updateSubscription
- Syntax
- Array|False = Subscription::updateSubscription( Array $action );
Description
Update subscription for current user.
/#controller#/updateSubscription/#subscription_id#
Parameters
- $action
-
Array Action array.
Action parameters
Parameters in $_POST
Return values
Array|false Subscription object. False on error.
Examples
Change subscription item – to free item (without price)
$SubscriptionClass = new Subscription();
$_POST["item_id"] = $item_id;
$subscription = $SubscriptionClass->updateSubscription(["updateSubscription", $subscription_id]);
This will create a callback to #ItemType#::subscribed
Change subscription item – to paid item
$SubscriptionClass = new Subscription();
$_POST["item_id"] = $item_id;
$_POST["order_id"] = $order_id;
$subscription = $SubscriptionClass->updateSubscription(["updateSubscription", $subscription_id]);
This will create a callback to #ItemType#::subscribed
Update expiry date
$SubscriptionClass = new Subscription();
$_POST["expires_at"] = "2020-03-02 00:00:00";
$subscription = $SubscriptionClass->updateSubscription(["updateSubscription", $subscription_id]);
Update order_id
$SubscriptionClass = new Subscription();
$_POST["order_id"] = $order_id;
$subscription = $SubscriptionClass->updateSubscription(["updateSubscription", $subscription_id]);
May be used if the order for the subscription were accidentally deleted.
Dependencies
PHP
- count
- unset
Janitor
- Model::getPostedEntities
- Model::validateList
- Model::getProperty
- Subscription::getSubscriptions
- Subscription::updateSubscriptions
- Subscription::calculateSubscriptionExpiry
- Member::getMembership
- Items::getItem
- Items::typeObject
- Type#ItemType#::subscribed
- Shop::getOrders
- Query::sql
- Page::addLog
Subscription::deleteSubscription
Definition
- Name
- deleteSubscription
- Syntax
- Boolean = Subscription::deleteSubscription( Array $action );
Description
Delete specified subscription for current user.
/#controller#/deleteSubscription/#subscription_id#
Parameters
- $action
-
Array Action array.
Action parameters
Return values
Boolean True on successful deletion. False on error.
Examples
$SubscriptionClass = new Subscription();
$result = $SubscriptionClass->deleteSubscription(["deleteSubscription", $subscription_id]);
Dependencies
PHP
- count
- method_exists
Janitor
- Session::value
- Query::sql
- Subscription::getSubscriptions
- Items::getItem
- Items::typeObject
- Type#ItemType#::unsubscribed
- Page::addLog
Subscription::calculateSubscriptionExpiry
Definition
- Name
- calculateSubscriptionExpiry
- Syntax
- String = Subscription::calculateSubscriptionExpiry( String $duration, [ String $start_time ] );
Description
Calculate expiry date for subscription.
Parameters
- $duration
-
String "annually", "monthly", or "weekly"
- $start_time
-
String Timestamp formatted as string. Optional – if not passed, current time will be used as start time.
Return values
String|false Formatted timestamp. False on error.
Examples
1a: Calculate expiry date for annual subscription, starting from current time.
$SubscriptionClass = new Subscription();
$expiry_date = $SubscriptionClass->calculateSubscriptionExpiry("annually");
1b: Calculate expiry date for annual subscription, starting from specified time.
$SubscriptionClass = new Subscription();
$start_time = "2018-06-06 00:00:00";
$expiry_date = $SubscriptionClass->calculateSubscriptionExpiry("annually", $start_time);
Dependencies
PHP
- strtotime
- time
- date
- mktime
Janitor
None