Created
April 10, 2012 08:10
-
-
Save nibsirahsieu/2349253 to your computer and use it in GitHub Desktop.
custom propelondemandformatter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Egov\DeliveryBundle\Util; | |
class myPropelOnDemandFormatter extends \PropelOnDemandFormatter | |
{ | |
protected $isSelect = false; | |
public function init(\ModelCriteria $criteria) | |
{ | |
parent::init($criteria); | |
if (!is_null($criteria->getSelect())) { | |
$this->isSelect = true; | |
} | |
return $this; | |
} | |
public function isObjectFormatter() | |
{ | |
return !$this->isSelect; | |
} | |
public function getAllObjectsFromRow($row) | |
{ | |
$result = null; | |
if ($this->isSelect) { | |
if ($object = $this->getStructuredArrayFromRow($row)) { | |
$result = $object; | |
} | |
} else { | |
$result = parent::getAllObjectsFromRow($row); | |
} | |
return $result; | |
} | |
//taken from PropelSimpleArrayFormatter | |
public function getStructuredArrayFromRow($row) | |
{ | |
$columnNames = array_keys($this->getAsColumns ()); | |
if (count($columnNames) > 1 && count($row) > 1) { | |
$finalRow = array(); | |
foreach ($row as $index => $value) { | |
$finalRow[str_replace('"', '', $columnNames[$index])] = $value; | |
} | |
} else { | |
$finalRow = $row[0]; | |
} | |
return $finalRow; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment