Ejemplo n.º 1
0
 /**
  * Function to build the form
  *
  * @return None
  * @access public
  */
 public function buildQuickForm()
 {
     // get categories for the contact id
     $entityTag = CRM_Core_BAO_EntityTag::getTag($this->_entityID, $this->_entityTable);
     $this->assign('tagged', $entityTag);
     // get the list of all the categories
     $allTag = CRM_Core_BAO_Tag::getTagsUsedFor($this->_entityTable);
     // need to append the array with the " checked " if contact is tagged with the tag
     foreach ($allTag as $tagID => $varValue) {
         if (in_array($tagID, $entityTag)) {
             $tagAttribute = array('onclick' => "return changeRowColor(\"rowidtag_{$tagID}\")", 'checked' => 'checked', 'id' => "tag_{$tagID}");
         } else {
             $tagAttribute = array('onclick' => "return changeRowColor(\"rowidtag_{$tagID}\")", 'id' => "tag_{$tagID}");
         }
         $tagChk[$tagID] = $this->createElement('checkbox', $tagID, '', '', $tagAttribute);
     }
     $this->addGroup($tagChk, 'tagList', NULL, NULL, TRUE);
     $tags = new CRM_Core_BAO_Tag();
     $tree = $tags->getTree($this->_entityTable, TRUE);
     $this->assign('tree', $tree);
     $this->assign('tag', $allTag);
     //build tag widget
     $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_contact');
     CRM_Core_Form_Tag::buildQuickForm($this, $parentNames, $this->_entityTable, $this->_entityID);
     if ($this->_action & CRM_Core_Action::BROWSE) {
         $this->freeze();
     } else {
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Update Tags'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
     }
 }
Ejemplo n.º 2
0
Archivo: Tag.php Proyecto: kidaa30/yes
 /**
  * Build the form object.
  *
  * @return void
  */
 public function buildQuickForm()
 {
     // get categories for the contact id
     $entityTag = CRM_Core_BAO_EntityTag::getTag($this->_entityID, $this->_entityTable);
     $this->assign('tagged', $entityTag);
     // get the list of all the categories
     $allTag = CRM_Core_BAO_Tag::getTagsUsedFor($this->_entityTable);
     // need to append the array with the " checked " if contact is tagged with the tag
     foreach ($allTag as $tagID => $varValue) {
         if (in_array($tagID, $entityTag)) {
             $tagAttribute = array('checked' => 'checked', 'id' => "tag_{$tagID}");
         } else {
             $tagAttribute = array('id' => "tag_{$tagID}");
         }
         $tagChk[$tagID] = $this->createElement('checkbox', $tagID, '', '', $tagAttribute);
     }
     $this->addGroup($tagChk, 'tagList', NULL, NULL, TRUE);
     $tags = new CRM_Core_BAO_Tag();
     $tree = $tags->getTree($this->_entityTable, TRUE);
     // let's not load jstree if there are not children. This also fixes blank
     // display at the beginning of checkboxes
     $loadJsTree = CRM_Utils_Array::retrieveValueRecursive($tree, 'children');
     $this->assign('loadjsTree', FALSE);
     if (!empty($loadJsTree)) {
         CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'packages/jquery/plugins/jstree/jquery.jstree.js', 0, 'html-header', FALSE)->addStyleFile('civicrm', 'packages/jquery/plugins/jstree/themes/default/style.css', 0, 'html-header');
         $this->assign('loadjsTree', TRUE);
     }
     $this->assign('tree', $tree);
     $this->assign('tag', $allTag);
     //build tag widget
     $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_contact');
     CRM_Core_Form_Tag::buildQuickForm($this, $parentNames, $this->_entityTable, $this->_entityID);
 }
Ejemplo n.º 3
0
 /**
  * Function to build the form
  *
  * @return void
  * @access public
  */
 public function buildQuickForm()
 {
     CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'packages/jquery/plugins/jstree/jquery.jstree.js', 0, 'html-header', FALSE)->addStyleFile('civicrm', 'packages/jquery/plugins/jstree/themes/default/style.css', 0, 'html-header');
     // get categories for the contact id
     $entityTag = CRM_Core_BAO_EntityTag::getTag($this->_entityID, $this->_entityTable);
     $this->assign('tagged', $entityTag);
     // get the list of all the categories
     $allTag = CRM_Core_BAO_Tag::getTagsUsedFor($this->_entityTable);
     // need to append the array with the " checked " if contact is tagged with the tag
     foreach ($allTag as $tagID => $varValue) {
         if (in_array($tagID, $entityTag)) {
             $tagAttribute = array('checked' => 'checked', 'id' => "tag_{$tagID}");
         } else {
             $tagAttribute = array('id' => "tag_{$tagID}");
         }
         $tagChk[$tagID] = $this->createElement('checkbox', $tagID, '', '', $tagAttribute);
     }
     $this->addGroup($tagChk, 'tagList', NULL, NULL, TRUE);
     $tags = new CRM_Core_BAO_Tag();
     $tree = $tags->getTree($this->_entityTable, TRUE);
     $this->assign('tree', $tree);
     $this->assign('tag', $allTag);
     //build tag widget
     $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_contact');
     CRM_Core_Form_Tag::buildQuickForm($this, $parentNames, $this->_entityTable, $this->_entityID);
     if ($this->_action & CRM_Core_Action::BROWSE) {
         $this->freeze();
     } else {
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Update Tags'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
     }
 }
 /**
  * Method to get groups
  *
  * @return array
  * @access protected
  */
 protected function getTags()
 {
     $tags = CRM_Core_BAO_Tag::getTagsUsedFor();
     $options = array();
     foreach ($tags as $tag_id => $tag) {
         $options[$tag_id] = $tag;
     }
     return $options;
 }
Ejemplo n.º 5
0
 /**
  * process the form after the input has been submitted and validated
  *
  * @access public
  *
  * @return void
  */
 public function postProcess()
 {
     //get the submitted values in an array
     $params = $this->controller->exportValues($this->_name);
     $contactTags = $tagList = array();
     // check if contact tags exists
     if (!empty($params['tag'])) {
         $contactTags = $params['tag'];
     }
     // check if tags are selected from taglists
     if (!empty($params['contact_taglist'])) {
         foreach ($params['contact_taglist'] as $val) {
             if ($val) {
                 if (is_numeric($val)) {
                     $tagList[$val] = 1;
                 } else {
                     $tagIDs = explode(',', $val);
                     if (!empty($tagIDs)) {
                         foreach ($tagIDs as $tagID) {
                             if (is_numeric($tagID)) {
                                 $tagList[$tagID] = 1;
                             }
                         }
                     }
                 }
             }
         }
     }
     $tagSets = CRM_Core_BAO_Tag::getTagsUsedFor('civicrm_contact', FALSE, TRUE);
     foreach ($tagSets as $key => $value) {
         $this->_tags[$key] = $value['name'];
     }
     // merge contact and taglist tags
     $allTags = CRM_Utils_Array::crmArrayMerge($contactTags, $tagList);
     $this->_name = array();
     foreach ($allTags as $key => $dnc) {
         $this->_name[] = $this->_tags[$key];
         list($total, $added, $notAdded) = CRM_Core_BAO_EntityTag::addEntitiesToTag($this->_contactIds, $key);
         $status = array(ts('%count contact tagged', array('count' => $added, 'plural' => '%count contacts tagged')));
         if ($notAdded) {
             $status[] = ts('%count contact already had this tag', array('count' => $notAdded, 'plural' => '%count contacts already had this tag'));
         }
         $status = '<ul><li>' . implode('</li><li>', $status) . '</li></ul>';
         CRM_Core_Session::setStatus($status, ts("Added Tag <em>%1</em>", array(1 => $this->_tags[$key])), 'success', array('expires' => 0));
     }
 }
Ejemplo n.º 6
0
 /**
  * add all the elements shared between case search and advanaced search
  *
  * @access public 
  * @return void
  * @static
  */
 static function buildSearchForm(&$form)
 {
     $config = CRM_Core_Config::singleton();
     //validate case configuration.
     require_once 'CRM/Case/BAO/Case.php';
     $configured = CRM_Case_BAO_Case::isCaseConfigured();
     $form->assign('notConfigured', !$configured['configured']);
     require_once "CRM/Case/PseudoConstant.php";
     $caseTypes = CRM_Case_PseudoConstant::caseType('label', false);
     foreach ($caseTypes as $id => $Name) {
         $form->addElement('checkbox', "case_type_id[{$id}]", null, $Name);
     }
     $statuses = CRM_Case_PseudoConstant::caseStatus('label', false);
     $form->add('select', 'case_status_id', ts('Case Status'), array('' => ts('- any status -')) + $statuses);
     $form->assign('validCiviCase', true);
     //give options when all cases are accessible.
     $accessAllCases = false;
     if (CRM_Core_Permission::check('access all cases and activities')) {
         $accessAllCases = true;
         $caseOwner = array(1 => ts('Search All Cases'), 2 => ts('Only My Cases'));
         $form->addRadio('case_owner', ts('Cases'), $caseOwner);
     }
     $form->assign('accessAllCases', $accessAllCases);
     require_once 'CRM/Core/BAO/Tag.php';
     $caseTags = CRM_Core_BAO_Tag::getTagsUsedFor(array('civicrm_case'));
     if ($caseTags) {
         foreach ($caseTags as $tagID => $tagName) {
             $form->_tagElement =& $form->addElement('checkbox', "case_tags[{$tagID}]", null, $tagName);
         }
     }
     require_once "CRM/Core/Permission.php";
     if (CRM_Core_Permission::check('administer CiviCRM')) {
         $form->addElement('checkbox', 'case_deleted', ts('Deleted Cases'));
     }
 }
