Commit 7362fe37 authored by BohdanDmytryshyn's avatar BohdanDmytryshyn
Browse files

Merge branch 'release_5_9_0' into 'master'

Release 5.9.0

See merge request !61
parents 8a568945 ebcaf234
......@@ -45,6 +45,18 @@ class CRM_CiviMobileAPI_ApiWrapper_Activity_Get implements API_Wrapper {
$value['can_edit'] = 0;
$value['can_delete'] = 0;
if (isset($value['details'])) {
$value['details'] = preg_replace('/ /', ' ', $value['details']);
$value['details'] = preg_replace('/'/', "'", $value['details']);
$value['details'] = html_entity_decode($value['details']);
if (!isset($value['short_description']) && isset($value['details'])) {
$value['short_description'] = $value['details'] ? (strip_tags(preg_replace('/\s\s+/', ' ', $value['details']))) : '';
}
} else {
$value['short_description'] = '';
}
if ($checkCaseActivity->find(TRUE)) {
$case = new CRM_Case_DAO_Case();
$case->id = $checkCaseActivity->case_id;
......
......@@ -38,7 +38,7 @@ class CRM_CiviMobileAPI_ApiWrapper_Activity_Notification implements API_Wrapper
$notificationManager->sendNotification();
}
} elseif ($apiRequest['action'] == 'delete') {
$notificationManager = new CRM_CiviMobileAPI_PushNotification_Utils_Hook_PostProcess_CasePushNotification($apiRequest['entity'], $apiRequest['action'], key($result['values']));
$notificationManager = new CRM_CiviMobileAPI_PushNotification_Utils_Hook_PostProcess_CasePushNotification($apiRequest['entity'], $apiRequest['action'], key([$result['values']]));
$notificationManager->sendNotification();
}
......
......@@ -13,6 +13,30 @@ class CRM_CiviMobileAPI_ApiWrapper_Case implements API_Wrapper {
* @return array
*/
public function fromApiInput($apiRequest) {
$contactIds = [];
$caseIds = [];
if (!empty($apiRequest['params']['contact_display_name']) || !empty($apiRequest['params']['activity_type'])) {
if (!empty($apiRequest['params']['contact_display_name'])) {
$contactIds = CRM_CiviMobileAPI_Utils_CaseSummary::getContactsIdByName($apiRequest['params']['contact_display_name']);
if (!$contactIds) {
$apiRequest['contacts_is_not_found'] = 1;
}
}
if (!empty($apiRequest['params']['activity_type'])) {
$caseIds = CRM_CiviMobileAPI_Utils_CaseSummary::getCaseIdByActivities($apiRequest['params']['activity_type']);
}
if (!empty($apiRequest['params']['id']) && !empty($apiRequest['params']['activity_type'])) {
$caseIds = array_intersect($caseIds, $apiRequest['params']['id']['IN']);
}
$apiRequest['params']['contact_id'] = !empty($contactIds) ? ['IN' => $contactIds] : NULL;
$apiRequest['params']['id'] = (!empty($params['id']) || !empty($apiRequest['params']['activity_type'])) ? ["IN" => $caseIds] : NULL;
}
return $apiRequest;
}
......@@ -27,46 +51,99 @@ class CRM_CiviMobileAPI_ApiWrapper_Case implements API_Wrapper {
* @return array
*/
public function toApiOutput($apiRequest, $result) {
$editAllCase = CRM_Core_Permission::check('access all cases and activities');
$editMyCase = CRM_Core_Permission::check('access my cases and activities');
$result['your_roles'] = [];
if (is_mobile_request()) {
if (!empty($result['values'])) {
$contactIds = $this->getCaseContactsId($result['values']);
if ($apiRequest['contacts_is_not_found'] ?? null) {
return [
'count' => 0,
'values' => [],
'version' => 3,
];
}
if (isset($result['details'])) {
$result['details'] = preg_replace('/ /', ' ', $result['details']);
try {
$contacts = civicrm_api3('Contact', 'get', [
'sequential' => 1,
'contact_is_deleted' => 0,
'id' => ["IN" => $contactIds],
'options' => ['limit' => 0],
])['values'];
} catch (CiviCRM_API3_Exception $e) {
$contacts = [];
}
if (!isset($result['short_description']) && isset($result['details'])) {
$result['short_description'] = $result['details'] ? mb_substr (strip_tags(preg_replace('/\s\s+/', ' ', $result['details'])), 0, 200) : '';
} else {
$result['short_description'] = '';
if (!empty($contacts)) {
foreach ($contacts as $contact) {
foreach ($result['values'] as &$case) {
if ($contact['id'] == $case['contact_id'][1]) {
if ($contact['contact_is_deleted']) {
$case['is_active'] = 0;
} else {
$case['is_active'] = 1;
}
$case['contact_display_name'] = !empty($contact['display_name']) ? $contact['display_name'] : '';
$case['contact_first_name'] = !empty($contact['first_name']) ? $contact['first_name'] : '';
$case['contact_last_name'] = !empty($contact['last_name']) ? $contact['last_name'] : '';
$case['contact_type'] = !empty($contact['contact_type']) ? $contact['contact_type'] : '';
$case['contact_image_URL'] = !empty($contact['image_URL']) ? $contact['image_URL'] : '';
}
}
}
}
}
}
if (isset($result['contacts'])) {
foreach ($result['contacts'] as $key => $contact) {
if (!isset($contact['image_URL'])) {
try {
$imageUrl = civicrm_api3('Contact', 'getvalue', [
'return' => 'image_URL',
'id' => $contact['contact_id'],
]);
} catch (Exception $e) {
$imageUrl = '';
$editAllCase = CRM_Core_Permission::check('access all cases and activities');
$editMyCase = CRM_Core_Permission::check('access my cases and activities');
$result['your_roles'] = [];
if (isset($result['contacts'])) {
foreach ($result['contacts'] as $key => $contact) {
if (!isset($contact['image_URL'])) {
try {
$imageUrl = civicrm_api3('Contact', 'getvalue', [
'return' => 'image_URL',
'id' => $contact['contact_id'],
]);
} catch (Exception $e) {
$imageUrl = '';
}
$result['contacts'][$key]['image_URL'] = $imageUrl;
}
$result['contacts'][$key]['image_URL'] = $imageUrl;
if ($contact['contact_id'] == CRM_Core_Session::singleton()->get('userID')) {
$result['your_roles'][] = $contact['role'];
}
}
}
if ($contact['contact_id'] == CRM_Core_Session::singleton()->get('userID')) {
$result['your_roles'][] = $contact['role'];
$result['can_create_activity'] = $editMyCase || $editAllCase ? 1 : 0;
$result['can_add_all_roles'] = $editAllCase ? 1 : 0;
$result['can_add_ordinary_roles'] = $editAllCase ? 1 : 0;
}
return $result;
}
/**
* Get case contact's Id
*
* @param $contributions
* @return array
*/
private function getCaseContactsId($cases) {
$contactIds = [];
if (!empty($cases)) {
if (is_array($cases) || is_object($cases)) {
foreach ($cases as $case) {
$contactIds[] = $case['contact_id'][1];
}
}
}
$result['can_create_activity'] = $editMyCase || $editAllCase ? 1 : 0;
$result['can_add_all_roles'] = $editAllCase ? 1 : 0;
$result['can_add_ordinary_roles'] = $editAllCase ? 1 : 0;
return $result;
return $contactIds;
}
}
......@@ -27,7 +27,10 @@ class CRM_CiviMobileAPI_Install_Entity_OptionValue extends CRM_CiviMobileAPI_Ins
const TAB_NOTES = 'civi_mobile_tab_notes';
const TAB_GROUPS = 'civi_mobile_tab_groups';
const TAB_TAGS = 'civi_mobile_tab_tags';
const TAB_NEWS = 'civi_mobile_tab_news';
const TAB_SURVEYS = 'civi_mobile_tab_surveys';
const TAB_PETITIONS = 'civi_mobile_tab_petitions';
const TAB_DONATIONS = 'civi_mobile_tab_donations';
/**
* Params for checking Entity existence
......@@ -125,7 +128,30 @@ class CRM_CiviMobileAPI_Install_Entity_OptionValue extends CRM_CiviMobileAPI_Ins
'value' => self::TAB_SURVEYS,
'weight' => 12,
],
[
'option_group_id' => CRM_CiviMobileAPI_Install_Entity_OptionGroup::TABS,
'label' => E::ts('News'),
'name' => self::TAB_NEWS,
'value' => self::TAB_NEWS,
'weight' => 13,
'is_active' => 0
],
[
'option_group_id' => CRM_CiviMobileAPI_Install_Entity_OptionGroup::TABS,
'label' => E::ts('Petitions'),
'name' => self::TAB_PETITIONS,
'value' => self::TAB_PETITIONS,
'weight' => 14,
'is_active' => 0
],
[
'option_group_id' => CRM_CiviMobileAPI_Install_Entity_OptionGroup::TABS,
'label' => E::ts('Donations'),
'name' => self::TAB_DONATIONS,
'value' => self::TAB_DONATIONS,
'weight' => 15,
'is_active' => 0
],
];
}
}
......@@ -35,6 +35,7 @@ class CRM_CiviMobileAPI_Page_PublicSettings extends CRM_Core_Page {
'is_civimobile_ext_has_right_folder_name' => (int) CRM_CiviMobileAPI_Utils_Extension::hasExtensionRightFolderName(),
'is_allow_cms_registration' => CRM_CiviMobileAPI_Utils_Extension::isAllowCmsRegistration(),
'is_showed_events_in_public_area' => CRM_CiviMobileAPI_Utils_Extension::isShowedEventsInPublicArea(),
'is_showed_donations_in_public_area' => CRM_CiviMobileAPI_Utils_Extension::isShowedDonationsInPublicArea(),
'is_showed_news_in_public_area' => CRM_CiviMobileAPI_Utils_Extension::isShowedNewsInPublicArea(),
'news_rss_feed_url' => CRM_CiviMobileAPI_Utils_Extension::newsRssFeedUrl(),
'cms_registration_requirements' => [
......
......@@ -196,6 +196,17 @@ class CRM_CiviMobileAPI_Upgrader extends CRM_CiviMobileAPI_Upgrader_Base {
return TRUE;
}
public function upgrade_0022() {
try {
(new CRM_CiviMobileAPI_Install_Entity_OptionGroup())->install();
(new CRM_CiviMobileAPI_Install_Entity_OptionValue())->install();
} catch (Exception $e) {
return FALSE;
}
return TRUE;
}
/**
* Installs scheduled job
*
......
......@@ -142,6 +142,13 @@ class CRM_CiviMobileAPI_Utils_CaseRole {
]);
}
public function getContactType($contactId) {
return civicrm_api3('Contact', 'getvalue', [
'return' => "contact_type",
'id' => $contactId,
]);
}
/**
* Sets clients and unassigned role
*/
......@@ -185,15 +192,16 @@ class CRM_CiviMobileAPI_Utils_CaseRole {
* Converts roles list
*
* @param $listOfRoles
* @param $contactId
*
* @return array
* @throws \CiviCRM_API3_Exception
*/
public function convertListOfRoles($listOfRoles) {
public function convertListOfRoles($listOfRoles, $contactId) {
$role = [];
foreach ($listOfRoles as $id => $relation) {
$role[] = $this->convertRole($relation);
$role[] = $this->convertRole($relation,$contactId);
}
return $role;
......@@ -207,7 +215,7 @@ class CRM_CiviMobileAPI_Utils_CaseRole {
* @return array
* @throws \CiviCRM_API3_Exception
*/
public function convertRole($listOfRoles) {
public function convertRole($listOfRoles, $contactId) {
return [
'contact_id' => $this->validateEntityExistence($listOfRoles['cid']) ? $listOfRoles['cid'] : '',
'relation' => $this->validateEntityExistence($listOfRoles['relation']) ? $listOfRoles['relation'] : '',
......@@ -217,6 +225,7 @@ class CRM_CiviMobileAPI_Utils_CaseRole {
'can_edit' => $this->canEdit(),
'can_delete' => $this->canEdit(),
'image_URL' => $this->validateEntityExistence($listOfRoles['image_URL']) ? $listOfRoles['image_URL'] : '',
'contact_type' => $this->getContactType($contactId),
];
}
......
<?php
/**
* Class provide case summary information
*/
class CRM_CiviMobileAPI_Utils_CaseSummary {
/**
* Get count of cases
*
* @param $status
* @param $params
* @return int
*/
public function getCountOfCases($status, $params) {
$contactIds = $this->getContactsIdByName($params['contact_display_name']);
$caseId = $this->getCaseIdByActivities($params['activity_type']);
if (!empty($params['id'])) {
$caseId = array_intersect($caseId, $params['id']['IN']);
}
try {
$cases = civicrm_api3('Case', 'get', [
'sequential' => 1,
'id' => ["IN" => $caseId],
'status_id' => $status,
'case_type_id' => !empty($params['case_type_id']) ? $params['case_type_id'] : NULL,
'subject' => !empty($params['subject']) ? $params['subject'] : NULL,
'contact_id' => !empty($contactIds) ? ['IN' => $contactIds] : NULL,
'start_date' => !empty($params['start_date']) ? $params['start_date'] : NULL,
'end_date' => !empty($params['end_date']) ? $params['end_date'] : NULL,
'options' => ['limit' => 0],
])['values'];
} catch (CiviCRM_API3_Exception $e) {
return 0;
}
return count($cases);
}
/**
* Get Contacts Ids by display name
*
* @param $displayName
* @return array
*/
public static function getContactsIdByName($displayName) {
try {
$contacts = civicrm_api3('Contact', 'get', [
'sequential' => 1,
'display_name' => $displayName,
'contact_is_deleted' => 0,
'options' => ['limit' => 0],
])['values'];
} catch (CiviCRM_API3_Exception $e) {
return [];
}
$contactsId = [];
if (!empty($contacts)) {
foreach ($contacts as $contact) {
$contactsId[] = $contact['id'];
}
}
return $contactsId;
}
/**
* Get Case Ids by activities
*
* @param int $activityTypeParam
* @return array
*/
public static function getCaseIdByActivities($activityTypeParam) {
if ($activityTypeParam == 1) {
$activityType = 'upcoming';
} elseif ($activityTypeParam == 2) {
$activityType = 'any';
} else {
$activityType = 'recent';
}
$userID = CRM_Core_Session::getLoggedInContactID();
$caseActivityQuery = CRM_Case_BAO_Case::getCaseActivityQuery($activityType, $userID, "civicrm_case.is_deleted = 0");
$caseActivities = CRM_Core_DAO::executeQuery($caseActivityQuery)->fetchAll();
$caseIds = [];
if (!empty($caseActivities)) {
foreach ($caseActivities as $caseActivity) {
$caseIds[] = $caseActivity['case_id'];
}
}
return $caseIds;
}
}
......@@ -116,6 +116,7 @@ class CRM_CiviMobileAPI_Utils_ContactFieldsFilter {
'sequential' => 1,
'display_name' => $contactDisplayNameParam,
'contact_id' => ["IN" => $listOfContributionContactsId],
'contact_is_deleted' => 0,
'contact_type' => $contactTypesParam,
'options' => ['limit' => 0],
'return' => ["id"]
......
......@@ -192,6 +192,11 @@ class CRM_CiviMobileAPI_Utils_Extension {
return (Civi::settings()->get('civimobile_is_allow_public_info_api') == 1 && in_array('CiviEvent', $enabledComponents)) ? 1 : 0;
}
public static function isShowedDonationsInPublicArea() {
$enabledComponents = CRM_CiviMobileAPI_Utils_CiviCRM::getEnabledComponents();
return (Civi::settings()->get('civimobile_is_allow_public_info_api') == 1 && in_array('CiviContribute', $enabledComponents)) ? 1 : 0;
}
/**
* Is showed news
*
......
......@@ -160,6 +160,7 @@ class CRM_CiviMobileAPI_Utils_Permission {
$accessAllCustomData = CRM_Core_Permission::check('access all custom data');
$accessCiviContribute = CRM_Core_Permission::check('access CiviContribute');
$makeOnlineContributions = CRM_Core_Permission::check('make online contributions');
$accessCiviCrm = CRM_Core_Permission::check('access CiviCRM');
} catch (Exception $e) {
return [];
}
......@@ -174,6 +175,7 @@ class CRM_CiviMobileAPI_Utils_Permission {
'view_petition' => $signPetition && $profileView && $accessAllCustomData ? 1 : 0,
'sign_petition' => $signPetition && $profileCreate && $accessAllCustomData ? 1 : 0,
'view_public_donation' => $accessCiviContribute && $makeOnlineContributions ? 1 : 0,
'access_civicrm' => $accessCiviCrm ? 1 : 0,
];
}
......
......@@ -40,7 +40,7 @@ class CRM_CiviMobileAPI_Utils_Statistic_Utils {
$contactsId = [];
try {
$membershipsContactIds = CRM_Core_DAO::executeQuery("SELECT DISTINCT(contact_id) FROM $membershipsTable")->fetchAll();
$membershipsContactIds = CRM_Core_DAO::executeQuery("SELECT DISTINCT(contact_id) FROM $membershipsTable RIGHT JOIN civicrm_contact ON civicrm_membership.contact_id = civicrm_contact.id AND civicrm_contact.is_deleted = 0 WHERE civicrm_membership.contact_id IS NOT NULL")->fetchAll();
} catch (Exception $e) {
return [];
}
......
<?php
use CRM_CiviMobileAPI_ExtensionUtil as E;
/**
* Gets summary for cases
*
* @param $params
* @return array
*/
function civicrm_api3_civi_mobile_case_get($params) {
$allStatuses = civicrm_api3('OptionValue', 'get', [
'sequential' => 1,
'option_group_id' => 'case_status',
]);
$id = 1;
foreach ($allStatuses['values'] as $value) {
$summary[] = ['status' => $value['label'],'amount' => (new CRM_CiviMobileAPI_Utils_CaseSummary)->getCountOfCases($value['value'], $params), 'id' => $id++];
}
return civicrm_api3_create_success($summary, $params);
}
/**
* Create new case
*
* @param $params
* @return array
*/
function civicrm_api3_civi_mobile_case_create($params) {
try {
$case = civicrm_api3('Case', 'create', $params);
} catch (CiviCRM_API3_Exception $e) {
$case = [];
}
if (!empty($case)) {
$caseId = $case['values'][$case['id']]['id'];
$contactId = CRM_Case_BAO_Case::getCaseClients($caseId)[0];
unset($params['status_id']);
$activities = CRM_Case_BAO_Case::getCaseActivity($caseId, $params, $contactId);
$activitiesId = [];
foreach ($activities['data'] as $activity) {
$activitiesId[$activity['DT_RowId']] = $activity['status_id'];
}
$mainActivityId = NULL;
foreach ($activitiesId as $activityId => $activityStatus) {
try {
civicrm_api3('Activity', 'create', [
'source_contact_id' => $contactId,
'id' => $activityId,
'activity_date_time' => $params['start_date'],
]);
} catch (CiviCRM_API3_Exception $e) {
continue;
}
if ($activityStatus == 'Completed') {
$mainActivityId = $activityId;
}
}
}
if (isset($_FILES['file'])) {
try {
civicrm_api3('Attachment', 'create', [
'name' => $_FILES['file']["name"],
'mime_type' => $_FILES['file']["type"],
'entity_id' => $mainActivityId,
'entity_table' => "civicrm_activity",
'url' => $_FILES['file']["tmp_name"],
'path' => $_FILES['file']["tmp_name"],
'upload_date' => date('Y-m-d H:i:s'),
'options' => [
'move-file' => $_FILES['file']['tmp_name']
]
]);
} catch (CiviCRM_API3_Exception $e) {
Civi::log()->warning("File not uploaded.");
}
}
return civicrm_api3_create_success($case['values']);
}
/**
* Adjust Metadata for create action
*
* The metadata is used for setting defaults, documentation & validation
* @param array $params array or parameters determined by getfields
*/
function _civicrm_api3_civi_mobile_case_create_spec(&$params) {
$params['id'] = [
'title' => 'Case Id',
'description' => E::ts('Case Id'),
'api.required' => 0,
'type' => CRM_Utils_Type::T_INT
];
$params['status_id'] = [
'title' => 'Case status',
'description' => E::ts('Case status'),
'api.required' => 0,
'type' => CRM_Utils_Type::T_STRING
];
$params['case_type_id'] = [
'title' => 'Case type',
'description' => E::ts('Case type'),
'api.required' => 0,
'type' => CRM_Utils_Type::T_INT
];
$params['contact_id'] = [
'title' => 'Case client',
'description' => E::ts('Case client'),
'api.required' => 0,
'type' => CRM_Utils_Type::T_INT
];
$params['subject'] = [
'title' => 'Case subject',
'description' => E::ts('Case subject'),
'api.required' => 0,
'type' => CRM_Utils_Type::T_STRING
];
$params['start_date'] = [
'title' => 'Start date',
'description' => E::ts('Start date'),
'api.required' => 0,
'type' => CRM_Utils_Type::T_STRING
];
$params['end_date'] = [
'title' => 'End date',
'description' => E::ts('End date'),
'api.required' => 0,
'type' => CRM_Utils_Type::T_STRING
];
$params['duration'] = [
'title