public function editfolderAction() { $this->fa->readOnly(); $form_config = $this->current_module_config->forms->folder->toArray(); $form_config['elements']['group_id'][1]['options'] = FolderGroup::fetchSelect($this->user->id, 'No Group'); $form = new \FA\Form($form_config); $id = (int) $this->getParam('id'); if ($id) { $record = Folder::getRepository()->findOneBy(array('id' => $id, 'user_id' => $this->user->id)); if (!$record instanceof Folder) { throw new \FA\Exception('Folder ID not found!'); } $form->populate($record->toArray()); } if ($this->request->isPost() && $form->isValid($_POST)) { $data = $form->getValues(); if (!$record instanceof Folder) { // TODO: Enforce folder count limit. $record = new Folder(); $record->user = $this->user; $record->sort_order = 100; } $record->fromArray($data); $record->save(); $this->_reSort(); $this->alert('<b>Folder updated!</b>', 'green'); return $this->redirectFromHere(array('action' => 'index', 'id' => NULL)); } $this->view->form = $form; }
/** * Assign submission(s) to a newly created folder. * * @return \Phalcon\Http\Response|\Phalcon\Http\ResponseInterface * @throws \FA\Exception */ public function createfolderAction() { $submissions = $this->_initBulkAction(); $folder_name = trim($this->getParam('new_folder_name')); if (empty($folder_name)) { throw new \FA\Exception('No folder name provided!'); } $folder = new Folder(); $folder->user = $this->user; $folder->name = $folder_name; $folder->save(); foreach ($submissions as $submission) { $subfolder = new UploadFolder(); $subfolder->upload = $submission; $subfolder->folder = $folder; $this->em->persist($subfolder); } $this->em->flush(); $this->alert('<b>Submissions added to a newly created folder!</b>', 'green'); return $this->redirectFromHere(array('action' => 'index', 'ids' => NULL)); }