This repository has been archived by the owner on Jul 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
785 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
class RK_TypeCMS_Block_Page extends Mage_Cms_Block_Page | ||
{ | ||
|
||
protected function _toHtml() | ||
{ | ||
$page = Mage::getModel('typecms/page')->load($this->getPage()->getId()); | ||
if ($page->getId() && $page->getPageTypeInstance()->getTemplate() != '') { | ||
/* @var $block Mage_Core_Block_Template */ | ||
$block = $this->getLayout()->createBlock('core/template', 'typecms_block'); | ||
$block->setTemplate($page->getPageTypeInstance()->getTemplate()); | ||
$block->addData($page->getFilteredData()); | ||
$block->addData($this->getPage()->getData()); | ||
return $block->toHtml(); | ||
} | ||
return parent::_toHtml(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
class RK_TypeCMS_Helper_Data extends Mage_Core_Helper_Abstract | ||
{ | ||
|
||
protected $_dbTypeToForm = array( | ||
'varchar' => 'text', | ||
'text' => 'editor', | ||
'int' => 'text', | ||
); | ||
|
||
public function dbTypeToForm($type) | ||
{ | ||
return $this->_dbTypeToForm[$type]; | ||
} | ||
|
||
public function setupAttributes() | ||
{ | ||
$config = Mage::getSingleton('typecms/config'); | ||
$setup = Mage::getResourceModel('typecms/setup', 'typecms_setup'); | ||
$pageTypes = $config->getPageTypes(); | ||
$attributes = array(); | ||
foreach ($pageTypes as $pageTypeCode => $pageType) { | ||
$attributes = $config->getAttributes($pageTypeCode); | ||
foreach ($attributes as $attributeCode => $attribute) { | ||
$attributeEntity = $setup->getAttribute(RK_TypeCMS_Model_Page::ENTITY, $attributeCode); | ||
if (!$attributeEntity) { | ||
$setup->addAttribute(RK_TypeCMS_Model_Page::ENTITY, $attributeCode, array( | ||
'type' => $attribute['type'], | ||
)); | ||
} | ||
$attributes[] = $attributeCode; | ||
} | ||
} | ||
|
||
/* @var $collection Mage_Eav_Model_Resource_Entity_Attribute_Collection */ | ||
$collection = Mage::getSingleton('eav/config') | ||
->getEntityType(RK_TypeCMS_Model_Page::ENTITY)->getAttributeCollection(); | ||
$collection->addFieldToFilter('backend_type', array('neq' => 'static')) | ||
->addFieldToFilter('attribute_code', array('nin' => $attributes)); | ||
|
||
foreach ($collection as $attribute) { | ||
$attribute->delete(); | ||
} | ||
|
||
$setup->getConnection()->commit(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
class RK_TypeCMS_Model_Config | ||
{ | ||
|
||
const XML_PATH_PAGE_TYPES = 'global/page/types'; | ||
|
||
protected $_pageTypes; | ||
|
||
public function getPageTypes() | ||
{ | ||
if (!isset($this->_pageTypes)) { | ||
$this->_pageTypes = Mage::getConfig()->getNode(self::XML_PATH_PAGE_TYPES)->asArray(); | ||
if (isset($this->_pageTypes['label'])) $this->_pageTypes['label'] = $this->__($this->_pageTypes['label']); | ||
} | ||
return $this->_pageTypes; | ||
} | ||
|
||
public function getPageType($type) | ||
{ | ||
$types = $this->getPageTypes(); | ||
if (!isset($types[$type])) $type = Mage::getSingleton('typecms/source_type')->getDefaultValue(); | ||
return $types[$type]; | ||
} | ||
|
||
public function getAttributes($pageType) | ||
{ | ||
$node = Mage::getConfig()->getNode(self::XML_PATH_PAGE_TYPES)->descend($pageType); | ||
|
||
if ($node && $node = $node->descend('attributes')) { | ||
return $node->hasChildren() ? $node->asArray() : array(); | ||
} | ||
return array(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
class RK_TypeCMS_Model_Observer { | ||
|
||
public function adminhtmlCmsPageEditTabMainPrepareForm($observer) | ||
{ | ||
/* @var $page Mage_Cms_Model_Page */ | ||
$page = Mage::registry('cms_page'); | ||
/* @var $form Varien_Data_Form */ | ||
$form = $observer->getForm(); | ||
/* @var $fieldset Varien_Data_Form_Element_Fieldset */ | ||
$fieldset = $form->getElement('base_fieldset'); | ||
$pageTypes = Mage::getSingleton('typecms/source_type')->toOptionArray(); | ||
$fieldset->addField('page_type', 'select', array( | ||
'name' => 'page_type', | ||
'label' => Mage::helper('typecms')->__('Page Type'), | ||
'values' => $pageTypes | ||
)); | ||
$model = Mage::getModel('typecms/page')->load($page->getId()); | ||
if (!$model->getPageType()) { | ||
$page->setPageType(Mage::getSingleton('typecms/source_type')->getDefaultValue()); | ||
$model->setPageType(Mage::getSingleton('typecms/source_type')->getDefaultValue()); | ||
} else { | ||
$page->setPageType($model->getPageType()); | ||
} | ||
$values = array(); | ||
foreach ($model->getFilteredData() as $key => $value) { | ||
$values['typecms_' . $key] = $value; | ||
} | ||
$page->addData($values); | ||
$pageTypeInstance = $model->getPageTypeInstance(); | ||
$pageTypeInstance->init($form); | ||
} | ||
|
||
public function cmsPageSaveAfter($observer) | ||
{ | ||
/* @var $page Mage_Cms_Model_Page */ | ||
$page = $observer->getObject(); | ||
|
||
Mage::helper('typecms')->setupAttributes(); | ||
|
||
$pageType = Mage::getModel('typecms/page')->load($page->getId()); | ||
if (!$pageType->getId()) { | ||
$pageType->setId($page->getId()); | ||
} | ||
$pageType->setPageType($page->getPageType()); | ||
$attributes = $page->getData('typecms'); | ||
if (isset($attributes)) $pageType->addData($attributes); | ||
$pageType->save(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
class RK_TypeCMS_Model_Page extends Mage_Core_Model_Abstract | ||
{ | ||
|
||
const ENTITY = 'typecms_page'; | ||
const DEFAULT_PAGE_TYPE = 'typecms/page_type_default'; | ||
|
||
protected $_eventPrefix = 'typecms_page'; | ||
protected $_eventObject = 'page'; | ||
|
||
protected $_pageTypeInstance; | ||
|
||
|
||
public function __construct() | ||
{ | ||
$this->_init('typecms/page'); | ||
} | ||
|
||
public function getPageTypeInstance() | ||
{ | ||
if (!isset($this->_pageTypeInstance)) { | ||
$pageType = Mage::getSingleton('typecms/config')->getPageType($this->getPageType()); | ||
$this->_pageTypeInstance = Mage::getModel(isset($pageType['model']) ? $pageType['model'] : self::DEFAULT_PAGE_TYPE); | ||
$this->_pageTypeInstance->setPageType($this->getPageType()); | ||
$this->_pageTypeInstance->addData($pageType); | ||
} | ||
return $this->_pageTypeInstance; | ||
} | ||
|
||
public function getFilteredData() | ||
{ | ||
$data = $this->getData(); | ||
unset($data['entity_id']); | ||
return $data; | ||
} | ||
|
||
protected function _beforeSave() | ||
{ | ||
if (!$this->getPageType()) { | ||
Mage::throwException('Missing Page Type'); | ||
} | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
app/code/community/RK/TypeCMS/Model/Page/Type/Abstract.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
abstract class RK_TypeCMS_Model_Page_Type_Abstract extends Varien_Object | ||
{ | ||
|
||
protected $_attributes; | ||
|
||
abstract function init(Varien_Data_Form $form); | ||
|
||
protected function getAttributes() | ||
{ | ||
if (!isset($this->_attributes)) { | ||
$this->_attributes = Mage::getSingleton('typecms/config')->getAttributes($this->getPageType()); | ||
} | ||
return $this->_attributes; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
class RK_TypeCMS_Model_Page_Type_Default extends RK_TypeCMS_Model_Page_Type_Abstract | ||
{ | ||
|
||
public function init(Varien_Data_Form $form) | ||
{ | ||
$attributes = $this->getAttributes(); | ||
|
||
if (!count($attributes)) return; | ||
$fieldset = $form->addFieldset('typecms_fields', array( | ||
'legend' => Mage::helper('typecms')->__('TypeCMS Fields'), | ||
'class' => 'fieldset-wide' | ||
)); | ||
|
||
foreach ($attributes as $code => $attribute) { | ||
$type = Mage::helper('typecms')->dbTypeToForm($attribute['type']); | ||
$label = Mage::helper('typecms')->__($attribute['label']); | ||
if ($type == 'editor') { | ||
$wysiwygConfig = Mage::getSingleton('cms/wysiwyg_config')->getConfig( | ||
array('tab_id' => 'main') | ||
); | ||
$fieldset->addField('typecms_' . $code, $type, array( | ||
'name' => 'typecms[' . $code . ']', | ||
'label' => $label, | ||
'style' => 'height:36em;', | ||
'config' => $wysiwygConfig | ||
)); | ||
} else { | ||
$fieldset->addField('typecms_' . $code, $type, array( | ||
'name' => 'typecms[' . $code . ']', | ||
'label' => $label, | ||
)); | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
class RK_TypeCMS_Model_Resource_Page extends Mage_Eav_Model_Entity_Abstract | ||
{ | ||
|
||
public function __construct() | ||
{ | ||
$resource = Mage::getSingleton('core/resource'); | ||
|
||
$this->setType(RK_TypeCMS_Model_Page::ENTITY); | ||
|
||
$this->setConnection( | ||
$resource->getConnection('typecms_read'), | ||
$resource->getConnection('typecms_write') | ||
); | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
app/code/community/RK/TypeCMS/Model/Resource/Page/Collection.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
class RK_TypeCMS_Model_Resource_Page_Collection extends Mage_Eav_Model_Entity_Collection_Abstract | ||
{ | ||
|
||
protected function _construct() | ||
{ | ||
$this->_init('typecms/page'); | ||
} | ||
|
||
protected function _initSelect() | ||
{ | ||
$this->getSelect()->from(array('e' => $this->getEntity()->getEntityTable())); | ||
|
||
return $this; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
class RK_TypeCMS_Model_Resource_Setup extends Mage_Eav_Model_Entity_Setup | ||
{ | ||
|
||
public function getDefaultEntities() { | ||
return array( | ||
RK_TypeCMS_Model_Page::ENTITY => array( | ||
'entity_model' => 'typecms/page', | ||
'table' => 'typecms/page', | ||
'attributes' => array( | ||
'page_type' => array('type' => 'static'), | ||
), | ||
), | ||
); | ||
} | ||
|
||
} |
Oops, something went wrong.