コード例 #1
0
 public function editAction()
 {
     $form_config = $this->current_module_config->forms->artist->toArray();
     unset($form_config['groups']['intro']);
     $form = new \DF\Form($form_config);
     if ($this->hasParam('id')) {
         $id = (int) $this->getParam('id');
         $record = Record::find($id);
         $form->setDefaults($record->toArray(TRUE, TRUE));
     }
     if ($_POST && $form->isValid($_POST)) {
         $data = $form->getValues();
         if (!$record instanceof Record) {
             $record = new Record();
         }
         $files = $form->processFiles('artists');
         foreach ($files as $file_field => $file_paths) {
             $data[$file_field] = $file_paths[1];
         }
         $record->fromArray($data);
         $record->save();
         $this->alert('Changes saved.', 'green');
         $origin = $this->getParam('origin', 'admin');
         if ($origin == 'profile') {
             return $this->redirectToRoute(array('module' => 'default', 'controller' => 'artists', 'action' => 'view', 'id' => $record->id));
         } else {
             return $this->redirectFromHere(array('action' => 'index', 'id' => NULL));
         }
     }
     $this->renderForm($form, 'edit', 'Edit Record');
 }
コード例 #2
0
 public function profileAction()
 {
     $this->acl->checkPermission('is logged in');
     $user = $this->auth->getLoggedInUser();
     $form_config = $this->module_config['admin']->forms->artist->toArray();
     unset($form_config['groups']['admin']);
     $form = new \DF\Form($form_config);
     if ($user->artist instanceof Artist) {
         $record = $user->artist;
         $form->setDefaults($record->toArray(TRUE, TRUE));
     }
     if ($_POST && $form->isValid($_POST)) {
         $data = $form->getValues();
         $files = $form->processFiles('artists');
         foreach ($files as $file_field => $file_paths) {
             $data[$file_field] = $file_paths[1];
         }
         if (!$record instanceof Artist) {
             // Check for existing artist with same name.
             $record = Artist::findAbandonedByName($data['name']);
             if ($record instanceof Artist) {
                 $record->user = $user;
             } else {
                 $record = new Artist();
                 $record->is_approved = false;
                 $record->user = $user;
             }
         }
         $record->fromArray($data);
         $record->save();
         $this->alert('<b>Your artist profile has been submitted!</b><br>After review, your profile will be listed on the Ponyville Live network artist directory. Thank you for your submission.', 'green');
         $this->redirectFromHere(array('action' => 'index'));
         return;
     }
     if ($user->is_artist) {
         $title = 'Update Artist Profile';
     } else {
         $title = 'Submit an Artist Profile';
     }
     $this->renderForm($form, 'edit', $title);
 }