protected $_tableFields = NULL;
+ /**
+ * @var array|null NULL if no limit; or array(0 => $limit, 1 => $offset)
+ */
protected $_limitClause = NULL;
+ /**
+ * @var array|null NULL if no limit; or array(0 => $limit, 1 => $offset)
+ */
protected $_limitRowClause = NULL;
+ /**
+ * @var array|null NULL if no limit; or array(0 => $limit, 1 => $offset)
+ */
protected $_limitDetailClause = NULL;
protected $_limitNumber = 10;
$this->_text = $formValues['text'];
if (!$this->_table) {
- $this->_limitClause = " LIMIT {$this->_limitNumberPlus1}";
- $this->_limitRowClause = $this->_limitDetailClause = " LIMIT {$this->_limitNumber}";
+ $this->_limitClause = array($this->_limitNumberPlus1, NULL);
+ $this->_limitRowClause = $this->_limitDetailClause = array($this->_limitNumber, NULL);
}
else {
// when there is table specified, we would like to use the pager. But since
$pageId = CRM_Utils_Array::value('crmPID', $_REQUEST, 1);
$offset = ($pageId - 1) * $rowCount;
$this->_limitClause = NULL;
- $this->_limitRowClause = " LIMIT $rowCount";
- $this->_limitDetailClause = " LIMIT $offset, $rowCount";
+ $this->_limitRowClause = array($rowCount, NULL);
+ $this->_limitDetailClause = array($rowCount, $offset);
}
$this->_formValues = $formValues;
// now iterate through the table and add entries to the relevant section
$sql = "SELECT * FROM {$this->_tableName}";
if ($this->_table) {
- $sql .= " {$this->_limitRowClause} ";
+ $sql .= " {$this->toLimit($this->_limitRowClause)} ";
}
$dao = CRM_Core_DAO::executeQuery($sql);
$sql = "
SELECT $select
FROM {$this->_tableName} contact_a
- {$this->_limitRowClause}
+ {$this->toLimit($this->_limitRowClause)}
";
return $sql;
}
CRM_Utils_System::setTitle($title);
}
}
+
+ /**
+ * @param int|array $limit
+ * @return string SQL
+ * @see CRM_Contact_Form_Search_Custom_FullText_AbstractPartialQuery::toLimit
+ */
+ public function toLimit($limit) {
+ if (is_array($limit)) {
+ list ($limit, $offset) = $limit;
+ }
+ if (empty($limit)) {
+ return '';
+ }
+ $result = "LIMIT {$limit}";
+ if ($offset) {
+ $result .= " OFFSET {$offset}";
+ }
+ return $result;
+ }
}
* TODO: Consider removing $entityIDTableName from the function-signature. Each implementation could be
* responsible for its own temp tables.
*
+ * TODO: Understand why $queryLimit and $detailLimit are different
+ *
* @param string $queryText a string of text to search for
* @param string $entityIDTableName a temporary table into which we can write a list of all matching IDs
* @param string $detailTable a table into which we can write details about a page worth of matches
- * @param string $queryLimit overall limit (applied when building $entityIDTableName)
- * @param string $detailLimit final limit (applied when building $detailTable)
+ * @param array|NULL $queryLimit overall limit (applied when building $entityIDTableName)
+ * NULL if no limit; or array(0 => $limit, 1 => $offset)
+ * @param array|NULL $detailLimit final limit (applied when building $detailTable)
+ * NULL if no limit; or array(0 => $limit, 1 => $offset)
* @return int number of matches
*/
public abstract function fillTempTable($queryText, $entityIDTableName, $detailTable, $queryLimit, $detailLimit);
$sql = "
REPLACE INTO {$entityIDTableName} ( entity_id )
$sqlStatement
-{$limit}
+{$this->toLimit($limit)}
";
CRM_Core_DAO::executeQuery($sql);
}
WHERE ( $whereClause )
AND {$tableValues['id']} IS NOT NULL
GROUP BY {$tableValues['id']}
-{$limit}
+{$this->toLimit($limit)}
";
CRM_Core_DAO::executeQuery($sql);
}
}
}
+ /**
+ * @param int|array $limit
+ * @return string SQL
+ * @see CRM_Contact_Form_Search_Custom_FullText::toLimit
+ */
+ public function toLimit($limit) {
+ if (is_array($limit)) {
+ list ($limit, $offset) = $limit;
+ }
+ if (empty($limit)) {
+ return '';
+ }
+ $result = "LIMIT {$limit}";
+ if ($offset) {
+ $result .= " OFFSET {$offset}";
+ }
+ return $result;
+ }
+
}
\ No newline at end of file
LEFT JOIN civicrm_case_contact ccc ON ccc.case_id = cca.case_id
WHERE (ca.is_deleted = 0 OR ca.is_deleted IS NULL)
GROUP BY ca.id
-{$limit}
+{$this->toLimit($limit)}
";
CRM_Core_DAO::executeQuery($sql);
}
INNER JOIN civicrm_case cc ON cc.id = ct.entity_id
LEFT JOIN civicrm_case_contact ccc ON cc.id = ccc.case_id
LEFT JOIN civicrm_contact c ON ccc.contact_id = c.id
-{$limit}
+{$this->toLimit($limit)}
";
CRM_Core_DAO::executeQuery($sql);
}
SELECT c.id, ct.entity_id, c.sort_name, c.display_name, 'Contact'
FROM {$fromTable} ct
INNER JOIN civicrm_contact c ON ct.entity_id = c.id
-{$limit}
+{$this->toLimit($limit)}
";
CRM_Core_DAO::executeQuery($sql);
}
LEFT JOIN civicrm_option_group option_group_contributionStatus ON option_group_contributionStatus.name = 'contribution_status'
LEFT JOIN civicrm_option_value contribution_status ON
( contribution_status.option_group_id = option_group_contributionStatus.id AND contribution_status.value = cc.contribution_status_id )
-{$limit}
+{$this->toLimit($limit)}
";
CRM_Core_DAO::executeQuery($sql);
}
LEFT JOIN civicrm_membership_payment cmp ON cmp.membership_id = cm.id
LEFT JOIN civicrm_contribution cc ON cc.id = cmp.contribution_id
LEFT JOIN civicrm_membership_status cms ON cms.id = cm.status_id
-{$limit}
+{$this->toLimit($limit)}
";
CRM_Core_DAO::executeQuery($sql);
}
LEFT JOIN civicrm_contact c ON cp.contact_id = c.id
LEFT JOIN civicrm_event ce ON ce.id = cp.event_id
LEFT JOIN civicrm_participant_status_type participantStatus ON participantStatus.id = cp.status_id
-{$limit}
+{$this->toLimit($limit)}
";
CRM_Core_DAO::executeQuery($sql);
}