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

Merge pull request #1079 from kurund/CRM-12965

CRM-12965
parents 2265dc3b 636f1cbe
Branches
Tags
No related merge requests found
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.3 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2013 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2013
* $Id$
*
*/
class CRM_Badge_BAO_Layout extends CRM_Core_DAO_PrintLabel {
/**
* class constructor
*/
function __construct() {
parent::__construct();
}
/**
* Takes a bunch of params that are needed to match certain criteria and
* retrieves the relevant objects. It also stores all the retrieved
* values in the default array
*
* @param array $params (reference ) an assoc array of name/value pairs
* @param array $defaults (reference ) an assoc array to hold the flattened values
*
* @return object CRM_Core_DAO_PrintLabel object on success, null otherwise
* @access public
* @static
*/
static function retrieve(&$params, &$defaults) {
$printLabel = new CRM_Core_DAO_PrintLabel();
$printLabel->copyValues($params);
if ($printLabel->find(TRUE)) {
CRM_Core_DAO::storeValues($printLabel, $defaults);
return $printLabel;
}
return NULL;
}
/**
* update the is_active flag in the db
*
* @param int $id id of the database record
* @param boolean $is_active value we want to set the is_active field
*
* @return Object DAO object on success, null otherwise
*
* @access public
* @static
*/
static function setIsActive($id, $is_active) {
return CRM_Core_DAO::setFieldValue('CRM_Core_DAO_PrintLabel', $id, 'is_active', $is_active);
}
/**
* Function to add a name label
*
* @param array $params reference array contains the values submitted by the form
* @param array $ids reference array contains the id
*
* @access public
* @static
*
* @return object
*/
static function create(&$params) {
$params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
$params['is_default'] = CRM_Utils_Array::value('is_default', $params, FALSE);
$params['is_reserved'] = CRM_Utils_Array::value('is_reserved', $params, FALSE);
$params['label_type_id'] = CRM_Core_OptionGroup::getValue('label_type', 'Event Badge', 'name');
// check if new layout is create, if so set the created_id (if not set)
if (empty($params['id'])) {
if (empty($params['created_id'])) {
$session = CRM_Core_Session::singleton();
$params['created_id'] = $session->get('userID');
}
}
if (!isset($params['id']) && !isset($params['name'])) {
$params['name'] = CRM_Utils_String::munge($params['title'], '_', 64);
}
// action is taken depending upon the mode
$printLabel = new CRM_Core_DAO_PrintLabel();
$printLabel->copyValues($params);
if ($params['is_default']) {
$query = "UPDATE civicrm_print_label SET is_default = 0";
CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
}
$printLabel->save();
return $printLabel;
}
/**
* Function to delete name labels
*
* @param int $printLabelId ID of the name label to be deleted.
*
* @access public
* @static
*/
static function del($printLabelId) {
$printLabel = new CRM_Core_DAO_PrintLabel();
$printLabel->id = $printLabelId;
$printLabel->delete();
}
}
......@@ -54,30 +54,82 @@ class CRM_Badge_Form_Layout extends CRM_Admin_Form {
}
$this->applyFilter('__ALL__', 'trim');
$this->add('text',
'name',
ts('Name'),
CRM_Core_DAO::getAttribute('CRM_Core_DAO_PrintLabel', 'name'),
TRUE
);
$this->addRule('name',
ts('Name already exists in Database.'),
'objectExists',
array('CRM_Core_DAO_PrintLabel', $this->_id)
);
$this->addRule('name',
ts('Name can only consist of alpha-numeric characters'),
'variable'
);
$this->add('text', 'title', ts('Title'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_PrintLabel', 'display_name'));
$this->add('text', 'description', ts('Description'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_PrintLabel', 'description'));
$this->add('checkbox', 'is_active', ts('Enabled?'));
$this->add('text', 'title', ts('Title'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_PrintLabel', 'title'), true);
$labelStyle = CRM_Core_PseudoConstant::get('CRM_Core_DAO_PrintLabel', 'label_format_id');
$this->add('select', 'label_format_id', ts('Label Style'), array('' => ts('- select -')) + $labelStyle, TRUE);
$this->add('text', 'description', ts('Description'),
CRM_Core_DAO::getAttribute('CRM_Core_DAO_PrintLabel', 'description'));
// get the tokens
$tokens = CRM_Core_SelectValues::contactTokens();
asort($tokens);
$fontSizes = CRM_Core_BAO_LabelFormat::getFontSizes();
$fontNames = CRM_Core_BAO_LabelFormat::getFontNames('name_badge');
$textAlignment = CRM_Core_BAO_LabelFormat::getTextAlignments();
$rowCount = 3;
for ( $i =1; $i <= $rowCount; $i++ ) {
$this->add('select', "token[$i]", ts('Token'), array('' => ts('- none -')) + $tokens);
$this->add('select', "font_name[$i]", ts('Font Name'), $fontNames);
$this->add('select', "font_size[$i]", ts('Font Size'), $fontSizes);
$this->add('select', "text_alignment[$i]", ts('Alignment'), $textAlignment);
}
$rowCount++;
$this->assign('rowCount', $rowCount);
$this->add('checkbox', 'add_barcode', ts('Barcode?'));
unset($textAlignment['J']);
$this->add('select', "barcode_alignment", ts('Alignment'), $textAlignment);
$this->add('checkbox', 'is_default', ts('Default?'));
$this->add('checkbox', 'is_active', ts('Enabled?'));
$this->add('checkbox', 'is_reserved', ts('Reserved?'));
if ($this->_action == CRM_Core_Action::UPDATE && CRM_Core_DAO::getFieldValue('CRM_Core_DAO_PrintLabel', $this->_id, 'is_reserved')) {
$this->freeze(array('name', 'description', 'is_active'));
$this->freeze(array('title', 'description', 'is_active'));
}
}
/**
* This function sets the default values for the form. MobileProvider that in edit/view mode
* the default values are retrieved from the database
*
* @access public
*
* @return None
*/
function setDefaultValues() {
if (isset($this->_id) && empty($this->_values)) {
$this->_values = array();
$params = array('id' => $this->_id);
CRM_Badge_BAO_Layout::retrieve($params, $this->_values );
}
$defaults = $this->_values;
$data = get_object_vars(json_decode($this->_values['data']));
$specialFields = array('token', 'font_name', 'font_size', 'text_alignment');
foreach($specialFields as $field) {
$defaults[$field] = get_object_vars($data[$field]);
}
$defaults['add_barcode'] = $data['add_barcode'];
$defaults['barcode_alignment'] = $data['barcode_alignment'];
$defaults['label_format_id'] = $data['label_format_id'];
if ($this->_action == CRM_Core_Action::DELETE && isset($defaults['title'])) {
$this->assign('delName', $defaults['title']);
}
// its ok if there is no element called is_active
$defaults['is_active'] = ($this->_id) ? CRM_Utils_Array::value('is_active', $defaults) : 1;
return $defaults;
}
/**
......@@ -88,41 +140,26 @@ class CRM_Badge_Form_Layout extends CRM_Admin_Form {
* @return None
*/
public function postProcess() {
/*
if ($this->_action & CRM_Core_Action::DELETE) {
CRM_Core_BAO_LocationType::del($this->_id);
CRM_Core_Session::setStatus(ts('Selected Location type has been deleted.'), ts('Record Deleted'), 'success');
return;
}
// store the submitted values in an array
$params = $this->exportValues();
$params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
$params['is_default'] = CRM_Utils_Array::value('is_default', $params, FALSE);
// action is taken depending upon the mode
$locationType = new CRM_Core_DAO_PrintLabel();
$locationType->name = $params['name'];
$locationType->display_name = $params['display_name'];
$locationType->vcard_name = $params['vcard_name'];
$locationType->description = $params['description'];
$locationType->is_active = $params['is_active'];
$locationType->is_default = $params['is_default'];
if ($params['is_default']) {
$query = "UPDATE civicrm_location_type SET is_default = 0";
CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
}
if ($this->_action & CRM_Core_Action::UPDATE) {
$locationType->id = $this->_id;
}
$locationType->save();
CRM_Core_Session::setStatus(ts("The location type '%1' has been saved.",
array(1 => $locationType->name)
), ts('Saved'), 'success');
*/
if ($this->_action & CRM_Core_Action::DELETE) {
CRM_Badge_BAO_Layout::del($this->_id);
CRM_Core_Session::setStatus(ts('Selected badge layout has been deleted.'), ts('Record Deleted'), 'success');
return;
}
$params = $data = $this->controller->exportValues($this->_name);
unset($data['qfKey']);
$params['data'] = json_encode($data);
if ($this->_id) {
$params['id'] = $this->_id;
}
// store the submitted values in an array
CRM_Badge_BAO_Layout::create($params);
CRM_Core_Session::setStatus(ts("The badge layout '%1' has been saved.",
array(1 => $params['title'])
), ts('Saved'), 'success');
}
}
......@@ -52,7 +52,7 @@ class CRM_Badge_Page_Layout extends CRM_Core_Page_Basic {
* @return string Classname of BAO.
*/
function getBAOName() {
return 'CRM_Core_DAO_PrintLabel';
return 'CRM_Badge_BAO_Layout';
}
/**
......
......@@ -226,6 +226,23 @@ class CRM_Core_BAO_LabelFormat extends CRM_Core_DAO_OptionValue {
);
}
/**
* Get text alignment recognized by the TCPDF package used to create PDF labels.
*
* @param void
*
* @return array array of alignments
* @access public
* @static
*/
public static function getTextAlignments() {
return array(
'R' => ts('Right'),
'L' => ts('Left'),
'J' => ts('Justify'),
);
}
/**
* Get Option Group ID for Label Formats
*
......
......@@ -307,7 +307,14 @@ abstract class CRM_Core_Page_Basic extends CRM_Core_Page {
$values['class'] = 'reserved';
// check if object is relationship type
$object_type = get_class($object);
if ($object_type == 'CRM_Contact_BAO_RelationshipType' || $object_type == 'CRM_Core_BAO_LocationType') {
$exceptions = array(
'CRM_Contact_BAO_RelationshipType',
'CRM_Core_BAO_LocationType',
'CRM_Badge_BAO_Layout',
);
if (in_array($object_type, $exceptions)) {
$newAction = CRM_Core_Action::VIEW + CRM_Core_Action::UPDATE;
}
else {
......
......@@ -767,11 +767,11 @@
<path>civicrm/admin/badgelayout</path>
<title>Badge Layout</title>
<page_callback>CRM_Badge_Page_Layout</page_callback>
<access_arguments>administer CiviCRM,access CiviEvent</access_arguments>
<access_arguments>administer CiviCRM</access_arguments>
</item>
<item>
<path>civicrm/admin/badgelayout/add</path>
<page_callback>CRM_Badge_Form_Layout</page_callback>
<access_arguments>administer CiviCRM,access CiviEvent</access_arguments>
<access_arguments>administer CiviCRM</access_arguments>
</item>
</menu>
......@@ -30,24 +30,55 @@
{if $action eq 8}
<div class="messages status no-popup">
<div class="icon inform-icon"></div>
{ts}WARNING: Deleting this option will result in the loss of all location type records which use the option.{/ts} {ts}This may mean the loss of a substantial amount of data, and the action cannot be undone.{/ts} {ts}Do you want to continue?{/ts}
{ts}This may mean the loss of a substantial amount of data, and the action cannot be undone.{/ts} {ts}Do you want to continue?{/ts}
</div>
{else}
<table class="form-layout-compressed">
<!--tr class="crm-badge-layout-form-block-label">
<td class="label">{$form.name.label}</td>
<td>{$form.name.html}<br/>
<span class="description">{ts}WARNING: Do NOT use spaces in the Location Name.{/ts}</span>
</td>
</tr-->
<tr class="crm-badge-layout-form-block-title">
<td class="label">{$form.title.label}</td>
<td>{$form.title.html}</td>
</tr>
<tr class="crm-badge-layout-form-block-label_format_id">
<td class="label">{$form.label_format_id.label}</td>
<td>{$form.label_format_id.html}</td>
</tr>
<tr class="crm-badge-layout-form-block-description">
<td class="label">{$form.description.label}</td>
<td>{$form.description.html}</td>
</tr>
<tr class="crm-badge-layout-form-block-elements">
<td class="label">{ts}Elements{/ts}</td>
<td>
<table class="form-layout-compressed">
<tr>
<td>{ts}Row{/ts}</td>
<td>{ts}Label{/ts}</td>
<td>{ts}Font{/ts}</td>
<td>{ts}Size{/ts}</td>
<td>{ts}Alignment{/ts}</td>
</tr>
{section name='i' start=1 loop=$rowCount}
{assign var='rowNumber' value=$smarty.section.i.index}
<tr>
<td>#{$rowNumber}</td>
<td>{$form.token.$rowNumber.html|crmAddClass:twenty}</td>
<td>{$form.font_name.$rowNumber.html}</td>
<td>{$form.font_size.$rowNumber.html}</td>
<td>{$form.text_alignment.$rowNumber.html}</td>
</tr>
{/section}
</table>
</td>
</tr>
<tr class="crm-badge-layout-form-block-attachment">
<td colspan="2">
</td>
</tr>
<tr class="crm-badge-layout-form-block-add_barcode">
<td class="label">{$form.add_barcode.label}</td>
<td>{$form.add_barcode.html}&nbsp;&nbsp;&nbsp;{ts}on{/ts}&nbsp;&nbsp;&nbsp;{$form.barcode_alignment.html}</td>
</tr>
<tr class="crm-badge-layout-form-block-is_active">
<td class="label">{$form.is_active.label}</td>
<td>{$form.is_active.html}</td>
......
......@@ -24,7 +24,7 @@
+--------------------------------------------------------------------+
*}
<div id="help">
{ts}Badge Layout.{/ts}
{ts}Badge Layout screen for creating custom labels{/ts}
</div>
{if $action eq 1 or $action eq 2 or $action eq 8}
......
......@@ -41,12 +41,18 @@
<field>
<name>label_format_id</name>
<type>int unsigned</type>
<comment>Implicit FK to civicrm_option_value row in label_format option group</comment>
<pseudoconstant>
<optionGroupName>name_badge</optionGroupName>
</pseudoconstant>
<comment>Implicit FK to civicrm_option_value row in name_badge option group</comment>
<add>4.4</add>
</field>
<field>
<name>label_type_id</name>
<type>int unsigned</type>
<pseudoconstant>
<optionGroupName>label_type</optionGroupName>
</pseudoconstant>
<comment>Implicit FK to civicrm_option_value row in NEW label_type option group</comment>
<add>4.4</add>
</field>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment