add a few comment blocks
[civicrm-core.git] / CRM / Contact / Form / Search / Custom / FullText / Membership.php
index 2ec54eeb5d8d957b56c9563894c1cf5b4561a6ac..250aeb044afada26bcf33cb4992c41a2649541b3 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.5                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
@@ -23,7 +23,7 @@
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *
  */
 class CRM_Contact_Form_Search_Custom_FullText_Membership extends CRM_Contact_Form_Search_Custom_FullText_AbstractPartialQuery {
 
-  function __construct() {
+  /**
+   * Class constructor.
+   */
+  public function __construct() {
     parent::__construct('Membership', ts('Memberships'));
   }
 
-  function isActive() {
+  /**
+   * @return bool
+   */
+  public function isActive() {
     $config = CRM_Core_Config::singleton();
     return in_array('CiviMember', $config->enableComponents) &&
-      CRM_Core_Permission::check('access CiviMember');
+    CRM_Core_Permission::check('access CiviMember');
   }
 
   /**
-   * {@inheritdoc}
+   * @inheritDoc
    */
   public function fillTempTable($queryText, $entityIDTableName, $toTable, $queryLimit, $detailLimit) {
-    $count = $this->fillMembershipIDs($queryText, $entityIDTableName, $queryLimit);
-    $this->moveMembershipIDs($entityIDTableName, $toTable, $detailLimit);
-    return $count;
+    $queries = $this->prepareQueries($queryText, $entityIDTableName);
+    $result = $this->runQueries($queryText, $queries, $entityIDTableName, $queryLimit);
+    $this->moveIDs($entityIDTableName, $toTable, $detailLimit);
+    if (!empty($result['files'])) {
+      $this->moveFileIDs($toTable, 'membership_id', $result['files']);
+    }
+    return $result;
   }
 
   /**
-   * get membership ids in entity tables.
+   * Get membership ids in entity tables.
    *
    * @param string $queryText
-   * @return int the total number of matches
+   * @param string $entityIDTableName
+   * @return array
+   *   list tables/queries (for runQueries)
    */
-  function fillMembershipIDs($queryText, $entityIDTableName, $limit) {
+  public function prepareQueries($queryText, $entityIDTableName) {
     // Note: For available full-text indices, see CRM_Core_InnoDBIndexer
 
     $contactSQL = array();
@@ -74,15 +86,18 @@ WHERE      ({$this->matchText('civicrm_contact c', array('sort_name', 'display_n
         'id' => 'id',
         'fields' => array('source' => NULL),
       ),
+      'file' => array(
+        'xparent_table' => 'civicrm_membership',
+      ),
       'sql' => $contactSQL,
     );
 
     // get the custom data info
     $this->fillCustomInfo($tables, "( 'Membership' )");
-    return $this->runQueries($queryText, $tables, $entityIDTableName, $limit);
+    return $tables;
   }
 
-  public function moveMembershipIDs($fromTable, $toTable, $limit) {
+  public function moveIDs($fromTable, $toTable, $limit) {
     $sql = "
 INSERT INTO {$toTable}
 ( table_name, contact_id, sort_name, membership_id, membership_type, membership_fee, membership_start_date,
@@ -100,4 +115,4 @@ LEFT JOIN  civicrm_membership_status cms ON cms.id = cm.status_id
     CRM_Core_DAO::executeQuery($sql);
   }
 
-}
\ No newline at end of file
+}