/**
  * loadCoreData
  * @param string $strType
  * @param array $arrTypeProperties
  * @author Thomas Schedler <*****@*****.**>
  * @version 1.0
  */
 protected final function loadCoreData($strType, $arrTypeProperties)
 {
     try {
         /**
          * generic form core fields
          */
         if (count($this->setup->CoreFields()) > 0) {
             /**
              * for each core field, try to select the secondary table
              */
             foreach ($this->setup->CoreFields() as $strField => $objField) {
                 $objGenTable = $this->getModelGenericData()->getGenericTable($strType . str_replace('_', '', substr($strField, strlen($strField) - 1) == 'y' ? ucfirst(rtrim($strField, 'y')) . 'ies' : ucfirst($strField) . 's'));
                 $objSelect = $objGenTable->select();
                 $objSelect->from($objGenTable->info(Zend_Db_Table_Abstract::NAME), array($strField));
                 $objSelect->where($strType . 'Id = ?', $arrTypeProperties['Id']);
                 $objSelect->where('version = ?', $arrTypeProperties['Version']);
                 $objSelect->where('idLanguages = ?', $this->Setup()->getLanguageId());
                 $arrGenFormsData = $objGenTable->fetchAll($objSelect)->toArray();
                 if (count($arrGenFormsData) > 0) {
                     $objField->blnHasLoadedData = true;
                     if (count($arrGenFormsData) > 1) {
                         $arrFieldData = array();
                         foreach ($arrGenFormsData as $arrRowGenFormData) {
                             foreach ($arrRowGenFormData as $column => $value) {
                                 array_push($arrFieldData, $value);
                             }
                         }
                         if ($column == $strField) {
                             $objField->setValue($arrFieldData);
                         } else {
                             $objField->{$column} = $arrFieldData;
                         }
                     } else {
                         foreach ($arrGenFormsData as $arrRowGenFormData) {
                             foreach ($arrRowGenFormData as $column => $value) {
                                 if ($column == $strField) {
                                     $objField->setValue($value);
                                 } else {
                                     $objField->{$column} = $value;
                                 }
                             }
                         }
                     }
                 }
             }
         }
     } catch (Exception $exc) {
         $this->core->logger->err($exc);
     }
 }
 /**
  * updateCoreData
  * @param string $strType, string $strTypeId, integer $intTypeVersion
  * @author Cornelius Hansjakob <*****@*****.**>
  * @version 1.0
  */
 protected final function updateCoreData($strType, $strTypeId, $intTypeVersion)
 {
     if (count($this->setup->CoreFields()) > 0) {
         $intUserId = Zend_Auth::getInstance()->getIdentity()->id;
         /**
          * for each core field, try to insert into the secondary table
          */
         foreach ($this->setup->CoreFields() as $strField => $objField) {
             $objGenTable = $this->getModelGenericData()->getGenericTable($strType . (substr($strField, strlen($strField) - 1) == 'y' ? ucfirst(rtrim($strField, 'y')) . 'ies' : ucfirst($strField) . 's'));
             if ($objField->getValue() != '') {
                 if (is_array($objField->getValue())) {
                     /**
                      * start transaction
                      */
                     $this->core->dbh->beginTransaction();
                     try {
                         $strWhere = $objGenTable->getAdapter()->quoteInto($strType . 'Id = ?', $strTypeId);
                         $strWhere .= $objGenTable->getAdapter()->quoteInto(' AND version = ?', $intTypeVersion);
                         $strWhere .= $objGenTable->getAdapter()->quoteInto(' AND idLanguages = ?', $this->setup->getLanguageId());
                         /**
                          * delete
                          */
                         $objGenTable->delete($strWhere);
                         /**
                          * insert data
                          */
                         foreach ($objField->getValue() as $key => $value) {
                             $arrCoreData = array($strType . 'Id' => $strTypeId, 'version' => $intTypeVersion, 'idLanguages' => $this->setup->getLanguageId(), $strField => $value, 'idUsers' => $intUserId, 'creator' => $intUserId, 'created' => date('Y-m-d H:i:s'));
                             $objGenTable->insert($arrCoreData);
                         }
                         /**
                          * commit transaction
                          */
                         $this->core->dbh->commit();
                     } catch (Exception $exc) {
                         /**
                          * roll back
                          */
                         $this->core->dbh->rollBack();
                         $this->core->logger->err($exc);
                     }
                 } else {
                     $arrCoreData = array($strField => $objField->getValue(), 'idUsers' => $intUserId, 'changed' => date('Y-m-d H:i:s'));
                     $strWhere = $objGenTable->getAdapter()->quoteInto($strType . 'Id = ?', $strTypeId);
                     $strWhere .= $objGenTable->getAdapter()->quoteInto(' AND version = ?', $intTypeVersion);
                     $strWhere .= $objGenTable->getAdapter()->quoteInto(' AND idLanguages = ?', $this->setup->getLanguageId());
                     $intNumOfEffectedRows = $objGenTable->update($arrCoreData, $strWhere);
                     if ($intNumOfEffectedRows == 0 && $objField->getValue() != '') {
                         $arrCoreData = array($strType . 'Id' => $strTypeId, 'version' => $intTypeVersion, 'idLanguages' => $this->setup->getLanguageId(), $strField => $objField->getValue(), 'idUsers' => $intUserId, 'creator' => $intUserId, 'created' => date('Y-m-d H:i:s'));
                         $objGenTable->insert($arrCoreData);
                     }
                 }
             } else {
                 $strWhere = $objGenTable->getAdapter()->quoteInto($strType . 'Id = ?', $strTypeId);
                 $strWhere .= $objGenTable->getAdapter()->quoteInto(' AND version = ?', $intTypeVersion);
                 $strWhere .= $objGenTable->getAdapter()->quoteInto(' AND idLanguages = ?', $this->setup->getLanguageId());
                 /**
                  * delete
                  */
                 $objGenTable->delete($strWhere);
             }
         }
     }
 }
 /**
  * compareGenericFieldValues
  * @author Thomas Schedler <*****@*****.**>
  * @version 1.0
  */
 public function compareGenericFieldValues(GenericSetup &$objGenericSetup)
 {
     $this->core->logger->debug('massiveart->generic->data->GenericData->compareGenericFieldValues()');
     try {
         if (count($objGenericSetup->CoreFields()) > 0) {
             /**
              * for each core field, try to get the "old" value
              */
             foreach ($objGenericSetup->CoreFields() as $strField => $objField) {
                 if (!is_null($this->setup->getCoreField($strField))) {
                     $objField->setValue($this->setup->getCoreField($strField)->getValue());
                 }
             }
         }
         if (count($objGenericSetup->FileFields()) > 0) {
             /**
              * for each file field, try to get the "old" value
              */
             foreach ($objGenericSetup->FileFields() as $strField => $objField) {
                 if (!is_null($this->setup->getFileField($strField))) {
                     $objField->setValue($this->setup->getFileField($strField)->getValue());
                 }
             }
         }
         if (count($objGenericSetup->InstanceFields()) > 0) {
             /**
              * for each instance field, try to get the "old" values
              */
             foreach ($objGenericSetup->InstanceFields() as $strField => $objField) {
                 if (!is_null($this->setup->getInstanceField($strField))) {
                     $objField->setValue($this->setup->getInstanceField($strField)->getValue());
                 }
             }
         }
         // TODO : compare special fields
     } catch (Exception $exc) {
         $this->core->logger->err($exc);
     }
 }