Exemple #1
0
 /**
  * returns all the rows in the given offset and rowCount
  *
  * @param enum   $action   the action being performed
  * @param int    $offset   the row number to start from
  * @param int    $rowCount the number of rows to return
  * @param string $sort     the sql string that describes the sort order
  * @param enum   $output   what should the result set include (web/email/csv)
  *
  * @return int   the total number of rows for this action
  */
 function &getRows($action, $offset, $rowCount, $sort, $output = null)
 {
     $config =& CRM_Core_Config::singleton();
     if (($output == CRM_Core_Selector_Controller::EXPORT || $output == CRM_Core_Selector_Controller::SCREEN) && $this->_formValues['radio_ts'] == 'ts_sel') {
         $includeContactIds = true;
     } else {
         $includeContactIds = false;
     }
     // note the formvalues were given by CRM_Contact_Form_Search to us
     // and contain the search criteria (parameters)
     // note that the default action is basic
     $result = $this->_query->searchQuery($offset, $rowCount, $sort, false, $includeContactIds);
     // process the result of the query
     $rows = array();
     $permissions = array(CRM_Core_Permission::getPermission());
     if (CRM_Core_Permission::check('delete contacts')) {
         $permissions[] = CRM_Core_Permission::DELETE;
     }
     $mask = CRM_Core_Action::mask($permissions);
     $mapMask = $mask & 4095;
     // mask value to hide map link if there are not lat/long
     $gc = CRM_Core_SelectValues::groupContactStatus();
     if ($this->_ufGroupID) {
         require_once 'CRM/Core/PseudoConstant.php';
         $locationTypes = CRM_Core_PseudoConstant::locationType();
         $names = array();
         static $skipFields = array('group', 'tag');
         foreach ($this->_fields as $key => $field) {
             if (CRM_Utils_Array::value('in_selector', $field) && !in_array($key, $skipFields)) {
                 if (strpos($key, '-') !== false) {
                     list($fieldName, $id, $type) = explode('-', $key);
                     if ($id == 'Primary') {
                         $locationTypeName = 1;
                     } else {
                         $locationTypeName = CRM_Utils_Array::value($id, $locationTypes);
                         if (!$locationTypeName) {
                             continue;
                         }
                     }
                     $locationTypeName = str_replace(' ', '_', $locationTypeName);
                     if (in_array($fieldName, array('phone', 'im', 'email'))) {
                         if ($type) {
                             $names[] = "{$locationTypeName}-{$fieldName}-{$type}";
                         } else {
                             $names[] = "{$locationTypeName}-{$fieldName}";
                         }
                     } else {
                         $names[] = "{$locationTypeName}-{$fieldName}";
                     }
                 } else {
                     $names[] = $field['name'];
                 }
             }
         }
         $names[] = "status";
     } else {
         if (!empty($this->_returnProperties)) {
             $names =& self::makeProperties($this->_returnProperties);
         } else {
             $names = self::$_properties;
         }
     }
     //hack for student data (checkboxs)
     $multipleSelectFields = array('preferred_communication_method' => 1);
     if (CRM_Core_Permission::access('Quest')) {
         require_once 'CRM/Quest/BAO/Student.php';
         $multipleSelectFields = CRM_Quest_BAO_Student::$multipleSelectFields;
     }
     $searchType = null;
     if ($this->_action == CRM_Core_Action::BASIC) {
         $searchType = 'basic';
     } elseif ($this->_action == CRM_Core_Action::ADVANCED) {
         $searchType = 'advance';
     }
     require_once 'CRM/Core/OptionGroup.php';
     $links =& self::links($searchType, $this->_contextMenu);
     //check explicitly added contact to a Smart Group.
     $groupID = CRM_Utils_Array::key('1', $this->_formValues['group']);
     while ($result->fetch()) {
         $row = array();
         // the columns we are interested in
         foreach ($names as $property) {
             if ($property == 'status') {
                 continue;
             }
             if ($cfID = CRM_Core_BAO_CustomField::getKeyID($property)) {
                 $row[$property] = CRM_Core_BAO_CustomField::getDisplayValue($result->{$property}, $cfID, $this->_options, $result->contact_id);
             } else {
                 if ($multipleSelectFields && array_key_exists($property, $multipleSelectFields)) {
                     //fix to display student checkboxes
                     $key = $property;
                     $paramsNew = array($key => $result->{$property});
                     if ($key == 'test_tutoring') {
                         $name = array($key => array('newName' => $key, 'groupName' => 'test'));
                     } else {
                         if (substr($key, 0, 4) == 'cmr_') {
                             //for  readers group
                             $name = array($key => array('newName' => $key, 'groupName' => substr($key, 0, -3)));
                         } else {
                             $name = array($key => array('newName' => $key, 'groupName' => $key));
                         }
                     }
                     CRM_Core_OptionGroup::lookupValues($paramsNew, $name, false);
                     $row[$key] = $paramsNew[$key];
                 } else {
                     if (isset($tmfFields) && $tmfFields && array_key_exists($property, $tmfFields) || substr($property, 0, 12) == 'participant_') {
                         if (substr($property, -3) == '_id') {
                             $key = substr($property, 0, -3);
                             $paramsNew = array($key => $result->{$property});
                             $name = array($key => array('newName' => $key, 'groupName' => $key));
                             CRM_Core_OptionGroup::lookupValues($paramsNew, $name, false);
                             $row[$key] = $paramsNew[$key];
                         } else {
                             $row[$property] = $result->{$property};
                         }
                     } else {
                         if (strpos($property, '-im')) {
                             $row[$property] = $result->{$property};
                             if (!empty($result->{$property})) {
                                 $imProviders = CRM_Core_PseudoConstant::IMProvider();
                                 $providerId = $property . "-provider_id";
                                 $providerName = $imProviders[$result->{$providerId}];
                                 $row[$property] = $result->{$property} . " ({$providerName})";
                             }
                         } else {
                             if (in_array($property, array('addressee', 'email_greeting', 'postal_greeting'))) {
                                 $greeting = $property . '_display';
                                 $row[$property] = $result->{$greeting};
                             } else {
                                 $row[$property] = $result->{$property};
                             }
                         }
                     }
                 }
             }
             if (!empty($result->{$property})) {
                 $empty = false;
             }
         }
         if (!empty($result->postal_code_suffix)) {
             $row['postal_code'] .= "-" . $result->postal_code_suffix;
         }
         if ($output != CRM_Core_Selector_Controller::EXPORT && $this->_searchContext == 'smog') {
             if (empty($result->status) && $groupID) {
                 $contactID = $result->contact_id;
                 if ($contactID) {
                     $gcParams = array('contact_id' => $contactID, 'group_id' => $groupID);
                     $gcDefaults = array();
                     CRM_Core_DAO::commonRetrieve('CRM_Contact_DAO_GroupContact', $gcParams, $gcDefaults);
                     if (empty($gcDefaults)) {
                         $row['status'] = ts('Smart');
                     } else {
                         $row['status'] = $gc[$gcDefaults['status']];
                     }
                 } else {
                     $row['status'] = null;
                 }
             } else {
                 $row['status'] = $gc[$result->status];
             }
         }
         if ($output != CRM_Core_Selector_Controller::EXPORT) {
             $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $result->contact_id;
             if (is_numeric(CRM_Utils_Array::value('geo_code_1', $row)) || $config->mapGeoCoding && CRM_Utils_Array::value('city', $row) && $row['state_province']) {
                 $row['action'] = CRM_Core_Action::formLink($links, $mask, array('id' => $result->contact_id));
             } else {
                 $row['action'] = CRM_Core_Action::formLink($links, $mapMask, array('id' => $result->contact_id));
             }
             // allow components to add more actions
             CRM_Core_Component::searchAction($row, $result->contact_id);
             require_once 'CRM/Contact/BAO/Contact/Utils.php';
             $row['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type);
             $row['contact_id'] = $result->contact_id;
             $row['sort_name'] = $result->sort_name;
             if (array_key_exists('id', $row)) {
                 $row['id'] = $result->contact_id;
             }
         }
         // Dedupe contacts
         if (!$empty) {
             $duplicate = false;
             foreach ($rows as $checkRow) {
                 if ($checkRow['contact_id'] == $row['contact_id']) {
                     $duplicate = true;
                 }
             }
             if (!$duplicate) {
                 $rows[] = $row;
             }
         }
     }
     //CRM_Core_Error::debug( '$rows', $rows );
     return $rows;
 }
Exemple #2
0
 /**
  * Returns all the rows in the given offset and rowCount.
  *
  * @param string $action
  *   The action being performed.
  * @param int $offset
  *   The row number to start from.
  * @param int $rowCount
  *   The number of rows to return.
  * @param string $sort
  *   The sql string that describes the sort order.
  * @param string $output
  *   What should the result set include (web/email/csv).
  *
  * @return array
  *   rows in the given offset and rowCount
  */
 public function &getRows($action, $offset, $rowCount, $sort, $output = NULL)
 {
     $result = $this->_query->searchQuery($offset, $rowCount, $sort, FALSE, FALSE, FALSE, FALSE, FALSE, $this->_eventClause);
     // process the result of the query
     $rows = array();
     //lets handle view, edit and delete separately. CRM-4418
     $permissions = array(CRM_Core_Permission::VIEW);
     if (CRM_Core_Permission::check('edit event participants')) {
         $permissions[] = CRM_Core_Permission::EDIT;
     }
     if (CRM_Core_Permission::check('delete in CiviEvent')) {
         $permissions[] = CRM_Core_Permission::DELETE;
     }
     $mask = CRM_Core_Action::mask($permissions);
     $statusTypes = CRM_Event_PseudoConstant::participantStatus();
     $statusClasses = CRM_Event_PseudoConstant::participantStatusClass();
     $participantRoles = CRM_Event_PseudoConstant::participantRole();
     $sep = CRM_Core_DAO::VALUE_SEPARATOR;
     //get all campaigns.
     $allCampaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
     while ($result->fetch()) {
         $row = array();
         // the columns we are interested in
         foreach (self::$_properties as $property) {
             if (isset($result->{$property})) {
                 $row[$property] = $result->{$property};
             }
         }
         //carry campaign on selectors.
         $row['campaign'] = CRM_Utils_Array::value($result->participant_campaign_id, $allCampaigns);
         $row['campaign_id'] = $result->participant_campaign_id;
         // gross hack to show extra information for pending status
         $statusClass = NULL;
         if (isset($row['participant_status_id']) && ($statusId = array_search($row['participant_status_id'], $statusTypes))) {
             $statusClass = $statusClasses[$statusId];
         }
         $row['showConfirmUrl'] = $statusClass == 'Pending' ? TRUE : FALSE;
         if (!empty($row['participant_is_test'])) {
             $row['participant_status'] .= ' (' . ts('test') . ')';
         }
         $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $result->participant_id;
         $links = self::links($this->_key, $this->_context, $this->_compContext);
         if ($statusTypes[$row['participant_status_id']] == 'Partially paid') {
             $links[CRM_Core_Action::ADD] = array('name' => ts('Record Payment'), 'url' => 'civicrm/payment', 'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&action=add&component=event', 'title' => ts('Record Payment'));
         }
         if ($statusTypes[$row['participant_status_id']] == 'Pending refund') {
             $links[CRM_Core_Action::ADD] = array('name' => ts('Record Refund'), 'url' => 'civicrm/payment', 'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&action=add&component=event', 'title' => ts('Record Refund'));
         }
         $row['action'] = CRM_Core_Action::formLink($links, $mask, array('id' => $result->participant_id, 'cid' => $result->contact_id, 'cxt' => $this->_context), ts('more'), FALSE, 'participant.selector.row', 'Participant', $result->participant_id);
         $row['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type, FALSE, $result->contact_id);
         $row['paid'] = CRM_Event_BAO_Event::isMonetary($row['event_id']);
         if (!empty($row['participant_fee_level'])) {
             CRM_Event_BAO_Participant::fixEventLevel($row['participant_fee_level']);
         }
         if (CRM_Event_BAO_Event::usesPriceSet($row['event_id'])) {
             // add line item details if applicable
             $lineItems[$row['participant_id']] = CRM_Price_BAO_LineItem::getLineItems($row['participant_id']);
         }
         if (!empty($row['participant_role_id'])) {
             $viewRoles = array();
             foreach (explode($sep, $row['participant_role_id']) as $k => $v) {
                 $viewRoles[] = $participantRoles[$v];
             }
             $row['participant_role_id'] = implode(', ', $viewRoles);
         }
         $rows[] = $row;
     }
     CRM_Core_Selector_Controller::$_template->assign_by_ref('lineItems', $lineItems);
     return $rows;
 }
Exemple #3
0
 /**
  * Retrieve cases related to particular contact or whole contact
  * used in Dashboad and Tab
  *
  * @param boolean $allCases
  *
  * @param int $userID
  *
  * @param String $type /upcoming,recent,all/
  *
  * @param string $context
  *
  * @return array     Array of Cases
  *
  * @access public
  */
 static function getCases($allCases = TRUE, $userID = NULL, $type = 'upcoming', $context = 'dashboard')
 {
     $condition = NULL;
     $casesList = array();
     //validate access for own cases.
     if (!self::accessCiviCase()) {
         return $casesList;
     }
     if (!$userID) {
         $session = CRM_Core_Session::singleton();
         $userID = $session->get('userID');
     }
     //validate access for all cases.
     if ($allCases && !CRM_Core_Permission::check('access all cases and activities')) {
         $allCases = FALSE;
     }
     $condition = " AND civicrm_case.is_deleted = 0 ";
     if (!$allCases) {
         $condition .= " AND case_relationship.contact_id_b = {$userID} ";
     }
     if ($type == 'upcoming' || $type == 'any') {
         $closedId = CRM_Core_OptionGroup::getValue('case_status', 'Closed', 'name');
         $condition .= "\nAND civicrm_case.status_id != {$closedId}";
     }
     $query = self::getCaseActivityQuery($type, $userID, $condition);
     $queryParams = array();
     $result = CRM_Core_DAO::executeQuery($query, $queryParams);
     $caseStatus = CRM_Core_OptionGroup::values('case_status', FALSE, FALSE, FALSE, " AND v.name = 'Urgent' ");
     $resultFields = array('contact_id', 'contact_type', 'sort_name', 'phone', 'case_id', 'case_subject', 'case_type', 'case_type_id', 'status_id', 'case_status', 'case_status_name', 'activity_type_id', 'case_start_date', 'case_role');
     if ($type == 'upcoming') {
         $resultFields[] = 'case_scheduled_activity_date';
         $resultFields[] = 'case_scheduled_activity_type_name';
         $resultFields[] = 'case_scheduled_activity_type';
         $resultFields[] = 'case_scheduled_activity_id';
     } elseif ($type == 'recent') {
         $resultFields[] = 'case_recent_activity_date';
         $resultFields[] = 'case_recent_activity_type_name';
         $resultFields[] = 'case_recent_activity_type';
         $resultFields[] = 'case_recent_activity_id';
     } elseif ($type == 'any') {
         $resultFields[] = 'case_activity_date';
         $resultFields[] = 'case_activity_type_name';
         $resultFields[] = 'case_activity_type';
         $resultFields[] = 'case_activity_id';
     }
     // we're going to use the usual actions, so doesn't make sense to duplicate definitions
     $actions = CRM_Case_Selector_Search::links();
     // check is the user has view/edit signer permission
     $permissions = array(CRM_Core_Permission::VIEW);
     if (CRM_Core_Permission::check('access all cases and activities') || !$allCases && CRM_Core_Permission::check('access my cases and activities')) {
         $permissions[] = CRM_Core_Permission::EDIT;
     }
     if (CRM_Core_Permission::check('delete in CiviCase')) {
         $permissions[] = CRM_Core_Permission::DELETE;
     }
     $mask = CRM_Core_Action::mask($permissions);
     while ($result->fetch()) {
         foreach ($resultFields as $donCare => $field) {
             $casesList[$result->case_id][$field] = $result->{$field};
             if ($field == 'contact_type') {
                 $casesList[$result->case_id]['contact_type_icon'] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type);
                 $casesList[$result->case_id]['action'] = CRM_Core_Action::formLink($actions['primaryActions'], $mask, array('id' => $result->case_id, 'cid' => $result->contact_id, 'cxt' => $context), ts('more'), FALSE, 'case.actions.primary', 'Case', $result->case_id);
                 $casesList[$result->case_id]['moreActions'] = CRM_Core_Action::formLink($actions['moreActions'], $mask, array('id' => $result->case_id, 'cid' => $result->contact_id, 'cxt' => $context), ts('more'), TRUE, 'case.actions.more', 'Case', $result->case_id);
             } elseif ($field == 'case_status') {
                 if (in_array($result->{$field}, $caseStatus)) {
                     $casesList[$result->case_id]['class'] = "status-urgent";
                 } else {
                     $casesList[$result->case_id]['class'] = "status-normal";
                 }
             }
         }
         //CRM-4510.
         $caseTypes = CRM_Case_PseudoConstant::caseType('name');
         $caseManagerContact = self::getCaseManagerContact($caseTypes[$result->case_type_id], $result->case_id);
         if (!empty($caseManagerContact)) {
             $casesList[$result->case_id]['casemanager_id'] = CRM_Utils_Array::value('casemanager_id', $caseManagerContact);
             $casesList[$result->case_id]['casemanager'] = CRM_Utils_Array::value('casemanager', $caseManagerContact);
         }
         //do check user permissions for edit/view activity.
         if (($actId = CRM_Utils_Array::value('case_scheduled_activity_id', $casesList[$result->case_id])) || ($actId = CRM_Utils_Array::value('case_recent_activity_id', $casesList[$result->case_id]))) {
             $casesList[$result->case_id]["case_{$type}_activity_editable"] = self::checkPermission($actId, 'edit', $casesList[$result->case_id]['activity_type_id'], $userID);
             $casesList[$result->case_id]["case_{$type}_activity_viewable"] = self::checkPermission($actId, 'view', $casesList[$result->case_id]['activity_type_id'], $userID);
         }
     }
     return $casesList;
 }
 /**
  * Wrapper for contact relationship selector.
  *
  * @param array $params
  *   Associated array for params record id.
  *
  * @return array
  *   associated array of contact relationships
  */
 public static function getContactRelationshipSelector(&$params)
 {
     // format the params
     $params['offset'] = ($params['page'] - 1) * $params['rp'];
     $params['sort'] = CRM_Utils_Array::value('sortBy', $params);
     if ($params['context'] == 'past') {
         $relationshipStatus = CRM_Contact_BAO_Relationship::INACTIVE;
     } elseif ($params['context'] == 'all') {
         $relationshipStatus = CRM_Contact_BAO_Relationship::ALL;
     } else {
         $relationshipStatus = CRM_Contact_BAO_Relationship::CURRENT;
     }
     // check logged in user for permission
     $page = new CRM_Core_Page();
     CRM_Contact_Page_View::checkUserPermission($page, $params['contact_id']);
     $permissions = array($page->_permission);
     if ($page->_permission == CRM_Core_Permission::EDIT) {
         $permissions[] = CRM_Core_Permission::DELETE;
     }
     $mask = CRM_Core_Action::mask($permissions);
     $permissionedContacts = TRUE;
     if ($params['context'] != 'user') {
         $links = CRM_Contact_Page_View_Relationship::links();
     } else {
         $links = CRM_Contact_Page_View_UserDashBoard::links();
         $mask = NULL;
     }
     // get contact relationships
     $relationships = CRM_Contact_BAO_Relationship::getRelationship($params['contact_id'], $relationshipStatus, $params['rp'], 0, 0, $links, $mask, $permissionedContacts, $params);
     $contactRelationships = array();
     $params['total'] = 0;
     if (!empty($relationships)) {
         // FIXME: we cannot directly determine total permissioned relationship, hence re-fire query
         $permissionedRelationships = CRM_Contact_BAO_Relationship::getRelationship($params['contact_id'], $relationshipStatus, 0, 0, 0, NULL, NULL, $permissionedContacts);
         $params['total'] = count($permissionedRelationships);
         // format params
         foreach ($relationships as $relationshipId => $values) {
             $relationship = array();
             $relationship['DT_RowId'] = $values['id'];
             $relationship['DT_RowClass'] = 'crm-entity';
             if ($values['is_active'] == 0) {
                 $relationship['DT_RowClass'] .= ' disabled';
             }
             $relationship['DT_RowAttr'] = array();
             $relationship['DT_RowAttr']['data-entity'] = 'relationship';
             $relationship['DT_RowAttr']['data-id'] = $values['id'];
             //Add image icon for related contacts: CRM-14919
             $icon = CRM_Contact_BAO_Contact_Utils::getImage($values['contact_type'], FALSE, $values['cid']);
             $relationship['sort_name'] = $icon . ' ' . CRM_Utils_System::href($values['name'], 'civicrm/contact/view', "reset=1&cid={$values['cid']}");
             $relationship['relation'] = CRM_Utils_System::href($values['relation'], 'civicrm/contact/view/rel', "action=view&reset=1&cid={$values['cid']}&id={$values['id']}&rtype={$values['rtype']}");
             if ($params['context'] == 'current') {
                 if ($params['contact_id'] == $values['contact_id_a'] and $values['is_permission_a_b'] == 1 or $params['contact_id'] == $values['contact_id_b'] and $values['is_permission_b_a'] == 1) {
                     $relationship['sort_name'] .= '<span id="permission-a-b" class="crm-marker permission-relationship"> *</span>';
                 }
                 if ($values['cid'] == $values['contact_id_a'] and $values['is_permission_a_b'] == 1 or $values['cid'] == $values['contact_id_b'] and $values['is_permission_b_a'] == 1) {
                     $relationship['relation'] .= '<span id="permission-b-a" class="crm-marker permission-relationship"> *</span>';
                 }
             }
             if (!empty($values['description'])) {
                 $relationship['relation'] .= "<p class='description'>{$values['description']}</p>";
             }
             $relationship['start_date'] = CRM_Utils_Date::customFormat($values['start_date']);
             $relationship['end_date'] = CRM_Utils_Date::customFormat($values['end_date']);
             $relationship['city'] = $values['city'];
             $relationship['state'] = $values['state'];
             $relationship['email'] = $values['email'];
             $relationship['phone'] = $values['phone'];
             $relationship['links'] = $values['action'];
             array_push($contactRelationships, $relationship);
         }
     }
     $relationshipsDT = array();
     $relationshipsDT['data'] = $contactRelationships;
     $relationshipsDT['recordsTotal'] = $params['total'];
     $relationshipsDT['recordsFiltered'] = $params['total'];
     return $relationshipsDT;
 }
 /**
  * Test case for getDisplayAndImage( ).
  */
 public function testGetDisplayAndImage()
 {
     //get the contact params
     $params = $this->contactParams();
     //create contact
     $contact = CRM_Contact_BAO_Contact::create($params);
     $contactId = $contact->id;
     //get DisplayAndImage.
     list($displayName, $image) = CRM_Contact_BAO_Contact::getDisplayAndImage($contactId);
     $checkImage = CRM_Contact_BAO_Contact_Utils::getImage($params['contact_type'], FALSE, $contactId);
     $prefix = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'prefix_id');
     $suffix = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'suffix_id');
     //build display name
     $paramsDisplayName = $prefix[$params['prefix_id']] . ' ' . $params['first_name'] . ' ' . $params['last_name'] . ' ' . $suffix[$params['suffix_id']];
     $this->assertEquals($displayName, $paramsDisplayName, 'Check For Display Name');
     $this->assertEquals($image, $checkImage, 'Check For Image');
     //cleanup DB by deleting the contact
     $this->contactDelete($contactId);
 }
