PHP Source Code

<?php

/**
 * File viewModel.php
 * Created on: Shawn at 2:38 PM
 * Project shawn_wilkerson
 * @package
 * @version
 * @category
 * @author W. Shawn Wilkerson
 * @link http://www.shawnWilkerson.com
 * @copyright Copyright (c) 2012, Sanity LLC. All rights reserved.
 * @license
 *
 */

$out = false;
$lookup = $modx->getOption('class', $scriptProperties, '');
if (!empty($lookup)) {
    $object = $modx->newObject($lookup);
    if (is_object($object)) {
        $out = '<h2>Output (with added headings):</h2>';
        $out .= '<h3>Table Fields</h3>';
        $out .= '<pre>' . print_r(array_keys($modx->getFields($lookup)), true) . '</pre>';
        $out .= '<h3>Table Construction (meta)</h3>';
        $out .= '<pre>' . print_r($modx->getFieldMeta($lookup), true) . '</pre>';
        $out .= '<h3>Attached Aggregate Tables</h3>';
        $out .= '<pre>' . print_r($modx->getAggregates($lookup), true) . '</pre>';
        $out .= '<h3>Attached Composite Tables</h3>';
        $out .= '<pre>' . print_r($modx->getComposites($lookup), true) . '</pre>';
        $out .= '<h3>Class Derived from (Ancestors)</h3>';
        $out .= '<pre>' . print_r(array_reverse($modx->getAncestry($lookup)), true) . '</pre>';
        $out .= '<h3>Class Extended to (Descendants)</h3>';
        $out .= '<pre>' . print_r($modx->getDescendants($lookup), true) . '</pre>';
    }
}
return $out;

Comments

Initially I utilized MODX Placeholders for the output, but decided to hard cord the presentation as not everyone who implements xPDO will be using MODX Revolution.

Recently, I have had an influx of requests to build third-party applications to attach to those already in operation and thought there to be a need for a simple reference for one developer to interact with another.

Note: $modx may have to replaced with $xpdo depending on the scope of your application.

Implementation using modUser

Output (with added headings):

Table Fields

Array
(
    [0] => id
    [1] => username
    [2] => password
    [3] => cachepwd
    [4] => class_key
    [5] => active
    [6] => remote_key
    [7] => remote_data
    [8] => hash_class
    [9] => salt
    [10] => primary_group
    [11] => session_stale
    [12] => sudo
    [13] => createdon
)

Table Construction (meta)

Array
(
    [id] => Array
        (
            [dbtype] => INTEGER
            [phptype] => integer
            [null] => 
            [index] => pk
            [generated] => native
            [attributes] => unsigned
        )

    [username] => Array
        (
            [dbtype] => varchar
            [precision] => 100
            [phptype] => string
            [null] => 
            [default] => 
            [index] => unique
        )

    [password] => Array
        (
            [dbtype] => varchar
            [precision] => 100
            [phptype] => string
            [null] => 
            [default] => 
        )

    [cachepwd] => Array
        (
            [dbtype] => varchar
            [precision] => 100
            [phptype] => string
            [null] => 
            [default] => 
        )

    [class_key] => Array
        (
            [dbtype] => varchar
            [precision] => 100
            [phptype] => string
            [null] => 
            [default] => modUser
            [index] => index
        )

    [active] => Array
        (
            [dbtype] => tinyint
            [precision] => 1
            [phptype] => boolean
            [attributes] => unsigned
            [null] => 
            [default] => 1
        )

    [remote_key] => Array
        (
            [dbtype] => varchar
            [precision] => 255
            [phptype] => string
            [null] => 1
            [index] => index
        )

    [remote_data] => Array
        (
            [dbtype] => text
            [phptype] => json
            [null] => 1
        )

    [hash_class] => Array
        (
            [dbtype] => varchar
            [precision] => 100
            [phptype] => string
            [null] => 
            [default] => hashing.modPBKDF2
        )

    [salt] => Array
        (
            [dbtype] => varchar
            [precision] => 100
            [phptype] => string
            [null] => 
            [default] => 
        )

    [primary_group] => Array
        (
            [dbtype] => int
            [precision] => 10
            [phptype] => integer
            [attributes] => unsigned
            [null] => 
            [default] => 0
            [index] => index
        )

    [session_stale] => Array
        (
            [dbtype] => text
            [phptype] => array
            [null] => 1
        )

    [sudo] => Array
        (
            [dbtype] => tinyint
            [precision] => 1
            [phptype] => boolean
            [attributes] => unsigned
            [null] => 
            [default] => 0
        )

    [createdon] => Array
        (
            [dbtype] => int
            [precision] => 20
            [phptype] => timestamp
            [null] => 
            [default] => 0
        )

)

Attached Aggregate Tables

