Example #1
0
 public function render(Varien_Object $row)
 {
     $fields = array();
     try {
         $fields = unserialize($row->getFields());
     } catch (Exception $e) {
         //
     }
     if (empty($fields)) {
         return '';
     }
     $fieldsHtml = '<dl style="margin-top: 10px">';
     foreach ($fields as $field) {
         $fieldsHtml .= '<dt><strong>' . $field['name'] . '</strong></dt>';
         $fieldsHtml .= '
             <dd style="padding-left: 15px; padding-bottom: 10px">
                 <pre>' . htmlspecialchars($field['content']) . '</pre>
             </dd>
         ';
     }
     $fieldsHtml .= '</dl>';
     return '
         <a href="#" onclick="javascript:document.getElementById(\'fields-' . $row->getId() . '\').style.display = \'block\';">Show</a>
         <span style="color:#666">|</span>
         <a href="#" onclick="javascript:document.getElementById(\'fields-' . $row->getId() . '\').style.display = \'none\';">Hide</a>
         <div id="fields-' . $row->getId() . '" style="display: none">' . $fieldsHtml . '</div>
     ';
 }
Example #2
0
 /**
  * Return editable values configs
  * 
  * @param string $type Grid block type
  * @param string $origin Values origin (if null, all values will be returned)
  * @return array
  */
 public function getEditableValues($type, $origin = null)
 {
     if (!isset($this->_editableValues[$type])) {
         // Build all base configs
         $fields = $this->_getEditableFields($type);
         foreach ($fields as $id => $field) {
             $fields[$id] = $this->_buildEditableFieldConfig($type, $id, $field);
         }
         $attributes = $this->_getEditableAttributes($type);
         foreach ($attributes as $code => $attribute) {
             $attributes[$code] = $this->_buildEditableAttributeConfig($type, $code, $attribute);
         }
         // Dispatch events for each kind of editable values
         $fieldsResponse = new Varien_Object(array('fields' => $fields));
         $attributesResponse = new Varien_Object(array('attributes' => $attributes));
         $attributeFieldsResponse = new Varien_Object(array('attribute_fields' => $this->_getEditableAttributeFields($type)));
         Mage::dispatchEvent('blcg_grid_type_editable_fields', array('response' => $fieldsResponse, 'type_model' => $this, 'block_type' => $type));
         Mage::dispatchEvent('blcg_grid_type_editable_attributes', array('response' => $attributesResponse, 'type_model' => $this, 'block_type' => $type));
         Mage::dispatchEvent('blcg_grid_type_editable_attribute_fields', array('response' => $attributeFieldsResponse, 'type_model' => $this, 'block_type' => $type));
         // Cache the results
         $this->_editableValues[$type] = array(self::EDITABLE_TYPE_FIELD => $fieldsResponse->getFields(), self::EDITABLE_TYPE_ATTRIBUTE => $attributesResponse->getAttributes(), self::EDITABLE_TYPE_ATTRIBUTE_FIELD => $attributeFieldsResponse->getAttributeFields());
     }
     if (!is_null($origin)) {
         if (isset($this->_editableValues[$type][$origin])) {
             return $this->_editableValues[$type][$origin];
         } else {
             return array();
         }
     } else {
         return $this->_editableValues[$type];
     }
 }
 /**
  * @param Varien_Object $context
  * @param Varien_Simplexml_Element $module
  * @param Varien_Simplexml_Element $entity
  * @param Varien_Simplexml_Element $scope
  */
 public function _endTableScript($context, $module, $entity, $scope)
 {
     $scope = $scope;
     if (!empty($scope->unique)) {
         /* @var $resource Mage_Core_Model_Mysql4_Resource */
         $resource = Mage::getResourceSingleton('core/resource');
         $indexes = $context->getIndexes();
         foreach ($scope->unique->children() as $unique) {
             $index = (object) array('unique' => 1, 'name' => 'unique_' . $unique->getName(), 'indexed_fields' => array());
             $includeUniqueIndex = false;
             foreach ($unique->children() as $field => $def) {
                 if ((string) $def['module'] == $this->getModuleName() && (string) $def['version'] == $this->getVersion()) {
                     $includeUniqueIndex = true;
                     $index->indexed_fields[] = $field;
                 } else {
                     $installedVersion = $resource->getDbVersion((string) $def['module'] . '_setup');
                     if ($installedVersion && version_compare($installedVersion, (string) $def['version']) >= 0) {
                         $index->indexed_fields[] = $field;
                     }
                 }
             }
             if ($includeUniqueIndex) {
                 if (!((string) $scope->unique['module'] == $this->getModuleName() && (string) $scope->unique['version'] == $this->getVersion())) {
                     $index->rebuild = true;
                 }
                 $indexes[] = $index;
             }
         }
         $context->setIndexes($indexes);
     }
     $sql = $context->getSql();
     $context->setTable($this->getTable((string) $module->name . '/' . (string) $entity->name . '/' . (string) $scope->name));
     if ((string) $scope['module'] != $this->getModuleName() || (string) $scope['version'] != $this->getVersion()) {
         foreach ($context->getFields() as $field) {
             $sql .= "ALTER TABLE `{$context->getTable()}` ADD COLUMN ( ";
             $sql .= $this->_renderField($field);
             $sql .= ");\n";
         }
         foreach ($context->getIndexes() as $index) {
             if (!empty($index->rebuild)) {
                 $sql .= "ALTER TABLE `{$context->getTable()}` DROP KEY `" . (string) $index->name . "`";
                 $sql .= ";\n";
             }
             $sql .= "ALTER TABLE `{$context->getTable()}` ADD ";
             $sql .= $this->_renderIndex($index);
             $sql .= ";\n";
         }
     } else {
         if (count($context->getFields()) || count($context->getIndexes())) {
             $sql .= "DROP TABLE IF EXISTS `{$context->getTable()}`;\n";
             $sql .= "CREATE TABLE `{$context->getTable()}` ( \n";
             $sep = false;
             foreach ($context->getFields() as $field) {
                 if ($sep) {
                     $sql .= ", \n";
                 } else {
                     $sep = true;
                 }
                 $sql .= "    " . $this->_renderField($field);
             }
             foreach ($context->getIndexes() as $index) {
                 if ($sep) {
                     $sql .= ", \n";
                 } else {
                     $sep = true;
                 }
                 $sql .= "    " . $this->_renderIndex($index);
             }
             $sql .= "\n";
             $sql .= ") ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='';\n";
         }
     }
     foreach ($context->getConstraints() as $constraint) {
         $sql .= "ALTER TABLE `{$context->getTable()}` ADD CONSTRAINT ";
         $sql .= $this->_renderConstraint($context, $constraint);
         $sql .= ";\n";
     }
     $context->setSql($sql);
 }