collectionToJSON

Tags:
xpdo,

PHP Source Code

<?php
/**
 * Processes a collection of objects
 * @param array Collection of objects
 * @return array of JSON
 */
public function collectionToJSON($collection){
    /**
     * [ denotes an array
     * { denotes an object
     */
    if (!empty($collection)) {
        $o = '[';
        $c = 0;
        foreach ($collection as $obj) {
            if ($obj instanceof xPDOObject){
                $o .= ($c++ > 0) ? ', ' : '';
                $o .= $obj->toJSON();
            }
        }
        $o .= ']';
    }
    return ($o) ? $o : false;
}

Output of modManagerLog

[{"id":1,"user":1,"occurred":"2015-05-01 13:32:49","action":"package_install","classKey":"transport.modTransportPackage","item":"unknown"},
{"id":2,"user":1,"occurred":"2015-05-01 13:32:49","action":"package_install","classKey":"transport.modTransportPackage","item":"unknown"},
{"id":3,"user":1,"occurred":"2015-05-01 13:32:49","action":"package_install","classKey":"transport.modTransportPackage","item":"unknown"},
{"id":4,"user":1,"occurred":"2015-05-01 13:33:46","action":"template_update","classKey":"modTemplate","item":"1"},
{"id":5,"user":1,"occurred":"2015-05-01 13:35:01","action":"chunk_create","classKey":"modChunk","item":"2"},
{"id":6,"user":1,"occurred":"2015-05-01 13:35:43","action":"chunk_create","classKey":"modChunk","item":"3"},
{"id":7,"user":1,"occurred":"2015-05-01 13:36:37","action":"chunk_create","classKey":"modChunk","item":"4"},
{"id":8,"user":1,"occurred":"2015-05-01 13:37:13","action":"chunk_update","classKey":"modChunk","item":"4"},
{"id":9,"user":1,"occurred":"2015-05-01 13:37:24","action":"chunk_update","classKey":"modChunk","item":"4"},
{"id":10,"user":1,"occurred":"2015-05-01 13:38:02","action":"chunk_create","classKey":"modChunk","item":"5"},
{"id":11,"user":1,"occurred":"2015-05-01 13:39:04","action":"chunk_create","classKey":"modChunk","item":"6"},
{"id":12,"user":1,"occurred":"2015-05-01 13:44:40","action":"chunk_update","classKey":"modChunk","item":"6"},
{"id":13,"user":1,"occurred":"2015-05-01 13:45:18","action":"chunk_create","classKey":"modChunk","item":"7"},
{"id":14,"user":1,"occurred":"2015-05-01 13:45:24","action":"chunk_update","classKey":"modChunk","item":"7"},
{"id":15,"user":1,"occurred":"2015-05-01 14:16:33","action":"chunk_update","classKey":"modChunk","item":"6"},
{"id":16,"user":1,"occurred":"2015-05-01 14:18:06","action":"template_update","classKey":"modTemplate","item":"1"},
{"id":17,"user":1,"occurred":"2015-05-01 14:19:27","action":"chunk_update","classKey":"modChunk","item":"4"},
{"id":18,"user":1,"occurred":"2015-05-01 14:20:57","action":"template_update","classKey":"modTemplate","item":"1"},
{"id":19,"user":1,"occurred":"2015-05-01 14:21:17","action":"template_update","classKey":"modTemplate","item":"1"}]