/** * Init * * @param \Zend\ModuleManager\ModuleManagerInterface $moduleManager * @return void */ public function init(ModuleManagerInterface $moduleManager) { $eventManager = MembershipEvent::getEventManager(); // someone forced a user's role, and now we must clean all the user's membership queue $eventManager->attach(UserEvent::EDIT_ROLE, function ($e) use($moduleManager) { if ($e->getParam('user_id') != UserBaseModel::DEFAULT_SYSTEM_ID) { $this->deleteUserMembershipLevels($moduleManager, $e->getParam('object_id')); } }); }
/** * Edit role * * @param array $roleInfo * @param array $formData * integer role_id - required * integer cost - required * integer lifetime - required * string description - required * string image - required * @param array $image * @return boolean|string */ public function editRole($roleInfo, array $formData, array $image) { try { $this->adapter->getDriver()->getConnection()->beginTransaction(); if (empty($formData['active'])) { $formData['active'] = self::MEMBERSHIP_LEVEL_STATUS_NOT_ACTIVE; } $update = $this->update()->table('membership_level')->set($formData)->where(['id' => $roleInfo['id']]); $statement = $this->prepareStatementForSqlObject($update); $statement->execute(); $this->uploadImage($roleInfo['id'], $image, $roleInfo['image']); $this->adapter->getDriver()->getConnection()->commit(); } catch (Exception $e) { $this->adapter->getDriver()->getConnection()->rollback(); ApplicationErrorLogger::log($e); return $e->getMessage(); } // fire the edit membership role event MembershipEvent::fireEditMembershipRoleEvent($roleInfo['id']); return true; }
/** * Activate the membership connection * * @param integer $connectionId * @return boolean */ public function activateMembershipConnection($connectionId) { try { $this->adapter->getDriver()->getConnection()->beginTransaction(); $time = time(); $update = $this->update()->table('membership_level_connection')->set(['active' => self::MEMBERSHIP_LEVEL_CONNECTION_ACTIVE, 'expire_date' => new Expression('? + (expire_value * ?)', [$time, self::SECONDS_IN_DAY]), 'notify_date' => new Expression('? + (notify_value * ?)', [$time, self::SECONDS_IN_DAY])])->where(['id' => $connectionId]); $statement = $this->prepareStatementForSqlObject($update); $result = $statement->execute(); $this->adapter->getDriver()->getConnection()->commit(); } catch (Exception $e) { $this->adapter->getDriver()->getConnection()->rollback(); ApplicationErrorLogger::log($e); return $e->getMessage(); } if ($result->count()) { // fire the activate membership connection event MembershipEvent::fireActivateMembershipConnectionEvent($connectionId); return true; } return false; }