コード例 #1
0
ファイル: Instance.php プロジェクト: hyebahi/civicrm-core
 /**
  * Post process function.
  *
  * @param CRM_Core_Form $form
  * @param bool $redirect
  */
 public static function postProcess(&$form, $redirect = TRUE)
 {
     $params = $form->getVar('_params');
     $instanceID = $form->getVar('_id');
     if ($isNew = $form->getVar('_createNew')) {
         // set the report_id since base template is going to be same, and we going to unset $instanceID
         // which will make it difficult later on, to compute report_id
         $params['report_id'] = CRM_Report_Utils_Report::getValueFromUrl($instanceID);
         // Unset $instanceID so a new copy would be created.
         $instanceID = NULL;
     }
     $params['instance_id'] = $instanceID;
     if (!empty($params['is_navigation'])) {
         $params['navigation'] = $form->_navigation;
     } elseif ($instanceID) {
         // Delete navigation if exists.
         $navId = CRM_Core_DAO::getFieldValue('CRM_Report_DAO_ReportInstance', $instanceID, 'navigation_id', 'id');
         if ($navId) {
             CRM_Core_BAO_Navigation::processDelete($navId);
             CRM_Core_BAO_Navigation::resetNavigation();
         }
     }
     // make a copy of params
     $formValues = $params;
     // unset params from $formValues that doesn't match with DB columns of instance tables, and also not required in form-values for sure
     $unsetFields = array('title', 'to_emails', 'cc_emails', 'header', 'footer', 'qfKey', 'id', '_qf_default', 'report_header', 'report_footer', 'grouprole');
     foreach ($unsetFields as $field) {
         unset($formValues[$field]);
     }
     $view_mode = $formValues['view_mode'];
     // pass form_values as string
     $params['form_values'] = serialize($formValues);
     $instance = CRM_Report_BAO_ReportInstance::create($params);
     $form->set('id', $instance->id);
     if ($instanceID && !$isNew) {
         // updating existing instance
         $statusMsg = ts('"%1" report has been updated.', array(1 => $instance->title));
     } elseif ($form->getVar('_id') && $isNew) {
         $statusMsg = ts('Your report has been successfully copied as "%1". You are currently viewing the new copy.', array(1 => $instance->title));
     } else {
         $statusMsg = ts('"%1" report has been successfully created. You are currently viewing the new report instance.', array(1 => $instance->title));
     }
     CRM_Core_Session::setStatus($statusMsg);
     if ($redirect) {
         $urlParams = array('reset' => 1);
         if ($view_mode == 'view') {
             $urlParams['force'] = 1;
         } else {
             $urlParams['output'] = 'criteria';
         }
         CRM_Utils_System::redirect(CRM_Utils_System::url("civicrm/report/instance/{$instance->id}", $urlParams));
     }
 }