From 95a06cb2d420a34c5d6bfddee653ce45ac955075 Mon Sep 17 00:00:00 2001 From: Rajeev K Tomy Date: Tue, 21 Apr 2015 17:16:51 +0530 Subject: [PATCH] added proper documentation; added license file --- LICENSE_JSSB.txt | 21 +++++ .../community/Rkt/JsCssforSb/Block/Jscss.php | 24 ++++- .../community/Rkt/JsCssforSb/Helper/Data.php | 33 +++++-- .../community/Rkt/JsCssforSb/Model/Block.php | 21 ++++- .../community/Rkt/JsCssforSb/Model/JsCss.php | 25 ++++- .../Rkt/JsCssforSb/Model/Observer.php | 91 ++++++++++--------- .../Rkt/JsCssforSb/Model/Resource/JsCss.php | 21 ++++- .../Model/Resource/JsCss/Collection.php | 25 ++++- .../Rkt/JsCssforSb/Model/Resource/Setup.php | 21 ++++- .../community/Rkt/JsCssforSb/etc/config.xml | 17 +++- .../template/rkt_jscssforsb/jscss.phtml | 18 +++- app/etc/modules/Rkt_JsCssforSb.xml | 17 +++- 12 files changed, 256 insertions(+), 78 deletions(-) create mode 100644 LICENSE_JSSB.txt diff --git a/LICENSE_JSSB.txt b/LICENSE_JSSB.txt new file mode 100644 index 0000000..516f51a --- /dev/null +++ b/LICENSE_JSSB.txt @@ -0,0 +1,21 @@ + +The MIT License (MIT) + +Copyright (c) 2015 Rajeev + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/app/code/community/Rkt/JsCssforSb/Block/Jscss.php b/app/code/community/Rkt/JsCssforSb/Block/Jscss.php index 5cea8ef..ac62361 100644 --- a/app/code/community/Rkt/JsCssforSb/Block/Jscss.php +++ b/app/code/community/Rkt/JsCssforSb/Block/Jscss.php @@ -1,12 +1,29 @@ load($id); } diff --git a/app/code/community/Rkt/JsCssforSb/Helper/Data.php b/app/code/community/Rkt/JsCssforSb/Helper/Data.php index 6c91c15..40fef8f 100644 --- a/app/code/community/Rkt/JsCssforSb/Helper/Data.php +++ b/app/code/community/Rkt/JsCssforSb/Helper/Data.php @@ -1,26 +1,43 @@ _init('rkt_jscssforsb/jsCss'); } diff --git a/app/code/community/Rkt/JsCssforSb/Model/Observer.php b/app/code/community/Rkt/JsCssforSb/Model/Observer.php index 0a1635f..7ff4f2c 100644 --- a/app/code/community/Rkt/JsCssforSb/Model/Observer.php +++ b/app/code/community/Rkt/JsCssforSb/Model/Observer.php @@ -1,13 +1,30 @@ static blocks * - * @category Extension + * @category Rkt * @package Rkt_JsCssforSb * @author Programmer-RKT */ -class Rkt_JsCssforSb_Model_Observer { +class Rkt_JsCssforSb_Model_Observer +{ /** * @@ -16,9 +33,9 @@ class Rkt_JsCssforSb_Model_Observer { * @param Varien_Event_Observer | $observer * */ - public function addNewFieldsetForCmsBlock($observer) { - - $block = $observer->getEvent()->getBlock(); + public function addNewFieldsetForCmsBlock(Varien_Event_Observer $observer) + { + $block = $observer->getEvent()->getBlock(); //check whether block is cms_block_form if ($block instanceof Mage_Adminhtml_Block_Cms_Block_Edit_Form) { @@ -28,12 +45,11 @@ public function addNewFieldsetForCmsBlock($observer) { //get jscss values $js_value = ''; $css_value = ''; - $block_id = (int)Mage::registry('cms_block')->getBlockId(); + $block_id = (int) Mage::registry('cms_block')->getBlockId(); $cms_block = $this->getJsCssEntity($block_id); //get values if entity exist - if($cms_block){ - + if ($cms_block) { $js_value = $cms_block->getJscssJs(); $css_value = $cms_block->getJscssCss(); } @@ -61,7 +77,7 @@ public function addNewFieldsetForCmsBlock($observer) { )); } - return; + return $this; } /** @@ -71,18 +87,19 @@ public function addNewFieldsetForCmsBlock($observer) { * @param Varien_Event_Observer | $observer * */ - public function saveJsCss($observer) { + public function saveJsCss(Varien_Event_Observer $observer) + { //get object $cms_block = $observer->getEvent()->getObject(); //retrieve essential datas to store - $block_id = (int)$cms_block->getBlockId(); + $block_id = (int) $cms_block->getBlockId(); $js = Mage::helper('rkt_jscssforsb')->modifyData($cms_block->getJscssJs()); $css = Mage::helper('rkt_jscssforsb')->modifyData($cms_block->getJscssCss()); - if($js != '' || $css != ''){ - + if ($js != '' || $css != '') { + //prepare data to save $data = array( 'block_id' => $block_id, @@ -94,19 +111,14 @@ public function saveJsCss($observer) { $model = Mage::getModel('rkt_jscssforsb/jsCss'); //saves data if cms block is new - if(!$this->getJsCssEntity($block_id)){ - + if (!$this->getJsCssEntity($block_id)) { $model->addData($data); $model->save(); - } - - //saves data if entry already exist - else { + } else { //saves data if entry already exist $exist_block = $this->getJsCssEntity($block_id); $exist_block->addData($data); $exist_block->save(); - } } @@ -119,18 +131,19 @@ public function saveJsCss($observer) { * @param Varien_Event_Observer | $observer * */ - public function applyJsCssToCMSBlocks($observer) { + public function applyJsCssToCMSBlocks(Varien_Event_Observer $observer) { //set default values to variables - $flag = 0; $jscss_ids = array(); + $flag = 0; + $jscss_ids = array(); $layout = $observer->getEvent()->getLayout(); foreach ($layout->getAllBlocks() as $block) { if ($block instanceof Mage_Cms_Block_Block) { - $flag = 1; + //get cms block id $block_identifier = $block->getBlockId(); $block_id = (int)Mage::getModel('cms/block')->getCollection() @@ -142,33 +155,26 @@ public function applyJsCssToCMSBlocks($observer) { //check for any entry that is correspond for cms block - if($cms_block = $this->getJsCssEntity($block_id)){ - + if ($cms_block = $this->getJsCssEntity($block_id)) { //store jscss ids $jscss_ids[] = (int)$cms_block->getJscssId(); - - } } } - //print_r($jscss_ids);die(); - if($flag == 1){ + + if ($flag == 1) { //create a custom block to insert js and css correspond to cms block $new_block = $layout->createBlock( - - 'Rkt_JsCssforSb_Block_Jscss', - 'jscss_block', + 'Rkt_JsCssforSb_Block_Jscss', 'jscss_block', array( - - 'template' => 'rkt_jscssforsb/jscss.phtml', - 'jscss_ids' => Mage::helper('rkt_jscssforsb')->__(implode(",",$jscss_ids)), - )); + 'template' => 'rkt_jscssforsb/jscss.phtml', + 'jscss_ids' => Mage::helper('rkt_jscssforsb')->__(implode(",", $jscss_ids)), + ) + ); $layout->getBlock('content')->append($new_block); - - } - + } } /** @@ -179,16 +185,17 @@ public function applyJsCssToCMSBlocks($observer) { * @return boolean or Rkt_JsCssforSb_Model_JsCss | false or $item * */ - public function getJsCssEntity($block_id){ + public function getJsCssEntity($block_id) + { //loads collection $collection = Mage::getModel('rkt_jscssforsb/jsCss')->getCollection() ->addFieldToSelect('*') ->addFieldToFilter('block_id', array('eq' => $block_id)) ->load(); - //ensure an item exist - if(count($collection->getFirstItem()->getData())){ + //ensure an item exist + if (count($collection->getFirstItem()->getData())) { return $collection->getFirstItem(); } diff --git a/app/code/community/Rkt/JsCssforSb/Model/Resource/JsCss.php b/app/code/community/Rkt/JsCssforSb/Model/Resource/JsCss.php index 75bf843..e57af39 100644 --- a/app/code/community/Rkt/JsCssforSb/Model/Resource/JsCss.php +++ b/app/code/community/Rkt/JsCssforSb/Model/Resource/JsCss.php @@ -1,12 +1,29 @@ _init('rkt_jscssforsb/jsCss'); } } \ No newline at end of file diff --git a/app/code/community/Rkt/JsCssforSb/Model/Resource/Setup.php b/app/code/community/Rkt/JsCssforSb/Model/Resource/Setup.php index 00e4bd8..7a0b64a 100644 --- a/app/code/community/Rkt/JsCssforSb/Model/Resource/Setup.php +++ b/app/code/community/Rkt/JsCssforSb/Model/Resource/Setup.php @@ -1,11 +1,28 @@ diff --git a/app/design/frontend/base/default/template/rkt_jscssforsb/jscss.phtml b/app/design/frontend/base/default/template/rkt_jscssforsb/jscss.phtml index cc209ca..a298543 100644 --- a/app/design/frontend/base/default/template/rkt_jscssforsb/jscss.phtml +++ b/app/design/frontend/base/default/template/rkt_jscssforsb/jscss.phtml @@ -1,8 +1,24 @@