Newer
Older
}
$glue = $Q->isOred() ? ' || ' : ' && ';
$expression = implode($glue, $expr);
if (count($expr) > 1)
$expression = '('.$expression.')';
if ($Q->isNegated)
$expression = '!'.$expression;
return $expression;
}
}
class AssignmentForm extends Form {
static $id = 'assign';
var $_assignee = null;
function getFields() {
if ($this->fields)
return $this->fields;
$fields = array(
'assignee' => new AssigneeField(array(
'id'=>1, 'label' => __('Assignee'),
'flags' => hexdec(0X450F3), 'required' => true,
'validator-error' => __('Assignee selection required'),
'configuration' => array(
'criteria' => array(
'available' => true,
),
),
'refer' => new BooleanField(array(
'id'=>2, 'label'=>'', 'required'=>false,
'default'=>false,
'configuration'=>array(
'desc' => 'Maintain referral access to current assignees')
)
),
'id' => 3, 'label'=> '', 'required'=>false, 'default'=>'',
'placeholder' => __('Optional reason for the assignment'),
),
)
),
);
$fields['assignee']->setChoices($this->_assignees);
$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('assignee')))
return false;
// Do additional assignment validation
if (!($assignee = $this->getAssignee())) {
$f->addError(__('Unknown assignee'));
} elseif ($assignee instanceof Staff) {
// Make sure the agent is available
if (!$assignee->isAvailable())
$f->addError(__('Agent is unavailable for assignment'));
} elseif ($assignee instanceof Team) {
// Make sure the team is active and has members
if (!$assignee->isActive())
$f->addError(__('Team is disabled'));
elseif (!$assignee->getNumMembers())
$f->addError(__('Team does not have members'));
function render($options=array()) {
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 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;
5173
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
5207
5208
5209
5210
5211
5212
5213
5214
5215
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();
}
}
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
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'),
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
'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
),
)
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
'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:
break;
default:
$f->addError(__('Unknown selection'));
}
return !$this->errors();
}
function render($options=array()) {
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=array()) {
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 {}