Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mahara
mahara
Commits
f2904674
Commit
f2904674
authored
Nov 13, 2007
by
Penny Leach
Browse files
Interaction base class & some changes to support it
parent
e1f47932
Changes
4
Hide whitespace changes
Inline
Side-by-side
htdocs/interaction/lib.php
View file @
f2904674
...
...
@@ -31,6 +31,110 @@ defined('INTERNAL') || die();
* Base interaction plugin class
* @abstract
*/
abstract
class
PluginInteraction
extends
Plugin
{
class
PluginInteraction
extends
Plugin
{
}
/**
* Base class for interaction instances
*/
class
InteractionInstance
{
protected
$id
;
protected
$title
;
protected
$description
;
protected
$group
;
protected
$plugin
;
protected
$ctime
;
protected
$dirty
;
public
function
__construct
(
$id
=
0
,
$data
=
null
)
{
if
(
!
empty
(
$id
))
{
if
(
empty
(
$data
))
{
if
(
!
$data
=
get_record
(
'interaction_instance'
,
'id'
,
$id
))
{
throw
new
InteractionInstanceNotFoundException
(
get_string
(
'interactioninstancenotfound'
,
'error'
,
$id
));
}
}
$this
->
id
=
$id
;
}
else
{
$this
->
dirty
=
true
;
}
if
(
empty
(
$data
))
{
$data
=
array
();
}
foreach
((
array
)
$data
as
$field
=>
$value
)
{
if
(
property_exists
(
$this
,
$field
))
{
$this
->
{
$field
}
=
$value
;
}
}
}
public
function
get
(
$field
)
{
if
(
!
property_exists
(
$this
,
$field
))
{
throw
new
ParamOutOfRangeException
(
"Field
$field
wasn't found in class "
.
get_class
(
$this
));
}
return
$this
->
{
$field
};
}
public
function
set
(
$field
,
$value
)
{
if
(
property_exists
(
$this
,
$field
))
{
if
(
$this
->
{
$field
}
!=
$value
)
{
// only set it to dirty if it's changed
$this
->
dirty
=
true
;
$this
->
{
$field
}
=
$value
;
}
return
true
;
}
throw
new
ParamOutOfRangeException
(
"Field
$field
wasn't found in class "
.
get_class
(
$this
));
}
public
function
commit
()
{
if
(
empty
(
$this
->
dirty
))
{
return
;
}
$fordb
=
new
StdClass
;
foreach
(
get_object_vars
(
$this
)
as
$k
=>
$v
)
{
$fordb
->
{
$k
}
=
$v
;
}
if
(
empty
(
$this
->
id
))
{
$this
->
id
=
insert_record
(
'interaction_instance'
,
$fordb
,
'id'
,
true
);
}
else
{
update_record
(
'interaction_instance'
,
$fordb
,
'id'
);
}
// @TODO maybe handle_event here.
$this
->
dirty
=
false
;
}
public
function
delete
()
{
if
(
empty
(
$this
->
id
))
{
$this
->
dirty
=
false
;
return
;
}
delete_records
(
'interaction_instance'
,
'id'
,
$this
->
id
);
$this
->
dirty
=
false
;
}
}
function
interaction_check_plugin_sanity
(
$pluginname
)
{
safe_require
(
'interaction'
,
$pluginname
);
$classname
=
generate_interaction_instance_class_name
(
$pluginname
);
if
(
!
class_exists
(
$classname
))
{
throw
new
InstallationException
(
get_string
(
'classmissing'
,
'error'
,
$classname
,
'interaction'
,
$pluginname
));
}
}
?>
htdocs/lang/en.utf8/error.php
View file @
f2904674
...
...
@@ -85,6 +85,8 @@ $string['artefactnotfoundmaybedeleted'] = "Artefact with id %s not found (maybe
$string
[
'notartefactowner'
]
=
'You do not own this artefact'
;
$string
[
'blockinstancednotfound'
]
=
'Block instance with id %s not found'
;
$string
[
'interactioninstancenotfound'
]
=
'Interaction instance with id %s not found'
;
$string
[
'invalidviewaction'
]
=
'Invalid view control action: %s'
;
$string
[
'missingparamblocktype'
]
=
'Try selecting a block type to add first'
;
...
...
htdocs/lib/errors.php
View file @
f2904674
...
...
@@ -693,6 +693,11 @@ class ArtefactNotFoundException extends NotFoundException {}
*/
class
BlockInstanceNotFoundException
extends
NotFoundException
{}
/**
* Exception - interaction instance not found
*/
class
InteractionInstanceNotFoundException
extends
NotFoundException
{}
/**
* Exception - view not found
*/
...
...
htdocs/lib/mahara.php
View file @
f2904674
...
...
@@ -861,6 +861,10 @@ function generate_artefact_class_name($type) {
return
'ArtefactType'
.
ucfirst
(
$type
);
}
function
generate_interaction_instance_class_name
(
$type
)
{
return
'Interaction'
.
ucfirst
(
$type
)
.
'Instance'
;
}
function
blocktype_namespaced_to_single
(
$blocktype
)
{
if
(
strpos
(
$blocktype
,
'/'
)
===
false
)
{
// system blocktype
return
$blocktype
;
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment