Ning Developer Network

Ning Developer Admin

Ning PHP API

The Ning PHP API includes classes to deal with objects in the Ning Platform, in particular around Content, Users, and Applications, as well as lower level elements like HTTP Requests. While the Reference section of this website is the best place to find specific information on specific topics, this page gives an overview of the main classes and their uses.

XN_Profile

An XN_Profile represents a Ning user.

XN_Application

An XN_Application object contains the metadata related to a network on Ning, also called applications.

XN_Content

Each XN_Content object represents a single object in the Ning content store.

XN_Content instances contain both system attributes (most of which are read-only) and user-defined attributes.

System Attributes

System attributes in XN_Content include:

  • type, a string, set when the object is created that defines the object's type. Read-only after the first time set.
  • title, a string, set after content creation. (writable)
  • description, a string, set after content creation (writable).
  • createdDate, date when the content was created, formatted as YYYYMMDDTHH:MM:DD where T and : are separators. Read-only.
  • updatedDate, date when the content was last updated, formatted as YYYYMMDDTHH:MM:DD where T and : are separators. Every time the content object is saved, the updated date will change automatically. Read-only.
  • owner, the XN_Application that owns this content. Read-only.
  • ownerName, the subdomain of the XN_Application that owns this content. Read-only.
  • id, a unique string ID for this object, read-only.

User-Defined Attributes

Attributes and properties are accessed through the same mechanisms, ie, as simulated instance variables accessed through the '->' operator using the magic __get and __set methods, and also through transformer methods such as content, htmlentities, and transform. Explicit get/set/add/remove attribute methods are provided for functionality not achievable through the '->' mechanism and also can be used in a method-chaining style of invocation. Set/add/remove content methods are provided as helper functions for manipulating content references.

XN_Tag

XN_Tag objects represent tags stored in the Ning Content Store, and associated with Content Objects (XN_Content).

Properties

  • public content = 'content' Read-only object property: the content tagged with this tag.
  • public contentId = 'contentId' Read-only string property: the id of the content tagged with this tag.
  • public createdDate = 'createdDate' Read-only string property: the created date of format YYYYMMDDTHH:MM:DD where T and : are separators.
  • public id = 'id' Read-only string property: the id.
  • public owner = 'owner' Read-only object property: the owner XN_Profile object.
  • public ownerId = 'ownerId' Read-only string property: the owner profile id.
  • public ownerName = 'ownerName' Read-only string property: the owner profile screen name.
  • public updatedDate = 'updatedDate' Read-only string property: the updated date of format YYYYMMDDTHH:MM:DD where T and : are separators.
  • public value = 'value' Read-only string property: the tag value.

Methods

  • public array addTags( $object, $tagString ) Adds the tags in a tag string to an object
  • public boolean checkTags( $tagString ) Determines whether any of the tag words in a string are syntactically invalid.
  • public create( $value, $content ) Static factory that creates and returns a new XN_Tag object of the given name for the given XN_Content object.
  • public string debugHtml( ) Returns a string debug representation of this XN_Tag object within an HTML pre tag.
  • public string debugString( ) Returns a string debug representation of the XN_Tag object.
  • public array deleteTags( $object, $tagString ) Deletes the tags in a tag string from an object. Just as addTags
  • public boolean isValidTagName( $tagName ) Determines whether a string is a valid Tag name
  • public boolean|array parseTagString( $tagString, [$check = false] ) Builds an array of Tag names from a string. Allows for double quotes to enclose Tag names with spaces, commas, or semicolons in them.
  • public Tag save( ) Saves this XN_Tag object to the database.
  • public array tagNamesFromTags( $tags ) Turns an array of XN_Tag objects into an array of string tag names

XN_Query

The XN_Query class is used for querying objects in the Ning Content Store.

Queries are created specifying the subject of the query. The possible query subjects are given by the SUBJECT constants. Filters are added for constraining the query, and ordering may be specified for the results. Paging of the query results can be set by specifying the begin and end positions for the results, and the query can also be set to always return the total count of possible results (it normally only returns the total count when the begin position is 0 or omitted).

