views:

98

answers:

2

I've been working with ProjectPier, and found arrays like the following. How do I read this architecture with PHP?

ApplicationLog Object
(
[is_new:DataObject:private] => 
[is_deleted:DataObject:private] => 
[is_loaded:DataObject:private] => 1
[column_values:DataObject:private] => Array
    (
        [id] => 24
        [taken_by_id] => 1
        [project_id] => 2
        [rel_object_id] => 7
        [object_name] => screenshots
        [rel_object_manager] => ProjectFolders
        [created_on] => DateTimeValue Object
            (
                [timestamp:DateTimeValue:private] => 1264869022
                [day:DateTimeValue:private] => 30
                [month:DateTimeValue:private] => 1
                [year:DateTimeValue:private] => 2010
                [hour:DateTimeValue:private] => 16
                [minute:DateTimeValue:private] => 30
                [second:DateTimeValue:private] => 22
            )

        [created_by_id] => 1
        [action] => add
        [is_private] => 
        [is_silent] => 
    )
A: 

Well the top "entry" is an object, it is not an array. Only the output (probably print_r($object) makes it look like an array. The (real) interesting array is column_values which is marked as private.
If this attribute is supposed to be accessible from the outside, the object of class ApplicationLog should have a method to get this array e.g.

$column_values = $object->getColumnValues();

Then you can access the entries of this array with:

$column_values['id']; // gives 24

And again, to access the DateTimeValue object, there must be some accessor methods like:

$month = $values['created_on']->getMonth();

Note: I don't know the accessor methods, this is just an example. You have to have a look at the API documentation or the source code of the classes to get the actual methods.

Felix Kling
+3  A: 

I downloaded ProjectPier and searched for the ApplicationLog class, (application/models/application_logs/ApplicationLog.class.php and application/models/application_logs/base/BaseApplicationLog.class.php)

which offers you a variety of getters (and setters):

function getTakenBy()
function getTakenByDisplayName() 
function getProject()
function getText() 
function getObject() 
function getObjectUrl() 
function getObjectTypeName()
function getId()
function getTakenById()
function getProjectId()
function getRelObjectId() 
function getObjectName() 
function getRelObjectManager()
function getCreatedOn() 
function getCreatedById()
function getAction() 
function getIsPrivate()
function getIsSilent()
function manager() 

You can access the column_values['id'] for example by $applicationLog->getId().

Karsten
Thanks for the detailed list!
konzepz