Packageindex Classtrees Modulegroups Elementlist Report XML Files

pxdb.content.input

pxdb_commit

pxdb_data
   |
  +-- pxdb_confront
     |
    +-- pxdb_commit

public class pxdb_commit extends pxdb_confront

This class has some overlap with the pxdb_record class, but the focus of this class is *writing* data to the database, within the system of privileges. The default use for this class is on the receiving end of a pxdb_input form. -- i.e. when this class is instantiated, it will seek to import any vars submitted by the pxdb_input form (including uploaded files). Before being written to the database, variables are processed, then validated using defined plugins or registered processor & validator functions. Records are inserted with 'read,write' privileges for the user inserting the record, for any admin user (pref: gid_admin) and a default 'read' value for Everyone. Additionally, if approve_disabled pref is not set then the record is marked approved only if a approve_auto is set (either generally or for the datatype). Auto-generated fields are calculated during the 'cleanup' phase. Additionally if the record being written is a 'user' or 'group' type record (as defined with the dt_user and dt_group pxdb_pref preferences) then the usergroup table is also automatically populated (e.g. for authentication with mod_auth_mysql) during the 'cleanup' phase.

AuthorsHans Lellelid <hans@velum.net>
Version$Revision: 1.26 $

 

Methods inherited from pxdb_confront

pxdb_confront, _get_form_element_name, _invoke_user_method, _import_uploaded_files, bind_validator

Methods inherited from pxdb_data

pxdb_data, set_show_unapproved, get_datatype_list, get_datatype_array, bind_tpl, bind_auth, lookup_colname, lookup_tfid, get_column_identifiers, get_identifiers, set_user_minimal_columns, sql_minimal_columns, sql_aliased_columns

Public Method Summary

void pxdb_commit([ integer $id ])
constructor
integer get_id()
Get the record id.
void set_id(integer $id)
Sets the record id.
int lookup_datatype(int $rec_id)
Returns the datatype for a given id
integer get_datatype()
Get the datatype.Warning: documentation is missing.
void set_datatype(integer $dt)
Sets the datatype.Warning: documentation is missing.
void read()
Reads in data from database.
void import([ array $source ])
Imports variables and uploaded files from global scope.Warning: documentation is missing.
boolean validate()
Wrapper function for form validation class' function (if present).
array get_modified_fields()
Gets a list of fields that were updated.
boolean is_changed(string $field, mixed $value)
Find out whether or not a field was modified (from db version).
string get_save_type()
Returns the type of save operation that was performed.
boolean save()
Main workhorse function of the pxdb_adm class.
void add_related(mixed $related_id, int $relid)
Adds a primaryrel relationship to current record.
void add_secondaryrel_related(mixed $related_id)
Adds a secondaryrel relationship to current record.
void add_child(mixed $related_id, [ int $noderel_id ])
Adds a noderel child to current record.
void add_parent(mixed $related_id, [ int $noderel_id ])
Adds a noderel parent to current record.
boolean approve()
Approve a record.
boolean unapprove()
Un-approve a record.
void set_approval_status(boolean $bit)
Sets the approval bit for a record.
boolean set_field(string $field, mixed $value, [ boolean $quote ])
Add (or sets) a field to be written to db.
boolean is_rlevel_authorized(integer $record_id)
Checks to see if current user has specified access to specified record.
boolean is_flevel_authorized(integer $field_id)
Checks to see if current user has specified access to specified field.
void set_default_priv(mixed $priv)
Sets the priv that is assigned by default to everyone.
boolean grant_priv(int $ugid, mixed $priv)
Function to grant privileges to a record.
boolean revoke_priv(int $ugid)
Function to revoke privileges to a record
boolean delete_related(mixed $relid, [ mixed $dt ])
Removes related [primaryrel] records from the database.
boolean delete_secondaryrel_related([ mixed $dt ])
Removes related [secondaryrel] records from the database.
Array delete_children([ boolean $purge_records, int $parent ])
Deletes children elements from noderel and [optionally] from records tables.
mixed delete()
Deletes the record and rows from relationships tables.

Private Method Summary

