public function set_bundle()
{
/* Sample use
---------------------------------------------------------
{exp:stash:set_bundle name="contact_form"}
--------------------------------------------------------- */
if (!!($bundle = $this->EE->TMPL->fetch_param('name', FALSE))) {
if (isset(self::$bundles[$bundle])) {
// get params
$bundle_label = $this->EE->TMPL->fetch_param('label', $bundle);
$unique = (bool) preg_match('/1|on|yes|y/i', $this->EE->TMPL->fetch_param('unique', 'yes'));
$bundle_entry_key = $bundle_entry_label = $bundle;
// get the bundle id
$bundle_id = $this->EE->stash_model->get_bundle_by_name($bundle);
// does this bundle already exist? Let's try to get it's id
if (!$bundle_id) {
// doesn't exist, let's create it
$bundle_id = $this->EE->stash_model->insert_bundle($bundle, $bundle_label);
} elseif (!$unique) {
// bundle exists, but do we want more than one entry per bundle?
$entry_count = $this->EE->stash_model->bundle_entry_count($bundle_id, $this->site_id);
if ($entry_count > 0) {
$bundle_entry_key .= '_' . $entry_count;
$bundle_entry_label = $bundle_entry_key;
}
}
// stash the data under a single key
$this->EE->TMPL->tagparams['name'] = $bundle_entry_key;
$this->EE->TMPL->tagparams['label'] = $bundle_entry_label;
$this->EE->TMPL->tagparams['save'] = 'yes';
$this->EE->TMPL->tagparams['scope'] = 'user';
$this->EE->TMPL->tagdata = serialize(self::$bundles[$bundle]);
$this->bundle_id = $bundle_id;
unset(self::$bundles[$bundle]);
return $this->set();
}
}
}