diff --git a/CRM/MembershipExtras/BAO/MembershipRate.php b/CRM/MembershipExtras/BAO/MembershipRate.php new file mode 100644 index 00000000..25c7f73a --- /dev/null +++ b/CRM/MembershipExtras/BAO/MembershipRate.php @@ -0,0 +1,27 @@ +copyValues($params); + $instance->save(); + CRM_Utils_Hook::post($hook, $entityName, $instance->id, $instance); + + return $instance; + } + +} diff --git a/CRM/MembershipExtras/BAO/MembershipRateMembershipType.php b/CRM/MembershipExtras/BAO/MembershipRateMembershipType.php new file mode 100644 index 00000000..2d8ab506 --- /dev/null +++ b/CRM/MembershipExtras/BAO/MembershipRateMembershipType.php @@ -0,0 +1,26 @@ +copyValues($params); + $instance->save(); + CRM_Utils_Hook::post($hook, $entityName, $instance->id, $instance); + + return $instance; + } + +} diff --git a/CRM/MembershipExtras/DAO/AutoMembershipUpgradeRule.php b/CRM/MembershipExtras/DAO/AutoMembershipUpgradeRule.php index 7d73c7f1..b32ef369 100644 --- a/CRM/MembershipExtras/DAO/AutoMembershipUpgradeRule.php +++ b/CRM/MembershipExtras/DAO/AutoMembershipUpgradeRule.php @@ -4,15 +4,18 @@ * @package CRM * @copyright CiviCRM LLC https://civicrm.org/licensing * - * Generated from /home/vagrant/buildkit/build/me4test6/web/sites/all/modules/civicrm/tools/extensions/uk.co.compucorp.membershipextras/xml/schema/CRM/MembershipExtras/AutoMembershipUpgradeRule.xml + * Generated from uk.co.compucorp.membershipextras/xml/schema/CRM/MembershipExtras/AutoMembershipUpgradeRule.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:1d9c07a1da7a8b6f08144088e9354390) + * (GenCodeChecksum:2074fbde3a3969945123affa03e1baed) */ +use CRM_MembershipExtras_ExtensionUtil as E; /** * Database access object for the AutoMembershipUpgradeRule entity. */ class CRM_MembershipExtras_DAO_AutoMembershipUpgradeRule extends CRM_Core_DAO { + const EXT = E::LONG_NAME; + const TABLE_ADDED = ''; /** * Static instance to hold the table name. @@ -29,63 +32,85 @@ class CRM_MembershipExtras_DAO_AutoMembershipUpgradeRule extends CRM_Core_DAO { public static $_log = FALSE; /** - * @var int + * @var int|string|null + * (SQL type: int unsigned) + * Note that values will be retrieved from the database as a string. */ public $id; /** * @var string + * (SQL type: varchar(255)) + * Note that values will be retrieved from the database as a string. */ public $name; /** * @var string + * (SQL type: varchar(255)) + * Note that values will be retrieved from the database as a string. */ public $label; /** * FK to civicrm_membership_type table * - * @var int + * @var int|string + * (SQL type: int unsigned) + * Note that values will be retrieved from the database as a string. */ public $from_membership_type_id; /** * FK to civicrm_membership_type table * - * @var int + * @var int|string + * (SQL type: int unsigned) + * Note that values will be retrieved from the database as a string. */ public $to_membership_type_id; /** - * @var int + * @var int|string + * (SQL type: int unsigned) + * Note that values will be retrieved from the database as a string. */ public $upgrade_trigger_date_type; /** - * @var int + * @var int|string + * (SQL type: int unsigned) + * Note that values will be retrieved from the database as a string. */ public $period_length; /** - * @var int + * @var int|string + * (SQL type: int unsigned) + * Note that values will be retrieved from the database as a string. */ public $period_length_unit; /** * FK to civicrm_group table * - * @var int + * @var int|string|null + * (SQL type: int unsigned) + * Note that values will be retrieved from the database as a string. */ public $filter_group; /** - * @var int + * @var int|string + * (SQL type: int unsigned) + * Note that values will be retrieved from the database as a string. */ public $weight; /** - * @var bool + * @var bool|string|null + * (SQL type: tinyint) + * Note that values will be retrieved from the database as a string. */ public $is_active; @@ -99,9 +124,12 @@ public function __construct() { /** * Returns localized title of this entity. + * + * @param bool $plural + * Whether to return the plural version of the title. */ - public static function getEntityTitle() { - return ts('Auto Membership Upgrade Rules'); + public static function getEntityTitle($plural = FALSE) { + return $plural ? E::ts('Auto Membership Upgrade Rules') : E::ts('Auto Membership Upgrade Rule'); } /** @@ -132,19 +160,20 @@ public static function &fields() { 'id' => [ 'name' => 'id', 'type' => CRM_Utils_Type::T_INT, - 'title' => CRM_MembershipExtras_ExtensionUtil::ts('Id'), + 'title' => E::ts('Id'), 'required' => TRUE, 'where' => 'membershipextras_auto_membership_upgrade_rule.id', 'table_name' => 'membershipextras_auto_membership_upgrade_rule', 'entity' => 'AutoMembershipUpgradeRule', 'bao' => 'CRM_MembershipExtras_DAO_AutoMembershipUpgradeRule', 'localizable' => 0, + 'readonly' => TRUE, 'add' => NULL, ], 'name' => [ 'name' => 'name', 'type' => CRM_Utils_Type::T_STRING, - 'title' => CRM_MembershipExtras_ExtensionUtil::ts('Name'), + 'title' => E::ts('Name'), 'required' => 1, 'maxlength' => 255, 'size' => CRM_Utils_Type::HUGE, @@ -158,7 +187,7 @@ public static function &fields() { 'label' => [ 'name' => 'label', 'type' => CRM_Utils_Type::T_STRING, - 'title' => CRM_MembershipExtras_ExtensionUtil::ts('Label'), + 'title' => E::ts('Label'), 'required' => 1, 'maxlength' => 255, 'size' => CRM_Utils_Type::HUGE, @@ -172,7 +201,7 @@ public static function &fields() { 'from_membership_type_id' => [ 'name' => 'from_membership_type_id', 'type' => CRM_Utils_Type::T_INT, - 'description' => CRM_MembershipExtras_ExtensionUtil::ts('FK to civicrm_membership_type table'), + 'description' => E::ts('FK to civicrm_membership_type table'), 'required' => 1, 'where' => 'membershipextras_auto_membership_upgrade_rule.from_membership_type_id', 'table_name' => 'membershipextras_auto_membership_upgrade_rule', @@ -185,7 +214,7 @@ public static function &fields() { 'to_membership_type_id' => [ 'name' => 'to_membership_type_id', 'type' => CRM_Utils_Type::T_INT, - 'description' => CRM_MembershipExtras_ExtensionUtil::ts('FK to civicrm_membership_type table'), + 'description' => E::ts('FK to civicrm_membership_type table'), 'required' => 1, 'where' => 'membershipextras_auto_membership_upgrade_rule.to_membership_type_id', 'table_name' => 'membershipextras_auto_membership_upgrade_rule', @@ -198,7 +227,7 @@ public static function &fields() { 'upgrade_trigger_date_type' => [ 'name' => 'upgrade_trigger_date_type', 'type' => CRM_Utils_Type::T_INT, - 'title' => CRM_MembershipExtras_ExtensionUtil::ts('Upgrade Trigger Date Type'), + 'title' => E::ts('Upgrade Trigger Date Type'), 'required' => 1, 'where' => 'membershipextras_auto_membership_upgrade_rule.upgrade_trigger_date_type', 'default' => '1', @@ -214,7 +243,7 @@ public static function &fields() { 'period_length' => [ 'name' => 'period_length', 'type' => CRM_Utils_Type::T_INT, - 'title' => CRM_MembershipExtras_ExtensionUtil::ts('Period Length'), + 'title' => E::ts('Period Length'), 'required' => 1, 'where' => 'membershipextras_auto_membership_upgrade_rule.period_length', 'default' => '1', @@ -227,7 +256,7 @@ public static function &fields() { 'period_length_unit' => [ 'name' => 'period_length_unit', 'type' => CRM_Utils_Type::T_INT, - 'title' => CRM_MembershipExtras_ExtensionUtil::ts('Period Length Unit'), + 'title' => E::ts('Period Length Unit'), 'required' => 1, 'where' => 'membershipextras_auto_membership_upgrade_rule.period_length_unit', 'default' => '1', @@ -243,8 +272,8 @@ public static function &fields() { 'filter_group' => [ 'name' => 'filter_group', 'type' => CRM_Utils_Type::T_INT, - 'title' => CRM_MembershipExtras_ExtensionUtil::ts('Filter Group'), - 'description' => CRM_MembershipExtras_ExtensionUtil::ts('FK to civicrm_group table'), + 'title' => E::ts('Filter Group'), + 'description' => E::ts('FK to civicrm_group table'), 'where' => 'membershipextras_auto_membership_upgrade_rule.filter_group', 'table_name' => 'membershipextras_auto_membership_upgrade_rule', 'entity' => 'AutoMembershipUpgradeRule', @@ -256,7 +285,7 @@ public static function &fields() { 'weight' => [ 'name' => 'weight', 'type' => CRM_Utils_Type::T_INT, - 'title' => CRM_MembershipExtras_ExtensionUtil::ts('Weight'), + 'title' => E::ts('Weight'), 'required' => 1, 'where' => 'membershipextras_auto_membership_upgrade_rule.weight', 'table_name' => 'membershipextras_auto_membership_upgrade_rule', diff --git a/CRM/MembershipExtras/DAO/ContributionRecurLineItem.php b/CRM/MembershipExtras/DAO/ContributionRecurLineItem.php index 074f6b59..4279f75e 100644 --- a/CRM/MembershipExtras/DAO/ContributionRecurLineItem.php +++ b/CRM/MembershipExtras/DAO/ContributionRecurLineItem.php @@ -4,15 +4,18 @@ * @package CRM * @copyright CiviCRM LLC https://civicrm.org/licensing * - * Generated from /home/vagrant/buildkit/build/me4test6/web/sites/all/modules/civicrm/tools/extensions/uk.co.compucorp.membershipextras/xml/schema/CRM/MembershipExtras/ContributionRecurLineItem.xml + * Generated from uk.co.compucorp.membershipextras/xml/schema/CRM/MembershipExtras/ContributionRecurLineItem.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:3c73385f5c295f0f4cfa7763ab39e986) + * (GenCodeChecksum:8a1cee1646df3534b1ae802f4d2b4c6b) */ +use CRM_MembershipExtras_ExtensionUtil as E; /** * Database access object for the ContributionRecurLineItem entity. */ class CRM_MembershipExtras_DAO_ContributionRecurLineItem extends CRM_Core_DAO { + const EXT = E::LONG_NAME; + const TABLE_ADDED = '5.0'; /** * Static instance to hold the table name. @@ -31,49 +34,63 @@ class CRM_MembershipExtras_DAO_ContributionRecurLineItem extends CRM_Core_DAO { /** * Discount Item ID * - * @var int + * @var int|string|null + * (SQL type: int unsigned) + * Note that values will be retrieved from the database as a string. */ public $id; /** * ID of the recurring contribution. * - * @var int + * @var int|string + * (SQL type: int unsigned) + * Note that values will be retrieved from the database as a string. */ public $contribution_recur_id; /** * ID of the line item related to the recurring contribution. * - * @var int + * @var int|string + * (SQL type: int unsigned) + * Note that values will be retrieved from the database as a string. */ public $line_item_id; /** * Start date of the period for the membership/recurring contribution. * - * @var datetime + * @var string + * (SQL type: datetime) + * Note that values will be retrieved from the database as a string. */ public $start_date; /** * End date of the period for the membership/recurring contribution. * - * @var datetime + * @var string + * (SQL type: datetime) + * Note that values will be retrieved from the database as a string. */ public $end_date; /** * If the line-item should be auto-renewed or not. * - * @var bool + * @var bool|string + * (SQL type: tinyint) + * Note that values will be retrieved from the database as a string. */ public $auto_renew; /** * If the line-item has been marked as removed or not. * - * @var bool + * @var bool|string + * (SQL type: tinyint) + * Note that values will be retrieved from the database as a string. */ public $is_removed; @@ -87,9 +104,12 @@ public function __construct() { /** * Returns localized title of this entity. + * + * @param bool $plural + * Whether to return the plural version of the title. */ - public static function getEntityTitle() { - return ts('Contribution Recur Line Items'); + public static function getEntityTitle($plural = FALSE) { + return $plural ? E::ts('Contribution Recur Line Items') : E::ts('Contribution Recur Line Item'); } /** @@ -119,19 +139,20 @@ public static function &fields() { 'id' => [ 'name' => 'id', 'type' => CRM_Utils_Type::T_INT, - 'description' => CRM_MembershipExtras_ExtensionUtil::ts('Discount Item ID'), + 'description' => E::ts('Discount Item ID'), 'required' => TRUE, 'where' => 'membershipextras_subscription_line.id', 'table_name' => 'membershipextras_subscription_line', 'entity' => 'ContributionRecurLineItem', 'bao' => 'CRM_MembershipExtras_DAO_ContributionRecurLineItem', 'localizable' => 0, + 'readonly' => TRUE, 'add' => '5.0', ], 'contribution_recur_id' => [ 'name' => 'contribution_recur_id', 'type' => CRM_Utils_Type::T_INT, - 'description' => CRM_MembershipExtras_ExtensionUtil::ts('ID of the recurring contribution.'), + 'description' => E::ts('ID of the recurring contribution.'), 'required' => TRUE, 'where' => 'membershipextras_subscription_line.contribution_recur_id', 'table_name' => 'membershipextras_subscription_line', @@ -144,7 +165,7 @@ public static function &fields() { 'line_item_id' => [ 'name' => 'line_item_id', 'type' => CRM_Utils_Type::T_INT, - 'description' => CRM_MembershipExtras_ExtensionUtil::ts('ID of the line item related to the recurring contribution.'), + 'description' => E::ts('ID of the line item related to the recurring contribution.'), 'required' => TRUE, 'where' => 'membershipextras_subscription_line.line_item_id', 'table_name' => 'membershipextras_subscription_line', @@ -157,8 +178,8 @@ public static function &fields() { 'start_date' => [ 'name' => 'start_date', 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME, - 'title' => CRM_MembershipExtras_ExtensionUtil::ts('Start Date'), - 'description' => CRM_MembershipExtras_ExtensionUtil::ts('Start date of the period for the membership/recurring contribution.'), + 'title' => E::ts('Start Date'), + 'description' => E::ts('Start date of the period for the membership/recurring contribution.'), 'required' => FALSE, 'where' => 'membershipextras_subscription_line.start_date', 'table_name' => 'membershipextras_subscription_line', @@ -170,8 +191,8 @@ public static function &fields() { 'end_date' => [ 'name' => 'end_date', 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME, - 'title' => CRM_MembershipExtras_ExtensionUtil::ts('End Date'), - 'description' => CRM_MembershipExtras_ExtensionUtil::ts('End date of the period for the membership/recurring contribution.'), + 'title' => E::ts('End Date'), + 'description' => E::ts('End date of the period for the membership/recurring contribution.'), 'required' => FALSE, 'where' => 'membershipextras_subscription_line.end_date', 'table_name' => 'membershipextras_subscription_line', @@ -183,8 +204,8 @@ public static function &fields() { 'auto_renew' => [ 'name' => 'auto_renew', 'type' => CRM_Utils_Type::T_BOOLEAN, - 'title' => CRM_MembershipExtras_ExtensionUtil::ts('Auto Renew'), - 'description' => CRM_MembershipExtras_ExtensionUtil::ts('If the line-item should be auto-renewed or not.'), + 'title' => E::ts('Auto Renew'), + 'description' => E::ts('If the line-item should be auto-renewed or not.'), 'required' => TRUE, 'where' => 'membershipextras_subscription_line.auto_renew', 'default' => 'false', @@ -197,7 +218,7 @@ public static function &fields() { 'is_removed' => [ 'name' => 'is_removed', 'type' => CRM_Utils_Type::T_BOOLEAN, - 'description' => CRM_MembershipExtras_ExtensionUtil::ts('If the line-item has been marked as removed or not.'), + 'description' => E::ts('If the line-item has been marked as removed or not.'), 'required' => TRUE, 'where' => 'membershipextras_subscription_line.is_removed', 'default' => 'false', diff --git a/CRM/MembershipExtras/DAO/MembershipRate.php b/CRM/MembershipExtras/DAO/MembershipRate.php new file mode 100644 index 00000000..8bf121ef --- /dev/null +++ b/CRM/MembershipExtras/DAO/MembershipRate.php @@ -0,0 +1,336 @@ + 'civicrm/member/membership-rate/new?reset=1&id=[id]&action=update', + 'delete' => 'civicrm/member/membership-rate/delete?reset=1&id=[id]', + ]; + + /** + * Unique MembershipRate ID + * + * @var int|string|null + * (SQL type: int unsigned) + * Note that values will be retrieved from the database as a string. + */ + public $id; + + /** + * Rate Label + * + * @var string + * (SQL type: varchar(255)) + * Note that values will be retrieved from the database as a string. + */ + public $label; + + /** + * Min Range Value + * + * @var float|string + * (SQL type: decimal(20,2)) + * Note that values will be retrieved from the database as a string. + */ + public $min_range; + + /** + * Max Range Value + * + * @var float|string + * (SQL type: decimal(20,2)) + * Note that values will be retrieved from the database as a string. + */ + public $max_range; + + /** + * Subscription Multiplier + * + * @var float|string + * (SQL type: decimal(20,2)) + * Note that values will be retrieved from the database as a string. + */ + public $multiplier; + + /** + * Min Subscription Rate + * + * @var float|string + * (SQL type: decimal(20,2)) + * Note that values will be retrieved from the database as a string. + */ + public $min_subscription_rate; + + /** + * Sort Order + * + * @var int|string + * (SQL type: int unsigned) + * Note that values will be retrieved from the database as a string. + */ + public $sort_order; + + /** + * Class constructor. + */ + public function __construct() { + $this->__table = 'membershipextras_membership_rate'; + parent::__construct(); + } + + /** + * Returns localized title of this entity. + * + * @param bool $plural + * Whether to return the plural version of the title. + */ + public static function getEntityTitle($plural = FALSE) { + return $plural ? E::ts('Membership Rates') : E::ts('Membership Rate'); + } + + /** + * Returns all the column names of this table + * + * @return array + */ + public static function &fields() { + if (!isset(Civi::$statics[__CLASS__]['fields'])) { + Civi::$statics[__CLASS__]['fields'] = [ + 'id' => [ + 'name' => 'id', + 'type' => CRM_Utils_Type::T_INT, + 'description' => E::ts('Unique MembershipRate ID'), + 'required' => TRUE, + 'where' => 'membershipextras_membership_rate.id', + 'table_name' => 'membershipextras_membership_rate', + 'entity' => 'MembershipRate', + 'bao' => 'CRM_MembershipExtras_DAO_MembershipRate', + 'localizable' => 0, + 'html' => [ + 'type' => 'Number', + ], + 'readonly' => TRUE, + 'add' => NULL, + ], + 'label' => [ + 'name' => 'label', + 'type' => CRM_Utils_Type::T_STRING, + 'title' => E::ts('Label'), + 'description' => E::ts('Rate Label'), + 'required' => FALSE, + 'maxlength' => 255, + 'size' => CRM_Utils_Type::HUGE, + 'where' => 'membershipextras_membership_rate.label', + 'table_name' => 'membershipextras_membership_rate', + 'entity' => 'MembershipRate', + 'bao' => 'CRM_MembershipExtras_DAO_MembershipRate', + 'localizable' => 0, + 'html' => [ + 'type' => 'Text', + ], + 'add' => NULL, + ], + 'min_range' => [ + 'name' => 'min_range', + 'type' => CRM_Utils_Type::T_MONEY, + 'title' => E::ts('Min Range'), + 'description' => E::ts('Min Range Value'), + 'required' => FALSE, + 'precision' => [ + 20, + 2, + ], + 'where' => 'membershipextras_membership_rate.min_range', + 'table_name' => 'membershipextras_membership_rate', + 'entity' => 'MembershipRate', + 'bao' => 'CRM_MembershipExtras_DAO_MembershipRate', + 'localizable' => 0, + 'html' => [ + 'type' => 'Text', + ], + 'add' => NULL, + ], + 'max_range' => [ + 'name' => 'max_range', + 'type' => CRM_Utils_Type::T_MONEY, + 'title' => E::ts('Max Range'), + 'description' => E::ts('Max Range Value'), + 'required' => FALSE, + 'precision' => [ + 20, + 2, + ], + 'where' => 'membershipextras_membership_rate.max_range', + 'table_name' => 'membershipextras_membership_rate', + 'entity' => 'MembershipRate', + 'bao' => 'CRM_MembershipExtras_DAO_MembershipRate', + 'localizable' => 0, + 'html' => [ + 'type' => 'Text', + ], + 'add' => NULL, + ], + 'multiplier' => [ + 'name' => 'multiplier', + 'type' => CRM_Utils_Type::T_MONEY, + 'title' => E::ts('Multiplier'), + 'description' => E::ts('Subscription Multiplier'), + 'required' => FALSE, + 'precision' => [ + 20, + 2, + ], + 'where' => 'membershipextras_membership_rate.multiplier', + 'table_name' => 'membershipextras_membership_rate', + 'entity' => 'MembershipRate', + 'bao' => 'CRM_MembershipExtras_DAO_MembershipRate', + 'localizable' => 0, + 'html' => [ + 'type' => 'Text', + ], + 'add' => NULL, + ], + 'min_subscription_rate' => [ + 'name' => 'min_subscription_rate', + 'type' => CRM_Utils_Type::T_MONEY, + 'title' => E::ts('Min Subscription Rate'), + 'description' => E::ts('Min Subscription Rate'), + 'required' => FALSE, + 'precision' => [ + 20, + 2, + ], + 'where' => 'membershipextras_membership_rate.min_subscription_rate', + 'table_name' => 'membershipextras_membership_rate', + 'entity' => 'MembershipRate', + 'bao' => 'CRM_MembershipExtras_DAO_MembershipRate', + 'localizable' => 0, + 'html' => [ + 'type' => 'Text', + ], + 'add' => NULL, + ], + 'sort_order' => [ + 'name' => 'sort_order', + 'type' => CRM_Utils_Type::T_INT, + 'title' => E::ts('Sort Order'), + 'description' => E::ts('Sort Order'), + 'required' => TRUE, + 'where' => 'membershipextras_membership_rate.sort_order', + 'table_name' => 'membershipextras_membership_rate', + 'entity' => 'MembershipRate', + 'bao' => 'CRM_MembershipExtras_DAO_MembershipRate', + 'localizable' => 0, + 'html' => [ + 'type' => 'Number', + ], + 'add' => NULL, + ], + ]; + CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']); + } + return Civi::$statics[__CLASS__]['fields']; + } + + /** + * Return a mapping from field-name to the corresponding key (as used in fields()). + * + * @return array + * Array(string $name => string $uniqueName). + */ + public static function &fieldKeys() { + if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) { + Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields())); + } + return Civi::$statics[__CLASS__]['fieldKeys']; + } + + /** + * Returns the names of this table + * + * @return string + */ + public static function getTableName() { + return self::$_tableName; + } + + /** + * Returns if this table needs to be logged + * + * @return bool + */ + public function getLog() { + return self::$_log; + } + + /** + * Returns the list of fields that can be imported + * + * @param bool $prefix + * + * @return array + */ + public static function &import($prefix = FALSE) { + $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'ipextras_membership_rate', $prefix, []); + return $r; + } + + /** + * Returns the list of fields that can be exported + * + * @param bool $prefix + * + * @return array + */ + public static function &export($prefix = FALSE) { + $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'ipextras_membership_rate', $prefix, []); + return $r; + } + + /** + * Returns the list of indices + * + * @param bool $localize + * + * @return array + */ + public static function indices($localize = TRUE) { + $indices = []; + return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices; + } + +} diff --git a/CRM/MembershipExtras/DAO/MembershipRateMembershipType.php b/CRM/MembershipExtras/DAO/MembershipRateMembershipType.php new file mode 100644 index 00000000..df6be342 --- /dev/null +++ b/CRM/MembershipExtras/DAO/MembershipRateMembershipType.php @@ -0,0 +1,216 @@ +__table = 'membershipextras_membership_rate_membership_type'; + parent::__construct(); + } + + /** + * Returns localized title of this entity. + * + * @param bool $plural + * Whether to return the plural version of the title. + */ + public static function getEntityTitle($plural = FALSE) { + return $plural ? E::ts('Membership Rate Membership Types') : E::ts('Membership Rate Membership Type'); + } + + /** + * Returns foreign keys and entity references. + * + * @return array + * [CRM_Core_Reference_Interface] + */ + public static function getReferenceColumns() { + if (!isset(Civi::$statics[__CLASS__]['links'])) { + Civi::$statics[__CLASS__]['links'] = static::createReferenceColumns(__CLASS__); + Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'membership_rate_id', 'membershipextras_membership_rate', 'id'); + Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'membership_type_id', 'civicrm_membership_type', 'id'); + CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']); + } + return Civi::$statics[__CLASS__]['links']; + } + + /** + * Returns all the column names of this table + * + * @return array + */ + public static function &fields() { + if (!isset(Civi::$statics[__CLASS__]['fields'])) { + Civi::$statics[__CLASS__]['fields'] = [ + 'id' => [ + 'name' => 'id', + 'type' => CRM_Utils_Type::T_INT, + 'description' => E::ts('Unique MembershipRateMembershipType ID'), + 'required' => TRUE, + 'where' => 'membershipextras_membership_rate_membership_type.id', + 'table_name' => 'membershipextras_membership_rate_membership_type', + 'entity' => 'MembershipRateMembershipType', + 'bao' => 'CRM_MembershipExtras_DAO_MembershipRateMembershipType', + 'localizable' => 0, + 'html' => [ + 'type' => 'Number', + ], + 'readonly' => TRUE, + 'add' => NULL, + ], + 'membership_rate_id' => [ + 'name' => 'membership_rate_id', + 'type' => CRM_Utils_Type::T_INT, + 'description' => E::ts('FK to MembershipRate'), + 'where' => 'membershipextras_membership_rate_membership_type.membership_rate_id', + 'table_name' => 'membershipextras_membership_rate_membership_type', + 'entity' => 'MembershipRateMembershipType', + 'bao' => 'CRM_MembershipExtras_DAO_MembershipRateMembershipType', + 'localizable' => 0, + 'FKClassName' => 'CRM_MembershipExtras_DAO_MembershipRate', + 'add' => NULL, + ], + 'membership_type_id' => [ + 'name' => 'membership_type_id', + 'type' => CRM_Utils_Type::T_INT, + 'description' => E::ts('FK to MembershipType'), + 'where' => 'membershipextras_membership_rate_membership_type.membership_type_id', + 'table_name' => 'membershipextras_membership_rate_membership_type', + 'entity' => 'MembershipRateMembershipType', + 'bao' => 'CRM_MembershipExtras_DAO_MembershipRateMembershipType', + 'localizable' => 0, + 'FKClassName' => 'CRM_Member_DAO_MembershipType', + 'add' => NULL, + ], + ]; + CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']); + } + return Civi::$statics[__CLASS__]['fields']; + } + + /** + * Return a mapping from field-name to the corresponding key (as used in fields()). + * + * @return array + * Array(string $name => string $uniqueName). + */ + public static function &fieldKeys() { + if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) { + Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields())); + } + return Civi::$statics[__CLASS__]['fieldKeys']; + } + + /** + * Returns the names of this table + * + * @return string + */ + public static function getTableName() { + return self::$_tableName; + } + + /** + * Returns if this table needs to be logged + * + * @return bool + */ + public function getLog() { + return self::$_log; + } + + /** + * Returns the list of fields that can be imported + * + * @param bool $prefix + * + * @return array + */ + public static function &import($prefix = FALSE) { + $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'ipextras_membership_rate_membership_type', $prefix, []); + return $r; + } + + /** + * Returns the list of fields that can be exported + * + * @param bool $prefix + * + * @return array + */ + public static function &export($prefix = FALSE) { + $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'ipextras_membership_rate_membership_type', $prefix, []); + return $r; + } + + /** + * Returns the list of indices + * + * @param bool $localize + * + * @return array + */ + public static function indices($localize = TRUE) { + $indices = []; + return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices; + } + +} diff --git a/CRM/MembershipExtras/Upgrader/Steps/Step0010.php b/CRM/MembershipExtras/Upgrader/Steps/Step0010.php new file mode 100644 index 00000000..d0d72f4b --- /dev/null +++ b/CRM/MembershipExtras/Upgrader/Steps/Step0010.php @@ -0,0 +1,11 @@ +executeSqlFile('sql/membershipratetable_install.sql'); + + return TRUE; + } + +} diff --git a/Civi/Api4/MembershipRate.php b/Civi/Api4/MembershipRate.php new file mode 100644 index 00000000..6732e3d5 --- /dev/null +++ b/Civi/Api4/MembershipRate.php @@ -0,0 +1,13 @@ + CRM/MembershipExtras + 22.05.2 https://github.com/compucorp/uk.co.compucorp.membershipextras/blob/master/readme.md + + menu-xml@1.0.0 + setting-php@1.0.0 + diff --git a/membershipextras.civix.php b/membershipextras.civix.php index f9eef936..10866ce0 100644 --- a/membershipextras.civix.php +++ b/membershipextras.civix.php @@ -91,9 +91,9 @@ function _membershipextras_civix_civicrm_config(&$config = NULL) { } $configured = TRUE; - $template =& CRM_Core_Smarty::singleton(); + $template = CRM_Core_Smarty::singleton(); - $extRoot = dirname(__FILE__) . DIRECTORY_SEPARATOR; + $extRoot = __DIR__ . DIRECTORY_SEPARATOR; $extDir = $extRoot . 'templates'; if (is_array($template->template_dir)) { @@ -107,19 +107,6 @@ function _membershipextras_civix_civicrm_config(&$config = NULL) { set_include_path($include_path); } -/** - * (Delegated) Implements hook_civicrm_xmlMenu(). - * - * @param $files array(string) - * - * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_xmlMenu - */ -function _membershipextras_civix_civicrm_xmlMenu(&$files) { - foreach (_membershipextras_civix_glob(__DIR__ . '/xml/Menu/*.xml') as $file) { - $files[] = $file; - } -} - /** * Implements hook_civicrm_install(). * @@ -217,160 +204,6 @@ function _membershipextras_civix_upgrader() { } } -/** - * Search directory tree for files which match a glob pattern. - * - * Note: Dot-directories (like "..", ".git", or ".svn") will be ignored. - * Note: In Civi 4.3+, delegate to CRM_Utils_File::findFiles() - * - * @param string $dir base dir - * @param string $pattern , glob pattern, eg "*.txt" - * - * @return array - */ -function _membershipextras_civix_find_files($dir, $pattern) { - if (is_callable(['CRM_Utils_File', 'findFiles'])) { - return CRM_Utils_File::findFiles($dir, $pattern); - } - - $todos = [$dir]; - $result = []; - while (!empty($todos)) { - $subdir = array_shift($todos); - foreach (_membershipextras_civix_glob("$subdir/$pattern") as $match) { - if (!is_dir($match)) { - $result[] = $match; - } - } - if ($dh = opendir($subdir)) { - while (FALSE !== ($entry = readdir($dh))) { - $path = $subdir . DIRECTORY_SEPARATOR . $entry; - if ($entry[0] == '.') { - } - elseif (is_dir($path)) { - $todos[] = $path; - } - } - closedir($dh); - } - } - return $result; -} - -/** - * (Delegated) Implements hook_civicrm_managed(). - * - * Find any *.mgd.php files, merge their content, and return. - * - * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_managed - */ -function _membershipextras_civix_civicrm_managed(&$entities) { - $mgdFiles = _membershipextras_civix_find_files(__DIR__, '*.mgd.php'); - sort($mgdFiles); - foreach ($mgdFiles as $file) { - $es = include $file; - foreach ($es as $e) { - if (empty($e['module'])) { - $e['module'] = E::LONG_NAME; - } - if (empty($e['params']['version'])) { - $e['params']['version'] = '3'; - } - $entities[] = $e; - } - } -} - -/** - * (Delegated) Implements hook_civicrm_caseTypes(). - * - * Find any and return any files matching "xml/case/*.xml" - * - * Note: This hook only runs in CiviCRM 4.4+. - * - * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_caseTypes - */ -function _membershipextras_civix_civicrm_caseTypes(&$caseTypes) { - if (!is_dir(__DIR__ . '/xml/case')) { - return; - } - - foreach (_membershipextras_civix_glob(__DIR__ . '/xml/case/*.xml') as $file) { - $name = preg_replace('/\.xml$/', '', basename($file)); - if ($name != CRM_Case_XMLProcessor::mungeCaseType($name)) { - $errorMessage = sprintf("Case-type file name is malformed (%s vs %s)", $name, CRM_Case_XMLProcessor::mungeCaseType($name)); - throw new CRM_Core_Exception($errorMessage); - } - $caseTypes[$name] = [ - 'module' => E::LONG_NAME, - 'name' => $name, - 'file' => $file, - ]; - } -} - -/** - * (Delegated) Implements hook_civicrm_angularModules(). - * - * Find any and return any files matching "ang/*.ang.php" - * - * Note: This hook only runs in CiviCRM 4.5+. - * - * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_angularModules - */ -function _membershipextras_civix_civicrm_angularModules(&$angularModules) { - if (!is_dir(__DIR__ . '/ang')) { - return; - } - - $files = _membershipextras_civix_glob(__DIR__ . '/ang/*.ang.php'); - foreach ($files as $file) { - $name = preg_replace(':\.ang\.php$:', '', basename($file)); - $module = include $file; - if (empty($module['ext'])) { - $module['ext'] = E::LONG_NAME; - } - $angularModules[$name] = $module; - } -} - -/** - * (Delegated) Implements hook_civicrm_themes(). - * - * Find any and return any files matching "*.theme.php" - */ -function _membershipextras_civix_civicrm_themes(&$themes) { - $files = _membershipextras_civix_glob(__DIR__ . '/*.theme.php'); - foreach ($files as $file) { - $themeMeta = include $file; - if (empty($themeMeta['name'])) { - $themeMeta['name'] = preg_replace(':\.theme\.php$:', '', basename($file)); - } - if (empty($themeMeta['ext'])) { - $themeMeta['ext'] = E::LONG_NAME; - } - $themes[$themeMeta['name']] = $themeMeta; - } -} - -/** - * Glob wrapper which is guaranteed to return an array. - * - * The documentation for glob() says, "On some systems it is impossible to - * distinguish between empty match and an error." Anecdotally, the return - * result for an empty match is sometimes array() and sometimes FALSE. - * This wrapper provides consistency. - * - * @link http://php.net/glob - * @param string $pattern - * - * @return array - */ -function _membershipextras_civix_glob($pattern) { - $result = glob($pattern); - return is_array($result) ? $result : []; -} - /** * Inserts a navigation menu item at a given place in the hierarchy. * @@ -453,18 +286,6 @@ function _membershipextras_civix_fixNavigationMenuItems(&$nodes, &$maxNavID, $pa } } -/** - * (Delegated) Implements hook_civicrm_alterSettingsFolders(). - * - * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_alterSettingsFolders - */ -function _membershipextras_civix_civicrm_alterSettingsFolders(&$metaDataFolders = NULL) { - $settingsDir = __DIR__ . DIRECTORY_SEPARATOR . 'settings'; - if (!in_array($settingsDir, $metaDataFolders) && is_dir($settingsDir)) { - $metaDataFolders[] = $settingsDir; - } -} - /** * (Delegated) Implements hook_civicrm_entityTypes(). * @@ -484,5 +305,15 @@ function _membershipextras_civix_civicrm_entityTypes(&$entityTypes) { 'class' => 'CRM_MembershipExtras_DAO_ContributionRecurLineItem', 'table' => 'membershipextras_subscription_line', ], + 'CRM_MembershipExtras_DAO_MembershipRate' => [ + 'name' => 'MembershipRate', + 'class' => 'CRM_MembershipExtras_DAO_MembershipRate', + 'table' => 'civicrm_membership_rate', + ], + 'CRM_MembershipExtras_DAO_MembershipRateMembershipType' => [ + 'name' => 'MembershipRateMembershipType', + 'class' => 'CRM_MembershipExtras_DAO_MembershipRateMembershipType', + 'table' => 'civicrm_membership_rate_membership_type', + ], ]); } diff --git a/membershipextras.php b/membershipextras.php index ce49838f..76f0cd42 100755 --- a/membershipextras.php +++ b/membershipextras.php @@ -13,15 +13,6 @@ function membershipextras_civicrm_config(&$config) { _membershipextras_civix_civicrm_config($config); } -/** - * Implements hook_civicrm_xmlMenu(). - * - * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_xmlMenu - */ -function membershipextras_civicrm_xmlMenu(&$files) { - _membershipextras_civix_civicrm_xmlMenu($files); -} - /** * Implements hook_civicrm_install(). * @@ -76,54 +67,6 @@ function membershipextras_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) { return _membershipextras_civix_civicrm_upgrade($op, $queue); } -/** - * Implements hook_civicrm_managed(). - * - * Generate a list of entities to create/deactivate/delete when this module - * is installed, disabled, uninstalled. - * - * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_managed - */ -function membershipextras_civicrm_managed(&$entities) { - _membershipextras_civix_civicrm_managed($entities); -} - -/** - * Implements hook_civicrm_caseTypes(). - * - * Generate a list of case-types. - * - * Note: This hook only runs in CiviCRM 4.4+. - * - * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_caseTypes - */ -function membershipextras_civicrm_caseTypes(&$caseTypes) { - _membershipextras_civix_civicrm_caseTypes($caseTypes); -} - -/** - * Implements hook_civicrm_angularModules(). - * - * Generate a list of Angular modules. - * - * Note: This hook only runs in CiviCRM 4.5+. It may - * use features only available in v4.6+. - * - * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_angularModules - */ -function membershipextras_civicrm_angularModules(&$angularModules) { - _membershipextras_civix_civicrm_angularModules($angularModules); -} - -/** - * Implements hook_civicrm_alterSettingsFolders(). - * - * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_alterSettingsFolders - */ -function membershipextras_civicrm_alterSettingsFolders(&$metaDataFolders = NULL) { - _membershipextras_civix_civicrm_alterSettingsFolders($metaDataFolders); -} - /** * Implements hook_civicrm_navigationMenu(). * diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 3567b894..22be2811 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -8,7 +8,6 @@ convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" - syntaxCheck="false" bootstrap="tests/phpunit/bootstrap.php" > diff --git a/sql/auto_uninstall.sql b/sql/auto_uninstall.sql index 1aefb762..d209ddef 100644 --- a/sql/auto_uninstall.sql +++ b/sql/auto_uninstall.sql @@ -17,4 +17,7 @@ DROP TABLE IF EXISTS `membershipextras_subscription_line`; -- *******************************************************/ DROP TABLE IF EXISTS `membershipextras_auto_membership_upgrade_rule`; +DROP TABLE IF EXISTS `membershipextras_membership_rate_membership_type`; +DROP TABLE IF EXISTS `membershipextras_membership_rate`; + SET FOREIGN_KEY_CHECKS=1; diff --git a/sql/membershipratetable_install.sql b/sql/membershipratetable_install.sql new file mode 100644 index 00000000..c9b8d62f --- /dev/null +++ b/sql/membershipratetable_install.sql @@ -0,0 +1,35 @@ +SET FOREIGN_KEY_CHECKS=0; +DROP TABLE IF EXISTS `membershipextras_membership_rate_membership_type`; +DROP TABLE IF EXISTS `membershipextras_membership_rate`; +SET FOREIGN_KEY_CHECKS=1; + +-- /******************************************************* +-- * membershipextras_membership_rate +-- * Entity to store different membership rates +-- *******************************************************/ +CREATE TABLE `membershipextras_membership_rate` ( + `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Unique MembershipRate ID', + `label` varchar(255) NULL COMMENT 'Rate Label', + `min_range` decimal(20,2) NULL COMMENT 'Min Range Value', + `max_range` decimal(20,2) NULL COMMENT 'Max Range Value', + `multiplier` decimal(20,2) NULL COMMENT 'Subscription Multiplier', + `min_subscription_rate` decimal(20,2) NULL COMMENT 'Min Subscription Rate', + `sort_order` int unsigned NOT NULL COMMENT 'Sort Order', + PRIMARY KEY (`id`) +) +ENGINE=InnoDB; + +-- /******************************************************* +-- * membershipextras_membership_rate_membership_type +-- * One to Many Membership Rate - Membership Type Relationship +-- *******************************************************/ +CREATE TABLE `membershipextras_membership_rate_membership_type` ( + `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Unique MembershipRateMembershipType ID', + `membership_rate_id` int unsigned COMMENT 'FK to MembershipRate', + `membership_type_id` int unsigned COMMENT 'FK to MembershipType', + PRIMARY KEY (`id`), + UNIQUE INDEX `unique_membership_rate_type_id` (membership_rate_id, membership_type_id), + CONSTRAINT FK_membership_type_membership_rate_id FOREIGN KEY (`membership_rate_id`) REFERENCES `membershipextras_membership_rate`(`id`) ON DELETE CASCADE, + CONSTRAINT FK_membership_type_membership_type_id FOREIGN KEY (`membership_type_id`) REFERENCES `civicrm_membership_type`(`id`) ON DELETE CASCADE +) +ENGINE=InnoDB; diff --git a/tests/phpunit/BaseHeadlessTest.php b/tests/phpunit/BaseHeadlessTest.php index ab1c926b..5258a4ed 100644 --- a/tests/phpunit/BaseHeadlessTest.php +++ b/tests/phpunit/BaseHeadlessTest.php @@ -3,12 +3,14 @@ use Civi\Test\HeadlessInterface; use Civi\Test\TransactionalInterface; -abstract class BaseHeadlessTest extends PHPUnit_Framework_TestCase implements - HeadlessInterface, TransactionalInterface { +abstract class BaseHeadlessTest extends PHPUnit\Framework\TestCase implements + HeadlessInterface, + TransactionalInterface { public function setUpHeadless() { return \Civi\Test::headless() ->installMe(__DIR__) ->apply(); } + } diff --git a/xml/schema/CRM/MembershipExtras/MembershipRate.entityType.php b/xml/schema/CRM/MembershipExtras/MembershipRate.entityType.php new file mode 100644 index 00000000..d8d67076 --- /dev/null +++ b/xml/schema/CRM/MembershipExtras/MembershipRate.entityType.php @@ -0,0 +1,11 @@ + 'MembershipRate', + 'class' => 'CRM_MembershipExtras_DAO_MembershipRate', + 'table' => 'civicrm_membership_rate', + ], +]; diff --git a/xml/schema/CRM/MembershipExtras/MembershipRate.xml b/xml/schema/CRM/MembershipExtras/MembershipRate.xml new file mode 100644 index 00000000..4a25fa91 --- /dev/null +++ b/xml/schema/CRM/MembershipExtras/MembershipRate.xml @@ -0,0 +1,89 @@ + + + + CRM/MembershipExtras + MembershipRate + membershipextras_membership_rate + Entity to store different membership rates + true + + + civicrm/member/membership-rate/new?reset=1&id=[id]&action=update + civicrm/member/membership-rate/delete?reset=1&id=[id] + + + + id + int unsigned + true + Unique MembershipRate ID + + Number + + + + id + true + + + + label + varchar + 255 + false + Rate Label + + Text + + + + + min_range + decimal + false + Min Range Value + + Text + + + + + max_range + decimal + false + Max Range Value + + Text + + + + + multiplier + decimal + false + Subscription Multiplier + + Text + + + + + min_subscription_rate + decimal + false + Min Subscription Rate + + Text + + + + + sort_order + int unsigned + true + Sort Order + + Number + + +
diff --git a/xml/schema/CRM/MembershipExtras/MembershipRateMembershipType.entityType.php b/xml/schema/CRM/MembershipExtras/MembershipRateMembershipType.entityType.php new file mode 100644 index 00000000..f68d96c6 --- /dev/null +++ b/xml/schema/CRM/MembershipExtras/MembershipRateMembershipType.entityType.php @@ -0,0 +1,11 @@ + 'MembershipRateMembershipType', + 'class' => 'CRM_MembershipExtras_DAO_MembershipRateMembershipType', + 'table' => 'civicrm_membership_rate_membership_type', + ], +]; diff --git a/xml/schema/CRM/MembershipExtras/MembershipRateMembershipType.xml b/xml/schema/CRM/MembershipExtras/MembershipRateMembershipType.xml new file mode 100644 index 00000000..6d95b1f6 --- /dev/null +++ b/xml/schema/CRM/MembershipExtras/MembershipRateMembershipType.xml @@ -0,0 +1,48 @@ + + + + CRM/MembershipExtras + MembershipRateMembershipType + membershipextras_membership_rate_membership_type + One to Many Membership Rate - Membership Type Relationship + true + + + id + int unsigned + true + Unique MembershipRateMembershipType ID + + Number + + + + id + true + + + + membership_rate_id + int unsigned + FK to MembershipRate + + + membership_rate_id +
membershipextras_membership_rate
+ id + CASCADE + + + + membership_type_id + int unsigned + FK to MembershipType + + + membership_type_id + civicrm_membership_type
+ id + CASCADE +
+ +