Example #1
0
  /**
   * see notes on processfilter - 'fixing' this doesn't seem to work across the board
   *
   * @param string $fieldName
   * @param array $field
   * @param array $defaults
   *
   * @return boolean
   */
  function dateParam($fieldName, &$field, &$defaults) {
    // type = 12 (datetime) is not recognized by Utils_Type::escape() method,
    // and therefore the below hack
    $type = 4;

    $from = CRM_Report_Utils_Get::getTypedValue("{$fieldName}_from", $type);
    $to = CRM_Report_Utils_Get::getTypedValue("{$fieldName}_to", $type);

    $relative = CRM_Utils_Array::value("{$fieldName}_relative", $_GET);
    if ($relative) {
      list($from, $to) = CRM_Report_Form::getFromTo($relative, NULL, NULL);
      $from = substr($from, 0, 8);
      $to = substr($to, 0, 8);
    }

    if (!($from || $to)) {
      return FALSE;
    }

    if ($from !== NULL) {
      $dateFrom = CRM_Utils_Date::setDateDefaults($from);
      if ($dateFrom !== NULL &&
        !empty($dateFrom[0])
      ) {
        $defaults["{$fieldName}_from"] = date('m/d/Y', strtotime($dateFrom[0]));
        $defaults["{$fieldName}_relative"] = 0;
      }
    }

    if ($to !== NULL) {
      $dateTo = CRM_Utils_Date::setDateDefaults($to);
      if ($dateTo !== NULL &&
        !empty($dateTo[0])
      ) {
        $defaults["{$fieldName}_to"] = $dateTo[0];
        $defaults["{$fieldName}_relative"] = 0;
      }
    }
  }
