Exemplo n.º 1
0
 public function save($aData)
 {
     //do minimal pre-requisite of aData
     if (empty($aData['fixedTitle'])) {
         throw new Zend_Exception('Catalog Title can not be EMPTY!');
     }
     if (empty($aData['profileGuid'])) {
         throw new Zend_Exception('Catalog Profile can not be EMPTY!');
     }
     $tblCatalog = new Kutu_Core_Orm_Table_Catalog();
     $gman = new Kutu_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();
         //echo "guid ditemukan:" .$rowCatalog->guid;
         $rowCatalog->shortTitle = isset($aData['shortTitle']) ? $aData['shortTitle'] : $rowCatalog->shortTitle;
         //$rowCatalog->profileGuid = $request->getParam('profileGuid');
         $rowCatalog->publishedDate = isset($aData['publishedDate']) ? $aData['publishedDate'] : $rowCatalog->publishedDate;
         $rowCatalog->expiredDate = isset($aData['expiredDate']) ? $aData['expiredDate'] : $rowCatalog->expiredDate;
         //$rowCatalog->createdBy = $request->getParam('createdBy');
         //$rowCatalog->modifiedBy = ($aData['username'])?$aData['username']:'';
         //$rowCatalog->createdDate = $request->getParam('createdDate');
         //$rowCatalog->modifiedDate = $aData['modifiedDate'];
         //$rowCatalog->deletedDate = $request->getParam('deletedDate');
         $rowCatalog->status = isset($aData['status']) ? $aData['status'] : $rowCatalog->status;
         $rowCatalog->price = isset($aData['price']) ? $aData['price'] : $rowCatalog->price;
     } else {
         $rowCatalog = $tblCatalog->fetchNew();
         //echo "guid tidak ditemukan";
         $rowCatalog->guid = $catalogGuid;
         $rowCatalog->shortTitle = isset($aData['shortTitle']) ? $aData['shortTitle'] : '';
         $rowCatalog->profileGuid = $aData['profileGuid'];
         $rowCatalog->publishedDate = '0000-00-00 00:00:00';
         $rowCatalog->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 Kutu_Core_Orm_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);
             //echo "rowcatalogattribute:" . $rowCatalogAttribute->attributeGuid;
         } else {
             $tblCatalogAttribute = new Kutu_Core_Orm_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)) {
         $rowCatalog->copyToFolder($folderGuid);
     }
     //do indexing
     $indexingEngine = Kutu_Search::manager();
     $indexingEngine->indexCatalog($catalogGuid);
     //after indexing, update isIndex and indexedDate in table KutuCatalog
     return $catalogGuid;
 }
 private function _createDocs($sourceCatalogId, $guidPrefix = 'lgsimpfl')
 {
     // get all related documents
     $tblCatalog = new Kutu_Core_Orm_Table_Catalog();
     $tblCatalogAttribute = new Kutu_Core_Orm_Table_CatalogAttribute();
     $tblRelatedItem = new Kutu_Core_Orm_Table_RelatedItem();
     $this->_dbSource->setFetchMode(Zend_Db::FETCH_OBJ);
     $rowsetDocItem = $this->_dbSource->fetchAll("SELECT * from tblDms_DocItem A  \n\t\t\t\tWHERE A.CatalogID = {$sourceCatalogId}");
     foreach ($rowsetDocItem as $rowDocItem) {
         $rowsetCatalog = $tblCatalog->find($guidPrefix . $rowDocItem->DocItemID);
         if (count($rowsetCatalog) == 0) {
             $rowCatalog = $tblCatalog->fetchNew();
             $rowCatalog->guid = $guidPrefix . $rowDocItem->DocItemID;
             echo "KITI: " . $rowCatalog->guid;
             $sFileAsli = str_replace(array('_', '.'), '-', $rowDocItem->DocFileAsli);
             $rowCatalog->shortTitle = $sFileAsli;
             $rowCatalog->profileGuid = "kutu_doc";
             $rowCatalog->createdBy = $rowDocItem->DocCreator;
             $rowCatalog->modifiedBy = $rowDocItem->DocModifier;
             $rowCatalog->createdDate = $rowDocItem->DocCreated;
             $rowCatalog->modifiedDate = $rowDocItem->DocModified;
             $rowCatalog->save();
             $rowExp = $this->_dbSource->fetchRow("Select * from tblDms_Exp_Seq where DocItemID={$rowDocItem->DocItemID} AND DocumentID={$rowDocItem->CatalogID}");
             //	untuk catalogAttributenya tambahan agar isinya fixedTitle,dsb itu
             // fixedTitle
             $rowCatalogAttribute = $tblCatalogAttribute->fetchNew();
             $rowCatalogAttribute->catalogGuid = $guidPrefix . $rowDocItem->DocItemID;
             $rowCatalogAttribute->attributeGuid = 'fixedTitle';
             if (empty($rowExp->Friendlyname)) {
                 $rowCatalogAttribute->value = $rowDocItem->DocFileAsli;
             } else {
                 $rowCatalogAttribute->value = $rowExp->Friendlyname;
             }
             $rowCatalogAttribute->save();
             // fixedKeywords
             $rowCatalogAttribute = $tblCatalogAttribute->fetchNew();
             $rowCatalogAttribute->catalogGuid = $guidPrefix . $rowDocItem->DocItemID;
             $rowCatalogAttribute->attributeGuid = 'fixedKeywords';
             $rowCatalogAttribute->value = "";
             $rowCatalogAttribute->save();
             // fixedDescription
             $rowCatalogAttribute = $tblCatalogAttribute->fetchNew();
             $rowCatalogAttribute->catalogGuid = $guidPrefix . $rowDocItem->DocItemID;
             $rowCatalogAttribute->attributeGuid = 'fixedDescription';
             $rowCatalogAttribute->value = "";
             $rowCatalogAttribute->save();
             // fixedLanguage
             $rowCatalogAttribute = $tblCatalogAttribute->fetchNew();
             $rowCatalogAttribute->catalogGuid = $guidPrefix . $rowDocItem->DocItemID;
             $rowCatalogAttribute->attributeGuid = 'fixedLanguage';
             $rowCatalogAttribute->value = "en";
             $rowCatalogAttribute->save();
             // docCategoryGuid
             $rowCatalogAttribute = $tblCatalogAttribute->fetchNew();
             $rowCatalogAttribute->catalogGuid = $guidPrefix . $rowDocItem->DocItemID;
             $rowCatalogAttribute->attributeGuid = 'docCategoryGuid';
             $rowCatalogAttribute->value = "";
             $rowCatalogAttribute->save();
             // docSystemName
             $rowCatalogAttribute = $tblCatalogAttribute->fetchNew();
             $rowCatalogAttribute->catalogGuid = $guidPrefix . $rowDocItem->DocItemID;
             $rowCatalogAttribute->attributeGuid = 'docSystemName';
             $rowCatalogAttribute->value = $rowDocItem->DocFileName;
             $rowCatalogAttribute->save();
             // docOriginalName
             $rowCatalogAttribute = $tblCatalogAttribute->fetchNew();
             $rowCatalogAttribute->catalogGuid = $guidPrefix . $rowDocItem->DocItemID;
             $rowCatalogAttribute->attributeGuid = 'docOriginalName';
             $rowCatalogAttribute->value = $rowDocItem->DocFileAsli;
             $rowCatalogAttribute->save();
             // docSize
             $rowCatalogAttribute = $tblCatalogAttribute->fetchNew();
             $rowCatalogAttribute->catalogGuid = $guidPrefix . $rowDocItem->DocItemID;
             $rowCatalogAttribute->attributeGuid = 'docSize';
             $rowCatalogAttribute->value = $rowDocItem->DocSize;
             $rowCatalogAttribute->save();
             // docMimeType
             $rowCatalogAttribute = $tblCatalogAttribute->fetchNew();
             $rowCatalogAttribute->catalogGuid = $guidPrefix . $rowDocItem->DocItemID;
             $rowCatalogAttribute->attributeGuid = 'docMimeType';
             $rowCatalogAttribute->value = $rowDocItem->DocType;
             $rowCatalogAttribute->save();
         } else {
             echo 'Data tidak disimpan';
         }
         // related the file/document as RELATED_FILE
         $rowsetRelatedItem = $tblRelatedItem->find($guidPrefix . $rowDocItem->DocItemID, 'lgsimpdms' . $rowDocItem->CatalogID, "RELATED_FILE");
         if (count($rowsetRelatedItem) == 0) {
             $rowRelation = $tblRelatedItem->createNew();
             $rowRelation->itemGuid = $guidPrefix . $rowDocItem->DocItemID;
             $rowRelation->relatedGuid = 'lgsimpdms' . $rowDocItem->CatalogID;
             $rowRelation->relateAs = "RELATED_FILE";
             if (isset($rowExp->Sequence)) {
                 $rowRelation->valueIntRelation = $rowExp->Sequence;
             }
             $rowRelation->save();
             //echo "<font color=blue>Record ke = ".$r." dari itemGuid = fl".$row->DocItemID." - ".$row->CatalogID." relasi file di-saved</font><br>";
         }
     }
 }