public function execute() { if(Gpf_Plugins_Engine::getInstance()->getConfiguration()->isPluginActive('AffiliateNetwork')){ $Merchant = new Gpf_Db_Role(); $Merchant->setId(Pap_Application::DEFAULT_ROLE_MERCHANT); $Merchant->load(); $Merchant->setName('Network Owner'); $Merchant->save(); } }
public function initDatabase() { $role = new Gpf_Db_Role(); $role->setId(self::DEFAULT_ROLE_MERCHANT); $role->setName('Merchant'); $role->setRoleType(self::ROLETYPE_MERCHANT); $role->insert(); $role = new Gpf_Db_Role(); $role->setId(self::DEFAULT_ROLE_AFFILIATE); $role->setName('Affiliate'); $role->setRoleType(self::ROLETYPE_AFFILIATE); $role->insert(); }
/** * @service role add * @return Gpf_Rpc_Form */ public function add(Gpf_Rpc_Params $params) { $form = new Gpf_Rpc_Form($params); $origRole = new Gpf_Db_Role(); $origRole->setId($form->getFieldValue('roleid')); $origRole->load(); $newRole = new Gpf_Db_Role(); $newRole->setName($form->getFieldValue('name')); $newRole->setAccountId(Gpf_Session::getInstance()->getAuthUser()->getAccountId()); $newRole->setRoleType($origRole->getRoleType()); $newRole->insert(); if (strlen($origRole->getAccountId())) { //it is custom role, copy privileges from db $select = new Gpf_SqlBuilder_SelectBuilder(); $select->select->addConstant($newRole->getId(), 'roleid'); $select->select->add(Gpf_Db_Table_RolePrivileges::OBJECT, Gpf_Db_Table_RolePrivileges::OBJECT); $select->select->add(Gpf_Db_Table_RolePrivileges::PRIVILEGE, Gpf_Db_Table_RolePrivileges::PRIVILEGE); $select->from->add(Gpf_Db_Table_RolePrivileges::getName()); $select->where->add(Gpf_Db_Table_Roles::ID, '=', $origRole->getId()); $insert = new Gpf_SqlBuilder_InsertBuilder(); $insert->setTable(Gpf_Db_Table_RolePrivileges::getInstance()); $insert->fromSelect($select); $insert->execute(); } else { //it is default role, copy privileges from php settings $privileges = Gpf_Application::getInstance()->getRoleDefaultPrivileges($origRole->getId()); foreach ($privileges as $objectName => $privilegeList) { foreach ($privilegeList as $right) { $privilege = new Gpf_Db_RolePrivilege(); $privilege->setRoleId($newRole->getId()); $privilege->setObject($objectName); $privilege->setPrivilege($right); $privilege->insert(); } } } return $form; }