+ /**
+ * Cached wrapper for membership types.
+ *
+ * Since this is used from the batched script caching helps.
+ *
+ * @throws \CiviCRM_API3_Exception
+ */
+ public static function getAllMembershipTypes() {
+ if (!Civi::cache('metadata')->has(__CLASS__ . __FUNCTION__)) {
+ Civi::cache('metadata')->set(__CLASS__ . __FUNCTION__, civicrm_api3('MembershipType', 'get', ['options' => ['limit' => 0, 'sort' => 'weight']])['values']);
+ }
+ return Civi::cache('metadata')->get(__CLASS__ . __FUNCTION__);
+ }
+
+ /**
+ * Get a specific membership type (leveraging the cache).
+ *
+ * @param int $id
+ *
+ * @return mixed
+ * @throws \CiviCRM_API3_Exception
+ */
+ public static function getMembershipType($id) {
+ return self::getAllMembershipTypes()[$id];
+ }
+