Automatically create a file set?

Permalink
Hi,

I'm developing a new theme, is there a way I can make the theme automatically create a file set with the name 'Background Image' when it is installed?
Obviously it should check if that set exists first then create it if necessary.

Thanks in advance :)

Dave

madesimplemedia
 
JohntheFish replied on at Permalink Best Answer Reply
JohntheFish
$fs = FileSet::createAndGetSet($name, $type, $uID = false)


as per

http://www.concrete5.org/documentation/developers/files/grouping-fi...
nebuleu replied on at Permalink Reply
nebuleu
According to
http://www.concrete5.org/documentation/developers/files/grouping-fi...
you can create a fileset with :
$fs = FileSet::createAndGetSet($name, $type, $uID = false)
Creates a new file set if set doesn't exist. Type may be one of the following
   FileSet::TYPE_PRIVATE
   FileSet::TYPE_PUBLIC
   FileSet::TYPE_STARRED


You can by example use this in your install() function of your controller.php package.
madesimplemedia replied on at Permalink Reply
madesimplemedia
That's the page I was looking for!
Thanks guys, much appreciated! :)
madesimplemedia replied on at Permalink Reply
madesimplemedia
Is it sufficient to add it in the controllers install function like this:

public function install() {
$pkg = parent::install();
$fs = FileSet::createAndGetSet('Background Image', FileSet::TYPE_PUBLIC, $uID = false);
PageTheme::add('street', $pkg);
}
JohntheFish replied on at Permalink Reply
JohntheFish
Yes, should be ok from a package controller as you have described.

As always, best to test it to make sure.
madesimplemedia replied on at Permalink Reply
madesimplemedia
Cool I'll test it later, thanks John!
madesimplemedia replied on at Permalink Reply
madesimplemedia
Tried to install it on a test site in WAMP and got this error:

( ! ) Fatal error: Class 'FileSet' not found in C:\wamp\www\street_theme\packages\street\controller.php on line 21

Here's my controller.php:
<?php   
defined('C5_EXECUTE') or die(_("Access Denied."));
class StreetPackage extends Package {
   protected $pkgHandle = 'street';
   protected $appVersionRequired = '5.5.2';
   protected $pkgVersion = '0.93';
   public function getPackageDescription() {
      return t("Installs Street theme.");
   }
   public function getPackageName() {
      return t("Street Theme");
   }
   public function install() {
      $pkg = parent::install();
      $fs = FileSet::createAndGetSet('Background Image', FileSet::TYPE_PUBLIC, $uID = false);
JohntheFish replied on at Permalink Reply
JohntheFish
It may be that the model is not loaded automatically at this stage.
Try
Loader::model('file_set');
madesimplemedia replied on at Permalink Reply
madesimplemedia
That was it, thanks John! :)