Skip to content

Instantly share code, notes, and snippets.

@nibsirahsieu
Created April 10, 2012 08:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nibsirahsieu/2349253 to your computer and use it in GitHub Desktop.
Save nibsirahsieu/2349253 to your computer and use it in GitHub Desktop.
custom propelondemandformatter
<?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