[ AdminAcl::ACL_VENDOR_RATES_READ_ID => [ 'list', ], AdminAcl::ACL_VENDOR_RATES_BLACKLIST_ID => [ 'list', 'cancel', 'insert', 'back', 'blacklist', 'whitelist', ], ], AdminObj::TYPE_TRIBAL_ACCOUNT => [ TribalAccountAcl::ACL_VENDOR_RATES_READ_ID => [ 'list', ], TribalAccountAcl::ACL_VENDOR_RATES_BLACKLIST_ID => [ 'list', 'cancel', 'insert', 'back', 'blacklist', 'whitelist', ], ], ]; protected function _init() { $this->_messageTemplates[self::MSG_ADDED_BLACKLIST] = 'Vendor has been added to Blacklist'; $this->_messageTemplates[self::MSG_ADDED_WHITELIST] = 'Vendor has been added to Whitelist'; return parent::_init(); } protected function _initAction() { $this->_initPermittedActions(); return parent::_initAction(); } protected function _initPermittedActions() { $aclIds = AclPermission::getAllowedResources(); if (AclPermission::isTribalAccount()) { $type = AdminObj::TYPE_TRIBAL_ACCOUNT; if (in_array(TribalAccountAcl::ACL_VENDOR_RATES_READ_ID, $aclIds)) { $this->_actions = array_merge( $this->_actions, $this->_allowedActions[$type][TribalAccountAcl::ACL_VENDOR_RATES_READ_ID] ); } if (in_array(TribalAccountAcl::ACL_VENDOR_RATES_BLACKLIST_ID, $aclIds)) { $this->_actions = array_merge( $this->_actions, $this->_allowedActions[$type][TribalAccountAcl::ACL_VENDOR_RATES_BLACKLIST_ID] ); } } else { $availableAclIds = array_intersect($aclIds, array_keys($this->_allowedActions[AdminObj::TYPE_ADMIN])); foreach ($availableAclIds as $availableAclId) { $this->_actions = array_merge( $this->_actions, $this->_allowedActions[AdminObj::TYPE_ADMIN][$availableAclId] ); } $this->_actions = array_unique($this->_actions); if ($this->getDoc()->getAuth()->getSuMode()) { $this->_actions[] = 'delete'; } } return $this; } protected function _getFormOptions($type = null) { $options = parent::_getFormOptions($type); $vendorId = null; if ($type == 'new') { $options['vendorAutocompleteUrl'] = VendorAutocompleteAdminView::getPage('url'); if (in_array($this->_action, [Entity::STATUS_BLACKLIST, Entity::STATUS_WHITELIST])) { $options['status'] = $this->_action; } if ($vendorId = Qs_Request::getGetValue('vendorId')) { $options['defaults']['vendorId'] = $vendorId; $options['vendorAutocompleteTitle'] = VendorAutocompleteAdminObj::getAutocompleteItemTitle($vendorId); } } if ($type == 'filter') { $options['vendorAutocompleteUrl'] = VendorAutocompleteAdminView::getPage('url'); if (($vendorId = Qs_Request::getGetValue('vendorId'))) { $options['vendorAutocompleteTitle'] = VendorAutocompleteAdminObj::getAutocompleteItemTitle($vendorId); } } return $options; } protected function _initFromForm(Qs_Form $form) { $data = $form->getValues(); $data['adminId'] = $this->_doc->getAuthData('id'); if (AclPermission::isTribalAccount()) { $data['tribeIds'] = [AclPermission::getAdminTribeId()]; } else { $data['tribeIds'] = []; } $this->_getDataObj()->initFromForm($data); return $this; } protected function _doBlacklist() { $this->_doc->setHeader('Add Vendor to Blacklist'); parent::_doNew(); return $this; } protected function _doWhitelist() { $this->_doc->setHeader('Add Vendor to Whitelist'); parent::_doNew(); return $this; } protected function _getDefaultLinks() { $links = parent::_getDefaultLinks(); if (false !== array_search('blacklist', $this->_actions)) { $links['blacklist'] = 'Blacklist ' . $this->getConfig('itemName'); } if (false !== array_search('whitelist', $this->_actions)) { $links['whitelist'] = 'Whitelist ' . $this->getConfig('itemName'); } return $links; } protected function _doInsert() { $form = $this->_getNewForm(['defaults' => Qs_Request::getPost()]); if ($form->validate()) { $this->_initFromForm($form); $status = $form->getValue('status'); if (false === $this->_getDataObj()->insert()) { $this->_setBackErrors($this->_getDataObj()->getErrors()); } else { $this->_postInsert(); $msg = ($status == Entity::STATUS_BLACKLIST) ? static::MSG_ADDED_BLACKLIST : static::MSG_ADDED_WHITELIST; $this->_setBackMessage($msg); } $this->_doBack(); } else { $this->_addFormItem($form); } return $this; } }