Test fixes for All kind of Custom Values
[civicrm-core.git] / CRM / Core / BAO / CustomGroup.php
index 6f2772475abe28b7c1c0535644040489bf23c4da..57e735752e71ace1e637ea5e244a81584854f4bf 100644 (file)
  *
  * @package CRM
  * @copyright CiviCRM LLC (c) 2004-2015
- * $Id$
- *
  */
 
 /**
- * Business object for managing custom data groups
- *
+ * Business object for managing custom data groups.
  */
 class CRM_Core_BAO_CustomGroup extends CRM_Core_DAO_CustomGroup {
 
@@ -142,7 +139,8 @@ class CRM_Core_BAO_CustomGroup extends CRM_Core_DAO_CustomGroup {
       if ((!empty($params['is_multiple']) || $isMultiple) &&
         ($params['is_multiple'] != $isMultiple)
       ) {
-        $oldTableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup',
+        $oldTableName = CRM_Core_DAO::getFieldValue(
+          'CRM_Core_DAO_CustomGroup',
           $params['id'],
           'table_name'
         );
@@ -763,9 +761,9 @@ ORDER BY civicrm_custom_group.weight,
    *   (reference) the group tree being build.
    * @param string $table
    *   Table name.
-   * @param unknown_type $groupID
+   * @param int $groupID
    *   Custom group ID.
-   * @param unknown_type $fieldID
+   * @param int $fieldID
    *   Custom field ID.
    */
   static public function buildCustomFieldData($dao, &$groupTree, $table, $groupID, $fieldID) {
@@ -868,7 +866,6 @@ ORDER BY civicrm_custom_group.weight,
    *
    * @return string
    *   title
-   *
    */
   public static function getTitle($id) {
     return CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $id, 'title');
@@ -890,8 +887,6 @@ ORDER BY civicrm_custom_group.weight,
    *
    * @return array
    *   array consisting of all group and field details
-   *
-   *
    */
   public static function &getGroupDetail($groupId = NULL, $searchable = NULL, &$extends = NULL, $inSelector = NULL) {
     // create a new tree
@@ -1168,9 +1163,6 @@ ORDER BY civicrm_custom_group.weight,
    *
    * @param int $entityID
    * @param bool $allSubtypes
-   *
-   * @return void
-   *
    */
   private static function _addWhereAdd(&$customGroupDAO, $entityType, $entityID = NULL, $allSubtypes = FALSE) {
     $addSubtypeClause = FALSE;
@@ -1230,17 +1222,17 @@ ORDER BY civicrm_custom_group.weight,
   /**
    * Delete the Custom Group.
    *
-   * @param $group
-   *   Object the DAO custom group object.
+   * @param CRM_Core_BAO_CustomGroup $group
+   *   Custom group object.
    * @param bool $force
    *   whether to force the deletion, even if there are custom fields.
    *
    * @return bool
-   *   false if field exists for this group, true if group gets deleted.
+   *   False if field exists for this group, true if group gets deleted.
    */
   public static function deleteGroup($group, $force = FALSE) {
 
-    //check wheter this contain any custom fields
+    //check whether this contain any custom fields
     $customField = new CRM_Core_DAO_CustomField();
     $customField->custom_group_id = $group->id;
     $customField->find();
@@ -1266,8 +1258,10 @@ ORDER BY civicrm_custom_group.weight,
   }
 
   /**
-   * @param $groupTree
-   * @param $defaults
+   * Set defaults.
+   *
+   * @param array $groupTree
+   * @param array $defaults
    * @param bool $viewMode
    * @param bool $inactiveNeeded
    * @param int $action
@@ -1410,7 +1404,9 @@ ORDER BY civicrm_custom_group.weight,
   }
 
   /**
-   * @param $groupTree
+   * PostProcess function.
+   *
+   * @param array $groupTree
    * @param array $params
    * @param bool $skipFile
    */
@@ -1542,8 +1538,6 @@ ORDER BY civicrm_custom_group.weight,
    *   Return inactive custom groups.
    * @param string $prefix
    *   Prefix for custom grouptree assigned to template.
-   *
-   * @return void
    */
   public static function buildQuickForm(&$form, &$groupTree, $inactiveNeeded = FALSE, $prefix = '') {
     $form->assign_by_ref("{$prefix}groupTree", $groupTree);
@@ -1570,8 +1564,7 @@ ORDER BY civicrm_custom_group.weight,
   }
 
   /**
-   * Extract the get params from the url, validate
-   * and store it in session
+   * Extract the get params from the url, validate and store it in session.
    *
    * @param CRM_Core_Form $form
    *   The form object.
@@ -1980,38 +1973,30 @@ SELECT IF( EXISTS(SELECT name FROM civicrm_contact_type WHERE name like %1), 1,
 
     switch ($dataType) {
       case 'Date':
-        $customTimeFormat = '';
         $customFormat = NULL;
 
-        switch ($timeFormat) {
-          case 1:
-            $customTimeFormat = '%l:%M %P';
-            break;
-
-          case 2:
-            $customTimeFormat = '%H:%M';
-            break;
-
-          default:
-            // if time is not selected remove time from value
-            $value = substr($value, 0, 10);
-        }
-
-        $supportableFormats = array(
-          'mm/dd' => "%B %E%f $customTimeFormat",
-          'dd-mm' => "%E%f %B $customTimeFormat",
-          'yy' => "%Y $customTimeFormat",
-          'M yy' => "%b %Y $customTimeFormat",
-          'yy-mm' => "%Y-%m $customTimeFormat",
-        );
+        $actualPHPFormats = CRM_Core_SelectValues::datePluginToPHPFormats();
 
         if ($format = CRM_Utils_Array::value('date_format', $field)) {
-          if (array_key_exists($format, $supportableFormats)) {
-            $customFormat = $supportableFormats["$format"];
+          if (array_key_exists($format, $actualPHPFormats)) {
+            $customTimeFormat = (array) CRM_Utils_Array::value($format, $actualPHPFormats);
+            switch ($timeFormat) {
+              case 1:
+                $customTimeFormat[] = 'g:iA';
+                break;
+
+              case 2:
+                $customTimeFormat[] = 'G:i';
+                break;
+
+              default:
+                // if time is not selected remove time from value
+                $value = substr($value, 0, 10);
+            }
+            $customFormat = implode(" ", $customTimeFormat);
           }
         }
-
-        $retValue = CRM_Utils_Date::customFormat($value, $customFormat);
+        $retValue = CRM_Utils_Date::processDate($value, NULL, FALSE, $customFormat);
         break;
 
       case 'Boolean':