5

I have a custom search extension and it was working fine in 4.4.14. Since I have upgraded to 4.6.3, "Actions" items only enabled for All records. But if I select certain records from result it does not enable "Actions" items. My custom PHP & a screenshot is shown below.

    <?php

/**
 * A custom contact search
 */
class CRM_Guestsearch_Form_Search_Guestsearch extends CRM_Contact_Form_Search_Custom_Base implements CRM_Contact_Form_Search_Interface {

  function __construct(&$formValues) {
    parent::__construct($formValues);
  }

  /**
   * Prepare a set of search fields
   *
   * @param CRM_Core_Form $form modifiable
   * @return void
   */
  function buildForm(&$form) {
    CRM_Utils_System::setTitle(ts('Registered Guest (Unassigned)'));

  /**
    $form->add('text', 'name', ts('Name'), TRUE
    );

    $form->setDefaults(array(
      'name' => '',
    ));
     */
    /**
     * if you are using the standard template, this array tells the template what elements
     * are part of the search criteria
     */
    $form->assign('elements', array('name'));
  }

  /**
   * Get a list of summary data points
   *
   * @return mixed; NULL or array with keys:
   *  - summary: string
   *  - total: numeric
   */
  function summary() {
    return NULL;
    // return array(
    //   'summary' => 'This is a summary',
    //   'total' => 50.0,
    // );
  }

  /**
   * Get a list of displayable columns
   *
   * @return array, keys are printable column headers and values are SQL column names
   */
  function &columns() {
    // return by reference
    $columns = array(
      ts('Contact Source') => 'source',
      ts('Name') => 'sort_name',
      ts('Phone') => 'phone',
      ts('Email') => 'email',
      ts('Date of visit') => CIVICRM_GUESTSEARCH_CUSTOM_COLUMN_NAME,
    );
    return $columns;
  }

  /**
   * Construct a full SQL query which returns one page worth of results
   *
   * @param int $offset
   * @param int $rowcount
   * @param null $sort
   * @param bool $includeContactIDs
   * @param bool $justIDs
   * @return string, sql
   */
  function all($offset = 0, $rowcount = 0, $sort = NULL, $includeContactIDs = FALSE, $justIDs = FALSE) {

    return $this->sql($this->select(), $offset, $rowcount, null, $includeContactIDs, NULL);
  }

  /**
   * Construct a SQL SELECT clause
   *
   * @return string, sql fragment with SELECT arguments
   */
  function select() {
    return "
      contact_a.id                  as contact_id,
      contact_a.source              as source,
      contact_a.contact_sub_type    as contact_sub_type,
      contact_a.sort_name           as sort_name,
      phone.phone ,
      email.email  ,
      date.
    " . CIVICRM_GUESTSEARCH_CUSTOM_COLUMN_NAME;
  }

  /**
   * Construct a SQL FROM clause
   *
   * @return string, sql fragment with FROM and JOIN clauses
   */
  function from() {
    return "
      FROM      civicrm_contact contact_a
      LEFT JOIN civicrm_activity_contact a ON (a.contact_id = contact_a.id)
      LEFT JOIN civicrm_phone phone ON (phone.contact_id = contact_a.id)
      LEFT JOIN civicrm_email email ON (email.contact_id = contact_a.id)
      LEFT JOIN " . CIVICRM_GUESTSEARCH_CUSTOM_TABLE_NAME . " date ON (date.entity_id = contact_a.id)
    ";
  }

  /**
   * Construct a SQL WHERE clause
   *
   * @param bool $includeContactIDs
   * @return string, sql fragment with conditional expressions
   */
  function where($includeContactIDs = false) {
    $params = array();

    $where = "contact_a.contact_sub_type = 'Guest' AND contact_a.source = 'Guest Greeter Signup' AND activity_id IS NULL ORDER BY date." . CIVICRM_GUESTSEARCH_CUSTOM_COLUMN_NAME . " ASC ";

    return $where;

  }

  /**
   * Determine the Smarty template for the search screen
   *
   * @return string, template path (findable through Smarty template path)
   */
  function templateFile() {
    return 'CRM/Contact/Form/Search/Custom.tpl';
  }

  /**
   * Modify the content of each row
   *
   * @param array $row modifiable SQL result row
   * @return void
   */

}

enter image description here

  • Have you reviewed the wiki to see if there is any documentation on changes for searches from 4.4 to 4.6? – Joe Murray May 29 '15 at 11:51
  • I did, but cant seems to find any significant difference..!!! – Tapash May 29 '15 at 14:19
3

