Esempio n. 1
0
 public function doimportAction()
 {
     Wind::import('SRV:upload.action.PwWordUpload');
     Wind::import('LIB:upload.PwUpload');
     $bhv = new PwWordUpload();
     $upload = new PwUpload($bhv);
     if (($result = $upload->check()) === true) {
         $result = $upload->execute();
     }
     if ($result !== true) {
         $error = $result->getError();
         if (is_array($error)) {
             list($error, ) = $error;
             if ($error == 'upload.ext.error') {
                 $this->showError('WORD:ext.error');
             }
         }
         $this->showError($result->getError());
     }
     $source = $bhv->getAbsoluteFile();
     if (!WindFile::isFile($source)) {
         $this->showError('operate.fail');
     }
     $content = WindFile::read($source);
     pw::deleteAttach($bhv->dir . $bhv->filename, 0, $bhv->isLocal);
     $content = explode("\n", $content);
     if (!$content) {
         $this->showError('WORD:import.data.empty');
     }
     $wordService = $this->_getWordService();
     $typeMap = $this->_getWordDS()->getTypeMap();
     Wind::import('SRV:word.dm.PwWordDm');
     foreach ($content as $value) {
         list($word, $type, $replace) = $this->_parseTextUseInImport($value, $typeMap);
         if (!$word || !$type || $wordService->isExistWord($word)) {
             continue;
         }
         $dm = new PwWordDm();
         /* @var $dm PwWordDm */
         $dm->setWord($word)->setWordType($type);
         $replace = $this->_getWordDS()->isReplaceWord($type) ? $replace ? $replace : '****' : '';
         $dm->setWordReplace($replace);
         $this->_getWordDS()->add($dm);
     }
     $this->_getWordFilter()->updateCache();
     $this->showMessage('success');
 }
Esempio n. 2
0
 /**
  * 批量更新
  *
  * @param array $wordIds
  * @param PwWordDm $dm
  */
 public function batchUpdate($wordIds, PwWordDm $dm)
 {
     if (empty($wordIds) || !is_array($wordIds)) {
         return false;
     }
     if (($result = $dm->beforeUpdate()) !== true) {
         return $result;
     }
     $result = $this->_getDao()->batchUpdate($wordIds, $dm->getData());
     return $result;
 }