Array
(
    [CreatedResources] => Array
        (
            [class] => modResource
            [local] => id
            [foreign] => createdby
            [cardinality] => many
            [owner] => local
        )

    [EditedResources] => Array
        (
            [class] => modResource
            [local] => id
            [foreign] => editedby
            [cardinality] => many
            [owner] => local
        )

    [DeletedResources] => Array
        (
            [class] => modResource
            [local] => id
            [foreign] => deletedby
            [cardinality] => many
            [owner] => local
        )

    [PublishedResources] => Array
        (
            [class] => modResource
            [local] => id
            [foreign] => publishedby
            [cardinality] => many
            [owner] => local
        )

    [SentMessages] => Array
        (
            [class] => modUserMessage
            [local] => id
            [foreign] => sender
            [cardinality] => many
            [owner] => local
        )

    [ReceivedMessages] => Array
        (
            [class] => modUserMessage
            [local] => id
            [foreign] => recipient
            [cardinality] => many
            [owner] => local
        )

    [PrimaryGroup] => Array
        (
            [class] => modUserGroup
            [local] => primary_group
            [foreign] => id
            [cardinality] => one
            [owner] => foreign
        )

)

Attached Composite Tables

Array
(
    [Acls] => Array
        (
            [class] => modAccess
            [local] => id
            [foreign] => principal
            [cardinality] => many
            [owner] => local
        )

    [Profile] => Array
        (
            [class] => modUserProfile
            [local] => id
            [foreign] => internalKey
            [cardinality] => one
            [owner] => local
        )

    [UserSettings] => Array
        (
            [class] => modUserSetting
            [local] => id
            [foreign] => user
            [cardinality] => many
            [owner] => local
        )

    [UserGroupMembers] => Array
        (
            [class] => modUserGroupMember
            [local] => id
            [foreign] => member
            [cardinality] => many
            [owner] => local
        )

    [ActiveUsers] => Array
        (
            [class] => modActiveUser
            [local] => id
            [foreign] => internalKey
            [cardinality] => many
            [owner] => local
        )

)

Class Derived from (Ancestors)

Array
(
    [0] => xPDOObject
    [1] => xPDOSimpleObject
    [2] => modPrincipal
    [3] => modUser
)

Class Extended to (Descendants)

Array
(
)

Implementation using xPDOObject base class

Output (with added headings):

Table Fields

Array
(
)

Table Construction (meta)

Array
(
)

Attached Aggregate Tables

Array
(
)

Attached Composite Tables

Array
(
)

Class Derived from (Ancestors)

Array
(
    [0] => xPDOObject
)

Class Extended to (Descendants)

Array
(
    [0] => xPDOSimpleObject
    [1] => modAccessibleObject
    [2] => modActiveUser
    [3] => modCategoryClosure
    [4] => modContextSetting
    [5] => modContextResource
    [6] => modDashboardWidgetPlacement
    [7] => modElementPropertySet
    [8] => modEvent
    [9] => modFormCustomizationProfileUserGroup
    [10] => modPluginEvent
    [11] => modSession
    [12] => modSystemSetting
    [13] => modTemplateVarTemplate
    [14] => modUserGroupSetting
    [15] => modUserSetting
    [16] => CollectionResourceTemplate
    [17] => CollectionSelection
    [18] => TaggerTagResource
    [19] => modAccess
    [20] => modAccessPolicy
    [21] => modAccessPolicyTemplate
    [22] => modAccessPolicyTemplateGroup
    [23] => modAccessPermission
    [24] => modActionField
    [25] => modClassMap
    [26] => modContentType
    [27] => modDashboard
    [28] => modDashboardWidget
    [29] => modFormCustomizationProfile
    [30] => modFormCustomizationSet
    [31] => modLexiconEntry
    [32] => modManagerLog
    [33] => modExtensionPackage
    [34] => modPrincipal
    [35] => modPropertySet
    [36] => modResourceGroupResource
    [37] => modTemplateVarResource
    [38] => modTemplateVarResourceGroup
    [39] => modUserGroupMember
    [40] => modUserGroupRole
    [41] => modUserMessage
    [42] => modUserProfile
    [43] => modWorkspace
    [44] => CollectionSetting
    [45] => CollectionTemplate
    [46] => CollectionTemplateColumn
    [47] => TaggerGroup
    [48] => TaggerTag
    [49] => modAccessAction
    [50] => modAccessActionDom
    [51] => modAccessCategory
    [52] => modAccessNamespace
    [53] => modAccessContext
    [54] => modAccessElement
    [55] => modAccessMenu
    [56] => modAccessResource
    [57] => modAccessResourceGroup
    [58] => modAccessTemplateVar
    [59] => modUser
    [60] => modUserGroup
    [61] => modAccessibleSimpleObject
    [62] => modContext
    [63] => modMenu
    [64] => modNamespace
    [65] => modAction
    [66] => modActionDom
    [67] => modCategory
    [68] => modElement
    [69] => modResource
    [70] => modResourceGroup
    [71] => modChunk
    [72] => modScript
    [73] => modTemplate
    [74] => modTemplateVar
    [75] => modPlugin
    [76] => modSnippet
    [77] => modDocument
    [78] => modStaticResource
    [79] => modSymLink
    [80] => modWebLink
    [81] => modXMLRPCResource
    [82] => CollectionContainer
    [83] => modJSONRPCResource
    [84] => SelectionContainer
)

Postulation

By moving upwards in the ancestors of modUser we can quickly find other classes with similar base properties. Also, notice the new classes added to the site via Packages being shown (i.g. CollectionContainer, modJSONRPCResource, SelectionContainer and others).

In this article