Skip to content

Instantly share code, notes, and snippets.

@nibsirahsieu
Created April 10, 2012 08:10
Show Gist options
  • Save nibsirahsieu/2349253 to your computer and use it in GitHub Desktop.
Save nibsirahsieu/2349253 to your computer and use it in GitHub Desktop.

Revisions

  1. nibsirahsieu revised this gist Apr 10, 2012. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions gistfile1.aw
    Original file line number Diff line number Diff line change
    @@ -37,6 +37,7 @@ class myPropelOnDemandFormatter extends \PropelOnDemandFormatter
    return $result;
    }

    //taken from PropelSimpleArrayFormatter
    public function getStructuredArrayFromRow($row)
    {
    $columnNames = array_keys($this->getAsColumns ());
  2. nibsirahsieu created this gist Apr 10, 2012.
    55 changes: 55 additions & 0 deletions gistfile1.aw
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,55 @@
    <?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;
    }

    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;
    }
    }