Ejemplo n.º 1
0
 /**
  * add new attribute
  * @access public
  * @param Ultimate_ModuleCreator_Model_Attribute $attribute
  * @return Ultimate_ModuleCreator_Model_Entity
  * @author Marius Strajeru <*****@*****.**>
  */
 public function addAttribute(Ultimate_ModuleCreator_Model_Attribute $attribute)
 {
     $attribute->setEntity($this);
     if (isset($this->_attribtues[$attribute->getCode()])) {
         throw new Ultimate_ModuleCreator_Exception(Mage::helper('modulecreator')->__('An attribute with the code "%s" already exists for entity "%s"', $attribute->getCode(), $this->getNameSingular()));
     }
     $this->_preparedAttributes = false;
     $this->_attribtues[$attribute->getCode()] = $attribute;
     $allowedTypes = array('text' => 'Text', 'int' => 'Integer', 'decimal' => 'Decimal');
     if ($attribute->getIsName()) {
         if (!in_array($attribute->getType(), array_keys($allowedTypes))) {
             throw new Ultimate_ModuleCreator_Exception(Mage::helper('modulecreator')->__('An attribute that acts as name must have the type %s.', implode(', ', array_values($allowedTypes))));
         }
         $this->_nameAttribute = $attribute;
     }
     if ($attribute->getEditor()) {
         $this->setEditor(true);
     }
     $this->_placeholders = array();
     return $this;
 }
Ejemplo n.º 2
0
 /**
  * add new attribute
  *
  * @access public
  * @param Ultimate_ModuleCreator_Model_Attribute $attribute
  * @return Ultimate_ModuleCreator_Model_Entity
  * @throws Ultimate_ModuleCreator_Exception
  * @author Marius Strajeru <*****@*****.**>
  */
 public function addAttribute(Ultimate_ModuleCreator_Model_Attribute $attribute)
 {
     Mage::dispatchEvent('umc_entity_add_attribute_before', array('attribute' => $attribute, 'entity' => $this));
     $attribute->setEntity($this);
     if (isset($this->_attributes[$attribute->getCode()])) {
         throw new Ultimate_ModuleCreator_Exception(Mage::helper('modulecreator')->__('An attribute with the code "%s" already exists for entity "%s"', $attribute->getCode(), $this->getNameSingular()));
     }
     $this->_preparedAttributes = false;
     $this->_attributes[$attribute->getCode()] = $attribute;
     if ($attribute->getIsName()) {
         if (!$attribute->getIsAllowedAsName()) {
             /** @var Ultimate_ModuleCreator_Helper_Data $helper */
             $helper = Mage::helper('modulecreator');
             $attributeTypes = $helper->getNameAttributeTypes(true);
             throw new Ultimate_ModuleCreator_Exception(Mage::helper('modulecreator')->__('An attribute that acts as name must have one of the types "%s".', implode(', ', $attributeTypes)));
         }
         $attribute->setUserDefined(false);
         $this->_nameAttribute = $attribute;
     }
     if ($attribute->getEditor()) {
         $this->setEditor(true);
     }
     if ($attribute->getType() == 'image') {
         $this->setHasImage(true);
     }
     if ($attribute->getType() == 'file') {
         $this->setHasFile(true);
     }
     if ($attribute->getType() == 'country') {
         $this->setHasCountry(true);
     }
     if ($attribute->getIsMultipleSelect()) {
         $this->setHasMultipleSelect(true);
     }
     Mage::dispatchEvent('umc_entity_add_attribute_after', array('attribute' => $attribute, 'entity' => $this));
     return $this;
 }