function processCaseTags()
 {
     $caseId = CRM_Utils_Type::escape($_POST['case_id'], 'Integer');
     $tags = CRM_Utils_Type::escape($_POST['tag'], 'String');
     if (empty($caseId)) {
         echo 'false';
         CRM_Utils_System::civiExit();
     }
     $tagIds = array();
     if ($tags) {
         $tagIds = explode(',', $tags);
     }
     $params = array('entity_id' => $caseId, 'entity_table' => 'civicrm_case');
     CRM_Core_BAO_EntityTag::del($params);
     foreach ($tagIds as $tagid) {
         if (is_numeric($tagid)) {
             $params['tag_id'] = $tagid;
             CRM_Core_BAO_EntityTag::add($params);
         }
     }
     $session = CRM_Core_Session::singleton();
     $activityParams = array();
     $activityParams['source_contact_id'] = $session->get('userID');
     $activityParams['activity_type_id'] = CRM_Core_OptionGroup::getValue('activity_type', 'Change Case Tags', 'name');
     $activityParams['activity_date_time'] = date('YmdHis');
     $activityParams['status_id'] = CRM_Core_OptionGroup::getValue('activity_status', 'Completed', 'name');
     $activityParams['case_id'] = $caseId;
     $activityParams['is_auto'] = 0;
     $activityParams['subject'] = 'Change Case Tags';
     $activity = CRM_Activity_BAO_Activity::create($activityParams);
     $caseParams = array('activity_id' => $activity->id, 'case_id' => $caseId);
     CRM_Case_BAO_Case::processCaseActivity($caseParams);
     echo 'true';
     CRM_Utils_System::civiExit();
 }
 static function processTags()
 {
     $skipTagCreate = $skipEntityAction = $entityId = NULL;
     $action = CRM_Utils_Type::escape($_POST['action'], 'String');
     $parentId = CRM_Utils_Type::escape($_POST['parentId'], 'Integer');
     if ($_POST['entityId']) {
         $entityId = CRM_Utils_Type::escape($_POST['entityId'], 'Integer');
     }
     $entityTable = CRM_Utils_Type::escape($_POST['entityTable'], 'String');
     if ($_POST['skipTagCreate']) {
         $skipTagCreate = CRM_Utils_Type::escape($_POST['skipTagCreate'], 'Integer');
     }
     if ($_POST['skipEntityAction']) {
         $skipEntityAction = CRM_Utils_Type::escape($_POST['skipEntityAction'], 'Integer');
     }
     // check if user has selected existing tag or is creating new tag
     // this is done to allow numeric tags etc.
     $tagValue = explode(':::', $_POST['tagID']);
     $createNewTag = FALSE;
     $tagID = $tagValue[0];
     if (isset($tagValue[1]) && $tagValue[1] == 'value') {
         $createNewTag = TRUE;
     }
     $tagInfo = array();
     // if action is select
     if ($action == 'select') {
         // check the value of tagID
         // if numeric that means existing tag
         // else create new tag
         if (!$skipTagCreate && $createNewTag) {
             $params = array('name' => $tagID, 'parent_id' => $parentId);
             $tagObject = CRM_Core_BAO_Tag::add($params, CRM_Core_DAO::$_nullArray);
             $tagInfo = array('name' => $tagID, 'id' => $tagObject->id, 'action' => $action);
             $tagID = $tagObject->id;
         }
         if (!$skipEntityAction && $entityId) {
             // save this tag to contact
             $params = array('entity_table' => $entityTable, 'entity_id' => $entityId, 'tag_id' => $tagID);
             CRM_Core_BAO_EntityTag::add($params);
         }
         // if action is delete
     } elseif ($action == 'delete') {
         if (!is_numeric($tagID)) {
             $tagID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Tag', $tagID, 'id', 'name');
         }
         if (!$skipEntityAction && $entityId) {
             // delete this tag entry for the entity
             $params = array('entity_table' => $entityTable, 'entity_id' => $entityId, 'tag_id' => $tagID);
             CRM_Core_BAO_EntityTag::del($params);
         }
         $tagInfo = array('id' => $tagID, 'action' => $action);
     }
     CRM_Utils_JSON::output($tagInfo);
 }
 /**
  * Takes an associative array and creates tag entity record for all tag entities.
  *
  * @param array $params
  *   (reference) an assoc array of name/value pairs.
  * @param $entityTable
  * @param int $entityID
  *
  * @return void
  */
 public static function create(&$params, $entityTable, $entityID)
 {
     // get categories for the entity id
     $entityTag = CRM_Core_BAO_EntityTag::getTag($entityID, $entityTable);
     // get the list of all the categories
     $allTag = CRM_Core_BAO_Tag::getTags($entityTable);
     // this fix is done to prevent warning generated by array_key_exits incase of empty array is given as input
     if (!is_array($params)) {
         $params = array();
     }
     // this fix is done to prevent warning generated by array_key_exits incase of empty array is given as input
     if (!is_array($entityTag)) {
         $entityTag = array();
     }
     // check which values has to be inserted/deleted for contact
     foreach ($allTag as $key => $varValue) {
         $tagParams['entity_table'] = $entityTable;
         $tagParams['entity_id'] = $entityID;
         $tagParams['tag_id'] = $key;
         if (array_key_exists($key, $params) && !array_key_exists($key, $entityTag)) {
             // insert a new record
             CRM_Core_BAO_EntityTag::add($tagParams);
         } elseif (!array_key_exists($key, $params) && array_key_exists($key, $entityTag)) {
             // delete a record for existing contact
             CRM_Core_BAO_EntityTag::del($tagParams);
         }
     }
 }
