Sorry this is a rather long PHP 4.2.3 class. Bottom line is that I have this class that can be called statically or instantiated, and I am trying to come up with the best possible model (Java-based) for this, and this is what I hacked together in 2 minutes.
I personally feel this could be done better, but I don't know how it can be done better, so ideas a re greatly appreciated.
Thanx
Phil
/**
* Generate an array of objects much like those created by MySQLQuery::getResult() with database and non-database information combined into a single
* single-structured object array
*
* @author Phil Powell
* @version 1.0.0
* @package
*/
class EditResultGenerator extends MethodGeneratorForActionPerformer {
/**
* @access private
* @var DBActionPerformer $dbAP
*/
var $dbAP;
/**
* @access private
* @var SortArrayFieldExtractor $safe
*/
var $safe;
/**
* @access private
* @var EditResultGenerator $self
*/
var $self;
/**
* Constructor. This class is normally called statically and thus not often (if ever) instantiated
*
* @access public
*/
function EditResultGenerator() { // CONSTRUCTOR
$this->dbAP = new DBActionPerformer();
$this->safe = new SortArrayFieldExtractor(0); // PLACEHOLDER PARAMETER
}
//-------------------------------------------- --* GETTER/SETTER METHODS *-- ------------------------------------------------
/**
* Retrieve $displayArray from $_SESSION variable and destroy session
*
* @access public
* @return array $displayArray
*/
function &getDisplayArray() { // STATIC ARRAY METHOD
}
/**
* Retrieve a single row from an array of objects to return as an object
*
* @access private
* @param object $result array of objects
* @return object $obj single row of $result array of objects
*/
function &getResultObject($result) { // STATIC OBJECT METHOD
return $obj;
}
/**
* Return an array of objects combining metadata-resulted db array with non-metadata-resulted directory array
*
* *NOTE* This class' main method will self-generate if need be
*
* @access public
* @param mixed $album optional
* @param int $sort optional
* @return object $result array of objects
* @see MySQLQuery
*/
function &getResult($album = '', $sort = '') { // STATIC ARRAY-OF-OBJECT METHOD
/*--------------------------------------------------------------------------------------------------------------------------------------------
This will combine the actions of returning an array of images with metadata along with images w/o metadata
into the schema-constructed object $result as an array of $result. This method will also be used as an EditView
instantiation by other classes as well
---------------------------------------------------------------------------------------------------------------------------------------------*/
global $section, $action, ${$section . 'LocationPath'}, $sortArray, $willPaginate, $displayItemLimit, $willUseVideoPointers;
foreach ($_REQUEST as $key => $val) if (!isset(${$key})) ${$key} = $val;
EditResultGenerator::generateSelf(); // GENERATE ITSELF
if (!$willKeepPageSession || $willFlushResult) $sectionArray = EditResultGenerator::getSectionArray($album);
// ONLY PRODUCE SORTING FIELD NAME AND DISPLAY RESULTS IF THERE IS EVENT DATA TO SORT
$hasObtainedField = false;
for ($i = 0; $i < @sizeof($sortArray[$section][$action]); $i++) {
$this->self->safe = new SortArrayFieldExtractor($i);
if (is_numeric($sort) && (int)$sort === $i)
$field = $this->self->safe->getField(); // $sort WILL REMAIN INT UNTIL MATCH IS MADE THEN = FIELD STRING
$displayArray[$i] = $this->self->safe->getDisplay();
if ($field && !$hasObtainedField) $hasObtainedField = true;
}
if (!$field && !$hasObtainedField) { // DEFAULT SET OF $field TO DEFAULT VALUE TO ENSURE PROPER SQL QUERY
$field = "upper(${section}_name) ";
$asc = 'asc'; // NOTE THAT $asc IS A VARIABLE THIS TIME TO ENSURE DESCENDING CHRONOLOGICAL DEFAULT ORDER OF EVENTS
}
if (!$willKeepPageSession || $willFlushResult) {
// OBTAIN QUERY RESULTS FROM ActionPerformer CUSTOMIZED SELECT STATEMENT BY USING MySQLQuery OBJECT INSTANCE INSTEAD OF select()
if (!$this->self->dbAP->getDBConn()) $this->self->dbAP->connect();
$query = new MySQLQuery($sql, $this->self->dbAP->getDBConn());
$result =@ $query->getResult();
if (mysql_error()) {
$this->self->isSuccessful = false;
$this->self->setErrorArray(array('action' => 'Unable to obtain metadata results: ' . nl2br(mysql_error())));
}
$query = null;
$this->self->dbAP->disconnect();
}
$hasResults = (is_array($result) && @sizeof($result) > 0) ? true : false;
if (!$hasResults && (!$willKeepPageSession || $willFlushResult)) $result = EditResultGenerator::getSkeletalResult(); // SEE NOTES ON THIS METHOD
if (!$willKeepPageSession || $willFlushResult) {
$sectionNonMetadataArray = $this->self->getSectionNonMetadataArray($sectionArray, $result); // FIND IMAGES/VIDEOS W/O METADATA
$this->self->setResultWithSectionArray($result, $sectionNonMetadataArray); // COMBINE INTO ONE ARRAY BOTH $result AND $sectionArray
if (!$hasResults) $junkObj = array_pop($result); // EMPTY DB ROW OBJECT ARRAY ELEMENT NEEDS TO BE REMOVED
}
$this->self->setDisplayArray($displayArray); // SET TO USE OUTSIDE OF THIS METHOD WITHIN EditView::displayHTML()
return $result;
}
/**
* Retrieve an array of images or videos depending on value of $section and on value of $album
*
* @access private
* @param mixed $album (optional)
* @param boolean $willParseIntoSQL (default false)
* @return array array of images/videos
* @see isAcceptableMimePrefix
* @see mime_content_type
*/
function &getSectionArray($album = '', $willParseIntoSQL = false) { // STATIC ARRAY METHOD
return $sectionArray;
}
/**
* Get section non-metadata and put into array generated by getSectionArray() method
*
* @access private
* @param array $sectionArray
* @param object $dbResultArray
* @return array
*/
function &getSectionNonMetadataArray($sectionArray, $dbResultArray) { // STATIC ARRAY METHOD
return array_diff($sectionArray, $tempSectionArray);
}
/**
* Retrieve the table "structure" w/o data as an array of objects in the same format as getResult() method
*
* @access private
* @return object $result skeletal result of fields - table structure only
*/
function &getSkeletalResult() { // STATIC ARRAY-OF-OBJECT METHOD
return $result;
}
/**
* Set $displayArray that can be inherited by other methods extending this class. Since class may not be instantiated you will set into $_SESSION variable
*
* @access private
* @param array $displayArray
*/
function &setDisplayArray($displayArray) { // STATIC VOID METHOD
global $projectAcronym;
}
/**
* Set result within the existing section array
*
* @access private
* @param object result reference array of objects
* @param array $sectionArray
*/
function &setResultWithSectionArray(&$result, $sectionArray) { // STATIC VOID METHOD
global $section;
$result = (@sizeof($tempResult) > 0) ? array_merge($tempResult, $result) : $result;
}
//-------------------------------------------- --* END OF GETTER/SETTER METHODS *-- ------------------------------------------------
/**
* Create an instance of itself if $this does not yet exist
*
* @access private
*/
function &generateSelf() { // STATIC VOID METHOD
if (!is_object($this->self)) $this->self =& new EditResultGenerator();
}
}