Beispiel #1
0
 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'));
     }
 }
Beispiel #2
0
 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;
 }
Beispiel #3
0
 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}\"";
         }
     }
 }