Beispiel #4
0
/**
 * Assigns an entity (e.g. Individual, Organization, Group, Contact_action) to a Tag (i.e. 'tags' that entity).
 *
 * @param $tag        object  valid tag object
 * @param $entity     object  valid entity object
 *
 * @return $entityTag object  A new Entity tag object
 * @access public
 */
function crm_create_entity_tag(&$tag, &$entity)
{
    require_once 'CRM/Core/BAO/EntityTag.php';
    if (!isset($tag->id) || !isset($entity->id)) {
        return _crm_error('Required parameters missing');
    }
    $params = array('tag_id' => $tag->id, 'contact_id' => $entity->id, 'entity_table' => 'civicrm_contact');
    return CRM_Core_BAO_EntityTag::add($params);
}
Beispiel #5
0
 static function processTags()
 {
     $skipTagCreate = $skipEntityAction = $entityId = null;
     $action = CRM_Utils_Type::escape($_POST['action'], 'String');
     $parentId = CRM_Utils_Type::escape($_POST['parentId'], 'Integer');
     if ($_POST['entityId']) {
         $entityId = CRM_Utils_Type::escape($_POST['entityId'], 'Integer');
     }
     $entityTable = CRM_Utils_Type::escape($_POST['entityTable'], 'String');
     if ($_POST['skipTagCreate']) {
         $skipTagCreate = CRM_Utils_Type::escape($_POST['skipTagCreate'], 'Integer');
     }
     if ($_POST['skipEntityAction']) {
         $skipEntityAction = CRM_Utils_Type::escape($_POST['skipEntityAction'], 'Integer');
     }
     $tagID = $_POST['tagID'];
     require_once 'CRM/Core/BAO/EntityTag.php';
     $tagInfo = array();
     // if action is select
     if ($action == 'select') {
         // check the value of tagID
         // if numeric that means existing tag
         // else create new tag
         if (!$skipTagCreate && !is_numeric($tagID)) {
             $params = array('name' => $tagID, 'parent_id' => $parentId);
             require_once 'CRM/Core/BAO/Tag.php';
             $tagObject = CRM_Core_BAO_Tag::add($params, CRM_Core_DAO::$_nullArray);
             $tagInfo = array('name' => $tagID, 'id' => $tagObject->id, 'action' => $action);
             $tagID = $tagObject->id;
         }
         if (!$skipEntityAction && $entityId) {
             // save this tag to contact
             $params = array('entity_table' => $entityTable, 'entity_id' => $entityId, 'tag_id' => $tagID);
             CRM_Core_BAO_EntityTag::add($params);
         }
     } elseif ($action == 'delete') {
         // if action is delete
         if (!is_numeric($tagID)) {
             $tagID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Tag', $tagID, 'id', 'name');
         }
         if ($entityId) {
             // delete this tag entry for the entity
             $params = array('entity_table' => $entityTable, 'entity_id' => $entityId, 'tag_id' => $tagID);
             CRM_Core_BAO_EntityTag::del($params);
         }
         $tagInfo = array('id' => $tagID, 'action' => $action);
     }
     echo json_encode($tagInfo);
     CRM_Utils_System::civiExit();
 }