Commit 4c6d48fc authored by Agiliway Group, Inc's avatar Agiliway Group, Inc
Browse files

Release 4.0.4

parent 1ead0f89
......@@ -10,6 +10,8 @@ class CRM_CiviMobileAPI_Utils_QRcode {
* Saves QRcode in Participant's custom fields
*
* @param $participantId
*
* @throws \api_Exception
*/
public static function generateQRcode($participantId) {
$participant = new CRM_Event_BAO_Participant();
......@@ -28,7 +30,8 @@ class CRM_CiviMobileAPI_Utils_QRcode {
$config = CRM_Core_Config::singleton();
$directoryName = $config->uploadDir . DIRECTORY_SEPARATOR . 'qr';
CRM_Utils_File::createDir($directoryName);
$path = $directoryName . DIRECTORY_SEPARATOR . 'participantId_' . $participantId . '.png';
$imageName = self::generateImageName($participantId);
$path = $directoryName . DIRECTORY_SEPARATOR . $imageName;
$params = [
'attachFile_1' => [
'uri' => $path,
......@@ -40,17 +43,61 @@ class CRM_CiviMobileAPI_Utils_QRcode {
\PHPQRCode\QRcode::png("http://civimobile.org/events?qr=" . $participantId . '_' . $hashCode, $path, 'L', 9, 3);
CRM_Core_BAO_File::processAttachment($params, 'civicrm_participant', $participantId);
$entityFileDAO = new CRM_Core_DAO_EntityFile();
$entityFileDAO->entity_table = 'civicrm_participant';
$entityFileDAO->entity_id = $participantId;
$entityFileDAO->find(true);
$fileId = $entityFileDAO->file_id;
$protocol = CRM_CiviMobileAPI_Utils_Website::getProtocol();
$fileUrlOther = $protocol . $_SERVER['SERVER_NAME'] . CRM_Utils_System::url('civicrm/file', 'reset=1&filename=participantId_' . $participantId . '.png&mime-type=image/png');
$fileUrl = $protocol . $_SERVER['SERVER_NAME'] . CRM_Utils_System::url('civicrm/file', 'reset=1&id=' . $fileId . '&eid=' . $participantId);
$fileUrl = self::getFileUrl($participantId);
CRM_CiviMobileAPI_Utils_ParticipantQrCode::setQrCodeToParticipant($participantId, $eventId, $contactId, $hashCode, $fileUrl);
}
}
/**
* Gets file url to qr code
*
* @param $participantId
*
* @return string
*/
private static function getFileUrl($participantId) {
$url = '';
$files = CRM_Core_BAO_File::getEntityFile('civicrm_participant', $participantId);
foreach ($files as $file) {
if ((!empty($file['fileName']) && $file['fileName'] == self::generateImageName($participantId))
|| (!empty($file['cleanName']) && $file['cleanName'] == self::generateImageName($participantId))) {
$url = $file['url'];
}
}
if (substr($url, 0, 1) == '/') {
$url = substr($url, 1);
}
$url = urldecode($url);
$currentCMS = CRM_CiviMobileAPI_Utils_CmsUser::getInstance()->getSystem();
if ($currentCMS == CRM_CiviMobileAPI_Utils_CmsUser::CMS_WORDPRESS ) {
$url = str_replace("wp-admin/admin.php", "index.php", $url);
}
if ($currentCMS == CRM_CiviMobileAPI_Utils_CmsUser::CMS_JOOMLA ) {
$url = str_replace("administrator/", "", CIVICRM_UF_BASEURL) . $url;
$url = str_replace("administrator/", "index.php", $url);
} else {
$url = CIVICRM_UF_BASEURL . $url;
}
$url = htmlspecialchars_decode($url);
return $url;
}
/**
* Generates image name
*
* @param $participantId
*
* @return string
*/
private static function generateImageName($participantId) {
return 'participantId_' . $participantId . '.png';
}
}
......@@ -16,6 +16,10 @@ class CRM_CiviMobileAPI_Utils_RestPath {
$restPath = $this->getWordpressRestPath();
}
if ($currentCMS == CRM_CiviMobileAPI_Utils_CmsUser::CMS_JOOMLA ) {
$restPath = $this->getJoomlaRestPath();
}
return $restPath;
}
......@@ -53,4 +57,13 @@ class CRM_CiviMobileAPI_Utils_RestPath {
return $restPath;
}
/**
* Gets Joomla 'rest path' for CiviCRM API
*
* @return string
*/
private function getJoomlaRestPath() {
return '/administrator' . Civi::paths()->getUrl("[civicrm.root]/extern/rest.php");
}
}
......@@ -464,6 +464,10 @@ function civimobileapi_civicrm_buildForm($formName, &$form) {
CRM_Core_Region::instance('page-body')->add([
'template' => "{$templatePath}/qrcode-checkin-event-options.tpl"
]);
CRM_Core_Region::instance('page-body')->add([
'style' => '.custom-group-' . CRM_CiviMobileAPI_Install_Entity_CustomGroup::QR_USES . ' { display:none;}'
]);
}
if ($formName == 'CRM_Event_Form_Participant' && $action == CRM_Core_Action::ADD) {
......@@ -475,3 +479,25 @@ function civimobileapi_civicrm_buildForm($formName, &$form) {
}
}
/**
* Implements hook_civicrm_alterBadge().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_alterBadge/
*/
function civimobileapi_civicrm_alterBadge( &$labelName, &$label, &$format, &$participant ) {
$qrCodeCustomFieldName = "custom_" . CRM_CiviMobileAPI_Utils_CustomField::getId(CRM_CiviMobileAPI_Install_Entity_CustomGroup::QR_CODES, CRM_CiviMobileAPI_Install_Entity_CustomField::QR_IMAGE);
if (isset($format['values'][$qrCodeCustomFieldName])) {
$link = $format['values'][$qrCodeCustomFieldName];
$label->printImage($link, '100', '0' , 30, 30);
//hide label
if (!empty($format['token'])) {
foreach ($format['token'] as $key => $token) {
if ($token['token'] == '{participant.' . $qrCodeCustomFieldName . '}') {
$format['token'][$key]['value'] = '';
}
}
}
}
}
......@@ -14,8 +14,8 @@
<url desc="Support">https://agiliway.com</url>
<url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url>
</urls>
<releaseDate>2019-08-06</releaseDate>
<version>4.0.3</version>
<releaseDate>2019-08-23</releaseDate>
<version>4.0.4</version>
<develStage>stable</develStage>
<compatibility>
<ver>4.7</ver>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment