diff --git a/include/class.orm.php b/include/class.orm.php index fe5d6e2781b0efd07779578b1bab208665168dc5..67b92c7dd56d93c0aa7185a94aecef0ccc07f584 100644 --- a/include/class.orm.php +++ b/include/class.orm.php @@ -321,6 +321,16 @@ class VerySimpleModel { $this->__new__ = true; } + /** + * Creates a new instance of the model without calling the constructor. + * If the constructor is required, consider using the PHP `new` keyword. + * The instance returned from this method will not be considered *new* + * and will now result in an INSERT when sent to the database. + */ + static function __hydrate($row=false) { + return static::getMeta()->newInstance($row); + } + function get($field, $default=false) { if (array_key_exists($field, $this->ht)) return $this->ht[$field]; @@ -727,16 +737,17 @@ extends {$class} { protected \$__overlay__; use {$extra}AnnotatedModelTrait; - function __construct(\$ht, \$annotations) { - \$this->ht = \$ht; - \$this->__overlay__ = \$annotations; + static function __hydrate(\$ht=false, \$annotations=false) { + \$instance = parent::__hydrate(\$ht); + \$instance->__overlay__ = \$annotations; + return \$instance; } } return "{$extra}AnnotatedModel___{$class}"; END_CLASS ); } - return new $classes[$class]($model->ht, $extras); + return $classes[$class]::__hydrate($model->ht, $extras); } } @@ -799,7 +810,7 @@ trait WriteableAnnotatedModelTrait { function save($refetch=false) { $this->__overlay__->save($refetch); - return parent::save(); + return parent::save($refetch); } function delete() { @@ -1781,7 +1792,7 @@ implements IteratorAggregate { // Check the cache for the model instance first if (!($m = self::checkCache($modelClass, $fields))) { // Construct and cache the object - $m = $modelClass::$meta->newInstance($fields); + $m = $modelClass::__hydrate($fields); // XXX: defer may refer to fields not in this model $m->__deferred__ = $this->queryset->defer; $m->__onload(); diff --git a/include/class.queue.php b/include/class.queue.php index bd0775da7ee17ec44d5150626ed6b594f3727fdb..289a003c498483f8fe491fc1fa2cc7049a69e574 100644 --- a/include/class.queue.php +++ b/include/class.queue.php @@ -460,8 +460,8 @@ class CustomQueue extends VerySimpleModel { } // Last resort — use standard columns - return array( - new QueueColumn(array( + foreach (array( + QueueColumn::placeholder(array( "heading" => "Number", "primary" => 'number', "width" => 85, @@ -469,12 +469,12 @@ class CustomQueue extends VerySimpleModel { "annotations" => '[{"c":"TicketSourceDecoration","p":"b"}]', "conditions" => '[{"crit":["isanswered","set",null],"prop":{"font-weight":"bold"}}]', )), - new QueueColumn(array( + QueueColumn::placeholder(array( "heading" => "Created", "primary" => 'created', "width" => 100, )), - new QueueColumn(array( + QueueColumn::placeholder(array( "heading" => "Subject", "primary" => 'cdata__subject', "width" => 250, @@ -482,22 +482,25 @@ class CustomQueue extends VerySimpleModel { "annotations" => '[{"c":"TicketThreadCount","p":">"},{"c":"ThreadAttachmentCount","p":"a"},{"c":"OverdueFlagDecoration","p":"<"}]', "truncate" => 'ellipsis', )), - new QueueColumn(array( + QueueColumn::placeholder(array( "heading" => "From", "primary" => 'user__name', "width" => 150, )), - new QueueColumn(array( + QueueColumn::placeholder(array( "heading" => "Priority", "primary" => 'cdata__priority', "width" => 120, )), - new QueueColumn(array( + QueueColumn::placeholder(array( "heading" => "Assignee", "primary" => 'assignee', "width" => 100, )), - ); + ) as $col) + $this->addColumn($col); + + return $this->getColumns(); } function addColumn(QueueColumn $col) { @@ -698,7 +701,7 @@ class CustomQueue extends VerySimpleModel { $this->title = $vars['name']; $this->parent_id = @$vars['parent_id'] ?: 0; - if (!$this->parent) + if ($this->parent_id && !$this->parent) $errors['parent_id'] = __('Select a valid queue'); // Set basic queue information @@ -1564,6 +1567,10 @@ extends VerySimpleModel { return $c; } + static function placeholder($vars) { + return static::__hydrate($vars); + } + function update($vars, $root='Ticket') { $form = $this->getDataConfigForm($vars); foreach ($form->getClean() as $k=>$v) diff --git a/include/staff/queue.inc.php b/include/staff/queue.inc.php index 4d2cc050e0384b17e25c9838b37f1d332e1569e7..cf116e4886bd8f8f364b85da2a1cf1380f72cda7 100644 --- a/include/staff/queue.inc.php +++ b/include/staff/queue.inc.php @@ -97,6 +97,7 @@ else { ><?php echo $cq->getFullName(); ?></option> <?php } ?> </select> + <div class="error"><?php echo Format::htmlchars($errors['parent_id']); ?></div> <br/> <br/> diff --git a/include/staff/templates/advanced-search-criteria.tmpl.php b/include/staff/templates/advanced-search-criteria.tmpl.php index 29bea883a9c534eb2f481a6bb538b1fb0de669f0..88060a6004f8c6bd0ae17729ff08451251362b6c 100644 --- a/include/staff/templates/advanced-search-criteria.tmpl.php +++ b/include/staff/templates/advanced-search-criteria.tmpl.php @@ -7,7 +7,7 @@ $info = $search->getSearchFields($form); foreach (array_keys($info) as $F) { ?><input type="hidden" name="fields[]" value="<?php echo $F; ?>"/><?php } -$errors = !!$form->errors(); +$has_errors = !!$form->errors(); $inbody = false; $first_field = true; foreach ($form->getFields() as $name=>$field) { @@ -22,7 +22,7 @@ foreach ($form->getFields() as $name=>$field) { } elseif (!$first_field && !$inbody) { echo sprintf('<div class="adv-search-field-body %s">', - !$errors && isset($info[$name]) && $info[$name]['active'] ? 'hidden' : ''); + !$has_errors && isset($info[$name]) && $info[$name]['active'] ? 'hidden' : ''); $inbody = true; } ?> @@ -40,7 +40,7 @@ foreach ($form->getFields() as $name=>$field) { echo 'class="'.implode(' ', $class).'"'; ?>> <?php echo $field->render(); ?> - <?php if (!$errors && $sub === 'search' && isset($info[$name]) && $info[$name]['active']) { ?> + <?php if (!$has_errors && $sub === 'search' && isset($info[$name]) && $info[$name]['active']) { ?> <span style="padding-left: 5px"> <a href="#" data-name="<?php echo Format::htmlchars($name); ?>" onclick="javascript: var $this = $(this), diff --git a/scp/queues.php b/scp/queues.php index 90e8e9bd86d5b000234711ed1bb38d5e584f9020..ac9efb966984e5682b347b5b945c9b47b384e4e1 100644 --- a/scp/queues.php +++ b/scp/queues.php @@ -35,7 +35,7 @@ if ($_POST) { $msg = sprintf(__('Successfully updated %s'), Format::htmlchars($_POST['name'])); } elseif (!$errors['err']) { - $errors['err']=sprintf(__('Unable to udpate %s. Correct error(s) below and try again.'), + $errors['err']=sprintf(__('Unable to update %s. Correct error(s) below and try again.'), __('this queue')); } break;