Skip to content

Instantly share code, notes, and snippets.

@stevewithington
Created March 2, 2012 05:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevewithington/1955838 to your computer and use it in GitHub Desktop.
Save stevewithington/1955838 to your computer and use it in GitHub Desktop.
plugin.cfc
<cfscript>
/**
*
* This file is part of MuraLocations TM
* (c) Stephen J. Withington, Jr. | www.stephenwithington.com
*
* CAREFULLY READ THE ENCLOSED LICENSE AGREEMENT (plugin/license.htm). BY USING THIS SOFTWARE,
* YOU ARE CONSENTING TO BE BOUND BY AND ARE BECOMING A PARTY TO THIS AGREEMENT. IF YOU DO NOT
* AGREE TO ALL OF THE TERMS OF THIS AGREEMENT, THEN DO NOT USE THIS SOFTWARE, AND, IF APPLICABLE,
* RETURN THIS PRODUCT TO THE PLACE OF PURCHASE FOR A FULL REFUND.
*
* @accessors true
* @extends 'mura.plugin.plugincfc'
* @output false
*/
component {
property name='config';
property name='packageName';
property name='subTypeName';
/**
* Constructor
* @output false
*/
public any function init(config='') {
if ( IsSimpleValue(arguments.config) and StructKeyExists(application, 'configBean') ) {
arguments.config = application.configBean;
};
setConfig(arguments.config);
setPackageName('MuraLocations');
setSubTypeName('MuraLocation');
return this;
};
/**
* Metadata property inspector
* @output false
*/
public struct function getProperties() {
var local = {};
local.properties = {};
local.data = getMetaData(this).properties;
for ( local.i=1; local.i lte ArrayLen(local.data); local.i++ ) {
local.properties[local.data[local.i].name] = Evaluate('get#local.data[local.i].name#()');
};
return local.properties;
};
/**
* @output false
*/
public void function install() {
var local = {};
// need to check and see if this is already installed ... if so, then abort!
local.moduleid = getConfig().getModuleID();
// only if this is NOT installed
if ( val(getInstallationCount()) eq 1 ) {
local.parentType = getSubTypeName() & ' Settings';
createPageMuraLocation(contentType='Page', subType=getSubTypeName(), parentType=local.parentType);
createPortalMuraLocation(contentType='Portal', subType=getSubTypeName(), parentType=local.parentType);
} else {
getConfig().getPluginManager().deletePlugin(local.moduleid);
};
application.appInitialized = false;
};
/**
* @output false
*/
public void function update() {
var local = {};
local.parentType = getSubTypeName() & ' Settings';
createPageMuraLocation(contentType='Page', subType=getSubTypeName(), parentType=local.parentType);
createPortalMuraLocation(contentType='Portal', subType=getSubTypeName(), parentType=local.parentType);
application.appInitialized = false;
};
/**
* @output false
*/
public void function delete() {
var local = {};
// don't delete the subTypes if this is being invoked by the deletePlugin() from install()
if ( val(getInstallationCount()) eq 1 ) {
// WARNING: deleting a subType will also delete any extended attributes associated with it!
//deleteSubType(type='Page', subType=getSubTypeName());
//deleteSubType(type='Portal', subType=getSubTypeName());
};
application.appInitialized = false;
};
/**
* i check to see if this plugin has already been installed. if so, i delete the new one.
* @output false
*/
private any function getInstallationCount(boolean debug=false) {
var qs = '';
var qoq = '';
var rs = application.configBean.getPluginManager().getAllPlugins();
var local = {};
local.ret = 0;
if ( rs.recordcount ) {
qs = new query();
qs.setDBType('query');
qs.setName('qoq');
qs.setAttributes(rs=rs); // need this for qoq to work in cfscript
qs.addParam(name='package', value=getPackageName(), cfsqltype='cf_sql_varchar', maxlength=100);
qs.setSQL('SELECT * FROM rs where package = :package');
local.result = qs.execute();
local.metaInfo = local.result.getPrefix();
if ( local.metaInfo.recordcount ) {
local.ret = val(local.metaInfo.recordcount);
};
};
if ( arguments.debug ) {
return local.result;
} else {
return local.ret;
};
};
/**
* @output false
* @parentType 'This is the Attribute Set Title that appears above the group of extended attributes.'
*/
private void function createPageMuraLocation(required string contentType, required string subType, required string parentType) {
var local = {};
local.rsSites = getConfig().getAssignedSites();
local.subType = application.classExtensionManager.getSubTypeBean();
for ( local.i=1; local.i lte local.rsSites.recordcount; local.i++ ) {
include 'AttributeSetsPageMuraLocation.cfm';
};
};
/**
* @output false
* @parentType 'This is the Attribute Set Title that appears above the group of extended attributes.'
*/
private void function createPortalMuraLocation(required string contentType, required string subType, required string parentType) {
var local = {};
local.rsSites = getConfig().getAssignedSites();
local.subType = application.classExtensionManager.getSubTypeBean();
for ( local.i=1; local.i lte local.rsSites.recordcount; local.i++ ) {
include 'AttributeSetsPortalMuraLocation.cfm';
};
};
/**
* @output false
*/
private void function deleteSubType(required string type, required string subType) {
var local = {};
local.rsSites = getConfig().getAssignedSites();
local.subType = application.classExtensionManager.getSubTypeBean();
for ( local.i=1; local.i lte local.rsSites.recordcount; local.i++ ) {
local.subType.setType(arguments.type);
local.subType.setSubType(arguments.subType);
local.subType.setSiteID(local.rsSites.siteid[local.i]);
local.subType.load();
local.subType.delete();
};
};
/**
* @output false
* @type 'Options are: TextBox^TextArea^HTMLEditor^SelectBox^MultiSelectBox^RadioGroup^File^Hidden'
* @validation 'Options are: None^Date^Numeric^Email^Regex ... if None, then it will be set to an empty string.'
* @parentType 'Class Extension Attribute Set Name (i.e., Default, etc.)'
* @container 'Which tab to display: default^basic^custom'
*/
private void function createAttributeSet(
required string siteID,
required string name,
required string contentType,
string subType=getSubTypeName(),
string label=arguments.name,
string hint='',
string type='TextBox',
string defaultValue='',
boolean required=false,
string validation='',
string regex='',
string message='',
string optionList='',
string optionLabelList='',
string parentType='Default',
numeric orderNo=99,
string container='default'
) {
var local = {};
// VALIDATION
local.validTypes = 'Text^TextBox^TextArea^HTMLEditor^SelectBox^MultiSelectBox^RadioGroup^File^Hidden';
if ( !ListFindNoCase(local.validTypes, arguments.type, '^') ) {
arguments.type = 'Text';
};
local.validValidations = 'Date^Numeric^Email^Regex';
if ( !ListFindNoCase(local.validValidations, arguments.validation, '^') ) {
arguments.validation = '';
};
local.validContainers = 'default^basic^custom';
if ( !ListFindNoCase(local.validContainers, arguments.container, '^') ) {
arguments.container = 'default';
};
// SUBTYPE SETUP
local.subType = application.classExtensionManager.getSubTypeBean();
local.subType.setType(arguments.contentType);
local.subType.setSubType(arguments.subType);
local.subType.setSiteID(arguments.siteid);
local.subType.setBaseTable('tcontent');
local.subType.setBaseKeyField('contentHistID');
local.subType.load();
local.subType.save();
// EXTEND SET SETUP
// let's create a custom Class Extension Set (Extend Set) name
local.extendSetName = arguments.parentType;
local.extendSetBean = local.subType.getExtendSetBean();
local.extendSetBean.setName(local.extendSetName);
local.extendSetBean.load();
local.extendSetBean.setContainer(arguments.container); //default, basic, custom
local.extendSetBean.save();
// ATTRIBUTE SETUP
// create a new attribute for the Extend Set created above
// getAttributeByName will look for the attribute and if it's not found, it will be created
local.attribute = local.extendSetBean.getAttributeByName(arguments.name);
local.attribute.setLabel(arguments.label);
local.attribute.setHint(arguments.hint);
local.attribute.setType(arguments.type);
local.attribute.setDefaultValue(arguments.defaultValue);
local.attribute.setRequired(arguments.required);
local.attribute.setValidation(arguments.validation);
local.attribute.setRegex(arguments.regex);
local.attribute.setMessage(arguments.message);
local.attribute.setOptionList(arguments.optionList);
local.attribute.setOptionLabelList(arguments.optionLabelList);
local.attribute.setOrderNo(arguments.orderNo);
local.attribute.save();
};
}
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment