protected function _updateCatalogAttribute($rowsetCatalogAttribute, $catalogGuid, $attributeGuid, $value) { if ($rowsetCatalogAttribute->findByAttributeGuid($attributeGuid)) { $rowCatalogAttribute = $rowsetCatalogAttribute->findByAttributeGuid($attributeGuid); } else { $tblCatalogAttribute = new Pandamp_Modules_Dms_Catalog_Model_CatalogAttribute(); $rowCatalogAttribute = $tblCatalogAttribute->fetchNew(); $rowCatalogAttribute->catalogGuid = $catalogGuid; $rowCatalogAttribute->attributeGuid = $attributeGuid; } $rowCatalogAttribute->value = $value; $rowCatalogAttribute->save(); }
function saveAction() { $response = array(); $request = $this->getRequest(); $tblCatalog = new Pandamp_Modules_Dms_Catalog_Model_Catalog(); $auth = Zend_Auth::getInstance(); if ($auth->hasIdentity()) { $userName = $auth->getIdentity()->username; } $gman = new Pandamp_Core_Guid(); $catalogGuid = $request->getParam('guid') ? $request->getParam('guid') : $gman->generateGuid(); $folderGuid = $request->getParam('folderGuid') ? $request->getParam('folderGuid') : ''; //if not empty, there are 2 possibilities $where = $tblCatalog->getAdapter()->quoteInto('guid=?', $catalogGuid); if ($tblCatalog->fetchRow($where)) { $rowCatalog = $tblCatalog->find($catalogGuid)->current(); $rowCatalog->shortTitle = $request->getParam('shortTitle'); $rowCatalog->publishedDate = $request->getParam('publishedDate'); $rowCatalog->expiredDate = $request->getParam('expiredDate'); $rowCatalog->modifiedBy = $userName; $rowCatalog->modifiedDate = date("Y-m-d h:i:s"); $rowCatalog->status = $request->getParam('status'); } else { $rowCatalog = $tblCatalog->fetchNew(); $rowCatalog->shortTitle = $request->getParam('shortTitle'); $rowCatalog->profileGuid = $request->getParam('profileGuid'); $rowCatalog->publishedDate = $request->getParam('publishedDate'); $rowCatalog->expiredDate = $request->getParam('expiredDate'); $rowCatalog->createdBy = $userName; $rowCatalog->modifiedBy = $userName; $rowCatalog->createdDate = date("Y-m-d h:i:s"); $rowCatalog->modifiedDate = date("Y-m-d h:i:s"); $rowCatalog->deletedDate = '0000-00-00 00:00:00'; $rowCatalog->status = $request->getParam('status'); } $catalogGuid = $rowCatalog->save(); $tableProfileAttribute = new Pandamp_Modules_Dms_Profile_Model_ProfileAttribute(); $profileGuid = $rowCatalog->profileGuid; $where = $tableProfileAttribute->getAdapter()->quoteInto('profileGuid=?', $profileGuid); $rowsetProfileAttribute = $tableProfileAttribute->fetchAll($where, 'viewOrder ASC'); $rowsetCatalogAttribute = $rowCatalog->findDependentRowsetCatalogAttribute(); foreach ($rowsetProfileAttribute as $rowProfileAttribute) { if ($rowsetCatalogAttribute->findByAttributeGuid($rowProfileAttribute->attributeGuid)) { $rowCatalogAttribute = $rowsetCatalogAttribute->findByAttributeGuid($rowProfileAttribute->attributeGuid); } else { $tblCatalogAttribute = new Pandamp_Modules_Dms_Catalog_Model_CatalogAttribute(); $rowCatalogAttribute = $tblCatalogAttribute->fetchNew(); $rowCatalogAttribute->catalogGuid = $catalogGuid; $rowCatalogAttribute->attributeGuid = $rowProfileAttribute->attributeGuid; } $rowCatalogAttribute->value = $request->getParam($rowProfileAttribute->attributeGuid); $rowCatalogAttribute->save(); } //save to table CatalogFolder only if folderGuid is not empty if (!empty($folderGuid)) { $tblCatalogFolder = new Pandamp_Modules_Dms_Catalog_Model_CatalogFolder(); $rowsetCatalogFolder = $tblCatalogFolder->find($catalogGuid, $folderGuid); if (count($rowsetCatalogFolder) <= 0) { $rowCatalogFolder = $tblCatalogFolder->createRow(array('catalogGuid' => '', 'folderGuid' => '')); $rowCatalogFolder->catalogGuid = $catalogGuid; $rowCatalogFolder->folderGuid = $folderGuid; $rowCatalogFolder->save(); } } $response['success'] = true; echo Zend_Json::encode($response); }