Exemple #6
0
 /**
  * returns all the rows in the given offset and rowCount
  *
  * @param enum   $action   the action being performed
  * @param int    $offset   the row number to start from
  * @param int    $rowCount the number of rows to return
  * @param string $sort     the sql string that describes the sort order
  * @param enum   $output   what should the result set include (web/email/csv)
  *
  * @return int   the total number of rows for this action
  */
 function &getRows($action, $offset, $rowCount, $sort, $output = null)
 {
     $result = $this->_query->searchQuery($offset, $rowCount, $sort, false, false, false, false, false, $this->_contributionClause);
     // process the result of the query
     $rows = array();
     require_once 'CRM/Event/BAO/Participant.php';
     require_once 'CRM/Contact/BAO/Contact/Utils.php';
     //CRM-4418 check for view/edit/delete
     $permissions = array(CRM_Core_Permission::VIEW);
     if (CRM_Core_Permission::check('edit contributions')) {
         $permissions[] = CRM_Core_Permission::EDIT;
     }
     if (CRM_Core_Permission::check('delete in CiviContribute')) {
         $permissions[] = CRM_Core_Permission::DELETE;
     }
     $mask = CRM_Core_Action::mask($permissions);
     $qfKey = $this->_key;
     $componentId = $componentContext = null;
     if ($this->_context != 'contribute') {
         $qfKey = CRM_Utils_Request::retrieve('key', 'String', CRM_Core_DAO::$_nullObject);
         $componentId = CRM_Utils_Request::retrieve('id', 'Positive', CRM_Core_DAO::$_nullObject);
         $componentAction = CRM_Utils_Request::retrieve('action', 'String', CRM_Core_DAO::$_nullObject);
         $componentContext = CRM_Utils_Request::retrieve('compContext', 'String', CRM_Core_DAO::$_nullObject);
         if (!$componentContext && $this->_compContext) {
             $componentContext = $this->_compContext;
             $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', CRM_Core_DAO::$_nullObject, null, false, 'REQUEST');
         }
     }
     // get all contribution status
     $contributionStatuses = CRM_Core_OptionGroup::values('contribution_status', false, false, false, null, 'name', false);
     while ($result->fetch()) {
         $row = array();
         // the columns we are interested in
         foreach (self::$_properties as $property) {
             if (property_exists($result, $property)) {
                 $row[$property] = $result->{$property};
             }
         }
         // add contribution status name
         $row['contribution_status_name'] = CRM_Utils_Array::value($row['contribution_status_id'], $contributionStatuses);
         if ($result->is_pay_later && CRM_Utils_Array::value('contribution_status_name', $row) == 'Pending') {
             $row['contribution_status'] .= ' (Pay Later)';
         } else {
             if (CRM_Utils_Array::value('contribution_status_name', $row) == 'Pending') {
                 $row['contribution_status'] .= ' (Incomplete Transaction)';
             }
         }
         if ($row['is_test']) {
             $row['contribution_type'] = $row['contribution_type'] . ' (test)';
         }
         $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $result->contribution_id;
         $actions = array('id' => $result->contribution_id, 'cid' => $result->contact_id, 'cxt' => $this->_context);
         $row['action'] = CRM_Core_Action::formLink(self::links($componentId, $componentAction, $qfKey, $componentContext), $mask, $actions);
         $row['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type, false, $result->contact_id);
         if (CRM_Utils_Array::value('amount_level', $row)) {
             CRM_Event_BAO_Participant::fixEventLevel($row['amount_level']);
         }
         $rows[] = $row;
     }
     return $rows;
 }
 /**
  * Get the information to map a contact.
  *
  * @param array $ids
  *   The list of ids for which we want map info.
  * $param  int    $locationTypeID
  *
  * @param int $locationTypeID
  * @param bool $imageUrlOnly
  *
  * @return null|string
  *   display name of the contact if found
  */
 public static function &getMapInfo($ids, $locationTypeID = NULL, $imageUrlOnly = FALSE)
 {
     $idString = ' ( ' . implode(',', $ids) . ' ) ';
     $sql = "\n   SELECT civicrm_contact.id as contact_id,\n          civicrm_contact.contact_type as contact_type,\n          civicrm_contact.contact_sub_type as contact_sub_type,\n          civicrm_contact.display_name as display_name,\n          civicrm_address.street_address as street_address,\n          civicrm_address.supplemental_address_1 as supplemental_address_1,\n          civicrm_address.supplemental_address_2 as supplemental_address_2,\n          civicrm_address.city as city,\n          civicrm_address.postal_code as postal_code,\n          civicrm_address.postal_code_suffix as postal_code_suffix,\n          civicrm_address.geo_code_1 as latitude,\n          civicrm_address.geo_code_2 as longitude,\n          civicrm_state_province.abbreviation as state,\n          civicrm_country.name as country,\n          civicrm_location_type.name as location_type\n     FROM civicrm_contact\nLEFT JOIN civicrm_address ON civicrm_address.contact_id = civicrm_contact.id\nLEFT JOIN civicrm_state_province ON civicrm_address.state_province_id = civicrm_state_province.id\nLEFT JOIN civicrm_country ON civicrm_address.country_id = civicrm_country.id\nLEFT JOIN civicrm_location_type ON civicrm_location_type.id = civicrm_address.location_type_id\nWHERE civicrm_address.geo_code_1 IS NOT NULL\nAND civicrm_address.geo_code_2 IS NOT NULL\nAND civicrm_contact.id IN {$idString} ";
     $params = array();
     if (!$locationTypeID) {
         $sql .= " AND civicrm_address.is_primary = 1";
     } else {
         $sql .= " AND civicrm_address.location_type_id = %1";
         $params[1] = array($locationTypeID, 'Integer');
     }
     $dao = CRM_Core_DAO::executeQuery($sql, $params);
     $locations = array();
     $config = CRM_Core_Config::singleton();
     while ($dao->fetch()) {
         $location = array();
         $location['contactID'] = $dao->contact_id;
         $location['displayName'] = addslashes($dao->display_name);
         $location['city'] = $dao->city;
         $location['state'] = $dao->state;
         $location['postal_code'] = $dao->postal_code;
         $location['lat'] = $dao->latitude;
         $location['lng'] = $dao->longitude;
         $location['marker_class'] = $dao->contact_type;
         $address = '';
         CRM_Utils_String::append($address, '<br />', array($dao->street_address, $dao->supplemental_address_1, $dao->supplemental_address_2, $dao->city));
         CRM_Utils_String::append($address, ', ', array($dao->state, $dao->postal_code));
         CRM_Utils_String::append($address, '<br /> ', array($dao->country));
         $location['address'] = addslashes($address);
         $location['displayAddress'] = str_replace('<br />', ', ', addslashes($address));
         $location['url'] = CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $dao->contact_id);
         $location['location_type'] = $dao->location_type;
         $location['image'] = CRM_Contact_BAO_Contact_Utils::getImage(isset($dao->contact_sub_type) ? $dao->contact_sub_type : $dao->contact_type, $imageUrlOnly, $dao->contact_id);
         $locations[] = $location;
     }
     return $locations;
 }