Since the number of selected records hasn't updated when you check the box, that suggests it's possibly a Javascript error. Try the steps in Troubleshooting JavaScript in CiviCRM and post back any new diagnostic info you find.

0

I am running into exactly the same problem (ie selecting some records does not activate the "Actions" button. It is happening with a custom search that was generated by "civix". (I only changed the title)

Did anyone find a solution?

Source code is: `

/** * A custom contact search */ class CRM_Financialsummaries_Form_Search_preparestatements extends CRM_Contact_Form_Search_Custom_Base implements CRM_Contact_Form_Search_Interface { function __construct(&$formValues) { parent::__construct($formValues); }

/** * Prepare a set of search fields * * @param CRM_Core_Form $form modifiable * @return void */ function buildForm(&$form) { CRM_Utils_System::setTitle(ts('Prepare Statements'));

$form->add('text',
  'household_name',
  ts('Household Name'),
  TRUE
);

$stateProvince = array('' => ts('- any state/province -')) + CRM_Core_PseudoConstant::stateProvince();
$form->addElement('select', 'state_province_id', ts('State/Province'), $stateProvince);

// Optionally define default search values
$form->setDefaults(array(
  'household_name' => '',
  'state_province_id' => NULL,
));

/**
 * if you are using the standard template, this array tells the template what elements
 * are part of the search criteria
 */
$form->assign('elements', array('household_name', 'state_province_id'));   }

/** * Get a list of summary data points * * @return mixed; NULL or array with keys: * - summary: string * - total: numeric */ function summary() { return NULL; // return array( // 'summary' => 'This is a summary', // 'total' => 50.0, // ); }

/** * Get a list of displayable columns * * @return array, keys are printable column headers and values are SQL column names
*/ function &columns() { // return by reference $columns = array( ts('Contact Id') => 'contact_id', ts('Contact Type') => 'contact_type', ts('Name') => 'sort_name', ts('State') => 'state_province', ); return $columns; }

/** * Construct a full SQL query which returns one page worth of results * * @param int $offset * @param int $rowcount * @param null $sort * @param bool $includeContactIDs * @param bool $justIDs * @return string, sql */ function all($offset = 0, $rowcount = 0, $sort = NULL, $includeContactIDs = FALSE, $justIDs = FALSE) { // delegate to $this->sql(), $this->select(), $this->from(), $this->where(), etc. return $this->sql($this->select(), $offset, $rowcount, $sort, $includeContactIDs, NULL); }

/** * Construct a SQL SELECT clause * * @return string, sql fragment with SELECT arguments */ function select() { return " contact_a.id as contact_id , contact_a.contact_type as contact_type, contact_a.sort_name as sort_name, state_province.name as state_province "; }

/** * Construct a SQL FROM clause * * @return string, sql fragment with FROM and JOIN clauses */ function from() { return " FROM civicrm_contact contact_a LEFT JOIN civicrm_address address ON ( address.contact_id = contact_a.id AND address.is_primary = 1 ) LEFT JOIN civicrm_email ON ( civicrm_email.contact_id = contact_a.id AND civicrm_email.is_primary = 1 ) LEFT JOIN civicrm_state_province state_province ON state_province.id = address.state_province_id "; }

/** * Construct a SQL WHERE clause * * @param bool $includeContactIDs * @return string, sql fragment with conditional expressions */ function where($includeContactIDs = FALSE) { $params = array(); $where = "contact_a.contact_type = 'Household'";

$count  = 1;
$clause = array();
$name   = CRM_Utils_Array::value('household_name',
  $this->_formValues
);
if ($name != NULL) {
  if (strpos($name, '%') === FALSE) {
    $name = "%{$name}%";
  }
  $params[$count] = array($name, 'String');
  $clause[] = "contact_a.household_name LIKE %{$count}";
  $count++;
}

$state = CRM_Utils_Array::value('state_province_id',
  $this->_formValues
);
if (!$state &&
  $this->_stateID
) {
  $state = $this->_stateID;
}

if ($state) {
  $params[$count] = array($state, 'Integer');
  $clause[] = "state_province.id = %{$count}";
}

if (!empty($clause)) {
  $where .= ' AND ' . implode(' AND ', $clause);
}

return $this->whereClause($where, $params);   }

/** * Determine the Smarty template for the search screen *
* @return string, template path (findable through Smarty template path) */ function templateFile() { return 'CRM/Contact/Form/Search/Custom.tpl'; }

/** * Modify the content of each row * * @param array $row modifiable SQL result row * @return void */ function alterRow(&$row) { $row['sort_name'] .= ' ( altered )'; } }`

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.