Constants

  • public EIC = 'eic' The operator for an 'equal-ignore-case' constraint.
  • public EQ = '=' The operator for an 'equal' constraint.
  • public GE = '>=' The operator for a '>=' constraint.
  • public GT = '>' The operator for a '>' constraint.
  • public IN = 'in' The operator for an 'in' constraint.
  • public LE = '<=' The operator for a '<=' constraint.
  • public LIKE = 'like' The operator for a 'like' constraint.
  • public LIKEIC = 'likeic' The operator for an 'ignore-case like' constraint.
  • public LT = '<' The operator for a '<' constraint.
  • public NE = '<>' The operator for a 'not-equal' constraint.
  • public NEIC = 'neic' The operator for a 'not-equal-ignore-case' constraint.
  • public SUBJECT_CONTENT = 'Content' The subject name for querying content objects.
  • public SUBJECT_CONTENT_COUNT = 'Content_Count' The subject name for querying content rollups
  • public SUBJECT_TAG = 'Tag' The subject name for querying tag objects.
  • public SUBJECT_TAG_VALUECOUNT = 'Tag_ValueCount' The subject name for querying the counts of tag values. Tag_ValueCount queries return an array in which each element's key is a tag value and each element's value is a count of tags with the tag value.

Methods

  • public alwaysReturnTotalCount( [$always = false] ) Controls whether a count of the total number of objects that match the
  • public begin( $begin ) Sets the zero-based position of the first object to retrieve relative to the total count of possible query results. The default is 0.
  • public create( $subject ) Constructs a new XN_Query object for the given subject. The supported subjects are given by the SUBJECT constants.
  • public string debugHtml( ) Returns a string debug representation of the XN_Query object within an HTML pre tag.
  • public string debugString( ) Returns a string debug representation of the XN_Query object
  • public end( $end ) Sets the zero-based position +1 of the last object to retrieve relative to the total count of possible query results. The default is the beginning position + 100.
  • public array execute( [$returnIds = false] ) Executes the query and returns an array of objects or ids of the subjects that match the query or an empty array if there are no subjects found.
  • public filter( $prop, [$operator = null], [$value = null], [$type = null] ) Filters the query with the given constraint. Multiple filters can be applied to a query.
  • public int getResultFrom( ) Returns the zero-based integer position of the first object in the returned list of results relative to the total count of possible query results. Is always the same as the begin position.
  • public int getResultSize( ) Returns the number of objects in the returned result set. Is always equal to getResultTo minus getResultFrom.
  • public int getResultTo( ) Returns the zero-based integer position +1 of the last object in the returned list of results relative to the total count of possible query results.
  • public int getTotalCount( ) If the begin position is 0 or alwaysReturnTotalCount is true, returns the total count of objects that match the query without bounds constraints.
  • public order( $prop, [$direction = null], [$type = 'string'] ) Adds a sort order for the query results. Depending on the subject of the query, multiple sort orders can be applied to the query result.
  • public printDebugHtml( ) Prints a string debug epresentation of the XN_Query object within an HTML pre tag.
  • public rollup( $prop ) Specifies the rollup field for Content_Count queries
  • public mixed uniqueResult( [$returnIds = false] ) Convenience method to return a single object or id of the subject that matches the query or null if there is no matching subject.

    Example 1

    Returns an array of content objects owned by the current application of a type equals-ignore-case "test" with a my->group attribute equal to "front" and a my->rating attribute >= 0. The result array is ordered by descending my->rating sorted as a number
     $contents = XN_Query::create('content')    ->filter( 'owner' )
        ->filter( 'type', 'eic', 'test' )
        ->filter( 'my->group', '=', 'front' )
        ->filter( 'my->rating', '>=', 0 )
        ->order( 'my->rating', 'desc', XN_Attribute::NUMBER )
        ->execute();
    
    

    Example 2

    Returns an array of anonymous content objects that have a my->comment attribute and ordered by ascending count of my->comment attributes
     $contents = XN_Query::create('content')    ->filter( 'contributor', '=', null )
        ->filter( 'my->comment', 'like', '%' )
        ->order( 'count(my->comment)', 'asc' )
        ->execute();
    

XN_Request

The XN_Request class provides access to information about the current request.

Methods:

  • uploadedFileContents ($name)

    Static factory that provides access to the raw file contents of a post that would normally be accessed through $_FILE.

    Parameters

    $name
    string, the file name (e.g. $_POST['name'])

    Return

    string, the file contents

    Usage

    ( imported from this techblog post by Tim)

    Let's say you've got a form like:

    <form method="POST" enctype="multipart/form-data" action="upload.php">
    <input type="file" name="myFile"/>
    <input type="submit"/>
    </form>


    If you want to assign the contents of the file to a variable in PHP, rather than saying:


    $contents = $_FILE['myFile'];

    instead say:


    $contents = XN_Request::uploadedFileContents($_POST['myFile']);

    And don't forget the enctype="multipart/form-data"! (I do that every time...)

Last updated by Ning Developer Admin May 9.

Documentation & Tips

© 2008   Created by Ning Developer Admin

Badges  |  Report an Issue  |  Privacy  |  Terms of Service