示例#1
0
文件: actions.php 项目: kc5nra/RevTK
 /**
  * Export a Trinity(alpha) user's vocab/sentence flashcards.
  * 
  * Request parameters:
  * 
  *   mode    'vocab' to export the user's vocab flashcards
  *           'sentences' to export the user's sentence flashcards
  * 
  * @date  2009-10-30
  */
 public function executeExportTrinity($request)
 {
     $exportMode = $this->getRequestParameter('mode');
     if (!in_array($exportMode, array('vocab', 'sentences'))) {
         throw new coreException("error");
     }
     $throttler = new RequestThrottler($this->getUser(), 'trinity.export');
     if (!$throttler->isValid()) {
         return $this->renderPartial('misc/requestThrottleError');
     }
     $db = $this->getContext()->getDatabase();
     $csv = new ExportCSV($db);
     // We build the select here, Trinity is no longer supported, no need for extra peer classes.
     if ($exportMode === 'vocab') {
         $select = $db->select(array('compound', 'reading', 'glossary', 'itemid', 'dateadded', 'lastreview', 'leitnerbox', 'failurecount', 'successcount'))->from(array('r' => 'vocabreviews'))->join(array('d' => 'jdict'), 'r.itemid = d.dictid')->where('userid = ?', $this->getUser()->getUserId());
         $csvText = $csv->export($select, array('compound', 'reading', 'definition', 'dictid', 'dateadded', 'lastreview', 'leitnerbox', 'failcount', 'passcount'), array('col_escape' => array(1, 1, 1, 0, 0, 0, 0, 0, 0), 'column_heads' => false));
         $downloadName = 'trinity_vocab.csv';
     } else {
         if ($exportMode === 'sentences') {
             $select = $db->select(array('question', 'answer', 'sn.spakid', 'sp.title', 'sn.lastedited', 'sn.dateadded', 'lastreview', 'leitnerbox', 'failurecount', 'successcount'))->from(array('sr' => 'sentencereviews'))->join(array('sn' => 'sentences'), 'sr.itemid = sn.sentenceid AND sr.userid = sn.userid')->join(array('sp' => 'sentencepacks'), 'sn.spakid = sp.spakid AND sn.userid = sp.userid')->where('sr.userid = ?', $this->getUser()->getUserId());
             $csvText = $csv->export($select, array('question', 'answer', 'sp_id', 'sp_title', 'lastedited', 'dateadded', 'lastreview', 'leitnerbox', 'failcount', 'passcount'), array('col_escape' => array(1, 1, 0, 1, 0, 0, 0, 0, 0, 0), 'column_heads' => false));
             $downloadName = 'trinity_sentences.csv';
         }
     }
     $throttler->setTimeout();
     $this->getResponse()->setFileAttachmentHeaders($downloadName);
     $this->setLayout(false);
     return $this->renderText($csvText);
 }
示例#2
0
文件: actions.php 项目: kc5nra/RevTK
 /**
  * Export user's stories to CSV.
  * 
  * Note! 'col_escape' option must match the select from StoriesPeer::getSelectForExport()
  *
  */
 public function executeExport($request)
 {
     $response = $this->getResponse();
     $response->setContentType('text/plain; charset=utf-8');
     $throttler = new RequestThrottler($this->getUser(), 'study.export');
     if (!$throttler->isValid()) {
         //	$response->setContentType('text/plain; charset=utf-8');
         $response->setContentType('html');
         return $this->renderPartial('misc/requestThrottleError');
     }
     $csv = new ExportCSV($this->getContext()->getDatabase());
     $select = StoriesPeer::getSelectForExport($this->getUser()->getUserId());
     $csvText = $csv->export($select, array('framenum', 'kanji', 'keyword', 'public', 'last_edited', 'story'), array('col_escape' => array(0, 0, 1, 0, 0, 1)));
     $throttler->setTimeout();
     $response->setHttpHeader('Cache-Control', 'no-cache, must-revalidate');
     $response->setHttpHeader('Expires', 'Mon, 26 Jul 1997 05:00:00 GMT');
     $response->setHttpHeader('Content-Disposition', 'attachment; filename="my_stories.csv"');
     $this->setLayout(false);
     return $this->renderText($csvText);
 }
示例#3
0
文件: actions.php 项目: kc5nra/RevTK
 public function executeExportflashcards()
 {
     $throttler = new RequestThrottler($this->getUser(), 'export');
     if (!$throttler->isValid()) {
         return $this->renderPartial('misc/requestThrottleError');
     }
     $csv = new ExportCSV($this->getContext()->getDatabase());
     $select = ReviewsPeer::getSelectForExport($this->getUser()->getUserId());
     $csvText = $csv->export($select, array('FrameNumber', 'Kanji', 'Keyword', 'LastReview', 'ExpireDate', 'LeitnerBox', 'FailCount', 'PassCount'), array('col_escape' => array(0, 1, 1, 0, 0, 0, 0, 0)));
     $throttler->setTimeout();
     $this->getResponse()->setFileAttachmentHeaders('rtk_flashcards.csv');
     $this->setLayout(false);
     return $this->renderText($csvText);
 }