Exemple #8
0
 public function voterList()
 {
     //get the search criteria params.
     $searchCriteria = CRM_Utils_Request::retrieve('searchCriteria', 'String', CRM_Core_DAO::$_nullObject, FALSE, NULL, 'POST');
     $searchParams = explode(',', $searchCriteria);
     $params = $searchRows = array();
     foreach ($searchParams as $param) {
         if (!empty($_POST[$param])) {
             $params[$param] = $_POST[$param];
         }
     }
     //format multi-select group and contact types.
     foreach (array('group', 'contact_type') as $param) {
         $paramValue = CRM_Utils_Array::value($param, $params);
         if ($paramValue) {
             unset($params[$param]);
             $paramValue = explode(',', $paramValue);
             foreach ($paramValue as $key => $value) {
                 $params[$param][$value] = 1;
             }
         }
     }
     $voterClauseParams = array();
     foreach (array('campaign_survey_id', 'survey_interviewer_id', 'campaign_search_voter_for') as $fld) {
         $voterClauseParams[$fld] = CRM_Utils_Array::value($fld, $params);
     }
     $interviewerId = $surveyTypeId = $surveyId = NULL;
     $searchVoterFor = $params['campaign_search_voter_for'];
     if ($searchVoterFor == 'reserve') {
         if (!empty($params['campaign_survey_id'])) {
             $survey = new CRM_Campaign_DAO_Survey();
             $survey->id = $surveyId = $params['campaign_survey_id'];
             $survey->selectAdd('campaign_id, activity_type_id');
             $survey->find(TRUE);
             $campaignId = $survey->campaign_id;
             $surveyTypeId = $survey->activity_type_id;
             //allow voter search in sub-part of given constituents,
             //but make sure in case user does not select any group.
             //get all associated campaign groups in where filter, CRM-7406
             $groups = CRM_Utils_Array::value('group', $params);
             if ($campaignId && CRM_Utils_System::isNull($groups)) {
                 $campaignGroups = CRM_Campaign_BAO_Campaign::getCampaignGroups($campaignId);
                 foreach ($campaignGroups as $id => $group) {
                     $params['group'][$id] = 1;
                 }
             }
             //apply filter of survey contact type for search.
             $contactType = CRM_Campaign_BAO_Survey::getSurveyContactType($surveyId);
             if ($contactType) {
                 $params['contact_type'][$contactType] = 1;
             }
             unset($params['campaign_survey_id']);
         }
         unset($params['survey_interviewer_id']);
     } else {
         //get the survey status in where clause.
         $scheduledStatusId = array_search('Scheduled', CRM_Core_PseudoConstant::activityStatus('name'));
         if ($scheduledStatusId) {
             $params['survey_status_id'] = $scheduledStatusId;
         }
         //BAO/Query knows reserve/release/interview processes.
         if ($params['campaign_search_voter_for'] == 'gotv') {
             $params['campaign_search_voter_for'] = 'release';
         }
     }
     $selectorCols = array('sort_name', 'street_address', 'street_name', 'street_number', 'street_unit');
     // get the data table params.
     $dataTableParams = array('sEcho' => array('name' => 'sEcho', 'type' => 'Integer', 'default' => 0), 'offset' => array('name' => 'iDisplayStart', 'type' => 'Integer', 'default' => 0), 'rowCount' => array('name' => 'iDisplayLength', 'type' => 'Integer', 'default' => 25), 'sort' => array('name' => 'iSortCol_0', 'type' => 'Integer', 'default' => 'sort_name'), 'sortOrder' => array('name' => 'sSortDir_0', 'type' => 'String', 'default' => 'asc'));
     foreach ($dataTableParams as $pName => $pValues) {
         ${$pName} = $pValues['default'];
         if (!empty($_POST[$pValues['name']])) {
             ${$pName} = CRM_Utils_Type::escape($_POST[$pValues['name']], $pValues['type']);
             if ($pName == 'sort') {
                 ${$pName} = $selectorCols[${$pName}];
             }
         }
     }
     $queryParams = CRM_Contact_BAO_Query::convertFormValues($params);
     $query = new CRM_Contact_BAO_Query($queryParams, NULL, NULL, FALSE, FALSE, CRM_Contact_BAO_Query::MODE_CAMPAIGN, TRUE);
     //get the voter clause to restrict and validate search.
     $voterClause = CRM_Campaign_BAO_Query::voterClause($voterClauseParams);
     $searchCount = $query->searchQuery(0, 0, NULL, TRUE, FALSE, FALSE, FALSE, FALSE, CRM_Utils_Array::value('whereClause', $voterClause), NULL, CRM_Utils_Array::value('fromClause', $voterClause));
     $iTotal = $searchCount;
     $selectorCols = array('contact_type', 'sort_name', 'street_address', 'street_name', 'street_number', 'street_unit');
     $extraVoterColName = 'is_interview_conducted';
     if ($params['campaign_search_voter_for'] == 'reserve') {
         $extraVoterColName = 'reserve_voter';
     }
     if ($searchCount > 0) {
         if ($searchCount < $offset) {
             $offset = 0;
         }
         $config = CRM_Core_Config::singleton();
         // get the result of the search
         $result = $query->searchQuery($offset, $rowCount, $sort, FALSE, FALSE, FALSE, FALSE, FALSE, CRM_Utils_Array::value('whereClause', $voterClause), $sortOrder, CRM_Utils_Array::value('fromClause', $voterClause));
         while ($result->fetch()) {
             $contactID = $result->contact_id;
             $typeImage = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type, FALSE, $result->contact_id);
             $searchRows[$contactID] = array('id' => $contactID);
             foreach ($selectorCols as $col) {
                 $val = $result->{$col};
                 if ($col == 'contact_type') {
                     $val = $typeImage;
                 }
                 $searchRows[$contactID][$col] = $val;
             }
             if ($searchVoterFor == 'reserve') {
                 $voterExtraColHtml = '<input type="checkbox" id="survey_activity[' . $contactID . ']" name="survey_activity[' . $contactID . ']" value=' . $contactID . ' onClick="processVoterData( this, \'reserve\' );" />';
                 $msg = ts('Respondent Reserved.');
                 $voterExtraColHtml .= "&nbsp;<span id='success_msg_{$contactID}' class='ok' style='display:none;'>{$msg}</span>";
             } elseif ($searchVoterFor == 'gotv') {
                 $surveyActId = $result->survey_activity_id;
                 $voterExtraColHtml = '<input type="checkbox" id="survey_activity[' . $surveyActId . ']" name="survey_activity[' . $surveyActId . ']" value=' . $surveyActId . ' onClick="processVoterData( this, \'gotv\' );" />';
                 $msg = ts('Vote Recorded.');
                 $voterExtraColHtml .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span id='success_msg_{$surveyActId}' class='ok' style='display:none;'>{$msg}</span>";
             } else {
                 $surveyActId = $result->survey_activity_id;
                 $voterExtraColHtml = '<input type="checkbox" id="survey_activity[' . $surveyActId . ']" name="survey_activity[' . $surveyActId . ']" value=' . $surveyActId . ' onClick="processVoterData( this, \'release\' );" />';
                 $msg = ts('Vote Recorded.');
                 $voterExtraColHtml .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span id='success_msg_{$surveyActId}' class='ok' style='display:none;'>{$msg}</span>";
             }
             $searchRows[$contactID][$extraVoterColName] = $voterExtraColHtml;
         }
     }
     $selectorElements = array_merge($selectorCols, array($extraVoterColName));
     $iFilteredTotal = $iTotal;
     CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
     echo CRM_Utils_JSON::encodeDataTableSelector($searchRows, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
     CRM_Utils_System::civiExit();
 }
 /**
  * returns all the rows in the given offset and rowCount
  *
  * @param enum   $action   the action being performed
  * @param int    $offset   the row number to start from
  * @param int    $rowCount the number of rows to return
  * @param string $sort     the sql string that describes the sort order
  * @param enum   $output   what should the result set include (web/email/csv)
  *
  * @return int   the total number of rows for this action
  */
 function &getRows($action, $offset, $rowCount, $sort, $output = NULL)
 {
     $multipleFields = array('url');
     //$sort object processing for location fields
     if ($sort) {
         $vars = $sort->_vars;
         $varArray = array();
         foreach ($vars as $key => $field) {
             $field = $vars[$key];
             $fieldArray = explode('-', $field['name']);
             $fieldType = CRM_Utils_Array::value('2', $fieldArray);
             if (is_numeric(CRM_Utils_Array::value('1', $fieldArray))) {
                 if (!in_array($fieldType, $multipleFields)) {
                     $locationType = new CRM_Core_DAO_LocationType();
                     $locationType->id = $fieldArray[1];
                     $locationType->find(TRUE);
                     if ($fieldArray[0] == 'email' || $fieldArray[0] == 'im' || $fieldArray[0] == 'phone') {
                         $field['name'] = "`" . $locationType->name . "-" . $fieldArray[0] . "-1`";
                     } else {
                         $field['name'] = "`" . $locationType->name . "-" . $fieldArray[0] . "`";
                     }
                 } else {
                     $field['name'] = "`website-" . $fieldArray[1] . "-{$fieldType}`";
                 }
             }
             $varArray[$key] = $field;
         }
         $sort->_vars = $varArray;
     }
     $additionalWhereClause = 'contact_a.is_deleted = 0';
     $returnQuery = NULL;
     if ($this->_multiRecordTableName) {
         $returnQuery = TRUE;
     }
     $result = $this->_query->searchQuery($offset, $rowCount, $sort, NULL, NULL, NULL, NULL, $returnQuery, $additionalWhereClause);
     if ($returnQuery) {
         $resQuery = preg_replace('/GROUP BY contact_a.id[\\s]+ORDER BY/', ' ORDER BY', $result);
         $result = CRM_Core_DAO::executeQuery($resQuery);
     }
     // process the result of the query
     $rows = array();
     // check if edit is configured in profile settings
     if ($this->_gid) {
         $editLink = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $this->_gid, 'is_edit_link');
     }
     //FIXME : make sure to handle delete separately. CRM-4418
     $mask = CRM_Core_Action::mask(array(CRM_Core_Permission::getPermission()));
     if ($editLink && $mask & CRM_Core_Permission::EDIT) {
         // do not allow edit for anon users in joomla frontend, CRM-4668
         $config = CRM_Core_Config::singleton();
         if (!$config->userFrameworkFrontend) {
             $this->_editLink = TRUE;
         }
     }
     $links = self::links($this->_map, $this->_editLink, $this->_linkToUF, $this->_profileIds);
     $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
     $names = array();
     static $skipFields = array('group', 'tag');
     foreach ($this->_fields as $key => $field) {
         // skip pseudo fields
         if (substr($key, 0, 9) == 'phone_ext') {
             continue;
         }
         if (!empty($field['in_selector']) && !in_array($key, $skipFields)) {
             if (strpos($key, '-') !== FALSE) {
                 $value = explode('-', $key);
                 $fieldName = CRM_Utils_Array::value(0, $value);
                 $id = CRM_Utils_Array::value(1, $value);
                 $type = CRM_Utils_Array::value(2, $value);
                 if (!in_array($fieldName, $multipleFields)) {
                     $locationTypeName = NULL;
                     if (is_numeric($id)) {
                         $locationTypeName = CRM_Utils_Array::value($id, $locationTypes);
                     } else {
                         if ($id == 'Primary') {
                             $locationTypeName = 1;
                         }
                     }
                     if (!$locationTypeName) {
                         continue;
                     }
                     $locationTypeName = str_replace(' ', '_', $locationTypeName);
                     if (in_array($fieldName, array('phone', 'im', 'email'))) {
                         if ($type) {
                             $names[] = "{$locationTypeName}-{$fieldName}-{$type}";
                         } else {
                             $names[] = "{$locationTypeName}-{$fieldName}";
                         }
                     } else {
                         $names[] = "{$locationTypeName}-{$fieldName}";
                     }
                 } else {
                     $names[] = "website-{$id}-{$fieldName}";
                 }
             } elseif ($field['name'] == 'id') {
                 $names[] = 'contact_id';
             } else {
                 $names[] = $field['name'];
             }
         }
     }
     $multipleSelectFields = array('preferred_communication_method' => 1);
     $multiRecordTableId = NULL;
     if ($this->_multiRecordTableName) {
         $multiRecordTableId = "{$this->_multiRecordTableName}_id";
     }
     // we need to determine of overlay profile should be shown
     $showProfileOverlay = CRM_Core_BAO_UFGroup::showOverlayProfile();
     while ($result->fetch()) {
         $this->_query->convertToPseudoNames($result);
         if (isset($result->country)) {
             // the query returns the untranslated country name
             $i18n = CRM_Core_I18n::singleton();
             $result->country = $i18n->translate($result->country);
         }
         $row = array();
         $empty = TRUE;
         $row[] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type, FALSE, $result->contact_id, $showProfileOverlay);
         if ($result->sort_name) {
             $row[] = $result->sort_name;
             $empty = FALSE;
         } else {
             continue;
         }
         foreach ($names as $name) {
             if ($cfID = CRM_Core_BAO_CustomField::getKeyID($name)) {
                 $row[] = CRM_Core_BAO_CustomField::getDisplayValue($result->{$name}, $cfID, $this->_options, $result->contact_id);
             } elseif (substr($name, -4) == '-url' && !empty($result->{$name})) {
                 $url = CRM_Utils_System::fixURL($result->{$name});
                 $typeId = substr($name, 0, -4) . "-website_type_id";
                 $typeName = CRM_Core_PseudoConstant::getLabel('CRM_Core_DAO_Website', 'website_type_id', $result->{$typeId});
                 if ($typeName) {
                     $row[] = "<a href=\"{$url}\">{$result->{$name}} ({$typeName})</a>";
                 } else {
                     $row[] = "<a href=\"{$url}\">{$result->{$name}}</a>";
                 }
             } elseif ($name == 'preferred_language') {
                 $row[] = CRM_Core_PseudoConstant::getLabel('CRM_Contact_DAO_Contact', 'preferred_language', $result->{$name});
             } elseif ($multipleSelectFields && array_key_exists($name, $multipleSelectFields)) {
                 $paramsNew = array($name => $result->{$name});
                 $name = array($name => array('newName' => $name, 'groupName' => $name));
                 CRM_Core_OptionGroup::lookupValues($paramsNew, $name, FALSE);
                 $row[] = $paramsNew[$key];
             } elseif (strpos($name, '-im')) {
                 if (!empty($result->{$name})) {
                     $providerId = $name . "-provider_id";
                     $providerName = CRM_Core_PseudoConstant::getLabel('CRM_Core_DAO_IM', 'provider_id', $result->{$providerId});
                     $row[] = $result->{$name} . " ({$providerName})";
                 } else {
                     $row[] = '';
                 }
             } elseif (strpos($name, '-phone-')) {
                 $phoneExtField = str_replace('phone', 'phone_ext', $name);
                 if (isset($result->{$phoneExtField})) {
                     $row[] = $result->{$name} . " (" . $result->{$phoneExtField} . ")";
                 } else {
                     $row[] = $result->{$name};
                 }
             } elseif (in_array($name, array('addressee', 'email_greeting', 'postal_greeting'))) {
                 $dname = $name . '_display';
                 $row[] = $result->{$dname};
             } elseif (in_array($name, array('birth_date', 'deceased_date'))) {
                 $row[] = CRM_Utils_Date::customFormat($result->{$name});
             } elseif (isset($result->{$name})) {
                 $row[] = $result->{$name};
             } else {
                 $row[] = '';
             }
             if (!empty($result->{$name})) {
                 $empty = FALSE;
             }
         }
         $newLinks = $links;
         $params = array('id' => $result->contact_id, 'gid' => implode(',', $this->_profileIds));
         // pass record id param to view url for multi record view
         if ($multiRecordTableId && $newLinks) {
             if ($result->{$multiRecordTableId}) {
                 if ($newLinks[CRM_Core_Action::VIEW]['url'] == 'civicrm/profile/view') {
                     $newLinks[CRM_Core_Action::VIEW]['qs'] .= "&multiRecord=view&recordId=%%recordId%%&allFields=1";
                     $params['recordId'] = $result->{$multiRecordTableId};
                 }
             }
         }
         if ($this->_linkToUF) {
             $ufID = CRM_Core_BAO_UFMatch::getUFId($result->contact_id);
             if (!$ufID) {
                 unset($newLinks[CRM_Core_Action::PROFILE]);
             } else {
                 $params['ufID'] = $ufID;
             }
         }
         $row[] = CRM_Core_Action::formLink($newLinks, $mask, $params, ts('more'), FALSE, 'profile.selector.row', 'Contact', $result->contact_id);
         if (!$empty) {
             $rows[] = $row;
         }
     }
     return $rows;
 }
Exemple #10
0
 /**
  * Returns all the rows in the given offset and rowCount.
  *
  * @param string $action
  *   The action being performed.
  * @param int $offset
  *   The row number to start from.
  * @param int $rowCount
  *   The number of rows to return.
  * @param string $sort
  *   The sql string that describes the sort order.
  * @param string $output
  *   What should the result set include (web/email/csv).
  *
  * @return int
  *   the total number of rows for this action
  */
 public function &getRows($action, $offset, $rowCount, $sort, $output = NULL)
 {
     if ($this->_includeSoftCredits) {
         // especial sort order when rows include soft credits
         $sort = "civicrm_contribution.receive_date DESC, civicrm_contribution.id, civicrm_contribution_soft.id";
     }
     $result = $this->_query->searchQuery($offset, $rowCount, $sort, FALSE, FALSE, FALSE, FALSE, FALSE, $this->_contributionClause);
     // process the result of the query
     $rows = array();
     //CRM-4418 check for view/edit/delete
     $permissions = array(CRM_Core_Permission::VIEW);
     if (CRM_Core_Permission::check('edit contributions')) {
         $permissions[] = CRM_Core_Permission::EDIT;
     }
     if (CRM_Core_Permission::check('delete in CiviContribute')) {
         $permissions[] = CRM_Core_Permission::DELETE;
     }
     $mask = CRM_Core_Action::mask($permissions);
     $qfKey = $this->_key;
     $componentId = $componentContext = NULL;
     if ($this->_context != 'contribute') {
         $qfKey = CRM_Utils_Request::retrieve('key', 'String', CRM_Core_DAO::$_nullObject);
         $componentId = CRM_Utils_Request::retrieve('id', 'Positive', CRM_Core_DAO::$_nullObject);
         $componentAction = CRM_Utils_Request::retrieve('action', 'String', CRM_Core_DAO::$_nullObject);
         $componentContext = CRM_Utils_Request::retrieve('compContext', 'String', CRM_Core_DAO::$_nullObject);
         if (!$componentContext && $this->_compContext) {
             $componentContext = $this->_compContext;
             $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', CRM_Core_DAO::$_nullObject, NULL, FALSE, 'REQUEST');
         }
     }
     // get all contribution status
     $contributionStatuses = CRM_Core_OptionGroup::values('contribution_status', FALSE, FALSE, FALSE, NULL, 'name', FALSE);
     //get all campaigns.
     $allCampaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
     while ($result->fetch()) {
         $links = self::links($componentId, $componentAction, $qfKey, $componentContext);
         $checkLineItem = FALSE;
         $row = array();
         // Now check for lineItems
         if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()) {
             $lineItems = CRM_Price_BAO_LineItem::getLineItemsByContributionID($result->id);
             foreach ($lineItems as $items) {
                 if (!CRM_Core_Permission::check('view contributions of type ' . CRM_Contribute_PseudoConstant::financialType($items['financial_type_id']))) {
                     $checkLineItem = TRUE;
                     break;
                 }
                 if (!CRM_Core_Permission::check('edit contributions of type ' . CRM_Contribute_PseudoConstant::financialType($items['financial_type_id']))) {
                     unset($links[CRM_Core_Action::UPDATE]);
                 }
                 if (!CRM_Core_Permission::check('delete contributions of type ' . CRM_Contribute_PseudoConstant::financialType($items['financial_type_id']))) {
                     unset($links[CRM_Core_Action::DELETE]);
                 }
             }
             if ($checkLineItem) {
                 continue;
             }
             if (!CRM_Core_Permission::check('edit contributions of type ' . CRM_Contribute_PseudoConstant::financialType($result->financial_type_id))) {
                 unset($links[CRM_Core_Action::UPDATE]);
             }
             if (!CRM_Core_Permission::check('delete contributions of type ' . CRM_Contribute_PseudoConstant::financialType($result->financial_type_id))) {
                 unset($links[CRM_Core_Action::DELETE]);
             }
         }
         // the columns we are interested in
         foreach (self::$_properties as $property) {
             if (property_exists($result, $property)) {
                 $row[$property] = $result->{$property};
             }
         }
         //carry campaign on selectors.
         $row['campaign'] = CRM_Utils_Array::value($result->contribution_campaign_id, $allCampaigns);
         $row['campaign_id'] = $result->contribution_campaign_id;
         // add contribution status name
         $row['contribution_status_name'] = CRM_Utils_Array::value($row['contribution_status_id'], $contributionStatuses);
         if ($result->is_pay_later && CRM_Utils_Array::value('contribution_status_name', $row) == 'Pending') {
             $row['contribution_status'] .= ' (' . ts('Pay Later') . ')';
         } elseif (CRM_Utils_Array::value('contribution_status_name', $row) == 'Pending') {
             $row['contribution_status'] .= ' (' . ts('Incomplete Transaction') . ')';
         }
         if ($row['is_test']) {
             $row['financial_type'] = $row['financial_type'] . ' (' . ts('test') . ')';
         }
         $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $result->contribution_id;
         $actions = array('id' => $result->contribution_id, 'cid' => $result->contact_id, 'cxt' => $this->_context);
         $row['action'] = CRM_Core_Action::formLink($links, $mask, $actions, ts('more'), FALSE, 'contribution.selector.row', 'Contribution', $result->contribution_id);
         $row['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type, FALSE, $result->contact_id);
         if (!empty($row['amount_level'])) {
             CRM_Event_BAO_Participant::fixEventLevel($row['amount_level']);
         }
         $rows[] = $row;
     }
     return $rows;
 }
