CRM-15779 remove duplicate code block
[civicrm-core.git] / CRM / Contact / BAO / GroupContact.php
index 0c1425ca060e353c580e69c09007cafd67373216..505f92cf2379415b345cb124e6f60a781c337306 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.5                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
@@ -37,7 +37,7 @@ class CRM_Contact_BAO_GroupContact extends CRM_Contact_DAO_GroupContact {
   /**
    * Class constructor
    */
-  function __construct() {
+  public function __construct() {
     parent::__construct();
   }
 
@@ -51,10 +51,9 @@ class CRM_Contact_BAO_GroupContact extends CRM_Contact_DAO_GroupContact {
    * @param array  $params         (reference ) an assoc array of name/value pairs
    *
    * @return CRM_Contact_BAO_Group object
-   * @access public
    * @static
    */
-  static function add(&$params) {
+  public static function add(&$params) {
 
     $dataExists = self::dataExists($params);
     if (!$dataExists) {
@@ -74,10 +73,9 @@ class CRM_Contact_BAO_GroupContact extends CRM_Contact_DAO_GroupContact {
    * @param array  $params         (reference ) an assoc array of name/value pairs
    *
    * @return boolean
-   * @access public
    * @static
    */
-  static function dataExists(&$params) {
+  public static function dataExists(&$params) {
     // return if no data present
     if ($params['group_id'] == 0) {
       return FALSE;
@@ -94,10 +92,9 @@ class CRM_Contact_BAO_GroupContact extends CRM_Contact_DAO_GroupContact {
    * @param array $values output values of the object
    *
    * @return array (reference)   the values that could be potentially assigned to smarty
-   * @access public
    * @static
    */
-  static function getValues(&$params, &$values) {
+  public static function getValues(&$params, &$values) {
     if (empty($params)) {
       return NULL;
     }
@@ -126,7 +123,6 @@ class CRM_Contact_BAO_GroupContact extends CRM_Contact_DAO_GroupContact {
    * @param int $tracking
    *
    * @return array             (total, added, notAdded) count of contacts added to group
-   * @access public
    * @static
    */
   static function addContactsToGroup(
@@ -175,7 +171,6 @@ class CRM_Contact_BAO_GroupContact extends CRM_Contact_DAO_GroupContact {
    * @param null $tracking
    *
    * @return array             (total, removed, notRemoved) count of contacts removed to group
-   * @access public
    * @static
    */
   static function removeContactsFromGroup(
@@ -272,12 +267,11 @@ class CRM_Contact_BAO_GroupContact extends CRM_Contact_DAO_GroupContact {
    *
    * @param bool $visibility
    *
-   * @access public
    *
    * @return array $values this array has key-> group id and value group title
    * @static
    */
-  static function getGroupList($contactId = 0, $visibility = FALSE) {
+  public static function getGroupList($contactId = 0, $visibility = FALSE) {
     $group = new CRM_Contact_DAO_Group();
 
     $select = $from = $where = '';
@@ -334,7 +328,8 @@ class CRM_Contact_BAO_GroupContact extends CRM_Contact_DAO_GroupContact {
     $count            = FALSE,
     $ignorePermission = FALSE,
     $onlyPublicGroups = FALSE,
-    $excludeHidden    = TRUE
+    $excludeHidden    = TRUE,
+    $groupId          = NULL
   ) {
     if ($count) {
       $select = 'SELECT count(DISTINCT civicrm_group_contact.id)';
@@ -362,6 +357,10 @@ class CRM_Contact_BAO_GroupContact extends CRM_Contact_DAO_GroupContact {
       $where .= ' AND civicrm_group_contact.status = %2';
       $params[2] = array($status, 'String');
     }
+    if (!empty($groupId)) {
+      $where .= " AND civicrm_group.id = %3 ";
+      $params[3] = array($groupId, 'Integer');
+    }
     $tables = array(
       'civicrm_group_contact' => 1,
       'civicrm_group' => 1,
@@ -442,10 +441,9 @@ class CRM_Contact_BAO_GroupContact extends CRM_Contact_DAO_GroupContact {
    * @param  string $method    If we want the subscription history details for a specific method
    *
    * @return object of group contact
-   * @access public
    * @static
    */
-  static function getMembershipDetail($contactId, $groupID, $method = 'Email') {
+  public static function getMembershipDetail($contactId, $groupID, $method = 'Email') {
     $leftJoin = $where = $orderBy = null;
 
     if ($method) {
@@ -483,10 +481,9 @@ SELECT    *
    *
    *
    * @return groupID
-   * @access public
    * @static
    */
-  static function getGroupId($groupContactID) {
+  public static function getGroupId($groupContactID) {
     $dao = new CRM_Contact_DAO_GroupContact();
     $dao->id = $groupContactID;
     $dao->find(TRUE);
@@ -505,10 +502,9 @@ SELECT    *
    * @param string $method
    *
    * @return void
-   * @access public
    * @static
    */
-  static function create(&$params, $contactId, $visibility = FALSE, $method = 'Admin') {
+  public static function create(&$params, $contactId, $visibility = FALSE, $method = 'Admin') {
     $contactIds = array();
     $contactIds[] = $contactId;
 
@@ -562,7 +558,7 @@ SELECT    *
    *
    * @return bool
    */
-  static function isContactInGroup($contactID, $groupID) {
+  public static function isContactInGroup($contactID, $groupID) {
     if (!CRM_Utils_Rule::positiveInteger($contactID) ||
       !CRM_Utils_Rule::positiveInteger($groupID)
     ) {
@@ -595,7 +591,7 @@ SELECT    *
    * @return void.
    * @static
    */
-  static function mergeGroupContact($mainContactId, $otherContactId) {
+  public static function mergeGroupContact($mainContactId, $otherContactId) {
     $params = array(1 => array($mainContactId, 'Integer'),
       2 => array($otherContactId, 'Integer'),
     );
@@ -699,7 +695,6 @@ AND       group_id IN ( $groupIDString )
    * @param null $tracking
    *
    * @return array             (total, added, notAdded) count of contacts added to group
-   * @access public
    * @static
    */
   static function bulkAddContactsToGroup(
@@ -771,5 +766,28 @@ AND    contact_id IN ( $contactStr )
 
     return array($numContactsAdded, $numContactsNotAdded);
   }
-}
 
+  /**
+   * Get options for a given field.
+   * @see CRM_Core_DAO::buildOptions
+   *
+   * @param String $fieldName
+   * @param String $context : @see CRM_Core_DAO::buildOptionsContext
+   * @param Array $props : whatever is known about this dao object
+   *
+   * @return Array|bool
+   */
+  public static function buildOptions($fieldName, $context = NULL, $props = array()) {
+    $params = array();
+
+    $options = CRM_Core_PseudoConstant::get(__CLASS__, $fieldName, $params, $context);
+
+    // Sort group list by hierarchy
+    // TODO: This will only work when api.entity is "group_contact". What about others?
+    if (($fieldName == 'group' || $fieldName == 'group_id') && ($context == 'search' || $context == 'create')) {
+      $options = CRM_Contact_BAO_Group::getGroupsHierarchy($options, NULL, '- ', TRUE);
+    }
+
+    return $options;
+  }
+}