예제 #1
0
 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;
 }