Future Specification - lokothodida/DM_Matrix GitHub Wiki
DM_query(query) - perform a simple query, results returned in an array
DM_getSchema - get the main Schema
DM_saveSchema - Save the schema out to an XML file schema.xml
createSchemaFolder - create the base folder for the record files
createRecord - Add a record/file to a table
getNextRecord - returns the next record number in the table
createSchemaTable - Create a new table
dropSchemaTable - Delete a table
addSchemaField - add a field to a table
deleteSchemaField - Delete a field from a table
getSchemaTable - return an array of a tables records.
DM_getRecord - get a single record from a table, supplying tabel and id of record
tableexists - check if a table exists
updateRecord - update a record
DM_createForm - create an input form from a table
DM_editForm - create a form for editing providing a record number.
Check that a table exists
if (matrix_table_exists('blog')) {
// ...
}Create a table with given parameters $params. Returns true on success.
$create = matrix_create_table('blog', array(
'maxrecords' => null,
'fields' => array(
'slug' => array(
'type' => 'slug'
),
'title' => array(
'type' => 'textlong',
),
'content' => array(
'type' => 'wysiwyg',
),
)
));Update a table with $params. Any fields set to false will be deleted. Returns true on success.
$edit = matrix_edit_table('blog', array(
'maxrecords' => null,
'fields' => array(
// Removes the title field
'title' => false,
// Changes content field to codeeditor type
content' => array(
'type' => 'codeeditor',
),
)
));Deletes a table. Returns true on success.
$delete = matrix_delete_table('blog');Gets the schema of a given table.
fields => array of fields of the table
maxrecords => maximum number of records for the table
$schema = matrix_get_table_schema('articles');
echo $schema['fields']['title']['type']; // textlongRuns a query with $query parameters. Returns array:
results => array of results
total => full size of the query (before limiting)
$results = matrix_query(array(
// SELECT userid, username, title, pubdate
'select' => array('userid', 'username', 'title', 'pubdate'),
// FROM users, articles
'from' => array('users', 'articles'),
// WHERE users.userid = articles.submittedby
'where' => function($user, $article) {
return $user['userid'] == $article['submittedby'];
},
// ORDER BY pubdate DESC
'orderby' => '-pubdate',
// LIMIT 5
'limit' => 5,
// OFFSET 5
'offset' => 5
));
foreach ($results as $result['results']) {
echo 'Article ' . $result['title'] . ' was submitted by '
. $result['username'] . ' on ' . $result['pubdate'];
}Creates a record in $table with $data. Returns true on success.
$create = matrix_create_record('articles', array(
'title' => 'A very interesting piece',
'content' => 'With some very interesting stuff to say...',
));Edits record in $table with id $id, using $data. Returns true on success.
$edit = matrix_edit_record('articles', 4, array(
'title' => 'New title'
));Deletes a record in $table with id $id. Returns true on success.
$delete = matrix_delete_record('articles', 4);Returns record data in $table with id $id. Returns false if the record doesn't exist.
$article = matrix_get_record('articles', 4);
if ($article) {
echo $article['title'];
}Returns data in $table of the latest record. Returns false if table is empty or doesn't exist.
$article = matrix_get_next_record('articles');
if ($article) {
echo $article['title'];
}Displays a form for creating a record in $table.
echo '<form action="create_entry.php" method="post">';
matrix_get_create_form('blog');
echo '<input type="submit" value="Create Entry"/>';
echo '</form>';Displays a form for editing a record in $table with id $id.
echo '<form action="edit_entry.php" method="post">';
matrix_get_edit_form('blog', 5);
echo '<input type="submit" value="Update Entry"/>';
echo '</form>';