/**
  * save
  * @author Cornelius Hansjakob <*****@*****.**>
  * @version 1.1
  */
 public function save()
 {
     $this->core->logger->debug('massiveart->generic->data->GenericDataTypeCategory->save()');
     try {
         $intUserId = Zend_Auth::getInstance()->getIdentity()->id;
         $this->getModelCategories()->setLanguageId($this->setup->getLanguageId());
         /**
          * add|edit|newVersion core and instance data
          */
         switch ($this->setup->getActionType()) {
             case $this->core->sysConfig->generic->actions->add:
                 /**
                  * add category node to the "Nested Set Model"
                  */
                 $this->setup->setElementId($this->objModelCategories->addCategoryNode($this->setup->getParentId(), array('idCategoryTypes' => $this->setup->getElementTypeId())));
                 if (count($this->setup->CoreFields()) > 0) {
                     foreach ($this->setup->CoreFields() as $strField => $objField) {
                         $arrCoreData = array('idCategories' => $this->setup->getElementId(), 'idLanguages' => $this->setup->getLanguageId(), $strField => $objField->getValue(), 'idUsers' => $intUserId, 'changed' => date('Y-m-d H:i:s'));
                         $this->getModelGenericData()->getGenericTable('category' . (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('category' . (substr($strField, strlen($strField) - 1) == 'y' ? ucfirst(rtrim($strField, 'y')) . 'ies' : ucfirst($strField) . 's'));
                         $arrCoreData = array($strField => $objField->getValue(), 'idUsers' => $intUserId, 'changed' => date('Y-m-d H:i:s'));
                         $strWhere = $objGenTable->getAdapter()->quoteInto('idCategories = ?', $this->setup->getElementId());
                         $strWhere .= $objGenTable->getAdapter()->quoteInto(' AND idLanguages = ?', $this->setup->getLanguageId());
                         $intNumOfEffectedRows = $objGenTable->update($arrCoreData, $strWhere);
                         if ($intNumOfEffectedRows == 0) {
                             $arrCoreData = array('idCategories' => $this->setup->getElementId(), 'idLanguages' => $this->setup->getLanguageId(), $strField => $objField->getValue(), 'idUsers' => $intUserId, 'changed' => date('Y-m-d H:i:s'));
                             $objGenTable->insert($arrCoreData);
                         }
                     }
                 }
                 break;
         }
         return $this->setup->getElementId();
     } catch (Exception $exc) {
         $this->core->logger->err($exc);
     }
 }