Merge remote-tracking branch 'upstream/4.4' into 4.4-master-2014-07-14-13-42-39
[civicrm-core.git] / CRM / Core / BAO / UFGroup.php
index 7395d7366b12083e4afac106ed9e0515f2f25a9f..cd7a474c1250eb3b34c83bcf9fc657cb0ca2b53f 100644 (file)
@@ -297,10 +297,10 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup {
     $gids = implode(',', $profileIds);
     $params = array();
     if ($restrict) {
-      $query = "SELECT g.* from civicrm_uf_group g, civicrm_uf_join j
+      $query = "SELECT g.* from civicrm_uf_group g
+                LEFT JOIN civicrm_uf_join j ON (j.uf_group_id = g.id)
                 WHERE g.id IN ( {$gids} )
-                AND j.uf_group_id IN ( {$gids} )
-                AND j.module      = %1
+                AND ((j.uf_group_id IN ( {$gids} ) AND j.module = %1) OR g.is_reserved = 1 )
                 ";
       $params = array(1 => array($restrict, 'String'));
     }
@@ -612,6 +612,13 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup {
     return TRUE;
   }
 
+  /**
+   * @param $showAll
+   * @param $profileType
+   * @param $contactActivityProfile
+   *
+   * @return array
+   */
   protected static function getImportableFields($showAll, $profileType, $contactActivityProfile) {
     if (!$showAll) {
       $importableFields = CRM_Contact_BAO_Contact::importableFields('All', FALSE, FALSE, FALSE, TRUE, TRUE);
@@ -659,6 +666,11 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup {
     return $locationFields;
   }
 
+  /**
+   * @param $ctype
+   *
+   * @return mixed
+   */
   protected static function getCustomFields($ctype) {
     static $customFieldCache = array();
     if (!isset($customFieldCache[$ctype])) {
@@ -679,11 +691,12 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup {
   /**
    * check the data validity
    *
-   * @param int    $userID    the user id that we are actually editing
-   * @param string $title     the title of the group we are interested in
-   * @pram  boolean $register is this the registrtion form
-   * @param int    $action  the action of the form
+   * @param int $userID the user id that we are actually editing
+   * @param string $title the title of the group we are interested in
+   * @param bool $register
+   * @param int $action the action of the form
    *
+   * @pram  boolean $register is this the registrtion form
    * @return boolean   true if form is valid
    * @static
    * @access public
@@ -720,12 +733,15 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup {
   /**
    * get the html for the form that represents this particular group
    *
-   * @param int     $userID    the user id that we are actually editing
-   * @param string  $title     the title of the group we are interested in
-   * @param int     $action    the action of the form
-   * @param boolean $register  is this the registration form
-   * @param boolean $reset     should we reset the form?
-   * @param int     $profileID do we have the profile ID?
+   * @param int $userID the user id that we are actually editing
+   * @param string $title the title of the group we are interested in
+   * @param int $action the action of the form
+   * @param boolean $register is this the registration form
+   * @param boolean $reset should we reset the form?
+   * @param int $profileID do we have the profile ID?
+   *
+   * @param bool $doNotProcess
+   * @param null $ctype
    *
    * @return string       the html for the form on success, otherwise empty string
    * @static
@@ -870,8 +886,10 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup {
    * searches for a contact in the db with similar attributes
    *
    * @param array $params the list of values to be used in the where clause
-   * @param int    $id          the current contact id (hence excluded from matching)
-   * @param boolean $flatten should we flatten the input params
+   * @param int $id the current contact id (hence excluded from matching)
+   * @param string $contactType
+   *
+   * @internal param bool $flatten should we flatten the input params
    *
    * @return contact_id if found, null otherwise
    * @access public
@@ -893,13 +911,16 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup {
    * Given a contact id and a field set, return the values from the db
    * for this contact
    *
-   * @param int     $id             the contact id
-   * @param array   $fields         the profile fields of interest
-   * @param array   $values         the values for the above fields
-   * @param boolean $searchable     searchable or not
-   * @param array   $componentWhere component condition
-   * @param boolean $absolute       return urls in absolute form (useful when sending an email)
+   * @param $cid
+   * @param array $fields the profile fields of interest
+   * @param array $values the values for the above fields
+   * @param boolean $searchable searchable or not
+   * @param array $componentWhere component condition
+   * @param boolean $absolute return urls in absolute form (useful when sending an email)
    *
+   * @param null $additionalWhereClause
+   *
+   * @internal param int $id the contact id
    * @return void
    * @access public
    * @static
@@ -937,7 +958,6 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup {
     $websiteTypes  = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Website', 'website_type_id');
 
     $multipleFields = array('url');
-    $nullIndex = $nullValueIndex = ' ';
 
     //start of code to set the default values
     foreach ($fields as $name => $field) {
@@ -951,18 +971,12 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup {
         continue;
       }
 
+      // Create a unique, non-empty index for each field.
       $index = $field['title'];
-      //handle for the label not set for the field
-      if (empty($field['title'])) {
-        $index = $nullIndex;
-        $nullIndex .= $nullIndex;
-      }
+      if ($index === '') $index = ' ';
+      while (array_key_exists($index, $values))
+        $index .= ' ';
 
-      //handle the case to avoid re-write where the profile field labels are the same
-      if (array_key_exists($index, $values)) {
-        $index .= $nullValueIndex;
-        $nullValueIndex .= $nullValueIndex;
-      }
       $params[$index] = $values[$index] = '';
       $customFieldName = NULL;
       // hack for CRM-665
@@ -3435,7 +3449,7 @@ SELECT  group_id
   }
 
   /**
-   * Funtion to determine of we show overlay profile or not
+   * Function to determine of we show overlay profile or not
    *
    * @return boolean true if profile should be shown else false
    * @static
@@ -3511,6 +3525,9 @@ SELECT  group_id
     return $groupTypeValue;
   }
 
+  /**
+   * @return bool|object
+   */
   static function isProfileDoubleOptin() {
     // check for double optin
     $config = CRM_Core_Config::singleton();
@@ -3522,6 +3539,9 @@ SELECT  group_id
     return FALSE;
   }
 
+  /**
+   * @return bool|object
+   */
   static function isProfileAddToGroupDoubleOptin() {
     // check for add to group double optin
     $config = CRM_Core_Config::singleton();