void __wakeup()
called by php's unserialize function
boolean _cleanup()
Performs any post-write functions.
boolean _calculate_autogen_fields()
Calculate any autogen fields in current fields.
mixed _include_generator(string $plugin_data, array &$data)
Include an autogen calculator.
boolean _handle_uploaded_files()
Renames and moves uploaded files from temporary location to datastore.
array _get_filestore_paths()
Returns an array with one or more PXDB_FILESTORE_PATH entries. Returns false if none found.
boolean _populate_usergroup()
Adds user idnum and group name to the usergroup table.
boolean _relate()
Broker function for writing relationships.
boolean _clear_relationship(string $reltype, mixed $related_id, [ int $relid ])
Clears a relationship from the database.
void _write_relationship(string $reltype, mixed $related_id, [ int $relid ])
Relates $this->record_id to a related id.
boolean _write()
Performs the update / insert query.
void _add_privs()
Adds privs to 'priv' table on insert of new record.
void send_event_notification(string $trigger)
Sends the specified trigger, and relevant record information to the event dispatcher
void _prepare()
Warning: documentation is missing.

Fields inherited from pxdb_confront

$_imported, $validator, $_upload_fields, $_params, $_widget_params, $_data, $data_name_structure, $param_name_structure, $widget_param_name_structure

Fields inherited from pxdb_data

$debug, $errors, $datatype, $auth, $tpl, $show_unapproved, $db, $user_minimal_columns

Public Field Summary

string $default_priv
The default priv assigned for everyone (gid 0).
boolean $auth_required
Whether authentication module must be bound.
$save_type
The type of save operation that was performed.

Private Field Summary

array $_related
Relationships that will be saved to db.
array $_record
Fields that will be saved to db.
array $_original_record
Saved copy of pre-change record.
string $mysql_password_function
The MySQL function to use to encrypt passwords.
array $_uploaded_files
Files that were uploaded.
array $_modified_fields
records columns that were modified by current save() action.

Included files Summary, Type: include

$gpath Warning: documentation is missing.

Public Method Details

pxdb_commit

public void pxdb_commit([ integer $id ])

 

Parameter
integer $id = >>null<<
The record id.
Returns void


get_id

public integer get_id()

 

Returns integer

The record id.


set_id

public void set_id(integer $id)

 

Parameter
integer $id
The record id.
Returns void


lookup_datatype

public int lookup_datatype(int $rec_id)

 

Parameter
int $rec_id
Record ID
Returns int

datatype ID


get_datatype

public integer get_datatype()

 

Warning: documentation is missing.

Returns integer

The datatype.


set_datatype

public void set_datatype(integer $dt)

 

Warning: documentation is missing.

Parameter
integer $dt
The datatype.
Returns void


read

public void read()

 

Returns void


import

public void import([ array $source ])

 

Warning: documentation is missing.

Parameter
array $source = >>null<<
The location of source data to use. (for upward compatibility with pxdb::import())
Returns void


validate

public boolean validate()

  This method is public and can be invoked separately. If you invoke this method you can expect to find the validation errors (array) in the global variable $pxdb['validator']. This array is automatically read-in by the pxdb_input class.

Returns boolean

True on success and false on error.


get_modified_fields

public array get_modified_fields()

  This will be set after the save method has been called. Note: it's not particularly useful after an insert(), since all fields will have been modified.

Returns array

Fields that were modified.


is_changed

public boolean is_changed(string $field, mixed $value)

  This method compares the value entered with $_original_record and returns true if they are not equal and false if they are.

Parameter
string $field
The field we are examining.
mixed $value
The new value for the field.
Returns boolean

true /false if changed


get_save_type

public string get_save_type()

 

Returns string

'insert' or 'update'


save

public boolean save()

  This method loads up the $related and $record arrays, then calls the methods that perform the db updates and inserts.

Returns boolean

on success.


add_related

public void add_related(mixed $related_id, int $relid)

 

Parameter
mixed $related_id
This is the record ID (or array of IDs) we are relating the current record to.
int $relid
This is the relid.
Returns void


add_secondaryrel_related

public void add_secondaryrel_related(mixed $related_id)

 

Parameter
mixed $related_id
This is the record ID (or array of IDs) we are relating the current record to.
Returns void


add_child

public void add_child(mixed $related_id, [ int $noderel_id ])

 

Parameter
mixed $related_id
This is the record ID (or array of IDs) we are relating the current record to.
int $noderel_id = >>null<<
The noderel ID of the noderel relationship type. Defaults to null for backward compatibility
Returns void


add_parent

public void add_parent(mixed $related_id, [ int $noderel_id ])

 

Parameter
mixed $related_id
This is the record ID (or array of IDs) we are relating the current record to.
int $noderel_id = >>null<<
The noderel ID of the noderel relationship type. Defaults to null for backward compatibility
Returns void


approve

public boolean approve()

  Tests to make sure that bound user has write access to this record & appropriate priv level to approve records of this datatype. -- Assuming yes, sets the approved column to 1.

Returns boolean

, false on error


unapprove

public boolean unapprove()

  Tests to make sure that bound user has write access to this record & appropriate priv level to approve records of this datatype. -- Assuming yes, sets the approved column to 0.

Returns boolean

, false on error


set_approval_status

public void set_approval_status(boolean $bit)

 

Parameter
boolean $bit
Approval bit for record.
Returns void


set_field

public boolean set_field(string $field, mixed $value, [ boolean $quote ])

  This is for manually writing a record to the database -- bypassing any input forms. Note that unless you set a record_id, it is assumed that you are inserting a new record. The datatype must be set before this function is invoked. -- You can do this with the set_datatype() method -- or it will happen automatically if you are editing an existing record. You may gets strange behavior if you are trying to overwrite a value set via a form and you do not use an identifier to specify the field.

Parameter
string $field
The fname -- or identifier -- of column we are adding.
mixed $value
The value for the new parameter..
boolean $quote = >>true<<
Whether to quote the string (assumes that all values should be quoted)
Returns boolean

true /false on success.


is_rlevel_authorized

public boolean is_rlevel_authorized(integer $record_id)

 

Parameter
integer $record_id
The ID of the record we are checking.
Returns boolean

Whether or not current user has specified privs.


is_flevel_authorized

public boolean is_flevel_authorized(integer $field_id)

 

Parameter
integer $field_id
The typesfield id of the field we are checking.
Returns boolean

Whether a user has specified access to specified field


set_default_priv

public void set_default_priv(mixed $priv)

  If empty, then no priv w/ ugid '0' will be inserted. The default is 'read,write'.

Parameter
mixed $priv
String or array containing the privileges to set.
Returns void


grant_priv

public boolean grant_priv(int $ugid, mixed $priv)

 

Parameter
int $ugid
The user/group id (from records table)
mixed $priv
A string or array containing privilegs e.g. 'read,write' or array('read', 'write').
Returns boolean

True or False (with $errors[] added)


revoke_priv

public boolean revoke_priv(int $ugid)

  By default it uses values in $_imported array, but can also be passed parameters -- for revoking privilegs internally.

Parameter
int $ugid
The user/group id (from records table)
Returns boolean

True or False (with $errors[] added)


delete_related

public boolean delete_related(mixed $relid, [ mixed $dt ])

  This function must be called manually. -- or you must override this class and redefine delete() to call this function *first*.

Parameter
mixed $relid
The integer relid or array of relids (only applicable to primaryrel relationships).
mixed $dt = >>null<<
The datatype of related records.
Returns boolean

true /false on success.


delete_secondaryrel_related

public boolean delete_secondaryrel_related([ mixed $dt ])

  This function must be called manually. -- or you must override this class and redefine delete() to call this function *first*.

Parameter
mixed $dt = >>null<<
The integer relid or array of relids (only applicable to primaryrel relationships).
Returns boolean

true /false on success.


delete_children

public Array delete_children([ boolean $purge_records, int $parent ])

  Note that this will recursively delete *all* rows from noderel that are subordinate (children) nodes of this record in the noderel table. This is different from standard delete() method in that, the standard method only removes the top node, essentially shifting everything up in the heirarchy. You may also pass a non false variable (i.e. type matters) as the first paramter to tell it to also purge the corresponding rows from records table. (dangerous!) relationship

Parameter
boolean $purge_records = >>false<<
Whether to remove records from records table (in addition to noderel).
int $parent = >>null<<
Used by the recursion to track the current $parent. Defaults to $this->record_id if false.
Returns Array

hash containing number of rows deleted (affected) for each table.


delete

