<commit_before><?php

namespace Audio\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Mongo;
use MongoId;
use MongoDate;
use Album\Entity\DBconnection;
use Album\Form\AudioForm;
use Audio\Form\UploadForm;
use Audio\Form\UpdateForm;
use Audio\Form\ViewAudioForm;
use \Dandan;
class AudioController extends AbstractActionController
{
	public function indexAction()
	{
		
		return new ViewModel();
	}
	public function uploadAction()
	{
		ini_set('display_errors', '1');
		$flag = 0;
		$mongo = DBConnection::instantiate();
		//get a MongoGridFS instance
		$gridFS = $mongo->database->getGridFS();
		$form = new UploadForm('upload-form');
		// $form->setValidationGroup('title', 'monthyear', 'caption', 'audio-file');
		$request = $this->getRequest();
		if ($request->isPost()) {
			// Make certain to merge the files info!
			$post = array_merge_recursive($request->getPost()->toArray() , $request->getFiles()->toArray());
			// $post = $request->getPost();
			$form->setData($post);
			if ($form->isValid()) {
				$data = $form->getData();
				$filetype = $data['audio-file']['type'];
				$title = $data['title'];
				$monthyear = $post['monthyear'];
				$tmpfilepath = $data['audio-file']['tmp_name'];
				$caption = $data['caption'];
				$filename = $data['audio-file']['name'];
				$mp3file = $tmpfilepath;
				$gridFS->storeFile($mp3file, array(
					'audioname' => $filename,
					'filetype' => $filetype,
					'state' => $post['state'],
					'city' => $post['city'],
					'caption' => $caption,
					'title' => $title,
					'monthyear' => $monthyear,
				));
				$flag = 1;
				
				return $this->redirect()->toRoute('audio', array(
					'action' => 'audioindb'
				));
			}
		}
		
		return array(
			'form' => $form,
			'flag' => $flag,
		);
	}
	public function updateAction()
	{
		ini_set('display_errors', '1');
		$id = $this->getEvent()->getRouteMatch()->getParam('id');
		$mongo = DBConnection::instantiate();
		$gridFS = $mongo->database->getGridFS();
		$mp3 = $gridFS->findOne(array(
			'_id' => new MongoId($id)
		));
		$form = new UploadForm();
		$form->setData($mp3->file);
		$request = $this->getRequest();
		if ($request->isPost()) {
			// Make certain to merge the files info!
			$post = $request->getPost();
			$form->setData($post);
			var_dump($post);
				// var_dump($data);
				// $filetype = $data['audio-file']['type'];
				$title = '2222222222222222222';
				// $title = $post['title'];
				// $filename = $data['audio-file']['name'];
				// $mp3file = $tmpfilepath;
				echo '111111111111111';
				$gridFS->update(array("_id" => $id), array(
					// 'audioname' => $filename,
					'title' => $title,
				));
				$flag = 1;
				
/*				return $this->redirect()->toRoute('audio', array(
					'action' => 'audioindb'
				));*/
		}
		<commit_msg>gridfs update<commit_after><?php

namespace Audio\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Mongo;
use MongoId;
use MongoDate;
use Album\Entity\DBconnection;
use Album\Form\AudioForm;
use Audio\Form\UploadForm;
use Audio\Form\UpdateForm;
use Audio\Form\ViewAudioForm;
use \Dandan;
class AudioController extends AbstractActionController
{
	public function indexAction()
	{
		
		return new ViewModel();
	}
	public function uploadAction()
	{
		ini_set('display_errors', '1');
		$flag = 0;
		$mongo = DBConnection::instantiate();
		//get a MongoGridFS instance
		$gridFS = $mongo->database->getGridFS();
		$form = new UploadForm('upload-form');
		// $form->setValidationGroup('title', 'monthyear', 'caption', 'audio-file');
		$request = $this->getRequest();
		if ($request->isPost()) {
			// Make certain to merge the files info!
			$post = array_merge_recursive($request->getPost()->toArray() , $request->getFiles()->toArray());
			// $post = $request->getPost();
			$form->setData($post);
			if ($form->isValid()) {
				$data = $form->getData();
				$filetype = $data['audio-file']['type'];
				$title = $data['title'];
				$monthyear = $post['monthyear'];
				$tmpfilepath = $data['audio-file']['tmp_name'];
				$caption = $data['caption'];
				$filename = $data['audio-file']['name'];
				$mp3file = $tmpfilepath;
				$gridFS->storeFile($mp3file, array(
					'audioname' => $filename,
					'filetype' => $filetype,
					'state' => $post['state'],
					'city' => $post['city'],
					'caption' => $caption,
					'title' => $title,
					'monthyear' => $monthyear,
				));
				$flag = 1;
				
				return $this->redirect()->toRoute('audio', array(
					'action' => 'audioindb'
				));
			}
		}
		
		return array(
			'form' => $form,
			'flag' => $flag,
		);
	}
	public function updateAction()
	{
		ini_set('display_errors', '1');
		$id = $this->getEvent()->getRouteMatch()->getParam('id');
		$mongo = DBConnection::instantiate();
		$gridFS = $mongo->database->getGridFS();
		$mp3 = $gridFS->findOne(array(
			'_id' => new MongoId($id)
		));
		$form = new UploadForm();
		$form->setData($mp3->file);
		$request = $this->getRequest();
		if ($request->isPost()) {
			// Make certain to merge the files info!
			$post = $request->getPost();
			$form->setData($post);
			var_dump($post);
				// var_dump($data);
				// $filetype = $data['audio-file']['type'];
				$title = '2222222222222222222';
				// $title = $post['title'];
				// $filename = $data['audio-file']['name'];
				// $mp3file = $tmpfilepath;
				echo '111111111111111';
				// $gridFS->update(array("_id" => $id), array(
				$gridFS->update(array("audioname" => "shandong.mp3"), array(
					'$set' => array(
					'title' => $title,)
				));
				$flag = 1;
				
/*				return $this->redirect()->toRoute('audio', array(
					'action' => 'audioindb'
				));*/
		}
		
{'fraction_non_alphanumeric': 0.20776937950430655, 'fraction_numerical': 0.01564422569871682, 'mean_word_length': 3.6563011456628476, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 97, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, 'word_list_counts': {'cursed_substrings.json': 11, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2647545', 'n_tokens_mistral': 2383, 'n_tokens_neox': 1943, 'n_words': 370}