Example #1
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;
 }