Пример #1
0
 protected function customExport()
 {
     $fields = array();
     $query = array();
     $limit = $this->request->getParam('limit');
     $skip = $this->request->getParam('skip');
     $limit = empty($limit) ? false : $limit;
     $skip = empty($skip) ? false : $skip;
     $path = '/tmp/';
     $fileName = $this->request->getParam('file_name');
     $fileName = (empty($fileName) ? $this->collection : $fileName) . '.json';
     $cursor = $this->getModel()->find($this->db, $this->collection, $query, $fields, $limit, $skip);
     $file = new File($path, $fileName);
     $file->delete();
     $cryptography = new Cryptography();
     while ($cursor->hasNext()) {
         $document = $cursor->getNext();
         $file->write($cryptography->arrayToJSON($document) . "\n");
     }
     if ($this->request->getParam('text_or_save') == 'save') {
         if ($file->success) {
             if ($this->request->getParam('compression') == 'none') {
                 $file->download();
             } else {
                 $compressFile = $this->createCompress($fileName, $file);
                 if ($compressFile) {
                     $file->download($compressFile);
                 } else {
                     $this->message->error = $file->message;
                     return false;
                 }
             }
         } else {
             $this->message->error = $file->message;
             return false;
         }
     } else {
         return file_get_contents($path . $fileName);
     }
 }