X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FCore%2FForm%2FTask.php;h=879bfc6a471bbd1e5dc26dbb80193981b3b3dd49;hb=cc58f6c5756ba74b4a914e21bb011332d5d79c80;hp=d9279d2000725532af65ed958ae34a96e788eb9d;hpb=518fa0ee1556723e8e67e02a59e8e7f51ed76f6b;p=civicrm-core.git diff --git a/CRM/Core/Form/Task.php b/CRM/Core/Form/Task.php index d9279d2000..879bfc6a47 100644 --- a/CRM/Core/Form/Task.php +++ b/CRM/Core/Form/Task.php @@ -1,33 +1,17 @@ queryMode ?: CRM_Contact_BAO_Query::MODE_CONTACTS; } + /** + * Given the component id, compute the contact id + * since it's used for things like send email. + * + * @todo At the moment this duplicates a similar function in CRM_Core_DAO + * because right now only the case component is using this. Since the + * default $orderBy is '' which is what the original does, others should be + * easily convertable as NFC. + * @todo The passed in variables should be class member variables. Shouldn't + * need to have passed in vars. + * + * @param $componentIDs + * @param string $tableName + * @param string $idField + * + * @return array + */ + public function getContactIDsFromComponent($componentIDs, $tableName, $idField = 'id') { + $contactIDs = []; + + if (empty($componentIDs)) { + return $contactIDs; + } + + $orderBy = $this->orderBy(); + + $IDs = implode(',', $componentIDs); + $query = " +SELECT contact_id + FROM $tableName + WHERE $idField IN ( $IDs ) $orderBy +"; + + $dao = CRM_Core_DAO::executeQuery($query); + while ($dao->fetch()) { + $contactIDs[] = $dao->contact_id; + } + return $contactIDs; + } + + /** + * Default ordering for getContactIDsFromComponent. Subclasses can override. + * + * @return string + * SQL fragment. Either return '' or a valid order clause including the + * words "ORDER BY", e.g. "ORDER BY `{$this->idField}`" + */ + public function orderBy() { + return ''; + } + }