public function save($aData) { if (empty($aData['profileGuid'])) { throw new Zend_Exception('Catalog Profile can not be EMPTY!'); } $tblCatalog = new App_Model_Db_Table_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()); } $tableProfileAttribute = new App_Model_Db_Table_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 App_Model_Db_Table_CatalogAttribute(); $rowCatalogAttribute = $tblCatalogAttribute->fetchNew(); $rowCatalogAttribute->catalogGuid = $catalogGuid; $rowCatalogAttribute->attributeGuid = $rowProfileAttribute->attributeGuid; } $rowCatalogAttribute->value = isset($aData[$rowProfileAttribute->attributeGuid]) ? $aData[$rowProfileAttribute->attributeGuid] : ''; $rowCatalogAttribute->save(); } //save to table CatalogFolder only if folderGuid is not empty if (!empty($folderGuid)) { $tblCatalogFolder = new App_Model_Db_Table_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); return $catalogGuid; }
public function uploadFile($aDataCatalog, $relatedGuid) { if ($aDataCatalog['profileGuid'] != 'kutu_doc') { throw new Zend_Exception('Profile does not match profile for FILE'); } if (empty($relatedGuid)) { throw new Zend_Exception('No RELATED GUID specified!'); } $registry = Zend_Registry::getInstance(); $config = $registry->get(Pandamp_Keys::REGISTRY_APP_OBJECT); $cdn = $config->getOption('cdn'); $id = 1 + ($aDataCatalog['id'] - 1); for ($x = 1; $x < $id; $x++) { $title = $aDataCatalog['fixedTitle' . $x] ? $aDataCatalog['fixedTitle' . $x] : ''; $registry = Zend_Registry::getInstance(); $files = $registry->get('files'); if (isset($files['uploadedFile' . $x])) { $file = $files['uploadedFile' . $x]; //$this->checkTitle($aDataCatalog['fixedTitle'.$x]); } $type = $aDataCatalog['fixedType' . $x] ? $aDataCatalog['fixedType' . $x] : ''; if ($type == 'file') { $relatedType = 'RELATED_FILE'; } elseif ($type == 'image') { $relatedType = 'RELATED_IMAGE'; $this->checkSize($file['size'], $aDataCatalog['fixedTitle' . $x]); } elseif ($type == 'video') { $relatedType = 'RELATED_VIDEO'; } $tblCatalog = new App_Model_Db_Table_Catalog(); $gman = new Pandamp_Core_Guid(); $catalogGuid = isset($aDataCatalog['guid']) && !empty($aDataCatalog['guid']) ? $aDataCatalog['guid'] : $gman->generateGuid(); $folderGuid = isset($aDataCatalog['folderGuid']) && !empty($aDataCatalog['folderGuid']) ? $aDataCatalog['folderGuid'] : ''; $where = $tblCatalog->getAdapter()->quoteInto('guid=?', $catalogGuid); if ($tblCatalog->fetchRow($where)) { $rowCatalog = $tblCatalog->find($catalogGuid)->current(); $rowCatalog->shortTitle = isset($aDataCatalog['shortTitle']) ? $aDataCatalog['shortTitle'] : $rowCatalog->shortTitle; $rowCatalog->publishedDate = isset($aDataCatalog['publishedDate']) ? $aDataCatalog['publishedDate'] : $rowCatalog->publishedDate; $rowCatalog->expiredDate = isset($aDataCatalog['expiredDate']) ? $aDataCatalog['expiredDate'] : $rowCatalog->expiredDate; $rowCatalog->status = isset($aDataCatalog['status']) ? $aDataCatalog['status'] : $rowCatalog->status; } else { $rowCatalog = $tblCatalog->fetchNew(); $rowCatalog->guid = $catalogGuid; $rowCatalog->shortTitle = isset($aDataCatalog['shortTitle']) ? $aDataCatalog['shortTitle'] : ''; $rowCatalog->profileGuid = $aDataCatalog['profileGuid']; $rowCatalog->publishedDate = isset($aDataCatalog['publishedDate']) ? $aDataCatalog['publishedDate'] : '0000-00-00 00:00:00'; $rowCatalog->expiredDate = isset($aDataCatalog['expiredDate']) ? $aDataCatalog['expiredDate'] : '0000-00-00 00:00:00'; $rowCatalog->createdBy = isset($aDataCatalog['username']) ? $aDataCatalog['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($aDataCatalog['status']) ? $aDataCatalog['status'] : 0; } $catalogGuid = $rowCatalog->save(); $rowsetCatalogAttribute = $rowCatalog->findDependentRowsetCatalogAttribute(); if (isset($files['uploadedFile' . $x])) { if (isset($files['uploadedFile' . $x]['name']) && !empty($files['uploadedFile' . $x]['name'])) { $this->_updateCatalogAttribute($rowsetCatalogAttribute, $catalogGuid, 'docSystemName', strtoupper(str_replace(' ', '_', $file['name']))); $this->_updateCatalogAttribute($rowsetCatalogAttribute, $catalogGuid, 'docOriginalName', strtoupper(str_replace(' ', '_', $file['name']))); $this->_updateCatalogAttribute($rowsetCatalogAttribute, $catalogGuid, 'docSize', $file['size']); $this->_updateCatalogAttribute($rowsetCatalogAttribute, $catalogGuid, 'docMimeType', $file['type']); $this->_updateCatalogAttribute($rowsetCatalogAttribute, $catalogGuid, 'fixedTitle', $title); $this->_updateCatalogAttribute($rowsetCatalogAttribute, $catalogGuid, 'docViewOrder', 0); if ($type == 'file') { //$sDir = ROOT_DIR.DIRECTORY_SEPARATOR.'uploads'.DIRECTORY_SEPARATOR.'files'.DIRECTORY_SEPARATOR.$relatedGuid; $sDir = $cdn['static']['dir']['files'] . DIRECTORY_SEPARATOR . $relatedGuid; if (is_dir($sDir)) { move_uploaded_file($file['tmp_name'], $sDir . DIRECTORY_SEPARATOR . strtoupper(str_replace(' ', '_', $file['name']))); } else { if (mkdir($sDir)) { move_uploaded_file($file['tmp_name'], $sDir . DIRECTORY_SEPARATOR . strtoupper(str_replace(' ', '_', $file['name']))); } else { move_uploaded_file($file['tmp_name'], $cdn['static']['dir']['files'] . DIRECTORY_SEPARATOR . strtoupper(str_replace(' ', '_', $file['name']))); } } } elseif ($type == 'image') { $sDir = $cdn['static']['dir']['images']; //$sDir = ROOT_DIR.DIRECTORY_SEPARATOR.'uploads'.DIRECTORY_SEPARATOR.'images'; $file = $files['uploadedFile' . $x]['name']; $ext = explode(".", $file); $ext = strtolower(array_pop($ext)); if ($ext == "jpg" || $ext == "jpeg" || $ext == "gif" || $ext == "png") { //$target_path = $sDir.DIRECTORY_SEPARATOR.$catalogGuid.".".$ext; $thumb_mode = $sDir . DIRECTORY_SEPARATOR . $catalogGuid . "." . $ext; $thumb = $sDir . DIRECTORY_SEPARATOR . $relatedGuid . DIRECTORY_SEPARATOR . $catalogGuid . "." . $ext; $target_path = $sDir . DIRECTORY_SEPARATOR . $relatedGuid; if (is_dir($target_path)) { move_uploaded_file($files['uploadedFile' . $x]['tmp_name'], $target_path . DIRECTORY_SEPARATOR . $catalogGuid . "." . $ext); //chmod($target_path,0644); Pandamp_Lib_Formater::createthumb($thumb, $target_path . '/tn_' . $catalogGuid . "." . $ext, 275, 160); // sebelumnya 130x130 } else { if (mkdir($target_path)) { move_uploaded_file($files['uploadedFile' . $x]['tmp_name'], $target_path . DIRECTORY_SEPARATOR . $catalogGuid . "." . $ext); //chmod($target_path,0644); Pandamp_Lib_Formater::createthumb($thumb, $target_path . '/tn_' . $catalogGuid . "." . $ext, 275, 160); } else { move_uploaded_file($files['uploadedFile' . $x]['tmp_name'], $sDir . DIRECTORY_SEPARATOR . $catalogGuid . "." . $ext); //chmod($target_path,0644); Pandamp_Lib_Formater::createthumb($thumb_mode, $sDir . '/tn_' . $catalogGuid . "." . $ext, 275, 160); } } } } elseif ($type == 'video') { $sDir = $cdn['static']['dir']['video'] . DIRECTORY_SEPARATOR . $relatedGuid; //$sDir = ROOT_DIR.DIRECTORY_SEPARATOR.'uploads'.DIRECTORY_SEPARATOR.'video'.DIRECTORY_SEPARATOR.$relatedGuid; if (is_dir($sDir)) { move_uploaded_file($file['tmp_name'], $sDir . DIRECTORY_SEPARATOR . strtoupper(str_replace(' ', '_', $file['name']))); } else { if (mkdir($sDir)) { move_uploaded_file($file['tmp_name'], $sDir . DIRECTORY_SEPARATOR . strtoupper(str_replace(' ', '_', $file['name']))); } else { move_uploaded_file($file['tmp_name'], $cdn['static']['dir']['video'] . DIRECTORY_SEPARATOR . strtoupper(str_replace(' ', '_', $file['name']))); } } } } } $this->relateTo($catalogGuid, $relatedGuid, $relatedType); $indexingEngine = Pandamp_Search::manager(); $indexingEngine->indexCatalog($catalogGuid); $registry = Zend_Registry::getInstance(); $application = Zend_Registry::get(Pandamp_Keys::REGISTRY_APP_OBJECT); $res = $application->getOption('resources')['indexing']['solr']['write']; $esolr = new Pandamp_Search_Adapter_Esolr($res['host'], $res['port'], $res['dir4']); $esolr->indexCatalog($catalogGuid); } }