function getPermissions($record) { $user = Dataface_AuthenticationTool::getInstance()->getLoggedInUser(); // If user is an admin defer to the application delegate class for // permissions if ($user and $user->val('role') == 'ADMIN') { return null; } elseif ($user and $user->val('role') == 'REGULAR') { return Dataface_PermissionsTool::getRolePermissions('REGULAR'); } if ($user) { // User is logged in return Dataface_PermissionsTool::READ_ONLY(); } // Defer to the application delegate class for all other users return null; }
/** * Builds a new empty schema for a field. Note that this method should be * callable in static context. Hence it should not require the use of $this. */ function _newSchema($type, $fieldname, $tablename = null, $permissions = null) { /* Example row as follows: Array ( [Field] => id [Type] => int(7) [Null] => [Key] => PRI [Default] => [Extra] => auto_increment ) */ if (!isset($tablename)) { $tablename = $this->tablename; } if (!isset($permissions) and is_a($this, 'Dataface_Table')) { $permissions = Dataface_PermissionsTool::getRolePermissions($this->app->_conf['default_field_role']); } else { if (!isset($permissions)) { $permissions = Dataface_PermissionsTool::READ_ONLY(); } } $schema = array("Field" => $fieldname, "Type" => $type, "Null" => '', "Key" => '', "Default" => '', "Extra" => ''); $schema = array_merge_recursive_unique($this->_global_field_properties, $schema); $widget = array(); $widget['label'] = ucfirst($schema['Field']); $widget['description'] = ''; $widget['label_i18n'] = $tablename . '.' . $fieldname . '.label'; $widget['description_i18n'] = $tablename . '.' . $fieldname . '.description'; $widget['macro'] = ''; $widget['helper_css'] = ''; $widget['helper_js'] = ''; $widget['class'] = ''; $widget['type'] = 'text'; $widget['atts'] = array(); //html attributes if (preg_match('/text/', $schema['Type'])) { $widget['type'] = 'textarea'; } else { if (preg_match('/blob/', $schema['Type'])) { $widget['type'] = 'file'; } } $schema['widget'] =& $widget; $schema['tab'] = '__main__'; $schema['tablename'] = $tablename; $schema['tableta'] = 'default'; $schema['vocabulary'] = ''; $schema['enforceVocabulary'] = false; $schema['validators'] = array(); $schema['name'] = $schema['Field']; $schema['permissions'] = $permissions; $schema['repeat'] = false; $schema['visibility'] = array('list' => 'visible', 'browse' => 'visible', 'find' => 'visible'); $schema = array_merge_recursive_unique($schema, $this->_global_field_properties); return $schema; }