Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
smradius
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
shail
smradius
Commits
a3987aa2
Commit
a3987aa2
authored
15 years ago
by
Nigel Kukard
Browse files
Options
Downloads
Patches
Plain Diff
* Removed JSON class from ajax.php
parent
74115004
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
webgui/ajax.php
+8
-151
8 additions, 151 deletions
webgui/ajax.php
with
8 additions
and
151 deletions
webgui/ajax.php
+
8
−
151
View file @
a3987aa2
<?php
# Requires / Includes
include_once
(
"functions/AdminUsers.php"
);
include_once
(
"functions/AdminGroups.php"
);
include_once
(
"functions/AdminRealms.php"
);
include_once
(
"functions/AdminLocations.php"
);
include_once
(
"includes/ajax/json.php"
);
include_once
(
"includes/ajax/functions/AdminUsers.php"
);
include_once
(
"includes/ajax/functions/AdminGroups.php"
);
include_once
(
"includes/ajax/functions/AdminRealms.php"
);
include_once
(
"includes/ajax/functions/AdminLocations.php"
);
define
(
'RES_OK'
,
0
);
define
(
'RES_ERR'
,
-
1
);
class
json_response
{
private
$_fields
=
array
();
private
$_id
;
private
$_results
;
private
$_datasetSize
;
private
$_status
=
RES_OK
;
## @method setID($id)
# Set ID column
#
# @param id ID column name
public
function
setID
(
$id
)
{
$this
->
_id
=
$id
;
}
## @method setStatus($status)
# Set response status
#
# @param status Either RES_OK (default) or RES_ERROR
public
function
setStatus
(
$status
)
{
$this
->
_status
=
$status
;
}
## @method addField($name,$type)
# Add a field to our return results
#
# @param name Field name
# @param type Field type, 'int', 'string', 'float', 'boolean', 'date'
public
function
addField
(
$name
,
$type
)
{
# Build field
$field
=
array
(
'name'
=>
$name
,
'type'
=>
$type
);
# Set ISO date format
if
(
$field
[
'type'
]
==
"date"
)
{
$field
[
'dateFormat'
]
=
"Y-m-d"
;
}
# Add field to list
array_push
(
$this
->
_fields
,
$field
);
}
## @method setDatasetSize($size)
# Set how many records are returned in the dataset
#
# @param size Dataset size
public
function
setDatasetSize
(
$size
)
{
$this
->
_datasetSize
=
$size
;
}
## @method parseArrayRef($array)
# Parse in the array of results and fix it up
#
# @param arrayref Array ref containing the results
public
function
parseArray
(
$array
)
{
$this
->
_results
=
array
();
# Loop with array items
foreach
(
$array
as
$aitem
)
{
$item
=
array
();
# Loop with fields we want
foreach
(
$this
->
_fields
as
$field
)
{
# FIXME - typecast?
$item
[
$field
[
'name'
]]
=
$aitem
[
$field
[
'name'
]];
}
array_push
(
$this
->
_results
,
$item
);
}
}
## @method parseHash($hashref)
# Parse in the hash of results and fix it up
#
# @param hashref Hash ref containing the results
public
function
parseHash
(
$hash
)
{
$this
->
_results
=
array
();
foreach
(
$this
->
_fields
as
$field
)
{
# FIXME - typecast?
$this_results
[
$field
[
'name'
]]
=
$hash
[
$field
[
'name'
]];
}
}
## @method export
# Export response into something we return
#
# @return JSON hash
# @li result - Result code/status
# @li data - Ref containing results
# @li metaData - Metadata containing info about the results being returned
# Metadata contains properties..
# - root: root element, which is always 'data'
# - fields: Optional field description, arrayref of hash refs, name = 'name', type 'type' and 'dateFormat' = 'Y-m-d'
# - id: Optional ID field name
# - totalProperty: Optional property name containing the number of records, always 'datasetSize'
# @li datasetSize Optional, number of records we're rturning
public
function
export
()
{
# Build result
$ret
=
array
(
'result'
=>
$this
->
_status
,
# Additional stuff for other things to make life easier
'success'
=>
$this
->
_status
==
RES_OK
?
1
:
0
,
'metaData'
=>
array
(
'successProperty'
=>
'success'
)
);
# If we have results, add them
if
(
isset
(
$this
->
_results
))
{
$ret
[
'data'
]
=
$this
->
_results
;
$ret
[
'metaData'
][
'root'
]
=
'data'
;
# If we have fields, set them up
if
(
isset
(
$this
->
_fields
))
{
$ret
[
'metaData'
][
'fields'
]
=
$this
->
_fields
;
}
}
# Check if we have an ID set
if
(
isset
(
$this
->
_id
))
{
$ret
[
'metaData'
][
'totalProperty'
]
=
'datasetSize'
;
$ret
[
'datasetSize'
]
=
$this
->
_datasetSize
;
}
return
$ret
;
}
}
/*
* AJAX Interface to SMEngine SOAP
*/
...
...
@@ -506,3 +360,6 @@
echo
json_encode
(
$soapRes
);
# vim: ts=4
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment