Merge pull request #2236 from eileenmcnaughton/CRM-14008
[civicrm-core.git] / CRM / Core / BAO / Tag.php
index 17a802f1a5a3bfc9cbfdf03a64ca98465c1f1142..3689539a98ff865e4d2ee6dcc1609efa47dcae2d 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
+ | CiviCRM version 4.4                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2013                                |
  +--------------------------------------------------------------------+
@@ -187,6 +187,9 @@ class CRM_Core_BAO_Tag extends CRM_Core_DAO_Tag {
     $parentId  = NULL,
     $separator = '&nbsp;&nbsp;'
   ) {
+    if (!is_array($tags)) {
+      $tags = array();
+    }
     // We need to build a list of tags ordered by hierarchy and sorted by
     // name. The heirarchy will be communicated by an accumulation of
     // separators in front of the name to give it a visual offset.
@@ -283,7 +286,6 @@ class CRM_Core_BAO_Tag extends CRM_Core_DAO_Tag {
 
     if ($tag->delete()) {
       CRM_Utils_Hook::post('delete', 'Tag', $id, $tag);
-      CRM_Core_Session::setStatus(ts('Selected tag has been deleted successfuly.'), ts('Tag Deleted'), 'success');
       return TRUE;
     }
     return FALSE;
@@ -297,13 +299,14 @@ class CRM_Core_BAO_Tag extends CRM_Core_DAO_Tag {
    * pairs
    *
    * @param array  $params         (reference) an assoc array of name/value pairs
-   * @param array  $ids            (reference) the array that holds all the db ids
+   * @param array  $ids  (optional)  the array that holds all the db ids - we are moving away from this in bao
+   * signatures
    *
    * @return object    CRM_Core_DAO_Tag object on success, otherwise null
    * @access public
    * @static
    */
-  static function add(&$params, &$ids) {
+  static function add(&$params, $ids = array()) {
     if (!self::dataExists($params)) {
       return NULL;
     }
@@ -317,15 +320,9 @@ class CRM_Core_BAO_Tag extends CRM_Core_DAO_Tag {
     }
 
     $tag->copyValues($params);
-    $tag->id = CRM_Utils_Array::value('tag', $ids);
-
-    $edit = ($tag->id) ? TRUE : FALSE;
-    if ($edit) {
-      CRM_Utils_Hook::pre('edit', 'Tag', $tag->id, $tag);
-    }
-    else {
-      CRM_Utils_Hook::pre('create', 'Tag', NULL, $tag);
-    }
+    $tag->id = CRM_Utils_Array::value('id', $params, CRM_Utils_Array::value('tag', $ids));
+    $hook = empty($params['id']) ? 'create' : 'edit';
+    CRM_Utils_Hook::pre($hook, 'Tag', $tag->id, $params);
 
     // save creator id and time
     if (!$tag->id) {
@@ -335,13 +332,7 @@ class CRM_Core_BAO_Tag extends CRM_Core_DAO_Tag {
     }
 
     $tag->save();
-
-    if ($edit) {
-      CRM_Utils_Hook::post('edit', 'Tag', $tag->id, $tag);
-    }
-    else {
-      CRM_Utils_Hook::post('create', 'Tag', NULL, $tag);
-    }
+    CRM_Utils_Hook::post($hook, 'Tag', $tag->id, $tag);
 
     // if we modify parent tag, then we need to update all children
     if ($tag->parent_id === 'null') {