Utility classes
miUtil class contains only two methods - getDBArray() and sendEmail(). Examples for using them follows
* getDBArray() example
<?php
// After execution $userNames will be associative array.
// For each element key is the value of UserID field, and value - the value of UserName field.
$userNames = miUtil::getDBArray('SELECT UserID, UserName FROM Users', 'UserID', 'UserName');
print_r($userNames);
// Will output something similar to:
// Array
// (
// [3] => John Smith
// [4] => John Doe
// [7] => Evan Sims
// )
?>
* sendEmail() example
<?php
$to = 'someone@google.com';
$from = 'me@google.com';
$subject = 'This is a test e-mail';
$body = 'This is the email body text';
miUtil::sendEmail($to, $from, $subject, $body)
?>
miUIUtil class has four methods - templetizeRows(), transposeRows(), createDropdownFilter() and getConstDropdown()
* transposeRows() and templetizeRows() are used when array retrieved from recordset object will be used with template section object
<?php
// Get the records from the database
$idArray = array('1', '3', '5');
$recordset = new miSqlRecordset('Users');
$recordset->addFilter(new miSqlFilterIn($idArray));
$records = $recordset->getRecords();
// Prepare the template section object
$recordsCount = sizeof($records);
$records = miUIUtil::templetizeRows(miUIUtil::transposeRows($records));
$section = new miTemplateParserSectionInfo('records', $recordsCount, $records);
?>
* Add drop-down filter in the table
<?php
class ClientTaskDataManager extends miDataManager {
public function addTableFeatures($table)
{
parent::addTableFeatures($table);
// Prepare the filter options
$taskStatuses = array(
'all' => 'All',
'completed' => 'Completed',
'not_completed' => 'Not completed'
);
// Create the actual drop-down filter
miUIUtil::createDropdownFilter($this, $table, 'TaskStatus', $taskStatuses, 'taskStatus');
// Link the filter clause with corresponding SqlFilter class
$this->getTableFilterObj()->setConditionHandler('taskStatus', 'TaskStatusSqlFilter');
}
}
?>
* Create a static (not database driven) select box
<?php
class EmployeeTaskDataManager extends miDataManager {
public function addTableFeatures($table)
{
parent::addTableFeatures($table);
// Prepare the select box options
$taskStatuses = array(
'' => 'Select new status',
'inprogress' => 'In Progress'
'waiting' => 'Waiting'
'completed' => 'Completed',
);
// Get the select box HTML code
$selectBox = miUIUtil::getConstDropdown('ChangeStatusTo', '', $taskStatuses);
// Add it as a table element
$table->assign('%%HTML_CHANGESTATUSTODRODOWN%%', $selectBox);
}
}
?>