Ejemplo n.º 7
0
 /** 
  * where clause for a single field
  * 
  * @return void 
  * @access public 
  */
 static function whereClauseSingle(&$values, &$query)
 {
     list($name, $op, $value, $grouping, $wildcard) = $values;
     $strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower';
     $query->_tables['civicrm_activity'] = $query->_whereTables['civicrm_activity'] = 1;
     if ($query->_mode & CRM_Contact_BAO_Query::MODE_ACTIVITY) {
         $query->_skipDeleteClause = true;
     }
     switch ($name) {
         case 'activity_type_id':
             $types = CRM_Core_PseudoConstant::activityType(true, true);
             $clause = array();
             if (is_array($value)) {
                 foreach ($value as $id => $dontCare) {
                     if (array_key_exists($id, $types) && $dontCare) {
                         $clause[] = "'" . CRM_Utils_Type::escape($types[$id], 'String') . "'";
                     }
                 }
                 $activityTypes = implode(',', array_keys($value));
             } else {
                 $clause[] = "'" . CRM_Utils_Type::escape($value, 'String') . "'";
                 $activityTypes = $value;
             }
             $query->_where[$grouping][] = ' civicrm_activity.activity_type_id IN (' . $activityTypes . ')';
             $query->_qill[$grouping][] = ts('Activity Type') . ' ' . implode(' ' . ts('or') . ' ', $clause);
             break;
         case 'activity_survey_id':
             if (!$value) {
                 break;
             }
             $value = CRM_Utils_Type::escape($value, 'Integer');
             $query->_where[$grouping][] = " source_record_id = {$value}";
             $query->_qill[$grouping][] = ts('Survey') . ' - ' . CRM_Core_DAO::getFieldValue('CRM_Campaign_DAO_Survey', $value, 'title');
             break;
         case 'activity_role':
             CRM_Contact_BAO_Query::$_activityRole = $values[2];
             //for activity target name
             $activityTargetName = $query->getWhereValues('activity_contact_name', $grouping);
             if (!$activityTargetName[2]) {
                 $name = null;
             } else {
                 $name = trim($activityTargetName[2]);
                 $name = strtolower(CRM_Core_DAO::escapeString($name));
             }
             $query->_where[$grouping][] = " contact_b.is_deleted = 0 AND contact_b.sort_name LIKE '%{$name}%'";
             if ($values[2] == 1) {
                 $query->_where[$grouping][] = " civicrm_activity.source_contact_id = contact_b.id";
                 $query->_qill[$grouping][] = ts('Activity created by') . " '{$name}'";
                 $query->_tables['civicrm_activity_contact'] = $query->_whereTables['civicrm_activity_contact'] = 1;
             } else {
                 if ($values[2] == 2) {
                     $query->_where[$grouping][] = " civicrm_activity_assignment.activity_id = civicrm_activity.id AND civicrm_activity_assignment.assignee_contact_id = contact_b.id";
                     $query->_tables['civicrm_activity_assignment'] = $query->_whereTables['civicrm_activity_assignment'] = 1;
                     $query->_tables['civicrm_activity_contact'] = $query->_whereTables['civicrm_activity_contact'] = 1;
                     $query->_qill[$grouping][] = ts('Activity assigned to') . " '{$name}'";
                 }
             }
             break;
         case 'activity_status':
             $status = CRM_Core_PseudoConstant::activityStatus();
             $clause = array();
             if (is_array($value)) {
                 foreach ($value as $k => $v) {
                     if ($k) {
                         $clause[] = "'" . CRM_Utils_Type::escape($status[$k], 'String') . "'";
                     }
                 }
             } else {
                 $clause[] = "'" . CRM_Utils_Type::escape($value, 'String') . "'";
             }
             $query->_where[$grouping][] = ' civicrm_activity.status_id IN (' . implode(',', array_keys($value)) . ')';
             $query->_qill[$grouping][] = ts('Activity Status') . ' - ' . implode(' ' . ts('or') . ' ', $clause);
             break;
         case 'activity_subject':
             $n = trim($value);
             $value = strtolower(CRM_Core_DAO::escapeString($n));
             if ($wildcard) {
                 if (strpos($value, '%') !== false) {
                     // only add wild card if not there
                     $value = "'{$value}'";
                 } else {
                     $value = "'%{$value}%'";
                 }
                 $op = 'LIKE';
             } else {
                 $value = "'{$value}'";
             }
             $wc = $op != 'LIKE' ? "LOWER(civicrm_activity.subject)" : "civicrm_activity.subject";
             $query->_where[$grouping][] = " {$wc} {$op} {$value}";
             $query->_qill[$grouping][] = ts('Subject') . " {$op} - '{$n}'";
             break;
         case 'activity_test':
             $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_activity.is_test", $op, $value, "Integer");
             if ($value) {
                 $query->_qill[$grouping][] = ts('Find Test Activities');
             }
             break;
         case 'activity_date':
         case 'activity_date_low':
         case 'activity_date_high':
             $query->dateQueryBuilder($values, 'civicrm_activity', 'activity_date', 'activity_date_time', ts('Activity Date'));
             break;
         case 'activity_tags':
             require_once 'CRM/Core/BAO/Tag.php';
             $value = array_keys($value);
             $activityTags = CRM_Core_BAO_Tag::getTagsUsedFor('civicrm_activity');
             $names = array();
             $val = array();
             if (is_array($value)) {
                 foreach ($value as $k => $v) {
                     $names[] = $activityTags[$v];
                 }
             }
             $query->_where[$grouping][] = "civicrm_activity_tag.tag_id IN (" . implode(",", $value) . ")";
             $query->_qill[$grouping][] = ts('Activity Tag %1', array(1 => $op)) . ' ' . implode(' ' . ts('OR') . ' ', $names);
             $query->_tables['civicrm_activity_tag'] = $query->_whereTables['civicrm_activity_tag'] = 1;
             break;
     }
 }
