Working with Calendar Dimension

Operating system requirements: iOS 5.0 or later.

Mobile device: iPad.

Description

This example describes some methods of working with calendar dimension. After starting the example the following operations are executed:

Source Code

Executing the example requires to place the following code in the body of the executeExample method of the ViewController class (see the Data Analysis section):

// Get all data dimensions
SNArray allDimensions = [self allDimensions];
for (int i = 0; i < allDimensions->count(); ++i) {
    SPPLDimension dimension = allDimensions->objectAtIndex<PPLDimension>(i);
    // Select calendar dimension
    if (dimension->type() == PPLDimension::kCalendarDimension) {
        // Create a calendar dimension
        SPPLCalendarDimension calDim = new PPLCalendarDimension();
        calDim = dimension->qClass<PPLCalendarDimension>();
        
        // Get calendar dimension data levels
        SPPLCalendarDimensionDataLevels levels = calDim->dataLevels();
        // Determine number of data levels
        SNArray items = levels->items();
        printf ("Number of data levels: %d \n", items->count());
        
        // Get base level of calendar dimension data
        SPPLCalendarDimensionDataLevel baseDataLevel = levels->baseDataLevel();
        printf("Base data level identifier: %lld \n", baseDataLevel->id());
        
        // Determine identifier and name of first data level
        PPLCalendarDimensionDataLevel dataLevel = *items->objectAtIndex(0)->qClass<PPLCalendarDimensionDataLevel>();
        printf("First data level identifier: %lld \n", dataLevel.id());
        SNString name = dataLevel.name();
        printf("Data level name: %s \n", name->UTF8String());
        
        // Create a data level container by means of default designer
        SPPLCalendarDimensionDataLevels dataLevels1 = new PPLCalendarDimensionDataLevels();
        printf("Number of data levels in empty container: %d \n", dataLevels1->items()->count());
        
        // Create a default data level with the 5 identifier
        SNDictionary description = NDictionary::dictionaryWithObjectForKey(NNumber::numberWithInt(5), NStr("id"));
        SPPLCalendarDimensionDataLevel defaultDataLevel = PPLCalendarDimensionDataLevel::dataLevel(description);
        // Create an array of data levels
        SNArray dataLevels = NArray::arrayWithObject(defaultDataLevel);
        SPPLCalendarDimensionDataLevels dataLevels2 = new PPLCalendarDimensionDataLevels(dataLevels);
        printf("Number of data levels in the second container: %d \n", dataLevels2->items()->count());
        for (int i = 0; i < dataLevels2->items()->count(); i++) {
            SPPLCalendarDimensionDataLevel calDataLevel = dataLevels2->items()->objectAtIndex<PPLCalendarDimensionDataLevel>(i);
            printf("Data level container №%d: %lld \n", i, calDataLevel->id());
        }
        
        // Create a periodic calendar dimension
        SPPLCalendarPeriodDimension periodDimension = new PPLCalendarPeriodDimension();
        SPPLCalendarDimension baseDimension = periodDimension->baseDimension();
        if (baseDimension != NULL) {
            printf("Base data level identifier: %lld \n", baseDataLevel->id());
            } else {
            printf("Base dimension is not defined \n");
        }
        // Get periodic calendar dimension settings
        SNID plist = periodDimension->generatePlist();
        if (plist != NULL) {
            SNDictionary plistDict = plist->qClass<NDictionary>();
            } else {
            printf("List of periodic calendar dimension settings is empty");
        }
    }
}

After executing the example the development environment console displays information on the obtained calendar dimension and the created periodic calendar dimension:

Number of data levels: 1

Base data level identifier: 1

First data level identifier: 1

Data level name: Years

Number of data levels in empty container: 0

Number of data levels in the second container: 1

Data levels identifier №0: 5

Base dimension is not defined

List of periodic calendar dimension settings is empty

See also:

Example of pplib++ Library Use