Exemple #11
0
 /**
  * Get output of financial transactions.
  *
  * @param bool $return
  *   Return result. This parameter allows the output to be unit tested.
  *
  * @return string
  */
 public static function getFinancialTransactionsList($return = FALSE)
 {
     $sortMapper = array(0 => '', 1 => '', 2 => 'sort_name', 3 => 'amount', 4 => 'trxn_id', 5 => 'transaction_date', 6 => 'payment_method', 7 => 'status', 8 => 'name');
     $sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer');
     $return = isset($_REQUEST['return']) ? CRM_Utils_Type::escape($_REQUEST['return'], 'Boolean') : FALSE;
     $offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0;
     $rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25;
     $sort = isset($_REQUEST['iSortCol_0']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_REQUEST['iSortCol_0'], 'Integer'), $sortMapper) : NULL;
     $sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc';
     $context = isset($_REQUEST['context']) ? CRM_Utils_Type::escape($_REQUEST['context'], 'String') : NULL;
     $entityID = isset($_REQUEST['entityID']) ? CRM_Utils_Type::escape($_REQUEST['entityID'], 'String') : NULL;
     $notPresent = isset($_REQUEST['notPresent']) ? CRM_Utils_Type::escape($_REQUEST['notPresent'], 'String') : NULL;
     $statusID = isset($_REQUEST['statusID']) ? CRM_Utils_Type::escape($_REQUEST['statusID'], 'String') : NULL;
     $search = isset($_REQUEST['search']) ? TRUE : FALSE;
     $params = $_POST;
     if ($sort && $sortOrder) {
         $params['sortBy'] = $sort . ' ' . $sortOrder;
     }
     $returnvalues = array('civicrm_financial_trxn.payment_instrument_id as payment_method', 'civicrm_contribution.contact_id as contact_id', 'civicrm_contribution.id as contributionID', 'contact_a.sort_name', 'civicrm_financial_trxn.total_amount as amount', 'civicrm_financial_trxn.trxn_id as trxn_id', 'contact_a.contact_type', 'contact_a.contact_sub_type', 'civicrm_financial_trxn.trxn_date as transaction_date', 'name', 'civicrm_contribution.currency as currency', 'civicrm_financial_trxn.status_id as status', 'civicrm_financial_trxn.check_number as check_number');
     $columnHeader = array('contact_type' => '', 'sort_name' => ts('Contact Name'), 'amount' => ts('Amount'), 'trxn_id' => ts('Trxn ID'), 'transaction_date' => ts('Received'), 'payment_method' => ts('Payment Method'), 'status' => ts('Status'), 'name' => ts('Type'));
     if ($sort && $sortOrder) {
         $params['sortBy'] = $sort . ' ' . $sortOrder;
     }
     $params['page'] = $offset / $rowCount + 1;
     $params['rp'] = $rowCount;
     $params['context'] = $context;
     $params['offset'] = ($params['page'] - 1) * $params['rp'];
     $params['rowCount'] = $params['rp'];
     $params['sort'] = CRM_Utils_Array::value('sortBy', $params);
     $params['total'] = 0;
     // get batch list
     if (isset($notPresent)) {
         $financialItem = CRM_Batch_BAO_Batch::getBatchFinancialItems($entityID, $returnvalues, $notPresent, $params);
         if ($search) {
             $unassignedTransactions = CRM_Batch_BAO_Batch::getBatchFinancialItems($entityID, $returnvalues, $notPresent, $params, TRUE);
         } else {
             $unassignedTransactions = CRM_Batch_BAO_Batch::getBatchFinancialItems($entityID, $returnvalues, $notPresent, NULL, TRUE);
         }
         while ($unassignedTransactions->fetch()) {
             $unassignedTransactionsCount[] = $unassignedTransactions->id;
         }
         if (!empty($unassignedTransactionsCount)) {
             $params['total'] = count($unassignedTransactionsCount);
         }
     } else {
         $financialItem = CRM_Batch_BAO_Batch::getBatchFinancialItems($entityID, $returnvalues, NULL, $params);
         $assignedTransactions = CRM_Batch_BAO_Batch::getBatchFinancialItems($entityID, $returnvalues);
         while ($assignedTransactions->fetch()) {
             $assignedTransactionsCount[] = $assignedTransactions->id;
         }
         if (!empty($assignedTransactionsCount)) {
             $params['total'] = count($assignedTransactionsCount);
         }
     }
     $financialitems = array();
     while ($financialItem->fetch()) {
         $row[$financialItem->id] = array();
         foreach ($columnHeader as $columnKey => $columnValue) {
             if ($financialItem->contact_sub_type && $columnKey == 'contact_type') {
                 $row[$financialItem->id][$columnKey] = $financialItem->contact_sub_type;
                 continue;
             }
             $row[$financialItem->id][$columnKey] = $financialItem->{$columnKey};
             if ($columnKey == 'sort_name' && $financialItem->{$columnKey}) {
                 $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid=" . $financialItem->contact_id);
                 $row[$financialItem->id][$columnKey] = '<a href=' . $url . '>' . $financialItem->{$columnKey} . '</a>';
             } elseif ($columnKey == 'payment_method' && $financialItem->{$columnKey}) {
                 $row[$financialItem->id][$columnKey] = CRM_Core_PseudoConstant::getLabel('CRM_Batch_BAO_Batch', 'payment_instrument_id', $financialItem->{$columnKey});
                 if ($row[$financialItem->id][$columnKey] == 'Check') {
                     $checkNumber = $financialItem->check_number ? ' (' . $financialItem->check_number . ')' : '';
                     $row[$financialItem->id][$columnKey] = $row[$financialItem->id][$columnKey] . $checkNumber;
                 }
             } elseif ($columnKey == 'amount' && $financialItem->{$columnKey}) {
                 $row[$financialItem->id][$columnKey] = CRM_Utils_Money::format($financialItem->{$columnKey}, $financialItem->currency);
             } elseif ($columnKey == 'transaction_date' && $financialItem->{$columnKey}) {
                 $row[$financialItem->id][$columnKey] = CRM_Utils_Date::customFormat($financialItem->{$columnKey});
             } elseif ($columnKey == 'status' && $financialItem->{$columnKey}) {
                 $row[$financialItem->id][$columnKey] = CRM_Core_PseudoConstant::getLabel('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $financialItem->{$columnKey});
             }
         }
         if ($statusID == CRM_Core_OptionGroup::getValue('batch_status', 'Open')) {
             if (isset($notPresent)) {
                 $js = "enableActions('x')";
                 $row[$financialItem->id]['check'] = "<input type='checkbox' id='mark_x_" . $financialItem->id . "' name='mark_x_" . $financialItem->id . "' value='1' onclick={$js}></input>";
                 $row[$financialItem->id]['action'] = CRM_Core_Action::formLink(CRM_Financial_Form_BatchTransaction::links(), NULL, array('id' => $financialItem->id, 'contid' => $financialItem->contributionID, 'cid' => $financialItem->contact_id), ts('more'), FALSE, 'financialItem.batch.row', 'FinancialItem', $financialItem->id);
             } else {
                 $js = "enableActions('y')";
                 $row[$financialItem->id]['check'] = "<input type='checkbox' id='mark_y_" . $financialItem->id . "' name='mark_y_" . $financialItem->id . "' value='1' onclick={$js}></input>";
                 $row[$financialItem->id]['action'] = CRM_Core_Action::formLink(CRM_Financial_Page_BatchTransaction::links(), NULL, array('id' => $financialItem->id, 'contid' => $financialItem->contributionID, 'cid' => $financialItem->contact_id), ts('more'), FALSE, 'financialItem.batch.row', 'FinancialItem', $financialItem->id);
             }
         } else {
             $row[$financialItem->id]['check'] = NULL;
             $tempBAO = new CRM_Financial_Page_BatchTransaction();
             $links = $tempBAO->links();
             unset($links['remove']);
             $row[$financialItem->id]['action'] = CRM_Core_Action::formLink($links, NULL, array('id' => $financialItem->id, 'contid' => $financialItem->contributionID, 'cid' => $financialItem->contact_id), ts('more'), FALSE, 'financialItem.batch.row', 'FinancialItem', $financialItem->id);
         }
         $row[$financialItem->id]['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage(CRM_Utils_Array::value('contact_sub_type', $row[$financialItem->id]) ? CRM_Utils_Array::value('contact_sub_type', $row[$financialItem->id]) : CRM_Utils_Array::value('contact_type', $row[$financialItem->id]), FALSE, $financialItem->contact_id);
         $financialitems = $row;
     }
     $iFilteredTotal = $iTotal = $params['total'];
     $selectorElements = array('check', 'contact_type', 'sort_name', 'amount', 'trxn_id', 'transaction_date', 'payment_method', 'status', 'name', 'action');
     if ($return) {
         return CRM_Utils_JSON::encodeDataTableSelector($financialitems, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
     }
     CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
     echo CRM_Utils_JSON::encodeDataTableSelector($financialitems, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
     CRM_Utils_System::civiExit();
 }
 static function relationshipContacts()
 {
     $data = $searchValues = $searchRows = array();
     $addCount = 0;
     $relType = CRM_Utils_Type::escape($_REQUEST['relType'], 'String');
     $typeName = isset($_REQUEST['typeName']) ? CRM_Utils_Type::escape($_REQUEST['typeName'], 'String') : '';
     $relContact = CRM_Utils_Type::escape($_REQUEST['relContact'], 'String');
     $currentContactId = CRM_Utils_Type::escape($_REQUEST['cid'], 'Integer');
     if (in_array($typeName, array('Employee of', 'Employer of'))) {
         $addCount = 1;
     }
     $sortMapper = array(1 => 'sort_name', 2 + $addCount => 'city', 3 + $addCount => 'state_province', 4 + $addCount => 'email', 5 + $addCount => 'phone');
     $sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer');
     $offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0;
     $rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25;
     $sort = isset($_REQUEST['iSortCol_0']) ? $sortMapper[CRM_Utils_Type::escape($_REQUEST['iSortCol_0'], 'Integer')] : 'sort_name';
     $sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc';
     $searchValues[] = array('sort_name', 'LIKE', $relContact, 0, 1);
     list($rid, $direction) = explode('_', $relType, 2);
     $relationshipType = new CRM_Contact_DAO_RelationshipType();
     $relationshipType->id = $rid;
     if ($relationshipType->find(TRUE)) {
         if ($direction == 'a_b') {
             $type = $relationshipType->contact_type_b;
             $subType = $relationshipType->contact_sub_type_b;
         } else {
             $type = $relationshipType->contact_type_a;
             $subType = $relationshipType->contact_sub_type_a;
         }
         if ($type == 'Individual' || $type == 'Organization' || $type == 'Household') {
             $searchValues[] = array('contact_type', '=', $type, 0, 0);
             $contactTypeAdded = TRUE;
         }
         if ($subType) {
             $searchValues[] = array('contact_sub_type', '=', $subType, 0, 0);
         }
     }
     // exclude current contact
     $searchValues[] = array('contact_id', '!=', $currentContactId, 0, 0);
     $contactBAO = new CRM_Contact_BAO_Contact();
     $query = new CRM_Contact_BAO_Query($searchValues);
     $searchCount = $query->searchQuery(0, 0, NULL, TRUE);
     $iTotal = $searchCount;
     if ($searchCount > 0) {
         // get the result of the search
         $result = $query->searchQuery($offset, $rowCount, $sort, FALSE, FALSE, FALSE, FALSE, FALSE, NULL, $sortOrder);
         $config = CRM_Core_Config::singleton();
         //variable is set if only one record is foun and that record already has relationship with the contact
         $duplicateRelationship = 0;
         while ($result->fetch()) {
             $contactID = $result->contact_id;
             $duplicateRelationship = 0;
             $contact_type = '<img src="' . $config->resourceBase . 'i/contact_';
             $typeImage = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type, FALSE, $contactID);
             $searchRows[$contactID]['id'] = $contactID;
             $searchRows[$contactID]['name'] = $typeImage . ' ' . $result->sort_name;
             $searchRows[$contactID]['city'] = $result->city;
             $searchRows[$contactID]['state'] = $result->state_province;
             $searchRows[$contactID]['email'] = $result->email;
             $searchRows[$contactID]['phone'] = $result->phone;
         }
     }
     foreach ($searchRows as $cid => $row) {
         $searchRows[$cid]['check'] = '<input type="checkbox" id="contact_check[' . $cid . ']" name="contact_check[' . $cid . ']" value=' . $cid . ' />';
         if ($typeName == 'Employee of') {
             $searchRows[$cid]['employee_of'] = '<input type="radio" name="employee_of" value=' . $cid . ' >';
         } elseif ($typeName == 'Employer of') {
             $searchRows[$cid]['employer_of'] = '<input type="checkbox"  name="employer_of[' . $cid . ']" value=' . $cid . ' />';
         }
     }
     $selectorElements = array('check', 'name');
     if ($typeName == 'Employee of') {
         $selectorElements[] = 'employee_of';
     } elseif ($typeName == 'Employer of') {
         $selectorElements[] = 'employer_of';
     }
     $selectorElements = array_merge($selectorElements, array('city', 'state', 'email', 'phone'));
     $iFilteredTotal = $iTotal;
     echo CRM_Utils_JSON::encodeDataTableSelector($searchRows, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
     CRM_Utils_System::civiExit();
 }
Exemple #13
0
 /**
  * Retrieve cases related to particular contact or whole contact
  * used in Dashboad and Tab
  *
  * @param boolean    $allCases  
  * 
  * @param int        $userID 
  *
  * @param String     $type /upcoming,recent,all/ 
  *
  * @return array     Array of Cases
  * 
  * @access public
  * 
  */
 function getCases($allCases = true, $userID = null, $type = 'upcoming')
 {
     $condition = null;
     if (!$allCases) {
         $condition = " AND case_relationship.contact_id_b = {$userID}";
     }
     $condition .= " \nAND civicrm_activity.is_deleted = 0\nAND civicrm_case.is_deleted     = 0";
     if ($type == 'upcoming') {
         $closedId = CRM_Core_OptionGroup::getValue('case_status', 'Closed', 'name');
         $condition .= "\nAND civicrm_case.status_id != {$closedId}";
     }
     $query = self::getCaseActivityQuery($type, $userID, $condition);
     $queryParams = array();
     $result = CRM_Core_DAO::executeQuery($query, $queryParams);
     require_once 'CRM/Core/OptionGroup.php';
     $caseStatus = CRM_Core_OptionGroup::values('case_status', false, false, false, " AND v.name = 'Urgent' ");
     $resultFields = array('contact_id', 'contact_type', 'sort_name', 'phone', 'case_id', 'case_type', 'case_type_name', 'status_id', 'case_status', 'case_status_name', 'activity_type_id', 'case_role');
     if ($type == 'upcoming') {
         $resultFields[] = 'case_scheduled_activity_date';
         $resultFields[] = 'case_scheduled_activity_type_name';
         $resultFields[] = 'case_scheduled_activity_type';
         $resultFields[] = 'case_scheduled_activity_id';
     } else {
         if ($type == 'recent') {
             $resultFields[] = 'case_recent_activity_date';
             $resultFields[] = 'case_recent_activity_type_name';
             $resultFields[] = 'case_recent_activity_type';
             $resultFields[] = 'case_recent_activity_id';
         }
     }
     // we're going to use the usual actions, so doesn't make sense to duplicate definitions
     require_once 'CRM/Case/Selector/Search.php';
     $actions = CRM_Case_Selector_Search::links();
     require_once "CRM/Contact/BAO/Contact/Utils.php";
     $casesList = array();
     // check is the user has view/edit signer permission
     $permissions = array(CRM_Core_Permission::VIEW);
     if (CRM_Core_Permission::check('edit cases')) {
         $permissions[] = CRM_Core_Permission::EDIT;
     }
     if (CRM_Core_Permission::check('delete in CiviCase')) {
         $permissions[] = CRM_Core_Permission::DELETE;
     }
     $mask = CRM_Core_Action::mask($permissions);
     while ($result->fetch()) {
         foreach ($resultFields as $donCare => $field) {
             $casesList[$result->case_id][$field] = $result->{$field};
             if ($field == 'contact_type') {
                 $casesList[$result->case_id]['contact_type_icon'] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type);
                 $casesList[$result->case_id]['action'] = CRM_Core_Action::formLink($actions, $mask, array('id' => $result->case_id, 'cid' => $result->contact_id, 'cxt' => 'dashboard'));
             } elseif ($field == 'case_status') {
                 if (in_array($result->{$field}, $caseStatus)) {
                     $casesList[$result->case_id]['class'] = "status-urgent";
                 } else {
                     $casesList[$result->case_id]['class'] = "status-normal";
                 }
             }
         }
         //CRM-4510.
         $caseManagerContact = self::getCaseManagerContact($result->case_type_name, $result->case_id);
         if (!empty($caseManagerContact)) {
             $casesList[$result->case_id]['casemanager_id'] = CRM_Utils_Array::value('casemanager_id', $caseManagerContact);
             $casesList[$result->case_id]['casemanager'] = CRM_Utils_Array::value('casemanager', $caseManagerContact);
         }
     }
     return $casesList;
 }
 /**
  * returns all the rows in the given offset and rowCount
  *
  * @param enum   $action   the action being performed
  * @param int    $offset   the row number to start from
  * @param int    $rowCount the number of rows to return
  * @param string $sort     the sql string that describes the sort order
  * @param enum   $output   what should the result set include (web/email/csv)
  *
  * @return int   the total number of rows for this action
  */
 function &getRows($action, $offset, $rowCount, $sort, $output = NULL)
 {
     $result = $this->_query->searchQuery($offset, $rowCount, $sort, FALSE, FALSE, FALSE, FALSE, FALSE, $this->_additionalClause);
     // process the result of the query
     $rows = array();
     // get all pledge status
     $pledgeStatuses = CRM_Core_OptionGroup::values('contribution_status', FALSE, FALSE, FALSE, NULL, 'name', FALSE);
     //get all campaigns.
     $allCampaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
     //4418 check for view, edit and delete
     $permissions = array(CRM_Core_Permission::VIEW);
     if (CRM_Core_Permission::check('edit pledges')) {
         $permissions[] = CRM_Core_Permission::EDIT;
     }
     if (CRM_Core_Permission::check('delete in CiviPledge')) {
         $permissions[] = CRM_Core_Permission::DELETE;
     }
     $mask = CRM_Core_Action::mask($permissions);
     while ($result->fetch()) {
         $row = array();
         // the columns we are interested in
         foreach (self::$_properties as $property) {
             if (isset($result->{$property})) {
                 $row[$property] = $result->{$property};
             }
         }
         //carry campaign on selectors.
         $row['campaign'] = CRM_Utils_Array::value($result->pledge_campaign_id, $allCampaigns);
         $row['campaign_id'] = $result->pledge_campaign_id;
         // add pledge status name
         $row['pledge_status_name'] = CRM_Utils_Array::value($row['pledge_status_id'], $pledgeStatuses);
         // append (test) to status label
         if (!empty($row['pledge_is_test'])) {
             $row['pledge_status'] .= ' (test)';
         }
         $hideOption = array();
         if (CRM_Utils_Array::key('Cancelled', $row) || CRM_Utils_Array::key('Completed', $row)) {
             $hideOption[] = 'Cancel';
         }
         $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $result->pledge_id;
         $row['action'] = CRM_Core_Action::formLink(self::links($hideOption, $this->_key), $mask, array('id' => $result->pledge_id, 'cid' => $result->contact_id, 'cxt' => $this->_context), ts('more'), FALSE, 'pledge.selector.row', 'Pledge', $result->pledge_id);
         $row['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type, FALSE, $result->contact_id);
         $rows[] = $row;
     }
     return $rows;
 }
Exemple #15
0
 /**
  * Returns all the rows in the given offset and rowCount.
  *
  * @param string $action
  *   The action being performed.
  * @param int $offset
  *   The row number to start from.
  * @param int $rowCount
  *   The number of rows to return.
  * @param string $sort
  *   The sql string that describes the sort order.
  * @param string $output
  *   What should the result set include (web/email/csv).
  *
  * @return int
  *   the total number of rows for this action
  */
 public function &getRows($action, $offset, $rowCount, $sort, $output = NULL)
 {
     $includeContactIDs = FALSE;
     if (($output == CRM_Core_Selector_Controller::EXPORT || $output == CRM_Core_Selector_Controller::SCREEN) && $this->_formValues['radio_ts'] == 'ts_sel') {
         $includeContactIDs = TRUE;
     }
     $sql = $this->_search->all($offset, $rowCount, $sort, $includeContactIDs);
     // contact query object used for creating $sql
     $contactQueryObj = NULL;
     if (method_exists($this->_search, 'getQueryObj') && is_a($this->_search->getQueryObj(), 'CRM_Contact_BAO_Query')) {
         $contactQueryObj = $this->_search->getQueryObj();
     }
     $dao = CRM_Core_DAO::executeQuery($sql, CRM_Core_DAO::$_nullArray);
     $columns = $this->_search->columns();
     $columnNames = array_values($columns);
     $links = self::links($this->_key);
     $permissions = array(CRM_Core_Permission::getPermission());
     if (CRM_Core_Permission::check('delete contacts')) {
         $permissions[] = CRM_Core_Permission::DELETE;
     }
     $mask = CRM_Core_Action::mask($permissions);
     $alterRow = FALSE;
     if (method_exists($this->_customSearchClass, 'alterRow')) {
         $alterRow = TRUE;
     }
     $image = FALSE;
     if (is_a($this->_search, 'CRM_Contact_Form_Search_Custom_Basic')) {
         $image = TRUE;
     }
     // process the result of the query
     $rows = array();
     while ($dao->fetch()) {
         $row = array();
         $empty = TRUE;
         // if contact query object present
         // process pseudo constants
         if ($contactQueryObj) {
             $contactQueryObj->convertToPseudoNames($dao);
         }
         // the columns we are interested in
         foreach ($columnNames as $property) {
             $row[$property] = $dao->{$property};
             if (!empty($dao->{$property})) {
                 $empty = FALSE;
             }
         }
         if (!$empty) {
             $contactID = isset($dao->contact_id) ? $dao->contact_id : NULL;
             $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $contactID;
             $row['action'] = CRM_Core_Action::formLink($links, $mask, array('id' => $contactID), ts('more'), FALSE, 'contact.custom.actions', 'Contact', $contactID);
             $row['contact_id'] = $contactID;
             if ($alterRow) {
                 $this->_search->alterRow($row);
             }
             if ($image) {
                 $row['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage($dao->contact_sub_type ? $dao->contact_sub_type : $dao->contact_type, FALSE, $contactID);
             }
             $rows[] = $row;
         }
     }
     $this->buildPrevNextCache($sort);
     return $rows;
 }
 /**
  * This function retrieve contact information.
  *
  * @param array $voterIds
  * @param array $returnProperties
  *   An array of return elements.
  *
  * @return array
  *   array of contact info.
  */
 public static function voterDetails($voterIds, $returnProperties = array())
 {
     $voterDetails = array();
     if (!is_array($voterIds) || empty($voterIds)) {
         return $voterDetails;
     }
     if (empty($returnProperties)) {
         $autocompleteContactSearch = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_autocomplete_options');
         $returnProperties = array_fill_keys(array_merge(array('contact_type', 'contact_sub_type', 'sort_name'), array_keys($autocompleteContactSearch)), 1);
     }
     $select = $from = array();
     foreach ($returnProperties as $property => $ignore) {
         $value = in_array($property, array('city', 'street_address')) ? 'address' : $property;
         switch ($property) {
             case 'sort_name':
             case 'contact_type':
             case 'contact_sub_type':
                 $select[] = "{$property} as {$property}";
                 $from['contact'] = 'civicrm_contact contact';
                 break;
             case 'email':
             case 'phone':
             case 'city':
             case 'street_address':
                 $select[] = "{$property} as {$property}";
                 $from[$value] = "LEFT JOIN civicrm_{$value} {$value} ON ( contact.id = {$value}.contact_id AND {$value}.is_primary = 1 ) ";
                 break;
             case 'country':
             case 'state_province':
                 $select[] = "{$property}.name as {$property}";
                 if (!in_array('address', $from)) {
                     $from['address'] = 'LEFT JOIN civicrm_address address ON ( contact.id = address.contact_id AND address.is_primary = 1) ';
                 }
                 $from[$value] = " LEFT JOIN civicrm_{$value} {$value} ON ( address.{$value}_id = {$value}.id  ) ";
                 break;
         }
     }
     //finally retrieve contact details.
     if (!empty($select) && !empty($from)) {
         $fromClause = implode(' ', $from);
         $selectClause = implode(', ', $select);
         $whereClause = "contact.id IN (" . implode(',', $voterIds) . ')';
         $query = "\n  SELECT  contact.id as contactId, {$selectClause}\n    FROM  {$fromClause}\n   WHERE  {$whereClause}\nGroup By  contact.id";
         $contact = CRM_Core_DAO::executeQuery($query);
         while ($contact->fetch()) {
             $voterDetails[$contact->contactId]['contact_id'] = $contact->contactId;
             foreach ($returnProperties as $property => $ignore) {
                 $voterDetails[$contact->contactId][$property] = $contact->{$property};
             }
             $image = CRM_Contact_BAO_Contact_Utils::getImage($contact->contact_sub_type ? $contact->contact_sub_type : $contact->contact_type, FALSE, $contact->contactId);
             $voterDetails[$contact->contactId]['contact_type'] = $image;
         }
         $contact->free();
     }
     return $voterDetails;
 }
 /**
  * This function is to get the result of the search for contact in relationship form
  *
  * @param  array $params  This contains elements for search criteria
  *
  * @access public
  * @return None
  *
  */
 function search(&$params)
 {
     //max records that will be listed
     $searchValues = array();
     if (CRM_Utils_Array::value('rel_contact', $params)) {
         if (is_numeric($params['rel_contact_id'])) {
             $searchValues[] = array('contact_id', '=', $params['rel_contact_id'], 0, 1);
         } else {
             $searchValues[] = array('sort_name', 'LIKE', $params['rel_contact'], 0, 1);
         }
     }
     $contactTypeAdded = false;
     $excludedContactIds = array($this->_contactId);
     if ($params['relationship_type_id']) {
         $relationshipType = new CRM_Contact_DAO_RelationshipType();
         list($rid, $direction) = explode('_', $params['relationship_type_id'], 2);
         $relationshipType->id = $rid;
         if ($relationshipType->find(true)) {
             if ($direction == 'a_b') {
                 $type = $relationshipType->contact_type_b;
                 $subType = $relationshipType->contact_sub_type_b;
             } else {
                 $type = $relationshipType->contact_type_a;
                 $subType = $relationshipType->contact_sub_type_a;
             }
             $this->set('contact_type', $type);
             $this->set('contact_sub_type', $subType);
             if ($type == 'Individual' || $type == 'Organization' || $type == 'Household') {
                 $searchValues[] = array('contact_type', '=', $type, 0, 0);
                 $contactTypeAdded = true;
             }
             if ($subType) {
                 $searchValues[] = array('contact_sub_type', '=', $subType, 0, 0);
             }
         }
     }
     if (!$contactTypeAdded && CRM_Utils_Array::value('contact_type', $params)) {
         $searchValues[] = array('contact_type', '=', $params['contact_type'], 0, 0);
     }
     // get the count of contact
     $contactBAO = new CRM_Contact_BAO_Contact();
     $query = new CRM_Contact_BAO_Query($searchValues);
     $searchCount = $query->searchQuery(0, 0, null, true);
     $this->set('searchCount', $searchCount);
     if ($searchCount <= self::MAX_RELATIONSHIPS) {
         // get the result of the search
         $result = $query->searchQuery(0, 50, null);
         $config = CRM_Core_Config::singleton();
         $searchRows = array();
         //variable is set if only one record is foun and that record already has relationship with the contact
         $duplicateRelationship = 0;
         while ($result->fetch()) {
             $contactID = $result->contact_id;
             if (in_array($contactID, $excludedContactIds)) {
                 $duplicateRelationship++;
                 continue;
             }
             $duplicateRelationship = 0;
             $searchRows[$contactID]['id'] = $contactID;
             $searchRows[$contactID]['name'] = $result->sort_name;
             $searchRows[$contactID]['city'] = $result->city;
             $searchRows[$contactID]['state'] = $result->state_province;
             $searchRows[$contactID]['email'] = $result->email;
             $searchRows[$contactID]['phone'] = $result->phone;
             $contact_type = '<img src="' . $config->resourceBase . 'i/contact_';
             require_once 'CRM/Contact/BAO/Contact/Utils.php';
             $searchRows[$contactID]['type'] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type);
         }
         $this->set('searchRows', $searchRows);
         $this->set('duplicateRelationship', $duplicateRelationship);
     } else {
         // resetting the session variables if many records are found
         $this->set('searchRows', null);
         $this->set('duplicateRelationship', null);
     }
 }
Exemple #18
0
 /**
  * Retrieve list of duplicate pairs from cache table.
  */
 public static function getDedupes()
 {
     $offset = isset($_REQUEST['start']) ? CRM_Utils_Type::escape($_REQUEST['start'], 'Integer') : 0;
     $rowCount = isset($_REQUEST['length']) ? CRM_Utils_Type::escape($_REQUEST['length'], 'Integer') : 25;
     $gid = isset($_REQUEST['gid']) ? CRM_Utils_Type::escape($_REQUEST['gid'], 'Integer') : 0;
     $rgid = isset($_REQUEST['rgid']) ? CRM_Utils_Type::escape($_REQUEST['rgid'], 'Integer') : 0;
     $selected = isset($_REQUEST['selected']) ? CRM_Utils_Type::escape($_REQUEST['selected'], 'Integer') : 0;
     if ($rowCount < 0) {
         $rowCount = 0;
     }
     $contactType = '';
     if ($rgid) {
         $contactType = CRM_Core_DAO::getFieldValue('CRM_Dedupe_DAO_RuleGroup', $rgid, 'contact_type');
     }
     $cacheKeyString = "merge {$contactType}_{$rgid}_{$gid}";
     $searchRows = array();
     $selectorElements = array('is_selected', 'is_selected_input', 'src_image', 'src', 'src_email', 'src_street', 'src_postcode', 'dst_image', 'dst', 'dst_email', 'dst_street', 'dst_postcode', 'conflicts', 'weight', 'actions');
     foreach ($_REQUEST['columns'] as $columnInfo) {
         if (!empty($columnInfo['search']['value'])) {
             ${$columnInfo['data']} = CRM_Utils_Type::escape($columnInfo['search']['value'], 'String');
         }
     }
     $join = '';
     $where = array();
     $searchData = CRM_Utils_Array::value('search', $_REQUEST);
     $searchData['value'] = CRM_Utils_Type::escape($searchData['value'], 'String');
     if ($src || !empty($searchData['value'])) {
         $src = $src ? $src : $searchData['value'];
         $where[] = " cc1.display_name LIKE '%{$src}%'";
     }
     if ($dst || !empty($searchData['value'])) {
         $dst = $dst ? $dst : $searchData['value'];
         $where[] = " cc2.display_name LIKE '%{$dst}%'";
     }
     if ($src_email || !empty($searchData['value'])) {
         $src_email = $src_email ? $src_email : $searchData['value'];
         $where[] = " (ce1.is_primary = 1 AND ce1.email LIKE '%{$src_email}%')";
     }
     if ($dst_email || !empty($searchData['value'])) {
         $dst_email = $dst_email ? $dst_email : $searchData['value'];
         $where[] = " (ce2.is_primary = 1 AND ce2.email LIKE '%{$dst_email}%')";
     }
     if ($src_postcode || !empty($searchData['value'])) {
         $src_postcode = $src_postcode ? $src_postcode : $searchData['value'];
         $where[] = " (ca1.is_primary = 1 AND ca1.postal_code LIKE '%{$src_postcode}%')";
     }
     if ($dst_postcode || !empty($searchData['value'])) {
         $dst_postcode = $dst_postcode ? $dst_postcode : $searchData['value'];
         $where[] = " (ca2.is_primary = 1 AND ca2.postal_code LIKE '%{$dst_postcode}%')";
     }
     if ($src_street || !empty($searchData['value'])) {
         $src_street = $src_street ? $src_street : $searchData['value'];
         $where[] = " (ca1.is_primary = 1 AND ca1.street_address LIKE '%{$src_street}%')";
     }
     if ($dst_street || !empty($searchData['value'])) {
         $dst_street = $dst_street ? $dst_street : $searchData['value'];
         $where[] = " (ca2.is_primary = 1 AND ca2.street_address LIKE '%{$dst_street}%')";
     }
     if (!empty($searchData['value'])) {
         $whereClause = ' ( ' . implode(' OR ', $where) . ' ) ';
     } else {
         if (!empty($where)) {
             $whereClause = implode(' AND ', $where);
         }
     }
     $whereClause .= $whereClause ? ' AND de.id IS NULL' : ' de.id IS NULL';
     if ($selected) {
         $whereClause .= ' AND pn.is_selected = 1';
     }
     $join .= " LEFT JOIN civicrm_dedupe_exception de ON ( pn.entity_id1 = de.contact_id1 AND pn.entity_id2 = de.contact_id2 )";
     $select = array('cc1.contact_type' => 'src_contact_type', 'cc1.display_name' => 'src_display_name', 'cc1.contact_sub_type' => 'src_contact_sub_type', 'cc2.contact_type' => 'dst_contact_type', 'cc2.display_name' => 'dst_display_name', 'cc2.contact_sub_type' => 'dst_contact_sub_type', 'ce1.email' => 'src_email', 'ce2.email' => 'dst_email', 'ca1.postal_code' => 'src_postcode', 'ca2.postal_code' => 'dst_postcode', 'ca1.street_address' => 'src_street', 'ca2.street_address' => 'dst_street');
     if ($select) {
         $join .= " INNER JOIN civicrm_contact cc1 ON cc1.id = pn.entity_id1";
         $join .= " INNER JOIN civicrm_contact cc2 ON cc2.id = pn.entity_id2";
         $join .= " LEFT JOIN civicrm_email ce1 ON (ce1.contact_id = pn.entity_id1 AND ce1.is_primary = 1 )";
         $join .= " LEFT JOIN civicrm_email ce2 ON (ce2.contact_id = pn.entity_id2 AND ce2.is_primary = 1 )";
         $join .= " LEFT JOIN civicrm_address ca1 ON (ca1.contact_id = pn.entity_id1 AND ca1.is_primary = 1 )";
         $join .= " LEFT JOIN civicrm_address ca2 ON (ca2.contact_id = pn.entity_id2 AND ca2.is_primary = 1 )";
     }
     $iTotal = CRM_Core_BAO_PrevNextCache::getCount($cacheKeyString, $join, $whereClause);
     foreach ($_REQUEST['order'] as $orderInfo) {
         if (!empty($orderInfo['column'])) {
             $orderColumnNumber = $orderInfo['column'];
             $dir = $orderInfo['dir'];
         }
     }
     $columnDetails = CRM_Utils_Array::value($orderColumnNumber, $_REQUEST['columns']);
     if (!empty($columnDetails)) {
         switch ($columnDetails['data']) {
             case 'src':
                 $whereClause .= " ORDER BY cc1.display_name {$dir}";
                 break;
             case 'src_email':
                 $whereClause .= " ORDER BY ce1.email {$dir}";
                 break;
             case 'src_street':
                 $whereClause .= " ORDER BY ca1.street_address {$dir}";
                 break;
             case 'src_postcode':
                 $whereClause .= " ORDER BY ca1.postal_code {$dir}";
                 break;
             case 'dst':
                 $whereClause .= " ORDER BY cc2.display_name {$dir}";
                 break;
             case 'dst_email':
                 $whereClause .= " ORDER BY ce2.email {$dir}";
                 break;
             case 'dst_street':
                 $whereClause .= " ORDER BY ca2.street_address {$dir}";
                 break;
             case 'dst_postcode':
                 $whereClause .= " ORDER BY ca2.postal_code {$dir}";
                 break;
             default:
                 break;
         }
     }
     $dupePairs = CRM_Core_BAO_PrevNextCache::retrieve($cacheKeyString, $join, $whereClause, $offset, $rowCount, $select);
     $iFilteredTotal = CRM_Core_DAO::singleValueQuery("SELECT FOUND_ROWS()");
     $count = 0;
     foreach ($dupePairs as $key => $pairInfo) {
         $pair =& $pairInfo['data'];
         $srcContactSubType = CRM_Utils_Array::value('src_contact_sub_type', $pairInfo);
         $dstContactSubType = CRM_Utils_Array::value('dst_contact_sub_type', $pairInfo);
         $srcTypeImage = CRM_Contact_BAO_Contact_Utils::getImage($srcContactSubType ? $srcContactSubType : $pairInfo['src_contact_type'], FALSE, $pairInfo['entity_id1']);
         $dstTypeImage = CRM_Contact_BAO_Contact_Utils::getImage($dstContactSubType ? $dstContactSubType : $pairInfo['dst_contact_type'], FALSE, $pairInfo['entity_id2']);
         $searchRows[$count]['is_selected'] = $pairInfo['is_selected'];
         $searchRows[$count]['is_selected_input'] = "<input type='checkbox' class='crm-dedupe-select' name='pnid_{$pairInfo['prevnext_id']}' value='{$pairInfo['is_selected']}' onclick='toggleDedupeSelect(this)'>";
         $searchRows[$count]['src_image'] = $srcTypeImage;
         $searchRows[$count]['src'] = CRM_Utils_System::href($pair['srcName'], 'civicrm/contact/view', "reset=1&cid={$pairInfo['entity_id1']}");
         $searchRows[$count]['src_email'] = CRM_Utils_Array::value('src_email', $pairInfo);
         $searchRows[$count]['src_street'] = CRM_Utils_Array::value('src_street', $pairInfo);
         $searchRows[$count]['src_postcode'] = CRM_Utils_Array::value('src_postcode', $pairInfo);
         $searchRows[$count]['dst_image'] = $dstTypeImage;
         $searchRows[$count]['dst'] = CRM_Utils_System::href($pair['dstName'], 'civicrm/contact/view', "reset=1&cid={$pairInfo['entity_id2']}");
         $searchRows[$count]['dst_email'] = CRM_Utils_Array::value('dst_email', $pairInfo);
         $searchRows[$count]['dst_street'] = CRM_Utils_Array::value('dst_street', $pairInfo);
         $searchRows[$count]['dst_postcode'] = CRM_Utils_Array::value('dst_postcode', $pairInfo);
         $searchRows[$count]['conflicts'] = str_replace("',", "',<br/>", CRM_Utils_Array::value('conflicts', $pair));
         $searchRows[$count]['weight'] = CRM_Utils_Array::value('weight', $pair);
         if (!empty($pairInfo['data']['canMerge'])) {
             $mergeParams = "reset=1&cid={$pairInfo['entity_id1']}&oid={$pairInfo['entity_id2']}&action=update&rgid={$rgid}";
             if ($gid) {
                 $mergeParams .= "&gid={$gid}";
             }
             $searchRows[$count]['actions'] = "<a class='crm-dedupe-flip' href='#' data-pnid={$pairInfo['prevnext_id']}>" . ts('flip') . "</a>&nbsp;|&nbsp;";
             $searchRows[$count]['actions'] .= CRM_Utils_System::href(ts('merge'), 'civicrm/contact/merge', $mergeParams);
             $searchRows[$count]['actions'] .= "&nbsp;|&nbsp;<a id='notDuplicate' href='#' onClick=\"processDupes( {$pairInfo['entity_id1']}, {$pairInfo['entity_id2']}, 'dupe-nondupe', 'dupe-listing'); return false;\">" . ts('not a duplicate') . "</a>";
         } else {
             $searchRows[$count]['actions'] = '<em>' . ts('Insufficient access rights - cannot merge') . '</em>';
         }
         $count++;
     }
     $dupePairs = array('data' => $searchRows, 'recordsTotal' => $iTotal, 'recordsFiltered' => $iFilteredTotal);
     CRM_Utils_JSON::output($dupePairs);
 }
Exemple #19
0
 /**
  * returns all the rows in the given offset and rowCount
  *
  * @param enum   $action   the action being performed
  * @param int    $offset   the row number to start from
  * @param int    $rowCount the number of rows to return
  * @param string $sort     the sql string that describes the sort order
  * @param enum   $output   what should the result set include (web/email/csv)
  *
  * @return int   the total number of rows for this action
  */
 function &getRows($action, $offset, $rowCount, $sort, $output = NULL)
 {
     $result = $this->_query->searchQuery($offset, $rowCount, $sort, FALSE, FALSE, FALSE, FALSE, FALSE, $this->_campaignWhereClause, NULL, $this->_campaignFromClause);
     // process the result of the query
     $rows = array();
     while ($result->fetch()) {
         $this->_query->convertToPseudoNames($result);
         $row = array();
         // the columns we are interested in
         foreach (self::$_properties as $property) {
             if (property_exists($result, $property)) {
                 $row[$property] = $result->{$property};
             }
         }
         $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $result->contact_id;
         $row['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_type, FALSE, $result->contact_id);
         $rows[] = $row;
     }
     $this->buildPrevNextCache($sort);
     return $rows;
 }
Exemple #20
0
 /**
  * Returns all the rows in the given offset and rowCount.
  *
  * @param string $action
  *   The action being performed.
  * @param int $offset
  *   The row number to start from.
  * @param int $rowCount
  *   The number of rows to return.
  * @param string $sort
  *   The sql string that describes the sort order.
  * @param string $output
  *   What should the result set include (web/email/csv).
  *
  * @return int
  *   the total number of rows for this action
  */
 public function &getRows($action, $offset, $rowCount, $sort, $output = NULL)
 {
     if ($this->_includeSoftCredits) {
         // especial sort order when rows include soft credits
         $sort = $sort->orderBy() . ", civicrm_contribution.id, civicrm_contribution_soft.id";
     }
     $result = $this->_query->searchQuery($offset, $rowCount, $sort, FALSE, FALSE, FALSE, FALSE, FALSE, $this->_contributionClause);
     // process the result of the query
     $rows = array();
     //CRM-4418 check for view/edit/delete
     $permissions = array(CRM_Core_Permission::VIEW);
     if (CRM_Core_Permission::check('edit contributions')) {
         $permissions[] = CRM_Core_Permission::EDIT;
     }
     if (CRM_Core_Permission::check('delete in CiviContribute')) {
         $permissions[] = CRM_Core_Permission::DELETE;
     }
     $mask = CRM_Core_Action::mask($permissions);
     $qfKey = $this->_key;
     $componentId = $componentContext = NULL;
     if ($this->_context != 'contribute') {
         // @todo explain the significance of context & why we do not get these i that context.
         $qfKey = CRM_Utils_Request::retrieve('key', 'String', CRM_Core_DAO::$_nullObject);
         $componentId = CRM_Utils_Request::retrieve('id', 'Positive', CRM_Core_DAO::$_nullObject);
         $componentAction = CRM_Utils_Request::retrieve('action', 'String', CRM_Core_DAO::$_nullObject);
         $componentContext = CRM_Utils_Request::retrieve('compContext', 'String', CRM_Core_DAO::$_nullObject);
         if (!$componentContext && $this->_compContext) {
             // @todo explain when this condition might occur.
             $componentContext = $this->_compContext;
             $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', CRM_Core_DAO::$_nullObject, NULL, FALSE, 'REQUEST');
         }
         // CRM-17628 for some reason qfKey is not always set when searching from contribution search.
         // as a result if the edit link is opened using right-click + open in new tab
         // then the browser is not returned to the search results on save.
         // This is an effort to getting the qfKey without, sadly, understanding the intent of those who came before me.
         if (empty($qfKey)) {
             $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', CRM_Core_DAO::$_nullObject, NULL, FALSE, 'REQUEST');
         }
     }
     // get all contribution status
     $contributionStatuses = CRM_Core_OptionGroup::values('contribution_status', FALSE, FALSE, FALSE, NULL, 'name', FALSE);
     //get all campaigns.
     $allCampaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
     while ($result->fetch()) {
         $links = self::links($componentId, $componentAction, $qfKey, $componentContext);
         $checkLineItem = FALSE;
         $row = array();
         // Now check for lineItems
         if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()) {
             $lineItems = CRM_Price_BAO_LineItem::getLineItemsByContributionID($result->id);
             foreach ($lineItems as $items) {
                 if (!CRM_Core_Permission::check('view contributions of type ' . CRM_Contribute_PseudoConstant::financialType($items['financial_type_id']))) {
                     $checkLineItem = TRUE;
                     break;
                 }
                 if (!CRM_Core_Permission::check('edit contributions of type ' . CRM_Contribute_PseudoConstant::financialType($items['financial_type_id']))) {
                     unset($links[CRM_Core_Action::UPDATE]);
                 }
                 if (!CRM_Core_Permission::check('delete contributions of type ' . CRM_Contribute_PseudoConstant::financialType($items['financial_type_id']))) {
                     unset($links[CRM_Core_Action::DELETE]);
                 }
             }
             if ($checkLineItem) {
                 continue;
             }
             if (!CRM_Core_Permission::check('edit contributions of type ' . CRM_Contribute_PseudoConstant::financialType($result->financial_type_id))) {
                 unset($links[CRM_Core_Action::UPDATE]);
             }
             if (!CRM_Core_Permission::check('delete contributions of type ' . CRM_Contribute_PseudoConstant::financialType($result->financial_type_id))) {
                 unset($links[CRM_Core_Action::DELETE]);
             }
         }
         // the columns we are interested in
         foreach (self::$_properties as $property) {
             if (property_exists($result, $property)) {
                 $row[$property] = $result->{$property};
             }
         }
         //carry campaign on selectors.
         // @todo - I can't find any evidence that 'carrying' the campaign on selectors actually
         // results in it being displayed anywhere so why do we do this???
         $row['campaign'] = CRM_Utils_Array::value($result->contribution_campaign_id, $allCampaigns);
         $row['campaign_id'] = $result->contribution_campaign_id;
         // add contribution status name
         $row['contribution_status_name'] = CRM_Utils_Array::value($row['contribution_status_id'], $contributionStatuses);
         if ($result->is_pay_later && CRM_Utils_Array::value('contribution_status_name', $row) == 'Pending') {
             $row['contribution_status'] .= ' (' . ts('Pay Later') . ')';
             $links[CRM_Core_Action::ADD] = array('name' => ts('Pay with Credit Card'), 'url' => 'civicrm/contact/view/contribution', 'qs' => 'reset=1&action=update&id=%%id%%&cid=%%cid%%&context=%%cxt%%&mode=live', 'title' => ts('Pay with Credit Card'));
         } elseif (CRM_Utils_Array::value('contribution_status_name', $row) == 'Pending') {
             $row['contribution_status'] .= ' (' . ts('Incomplete Transaction') . ')';
         }
         if ($row['is_test']) {
             $row['financial_type'] = $row['financial_type'] . ' (' . ts('test') . ')';
         }
         $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $result->contribution_id;
         $actions = array('id' => $result->contribution_id, 'cid' => $result->contact_id, 'cxt' => $this->_context);
         $row['action'] = CRM_Core_Action::formLink($links, $mask, $actions, ts('more'), FALSE, 'contribution.selector.row', 'Contribution', $result->contribution_id);
         $row['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type, FALSE, $result->contact_id);
         if (!empty($row['amount_level'])) {
             CRM_Event_BAO_Participant::fixEventLevel($row['amount_level']);
         }
         $rows[] = $row;
     }
     return $rows;
 }
Exemple #21
0
 /**
  * returns all the rows in the given offset and rowCount
  *
  * @param enum   $action   the action being performed
  * @param int    $offset   the row number to start from
  * @param int    $rowCount the number of rows to return
  * @param string $sort     the sql string that describes the sort order
  * @param enum   $output   what should the result set include (web/email/csv)
  *
  * @return int   the total number of rows for this action
  */
 function &getRows($action, $offset, $rowCount, $sort, $output = null)
 {
     $includeContactIDs = false;
     if (($output == CRM_Core_Selector_Controller::EXPORT || $output == CRM_Core_Selector_Controller::SCREEN) && $this->_formValues['radio_ts'] == 'ts_sel') {
         $includeContactIDs = true;
     }
     $sql = $this->_search->all($offset, $rowCount, $sort, $includeContactIDs);
     $dao = CRM_Core_DAO::executeQuery($sql, CRM_Core_DAO::$_nullArray);
     $columns = $this->_search->columns();
     $columnNames = array_values($columns);
     $links = self::links();
     $permissions = array(CRM_Core_Permission::getPermission());
     if (CRM_Core_Permission::check('delete contacts')) {
         $permissions[] = CRM_Core_Permission::DELETE;
     }
     $mask = CRM_Core_Action::mask($permissions);
     $alterRow = false;
     if (method_exists($this->_customSearchClass, 'alterRow')) {
         $alterRow = true;
     }
     $image = false;
     if (is_a($this->_search, 'CRM_Contact_Form_Search_Custom_Basic')) {
         $image = true;
     }
     // process the result of the query
     $rows = array();
     while ($dao->fetch()) {
         $row = array();
         $empty = true;
         // the columns we are interested in
         foreach ($columnNames as $property) {
             $row[$property] = $dao->{$property};
             if (!empty($dao->{$property})) {
                 $empty = false;
             }
         }
         if (!$empty) {
             $contactID = isset($dao->contact_id) ? $dao->contact_id : NULL;
             $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $contactID;
             $row['action'] = CRM_Core_Action::formLink($links, $mask, array('id' => $contactID));
             $row['contact_id'] = $contactID;
             if ($alterRow) {
                 $this->_search->alterRow($row);
             }
             if ($image) {
                 require_once 'CRM/Contact/BAO/Contact/Utils.php';
                 $row['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage($dao->contact_sub_type ? $dao->contact_sub_type : $dao->contact_type, false, $contactID);
             }
             $rows[] = $row;
         }
     }
     return $rows;
 }
 /**
  * Returns all the rows in the given offset and rowCount.
  *
  * @param string $action
  *   The action being performed.
  * @param int $offset
  *   The row number to start from.
  * @param int $rowCount
  *   The number of rows to return.
  * @param string $sort
  *   The sql string that describes the sort order.
  * @param string $output
  *   What should the result set include (web/email/csv).
  *
  * @return int
  *   the total number of rows for this action
  */
 public function &getRows($action, $offset, $rowCount, $sort, $output = NULL)
 {
     $result = $this->_query->searchQuery($offset, $rowCount, $sort, FALSE, FALSE, FALSE, FALSE, FALSE, $this->_additionalClause);
     // process the result of the query
     $rows = array();
     //CRM-4418 check for view, edit, delete
     $permissions = array(CRM_Core_Permission::VIEW);
     if (CRM_Core_Permission::check('access all cases and activities') || CRM_Core_Permission::check('access my cases and activities')) {
         $permissions[] = CRM_Core_Permission::EDIT;
     }
     if (CRM_Core_Permission::check('delete in CiviCase')) {
         $permissions[] = CRM_Core_Permission::DELETE;
     }
     $mask = CRM_Core_Action::mask($permissions);
     $caseStatus = CRM_Core_OptionGroup::values('case_status', FALSE, FALSE, FALSE, " AND v.name = 'Urgent' ");
     $scheduledInfo = array();
     while ($result->fetch()) {
         $row = array();
         // the columns we are interested in
         foreach (self::$_properties as $property) {
             if (isset($result->{$property})) {
                 $row[$property] = $result->{$property};
             }
         }
         $isDeleted = FALSE;
         if ($result->case_deleted) {
             $isDeleted = TRUE;
             $row['case_status_id'] = empty($row['case_status_id']) ? "" : $row['case_status_id'] . '<br />(deleted)';
         }
         $scheduledInfo['case_id'][] = $result->case_id;
         $scheduledInfo['contact_id'][] = $result->contact_id;
         $scheduledInfo['case_deleted'] = $result->case_deleted;
         $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $result->case_id;
         $links = self::links($isDeleted, $this->_key);
         $row['action'] = CRM_Core_Action::formLink($links['primaryActions'], $mask, array('id' => $result->case_id, 'cid' => $result->contact_id, 'cxt' => $this->_context), ts('more'), FALSE, 'case.selector.actions', 'Case', $result->case_id);
         $row['moreActions'] = CRM_Core_Action::formLink(CRM_Utils_Array::value('moreActions', $links), $mask, array('id' => $result->case_id, 'cid' => $result->contact_id, 'cxt' => $this->_context), ts('more'), TRUE, 'case.selector.moreActions', 'Case', $result->case_id);
         $row['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type);
         //adding case manager to case selector.CRM-4510.
         $caseType = CRM_Case_BAO_Case::getCaseType($result->case_id, 'name');
         $caseManagerContact = CRM_Case_BAO_Case::getCaseManagerContact($caseType, $result->case_id);
         if (!empty($caseManagerContact)) {
             $row['casemanager_id'] = CRM_Utils_Array::value('casemanager_id', $caseManagerContact);
             $row['casemanager'] = CRM_Utils_Array::value('casemanager', $caseManagerContact);
         }
         if (isset($result->case_status_id) && array_key_exists($result->case_status_id, $caseStatus)) {
             $row['class'] = "status-urgent";
         } else {
             $row['class'] = "status-normal";
         }
         $rows[$result->case_id] = $row;
     }
     //retrive the scheduled & recent Activity type and date for selector
     if (!empty($scheduledInfo)) {
         $schdeduledActivity = CRM_Case_BAO_Case::getNextScheduledActivity($scheduledInfo, 'upcoming');
         foreach ($schdeduledActivity as $key => $value) {
             $rows[$key]['case_scheduled_activity_date'] = $value['date'];
             $rows[$key]['case_scheduled_activity_type'] = $value['type'];
         }
         $recentActivity = CRM_Case_BAO_Case::getNextScheduledActivity($scheduledInfo, 'recent');
         foreach ($recentActivity as $key => $value) {
             $rows[$key]['case_recent_activity_date'] = $value['date'];
             $rows[$key]['case_recent_activity_type'] = $value['type'];
         }
     }
     return $rows;
 }
 /**
  * returns all the rows in the given offset and rowCount
  *
  * @param enum   $action   the action being performed
  * @param int    $offset   the row number to start from
  * @param int    $rowCount the number of rows to return
  * @param string $sort     the sql string that describes the sort order
  * @param enum   $output   what should the result set include (web/email/csv)
  *
  * @return int   the total number of rows for this action
  */
 function &getRows($action, $offset, $rowCount, $sort, $output = NULL)
 {
     // check if we can process credit card registration
     $processors = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE, "billing_mode IN ( 1, 3 )");
     if (count($processors) > 0) {
         $this->_isPaymentProcessor = TRUE;
     } else {
         $this->_isPaymentProcessor = FALSE;
     }
     // Only show credit card membership signup and renewal if user has CiviContribute permission
     if (CRM_Core_Permission::access('CiviContribute')) {
         $this->_accessContribution = TRUE;
     } else {
         $this->_accessContribution = FALSE;
     }
     //get all campaigns.
     $allCampaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
     $result = $this->_query->searchQuery($offset, $rowCount, $sort, FALSE, FALSE, FALSE, FALSE, FALSE, $this->_memberClause);
     // process the result of the query
     $rows = array();
     //CRM-4418 check for view, edit, delete
     $permissions = array(CRM_Core_Permission::VIEW);
     if (CRM_Core_Permission::check('edit memberships')) {
         $permissions[] = CRM_Core_Permission::EDIT;
     }
     if (CRM_Core_Permission::check('delete in CiviMember')) {
         $permissions[] = CRM_Core_Permission::DELETE;
     }
     $mask = CRM_Core_Action::mask($permissions);
     while ($result->fetch()) {
         $row = array();
         // the columns we are interested in
         foreach (self::$_properties as $property) {
             if (property_exists($result, $property)) {
                 $row[$property] = $result->{$property};
             }
         }
         //carry campaign on selectors.
         $row['campaign'] = CRM_Utils_Array::value($result->member_campaign_id, $allCampaigns);
         $row['campaign_id'] = $result->member_campaign_id;
         if (!empty($row['member_is_test'])) {
             $row['membership_type'] = $row['membership_type'] . " (test)";
         }
         $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $result->membership_id;
         if (!isset($result->owner_membership_id)) {
             // unset renew and followup link for deceased membership
             $currentMask = $mask;
             if ($result->membership_status == 'Deceased') {
                 $currentMask = $currentMask & ~CRM_Core_Action::RENEW & ~CRM_Core_Action::FOLLOWUP;
             }
             $isCancelSupported = CRM_Member_BAO_Membership::isCancelSubscriptionSupported($row['membership_id']);
             $row['action'] = CRM_Core_Action::formLink(self::links('all', $this->_isPaymentProcessor, $this->_accessContribution, $this->_key, $this->_context, $isCancelSupported), $currentMask, array('id' => $result->membership_id, 'cid' => $result->contact_id, 'cxt' => $this->_context), ts('more'), FALSE, 'membership.selector.row', 'Membership', $result->membership_id);
         } else {
             $row['action'] = CRM_Core_Action::formLink(self::links('view'), $mask, array('id' => $result->membership_id, 'cid' => $result->contact_id, 'cxt' => $this->_context), ts('more'), FALSE, 'membership.selector.row', 'Membership', $result->membership_id);
         }
         //does membership have auto renew CRM-7137.
         $autoRenew = FALSE;
         if (isset($result->membership_recur_id) && $result->membership_recur_id && !CRM_Member_BAO_Membership::isSubscriptionCancelled($row['membership_id'])) {
             $autoRenew = TRUE;
         }
         $row['auto_renew'] = $autoRenew;
         $row['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type, FALSE, $result->contact_id);
         $rows[] = $row;
     }
     return $rows;
 }
 /**
  * Get the result of the search for Add to * forms.
  *
  * @param CRM_Core_Form $form
  * @param array $params
  *   This contains elements for search criteria.
  */
 public function search(&$form, &$params)
 {
     //max records that will be listed
     $searchValues = array();
     if (!empty($params['rel_contact'])) {
         if (isset($params['rel_contact_id']) && is_numeric($params['rel_contact_id'])) {
             $searchValues[] = array('contact_id', '=', $params['rel_contact_id'], 0, 1);
         } else {
             $searchValues[] = array('sort_name', 'LIKE', $params['rel_contact'], 0, 1);
         }
     }
     $contactTypeAdded = FALSE;
     $excludedContactIds = array();
     if (isset($form->_contactId)) {
         $excludedContactIds[] = $form->_contactId;
     }
     if (!empty($params['relationship_type_id'])) {
         $relationshipType = new CRM_Contact_DAO_RelationshipType();
         list($rid, $direction) = explode('_', $params['relationship_type_id'], 2);
         $relationshipType->id = $rid;
         if ($relationshipType->find(TRUE)) {
             if ($direction == 'a_b') {
                 $type = $relationshipType->contact_type_b;
                 $subType = $relationshipType->contact_sub_type_b;
             } else {
                 $type = $relationshipType->contact_type_a;
                 $subType = $relationshipType->contact_sub_type_a;
             }
             $form->set('contact_type', $type);
             $form->set('contact_sub_type', $subType);
             if ($type == 'Individual' || $type == 'Organization' || $type == 'Household') {
                 $searchValues[] = array('contact_type', '=', $type, 0, 0);
                 $contactTypeAdded = TRUE;
             }
             if ($subType) {
                 $searchValues[] = array('contact_sub_type', '=', $subType, 0, 0);
             }
         }
     }
     if (!$contactTypeAdded && !empty($params['contact_type'])) {
         $searchValues[] = array('contact_type', '=', $params['contact_type'], 0, 0);
     }
     // get the count of contact
     $contactBAO = new CRM_Contact_BAO_Contact();
     $query = new CRM_Contact_BAO_Query($searchValues);
     $searchCount = $query->searchQuery(0, 0, NULL, TRUE);
     $form->set('searchCount', $searchCount);
     if ($searchCount <= 50) {
         // get the result of the search
         $result = $query->searchQuery(0, 50, NULL);
         $config = CRM_Core_Config::singleton();
         $searchRows = array();
         //variable is set if only one record is foun and that record already has relationship with the contact
         $duplicateRelationship = 0;
         while ($result->fetch()) {
             $query->convertToPseudoNames($result);
             $contactID = $result->contact_id;
             if (in_array($contactID, $excludedContactIds)) {
                 $duplicateRelationship++;
                 continue;
             }
             $duplicateRelationship = 0;
             $searchRows[$contactID]['id'] = $contactID;
             $searchRows[$contactID]['name'] = $result->sort_name;
             $searchRows[$contactID]['city'] = $result->city;
             $searchRows[$contactID]['state'] = $result->state_province;
             $searchRows[$contactID]['email'] = $result->email;
             $searchRows[$contactID]['phone'] = $result->phone;
             $contact_type = '<img src="' . $config->resourceBase . 'i/contact_';
             $searchRows[$contactID]['type'] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type);
         }
         $form->set('searchRows', $searchRows);
         $form->set('duplicateRelationship', $duplicateRelationship);
     } else {
         // resetting the session variables if many records are found
         $form->set('searchRows', NULL);
         $form->set('duplicateRelationship', NULL);
     }
 }
Exemple #25
0
 /**
  * Retrieve list of duplicate pairs from cache table.
  */
 public static function getDedupes()
 {
     $offset = isset($_REQUEST['start']) ? CRM_Utils_Type::escape($_REQUEST['start'], 'Integer') : 0;
     $rowCount = isset($_REQUEST['length']) ? CRM_Utils_Type::escape($_REQUEST['length'], 'Integer') : 25;
     $gid = CRM_Utils_Request::retrieve('gid', 'Positive');
     $rgid = CRM_Utils_Request::retrieve('rgid', 'Positive');
     $selected = isset($_REQUEST['selected']) ? CRM_Utils_Type::escape($_REQUEST['selected'], 'Integer') : 0;
     if ($rowCount < 0) {
         $rowCount = 0;
     }
     $whereClause = $orderByClause = '';
     $cacheKeyString = CRM_Dedupe_Merger::getMergeCacheKeyString($rgid, $gid);
     $searchRows = array();
     $searchParams = self::getSearchOptionsFromRequest();
     $queryParams = array();
     $join = '';
     $where = array();
     $isOrQuery = self::isOrQuery();
     $nextParamKey = 3;
     $mappings = array('dst' => 'cc1.display_name', 'src' => 'cc2.display_name', 'dst_email' => 'ce1.email', 'src_email' => 'ce2.email', 'dst_postcode' => 'ca1.postal_code', 'src_postcode' => 'ca2.postal_code', 'dst_street' => 'ca1.street', 'src_street' => 'ca2.street');
     foreach ($mappings as $key => $dbName) {
         if (!empty($searchParams[$key])) {
             $queryParams[$nextParamKey] = array('%' . $searchParams[$key] . '%', 'String');
             $where[] = $dbName . " LIKE %{$nextParamKey} ";
             $nextParamKey++;
         }
     }
     if ($isOrQuery) {
         $whereClause = ' ( ' . implode(' OR ', $where) . ' ) ';
     } else {
         if (!empty($where)) {
             $whereClause = implode(' AND ', $where);
         }
     }
     $whereClause .= $whereClause ? ' AND de.id IS NULL' : ' de.id IS NULL';
     if ($selected) {
         $whereClause .= ' AND pn.is_selected = 1';
     }
     $join .= CRM_Dedupe_Merger::getJoinOnDedupeTable();
     $select = array('cc1.contact_type' => 'dst_contact_type', 'cc1.display_name' => 'dst_display_name', 'cc1.contact_sub_type' => 'dst_contact_sub_type', 'cc2.contact_type' => 'src_contact_type', 'cc2.display_name' => 'src_display_name', 'cc2.contact_sub_type' => 'src_contact_sub_type', 'ce1.email' => 'dst_email', 'ce2.email' => 'src_email', 'ca1.postal_code' => 'dst_postcode', 'ca2.postal_code' => 'src_postcode', 'ca1.street_address' => 'dst_street', 'ca2.street_address' => 'src_street');
     if ($select) {
         $join .= " INNER JOIN civicrm_contact cc1 ON cc1.id = pn.entity_id1";
         $join .= " INNER JOIN civicrm_contact cc2 ON cc2.id = pn.entity_id2";
         $join .= " LEFT JOIN civicrm_email ce1 ON (ce1.contact_id = pn.entity_id1 AND ce1.is_primary = 1 )";
         $join .= " LEFT JOIN civicrm_email ce2 ON (ce2.contact_id = pn.entity_id2 AND ce2.is_primary = 1 )";
         $join .= " LEFT JOIN civicrm_address ca1 ON (ca1.contact_id = pn.entity_id1 AND ca1.is_primary = 1 )";
         $join .= " LEFT JOIN civicrm_address ca2 ON (ca2.contact_id = pn.entity_id2 AND ca2.is_primary = 1 )";
     }
     $iTotal = CRM_Core_BAO_PrevNextCache::getCount($cacheKeyString, $join, $whereClause, '=', $queryParams);
     if (!empty($_REQUEST['order'])) {
         foreach ($_REQUEST['order'] as $orderInfo) {
             if (!empty($orderInfo['column'])) {
                 $orderColumnNumber = $orderInfo['column'];
                 $dir = $orderInfo['dir'];
             }
         }
         $columnDetails = CRM_Utils_Array::value($orderColumnNumber, $_REQUEST['columns']);
     }
     if (!empty($columnDetails)) {
         switch ($columnDetails['data']) {
             case 'src':
                 $orderByClause = " ORDER BY cc2.display_name {$dir}";
                 break;
             case 'src_email':
                 $orderByClause = " ORDER BY ce2.email {$dir}";
                 break;
             case 'src_street':
                 $orderByClause = " ORDER BY ca2.street_address {$dir}";
                 break;
             case 'src_postcode':
                 $orderByClause = " ORDER BY ca2.postal_code {$dir}";
                 break;
             case 'dst':
                 $orderByClause = " ORDER BY cc1.display_name {$dir}";
                 break;
             case 'dst_email':
                 $orderByClause = " ORDER BY ce1.email {$dir}";
                 break;
             case 'dst_street':
                 $orderByClause = " ORDER BY ca1.street_address {$dir}";
                 break;
             case 'dst_postcode':
                 $orderByClause = " ORDER BY ca1.postal_code {$dir}";
                 break;
             default:
                 $orderByClause = " ORDER BY cc1.display_name ASC";
                 break;
         }
     }
     $dupePairs = CRM_Core_BAO_PrevNextCache::retrieve($cacheKeyString, $join, $whereClause, $offset, $rowCount, $select, $orderByClause, TRUE, $queryParams);
     $iFilteredTotal = CRM_Core_DAO::singleValueQuery("SELECT FOUND_ROWS()");
     $count = 0;
     foreach ($dupePairs as $key => $pairInfo) {
         $pair = $pairInfo['data'];
         $srcContactSubType = CRM_Utils_Array::value('src_contact_sub_type', $pairInfo);
         $dstContactSubType = CRM_Utils_Array::value('dst_contact_sub_type', $pairInfo);
         $srcTypeImage = CRM_Contact_BAO_Contact_Utils::getImage($srcContactSubType ? $srcContactSubType : $pairInfo['src_contact_type'], FALSE, $pairInfo['entity_id2']);
         $dstTypeImage = CRM_Contact_BAO_Contact_Utils::getImage($dstContactSubType ? $dstContactSubType : $pairInfo['dst_contact_type'], FALSE, $pairInfo['entity_id1']);
         $searchRows[$count]['is_selected'] = $pairInfo['is_selected'];
         $searchRows[$count]['is_selected_input'] = "<input type='checkbox' class='crm-dedupe-select' name='pnid_{$pairInfo['prevnext_id']}' value='{$pairInfo['is_selected']}' onclick='toggleDedupeSelect(this)'>";
         $searchRows[$count]['src_image'] = $srcTypeImage;
         $searchRows[$count]['src'] = CRM_Utils_System::href($pair['srcName'], 'civicrm/contact/view', "reset=1&cid={$pairInfo['entity_id2']}");
         $searchRows[$count]['src_email'] = CRM_Utils_Array::value('src_email', $pairInfo);
         $searchRows[$count]['src_street'] = CRM_Utils_Array::value('src_street', $pairInfo);
         $searchRows[$count]['src_postcode'] = CRM_Utils_Array::value('src_postcode', $pairInfo);
         $searchRows[$count]['dst_image'] = $dstTypeImage;
         $searchRows[$count]['dst'] = CRM_Utils_System::href($pair['dstName'], 'civicrm/contact/view', "reset=1&cid={$pairInfo['entity_id1']}");
         $searchRows[$count]['dst_email'] = CRM_Utils_Array::value('dst_email', $pairInfo);
         $searchRows[$count]['dst_street'] = CRM_Utils_Array::value('dst_street', $pairInfo);
         $searchRows[$count]['dst_postcode'] = CRM_Utils_Array::value('dst_postcode', $pairInfo);
         $searchRows[$count]['conflicts'] = str_replace("',", "',<br/>", CRM_Utils_Array::value('conflicts', $pair));
         $searchRows[$count]['weight'] = CRM_Utils_Array::value('weight', $pair);
         if (!empty($pairInfo['data']['canMerge'])) {
             $mergeParams = "reset=1&cid={$pairInfo['entity_id1']}&oid={$pairInfo['entity_id2']}&action=update&rgid={$rgid}&limit=" . CRM_Utils_Request::retrieve('limit', 'Integer');
             if ($gid) {
                 $mergeParams .= "&gid={$gid}";
             }
             $searchRows[$count]['actions'] = "<a class='crm-dedupe-flip' href='#' data-pnid={$pairInfo['prevnext_id']}>" . ts('flip') . "</a>&nbsp;|&nbsp;";
             $searchRows[$count]['actions'] .= CRM_Utils_System::href(ts('merge'), 'civicrm/contact/merge', $mergeParams);
             $searchRows[$count]['actions'] .= "&nbsp;|&nbsp;<a id='notDuplicate' href='#' onClick=\"processDupes( {$pairInfo['entity_id1']}, {$pairInfo['entity_id2']}, 'dupe-nondupe', 'dupe-listing'); return false;\">" . ts('not a duplicate') . "</a>";
         } else {
             $searchRows[$count]['actions'] = '<em>' . ts('Insufficient access rights - cannot merge') . '</em>';
         }
         $count++;
     }
     $dupePairs = array('data' => $searchRows, 'recordsTotal' => $iTotal, 'recordsFiltered' => $iFilteredTotal);
     if (!empty($_REQUEST['is_unit_test'])) {
         return $dupePairs;
     }
     CRM_Utils_JSON::output($dupePairs);
 }
 /**
  * Get the display name and image of a contact.
  *
  * @param int $id
  *   The contactId.
  *
  * @param bool $includeTypeInReturnParameters
  *   Should type be part of the returned array?
  *
  * @return array
  *   the displayName and contactImage for this contact
  */
 public static function getDisplayAndImage($id, $includeTypeInReturnParameters = FALSE)
 {
     //CRM-14276 added the * on the civicrm_contact table so that we have all the contact info available
     $sql = "\nSELECT    civicrm_contact.*,\n          civicrm_email.email          as email\nFROM      civicrm_contact\nLEFT JOIN civicrm_email ON civicrm_email.contact_id = civicrm_contact.id\n     AND  civicrm_email.is_primary = 1\nWHERE     civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer');
     $dao = new CRM_Core_DAO();
     $dao->query($sql);
     if ($dao->fetch()) {
         $image = CRM_Contact_BAO_Contact_Utils::getImage($dao->contact_sub_type ? $dao->contact_sub_type : $dao->contact_type, FALSE, $id);
         $imageUrl = CRM_Contact_BAO_Contact_Utils::getImage($dao->contact_sub_type ? $dao->contact_sub_type : $dao->contact_type, TRUE, $id);
         // use email if display_name is empty
         if (empty($dao->display_name)) {
             $displayName = $dao->email;
         } else {
             $displayName = $dao->display_name;
         }
         CRM_Utils_Hook::alterDisplayName($displayName, $id, $dao);
         return $includeTypeInReturnParameters ? array($displayName, $image, $dao->contact_type, $dao->contact_sub_type, $imageUrl) : array($displayName, $image, $imageUrl);
     }
     return NULL;
 }
 /**
  * @param $rows
  */
 function addActions(&$rows)
 {
     $config = CRM_Core_Config::singleton();
     $permissions = array(CRM_Core_Permission::getPermission());
     if (CRM_Core_Permission::check('delete contacts')) {
         $permissions[] = CRM_Core_Permission::DELETE;
     }
     $mask = CRM_Core_Action::mask($permissions);
     // mask value to hide map link if there are not lat/long
     $mapMask = $mask & 4095;
     // mask value to hide map link if there are not lat/long
     $mapMask = $mask & 4095;
     $links = self::links($this->_context, $this->_contextMenu, $this->_key);
     foreach ($rows as $id => &$row) {
         if (!empty($this->_formValues['deleted_contacts']) && CRM_Core_Permission::check('access deleted contacts')) {
             $links = array(array('name' => ts('View'), 'url' => 'civicrm/contact/view', 'qs' => 'reset=1&cid=%%id%%', 'class' => 'no-popup', 'title' => ts('View Contact Details')), array('name' => ts('Restore'), 'url' => 'civicrm/contact/view/delete', 'qs' => 'reset=1&cid=%%id%%&restore=1', 'title' => ts('Restore Contact')));
             if (CRM_Core_Permission::check('delete contacts')) {
                 $links[] = array('name' => ts('Delete Permanently'), 'url' => 'civicrm/contact/view/delete', 'qs' => 'reset=1&cid=%%id%%&skip_undelete=1', 'title' => ts('Permanently Delete Contact'));
             }
             $row['action'] = CRM_Core_Action::formLink($links, null, array('id' => $row['contact_id']), ts('more'), FALSE, 'contact.selector.actions', 'Contact', $row['contact_id']);
         } elseif (is_numeric(CRM_Utils_Array::value('geo_code_1', $row)) || $config->mapGeoCoding && !empty($row['city']) && CRM_Utils_Array::value('state_province', $row)) {
             $row['action'] = CRM_Core_Action::formLink($links, $mask, array('id' => $row['contact_id']), ts('more'), FALSE, 'contact.selector.actions', 'Contact', $row['contact_id']);
         } else {
             $row['action'] = CRM_Core_Action::formLink($links, $mapMask, array('id' => $row['contact_id']), ts('more'), FALSE, 'contact.selector.actions', 'Contact', $row['contact_id']);
         }
         // allow components to add more actions
         CRM_Core_Component::searchAction($row, $row['contact_id']);
         if (!empty($row['contact_type_orig'])) {
             $row['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage($row['contact_type_orig'], FALSE, $row['contact_id']);
         }
     }
 }
Exemple #28
0
 /**
  * Returns all the rows in the given offset and rowCount     *
  *
  * @param string $action
  *   The action being performed.
  * @param int $offset
  *   The row number to start from.
  * @param int $rowCount
  *   The number of rows to return.
  * @param string $sort
  *   The sql string that describes the sort order.
  * @param string $output
  *   What should the result set include (web/email/csv).
  *
  * @return int
  *   the total number of rows for this action
  */
 public function &getRows($action, $offset, $rowCount, $sort, $output = NULL)
 {
     $result = $this->_query->searchQuery($offset, $rowCount, $sort, FALSE, FALSE, FALSE, FALSE, FALSE, $this->_grantClause);
     // process the result of the query
     $rows = array();
     //CRM-4418 check for view, edit, delete
     $permissions = array(CRM_Core_Permission::VIEW);
     if (CRM_Core_Permission::check('edit grants')) {
         $permissions[] = CRM_Core_Permission::EDIT;
     }
     if (CRM_Core_Permission::check('delete in CiviGrant')) {
         $permissions[] = CRM_Core_Permission::DELETE;
     }
     $mask = CRM_Core_Action::mask($permissions);
     while ($result->fetch()) {
         $row = array();
         // the columns we are interested in
         foreach (self::$_properties as $property) {
             if (isset($result->{$property})) {
                 $row[$property] = $result->{$property};
             }
         }
         if ($this->_context == 'search') {
             $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $result->grant_id;
         }
         $row['action'] = CRM_Core_Action::formLink(self::links($this->_key), $mask, array('id' => $result->grant_id, 'cid' => $result->contact_id, 'cxt' => $this->_context), ts('more'), FALSE, 'grant.selector.row', 'Grant', $result->grant_id);
         $row['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type, FALSE, $result->contact_id);
         $rows[] = $row;
     }
     return $rows;
 }
 /**
  * Returns all the rows in the given offset and rowCount.
  *
  * @param string $action
  *   The action being performed.
  * @param int $offset
  *   The row number to start from.
  * @param int $rowCount
  *   The number of rows to return.
  * @param string $sort
  *   The sql string that describes the sort order.
  * @param string $output
  *   What should the result set include (web/email/csv).
  *
  * @return array
  *   rows in the given offset and rowCount
  */
 public function &getRows($action, $offset, $rowCount, $sort, $output = NULL)
 {
     $result = $this->_query->searchQuery($offset, $rowCount, $sort, FALSE, FALSE, FALSE, FALSE, FALSE, $this->_activityClause);
     $rows = array();
     $mailingIDs = CRM_Mailing_BAO_Mailing::mailingACLIDs();
     $accessCiviMail = CRM_Core_Permission::check('access CiviMail');
     //get all campaigns.
     $allCampaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
     $engagementLevels = CRM_Campaign_PseudoConstant::engagementLevel();
     $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
     $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
     $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
     $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
     //get all activity types
     $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'name', TRUE);
     while ($result->fetch()) {
         $row = array();
         // ignore rows where we dont have an activity id
         if (empty($result->activity_id)) {
             continue;
         }
         // the columns we are interested in
         foreach (self::$_properties as $property) {
             if (isset($result->{$property})) {
                 $row[$property] = $result->{$property};
             }
         }
         $contactId = CRM_Utils_Array::value('contact_id', $row);
         if (!$contactId) {
             $contactId = CRM_Utils_Array::value('source_contact_id', $row);
         }
         $row['target_contact_name'] = CRM_Activity_BAO_ActivityContact::getNames($row['activity_id'], $targetID);
         $row['assignee_contact_name'] = CRM_Activity_BAO_ActivityContact::getNames($row['activity_id'], $assigneeID);
         list($row['source_contact_name'], $row['source_contact_id']) = CRM_Activity_BAO_ActivityContact::getNames($row['activity_id'], $sourceID, TRUE);
         $row['source_contact_name'] = implode(',', array_values($row['source_contact_name']));
         $row['source_contact_id'] = implode(',', $row['source_contact_id']);
         if ($this->_context == 'search') {
             $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $result->activity_id;
         }
         $row['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type, FALSE, $result->contact_id);
         $accessMailingReport = FALSE;
         $activityTypeId = $row['activity_type_id'];
         if ($row['activity_is_test']) {
             $row['activity_type'] = $row['activity_type'] . " (test)";
         }
         $bulkActivityTypeID = CRM_Utils_Array::key('Bulk Email', $activityTypes);
         $row['mailingId'] = '';
         if ($accessCiviMail && ($mailingIDs === TRUE || in_array($result->source_record_id, $mailingIDs)) && $bulkActivityTypeID == $activityTypeId) {
             $row['mailingId'] = CRM_Utils_System::url('civicrm/mailing/report', "mid={$result->source_record_id}&reset=1&cid={$contactId}&context=activitySelector");
             $row['recipients'] = ts('(recipients)');
             $row['target_contact_name'] = '';
             $row['assignee_contact_name'] = '';
             $accessMailingReport = TRUE;
         }
         $activityActions = new CRM_Activity_Selector_Activity($result->contact_id, NULL);
         $actionLinks = $activityActions->actionLinks($activityTypeId, CRM_Utils_Array::value('source_record_id', $row), $accessMailingReport, CRM_Utils_Array::value('activity_id', $row), $this->_key, $this->_compContext);
         $row['action'] = CRM_Core_Action::formLink($actionLinks, NULL, array('id' => $result->activity_id, 'cid' => $contactId, 'cxt' => $this->_context), ts('more'), FALSE, 'activity.selector.row', 'Activity', $result->activity_id);
         //carry campaign to selector.
         $row['campaign'] = CRM_Utils_Array::value($result->activity_campaign_id, $allCampaigns);
         $row['campaign_id'] = $result->activity_campaign_id;
         if ($engagementLevel = CRM_Utils_Array::value('activity_engagement_level', $row)) {
             $row['activity_engagement_level'] = CRM_Utils_Array::value($engagementLevel, $engagementLevels, $engagementLevel);
         }
         //Check if recurring activity
         $repeat = CRM_Core_BAO_RecurringEntity::getPositionAndCount($row['activity_id'], 'civicrm_activity');
         $row['repeat'] = '';
         if ($repeat) {
             $row['repeat'] = ts('Repeating (%1 of %2)', array(1 => $repeat[0], 2 => $repeat[1]));
         }
         $rows[] = $row;
     }
     return $rows;
 }
Exemple #30
0
 /**
  * returns all the rows in the given offset and rowCount
  *
  * @param enum   $action   the action being performed
  * @param int    $offset   the row number to start from
  * @param int    $rowCount the number of rows to return
  * @param string $sort     the sql string that describes the sort order
  * @param enum   $output   what should the result set include (web/email/csv)
  *
  * @return array  rows in the given offset and rowCount
  */
 function &getRows($action, $offset, $rowCount, $sort, $output = null)
 {
     $result = $this->_query->searchQuery($offset, $rowCount, $sort, false, false, false, false, false, $this->_eventClause);
     // process the result of the query
     $rows = array();
     //lets handle view, edit and delete separately. CRM-4418
     $permissions = array(CRM_Core_Permission::VIEW);
     if (CRM_Core_Permission::check('edit event participants')) {
         $permissions[] = CRM_Core_Permission::EDIT;
     }
     if (CRM_Core_Permission::check('delete in CiviEvent')) {
         $permissions[] = CRM_Core_Permission::DELETE;
     }
     $mask = CRM_Core_Action::mask($permissions);
     require_once 'CRM/Event/BAO/Event.php';
     require_once 'CRM/Event/PseudoConstant.php';
     $statusTypes = CRM_Event_PseudoConstant::participantStatus();
     $statusClasses = CRM_Event_PseudoConstant::participantStatusClass();
     while ($result->fetch()) {
         $row = array();
         // the columns we are interested in
         foreach (self::$_properties as $property) {
             if (isset($result->{$property})) {
                 $row[$property] = $result->{$property};
             }
         }
         // gross hack to show extra information for pending status
         $statusClass = null;
         if ($statusId = array_search($row['participant_status_id'], $statusTypes)) {
             $statusClass = $statusClasses[$statusId];
         }
         $extraInfo = array();
         $row['showConfirmUrl'] = false;
         if ($statusClass == 'Pending') {
             $row['showConfirmUrl'] = true;
         }
         if (CRM_Utils_Array::value('participant_is_test', $row)) {
             $extraInfo[] = ts('test');
         }
         if ($extraInfo) {
             $row['participant_status_id'] .= ' (' . implode(', ', $extraInfo) . ')';
         }
         $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $result->participant_id;
         $row['action'] = CRM_Core_Action::formLink(self::links(), $mask, array('id' => $result->participant_id, 'cid' => $result->contact_id, 'cxt' => $this->_context));
         require_once 'CRM/Contact/BAO/Contact/Utils.php';
         $row['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type);
         $row['paid'] = CRM_Event_BAO_Event::isMonetary($row['event_id']);
         if (CRM_Utils_Array::value('participant_fee_level', $row)) {
             CRM_Event_BAO_Participant::fixEventLevel($row['participant_fee_level']);
         }
         if (CRM_Event_BAO_Event::usesPriceSet($row['event_id'])) {
             // add line item details if applicable
             require_once 'CRM/Price/BAO/LineItem.php';
             $lineItems[$row['participant_id']] = CRM_Price_BAO_LineItem::getLineItems($row['participant_id']);
         }
         $rows[] = $row;
     }
     CRM_Core_Selector_Controller::$_template->assign_by_ref('lineItems', $lineItems);
     return $rows;
 }