Now that you have learned how to instantiate the object and how to interact with content items:

... let's see a few more capabilities!

"setOptions" method

After instantiating the object, one call to the setOptions method will allow you to change the default behaviour of the class.

$content = new JCckContentArticle; 
$ops       = array(
                     'check_permissions'=>0,
                  );
$content->setOptions( $opts );

// Do something

JCckContent natively supports SEBLOD permissions: "Create" for the create method, "Edit" / "Edit Own" for the store method, ...

Depending on the context, from where you call the methods, you may need to bypass the permissions check. The above code does it for you. Of course in most cases, we strongly suggest to apply the right permissions directly on the Content Type, without bypassing permissions programatically.



"preset" method

If you need to migrate content from an old site to your brand new SEBLOD site, you'll find JCckContent class to be a great tool for doing it.
Assuming you have imported the old tables into the same database with PhpMyAdmin, and executed a query to retrieve all your items (with the right aliases), you'll use the create method.

$content = new JCckContentArticle;
$default  = array(
                     'catid'=>2,
                     'state'=>1
                  );

foreach ( $items as $item ) {
    unset( $item->id );
    $data  = (array)$item;

    if ( $content->preset( $default )->create( $content_type, $data )->isSuccessful() ) {
        // Do something
    }

One call to the preset method prior create, will allow you to set the default values of your content item.



"import" method

What if you had some existing Joomla! content items that you wished to convert to SEBLOD content items?
Yes the import method is what you are looking for!

$content = new JCckContentCategory;

if ( $content->import( $content_type, $pk )->isSuccessful() ) {
    // Do something
    echo $content->getPk();