Skip to content
Snippets Groups Projects
Commit 6d4a64c8 authored by Kurund Jalmi's avatar Kurund Jalmi
Browse files

code cleanup and also added 'Save and Preview' option CRM-12965

parent 80bb6572
Branches
Tags
No related merge requests found
......@@ -235,7 +235,7 @@ class CRM_Badge_BAO_Badge {
'stretchtext' => 0,
);
$this->pdf->write1DBarcode($data['current_value'], 'C128', $xAlign, $y + $this->pdf->height - 10, '',
$this->pdf->write1DBarcode($data['current_value'], 'C128', $xAlign, $y + $this->pdf->height - 10, '65',
12, 0.4, $style, 'B');
}
else {
......@@ -244,7 +244,7 @@ class CRM_Badge_BAO_Badge {
switch ($formattedRow['barcode']['alignment']) {
case 'L':
$xAlign += -8;
$xAlign += -4;
break;
case 'R':
$xAlign += 63;
......@@ -263,8 +263,8 @@ class CRM_Badge_BAO_Badge {
'position' => '',
);
$this->pdf->write2DBarcode($data['current_value'], 'QRCODE,Q', $xAlign, $y + $this->pdf->height - 23, 30,
30, $style, 'B');
$this->pdf->write2DBarcode($data['current_value'], 'QRCODE,H', $xAlign, $y + $this->pdf->height - 20, 23,
23, $style, 'B');
}
}
}
......@@ -298,5 +298,96 @@ class CRM_Badge_BAO_Badge {
}
$this->pdf->SetXY($x, $y);
}
/**
* function to build badges parameters before actually creating badges.
*
* @param array $params associated array of submitted values
* @params object $form form/controller object
*
* @return void
* @access public
* @static
*/
public static function buildBadges(&$params, &$form) {
// get name badge layout info
$layoutInfo = CRM_Badge_BAO_Layout::buildLayout($params);
// spit / get actual field names from token
$returnProperties = array();
if (!empty($layoutInfo['data']['token'])) {
foreach ($layoutInfo['data']['token'] as $index => $value) {
$element = '';
if ($value) {
$token = CRM_Utils_Token::getTokens($value);
if (key($token) == 'contact') {
$element = $token['contact'][0];
}
elseif (key($token) == 'event') {
$element = $token['event'][0];
//FIX ME - we need to standardize event token names
if (!strpos($element, 'event_')) {
$element = 'event_' . $element;
}
}
elseif (key($token) == 'participant') {
$element = $token['participant'][0];
}
// build returnproperties for query
$returnProperties[$element] = 1;
}
// add actual field name to row element
$layoutInfo['data']['rowElements'][$index] = $element;
}
}
// add additional required fields for query execution
$additionalFields = array('participant_register_date', 'participant_id', 'event_id', 'contact_id');
foreach ($additionalFields as $field) {
$returnProperties[$field] = 1;
}
if ($form->_single) {
$queryParams = NULL;
}
else {
$queryParams = $form->get('queryParams');
}
$query = new CRM_Contact_BAO_Query($queryParams, $returnProperties, NULL, FALSE, FALSE,
CRM_Contact_BAO_Query::MODE_EVENT
);
list($select, $from, $where, $having) = $query->query();
if (empty($where)) {
$where = "WHERE {$form->_componentClause}";
}
else {
$where .= " AND {$form->_componentClause}";
}
$sortOrder = NULL;
if ($form->get(CRM_Utils_Sort::SORT_ORDER)) {
$sortOrder = $form->get(CRM_Utils_Sort::SORT_ORDER);
if (!empty($sortOrder)) {
$sortOrder = " ORDER BY $sortOrder";
}
}
$queryString = "$select $from $where $having $sortOrder";
$dao = CRM_Core_DAO::executeQuery($queryString);
$rows = array();
while ($dao->fetch()) {
$rows[$dao->participant_id] = array();
foreach ($returnProperties as $key => $dontCare) {
$rows[$dao->participant_id][$key] = isset($dao->$key) ? $dao->$key : NULL;
}
}
$eventBadgeClass = new CRM_Badge_BAO_Badge();
$eventBadgeClass->createLabels($rows, $layoutInfo);
}
}
......@@ -46,9 +46,19 @@ class CRM_Badge_Form_Layout extends CRM_Admin_Form {
* @access public
*/
public function buildQuickForm() {
parent::buildQuickForm();
if ($this->_action & CRM_Core_Action::DELETE) {
$this->addButtons(array(
array(
'type' => 'next',
'name' => ts('Delete'),
'isDefault' => TRUE,
),
array(
'type' => 'cancel',
'name' => ts('Cancel'),
),
)
);
return;
}
......@@ -110,6 +120,23 @@ class CRM_Badge_Form_Layout extends CRM_Admin_Form {
$this->add('checkbox', 'is_reserved', ts('Reserved?'));
$this->addFormRule(array('CRM_Badge_Form_Layout', 'formRule'));
$this->addButtons(array(
array(
'type' => 'next',
'name' => ts('Save'),
'isDefault' => TRUE,
),
array(
'type' => 'refresh',
'name' => ts('Save and Preview'),
),
array(
'type' => 'cancel',
'name' => ts('Cancel'),
),
)
);
}
/**
......@@ -181,7 +208,7 @@ class CRM_Badge_Form_Layout extends CRM_Admin_Form {
return;
}
$params = $data = $this->controller->exportValues($this->_name);
$params = $data = $this->exportValues();
unset($data['qfKey']);
$params['data'] = json_encode($data);
......@@ -191,10 +218,27 @@ class CRM_Badge_Form_Layout extends CRM_Admin_Form {
}
// store the submitted values in an array
CRM_Badge_BAO_Layout::create($params);
$badgeInfo = CRM_Badge_BAO_Layout::create($params);
if (isset($params['_qf_Layout_refresh'])) {
$params['badge_id'] = $badgeInfo->id;
self::buildPreview($params);
}
else {
CRM_Core_Session::setStatus(ts("The badge layout '%1' has been saved.",
array(1 => $params['title'])
), ts('Saved'), 'success');
}
}
public function buildPreview(&$params) {
// get a max participant id
$participantID = CRM_Core_DAO::singleValueQuery('select max(id) from civicrm_participant');
$this->_single = TRUE;
$this->_participantIds = array($participantID);
$this->_componentClause = " civicrm_participant.id = $participantID ";
CRM_Core_Session::setStatus(ts("The badge layout '%1' has been saved.",
array(1 => $params['title'])
), ts('Saved'), 'success');
CRM_Badge_BAO_Badge::buildBadges($params, $this);
}
}
......@@ -47,6 +47,11 @@ class CRM_Event_Form_Task_Badge extends CRM_Event_Form_Task {
*/
public $_single = FALSE;
/**
* component clause
*/
public $_componentClause;
/**
* build all the data structures needed to build the form
*
......@@ -54,7 +59,8 @@ class CRM_Event_Form_Task_Badge extends CRM_Event_Form_Task {
*
* @return void
* @access public
*/ function preProcess() {
*/
function preProcess() {
$this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
if ($this->_context == 'view') {
$this->_single = TRUE;
......@@ -110,85 +116,7 @@ class CRM_Event_Form_Task_Badge extends CRM_Event_Form_Task {
*/
public function postProcess() {
$params = $this->controller->exportValues($this->_name);
// get name badge layout info
$layoutInfo = CRM_Badge_BAO_Layout::buildLayout($params);
// spit / get actual field names from token
$returnProperties = array();
if (!empty($layoutInfo['data']['token'])) {
foreach ($layoutInfo['data']['token'] as $index => $value) {
$element = '';
if ($value) {
$token = CRM_Utils_Token::getTokens($value);
if (key($token) == 'contact') {
$element = $token['contact'][0];
}
elseif (key($token) == 'event') {
$element = $token['event'][0];
//FIX ME - we need to standardize event token names
if (!strpos($element, 'event_')) {
$element = 'event_' . $element;
}
}
elseif (key($token) == 'participant') {
$element = $token['participant'][0];
}
// build returnproperties for query
$returnProperties[$element] = 1;
}
// add actual field name to row element
$layoutInfo['data']['rowElements'][$index] = $element;
}
}
// add additional required fields for query execution
$additionalFields = array('participant_register_date', 'participant_id', 'event_id', 'contact_id');
foreach ($additionalFields as $field) {
$returnProperties[$field] = 1;
}
if ($this->_single) {
$queryParams = NULL;
}
else {
$queryParams = $this->get('queryParams');
}
$query = new CRM_Contact_BAO_Query($queryParams, $returnProperties, NULL, FALSE, FALSE,
CRM_Contact_BAO_Query::MODE_EVENT
);
list($select, $from, $where, $having) = $query->query();
if (empty($where)) {
$where = "WHERE {$this->_componentClause}";
}
else {
$where .= " AND {$this->_componentClause}";
}
$sortOrder = NULL;
if ($this->get(CRM_Utils_Sort::SORT_ORDER)) {
$sortOrder = $this->get(CRM_Utils_Sort::SORT_ORDER);
if (!empty($sortOrder)) {
$sortOrder = " ORDER BY $sortOrder";
}
}
$queryString = "$select $from $where $having $sortOrder";
$dao = CRM_Core_DAO::executeQuery($queryString);
$rows = array();
while ($dao->fetch()) {
$rows[$dao->participant_id] = array();
foreach ($returnProperties as $key => $dontCare) {
$rows[$dao->participant_id][$key] = isset($dao->$key) ? $dao->$key : NULL;
}
}
$eventBadgeClass = new CRM_Badge_BAO_Badge();
$eventBadgeClass->createLabels($rows, $layoutInfo);
CRM_Badge_BAO_Badge::buildBadges($params, $this);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment