Umfragen
db Class Reference

database class, handles all database stuff More...

Public Member Functions

 __construct ($dbuser, $dbpass, $dbname, $dbhost)
 get_sql_all_assoc ($sql)
 makes a databse query and returns an array or results
 get_poll_name_from_list ($polls)
 gets a mapping array of ID to name of a pollist
 get_all_polls_array ()
 gets an array of all polls
 get_all_polls_array_from_status ($stat)
 get_poll_infoArray ($pollID)
 gets an infoarray for a specific poll
 get_poll_result_for_user ($pollID, $username)
 gets the pollresult from a user
 get_widget_names ($pollID)
 gets a list of all widget names from a poll
 get_config_array ()
 gets all config variable stored in the database
 count_results ($pollID)
 simple result count
 get_schedule_widget_data ($widget)
 gets a list of data for the schedule widget
 export_to_csv (poll $poll, $delimiter, $enclosure, $download=true)
 exports results to csv
 export_result ($pollID, $sort="", $order="asc")
 exports the result table according to sort criteria
 load_child_from_parentID ($pollID, $ID, $whitelist)
 loads all childs which have the same parent ID. used by db::load_widget()
 load_widget ($pollID, $ID)
 loads a specific widget completely with options
 load_poll ($pollID)
 loads the widget_list, an array of all widgets from a poll
 insert_widget (&$w, $pollType)
 inserts a widget and sets it's ID
 insert_poll (&$p, $create_result_table=true)
 inserts a poll with its widgets and sets the pollID.
 make_umfragen_table ()
 creates the table where all polls are stored
 make_user_config_table ()
 creates the table where all polls are stored
 make_config_table ()
 creates the table where some settings are stored
 make_email_stack_table ()
 creates the table where some settings are stored
 check_tables ()
 checks if all vital tables are there (not complete)
 duplicate_poll ($pID)
 duplicates a poll
 duplicate_widget ($pID, $wID)
 duplicates a widget in a specific poll
 rename_result_column ($pollID, $long_result, $old_name, $new_name)
 renames a column in the result table of a poll
 add_widget_to_result_table ($widget)
 adds a widget to the result table according to its nature
 make_void_result_table (poll $poll)
 makes a clean result table for a poll.
 make_poll_result_table (poll $poll)
 makes a complete result table including widgets
 add_all_widgets_to_poll_result_table (poll $poll)
 adds all widgets to a (clean) pollresult table
 insert_poll_result ($poll2)
 inserts a complete result record in the result table
 klassenliste ($au, $poll)
 makes a list of users into the results table
 garbage_collect_result_table (poll $poll)
 deletes unused and empty columns in the result table
 get_visited_polls_for_user ($user)
 get a list of polls a user has visited and participated in
 garbage_collect_visited_polls ($user)
 remove deleted pollIDs from the list of visited polls of a user, does not update the database
 update_visited_polls ($user, $pollID)
 appends a pollID to the list of visited polls for a user
 remove_visited_poll ($user, $pollID)
 appends a pollID to the list of visited polls for a user
 mass_update_widget ($wlist)
 updates the database records of a list of widgets
 update_widget_field ($w, $field, $data)
 updates a specific database column of a widget
 update_poll_field ($ID, $field, $data)
 updates a specific database column of a poll
 update_user_config_field ($user, $field, $data)
 updates a specific database column of a user_config
 email_stack_add ($data)
 adds a email event on the email stack table
 email_stack_get ()
 get the next entry from the email stack, does not delete it from the database
 email_stack_get_all ()
 gets all entries from the email stack array of array of results
 email_stack_del ($ID)
 deletes an entry from the emails stack
 update_config_field ($name, $value)
 updates a specific database column of the config table
 load_user_config_field ($user, $field)
 loads a specific database column of a user_config
 update_widget_name ($widget, $new_name)
 updates a widget::name in the result table and the widgets table
 convert_polltype_S2A ($poll)
 converts the polltype of a poll from simple to advanced
 convert_polltype_A2S ($poll)
 converts the polltype of a poll from advanced to simple
 is_results_empty ($pid)
 checks if there is data in the result table (apart from the standard fields as username...)
 anonymize_results ($pollID)
 does nothing
 drop_poll ($id)
 deletes the widget table of a poll
 drop_poll_results ($id)
 deletes the result table trom a poll
 delete_poll ($id)
 deletes the row from umfragen table of a poll
 delete_widget ($pollID, $wID)
 deletes a widget from a poll
 delete_result_for_user_list ($pollID, $username_list)
 deletes the row in the result table of a poll belonging to users from a list
 delete_all_result ($pollID)
 deletes all results bot not the result table from a poll

Data Fields

 $dbh
 holds the PDO connection to the database
 $last_poll_insert_id = -1

Detailed Description

database class, handles all database stuff

this object is intended to be used as singleton per page

Definition at line 37 of file db.class.php.

Constructor & Destructor Documentation

__construct (   $dbuser,
  $dbpass,
  $dbname,
  $dbhost 
)

constructor, connects directly to the database server and stores the reference

Definition at line 45 of file db.class.php.

Member Function Documentation

add_all_widgets_to_poll_result_table ( poll  $poll)

adds all widgets to a (clean) pollresult table

Parameters
poll$poll
Returns
return value of PDO::exec()

Definition at line 1054 of file db.class.php.

add_widget_to_result_table (   $widget)

adds a widget to the result table according to its nature

Parameters
widget$widget
Returns
result of PDO::exec()

Definition at line 990 of file db.class.php.

anonymize_results (   $pollID)

does nothing

Parameters
int$pollID
Returns
NULL

Definition at line 1773 of file db.class.php.

check_tables ( )

checks if all vital tables are there (not complete)

Returns
array indexed by tablename and with bools as value

Definition at line 795 of file db.class.php.

convert_polltype_A2S (   $poll)

converts the polltype of a poll from advanced to simple

Parameters
poll$poll
Returns
NULL

Definition at line 1709 of file db.class.php.

convert_polltype_S2A (   $poll)

converts the polltype of a poll from simple to advanced

Parameters
poll$poll
Returns
NULL

Definition at line 1688 of file db.class.php.

count_results (   $pollID)

simple result count

Parameters
int$pollID
Returns
mixed: array, false on failure

Definition at line 168 of file db.class.php.

delete_all_result (   $pollID)

deletes all results bot not the result table from a poll

Parameters
int$pollIDpollID
Returns
bool true

Definition at line 1861 of file db.class.php.

delete_poll (   $id)

deletes the row from umfragen table of a poll

Parameters
int$idpollID
Returns
bool true

Definition at line 1809 of file db.class.php.

delete_result_for_user_list (   $pollID,
  $username_list 
)

deletes the row in the result table of a poll belonging to users from a list

Parameters
int$pollIDpollID
array$username_listlist of usernames
Returns
bool true on success, false on failure

Definition at line 1836 of file db.class.php.

delete_widget (   $pollID,
  $wID 
)

deletes a widget from a poll

Parameters
int$pollIDpollID
int$wIDthe widget ID
Returns
bool true

Definition at line 1821 of file db.class.php.

drop_poll (   $id)

deletes the widget table of a poll

Parameters
int$idpollID
Returns
bool true

Definition at line 1787 of file db.class.php.

drop_poll_results (   $id)

deletes the result table trom a poll

Parameters
int$idpollID
Returns
bool true

Definition at line 1798 of file db.class.php.

duplicate_poll (   $pID)

duplicates a poll

Parameters
int$pIDpollID
Returns
poll or NULL on failure

Definition at line 836 of file db.class.php.

duplicate_widget (   $pID,
  $wID 
)

duplicates a widget in a specific poll

Parameters
int$pIDpollID
int$wIDthe widgets ID
Returns
NULL when poll not found, int new widget ID when successfull

Definition at line 891 of file db.class.php.

email_stack_add (   $data)

adds a email event on the email stack table

Parameters
array$dataan array with data we want to write into the database
Exceptions
exceptionif the values in the array are not set

the array needs following indexes: pollID, type, fullName, uname

Definition at line 1561 of file db.class.php.

email_stack_del (   $ID)

deletes an entry from the emails stack

Parameters
string$IDthe email stack table ID of the element bool true

Definition at line 1604 of file db.class.php.

email_stack_get ( )

get the next entry from the email stack, does not delete it from the database

Returns
array on success, false on error

Definition at line 1580 of file db.class.php.

email_stack_get_all ( )

gets all entries from the email stack array of array of results

Definition at line 1593 of file db.class.php.

export_result (   $pollID,
  $sort = "",
  $order = "asc" 
)

exports the result table according to sort criteria

Parameters
string$pollIDthe Id of the poll
string$sorta column name we want to sort by
$ordereither "asc" or "desc" for the order of the sort
Returns
array of arrays indexed by column name of the database or empty array on failure

Definition at line 409 of file db.class.php.

export_to_csv ( poll  $poll,
  $delimiter,
  $enclosure,
  $download = true 
)

exports results to csv

Parameters
poll$poll
string$delimiterThe delimiter used for the CSV
string$enclosureThe enclosureused for the CSV
bool$downloadTrue if the file is for download. Uses HTTP header!
Returns
NULL

Definition at line 357 of file db.class.php.

garbage_collect_result_table ( poll  $poll)

deletes unused and empty columns in the result table

Parameters
poll$poll
Returns
bool true on succes, false on failure

Definition at line 1288 of file db.class.php.

garbage_collect_visited_polls (   $user)

remove deleted pollIDs from the list of visited polls of a user, does not update the database

Parameters
string$userthe username of the user
Returns
array new list

Definition at line 1373 of file db.class.php.

get_all_polls_array ( )

gets an array of all polls

Returns
array of arrays indexed by database colnames

Definition at line 97 of file db.class.php.

get_all_polls_array_from_status (   $stat)
Parameters
int$statstatusID as defined in the configfile
Returns
array of array indexed by database columnames

Definition at line 107 of file db.class.php.

get_config_array ( )

gets all config variable stored in the database

Returns
array indexed by database columnames "name" and "value"

Definition at line 154 of file db.class.php.

get_poll_infoArray (   $pollID)

gets an infoarray for a specific poll

Parameters
int$pollID
Returns
array indexed by columnames from database

Definition at line 117 of file db.class.php.

get_poll_name_from_list (   $polls)

gets a mapping array of ID to name of a pollist

Parameters
array$pollslist with pollIDs
Returns
array indexed by ID with poll names

Definition at line 80 of file db.class.php.

get_poll_result_for_user (   $pollID,
  $username 
)

gets the pollresult from a user

Parameters
int$pollID
string$username
Returns
array indexed by database columnames

Definition at line 128 of file db.class.php.

get_schedule_widget_data (   $widget)

gets a list of data for the schedule widget

Parameters
widget$widgetthe schedule widget we want the data from
Returns
array indexed by childID containing other array 0indexed containing values

Definition at line 317 of file db.class.php.

get_sql_all_assoc (   $sql)

makes a databse query and returns an array or results

Parameters
string$sqla valid SQL query string
Returns
array of arrays indexed by column names, returned by the PDO driver

Definition at line 66 of file db.class.php.

get_visited_polls_for_user (   $user)

get a list of polls a user has visited and participated in

Parameters
string"user" the username of the user
Returns
array

Definition at line 1357 of file db.class.php.

get_widget_names (   $pollID)

gets a list of all widget names from a poll

Parameters
int$pollID
Returns
array indexed by database columnames "name" + "ID"

Definition at line 141 of file db.class.php.

insert_poll ( $p,
  $create_result_table = true 
)

inserts a poll with its widgets and sets the pollID.

Parameters
poll$p
bool$create_result_table,=falsenot used anymore
Returns
poll or false on failure

Definition at line 658 of file db.class.php.

insert_poll_result (   $poll2)

inserts a complete result record in the result table

uses a clone of the poll object and inserts there the matrixQuestion objects

Parameters
poll$poll2
Returns
array with keys "value" (bool true -> success) and "action" which is either "update" or "insert"

Definition at line 1073 of file db.class.php.

insert_widget ( $w,
  $pollType 
)

inserts a widget and sets it's ID

Parameters
widget&$w
int$pollTypeprovided by configfile: simple or advanced
Returns
bool success of the PDO execution.

Definition at line 550 of file db.class.php.

is_results_empty (   $pid)

checks if there is data in the result table (apart from the standard fields as username...)

Parameters
int$pidpollID
Returns
bool true the result tabe is "empty", false there is min one record

Definition at line 1730 of file db.class.php.

klassenliste (   $au,
  $poll 
)

makes a list of users into the results table

Parameters
auth$au(LSAP OR MYSQL authentification object)
poll$poll
Returns
NULL

Definition at line 1221 of file db.class.php.

load_child_from_parentID (   $pollID,
  $ID,
  $whitelist 
)

loads all childs which have the same parent ID. used by db::load_widget()

Parameters
int$pollID
int$IDthe parent ID
array$whitelistwhitelist of widget types which are allowed as child ("*" -> no restriction)
Returns
array of matrixQuestion, bool false on failure

Definition at line 457 of file db.class.php.

load_poll (   $pollID)

loads the widget_list, an array of all widgets from a poll

Parameters
int$pollID
Returns
array of widgets

Definition at line 522 of file db.class.php.

load_user_config_field (   $user,
  $field 
)

loads a specific database column of a user_config

Parameters
int$userthe username
mixed$fieldthe column name to be updated if $field is an array of strings, then a array of results will be returned. The "*" wildcard works.
Returns
mixed data, string then fetching one column, indexed array by fieldname when multiple fields are given

Definition at line 1645 of file db.class.php.

load_widget (   $pollID,
  $ID 
)

loads a specific widget completely with options

Parameters
int$pollID
int$IDthe ID of the widget
Returns
widget , bool false on failure

Definition at line 489 of file db.class.php.

make_config_table ( )

creates the table where some settings are stored

Returns
bool true

Definition at line 761 of file db.class.php.

make_email_stack_table ( )

creates the table where some settings are stored

Returns
bool true

Definition at line 775 of file db.class.php.

make_poll_result_table ( poll  $poll)

makes a complete result table including widgets

Parameters
poll$poll
Returns
return of PDO::exec()

Definition at line 1027 of file db.class.php.

make_umfragen_table ( )

creates the table where all polls are stored

Returns
bool true

Definition at line 717 of file db.class.php.

make_user_config_table ( )

creates the table where all polls are stored

Returns
bool true

Definition at line 745 of file db.class.php.

make_void_result_table ( poll  $poll)

makes a clean result table for a poll.

standard colums:

  • user
  • name
  • group
  • Datum
    Parameters
    poll$poll
    Returns
    result of PDO::exec()

Definition at line 1010 of file db.class.php.

mass_update_widget (   $wlist)

updates the database records of a list of widgets

Parameters
array$wlistlist of widget objects
Returns
NULL

Definition at line 1450 of file db.class.php.

remove_visited_poll (   $user,
  $pollID 
)

appends a pollID to the list of visited polls for a user

Parameters
string$userthe username of the user
string$pollIDthe ID we want add
Returns
bool true on success, false on failure

Definition at line 1433 of file db.class.php.

rename_result_column (   $pollID,
  $long_result,
  $old_name,
  $new_name 
)

renames a column in the result table of a poll

Parameters
int$pollID
string$widgettypethe type of the widget in string form
string$old_namethe old name of the column
string$new_namethe new name of the column
Returns
result of PDO execute

Definition at line 975 of file db.class.php.

update_config_field (   $name,
  $value 
)

updates a specific database column of the config table

Parameters
string$namethe variable name to save
string$valuethe data we want store. mostly serialized
Returns
bool true on succes, false on failure

Definition at line 1615 of file db.class.php.

update_poll_field (   $ID,
  $field,
  $data 
)

updates a specific database column of a poll

Parameters
int$IDthe pollID
string$fieldthe column name to be updated
mixed$datathe value to be set
Returns
bool true on succes, false on failure

Definition at line 1522 of file db.class.php.

update_user_config_field (   $user,
  $field,
  $data 
)

updates a specific database column of a user_config

Parameters
int$userthe username
string$fieldthe column name to be updated
mixed$datathe value to be set
Returns
bool true on succes, false on failure

Definition at line 1534 of file db.class.php.

update_visited_polls (   $user,
  $pollID 
)

appends a pollID to the list of visited polls for a user

Parameters
string$userthe username of the user
string$pollIDthe ID we want add
Returns
bool true on success, false on failure

Definition at line 1402 of file db.class.php.

update_widget_field (   $w,
  $field,
  $data 
)

updates a specific database column of a widget

Parameters
widget$w
string$fieldthe column name to be updated
mixed$datathe value to be set
Returns
bool true on succes, false on failure

Definition at line 1501 of file db.class.php.

update_widget_name (   $widget,
  $new_name 
)

updates a widget::name in the result table and the widgets table

Parameters
widget$widget
string$new_namethe name to be set
Returns
NULL

Definition at line 1674 of file db.class.php.

Field Documentation

$dbh

holds the PDO connection to the database

Definition at line 39 of file db.class.php.

$last_poll_insert_id = -1

Definition at line 40 of file db.class.php.


The documentation for this class was generated from the following file: