Class Properties and Methods - Cms.class.php
This class has two primary functionalities. It routs views to the manage & edit models, and it manipulates $_POST[] data. Each method is calibrated to take data either from URL parameters to produce the corresponding views, or $_POST[] to update corresponding tables using an Sql object. Some methods can be further calibrated site-by-site to rout certain ways as needed. For instance, if a table view calls the Cms object to create a nested table within, on updating, editing, or deleting, the child table can be routed to the parent table.
Properties
Methods
- public static function printTable($table, $where = array(), $types = '', $vals = '')
- Takes a table from admin / views / manage and outputs its HTML & scripts
- Optionally filter the output based on $where[] conditions input through the parameters
- Returns: String. The full content of a php file located in admin/views/manage, grabbed via include() and set to $output variable. (Link to table view documentation here)
- Parameters
- $table
- Mandatory
- Sets which table to print from in the database
- Some views, such as media (file manager home), have no table in the database, and thus the view is a simple html template that calls the plugin. A script will detect whether or not it should call the Sql class to produce content
- $where
- Optional
- Sets column to filter values from
- Sometimes, certain rows need to be filtered from the table being printed, such as when an entry has an active vs inactive column. Usually the view calls two tables-- one collapsed that shows all inactive entries, the other active that shows all active entries
- $types
- Optional
- Corresponds to $vals being input when filtering using $where
- $vals
- Optional
- Corresponds to columns being picked w/ $where
- public static function printEditor($table, $ID, $row)
- Take a form from admin -> views -> edit and output its HTML / inline scripts
- Returns: String. The full content of a php file located in admin/views/edit, grabbed via include() and set to $output variable. (Link to table view documentation here).
- Check in-line on the view whether $row is set, and use tertiary comparisons to either fill the field or leave it blank.
- Parameters:
- $table
- Mandatory
- Sets which table to pull data from
- $ID
- Optional
- I... I can't remember why this here. I think the initial framework used this to differentiate between an add and an update, but the next parameter makes that distinction in practice. I think I can safely phase this out.
- $row
- Mandatory
- The Edit model retrieves data from the row being worked on. This parameter feeds the data to the Edit view that's being printed.
- Can be empty; the view should distinguish between a row with data and an empty row to distinguish between content being updated and content being made.
- public static function getIDCol($table)
- Helper method to grab the ID column name of whichever table is being manipulated
- Uses SQL object to read from INFORMATION_SCHEMA.COLUMNS
- Returns: String. The name of the ID column, the primary key
- Parameters:
- $table
- Mandatory
- Sets which table to read the ID column from
- private function typesHelper($vals)
- Helper method to construct a types string for the SQL object to use when adding or updating content from an Edit view
- Returns: String. Data type indicator string for SQL object's bind_Prep() method
- Parameters:
- $vals
- Mandatory
- Must be an array. Method loops through each index, detecting its type, and adding a chunk of the type indicator string for each iteration
- public function addContent($table)
- Grabs $_POST from an Edit view on the Edit model, processes it, and feeds it to the SQL object to add to the database
- Returns: None. Calls the SQL object and feeds $_POST data to the insert methods
- Parameters:
- $table
- Mandatory.
- Sets which table to post the data from the view to
- Usually set via $_GET in the Edit model, the same way that printEditor and printTable get which table to print from
- Notes:
- Includes a destination route for where the admin lands after adding content. Switch statement, which by default, leads back to DIRADMIN . manage/$table - the table user is currently working in.
- However, if the table being added to is nested within another manage table, going directly to the manage/$table will lead to a manage page that only includes the child table information.
- Not to mention, if you are calling the CMS from the front for a user to add content to the database (event registrants, etc), we don't want them winding up on the admin side.
- Bypass this by including a switch block for the child table that routes back to the parent table
- public function updateContent($table)
- Grabs $_POST from an Edit view on the Edit model, processes it, and feeds it to the SQL object to add to the database
- Returns: None. Calls the SQL object and feeds $_POST data to the update methods. Functions much the same way as addContent(), but has additional processing for the ID column.
- Parameters:
- $table
- Mandatory.
- Sets which table to post the data from the view to
- Usually set via $_GET in the Edit model, the same way that printEditor and printTable get which table to print from
- Notes:
- Same routing deal as with addContent(). Has an additional default route for the Options table, since that page leads directly to its edit view.
- public function deleteContent($table, $col, $delete)
- Deletes an entry from a table. Most tables have a delete button under the actions column. This button is an onClick JavaScript function, which is scripted in admin/includes/standardHeadAdmin.php.
- The delpage function takes four parameters: id, title, loc, col. It constructs a link with two parameters, and a confirmation popup.
- window.location.href = '' + loc + '&delete=' + id + '&col=' + col;
- loc is current location, id is the ID of the entry being deleted, and col is the name of the ID column for the table
- On arriving back at the Manage view with the delete parameter set, this method is called and runs the SQL object delete method.
- Parameters:
- $table
- Mandatory
- Designates which table to delete from. Set by $_GET on the view
- $col
- Mandatory
- Designates which column the ID should match in the SQL object delete method
- $delete
- Mandatory
- ID of the row being deleted