/** * Allow resource * * @param integer $roleId * @param integer $resourceId * @return boolean|string */ public function allowResource($roleId, $resourceId) { try { $this->adapter->getDriver()->getConnection()->beginTransaction(); // check the existing connection $select = $this->select(); $select->from('acl_resource_connection')->columns(['resource'])->where(['role' => $roleId, 'resource' => $resourceId]); $statement = $this->prepareStatementForSqlObject($select); $result = $statement->execute(); // add a new connection if (!$result->current()) { $insert = $this->insert()->into('acl_resource_connection')->values(['role' => $roleId, 'resource' => $resourceId]); $statement = $this->prepareStatementForSqlObject($insert); $statement->execute(); } $this->adapter->getDriver()->getConnection()->commit(); } catch (Exception $e) { $this->adapter->getDriver()->getConnection()->rollback(); ApplicationErrorLogger::log($e); return $e->getMessage(); } // fire the allow acl resource event AclEvent::fireAllowAclResourceEvent($resourceId, $roleId); return true; }