Newer
Older
function setAssignees($assignees) {
$this->_assignees = $assignees;
$this->_fields = array();
}
function getAssignees() {
return $this->_assignees;
}
if (!isset($this->_assignee))
$this->_assignee = $this->getField('assignee')->getClean();
function getComments() {
return $this->getField('comments')->getClean();
function refer() {
return $this->getField('refer')->getClean();
}
}
class ClaimForm extends AssignmentForm {
var $_fields;
function setFields($fields) {
$this->_fields = $fields;
parent::setFields($fields);
}
function getFields() {
if ($this->_fields)
return $this->_fields;
// Disable && hide assignee field selection
if (isset($fields['assignee'])) {
$visibility = new VisibilityConstraint(
new Q(array()), VisibilityConstraint::HIDDEN);
$fields['assignee']->set('visibility', $visibility);
}
// Change coments placeholder to reflect claim
if (isset($fields['comments'])) {
$fields['comments']->configure('placeholder',
__('Optional reason for the claim'));
}
$this->setFields($fields);
return $this->fields;
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
class ReleaseForm extends Form {
static $id = 'unassign';
function getFields() {
if ($this->fields)
return $this->fields;
$fields = array(
'comments' => new TextareaField(array(
'id' => 1, 'label'=> '', 'required'=>false, 'default'=>'',
'configuration' => array(
'html' => true,
'size' => 'small',
'placeholder' => __('Optional reason for releasing assignment'),
),
)
),
);
$this->setFields($fields);
return $this->fields;
}
function getField($name) {
if (($fields = $this->getFields())
&& isset($fields[$name]))
return $fields[$name];
}
function isValid($include=false) {
if (!parent::isValid($include))
return false;
return !$this->errors();
}
function getComments() {
return $this->getField('comments')->getClean();
}
}
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
class MarkAsForm extends Form {
static $id = 'markAs';
function getFields() {
if ($this->fields)
return $this->fields;
$fields = array(
'comments' => new TextareaField(array(
'id' => 1, 'label'=> '', 'required'=>false, 'default'=>'',
'configuration' => array(
'html' => true,
'size' => 'small',
'placeholder' => __('Optional reason for marking ticket as (un)answered'),
),
)
),
);
$this->setFields($fields);
return $this->fields;
}
function getField($name) {
if (($fields = $this->getFields())
&& isset($fields[$name]))
return $fields[$name];
}
function isValid($include=false) {
if (!parent::isValid($include))
return false;
return !$this->errors();
}
function getComments() {
return $this->getField('comments')->getClean();
}
}
class ReferralForm extends Form {
static $id = 'refer';
var $_target = null;
var $_choices = null;
var $_prompt = '';
function getFields() {
if ($this->fields)
return $this->fields;
$fields = array(
'target' => new ChoiceField(array(
'id'=>1,
'label' => __('Referee'),
'flags' => hexdec(0X450F3),
'required' => true,
'validator-error' => __('Selection required'),
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
'choices' => array(
'agent' => __('Agent'),
'team' => __('Team'),
'dept' => __('Department'),
),
)
),
'agent' => new ChoiceField(array(
'id'=>2,
'label' => '',
'flags' => hexdec(0X450F3),
'required' => true,
'configuration'=>array('prompt'=>__('Select Agent')),
'validator-error' => __('Agent selection required'),
'visibility' => new VisibilityConstraint(
new Q(array('target__eq'=>'agent')),
VisibilityConstraint::HIDDEN
),
)
),
'team' => new ChoiceField(array(
'id'=>3,
'label' => '',
'flags' => hexdec(0X450F3),
'required' => true,
'validator-error' => __('Team selection required'),
'configuration'=>array('prompt'=>__('Select Team')),
'visibility' => new VisibilityConstraint(
new Q(array('target__eq'=>'team')),
VisibilityConstraint::HIDDEN
),
)
),
'dept' => new DepartmentField(array(
'id'=>4,
'label' => '',
'flags' => hexdec(0X450F3),
'required' => true,
'validator-error' => __('Dept. selection required'),
'configuration'=>array('prompt'=>__('Select Department')),
'visibility' => new VisibilityConstraint(
new Q(array('target__eq'=>'dept')),
VisibilityConstraint::HIDDEN
),
)
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
'label'=> '',
'required'=>false,
'default'=>'',
'configuration' => array(
'html' => true,
'size' => 'small',
'placeholder' => __('Optional reason for the referral'),
),
)
),
);
$this->setFields($fields);
return $this->fields;
}
function getField($name) {
if (($fields = $this->getFields())
&& isset($fields[$name]))
return $fields[$name];
}
function isValid($include=false) {
if (!parent::isValid($include) || !($f=$this->getField('target')))
return false;
// Do additional assignment validation
$referee = $this->getReferee();
case $referee instanceof Staff:
if (!$referee->isAvailable())
$f->addError(__('Agent is unavailable for assignment'));
break;
case $referee instanceof Team:
elseif (!$referee->getNumMembers())
$f->addError(__('Team does not have members'));
break;
case $referee instanceof Dept:
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
break;
default:
$f->addError(__('Unknown selection'));
}
return !$this->errors();
}
function render($options) {
switch(strtolower($options['template'])) {
case 'simple':
$inc = STAFFINC_DIR . 'templates/dynamic-form-simple.tmpl.php';
break;
default:
throw new Exception(sprintf(__('%s: Unknown template style %s'),
'FormUtils', $options['template']));
}
$form = $this;
include $inc;
}
function setChoices($field, $choices, $prompt='') {
if (!($f= $this->getField($field)))
return;
$f->set('choices', $choices);
return $f;
$target = $this->getField('target')->getClean();
if (!$target || !($f=$this->getField($target)))
return null;
$id = $f->getClean();
switch($target) {
case 'agent':
return Staff::lookup($id);
case 'team':
return Team::lookup($id);
case 'dept':
return Dept::lookup($id);
}
}
function getComments() {
return $this->getField('comments')->getClean();
}
}
class TransferForm extends Form {
static $id = 'transfer';
var $_dept = null;
function __construct($source=null, $options=array()) {
parent::__construct($source, $options);
function getFields() {
if ($this->fields)
return $this->fields;
$fields = array(
'dept' => new DepartmentField(array(
'id'=>1,
'label' => __('Department'),
'flags' => hexdec(0X450F3),
'required' => true,
'validator-error' => __('Department selection is required'),
'refer' => new BooleanField(array(
'id'=>2, 'label'=>'', 'required'=>false, 'default'=>false,
'configuration'=>array(
'desc' => 'Maintain referral access to current department')
)),
'label'=> '',
'required'=>false,
'default'=>'',
'configuration' => array(
'html' => true,
'placeholder' => __('Optional reason for the transfer'),
),
)
),
);
$this->setFields($fields);
return $this->fields;
function isValid($include=false) {
if (!parent::isValid($include))
return false;
// Do additional validations
if (!($dept = $this->getDept()))
$this->getField('dept')->addError(
__('Unknown department'));
return !$this->errors();
function render($options) {
switch(strtolower($options['template'])) {
case 'simple':
$inc = STAFFINC_DIR . 'templates/dynamic-form-simple.tmpl.php';
break;
default:
throw new Exception(sprintf(__('%s: Unknown template style %s'),
get_class(), $options['template']));
}
$form = $this;
include $inc;
function refer() {
return $this->getField('refer')->getClean();
}
function getDept() {
if (!isset($this->_dept)) {
if (($id = $this->getField('dept')->getClean()))
$this->_dept = Dept::lookup($id);
}
return $this->_dept;
/**
* FieldUnchanged
*
* Thrown in the to_database() method to indicate the value should not be
* saved in the database (it wasn't changed in the request)
*/
class FieldUnchanged extends Exception {}