Merge pull request #5550 from civicrm/4.5
[civicrm-core.git] / CRM / Core / BAO / UFGroup.php
index 0f1e6fdaa255728fe91e6f06e209ae2588b6d9e4..2c90b4bbed61ef99f2c924d99e1a9cf702f3a321 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014                                |
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
  * $Id$
  *
  */
@@ -42,14 +42,14 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup {
     LISTINGS_VISIBILITY = 4;
 
   /**
-   * Cache the match clause used in this transaction
+   * Cache the match clause used in this transaction.
    *
    * @var string
    */
   static $_matchFields = NULL;
 
   /**
-   * Fetch object based on array of properties
+   * Fetch object based on array of properties.
    *
    * @param array $params
    *   (reference) an assoc array of name/value pairs.
@@ -111,7 +111,7 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup {
   }
 
   /**
-   * Update the is_active flag in the db
+   * Update the is_active flag in the db.
    *
    * @param int $id
    *   Id of the database record.
@@ -126,7 +126,7 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup {
   }
 
   /**
-   * Get all the registration fields
+   * Get all the registration fields.
    *
    * @param int $action
    *   What action are we doing.
@@ -182,7 +182,7 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup {
   }
 
   /**
-   * Get all the listing fields
+   * Get all the listing fields.
    *
    * @param int $action
    *   What action are we doing.
@@ -199,7 +199,7 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup {
    * @return array
    *   the fields that are listings related
    */
-  static function getListingFields(
+  public static function getListingFields(
     $action,
     $visibility,
     $considerSelector = FALSE,
@@ -278,7 +278,7 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup {
    * @return array
    *   the fields that belong to this ufgroup(s)
    */
-  static function getFields(
+  public static function getFields(
     $id,
     $register = FALSE,
     $action = NULL,
@@ -422,9 +422,9 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup {
    *
    * @param CRM_Core_DAO_UFGroup|CRM_Core_DAO $group
    * @param CRM_Core_DAO_UFField|CRM_Core_DAO $field
+   * @param array $customFields
    * @param array $addressCustomFields
    * @param array $importableFields
-   * @param array $customFields
    * @param int $permissionType
    *   Eg CRM_Core_Permission::CREATE.
    * @return array
@@ -535,7 +535,7 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup {
   }
 
   /**
-   * Create a query to find all visible UFFields in a UFGroup
+   * Create a query to find all visible UFFields in a UFGroup.
    *
    * This is the SQL-variant of checkUFFieldDisplayable().
    *
@@ -583,7 +583,7 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup {
   }
 
   /**
-   * Create a query to find all visible UFFields in a UFGroup
+   * Create a query to find all visible UFFields in a UFGroup.
    *
    * This is the PHP in-memory variant of createUFFieldQuery().
    *
@@ -700,7 +700,7 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup {
   }
 
   /**
-   * Check the data validity
+   * Check the data validity.
    *
    * @param int $userID
    *   The user id that we are actually editing.
@@ -711,7 +711,7 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup {
    *   The action of the form.
    *
    * @pram  boolean $register is this the registrtion form
-   * @return boolean
+   * @return bool
    *   true if form is valid
    */
   public static function isValid($userID, $title, $register = FALSE, $action = NULL) {
@@ -744,7 +744,7 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup {
   }
 
   /**
-   * Get the html for the form that represents this particular group
+   * Get the html for the form that represents this particular group.
    *
    * @param int $userID
    *   The user id that we are actually editing.
@@ -765,7 +765,7 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup {
    * @return string
    *   the html for the form on success, otherwise empty string
    */
-  static function getEditHTML(
+  public static function getEditHTML(
     $userID,
     $title,
     $action = NULL,
@@ -902,7 +902,7 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup {
   }
 
   /**
-   * Searches for a contact in the db with similar attributes
+   * Searches for a contact in the db with similar attributes.
    *
    * @param array $params
    *   The list of values to be used in the where clause.
@@ -1376,7 +1376,7 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup {
    * @param int $id
    *   Profile Id.
    *
-   * @return boolean
+   * @return bool
    *
    */
   public static function usedByModule($id) {
@@ -1401,7 +1401,7 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup {
    * @param int $id
    *   Profile Id.
    *
-   * @return boolean
+   * @return bool
    *
    */
   public static function del($id) {
@@ -1426,7 +1426,7 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup {
   }
 
   /**
-   * Add the UF Group
+   * Add the UF Group.
    *
    * @param array $params
    *   Reference array contains the values submitted by the form.
@@ -1477,7 +1477,7 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup {
   }
 
   /**
-   * Make uf join entries for an uf group
+   * Make uf join entries for an uf group.
    *
    * @param array $params
    *   (reference) an assoc array of name/value pairs.
@@ -1548,7 +1548,7 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
   }
 
   /**
-   * Get the UF Join records for an ufgroup id
+   * Get the UF Join records for an ufgroup id.
    *
    * @param int $ufGroupId
    *   Uf group id.
@@ -1597,7 +1597,7 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
   }
 
   /**
-   * Function takes an associative array and creates a ufjoin record for ufgroup
+   * Function takes an associative array and creates a ufjoin record for ufgroup.
    *
    * @param array $params
    *   (reference) an assoc array of name/value pairs.
@@ -1612,7 +1612,7 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
   }
 
   /**
-   * Delete the uf join record for an uf group
+   * Delete the uf join record for an uf group.
    *
    * @param array $params
    *   (reference) an assoc array of name/value pairs.
@@ -1626,7 +1626,7 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
   }
 
   /**
-   * Get the weight for ufjoin record
+   * Get the weight for ufjoin record.
    *
    * @param int $ufGroupId
    *   If $ufGroupId get update weight or add weight.
@@ -1656,7 +1656,7 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
   }
 
   /**
-   * Get the uf group for a module
+   * Get the uf group for a module.
    *
    * @param string $moduleName
    *   Module name.
@@ -1718,10 +1718,6 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
         if ($field == 'id') {
           continue;
         }
-        elseif ($field == 'name') {
-          $ufGroups[$dao->id][$field] = $dao->title;
-          continue;
-        }
         $ufGroups[$dao->id][$field] = $dao->$field;
       }
     }
@@ -1733,13 +1729,13 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
   }
 
   /**
-   * Filter ufgroups based on logged in user contact type
+   * Filter ufgroups based on logged in user contact type.
    *
    * @param int $ufGroupId
    *   Uf group id (profile id).
    * @param int $contactID
    *
-   * @return boolean
+   * @return bool
    *   true or false
    */
   public static function filterUFGroups($ufGroupId, $contactID = NULL) {
@@ -1775,7 +1771,7 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
   }
 
   /**
-   * Add profile field to a form
+   * Add profile field to a form.
    *
    * @param CRM_Core_Form $form
    * @param array $field
@@ -1791,7 +1787,7 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
    *
    * @return null
    */
-  static function buildProfile(
+  public static function buildProfile(
     &$form,
     &$field,
     $mode,
@@ -1814,7 +1810,7 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
     // do not display view fields in drupal registration form
     // CRM-4632
     if ($view && $mode == CRM_Profile_Form::MODE_REGISTER) {
-      return;
+      return NULL;
     }
 
     if ($usedFor == 'onbehalf') {
@@ -1841,14 +1837,13 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
     if ($fieldName == 'image_URL' && $mode == CRM_Profile_Form::MODE_EDIT) {
       $deleteExtra = ts('Are you sure you want to delete contact image.');
       $deleteURL = array(
-        CRM_Core_Action::DELETE =>
-          array(
-            'name' => ts('Delete Contact Image'),
-            'url' => 'civicrm/contact/image',
-            'qs' => 'reset=1&id=%%id%%&gid=%%gid%%&action=delete',
-            'extra' =>
-              'onclick = "if (confirm( \'' . $deleteExtra . '\' ) ) this.href+=\'&amp;confirmed=1\'; else return false;"',
-          ),
+        CRM_Core_Action::DELETE => array(
+          'name' => ts('Delete Contact Image'),
+          'url' => 'civicrm/contact/image',
+          'qs' => 'reset=1&id=%%id%%&gid=%%gid%%&action=delete',
+          'extra' =>
+          'onclick = "if (confirm( \'' . $deleteExtra . '\' ) ) this.href+=\'&amp;confirmed=1\'; else return false;"',
+        ),
       );
       $deleteURL = CRM_Core_Action::formLink($deleteURL,
         CRM_Core_Action::DELETE,
@@ -1937,7 +1932,7 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
       'membership_end_date',
       'join_date',
     ))) {
-      $form->addDate($name, $title, $required, array('formatType' => 'custom'));
+      $form->addDate($name, $title, $required, array('formatType' => 'activityDate'));
     }
     elseif (CRM_Utils_Array::value('name', $field) == 'membership_type') {
       list($orgInfo, $types) = CRM_Member_BAO_MembershipType::getMembershipTypeInfo();
@@ -2141,8 +2136,8 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
       list($products, $options) = CRM_Contribute_BAO_Premium::getPremiumProductInfo();
       $sel = &$form->addElement('hierselect', $name, $title);
       $products = array(
-          '0' => ts('- select -'),
-        ) + $products;
+        '0' => ts('- select -'),
+      ) + $products;
       $sel->setOptions(array($products, $options));
     }
     elseif ($fieldName == 'payment_instrument') {
@@ -2316,7 +2311,7 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
   }
 
   /**
-   * Set profile defaults
+   * Set profile defaults.
    *
    * @param int $contactId
    *   Contact id.
@@ -2329,10 +2324,8 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
    * @param int $componentId
    *   Id for specific components like contribute, event etc.
    * @param null $component
-   *
-   * @return null
    */
-  static function setProfileDefaults(
+  public static function setProfileDefaults(
     $contactId, &$fields, &$defaults,
     $singleProfile = TRUE, $componentId = NULL, $component = NULL
   ) {
@@ -2617,7 +2610,7 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
    */
   public static function getValidProfiles($required, $optional = NULL) {
     if (!is_array($required) || empty($required)) {
-      return;
+      return NULL;
     }
 
     $profiles = array();
@@ -2773,7 +2766,6 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
    *
    * @return void
    */
-
   public static function commonSendMail($contactID, &$values) {
     if (!$contactID || !$values) {
       return;
@@ -2860,7 +2852,7 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
   }
 
   /**
-   * Assign uf fields to template
+   * Assign uf fields to template.
    *
    * @param int $gid
    *   Group id.
@@ -2878,7 +2870,7 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
   }
 
   /**
-   * Format fields for dupe Contact Matching
+   * Format fields for dupe Contact Matching.
    *
    * @param array $params
    *
@@ -3106,7 +3098,7 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
    * @param array $groupTypes
    *   With key having group type names.
    *
-   * @return Boolean
+   * @return bool
    */
   public static function updateGroupTypes($gId, $groupTypes = array()) {
     if (!is_array($groupTypes) || !$gId) {
@@ -3170,7 +3162,7 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
   }
 
   /**
-   * Create a "group_type" string
+   * Create a "group_type" string.
    *
    * @param array $coreTypes
    *   E.g. array('Individual','Contact','Student').
@@ -3294,8 +3286,8 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
       }
       elseif ($name == 'membership_type') {
         // since membership_type field is a hierselect -
-        $defaults[$fldName][0] =
-          CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $values['membership_type_id'], 'member_of_contact_id', 'id');
+        $defaults[$fldName][0]
+          CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $values['membership_type_id'], 'member_of_contact_id', 'id');
         $defaults[$fldName][1] = $values['membership_type_id'];
       }
       elseif ($name == 'membership_status') {
@@ -3399,7 +3391,7 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
   }
 
   /**
-   * Retrieve groups of  profiles
+   * Retrieve groups of  profiles.
    *
    * @param int $profileID
    *   Id of the profile.
@@ -3495,12 +3487,12 @@ SELECT  group_id
   }
 
   /**
-   * Check if we are rendering mixed profiles
+   * Check if we are rendering mixed profiles.
    *
    * @param array $profileIds
    *   Associated array of profile ids.
    *
-   * @return boolean
+   * @return bool
    *   true if profile is mixed
    */
   public static function checkForMixProfiles($profileIds) {
@@ -3548,9 +3540,9 @@ SELECT  group_id
   }
 
   /**
-   * Determine of we show overlay profile or not
+   * Determine of we show overlay profile or not.
    *
-   * @return boolean
+   * @return bool
    *   true if profile should be shown else false
    */
   public static function showOverlayProfile() {
@@ -3572,12 +3564,12 @@ SELECT  group_id
   }
 
   /**
-   * Get group type values of the profile
+   * Get group type values of the profile.
    *
    * @param int $profileId
    * @param string $groupType
    *
-   * @return Array
+   * @return array
    *   group type values
    */
   public static function groupTypeValues($profileId, $groupType = NULL) {
@@ -3648,7 +3640,7 @@ SELECT  group_id
   }
 
   /**
-   * Get profiles used for batch entry
+   * Get profiles used for batch entry.
    *
    * @return array
    *   profileIds profile ids
@@ -3693,7 +3685,7 @@ SELECT  group_id
   }
 
   /**
-   * This is function is used to format pseudo fields
+   * This is function is used to format pseudo fields.
    *
    * @param array $fields
    *   Associated array of profile fields.
@@ -3722,4 +3714,5 @@ SELECT  group_id
       }
     }
   }
+
 }