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); }
public function save($aData) { if (empty($aData['profileGuid'])) { throw new Zend_Exception('Catalog Profile can not be EMPTY!'); } $tblCatalog = new Pandamp_Modules_Dms_Catalog_Model_Catalog(); $gman = new Pandamp_Core_Guid(); $catalogGuid = isset($aData['guid']) && !empty($aData['guid']) ? $aData['guid'] : $gman->generateGuid(); $folderGuid = isset($aData['folderGuid']) && !empty($aData['folderGuid']) ? $aData['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 = isset($aData['shortTitle']) ? $aData['shortTitle'] : $rowCatalog->shortTitle; $rowCatalog->publishedDate = isset($aData['publishedDate']) ? $aData['publishedDate'] : $rowCatalog->publishedDate; $rowCatalog->expiredDate = isset($aData['expiredDate']) ? $aData['expiredDate'] : $rowCatalog->expiredDate; $rowCatalog->status = isset($aData['status']) ? $aData['status'] : $rowCatalog->status; $rowCatalog->price = isset($aData['price']) ? $aData['price'] : $rowCatalog->price; } else { $rowCatalog = $tblCatalog->fetchNew(); $rowCatalog->guid = $catalogGuid; $rowCatalog->shortTitle = isset($aData['shortTitle']) ? $aData['shortTitle'] : ''; $rowCatalog->profileGuid = $aData['profileGuid']; $rowCatalog->publishedDate = isset($aData['publishedDate']) ? $aData['publishedDate'] : '0000-00-00 00:00:00'; $rowCatalog->expiredDate = isset($aData['expiredDate']) ? $aData['expiredDate'] : '0000-00-00 00:00:00'; $rowCatalog->createdBy = isset($aData['username']) ? $aData['username'] : ''; $rowCatalog->modifiedBy = $rowCatalog->createdBy; $rowCatalog->createdDate = date("Y-m-d h:i:s"); $rowCatalog->modifiedDate = $rowCatalog->createdDate; $rowCatalog->deletedDate = '0000-00-00 00:00:00'; $rowCatalog->status = isset($aData['status']) ? $aData['status'] : 0; $rowCatalog->price = isset($aData['price']) ? $aData['price'] : 0; } try { $catalogGuid = $rowCatalog->save(); } catch (Exception $e) { die($e->getMessage()); } //$cache = Zend_Registry::get('cache'); $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 = isset($aData[$rowProfileAttribute->attributeGuid]) ? $aData[$rowProfileAttribute->attributeGuid] : ''; //$cacheKey = "gcav_cg_".$catalogGuid."_ag_".$rowProfileAttribute->attributeGuid; //if ($cacheKey) $cache->remove($cacheKey); $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(); } } //do indexing $indexingEngine = Pandamp_Search::manager(); $indexingEngine->indexCatalog($catalogGuid); //$cache->remove("catalog"); try { $url_content = ROOT_URL . '/berita/baca/' . $catalogGuid . '/' . $rowCatalog->shortTitle; $url = 'http://developers.facebook.com/tools/lint/?url={' . $url_content . '}&format=json'; $ch = curl_init($url); curl_setopt($ch, CURLOPT_NOBODY, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_exec($ch); $retcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); } catch (Exception $e) { die($e->getMessage()); } return $catalogGuid; }
function moveToCatalogAction() { $selitem = $this->_getParam('selitem') ? $this->_getParam('selitem') : ''; $targetGuid = $this->_getParam('targetGuid') ? $this->_getParam('targetGuid') : ''; $currentGuid = $this->_getParam('folderGuid') ? $this->_getParam('folderGuid') : ''; $tblCatalogFolder = new Pandamp_Modules_Dms_Catalog_Model_CatalogFolder(); $rowset = $tblCatalogFolder->find($selitem, $currentGuid)->current(); $rowset->folderGuid = $targetGuid; try { $rowset->save(); $this->view->success = true; $this->view->message = 'Move to Catalog Success'; } catch (Exception $e) { $this->view->success = false; $this->view->error = $e->getMessage(); } }