Skip to content

Instantly share code, notes, and snippets.

@justrjlewis
Last active August 29, 2015 14:06
Show Gist options
  • Save justrjlewis/1b104547fddbde82325b to your computer and use it in GitHub Desktop.
Save justrjlewis/1b104547fddbde82325b to your computer and use it in GitHub Desktop.
Concrete5 Package Controllers
<?php
defined('C5_EXECUTE') or die(_("Access Denied."));
/**
* Blocks
* Page Types
* right_sidebar
* left_sidebar
* full
* complex
* event post
* Attribute Collections
* Attributes
* Files
* Pkg Upgrade
*/
class PackageNamePackage extends Package {
protected $pkgHandle = 'package_name';
protected $pkgName = 'Theme Name Spaced';
protected $pkgDescription = 'Installs the Theme by RJ Lewis';
protected $appVersionRequired = '5.6.0.2';
protected $pkgVersion = '0.6.7';
public function install() {
$pkg = parent::install();
$this->configurePackage($pkg);
}
public function upgrade() {
$pkg = $this;
parent::upgrade();
$this->configurePackage($pkg);
}
public function configurePackage($pkg){
$this->configureThemes($pkg);
$this->configureAttributes($pkg);
$this->configurePageTypes($pkg);
// $this->configureBlocks($pkg);
// $this->configureUserGroups($pkg);
// $this->configureSinglePages($pkg);
// $this->configureUserAttributes($pkg);
// $this->configureFileAttributes($pkg);
// $this->overrideCoreSinglePagePackage($pkg);
}
public function uninstall() {
parent::uninstall();
// $this->unOverrideCoreSinglePagePackage($pkg);
}
public function configureThemes($pkg) {
if(!is_object(PageTheme::getByHandle('okzetas'))) {
PageTheme::add('okzetas', $pkg);
}
}
public function configureAttributes($pkg) {
Loader::model('attribute/categories/collection');
$eaku = AttributeKeyCategory::getByHandle('collection');
$eaku->setAllowAttributeSets(AttributeKeyCategory::ASET_ALLOW_SINGLE);
if (!is_object(AttributeSet::getByHandle('event_post'))) {
$eventpostSet = $eaku->addSet('event_post',t('News and Events'),$pkg);
} else {
$eventpostSet = AttributeSet::getByHandle('event_post');
}
$bool = 'boolean'; //checkbox
$dt = 'date_time'; //date picker
$txt = 'text'; //text box
$collection_attributes = array(
array('akHandle' => 'is_featured',
'akName' => 'Featured Post',
'akType' => $bool),
array('akHandle' => 'date_range',
'akName' => 'Multi-Date Event',
'akType' => $bool),
array('akHandle' => 'show_poc',
'akName' => 'Show Point of Contact',
'akType' => $bool),
array('akHandle' => 'show_time',
'akName' => 'Show Time',
'akType' => $bool),
array('akHandle' => 'start_date',
'akName' => 'Start Date' ,
'akType' => $dt),
array('akHandle' => 'end_date',
'akName' => 'End Date' ,
'akType' => $dt),
array('akHandle' => 'chapter_name',
'akName' => 'Chapter Name' ,
'akType' => $txt),
array('akHandle' => 'contact_name',
'akName' => 'Contact Name' ,
'akType' => $txt),
array('akHandle' => 'contact_phone',
'akName' => 'Contact Phone' ,
'akType' => $txt),
array('akHandle' => 'contact_email',
'akName' => 'Contact Email' ,
'akType' => $txt)
);
foreach($collection_attributes as $key => $newAttribute) {
$this->addNewAttribute($eventpostSet,$collection_attributes,$newAttribute,$pkg);
}
}
private function addNewAttribute($attributeSet,$collection_attributes,$newAttribute,$pkg) {
$newAttributeHandle = CollectionAttributeKey::getByHandle($newAttribute['akHandle']);
if(!is_object($newAttributeHandle)) {
$attributeType = AttributeType::getByHandle($newAttribute['akType']);
$newAttributeHandle = CollectionAttributeKey::add($attributeType,$newAttribute,$pkg)->setAttributeSet($attributeSet);
}
return $newAttributeHandle;
}
protected $pagetypes = array(
'right_sidebar'=>'Right Sidebar',
'left_sidebar'=>'Left Sidebar',
'full'=>'Full',
'complex'=>'Complex',
'event_post'=>'Event Post'
);
public function configurePageTypes($pkg) {
//install Page Types
foreach($this->pagetypes as $key => $pagetypes) {
$ct = CollectionType::getByHandle($key);
if((!is_object($ct)) || ($ct->getCollectionTypeID() < 1)) {
$data['ctHandle'] = $key;
$data['ctName'] = t($pagetypes);
$hpt = CollectionType::add($data, $pkg);
}
}
}
}
?>
<?php
namespace Concrete\Package\ThemeNewCmesexy;
use Package;
use PageTheme;
use PageType;
use PageTemplate;
use \Concrete\Core\Attribute\Key\Category as AttributeKeyCategory;
use AttributeSet;
use \Concrete\Core\Attribute\Type as AttributeType;
use \Concrete\Core\Attribute\Key\CollectionKey as CollectionAttributeKey;
defined('C5_EXECUTE') or die(_("Access Denied."));
class Controller extends Package {
protected $pkgHandle = 'theme_handle';
protected $appVersionRequired = '5.7.***';
protected $pkgVersion = '0.1.0';
protected $pkgName = '*** Theme updated for Concrete5 version 5.7';
protected $pkgDescription = 'Installs *** Theme by RJ Lewis';
public function install() {
$pkg = parent::install();
$this->configurePackage($pkg);
}
public function upgrade() {
$pkg = $this;
parent::upgrade();
$this->configurePackage($pkg);
}
public function uninstall() {
parent::uninstall();
}
public function configurePackage($pkg){
//what functionality is in this package
$this->configureThemes($pkg);
$this->configureAttributes($pkg);
$this->configurePageTemplates($pkg);
// $this->configureBlocks($pkg);
// $this->configureUserGroups($pkg);
// $this->configureSinglePages($pkg);
// $this->configureUserAttributes($pkg);
// $this->configureFileAttributes($pkg);
// $this->overrideCoreSinglePagePackage($pkg);
}
public function configureThemes($pkg) {
if(!is_object(PageTheme::getByHandle('handle'))) {
PageTheme::add('handle', $pkg);
}
}
// @group attributes
//////////////////////////////
public function configureAttributes($pkg) {
// add theme attribute category
$category = AttributeKeyCategory::getByHandle('collection');
$category->allowAttributeSets(AttributeKeyCategory::ASET_ALLOW_SINGLE);
if (!is_object(AttributeSet::getByHandle('theme_attr'))) {
$themeattributeSet = $category->addSet('theme_attr',t('Theme Name'),$pkg);
} else {
$themeattributeSet = AttributeSet::getByHandle('theme_attr');
}
$boolean = 'boolean'; //checkbox
// $dt = 'date_time'; //date picker
// $txt = 'text'; //text box
$collection_attributes = array(
array(
'akType' => $boolean,
'akHandle' => 'is_featured',
'akName' => 'Featured Post',
'akIsSearchable'=> true,
'akCheckedByDefault' => false
)
);
foreach($collection_attributes as $key => $newAttribute) {
$this->addNewAttribute($themeattributeSet,$collection_attributes,$newAttribute,$pkg);
}
}
private function addNewAttribute($themeattributeSet,$collection_attributes,$newAttribute,$pkg) {
$newAttributeHandle = CollectionAttributeKey::getByHandle($newAttribute['akHandle']);
if(!is_object($newAttributeHandle)) {
$attributeType = AttributeType::getByHandle($newAttribute['akType']);
$newAttributeHandle = CollectionAttributeKey::add($attributeType,$newAttribute,$pkg)->setAttributeSet($themeattributeSet);
}
return $newAttributeHandle;
}
// @end attributes
// @group page templates
//////////////////////////////
protected $pagetemplates = array(
'right_sidebar'=>'Right Sidebar',
'left_sidebar'=>'Left Sidebar',
'full'=>'Full',
'complex'=>'Complex'
);
public function configurePageTemplates($pkg) {
//thanks to [huntman](http://hutman.net)
foreach($this->pagetemplates as $key => $pagetemplates) {
$pt = PageTemplate::getByHandle($key);
if(!is_object($pt)) {
$pt = PageTemplate::add($key, t($pagetemplates),FILENAME_PAGE_TEMPLATE_DEFAULT_ICON, $pkg);
}
}
}
// @end page types
}
?>
protected $pagetemplates = array(
'right_sidebar'=>'Right Sidebar',
'left_sidebar'=>'Left Sidebar',
'full'=>'Full',
'complex'=>'Complex'
);
public function configurePageTemplates($pkg) {
//thanks to [huntman](http://hutman.net)
foreach($this->pagetemplates as $key => $pagetemplates) {
$pt = PageTemplate::getByHandle($key);
if(!is_object($pt)) {
$pt = PageTemplate::add($key, t($pagetemplates),FILENAME_PAGE_TEMPLATE_DEFAULT_ICON, $pkg);
}
}
}
// install Page Templates
if (!is_object(PageTemplate::getByHandle('right_sidebar'))){
$pt = PageTemplate::add('right_sidebar', 'Right Sidebar');
}
if (!is_object(PageTemplate::getByHandle('left_sidebar'))){
$pt = PageTemplate::add('left_sidebar', 'Left Sidebar');
}
if (!is_object(PageTemplate::getByHandle('full'))){
$pt = PageTemplate::add('full', 'Full');
}
if (!is_object(PageTemplate::getByHandle('complex'))){
$pt = PageTemplate::add('complex', 'Complex');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment