/**
  * save
  * @author Thomas Schedler <*****@*****.**>
  * @version 1.1
  */
 public function save()
 {
     $this->core->logger->debug('massiveart->generic->data->GenericDataTypeUnit->save()');
     try {
         $this->getModelContacts()->setLanguageId($this->setup->getLanguageId());
         /**
          * add|edit|newVersion core and instance data
          */
         switch ($this->setup->getActionType()) {
             case $this->core->sysConfig->generic->actions->add:
                 /**
                  * add unit node to the "Nested Set Model"
                  */
                 $this->setup->setElementId($this->objModelContacts->addUnitNode($this->setup->getParentId(), array('idGenericForms' => $this->setup->getGenFormId(), 'idRootLevels' => $this->setup->getRootLevelId())));
                 if (count($this->setup->CoreFields()) > 0) {
                     foreach ($this->setup->CoreFields() as $strField => $obField) {
                         $arrCoreData = array('idUnits' => $this->setup->getElementId(), 'idLanguages' => $this->setup->getLanguageId(), $strField => $obField->getValue());
                         $this->getModelGenericData()->getGenericTable('unit' . (substr($strField, strlen($strField) - 1) == 'y' ? ucfirst(rtrim($strField, 'y')) . 'ies' : ucfirst($strField) . 's'))->insert($arrCoreData);
                     }
                 }
                 break;
             case $this->core->sysConfig->generic->actions->edit:
                 if (count($this->setup->CoreFields()) > 0) {
                     /**
                      * for each core field, try to insert into the secondary table
                      */
                     foreach ($this->setup->CoreFields() as $strField => $objField) {
                         $objGenTable = $this->getModelGenericData()->getGenericTable('unit' . (substr($strField, strlen($strField) - 1) == 'y' ? ucfirst(rtrim($strField, 'y')) . 'ies' : ucfirst($strField) . 's'));
                         $arrCoreData = array($strField => $objField->getValue());
                         $strWhere = $objGenTable->getAdapter()->quoteInto('idUnits = ?', $this->setup->getElementId());
                         $strWhere .= $objGenTable->getAdapter()->quoteInto(' AND idLanguages = ?', $this->setup->getLanguageId());
                         $objGenTable->update($arrCoreData, $strWhere);
                     }
                 }
                 break;
         }
         return $this->setup->getElementId();
     } catch (Exception $exc) {
         $this->core->logger->err($exc);
     }
 }