Mage_Eav_Model_Entity_Attribute_Set Class Reference

Inheritance diagram for Mage_Eav_Model_Entity_Attribute_Set:

Mage_Core_Model_Abstract Varien_Object

List of all members.

Public Member Functions

 initFromSkeleton ($skeletonId)
 organizeData ($data)
 validate ($name)
 addSetInfo ($entityType, array $attributes, $setId=null)

Protected Member Functions

 _construct ()


Detailed Description

Definition at line 35 of file Set.php.


Member Function Documentation

_construct (  )  [protected]

Initialize resource model

Reimplemented from Varien_Object.

Definition at line 41 of file Set.php.

00042     {
00043         $this->_init('eav/entity_attribute_set');
00044     }

addSetInfo ( entityType,
array attributes,
setId = null 
)

Add set info to attributes

Parameters:
string|Mage_Eav_Model_Entity_Type $entityType
array $attributes
int $setId
Returns:
Mage_Eav_Model_Entity_Attribute_Set

Definition at line 172 of file Set.php.

00173     {
00174         $attributeIds   = array();
00175         $config         = Mage::getSingleton('eav/config');
00176         $entityType     = $config->getEntityType($entityType);
00177         foreach ($attributes as $attribute) {
00178             $attribute = $config->getAttribute($entityType, $attribute);
00179             if ($setId && is_array($attribute->getAttributeSetInfo($setId))) {
00180                 continue;
00181             }
00182             if (!$attribute->getAttributeId()) {
00183                 continue;
00184             }
00185             $attributeIds[] = $attribute->getAttributeId();
00186         }
00187 
00188         if ($attributeIds) {
00189             $setInfo = $this->_getResource()
00190                 ->getSetInfo($attributeIds, $setId);
00191 
00192             foreach ($attributes as $attribute) {
00193                 $attribute = $config->getAttribute($entityType, $attribute);
00194                 if (!$attribute->getAttributeId()) {
00195                     continue;
00196                 }
00197                 if (!in_array($attribute->getAttributeId(), $attributeIds)) {
00198                     continue;
00199                 }
00200                 if (is_numeric($setId)) {
00201                     $attributeSetInfo = $attribute->getAttributeSetInfo();
00202                     if (!is_array($attributeSetInfo)) {
00203                         $attributeSetInfo = array();
00204                     }
00205                     if (isset($setInfo[$attribute->getAttributeId()][$setId])) {
00206                         $attributeSetInfo[$setId] = $setInfo[$attribute->getAttributeId()][$setId];
00207                     }
00208                     $attribute->setAttributeSetInfo($attributeSetInfo);
00209                 }
00210                 else {
00211                     if (isset($setInfo[$attribute->getAttributeId()])) {
00212                         $attribute->setAttributeSetInfo($setInfo[$attribute->getAttributeId()]);
00213                     }
00214                     else {
00215                         $attribute->setAttributeSetInfo(array());
00216                     }
00217                 }
00218             }
00219         }
00220 
00221         return $this;
00222     }

initFromSkeleton ( skeletonId  ) 

Init attribute set from skeleton (another attribute set)

Parameters:
int $skeletonId
Returns:
Mage_Eav_Model_Entity_Attribute_Set

Definition at line 52 of file Set.php.

00053     {
00054         $groups = Mage::getModel('eav/entity_attribute_group')
00055             ->getResourceCollection()
00056             ->setAttributeSetFilter($skeletonId)
00057             ->load();
00058 
00059         $newGroups = array();
00060         foreach( $groups as $group ) {
00061             $newGroup = clone $group;
00062             $newGroup->setId(null)
00063                 ->setAttributeSetId($this->getId())
00064                 ->setDefaultId($group->getDefaultId());
00065 
00066             $groupAttributesCollection = Mage::getModel('eav/entity_attribute')
00067                 ->getResourceCollection()
00068                 ->setAttributeGroupFilter($group->getId())
00069                 ->load();
00070 
00071             $newAttributes = array();
00072             foreach( $groupAttributesCollection as $attribute ) {
00073                 $newAttribute = Mage::getModel('eav/entity_attribute')
00074                     ->setId($attribute->getId())
00075                     //->setAttributeGroupId($newGroup->getId())
00076                     ->setAttributeSetId($this->getId())
00077                     ->setEntityTypeId($this->getEntityTypeId())
00078                     ->setSortOrder($attribute->getSortOrder());
00079                 $newAttributes[] = $newAttribute;
00080             }
00081             $newGroup->setAttributes($newAttributes);
00082             $newGroups[] = $newGroup;
00083         }
00084         $this->setGroups($newGroups);
00085         return $this;
00086     }

organizeData ( data  ) 

Collect data for save

Parameters:
array $data

Definition at line 93 of file Set.php.

00094     {
00095         $modelGroupArray = array();
00096         $modelAttributeArray = array();
00097         if( $data['groups'] ) {
00098             foreach( $data['groups'] as $group ) {
00099                 $modelGroup = Mage::getModel('eav/entity_attribute_group');
00100                 $modelGroup->setId(is_numeric($group[0]) && $group[0] > 0 ? $group[0] : null)
00101                     ->setAttributeGroupName($group[1])
00102                     ->setAttributeSetId($this->getId())
00103                     ->setSortOrder($group[2]);
00104 
00105                 if( $data['attributes'] ) {
00106                     foreach( $data['attributes'] as $attribute ) {
00107                         if( $attribute[1] == $group[0] ) {
00108                             $modelAttribute = Mage::getModel('eav/entity_attribute');
00109                             $modelAttribute->setId($attribute[0])
00110                                 ->setAttributeGroupId($attribute[1])
00111                                 ->setAttributeSetId($this->getId())
00112                                 ->setEntityTypeId($this->getEntityTypeId())
00113                                 ->setSortOrder($attribute[2]);
00114                             $modelAttributeArray[] = $modelAttribute;
00115                         }
00116                     }
00117                     $modelGroup->setAttributes($modelAttributeArray);
00118                     $modelAttributeArray = array();
00119                 }
00120                 $modelGroupArray[] = $modelGroup;
00121             }
00122             $this->setGroups($modelGroupArray);
00123         }
00124 
00125 
00126         if( $data['not_attributes'] ) {
00127             $modelAttributeArray = array();
00128             foreach( $data['not_attributes'] as $attributeId ) {
00129                 $modelAttribute = Mage::getModel('eav/entity_attribute');
00130 
00131                 $modelAttribute->setEntityAttributeId($attributeId);
00132                 $modelAttributeArray[] = $modelAttribute;
00133             }
00134             $this->setRemoveAttributes($modelAttributeArray);
00135         }
00136 
00137         if( $data['removeGroups'] ) {
00138             $modelGroupArray = array();
00139             foreach( $data['removeGroups'] as $groupId ) {
00140                 $modelGroup = Mage::getModel('eav/entity_attribute_group');
00141                 $modelGroup->setId($groupId);
00142 
00143                 $modelGroupArray[] = $modelGroup;
00144             }
00145             $this->setRemoveGroups($modelGroupArray);
00146         }
00147         $this->setAttributeSetName($data['attribute_set_name'])
00148             ->setEntityTypeId($this->getEntityTypeId());
00149     }

validate ( name  ) 

Validate attribute set name

Parameters:
string $name
Exceptions:
Mage_Core_Exception 

Definition at line 157 of file Set.php.

00158     {
00159         if (!$this->_getResource()->validate($this, $name)) {
00160             Mage::throwException(Mage::helper('eav')->__('Attribute set with the "%s" name already exists',$name));
00161         }
00162     }


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:24:10 2009 for Magento by  doxygen 1.5.8