コード例 #1
0
 /**
  * Test the query from the selector class is consistent with the dataset expectation.
  *
  * @param array $dataSet
  *   The data set to be tested. Note that when adding new datasets often only form_values and expected where
  *   clause will need changing.
  *
  * @dataProvider querySets
  */
 public function testSelectorQuery($dataSet)
 {
     $params = CRM_Contact_BAO_Query::convertFormValues($dataSet['form_values'], 0, FALSE, NULL, array());
     foreach ($dataSet['settings'] as $setting) {
         $this->callAPISuccess('Setting', 'create', array($setting['name'] => $setting['value']));
     }
     $selector = new CRM_Contact_Selector($dataSet['class'], $dataSet['form_values'], $params, $dataSet['return_properties'], $dataSet['action'], $dataSet['includeContactIds'], $dataSet['searchDescendentGroups'], $dataSet['context']);
     $queryObject = $selector->getQueryObject();
     $sql = $queryObject->query();
     $this->wrangleDefaultClauses($dataSet['expected_query']);
     foreach ($dataSet['expected_query'] as $index => $queryString) {
         $this->assertEquals($this->strWrangle($queryString), $this->strWrangle($sql[$index]));
     }
 }
コード例 #2
0
 /**
  * returns all the rows in the given offset and rowCount
  *
  * @param enum   $action   the action being performed
  * @param int    $offset   the row number to start from
  * @param int    $rowCount the number of rows to return
  * @param string $sort     the sql string that describes the sort order
  * @param enum   $output   what should the result set include (web/email/csv)
  *
  * @return int   the total number of rows for this action
  */
 function &getRows($action, $offset, $rowCount, $sort, $output = null)
 {
     $config =& CRM_Core_Config::singleton();
     if (($output == CRM_CORE_SELECTOR_CONTROLLER_EXPORT || $output == CRM_CORE_SELECTOR_CONTROLLER_SCREEN) && $this->_formValues['radio_ts'] == 'ts_sel') {
         $includeContactIds = true;
     } else {
         $includeContactIds = false;
     }
     // note the formvalues were given by CRM_Contact_Form_Search to us
     // and contain the search criteria (parameters)
     // note that the default action is basic
     $result = $this->_query->searchQuery($offset, $rowCount, $sort, false, $includeContactIds);
     // process the result of the query
     $rows = array();
     $mask = CRM_Core_Action::mask(CRM_Core_Permission::getPermission());
     $mapMask = $mask & 4095;
     // mask value to hide map link if there are not lat/long
     $gc = CRM_Core_SelectValues::groupContactStatus();
     /* Dirty session hack to get at the context */
     $session =& CRM_Core_Session::singleton();
     $context = $session->get('context', 'CRM_Contact_Controller_Search');
     // CRM_Core_Error::debug( 'p', self::$_properties );
     while ($result->fetch()) {
         $row = array();
         // the columns we are interested in
         foreach ($GLOBALS['_CRM_CONTACT_SELECTOR']['_properties'] as $property) {
             if ($property == 'status') {
                 continue;
             }
             $row[$property] = $result->{$property};
         }
         if (!empty($result->postal_code_suffix)) {
             $row['postal_code'] .= "-" . $result->postal_code_suffix;
         }
         if ($output != CRM_CORE_SELECTOR_CONTROLLER_EXPORT || $context == 'smog') {
             if (empty($result->status)) {
                 $row['status'] = ts('Smart');
             } else {
                 $row['status'] = $gc[$result->status];
             }
         }
         if ($output != CRM_CORE_SELECTOR_CONTROLLER_EXPORT && $output != CRM_CORE_SELECTOR_CONTROLLER_SCREEN) {
             $row['checkbox'] = CRM_CORE_FORM_CB_PREFIX . $result->contact_id;
             if (is_numeric(CRM_Utils_Array::value('geo_code_1', $row))) {
                 $row['action'] = CRM_Core_Action::formLink(CRM_Contact_Selector::links(), $mask, array('id' => $result->contact_id));
             } else {
                 $row['action'] = CRM_Core_Action::formLink(CRM_Contact_Selector::links(), $mapMask, array('id' => $result->contact_id));
             }
             $contact_type = '<img src="' . $config->resourceBase . 'i/contact_';
             switch ($result->contact_type) {
                 case 'Individual':
                     $contact_type .= 'ind.gif" alt="' . ts('Individual') . '" />';
                     break;
                 case 'Household':
                     $contact_type .= 'house.png" alt="' . ts('Household') . '" height="16" width="16" />';
                     break;
                 case 'Organization':
                     $contact_type .= 'org.gif" alt="' . ts('Organization') . '" height="16" width="18" />';
                     break;
             }
             $row['contact_type'] = $contact_type;
         }
         $rows[] = $row;
     }
     return $rows;
 }
コード例 #3
0
 /**
  * get colunmn headers for search selector
  *
  *
  * @return array $_columnHeaders
  * @access private
  */
 private static function &_getColumnHeaders()
 {
     if (!isset(self::$_columnHeaders)) {
         $addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'address_options', TRUE, NULL, TRUE);
         self::$_columnHeaders = array('contact_type' => array('desc' => ts('Contact Type')), 'sort_name' => array('name' => ts('Name'), 'sort' => 'sort_name', 'direction' => CRM_Utils_Sort::ASCENDING));
         $defaultAddress = array('street_address' => array('name' => ts('Address')), 'city' => array('name' => ts('City'), 'sort' => 'city', 'direction' => CRM_Utils_Sort::DONTCARE), 'state_province' => array('name' => ts('State'), 'sort' => 'state_province', 'direction' => CRM_Utils_Sort::DONTCARE), 'postal_code' => array('name' => ts('Postal'), 'sort' => 'postal_code', 'direction' => CRM_Utils_Sort::DONTCARE), 'country' => array('name' => ts('Country'), 'sort' => 'country', 'direction' => CRM_Utils_Sort::DONTCARE));
         foreach ($defaultAddress as $columnName => $column) {
             if (!empty($addressOptions[$columnName])) {
                 self::$_columnHeaders[$columnName] = $column;
             }
         }
         self::$_columnHeaders['email'] = array('name' => ts('Email'), 'sort' => 'email', 'direction' => CRM_Utils_Sort::DONTCARE);
         self::$_columnHeaders['phone'] = array('name' => ts('Phone'));
     }
     return self::$_columnHeaders;
 }
コード例 #4
0
ファイル: Selector.php プロジェクト: ksecor/civicrm
 /**
  * get colunmn headers for search selector
  *
  *
  * @return array $_columnHeaders
  * @access private
  */
 private static function &_getColumnHeaders()
 {
     if (!isset(self::$_columnHeaders)) {
         self::$_columnHeaders = array(array('desc' => ts('Contact Type')), array('name' => ts('Name'), 'sort' => 'sort_name', 'direction' => CRM_Utils_Sort::ASCENDING), array('name' => ts('Address')), array('name' => ts('City'), 'sort' => 'city', 'direction' => CRM_Utils_Sort::DONTCARE), array('name' => ts('State'), 'sort' => 'state_province', 'direction' => CRM_Utils_Sort::DONTCARE), array('name' => ts('Postal'), 'sort' => 'postal_code', 'direction' => CRM_Utils_Sort::DONTCARE), array('name' => ts('Country'), 'sort' => 'country', 'direction' => CRM_Utils_Sort::DONTCARE), array('name' => ts('Email'), 'sort' => 'email', 'direction' => CRM_Utils_Sort::DONTCARE), array('name' => ts('Phone')));
     }
     return self::$_columnHeaders;
 }