public mixed delete()

  This method does not delete any related or children records. If you want to do this, you must either call those delete methods individually, or extend this class and override this method to call those delete methods before calling parent::delete().

Returns mixed

Boolean false on failure, array of affected rows on success


Private Method Details

__wakeup

private void __wakeup()

 

Returns void


_cleanup

private boolean _cleanup()

  This function was created by the need to rename files with the record id -- which can only be done once the record has been written (in the case of adding records). This function could call any other functions that depended on the record being written.

Returns boolean

True /False on success.


_calculate_autogen_fields

private boolean _calculate_autogen_fields()

  This method relies on pxdb_input specifying a ['autogen'] array containing identifiers for autogen fields that should be handled by this script. This script processes the autogen field from typesfields and updates the records table with the results.

Returns boolean

True /false on success.


_include_generator

private mixed _include_generator(string $plugin_data, array &$data)

 

Parameter
string $plugin_data
The plugin name for the generator we want to include and any params.
array &$data
Hash of data to pass to autogen function.
Returns mixed


_handle_uploaded_files

private boolean _handle_uploaded_files()

  This function requires that you have set a path for your files in the pxdb_prefs table (pref_name = 'datastore'; pref_key = 'path' and pref_key = 'url' for the filesystem path and relative URL respectively). If no datastore pref is found, then it will try to put files to directory where current script (class file) is located -- and that probably won't work. OAM - Aug 2005. Updated and created a constant PXDB_FILESTORE_PATH that is set in config/initialize.php.

Returns boolean


_get_filestore_paths

private array _get_filestore_paths()

 

Returns array

Array of filestore path strings, or boolean false if none found

Author(s) Sandy Smith <ssmith@forumone.com>

_populate_usergroup

private boolean _populate_usergroup()

  The usergroup table is a hack so that you can authenticate against a Syntax instance using a tool like mod_auth_mysql -- which requires a more straightforward user-group relationship table than the primaryrel table can provide.

Returns boolean


_relate

private boolean _relate()

  This function loops through the related array and calls the _clear_relationship() and write_relationship() methods which actually performs the db queries.

Returns boolean


_clear_relationship

private boolean _clear_relationship(string $reltype, mixed $related_id, [ int $relid ])

  This is only for relationships which are being set through the HTML form -- which means right now only primaryrel and pickrel actually can be cleared.

Parameter
string $reltype
This is text describing the relationship: 'primaryrel', 'pickrel', 'noderel', 'secondaryrel'
mixed $related_id
This is the record ID (or array of IDs) we are relating the current record to.
int $relid = >>null<<
This is the relid (if type is primaryrel) or the f_id (if pickrel).
Returns boolean


_write_relationship

private void _write_relationship(string $reltype, mixed $related_id, [ int $relid ])

  Note that the record must have already been written before this function can be called; i.e. if we are inserting a record we need to know the record id before we can then relate that record.

Parameter
string $reltype
This is text describing the relationship: 'primaryrel', 'pickrel', 'noderel', 'secondaryrel'
mixed $related_id
This is the record ID (or array of IDs) we are relating the current record to.
int $relid = >>null<<
This is the relid (if type is primaryrel) or the f_id (if pickrel).
Returns void


_write

private boolean _write()

 

Returns boolean

true /false on success.


_add_privs

private void _add_privs()

 

Returns void


send_event_notification

private void send_event_notification(string $trigger)

 

Parameter
string $trigger
name
Returns void


_prepare

private void _prepare()

 

Warning: documentation is missing.

Returns void


Public Field Details

$default_priv

public string $default_priv

>>'read,write'<<


$auth_required

public boolean $auth_required

>>false<<


$save_type

public $save_type

>>null<<

(e.g. insert or update)


Private Field Details

$_related

private array $_related

>>array()<<


$_record

private array $_record

>>array()<<


$_original_record

private array $_original_record

>><<


$mysql_password_function

private string $mysql_password_function

>>'ENCRYPT'<<


$_uploaded_files

private array $_uploaded_files

>>array()<<


$_modified_fields

private array $_modified_fields

>>array()<<


Included Files, Type: include

$gpath

include( $gpath )



Packageindex Classtrees Modulegroups Elementlist Report XML Files
Generated on Fri, 28 Apr 2006 19:07:22 -0400 by PHPDoc v1.5 www.phpdoc.de