public function initWithEntityFields(coreBaseEntity $entity) { parent::initWithEntityFields($entity); if ($entity->id) { $type_field = coreFormElementsLibrary::get('fixed_value', 'type'); $type_field->setFixedValue($entity->getTypeName()); $this->replaceField($type_field); $this->makeFieldOptional('type'); $status_select = coreFormElementsLibrary::get('select', 'new_status'); $new_status_options = array(null => $entity->getStatusName()); foreach (ocsPkgOcsOrderStatusHelperLibrary::getNextStatusOptions($entity) as $k => $v) { $new_status_options[$k] = $v; } $this->addField($status_select); $status_select->setOptions($new_status_options); $this->setFieldCaption('new_status', 'Статус'); $comment_field = coreFormElementsLibrary::get('textarea', 'new_status_comment'); $this->addField($comment_field); $this->setFieldCaption('new_status_comment', 'Комментарий к изменению статуса'); $created_str = coreFormattingLibrary::formatDate($entity->created); $this->addField(coreFormElementsLibrary::get('fixed_value', 'created_str')->setFixedValue($created_str)); $this->setFieldCaption('created_str', 'Создана'); $this->setFieldsOrder(array('created_str', 'type', 'new_status', 'new_status_comment')); } }
public function save() { if (!$this->ocs_channel_id) { $this->ocs_channel_id = null; } if (!$this->ocs_client_id) { $this->ocs_client_id = null; } $this->price_quote = (double) $this->price_quote; $is_new = !$this->id; if ($is_new) { $initial_status_options = ocsPkgOcsOrderStatusHelperLibrary::getNextStatusOptions($this); if ($initial_status_options) { $initial_status = array_shift(array_keys($initial_status_options)); $this->setStatus($initial_status); } $this->created = date("Y-m-d H:i:s"); } $id = parent::save(); if ($id) { foreach ($this->_flow as $f) { if (!$f->ocs_order_id) { $f->ocs_order_id = $id; } if (!$f->id) { $f->save(); } } } return $id; }
public function load_list($params = array()) { $list = parent::load_list($params); foreach ($list as $item) { $item->status_name = ocsPkgOcsOrderStatusHelperLibrary::getStatusName($item->status); } return $list; }
protected function validateObject($object) { $this->form->validate(); foreach ($this->form->getErrors() as $field_name => $field_errors) { foreach ($field_errors as $error) { $this->errors[] = $error; } } $new_status = $this->form->getValue('new_status'); if ($new_status) { $new_status_options = ocsPkgOcsOrderStatusHelperLibrary::getNextStatusOptions($object); $new_status_allowed = array_key_exists($new_status, $new_status_options); if (!$new_status_allowed) { $old_status_name = ocsPkgOcsOrderStatusHelperLibrary::getStatusName($object->getStatus()); $new_status_name = ocsPkgOcsOrderStatusHelperLibrary::getStatusName($new_status); $this->errors[] = "Нельзя переводить заявку из статуса \"{$old_status_name}\" в статус \"{$new_status_name}\""; } } }
protected function initFieldSet() { parent::initFieldSet(); $client_options = $this->entity->getClientOptions('-- Любой --'); $client_field = coreFormElementsLibrary::get('select', 'client_id'); $client_field->setOptions($client_options); $this->addField($client_field); $this->setFieldCaption('client_id', 'Клиент'); $type_options = $this->entity->getTypeOptions('-- Любой --'); $type_field = coreFormElementsLibrary::get('select', 'type'); $type_field->setOptions($type_options); $this->addField($type_field); $this->setFieldCaption('type', 'Тип'); $status_options = ocsPkgOcsOrderStatusHelperLibrary::getAllStatusOptions(); $status_field = coreFormElementsLibrary::get('checkbox_collection', 'status'); $status_field->setOptions($status_options); $status_field->setMaxColumns(2); $this->addField($status_field); $this->setFieldCaption('status', 'Статус'); $date_field = coreFormElementsLibrary::get('date_range', 'date_range'); $this->addField($date_field); $this->setFieldCaption('date_range', 'Дата создания'); }