The SuperMember Class

Getting, creating and manipulating members.

Functions

SuperMember::addNewMembership

Definition

Name
addNewMembership
Syntax
Array|False = SuperMember::addNewMembership( Array $action );

Description

Add new membership to specified user.

Can be called via API, as opposed to SuperMember::addMembership.

/#controller#/addNewMembership/#user_id#

Parameters

$action
Array Action array.
Action parameters
$action[0]
"addNewMembership"
$action[1]
#user_id#
Parameters in $_POST
item_id
item_id for Membership item (Required)

Return values

Array|false Order object. False on error.

Examples

$MC = new SuperMember(); $_POST["item_id"] = $item_id; $order = $MC->addNewMembership($action);

Dependencies

PHP
  • count
  • unset
Janitor
  • Model::getPostedEntities
  • Model::validateList
  • Model::getProperty
  • User::getUser
  • SuperShop::addToNewInternalCart
  • SuperShop::newOrderFromCart

SuperMember::addMembership

Definition

Name
addMembership
Syntax
Array|False = SuperMember::addMembership( Integer $item_id, Integer $subscription_id, Array|false $_options );

Description

Add membership to specified user.

Meant for internal use, as opposed to SuperMember::addNewMembership.

Parameters

$item_id
Integer Id for membership item.
$subscription_id
Integer Id for subscription.
$_options
Array|false Options array
Options
user_id
Required

Return values

Array|false Membership object. False on error.

Examples

$MC = new SuperMember(); $membership = $MC->addMembership($item_id, subscription_id, ["user_id" => $user_id]);

Dependencies

Janitor
  • SuperSubscription::getSubscriptions
  • SuperMember::getMembers
  • SuperMember::updateMembership
  • Query::sql
  • Page::addLog

SuperMember::updateMembership

Definition

Name
updateMembership
Syntax
Array|False = SuperMember::updateMembership( Array $options = false );

Description

Update membership for specified user.

Parameters

$_options
Array|False Optional parameters.
Options
user_id
Required
subscription_id
To be used if reactivating an inactive membership

Return values

Array|false Membership object. False on non-existing membership. False on error.

Examples

Normal use:

$MC = new SuperMember(); $membership = $MC->updateMembership(["user_id" => $user_id]);

Reactivating an inactive (cancelled) membership:

$MC = new SuperMember(); $membership = $MC->updateMembership(["user_id" => $user_id, "subscription_id" => $subscription_id]);

Dependencies

Janitor
  • SuperSubscription::getSubscriptions
  • SuperMember::getMembers
  • Query::sql
  • Page::addLog
  • message()->addMessage()

SuperMember::cancelMembership

Definition

Name
cancelMembership
Syntax
Boolean = SuperMember::cancelMembership( Array $action );

Description

Cancel membership for specified user.

Removes subscription_id from membership and deletes related subscription. Sends a notification email to administrator.

/#controller#/cancelMembership/#user_id/#member_id#

Parameters

$action
Array Action array.
Action parameters
$action[0]
"cancelMembership"
$action[1]
#user_id#
$action[2]
#member_id#

Return values

Boolean True on successful cancellation. False on error.

Examples

$MC = new SuperMember(); $order = $MC->cancelMembership($action);

Dependencies

PHP
  • count
Janitor
  • SuperUser::getUsers
  • SuperMember::getMembers
  • SuperSubscription::deleteSubscription
  • Query::sql
  • Page::addLog
  • message()->addMessage()

SuperMember::upgradeMembership

Definition

Name
upgradeMembership
Syntax
Boolean = SuperMember::upgradeMembership( Array $action );

Description

Upgrade membership for specified user.

Adds new order with custom price (new_price - current_price). Gets existing membership order and copies info to new membership order, then adds manual order line.

/#controller#/upgradeMembership/#user_id#

Parameters

$action
Array Action array.
Action parameters
$action[0]
"upgradeMembership"
$action[1]
#user_id#
Parameters in $_POST
item_id
item_id for Membership item (Required)

Return values

Boolean True on successful upgrade. False on error.

Examples

$MC = new SuperMember(); $_POST["item_id"] = $item_id; $upgrade_success = $MC->upgradeMembership($action);

Dependencies

PHP
  • count
  • preg_match
Janitor
  • Model::getProperty
  • SuperUser::getUsers
  • SuperMember::getMembers
  • SuperShop::getPrice
  • SuperShop::getNewOrderNumber
  • SuperShop::getOrders
  • SuperSubscription::getSubscriptions
  • Subscription::calculateSubscriptionExpiry
  • Items::getItem
  • Items::typeObject
  • Query::sql
  • Query::result
  • Page::addLog

SuperMember::switchMembership

Definition

Name
switchMembership
Syntax
Array|False = SuperMember::switchMembership( Array $action );

Description

Switch membership for specified user.

/#controller#/switchMembership/#user_id#

Parameters

$action
Array Action array.
Action parameters
$action[0]
"switchMembership"
$action[1]
#user_id#
Parameters in $_POST
item_id
item_id for new Membership item (Required)

Return values

Array|false Order object. False on error.

Examples

$MC = new SuperMember(); $_POST["item_id"] = $item_id; $order = $MC->switchMembership($action);

Dependencies

PHP
  • count
Janitor
  • Model::getPostedEntities
  • Model::validateList
  • Model::getProperty
  • SuperUser::getUsers
  • SuperMember::getMembers
  • SuperShop::addToNewInternalCart
  • SuperShop::newOrderFromCart

SuperMember::getMemberCount

Definition

Name
getMemberCount
Syntax
Integer = SuperMember::getMemberCount( Array|false $_options );

Description

A shorthand function to get order count for UI.

Can return the total member count, or member count for a specific membership type.

Parameters

$_options
Array|false Options array
Options
item_id
Id for specific membership type

Return values

Integer Member count. Will return 0 on error.

Examples

Count all members.

$MC = new SuperMember(); $member_count = $MC->getMemberCount();

Count all members with specific membership type.

$MC = new SuperMember(); $member_count = $MC->getMemberCount(["item_id" => $membership_item_id]);

Dependencies

PHP
  • count
Janitor
  • Query::sql
  • Query::result

SuperMember::getMembers

Definition

Name
getMembers
Syntax
Array|False = SuperMember::getMembers( Array|false $_options );

Description

Get members (by user_id, member_id, item_id or all).

Passing no parameters in $_options will return all members, including cancelled members.

Parameters

$_options
Array|false Options array
Options
user_id
Get member object for user_id.
member_id
Get specific member object.
item_id
Get all members with specific membership.

Return values

Array|false One or several membership objects. False on error.

Examples

Get all members, including cancelled memberships.

$MC = new SuperMember(); $members = $MC->getMembers();

Get member object for user_id.

$MC = new SuperMember(); $member = $MC->getMembers(["user_id"] => $user_id);

Get specific member object.

$MC = new SuperMember(); $member = $MC->getMembers(["member_id" => $member_id]);

Get all members with specific membership.

$MC = new SuperMember(); $members = $MC->getMembers(["item_id"] => $membership_item_id);

Dependencies

Janitor
  • SuperUser::getUsers
  • Items::getItem
  • SuperShop::getOrders
  • Query::sql
  • Query::result