Ejemplo n.º 8
0
 /**
  * @param CRM_Core_Form $form
  */
 public static function basic(&$form)
 {
     $form->addElement('hidden', 'hidden_basic', 1);
     if ($form->_searchOptions['contactType']) {
         // add checkboxes for contact type
         //@todo FIXME - using the CRM_Core_DAO::VALUE_SEPARATOR creates invalid html - if you can find the form
         // this is loaded onto then replace with something like '__' & test
         $separator = CRM_Core_DAO::VALUE_SEPARATOR;
         $contactTypes = CRM_Contact_BAO_ContactType::getSelectElements(FALSE, TRUE, $separator);
         if ($contactTypes) {
             $form->add('select', 'contact_type', ts('Contact Type(s)'), $contactTypes, FALSE, array('id' => 'contact_type', 'multiple' => 'multiple', 'class' => 'crm-select2', 'style' => 'width: 100%;'));
         }
     }
     if ($form->_searchOptions['groups']) {
         // multiselect for groups
         if ($form->_group) {
             // Arrange groups into hierarchical listing (child groups follow their parents and have indentation spacing in title)
             $groupHierarchy = CRM_Contact_BAO_Group::getGroupsHierarchy($form->_group, NULL, '&nbsp;&nbsp;', TRUE);
             $form->add('select', 'group', ts('Groups'), $groupHierarchy, FALSE, array('id' => 'group', 'multiple' => 'multiple', 'class' => 'crm-select2'));
             $groupOptions = CRM_Core_BAO_OptionValue::getOptionValuesAssocArrayFromName('group_type');
             $form->add('select', 'group_type', ts('Group Types'), $groupOptions, FALSE, array('id' => 'group_type', 'multiple' => 'multiple', 'class' => 'crm-select2'));
             $form->add('hidden', 'group_search_selected', 'group');
         }
     }
     if ($form->_searchOptions['tags']) {
         // multiselect for categories
         $contactTags = CRM_Core_BAO_Tag::getTags();
         if ($contactTags) {
             $form->add('select', 'contact_tags', ts('Tags'), $contactTags, FALSE, array('id' => 'contact_tags', 'multiple' => 'multiple', 'class' => 'crm-select2', 'style' => 'width: 100%;'));
         }
         $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_contact');
         CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_contact', NULL, TRUE, FALSE);
         $used_for = CRM_Core_OptionGroup::values('tag_used_for');
         $tagsTypes = array();
         $showAllTagTypes = FALSE;
         foreach ($used_for as $key => $value) {
             //check tags for every type and find if there are any defined
             $tags = CRM_Core_BAO_Tag::getTagsUsedFor($key, FALSE, TRUE, NULL);
             // check if there are tags other than contact type, if no - keep checkbox hidden on adv search
             // we will hide searching contact by attachments tags until it will be implemented in core
             if (count($tags) && $key != 'civicrm_file' && $key != 'civicrm_contact') {
                 //if tags exists then add type to display in adv search form help text
                 $tagsTypes[] = ts($value);
                 $showAllTagTypes = TRUE;
             }
         }
         $tagTypesText = implode(" or ", $tagsTypes);
         if ($showAllTagTypes) {
             $form->add('checkbox', 'all_tag_types', ts('Include tags used for %1', array(1 => $tagTypesText)));
             $form->add('hidden', 'tag_types_text', $tagTypesText);
         }
     }
     // add text box for last name, first name, street name, city
     $form->addElement('text', 'sort_name', ts('Find...'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
     // add text box for last name, first name, street name, city
     $form->add('text', 'email', ts('Contact Email'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
     //added contact source
     $form->add('text', 'contact_source', ts('Contact Source'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'contact_source'));
     //added job title
     $form->addElement('text', 'job_title', ts('Job Title'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'job_title'));
     //added internal ID
     $form->addElement('text', 'contact_id', ts('Contact ID'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'id'));
     $form->addRule('contact_id', ts('Please enter valid Contact ID'), 'positiveInteger');
     //added external ID
     $form->addElement('text', 'external_identifier', ts('External ID'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'external_identifier'));
     if (CRM_Core_Permission::check('access deleted contacts') and CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_undelete', NULL)) {
         $form->add('checkbox', 'deleted_contacts', ts('Search in Trash') . '<br />' . ts('(deleted contacts)'));
     }
     // add checkbox for cms users only
     $form->addYesNo('uf_user', ts('CMS User?'), TRUE);
     // tag all search
     $form->add('text', 'tag_search', ts('All Tags'));
     // add search profiles
     // FIXME: This is probably a part of profiles - need to be
     // FIXME: eradicated from here when profiles are reworked.
     $types = array('Participant', 'Contribution', 'Membership');
     // get component profiles
     $componentProfiles = array();
     $componentProfiles = CRM_Core_BAO_UFGroup::getProfiles($types);
     $ufGroups = CRM_Core_BAO_UFGroup::getModuleUFGroup('Search Profile', 1);
     $accessibleUfGroups = CRM_Core_Permission::ufGroup(CRM_Core_Permission::VIEW);
     $searchProfiles = array();
     foreach ($ufGroups as $key => $var) {
         if (!array_key_exists($key, $componentProfiles) && in_array($key, $accessibleUfGroups)) {
             $searchProfiles[$key] = $var['title'];
         }
     }
     $form->add('select', 'uf_group_id', ts('Search Views'), array('0' => ts('- default view -')) + $searchProfiles, FALSE, array('class' => 'crm-select2'));
     $componentModes = CRM_Contact_Form_Search::getModeSelect();
     // unset contributions or participants if user does not have
     // permission on them
     if (!CRM_Core_Permission::access('CiviContribute')) {
         unset($componentModes['2']);
     }
     if (!CRM_Core_Permission::access('CiviEvent')) {
         unset($componentModes['3']);
     }
     if (!CRM_Core_Permission::access('CiviMember')) {
         unset($componentModes['5']);
     }
     if (!CRM_Core_Permission::check('view all activities')) {
         unset($componentModes['4']);
     }
     if (count($componentModes) > 1) {
         $form->add('select', 'component_mode', ts('Display Results As'), $componentModes, FALSE, array('class' => 'crm-select2'));
     }
     $form->addRadio('operator', ts('Search Operator'), array('AND' => ts('AND'), 'OR' => ts('OR')), array('allowClear' => FALSE));
     // add the option to display relationships
     $rTypes = CRM_Core_PseudoConstant::relationshipType();
     $rSelect = array('' => ts('- Select Relationship Type-'));
     foreach ($rTypes as $rid => $rValue) {
         if ($rValue['label_a_b'] == $rValue['label_b_a']) {
             $rSelect[$rid] = $rValue['label_a_b'];
         } else {
             $rSelect["{$rid}_a_b"] = $rValue['label_a_b'];
             $rSelect["{$rid}_b_a"] = $rValue['label_b_a'];
         }
     }
     $form->addElement('select', 'display_relationship_type', ts('Display Results as Relationship'), $rSelect, array('class' => 'crm-select2'));
     // checkboxes for DO NOT phone, email, mail
     // we take labels from SelectValues
     $t = CRM_Core_SelectValues::privacy();
     $form->add('select', 'privacy_options', ts('Privacy'), $t, FALSE, array('id' => 'privacy_options', 'multiple' => 'multiple', 'class' => 'crm-select2'));
     $form->addElement('select', 'privacy_operator', ts('Operator'), array('OR' => ts('OR'), 'AND' => ts('AND')));
     $options = array(1 => ts('Exclude'), 2 => ts('Include by Privacy Option(s)'));
     $form->addRadio('privacy_toggle', ts('Privacy Options'), $options, array('allowClear' => FALSE));
     // preferred communication method
     $comm = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'preferred_communication_method');
     $commPreff = array();
     foreach ($comm as $k => $v) {
         $commPreff[] = $form->createElement('advcheckbox', $k, NULL, $v);
     }
     $onHold[] = $form->createElement('advcheckbox', 'on_hold', NULL, '');
     $form->addGroup($onHold, 'email_on_hold', ts('Email On Hold'));
     $form->addGroup($commPreff, 'preferred_communication_method', ts('Preferred Communication Method'));
     //CRM-6138 Preferred Language
     $form->addSelect('preferred_language', array('class' => 'twenty', 'context' => 'search'));
     // Phone search
     $form->addElement('text', 'phone_numeric', ts('Phone Number'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Phone', 'phone'));
     $locationType = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
     $phoneType = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id');
     $form->add('select', 'phone_location_type_id', ts('Phone Location'), array('' => ts('- any -')) + $locationType, FALSE, array('class' => 'crm-select2'));
     $form->add('select', 'phone_phone_type_id', ts('Phone Type'), array('' => ts('- any -')) + $phoneType, FALSE, array('class' => 'crm-select2'));
 }
Ejemplo n.º 9
0
 /**
  * Function to build tag widget if correct parent is passed
  *
  * @param object  $form form object
  * @param string  $parentName parent name ( tag name)
  * @param string  $entityTable entitytable 'eg: civicrm_contact'
  * @param int     $entityId    entityid  'eg: contact id'
  *
  * @return void
  * @access public
  * @static
  */
 static function buildQuickForm(&$form, $parentNames, $entityTable, $entityId = NULL, $skipTagCreate = FALSE, $skipEntityAction = FALSE, $searchMode = FALSE)
 {
     $tagset = $form->_entityTagValues = array();
     $mode = NULL;
     foreach ($parentNames as &$parentNameItem) {
         // get the parent id for tag list input for keyword
         $parentId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Tag', $parentNameItem, 'id', 'name');
         // check if parent exists
         $entityTags = array();
         if ($parentId) {
             $tagsetItem = 'parentId_' . $parentId;
             $tagset[$tagsetItem]['parentName'] = $parentNameItem;
             $tagset[$tagsetItem]['parentID'] = $parentId;
             //tokeninput url
             $qparams = "parentId={$parentId}";
             if ($searchMode) {
                 $qparams .= '&search=1';
             }
             $tagUrl = CRM_Utils_System::url('civicrm/ajax/taglist', $qparams, FALSE, NULL, FALSE);
             $tagset[$tagsetItem]['tagUrl'] = $tagUrl;
             $tagset[$tagsetItem]['entityTable'] = $entityTable;
             $tagset[$tagsetItem]['skipTagCreate'] = $skipTagCreate;
             $tagset[$tagsetItem]['skipEntityAction'] = $skipEntityAction;
             switch ($entityTable) {
                 case 'civicrm_activity':
                     $tagsetElementName = "activity_taglist";
                     $mode = 'activity';
                     break;
                 case 'civicrm_case':
                     $tagsetElementName = "case_taglist";
                     $mode = 'case';
                     break;
                 default:
                     $tagsetElementName = "contact_taglist";
                     $mode = 'contact';
             }
             $tagset[$tagsetItem]['tagsetElementName'] = $tagsetElementName;
             $form->add('text', "{$tagsetElementName}[{$parentId}]", NULL);
             if ($entityId) {
                 $tagset[$tagsetItem]['entityId'] = $entityId;
                 $entityTags = CRM_Core_BAO_EntityTag::getChildEntityTags($parentId, $entityId, $entityTable);
             } else {
                 switch ($entityTable) {
                     case 'civicrm_activity':
                         if (!empty($form->_submitValues['activity_taglist']) && CRM_Utils_Array::value($parentId, $form->_submitValues['activity_taglist'])) {
                             $allTags = CRM_Core_PseudoConstant::tag();
                             $tagIds = explode(',', $form->_submitValues['activity_taglist'][$parentId]);
                             foreach ($tagIds as $tagId) {
                                 if (is_numeric($tagId)) {
                                     $tagName = $allTags[$tagId];
                                 } else {
                                     $tagName = $tagId;
                                 }
                                 $entityTags[$tagId] = array('id' => $tagId, 'name' => $tagName);
                             }
                         }
                         break;
                     case 'civicrm_case':
                         if (!empty($form->_submitValues['case_taglist']) && CRM_Utils_Array::value($parentId, $form->_submitValues['case_taglist'])) {
                             $allTags = CRM_Core_PseudoConstant::tag();
                             $tagIds = explode(',', $form->_submitValues['case_taglist'][$parentId]);
                             foreach ($tagIds as $tagId) {
                                 if (is_numeric($tagId)) {
                                     $tagName = $allTags[$tagId];
                                 } else {
                                     $tagName = $tagId;
                                 }
                                 $entityTags[$tagId] = array('id' => $tagId, 'name' => $tagName);
                             }
                         }
                         break;
                     default:
                         if (!empty($form->_formValues['contact_tags'])) {
                             $contactTags = CRM_Core_BAO_Tag::getTagsUsedFor('civicrm_contact', TRUE, FALSE, $parentId);
                             foreach (array_keys($form->_formValues['contact_tags']) as $tagId) {
                                 if (CRM_Utils_Array::value($tagId, $contactTags)) {
                                     $tagName = $tagId;
                                     if (is_numeric($tagId)) {
                                         $tagName = $contactTags[$tagId];
                                     }
                                     $entityTags[$tagId] = array('id' => $tagId, 'name' => $tagName);
                                 }
                             }
                         }
                 }
             }
             if (!empty($entityTags)) {
                 // assign as simple array for display in smarty
                 $tagset[$tagsetItem]['entityTagsArray'] = $entityTags;
                 // assign as json for js widget
                 $tagset[$tagsetItem]['entityTags'] = json_encode(array_values($entityTags));
                 if (!empty($form->_entityTagValues)) {
                     $form->_entityTagValues = CRM_Utils_Array::crmArrayMerge($entityTags, $form->_entityTagValues);
                 } else {
                     $form->_entityTagValues = $entityTags;
                 }
             }
         }
     }
     if (!empty($tagset)) {
         $form->assign("tagsetInfo_{$mode}", $tagset);
     }
 }
 /**
  * process the form after the input has been submitted and validated
  *
  * @access public
  *
  * @return None
  */
 public function postProcess()
 {
     //get the submitted values in an array
     $params = $this->controller->exportValues($this->_name);
     $contactTags = $tagList = array();
     // check if contact tags exists
     if (CRM_Utils_Array::value('tag', $params)) {
         $contactTags = $params['tag'];
     }
     // check if tags are selected from taglists
     if (CRM_Utils_Array::value('contact_taglist', $params)) {
         foreach ($params['contact_taglist'] as $val) {
             if ($val) {
                 if (is_numeric($val)) {
                     $tagList[$val] = 1;
                 } else {
                     list($label, $tagID) = explode(',', $val);
                     $tagList[$tagID] = 1;
                 }
             }
         }
     }
     $tagSets = CRM_Core_BAO_Tag::getTagsUsedFor('civicrm_contact', FALSE, TRUE);
     foreach ($tagSets as $key => $value) {
         $this->_tags[$key] = $value['name'];
     }
     // merge contact and taglist tags
     $allTags = CRM_Utils_Array::crmArrayMerge($contactTags, $tagList);
     $this->_name = array();
     foreach ($allTags as $key => $dnc) {
         $this->_name[] = $this->_tags[$key];
         list($total, $removed, $notRemoved) = CRM_Core_BAO_EntityTag::removeEntitiesFromTag($this->_contactIds, $key);
         $status = array('Contact(s) tagged as: ' . implode(',', $this->_name), 'Total Selected Contact(s): ' . $total);
     }
     if ($removed) {
         $status[] = 'Total Contact(s) to be  removed from tag: ' . $removed;
     }
     if ($notRemoved) {
         $status[] = 'Total Contact(s) already removed: ' . $notRemoved;
     }
     CRM_Core_Session::setStatus($status);
 }
Ejemplo n.º 11
0
 /**
  * Function to build tag widget if correct parent is passed
  * 
  * @param object  $form form object
  * @param string  $parentName parent name ( tag name)
  * @param string  $entityTable entitytable 'eg: civicrm_contact'
  * @param int     $entityId    entityid  'eg: contact id'
  *
  * @return void
  * @access public
  * @static
  */
 static function buildQuickForm(&$form, $parentNames, $entityTable, $entityId = null, $skipTagCreate = false, $skipEntityAction = false)
 {
     $tagset = $form->_entityTagValues = array();
     foreach ($parentNames as &$parentNameItem) {
         // get the parent id for tag list input for keyword
         $parentId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Tag', $parentNameItem, 'id', 'name');
         // check if parent exists
         $entityTags = array();
         if ($parentId) {
             $tagsetItem = 'parentId_' . $parentId;
             $tagset[$tagsetItem]['parentName'] = $parentNameItem;
             $tagset[$tagsetItem]['parentID'] = $parentId;
             //tokeninput url
             $tagUrl = CRM_Utils_System::url('civicrm/ajax/taglist', "parentId={$parentId}", false, null, false);
             $tagset[$tagsetItem]['tagUrl'] = $tagUrl;
             $tagset[$tagsetItem]['entityTable'] = $entityTable;
             $tagset[$tagsetItem]['skipTagCreate'] = $skipTagCreate;
             $tagset[$tagsetItem]['skipEntityAction'] = $skipEntityAction;
             $tagset[$tagsetItem]['tagElementName'] = "taglist[{$parentId}]";
             $form->add('text', "taglist[{$parentId}]", null);
             if ($entityId) {
                 $tagset[$tagsetItem]['entityId'] = $entityId;
                 require_once 'CRM/Core/BAO/EntityTag.php';
                 $entityTags = CRM_Core_BAO_EntityTag::getChildEntityTags($parentId, $entityId, $entityTable);
             } elseif (!empty($form->_submitValues['taglist']) && CRM_Utils_Array::value($parentId, $form->_submitValues['taglist'])) {
                 $allTags = CRM_Core_Pseudoconstant::tag();
                 $tagIds = explode(',', $form->_submitValues['taglist'][$parentId]);
                 foreach ($tagIds as $tagId) {
                     if (is_numeric($tagId)) {
                         $tagName = $allTags[$tagId];
                     } else {
                         $tagName = $tagId;
                     }
                     $entityTags[$tagId] = array('id' => $tagId, 'name' => $tagName);
                 }
             } elseif (!empty($form->_formValues['contact_tags'])) {
                 require_once 'CRM/Core/BAO/Tag.php';
                 $contactTags = CRM_Core_BAO_Tag::getTagsUsedFor('civicrm_contact', true, false, $parentId);
                 foreach (array_keys($form->_formValues['contact_tags']) as $tagId) {
                     if (CRM_Utils_Array::value($tagId, $contactTags)) {
                         $tagName = $tagId;
                         if (is_numeric($tagId)) {
                             $tagName = $contactTags[$tagId];
                         }
                         $entityTags[$tagId] = array('id' => $tagId, 'name' => $tagName);
                     }
                 }
             }
             if (!empty($entityTags)) {
                 // assign as simple array for display in smarty
                 $tagset[$tagsetItem]['entityTagsArray'] = $entityTags;
                 // assign as json for js widget
                 $tagset[$tagsetItem]['entityTags'] = json_encode(array_values($entityTags));
                 if (!empty($form->_entityTagValues)) {
                     $form->_entityTagValues = CRM_Utils_Array::crmArrayMerge($entityTags, $form->_entityTagValues);
                 } else {
                     $form->_entityTagValues = $entityTags;
                 }
             }
         }
     }
     $form->assign('tagset', $tagset);
 }