Text Schema (v. 1.2, 2.0)

Text Schema is a data structure used to define content type. For example, in your personal website, you have a 'News' content. So you define one schema "News" with the element of Title, Body and Author. In a normal ASP.NET development, this can be considered as a table in the database. Actually, Kooboo creates a new table in the database when you create a new schema.

Schema definition will generate a content input form. Text schema can include or refer to other Text Schema or Binary Schema. In the <<Quick start>> document, we already talked about the basic of Text Schema.

1. Column definition



Add path: Application --> SiteManager --> Schema --> Text, click "New" button to add a new text schema
Kooboo add text schema
Schema definition page looks like:
Kooboo text schema editing
In the "Columns" tab, move your mouse to any of the columns such "name" or "label", a down arrow will appear. Click on the arrow will open below screen.
Kooboo text schema advanced
Name, Label, DataType and ControlType are the common settings of a field. Besides that, there are some more advanced settings.

ColumnId: System generated value
UUID: System generated value
OriginalUUID: System generated value
Name: How you name your field, also the data key for accessing content from API.
Label: The text label that will appear on the content input form.
DataType: The datatype of this field, like string, date or number.
Length: The length of your data. This feature will be used in the future versions.
ControlType: The type of control to use when generating the schema content input form. Advanced user can define their own ControlType using JavaScript. Example ControlTypes are text, checkbox and htmleditor.
Selection Items: The items to be used for dropdown or checkbox value. Value format are: name1:::value1|name2:::value2
VisibleInList: If checked, this column will appear in the CMS content list page.
DefaultValue: Default value of this field.
Allownull: Allow null value.
CMS search: Whether this field will be included in the search field within this CMS backend or not.
Search Index: Include in the index file available for front end site search.
Modifiable: Can this column data editable in the editing form. When false, field can not be modified after creation.
SortOrder: DESC or ASC. By default content is sorted by the modify date
VType: Built-in basic validation group. Currently Kooboo has alpha, alphanum, email and url. It can be extended using JavaScript.
Validation Group: Self defined validation group.
Template: HTML template to display this item in the content list page. You can use {fieldname} to represent the field value. For example: <a href="{link}">{author}</a>

System columns: Some fields are required by system. Those fields are generated by system and can not be removed. Those columns can be used on value condition query or other purposes. Below is the list of System columns.

ContentId: Int, incremental ID
UUID: Guid, The universal identity of this content. GUID is used for the reason of deployment possibility.
ApplicationId: Guid, The application universal identity.
UserName: String, content update user.
Title: String, name of title of the content.
ModifiedDate: Datetime, last modified date time.
PostDate: Datetime, content creation date.
ContentStatus: Int, content status. There are two status right now, 0=draft, 1= published.
UserKey: String, user defined key, can be used for SEO URL. See below advanced setting.

2. Advanced setting


Click the "Advanced" tag, you will some advance settings.
Kooboo text schema advanced screen
User Key
If checked, content input form will contain a field called "User key". This key can be used for data query. It can be useful in scenarios like using the user key as a query string in the URL for SEO friendly and user friendly URL. In case that you did not check this option, system still generate a user key. It will use the content title. When there are duplicated titles, an additional number starting from 1 will be appended to the content title.

File included
When checked, the content input form will include a file upload box. You can upload unlimited number of files into this content item. The uploaded files will be accessible via our API method. Exactly same as accessing Binary Schema content. The API method is ContentService.GetAttachments. Please refer to Binary Schema document.

File extension
Allowed file extension to be uploaded. For example: "jpg|gif".
Note: If you would like to include fixed amount of files in your Text Schema, you can use the ControlType: file.

Binary Schema
Reference to a Binary Schema. Similar as a Text Schema reference (Category), a selection window will appear to select related Binary content same as "Category" content. ContentService.GetAttachments method is provided to access Binary Schema content. See Binary Schema document for more information.

Child Schema
Text content to be included within current content item. This is used for sub content of one content item. For example, one blog may have one or more comments. Comment is sub content of blog, one comment only belongs to one blog.

To use a Child schema, you have to add that child schema first. For example, for Schema blog to include comment, we first need to create a schema called "comment". After that we will be able to include "Comment" as a child schema for blog.
Kooboo text schema child schema
When a Child schema is defined, the content input form will include a sub form for child content. You can go to one content folder, and click one item:

You can get the below screen.
Kooboo text schema sub content
Sub content can be edited in CMS, sometimes may be added by user at front end site. For example, blog comment added at front end. Kooboo offer APIs for read & write sub contents. Below is an example method.
 
public IDictionary AddSubContent(int parentId, string schemaName, string userName, NameValueCollection values, HttpFileCollectionBase files);

More information regarding the API can be found at Kooboo API reference chm file in the download section of Kooboo website.

Category
One content can refer to or belong to another content. This is similar as a foreign key in database table. It creates a "many to many" relation between two content items. The most common situation is products belong to one or more categories and students belong to one or more classes. "many to many" can be used for "1 to many" relation as well, there is no constraint rules implemented yet for the content relation.

We call this "category" because content editor seems like can understand category easier than a relation or other words.

Adding a category schema is similar as a child schema, you need to create both schemas first and then make the relation between them.

In the content input form, category schema will appear as a selection window. Data Rule can be used to get Categories based on one content or get contents based on one category. API access is also possible.
category selection
Click the "select" will open the category content selection window as below screen. Windows on the left is the source to select from, window on right is the selected item window. You can drag & drop, double click or use the arrow to make the selection.
Kooboo category selection window

3. Validation rule and group



There are some built in Validation groups named Vtype. A validation Group contain one or more validation rules. Validation rule can be created using JavaScript. You can assign validation groups to a Schema field. When adding content, this field needs to pass validation check defined in the validation group.

Define Validation Rule
First you need to define validation rule using JavaScript. Below is an example of a validation rule.
 
    function(value) {

        if (value.length < 10)
        return "the value must more than 10 letters";
        return true;

    }

When validation failed, it should return an error message. When success, return true.

Define Validation Group
You can combine one or more validation rules into a Validation Group. In the schema definition page, check "Validation Group", and then on that field, select the group you just created.
Kooboo text schema validation group
After a Validation Group is assigned, the validation will be active during editing of that field.

4. Function


You can define your own function to be used on content list or detail page. On schema definition page, click "function" menu, then click "New" button to add a new user define function. There is only one Method defined in the interface, and a number of objects you can use to update "content".
Kooboo text schema function
Name: Can be anything.
Event: When select "list page" or "detail page", this function will appear as a menu in the CMS content list or detail page. When select "After Insert", "After Update" or "Before Delete", this function will be executed on the selected event.
Script: Standard .NET code run as a Script. There is some sample code to update content values when creating a function. You can modify to fit your needs.

After a function is created, if you choose the "list page" or "detail page", you will be able to use your own function for content management. For example, go to the schema content list page, right click an item, you can see the function you just created.
Kooboo Text schema custom function
Important note: In order to use Text Schema custom function, the "Trust Level" of your ASP.NET application must be run in "Full Trust". When you own a dedicated server, Full Trust is the default setting, if you use hosting packages, most of the time, it is running under Medium Trust level.