params[$key]['value'] = $val;
}
/** Return an array of parameter names.
*/
function getParamNames()
{
return array_keys($this->params);
}
/** Return the value of a parameter of the plugin.
*/
function getParamValue($key)
{
return isset($this->params[$key]['value']) ? $this->params[$key]['value'] : '';
}
/** Set the value of a parameter of the plugin.
*/
function setParamValue($key, $val)
{
if (isset($this->params[$key]['value'])) {
$this->params[$key]['value'] = $val;
}
}
/** Erase parameters from database.
*
* @param $barrel
* @param $page
*/
function eraseParameters($barrel = '', $page = 0)
{
global $globals;
//echo $this->name . " : eraseParams($barrel, $page)
\n";
$globals->db->query("delete from diogenes_plugin where plugin='{$this->name}' and barrel='$barrel' and page='$page'");
unset($this->pos);
foreach ($this->getParamNames() as $key)
{
//echo "$this->name : erasing param
\n";
$this->setParamValue($key, '');
}
}
/** Read parameters from an array.
*/
function fromArray($plugentry)
{
$this->pos = $plugentry['pos'];
$this->status = $plugentry['status'];
foreach ($plugentry['params'] as $key => $val)
{
$this->setParamValue($key, $val['value']);
}
}
/** Store parameters to database.
*
* @param $barrel
* @param $page
* @param $pos
*/
function toDatabase($barrel = '', $page = 0, $pos = 0)
{
global $globals;
$this->pos = $pos;
$params = var_encode_bin($this->params);
//echo "toDatabase called for '{$this->name}' in barrel '$barrel' (status : {$this->status}, params : '$params')
";
$globals->db->query("replace into diogenes_plugin set plugin='{$this->name}', status='{$this->status}', barrel='$barrel', page='$page', pos='$pos', params='$params'");
}
/** Dump parameters to a table.
*/
function toArray()
{
$plugentr = array();
// copy over properties
$props = array('status', 'name', 'params', 'description', 'version', 'type', 'pos');
foreach ($props as $prop)
{
$plugentr[$prop] = stripslashes_recurse($this->$prop);
}
return $plugentr;
}
}
?>