Exemplo n.º 1
0
 /**
  * Given a list of conditions in params generate the required.
  * where clause
  *
  * @return string
  */
 public function whereClause()
 {
     $this->_where[0] = array();
     $this->_qill[0] = array();
     $this->includeContactIds();
     if (!empty($this->_params)) {
         foreach (array_keys($this->_params) as $id) {
             if (empty($this->_params[$id][0])) {
                 continue;
             }
             // check for both id and contact_id
             if ($this->_params[$id][0] == 'id' || $this->_params[$id][0] == 'contact_id') {
                 if ($this->_params[$id][1] == 'IS NULL' || $this->_params[$id][1] == 'IS NOT NULL') {
                     $this->_where[0][] = "contact_a.id {$this->_params[$id][1]}";
                 } elseif (is_array($this->_params[$id][2])) {
                     $idList = implode("','", $this->_params[$id][2]);
                     //why on earth do they put ' in the middle & not on the outside? We have to assume it's
                     //to support 'something' so lets add them conditionally to support the api (which is a tested flow
                     // so if you are looking to alter this check api test results
                     if (strpos(trim($idList), "'") > 0) {
                         $idList = "'" . $idList . "'";
                     }
                     $this->_where[0][] = "contact_a.id IN ({$idList})";
                 } else {
                     $this->_where[0][] = self::buildClause("contact_a.id", "{$this->_params[$id][1]}", "{$this->_params[$id][2]}");
                 }
             } else {
                 $this->whereClauseSingle($this->_params[$id]);
             }
         }
         CRM_Core_Component::alterQuery($this, 'where');
         CRM_Contact_BAO_Query_Hook::singleton()->alterSearchQuery($this, 'where');
     }
     if ($this->_customQuery) {
         // Added following if condition to avoid the wrong value diplay for 'myaccount' / any UF info.
         // Hope it wont affect the other part of civicrm.. if it does please remove it.
         if (!empty($this->_customQuery->_where)) {
             $this->_where = CRM_Utils_Array::crmArrayMerge($this->_where, $this->_customQuery->_where);
         }
         $this->_qill = CRM_Utils_Array::crmArrayMerge($this->_qill, $this->_customQuery->_qill);
     }
     $clauses = array();
     $andClauses = array();
     $validClauses = 0;
     if (!empty($this->_where)) {
         foreach ($this->_where as $grouping => $values) {
             if ($grouping > 0 && !empty($values)) {
                 $clauses[$grouping] = ' ( ' . implode(" {$this->_operator} ", $values) . ' ) ';
                 $validClauses++;
             }
         }
         if (!empty($this->_where[0])) {
             $andClauses[] = ' ( ' . implode(" {$this->_operator} ", $this->_where[0]) . ' ) ';
         }
         if (!empty($clauses)) {
             $andClauses[] = ' ( ' . implode(' OR ', $clauses) . ' ) ';
         }
         if ($validClauses > 1) {
             $this->_useDistinct = TRUE;
         }
     }
     return implode(' AND ', $andClauses);
 }
Exemplo n.º 2
0
 /**
  * Given a list of conditions in params generate the required
  * where clause
  *
  * @return void
  * @access public
  */
 function whereClause()
 {
     $this->_where[0] = array();
     $this->_qill[0] = array();
     $config = CRM_Core_Config::singleton();
     $this->includeContactIds();
     if (!empty($this->_params)) {
         $activity = FALSE;
         foreach (array_keys($this->_params) as $id) {
             if (!CRM_Utils_Array::value(0, $this->_params[$id])) {
                 continue;
             }
             // check for both id and contact_id
             if ($this->_params[$id][0] == 'id' || $this->_params[$id][0] == 'contact_id') {
                 if ($this->_params[$id][1] == 'IS NULL' || $this->_params[$id][1] == 'IS NOT NULL') {
                     $this->_where[0][] = "contact_a.id {$this->_params[$id][1]}";
                 } else {
                     $this->_where[0][] = "contact_a.id {$this->_params[$id][1]} {$this->_params[$id][2]}";
                 }
             } else {
                 $this->whereClauseSingle($this->_params[$id]);
             }
             if (substr($this->_params[$id][0], 0, 9) == 'activity_') {
                 $activity = TRUE;
             }
         }
         CRM_Core_Component::alterQuery($this, 'where');
     }
     if ($this->_customQuery) {
         // Added following if condition to avoid the wrong value diplay for 'myaccount' / any UF info.
         // Hope it wont affect the other part of civicrm.. if it does please remove it.
         if (!empty($this->_customQuery->_where)) {
             $this->_where = CRM_Utils_Array::crmArrayMerge($this->_where, $this->_customQuery->_where);
         }
         $this->_qill = CRM_Utils_Array::crmArrayMerge($this->_qill, $this->_customQuery->_qill);
     }
     $clauses = array();
     $andClauses = array();
     $validClauses = 0;
     if (!empty($this->_where)) {
         foreach ($this->_where as $grouping => $values) {
             if ($grouping > 0 && !empty($values)) {
                 $clauses[$grouping] = ' ( ' . implode(" {$this->_operator} ", $values) . ' ) ';
                 $validClauses++;
             }
         }
         if (!empty($this->_where[0])) {
             $andClauses[] = ' ( ' . implode(" {$this->_operator} ", $this->_where[0]) . ' ) ';
         }
         if (!empty($clauses)) {
             $andClauses[] = ' ( ' . implode(' OR ', $clauses) . ' ) ';
         }
         if ($validClauses > 1) {
             $this->_useDistinct = TRUE;
         }
     }
     return implode(' AND ', $andClauses);
 }
Exemplo n.º 3
0
 /**
  * Given a list of conditions in params generate the required where clause.
  *
  * @param string $apiEntity
  *
  * @return string
  */
 public function whereClause($apiEntity = NULL)
 {
     $this->_where[0] = array();
     $this->_qill[0] = array();
     $this->includeContactIds();
     if (!empty($this->_params)) {
         foreach (array_keys($this->_params) as $id) {
             if (empty($this->_params[$id][0])) {
                 continue;
             }
             // check for both id and contact_id
             if ($this->_params[$id][0] == 'id' || $this->_params[$id][0] == 'contact_id') {
                 $this->_where[0][] = self::buildClause("contact_a.id", $this->_params[$id][1], $this->_params[$id][2]);
             } else {
                 $this->whereClauseSingle($this->_params[$id], $apiEntity);
             }
         }
         CRM_Core_Component::alterQuery($this, 'where');
         CRM_Contact_BAO_Query_Hook::singleton()->alterSearchQuery($this, 'where');
     }
     if ($this->_customQuery) {
         // Added following if condition to avoid the wrong value display for 'my account' / any UF info.
         // Hope it wont affect the other part of civicrm.. if it does please remove it.
         if (!empty($this->_customQuery->_where)) {
             $this->_where = CRM_Utils_Array::crmArrayMerge($this->_where, $this->_customQuery->_where);
         }
         $this->_qill = CRM_Utils_Array::crmArrayMerge($this->_qill, $this->_customQuery->_qill);
     }
     $clauses = array();
     $andClauses = array();
     $validClauses = 0;
     if (!empty($this->_where)) {
         foreach ($this->_where as $grouping => $values) {
             if ($grouping > 0 && !empty($values)) {
                 $clauses[$grouping] = ' ( ' . implode(" {$this->_operator} ", $values) . ' ) ';
                 $validClauses++;
             }
         }
         if (!empty($this->_where[0])) {
             $andClauses[] = ' ( ' . implode(" {$this->_operator} ", $this->_where[0]) . ' ) ';
         }
         if (!empty($clauses)) {
             $andClauses[] = ' ( ' . implode(' OR ', $clauses) . ' ) ';
         }
         if ($validClauses > 1) {
             $this->_useDistinct = TRUE;
         }
     }
     return implode(' AND ', $andClauses);
 }