Example #2
0
 /**
  * Pre process function.
  *
  * Called prior to build form.
  */
 public function preProcess()
 {
     $this->preProcessCommon();
     if (!$this->_id) {
         $this->addBreadCrumb();
     }
     foreach ($this->_columns as $tableName => $table) {
         // set alias
         if (!isset($table['alias'])) {
             $this->_columns[$tableName]['alias'] = substr($tableName, 8) . '_civireport';
         } else {
             $this->_columns[$tableName]['alias'] = $table['alias'] . '_civireport';
         }
         $this->_aliases[$tableName] = $this->_columns[$tableName]['alias'];
         $daoOrBaoName = NULL;
         // higher preference to bao object
         if (array_key_exists('bao', $table)) {
             $daoOrBaoName = $table['bao'];
             $expFields = $daoOrBaoName::exportableFields();
         } elseif (array_key_exists('dao', $table)) {
             $daoOrBaoName = $table['dao'];
             $expFields = $daoOrBaoName::export();
         } else {
             $expFields = array();
         }
         $doNotCopy = array('required');
         $fieldGroups = array('fields', 'filters', 'group_bys', 'order_bys');
         foreach ($fieldGroups as $fieldGrp) {
             if (!empty($table[$fieldGrp]) && is_array($table[$fieldGrp])) {
                 foreach ($table[$fieldGrp] as $fieldName => $field) {
                     // $name is the field name used to reference the BAO/DAO export fields array
                     $name = isset($field['name']) ? $field['name'] : $fieldName;
                     // Sometimes the field name key in the BAO/DAO export fields array is
                     // different from the actual database field name.
                     // Unset $field['name'] so that actual database field name can be obtained
                     // from the BAO/DAO export fields array.
                     unset($field['name']);
                     if (array_key_exists($name, $expFields)) {
                         foreach ($doNotCopy as $dnc) {
                             // unset the values we don't want to be copied.
                             unset($expFields[$name][$dnc]);
                         }
                         if (empty($field)) {
                             $this->_columns[$tableName][$fieldGrp][$fieldName] = $expFields[$name];
                         } else {
                             foreach ($expFields[$name] as $property => $val) {
                                 if (!array_key_exists($property, $field)) {
                                     $this->_columns[$tableName][$fieldGrp][$fieldName][$property] = $val;
                                 }
                             }
                         }
                     }
                     // fill other vars
                     if (!empty($field['no_repeat'])) {
                         $this->_noRepeats[] = "{$tableName}_{$fieldName}";
                     }
                     if (!empty($field['no_display'])) {
                         $this->_noDisplay[] = "{$tableName}_{$fieldName}";
                     }
                     // set alias = table-name, unless already set
                     $alias = isset($field['alias']) ? $field['alias'] : (isset($this->_columns[$tableName]['alias']) ? $this->_columns[$tableName]['alias'] : $tableName);
                     $this->_columns[$tableName][$fieldGrp][$fieldName]['alias'] = $alias;
                     // set name = fieldName, unless already set
                     if (!isset($this->_columns[$tableName][$fieldGrp][$fieldName]['name'])) {
                         $this->_columns[$tableName][$fieldGrp][$fieldName]['name'] = $name;
                     }
                     // set dbAlias = alias.name, unless already set
                     if (!isset($this->_columns[$tableName][$fieldGrp][$fieldName]['dbAlias'])) {
                         $this->_columns[$tableName][$fieldGrp][$fieldName]['dbAlias'] = $alias . '.' . $this->_columns[$tableName][$fieldGrp][$fieldName]['name'];
                     }
                     // a few auto fills for filters
                     if ($fieldGrp == 'filters') {
                         // fill operator types
                         if (!array_key_exists('operatorType', $this->_columns[$tableName][$fieldGrp][$fieldName])) {
                             switch (CRM_Utils_Array::value('type', $this->_columns[$tableName][$fieldGrp][$fieldName])) {
                                 case CRM_Utils_Type::T_MONEY:
                                 case CRM_Utils_Type::T_FLOAT:
                                     $this->_columns[$tableName][$fieldGrp][$fieldName]['operatorType'] = CRM_Report_Form::OP_FLOAT;
                                     break;
                                 case CRM_Utils_Type::T_INT:
                                     $this->_columns[$tableName][$fieldGrp][$fieldName]['operatorType'] = CRM_Report_Form::OP_INT;
                                     break;
                                 case CRM_Utils_Type::T_DATE:
                                     $this->_columns[$tableName][$fieldGrp][$fieldName]['operatorType'] = CRM_Report_Form::OP_DATE;
                                     break;
                                 case CRM_Utils_Type::T_BOOLEAN:
                                     $this->_columns[$tableName][$fieldGrp][$fieldName]['operatorType'] = CRM_Report_Form::OP_SELECT;
                                     if (!array_key_exists('options', $this->_columns[$tableName][$fieldGrp][$fieldName])) {
                                         $this->_columns[$tableName][$fieldGrp][$fieldName]['options'] = array('' => ts('Any'), '0' => ts('No'), '1' => ts('Yes'));
                                     }
                                     break;
                                 default:
                                     if ($daoOrBaoName && array_key_exists('pseudoconstant', $this->_columns[$tableName][$fieldGrp][$fieldName])) {
                                         // with multiple options operator-type is generally multi-select
                                         $this->_columns[$tableName][$fieldGrp][$fieldName]['operatorType'] = CRM_Report_Form::OP_MULTISELECT;
                                         if (!array_key_exists('options', $this->_columns[$tableName][$fieldGrp][$fieldName])) {
                                             // fill options
                                             $this->_columns[$tableName][$fieldGrp][$fieldName]['options'] = CRM_Core_PseudoConstant::get($daoOrBaoName, $fieldName);
                                         }
                                     }
                                     break;
                             }
                         }
                     }
                 }
             }
         }
         // copy filters to a separate handy variable
         if (array_key_exists('filters', $table)) {
             $this->_filters[$tableName] = $this->_columns[$tableName]['filters'];
         }
         if (array_key_exists('group_bys', $table)) {
             $groupBys[$tableName] = $this->_columns[$tableName]['group_bys'];
         }
         if (array_key_exists('fields', $table)) {
             $reportFields[$tableName] = $this->_columns[$tableName]['fields'];
         }
     }
     if ($this->_force) {
         $this->setDefaultValues(FALSE);
     }
     CRM_Report_Utils_Get::processFilter($this->_filters, $this->_defaults);
     CRM_Report_Utils_Get::processGroupBy($groupBys, $this->_defaults);
     CRM_Report_Utils_Get::processFields($reportFields, $this->_defaults);
     CRM_Report_Utils_Get::processChart($this->_defaults);
     if ($this->_force) {
         $this->_formValues = $this->_defaults;
         $this->postProcess();
     }
 }
 function preProcess()
 {
     self::preProcessCommon();
     if (!$this->_id) {
         self::addBreadCrumb();
     }
     foreach ($this->_columns as $tableName => $table) {
         // set alias
         if (!isset($table['alias'])) {
             $this->_columns[$tableName]['alias'] = substr($tableName, 8) . '_civireport';
         } else {
             $this->_columns[$tableName]['alias'] = $table['alias'] . '_civireport';
         }
         $this->_aliases[$tableName] = $this->_columns[$tableName]['alias'];
         // higher preference to bao object
         if (array_key_exists('bao', $table)) {
             require_once str_replace('_', DIRECTORY_SEPARATOR, $table['bao'] . '.php');
             eval("\$expFields = {$table['bao']}::exportableFields( );");
         } else {
             require_once str_replace('_', DIRECTORY_SEPARATOR, $table['dao'] . '.php');
             eval("\$expFields = {$table['dao']}::export( );");
         }
         $doNotCopy = array('required');
         $fieldGroups = array('fields', 'filters', 'group_bys', 'order_bys');
         foreach ($fieldGroups as $fieldGrp) {
             if (CRM_Utils_Array::value($fieldGrp, $table) && is_array($table[$fieldGrp])) {
                 foreach ($table[$fieldGrp] as $fieldName => $field) {
                     // $name is the field name used to reference the BAO/DAO export fields array
                     $name = isset($field['name']) ? $field['name'] : $fieldName;
                     // Sometimes the field name key in the BAO/DAO export fields array is
                     // different from the actual database field name.
                     // Unset $field['name'] so that actual database field name can be obtained
                     // from the BAO/DAO export fields array.
                     unset($field['name']);
                     if (array_key_exists($name, $expFields)) {
                         foreach ($doNotCopy as $dnc) {
                             // unset the values we don't want to be copied.
                             unset($expFields[$name][$dnc]);
                         }
                         if (empty($field)) {
                             $this->_columns[$tableName][$fieldGrp][$fieldName] = $expFields[$name];
                         } else {
                             foreach ($expFields[$name] as $property => $val) {
                                 if (!array_key_exists($property, $field)) {
                                     $this->_columns[$tableName][$fieldGrp][$fieldName][$property] = $val;
                                 }
                             }
                         }
                     }
                     // fill other vars
                     if (CRM_Utils_Array::value('no_repeat', $field)) {
                         $this->_noRepeats[] = "{$tableName}_{$fieldName}";
                     }
                     if (CRM_Utils_Array::value('no_display', $field)) {
                         $this->_noDisplay[] = "{$tableName}_{$fieldName}";
                     }
                     // set alias = table-name, unless already set
                     $alias = isset($field['alias']) ? $field['alias'] : (isset($this->_columns[$tableName]['alias']) ? $this->_columns[$tableName]['alias'] : $tableName);
                     $this->_columns[$tableName][$fieldGrp][$fieldName]['alias'] = $alias;
                     // set name = fieldName, unless already set
                     if (!isset($this->_columns[$tableName][$fieldGrp][$fieldName]['name'])) {
                         $this->_columns[$tableName][$fieldGrp][$fieldName]['name'] = $name;
                     }
                     // set dbAlias = alias.name, unless already set
                     if (!isset($this->_columns[$tableName][$fieldGrp][$fieldName]['dbAlias'])) {
                         $this->_columns[$tableName][$fieldGrp][$fieldName]['dbAlias'] = $alias . '.' . $this->_columns[$tableName][$fieldGrp][$fieldName]['name'];
                     }
                     if (CRM_Utils_Array::value('type', $this->_columns[$tableName][$fieldGrp][$fieldName]) && !isset($this->_columns[$tableName][$fieldGrp][$fieldName]['operatorType'])) {
                         if (in_array($this->_columns[$tableName][$fieldGrp][$fieldName]['type'], array(CRM_Utils_Type::T_MONEY, CRM_Utils_Type::T_FLOAT))) {
                             $this->_columns[$tableName][$fieldGrp][$fieldName]['operatorType'] = CRM_Report_Form::OP_FLOAT;
                         } elseif (in_array($this->_columns[$tableName][$fieldGrp][$fieldName]['type'], array(CRM_Utils_Type::T_INT))) {
                             $this->_columns[$tableName][$fieldGrp][$fieldName]['operatorType'] = CRM_Report_Form::OP_INT;
                         }
                     }
                 }
             }
         }
         // copy filters to a separate handy variable
         if (array_key_exists('filters', $table)) {
             $this->_filters[$tableName] = $this->_columns[$tableName]['filters'];
         }
         if (array_key_exists('group_bys', $table)) {
             $groupBys[$tableName] = $this->_columns[$tableName]['group_bys'];
         }
         if (array_key_exists('fields', $table)) {
             $reportFields[$tableName] = $this->_columns[$tableName]['fields'];
         }
     }
     if ($this->_force) {
         $this->setDefaultValues(FALSE);
     }
     CRM_Report_Utils_Get::processFilter($this->_filters, $this->_defaults);
     CRM_Report_Utils_Get::processGroupBy($groupBys, $this->_defaults);
     CRM_Report_Utils_Get::processFields($reportFields, $this->_defaults);
     CRM_Report_Utils_Get::processChart($this->_defaults);
     if ($this->_force) {
         $this->_formValues = $this->_defaults;
         $this->postProcess();
     }
 }