Exemple #1
0
 /**
  * Save a type
  *
  * @return     void
  */
 public function saveTask($redirect = false)
 {
     // Check for request forgeries
     Request::checkToken();
     $fields = Request::getVar('fields', array(), 'post', 'none', 2);
     $fields = array_map('trim', $fields);
     // Initiate extended database class
     $row = new \Components\Publications\Tables\MasterType($this->database);
     $url = Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&task=edit&id[]=' . $fields['id'], false);
     // Load record
     if ($fields['id']) {
         $row->load($fields['id']);
     }
     // Bind new data
     if (!$row->bind($fields)) {
         $this->addComponentMessage($row->getError(), 'error');
         App::redirect($url);
         return;
     }
     // Save curation config
     if ($row->id) {
         // Incoming
         $curatorGroup = Request::getVar('curatorgroup', '');
         if ($group = \Hubzero\User\Group::getInstance($curatorGroup)) {
             $row->curatorGroup = $group->get('gidNumber');
         }
         if (!$curatorGroup) {
             $row->curatorGroup = 0;
         }
         $objC = new \Components\Publications\Models\Curation($row->curation);
         $manifest = $objC->_manifest;
         // Get curation configs
         $curation = Request::getVar('curation', array(), 'post');
         // Collect modifications
         if (is_array($curation)) {
             // Save params
             if (isset($curation['params'])) {
                 foreach ($curation['params'] as $cpName => $cpValue) {
                     $manifest->params->{$cpName} = trim($cpValue);
                 }
             }
             // Save blocks
             if (isset($curation['blocks'])) {
                 foreach ($curation['blocks'] as $blockId => $blockData) {
                     foreach ($blockData as $dataLabel => $dataValue) {
                         if ($dataLabel == 'params') {
                             // Save block params
                             foreach ($dataValue as $bpName => $bpValue) {
                                 // Determine value type
                                 if (is_array($manifest->blocks->{$blockId}->{$dataLabel}->{$bpName})) {
                                     $pval = trim($bpValue) ? explode(',', trim($bpValue)) : array();
                                 } else {
                                     $pval = trim($bpValue);
                                 }
                                 $manifest->blocks->{$blockId}->{$dataLabel}->{$bpName} = $pval;
                             }
                         } else {
                             $manifest->blocks->{$blockId}->{$dataLabel} = trim($dataValue);
                         }
                     }
                 }
             }
         }
         // Store modified curation
         $row->curation = json_encode($manifest);
     } else {
         // Get parameters
         $params = Request::getVar('params', '', 'post');
         if (is_array($params)) {
             $txt = array();
             foreach ($params as $k => $v) {
                 $txt[] = "{$k}={$v}";
             }
             $row->params = implode("\n", $txt);
         }
     }
     // Check content
     if (!$row->check()) {
         App::redirect($url, $row->getError(), 'error');
         return;
     }
     // Store new content
     if (!$row->store()) {
         App::redirect($url, $row->getError(), 'error');
         return;
     }
     // Redirect to edit view?
     if ($redirect) {
         App::redirect($url, Lang::txt('COM_PUBLICATIONS_SUCCESS_TYPE_SAVED'));
     } else {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_PUBLICATIONS_SUCCESS_TYPE_SAVED'));
     }
     return;
 }