Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpnSense
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
OpnSense
Commits
2d303f15
Commit
2d303f15
authored
Aug 08, 2016
by
pv2b
Committed by
Per von Zweigbergk
Aug 09, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ApiMutableTableModelControllerBase implemented methods
parent
bd7f2f3a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
105 additions
and
6 deletions
+105
-6
ApiMutableTableModelControllerBase.php
...lers/OPNsense/Base/ApiMutableTableModelControllerBase.php
+105
-6
No files found.
src/opnsense/mvc/app/controllers/OPNsense/Base/ApiMutableTableModelControllerBase.php
View file @
2d303f15
...
@@ -37,6 +37,8 @@ namespace OPNsense\Base;
...
@@ -37,6 +37,8 @@ namespace OPNsense\Base;
*/
*/
abstract
class
ApiMutableTableModelControllerBase
extends
ApiControllerBase
abstract
class
ApiMutableTableModelControllerBase
extends
ApiControllerBase
{
{
// FIXME What about validation?
static
protected
$modelPathPrefix
=
''
;
static
protected
$modelPathPrefix
=
''
;
private
function
getNodes
()
{
private
function
getNodes
()
{
$ref
=
static
::
$modelPathPrefix
$ref
=
static
::
$modelPathPrefix
...
@@ -46,10 +48,16 @@ abstract class ApiMutableTableModelControllerBase extends ApiControllerBase
...
@@ -46,10 +48,16 @@ abstract class ApiMutableTableModelControllerBase extends ApiControllerBase
private
function
getNodeByUUID
(
$uuid
)
{
private
function
getNodeByUUID
(
$uuid
)
{
return
$this
->
getNodes
()
->
$uuid
;
return
$this
->
getNodes
()
->
$uuid
;
}
}
/**
* retrieve item or return defaults
* @param $uuid item unique id
* @return array
*/
public
function
getItemAction
(
$uuid
=
null
)
{
public
function
getItemAction
(
$uuid
=
null
)
{
$mdl
=
$this
->
getModel
();
$mdl
=
$this
->
getModel
();
if
(
$uuid
!=
null
)
{
if
(
$uuid
!=
null
)
{
$node
=
getNodeByUUID
(
$uuid
);
$node
=
$this
->
getNodeByUUID
(
$uuid
);
if
(
$node
!=
null
)
{
if
(
$node
!=
null
)
{
// return node
// return node
return
array
(
static
::
$internalModelName
=>
$node
->
getNodes
());
return
array
(
static
::
$internalModelName
=>
$node
->
getNodes
());
...
@@ -61,19 +69,110 @@ abstract class ApiMutableTableModelControllerBase extends ApiControllerBase
...
@@ -61,19 +69,110 @@ abstract class ApiMutableTableModelControllerBase extends ApiControllerBase
}
}
return
array
();
return
array
();
}
}
/**
* update item with given properties
* @param $uuid item unique id
* @return array
*/
public
function
setItemAction
(
$uuid
)
{
public
function
setItemAction
(
$uuid
)
{
// FIXME To be implemented
if
(
$this
->
request
->
isPost
()
&&
$this
->
request
->
hasPost
(
static
::
$internalModelName
))
{
$mdl
=
$this
->
getModel
();
if
(
$uuid
!=
null
)
{
$node
=
$this
->
getNodeByUUID
(
$uuid
);
if
(
$node
!=
null
)
{
$node
->
setNodes
(
$this
->
request
->
getPost
(
static
::
$internalModelName
));
return
$this
->
save
(
$mdl
,
$node
,
static
::
$internalModelName
);
}
}
}
return
array
(
"result"
=>
"failed"
);
}
}
/**
* add new item and set with attributes from post
* @return array
*/
public
function
addItemAction
()
{
public
function
addItemAction
()
{
// FIXME To be implemented
$result
=
array
(
"result"
=>
"failed"
);
if
(
$this
->
request
->
isPost
()
&&
$this
->
request
->
hasPost
(
static
::
$internalModelName
)))
{
$mdl
=
$this
->
getModel
();
// FIXME Is this correct?
$node
=
$this
->
getNodes
()
->
add
();
$node
->
setNodes
(
$this
->
request
->
getPost
(
static
::
$internalModelName
)));
// FIXME What do we do with this? Is this traffic-shaper specific? Do we need a hook here?
$node
->
origin
=
"TrafficShaper"
;
// set origin to this component.
return
$this
->
save
(
$mdl
,
$node
,
static
::
$internalModelName
));
}
return
$result
;
}
}
/**
* delete item by uuid
* @param $uuid item unique id
* @return array status
*/
public
function
delItemAction
(
$uuid
)
{
public
function
delItemAction
(
$uuid
)
{
// FIXME To be implemented
$result
=
array
(
"result"
=>
"failed"
);
if
(
$this
->
request
->
isPost
())
{
$mdl
=
$this
->
getModel
();
if
(
$uuid
!=
null
)
{
if
(
getNodes
()
->
del
(
$uuid
))
{
// if item is removed, serialize to config and save
$mdlShaper
->
serializeToConfig
();
Config
::
getInstance
()
->
save
();
$result
[
'result'
]
=
'deleted'
;
}
else
{
$result
[
'result'
]
=
'not found'
;
}
}
}
return
$result
;
}
}
/**
* toggle item by uuid (enable/disable)
* @param $uuid item unique id
* @param $enabled desired state enabled(1)/disabled(1), leave empty for toggle
* @return array status
*/
public
function
toggleItemAction
(
$uuid
,
$enabled
=
null
)
{
public
function
toggleItemAction
(
$uuid
,
$enabled
=
null
)
{
// FIXME To be implemented
$result
=
array
(
"result"
=>
"failed"
);
if
(
$this
->
request
->
isPost
())
{
$mdl
=
$this
->
getModel
();
if
(
$uuid
!=
null
)
{
$node
=
$mdl
->
getNodeByUUID
(
$uuid
);
if
(
$node
!=
null
)
{
if
(
$enabled
==
"0"
||
$enabled
==
"1"
)
{
$node
->
enabled
=
(
string
)
$enabled
;
}
elseif
(
$node
->
enabled
->
__toString
()
==
"1"
)
{
$node
->
enabled
=
"0"
;
}
else
{
$node
->
enabled
=
"1"
;
}
$result
[
'result'
]
=
$node
->
enabled
;
// if item has toggled, serialize to config and save
$mdlShaper
->
serializeToConfig
();
Config
::
getInstance
()
->
save
();
}
}
}
return
$result
;
}
}
/**
* search items
* @return array
*/
public
function
searchItemsAction
()
{
public
function
searchItemsAction
()
{
// FIXME To be implemented
$this
->
sessionClose
();
$mdl
=
$this
->
getModel
();
$grid
=
new
UIModelGrid
(
$this
->
getNodes
());
return
$grid
->
fetchBindRequest
(
$this
->
request
,
// FIXME Where do we get this list from? Is this something to be supplied by class implementor?
array
(
"enabled"
,
"number"
,
"bandwidth"
,
"bandwidthMetric"
,
"burst"
,
"description"
,
"mask"
,
"origin"
),
"number"
);
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment