@@ -24,15 +24,36 @@ class DAO {
2424 /**
2525 * Constructor.
2626 * @param Database $database - the database object
27- * @param string $tableName - the table name this object will handle (can include #__ as prefix)
28- * @param string $modelClass - the name of the class that rows will be converted to (optional, default is \stdClass).
29- * @param string $idColumn - the name of the integer, auto-incremental primary key column (optional, default is uid)
27+ * @param string $tableName - the table name this object will handle (can include #__ as prefix)
28+ * @param string $modelClass - the name of the class that rows will be converted to (optional, default is \stdClass).
29+ * @param string $idColumn - the name of the integer, auto-incremental primary key column (optional, default is uid)
30+ * @param boolean $checkTable - whether to check existance of table and create if required (optional, default is FALSE)
3031 */
31- public function __construct ($ database , $ tableName , $ modelClass = 'stdClass ' , $ idColumn = 'uid ' ) {
32+ public function __construct ($ database , $ tableName , $ modelClass = 'stdClass ' , $ idColumn = 'uid ' , $ checkTable = FALSE ) {
3233 $ this ->database = $ database ;
3334 $ this ->tableName = $ tableName ;
3435 $ this ->modelClass = class_exists ($ modelClass ) ? $ modelClass : 'stdClass ' ;
3536 $ this ->idColumn = $ idColumn ;
37+ if ($ checkTable ) $ this ->checkTable ();
38+ }
39+
40+ /**
41+ * Checks the underlying table for existance and calls #createTable() if it does not exist.
42+ * @return boolean TRUE when table exists or was created successfully.
43+ */
44+ public function checkTable () {
45+ if (!$ this ->tableExists ()) {
46+ return $ this ->createTable ();
47+ }
48+ return TRUE ;
49+ }
50+
51+ /**
52+ * Creates the table. Default implementation does nothing and returns FALSE.
53+ * @return TRUE when table was created successfully.
54+ */
55+ public function createTable () {
56+ return FALSE ;
3657 }
3758
3859 /**
0 commit comments