A widget consists of four (or, well, five) identifying pieces of information. More...
Public Member Functions | |
__construct ($db_row) | |
You should not call this constructor directly! | |
save () | |
Save any changes to the widget. | |
merge_settings ($new_setting) | |
Given an array of new settings, update the local settings with those. | |
copy () | |
Create new instance of widget and save. | |
delete () | |
Deletes a copy of a widget. | |
Static Public Member Functions | |
static | fetch_all ($page) |
Fetches a list of widget names for a given page. | |
static | get ($page, $widget, $instance_id=null) |
Fetch info on a saved widget for a page. | |
static | install ($page, $name, $friendly_name) |
Add a new widget to ninja_widgets table. | |
static | uninstall ($name) |
Remove any instance of a widget from the ninja_widgets stable Scary to expose to end users, as it does no authorization checks. | |
static | update_all_widgets ($page=false, $value=false, $type='refresh_interval') |
Update setting for all widgets on a page. | |
static | fetch_widget_order ($page=false) |
Parse the widget order for use on a page. | |
static | set_widget_order ($page, $widget_order) |
Given a structure like array(placeholder1 => array(widget1, widget2, widgetn), placeholder2 => array(. | |
static | rename_widget ($old_name, $new_name) |
DANGER WILL ROBINSON! This makes a ton of assumptions, and should only be called after much consideration. | |
static | rename_friendly_widget ($old_name, $new_name) |
Renames the friendly name of a widget. | |
Data Fields | |
const | FIRST_INSTANCE_ID = 1 |
When getting "any" instance of a widget, we will specifically look for this. | |
$name | |
The internal name of the widget. | |
$page | |
The page the widget is shown on. | |
$instance_id | |
The widget's instance id. | |
$username | |
The user's username. | |
$setting | |
The widget's settings. |
A widget consists of four (or, well, five) identifying pieces of information.
It has a name. The name links it to the on-disk PHP files.
It has a page. This means the same widget can/will look different depending on your URL.
It has a user. This means that different users see the same widget differently.
It has an instance id. This means that the same user can see the same widget multiple times on the same page, with different options in each.
(there's also an ID column, but it's pretty useless)
When showing a widget, we first try to find a widget with the same page, user and instance id. If that's not possible, we fall back to the same page and user, but any id we can find, then to the same page but with blank user and id, and then to the 'tac/index' page with a blank user and id. When returning data from this model, nobody should have to bother about whether the widget information was returned from a fallback or not.
(If you have a clever, quick, cross-database solution to do this whole thing in-database, please don't hesitate to do it)
We no longer send hidden default widgets to the user. We must thus send empty widget instances that the user can copy into their own namespace.
Saving an edited widget must never save to any of the fallback options. In particular, for legacy systems, that means we must never write to anything with an empty instance id. FIXME: tested?
There are two add/remove pairs of functions: install/uninstall, and copy/delete. The first pair works globally, the second per-user.
Ninja_widget_Model::__construct | ( | $ | db_row | ) |
You should not call this constructor directly!
What you're looking for is probably get.
Ninja_widget_Model::copy | ( | ) |
static Ninja_widget_Model::fetch_all | ( | $ | page | ) | [static] |
Fetches a list of widget names for a given page.
$page | The page name |
static Ninja_widget_Model::get | ( | $ | page, | |
$ | widget, | |||
$ | instance_id = null | |||
) | [static] |
static Ninja_widget_Model::install | ( | $ | page, | |
$ | name, | |||
$ | friendly_name | |||
) | [static] |
Ninja_widget_Model::merge_settings | ( | $ | new_setting | ) |
Given an array of new settings, update the local settings with those.
Any preexisting settings not in $new_setting will be kept around. This does not write to database - see save()
$new_setting | Array of new settings to overwrite the old ones with |
static Ninja_widget_Model::rename_friendly_widget | ( | $ | old_name, | |
$ | new_name | |||
) | [static] |
Ninja_widget_Model::save | ( | ) |
static Ninja_widget_Model::set_widget_order | ( | $ | page, | |
$ | widget_order | |||
) | [static] |
Given a structure like array(placeholder1 => array(widget1, widget2, widgetn), placeholder2 => array(.
..)) serialize it and save it in the database.
static Ninja_widget_Model::uninstall | ( | $ | name | ) | [static] |