Esempio n. 1
0
 function value($new_value = null)
 {
     $value = (bool) parent::value($new_value);
     if ($this->_checked) {
         return (bool) $value;
     } else {
         return $value;
     }
 }
Esempio n. 2
0
 function value($new = null)
 {
     $value = parent::value($new);
     if ($this->_checked) {
         return doubleval($value);
     } else {
         return $value;
     }
 }
Esempio n. 3
0
 function value($new = null)
 {
     $value = parent::value($new);
     if (!isset($this->_file_content)) {
         if (!$value && $this->is_file()) {
             $filename = $this->file(null, true);
             $this->_file_content = file_get_contents($filename);
         } else {
             $this->_file_content = $value;
         }
     }
     return $this->_file_content;
 }
Esempio n. 4
0
 function rule()
 {
     return parent::rule()->mix(Rule::arrays(['value' => Rule::email()]));
 }
Esempio n. 5
0
 /**
  * @param Entity $entity
  * @param array $properties
  * @param \Closure $file_save_callback Функция для обработки подключенных к объекту файлов
  * @return array
  */
 protected function export($entity, $properties = [], $file_save_callback = null)
 {
     // Новые сведения об объекте
     $result = [];
     $result['proto'] = $entity->proto();
     if ($entity->author()) {
         $result['author'] = $entity->author();
     }
     if ($entity->order() < Entity::MAX_ORDER) {
         $result['order'] = $entity->order();
     }
     if ($entity->created() > 0) {
         $result['created'] = $entity->created();
     }
     if ($entity->updated() > 0) {
         $result['updated'] = $entity->updated();
     }
     // value
     if (!$entity->is_default_value()) {
         $result['value'] = $entity->value();
     }
     // file
     if (!$entity->is_default_file()) {
         if ($entity->is_file()) {
             $file_attache = $entity->file();
             if (is_array($file_attache)) {
                 // Загрузка файла
                 if ($file_save_callback instanceof \Closure) {
                     if (!($result['file'] = $file_save_callback($entity, $file_attache))) {
                         unset($result['file']);
                     }
                 }
             } else {
                 $result['file'] = basename($file_attache);
             }
         } else {
             // файла нет, но нужно отменить наследование файла
             $result['file'] = null;
         }
     }
     if (!$entity->is_default_logic()) {
         $result['logic'] = true;
     }
     if ($entity->is_draft()) {
         $result['is_draft'] = true;
     }
     if ($entity->is_hidden()) {
         $result['is_hidden'] = true;
     }
     if ($entity->is_mandatory()) {
         $result['is_mandatory'] = true;
     }
     //        if ($entity->is_property()) $result['is_property'] = $entity->is_property();
     if ($entity->is_relative()) {
         $result['is_relative'] = true;
     }
     if ($entity->is_link()) {
         $result['is_link'] = true;
     }
     if (is_array($properties)) {
         $result['properties'] = $properties;
     }
     /** @var Entity $child */
     foreach ($entity->children() as $name => $child) {
         if ($child->is_property()) {
             $result['properties'][$name] = $this->export($child, isset($properties[$name]['properties']) ? $properties[$name]['properties'] : [], $file_save_callback);
         }
     }
     if (empty($result['properties'])) {
         unset($result['properties']);
     }
     return $result;
 }
Esempio n. 6
0
 /**
  * Загрузка файла в директорию объекта
  * @param Entity $entity
  * @param array $file Инфо о файла в формате $_FILES
  * @return null|string Имя файла
  */
 static function save_file($entity, $file)
 {
     // Обработка файла у объекта и его свойств
     $f = File::fileInfo($file['tmp_name']);
     $name = ($f['back'] ? '../' : '') . $entity->name();
     // расширение
     if (empty($file['name'])) {
         if ($f['ext']) {
             $name .= '.' . $f['ext'];
         }
     } else {
         $f = File::fileInfo($file['name']);
         if ($f['ext']) {
             $name .= '.' . $f['ext'];
         }
     }
     //
     $path = $entity->dir(true) . $name;
     if ($file['tmp_name'] != $path) {
         if (!File::upload($file['tmp_name'], $path)) {
             // @todo Проверить безопасность?
             // Копирование, если объект-файл создаётся из уже имеющихся на сервере файлов, например при импорте каталога
             if (!File::copy($file['tmp_name'], $path)) {
                 $name = null;
             }
         }
     }
     return $name;
 }
Esempio n. 7
0
 /**
  * Проверка, является ли подчиненным для указанного родителя?
  * @param string|Entity $parent Экземпляр родителя или его идентификатор
  * @return bool
  */
 function in($parent)
 {
     if (!$this->is_exists() || $parent instanceof Entity && !$parent->is_exists()) {
         return false;
     }
     if ($this->eq($parent)) {
         return true;
     }
     return $this->child_of($parent);
 }
Esempio n. 8
0
 function work(Request $request)
 {
     $this->_base_uri = $request['REQUEST']['object']->uri();
     $request->mix(['REQUEST' => ['base_uri' => $this->_base_uri]]);
     if ($request['REQUEST']['form'] !== false) {
         // Обработка формы
         $session = array();
         try {
             // Вызов полей для свойств объекта
             $request->mix(['REQUEST' => ['call' => 'check']]);
             $list = $this->getList($request);
             if (is_array($list)) {
                 $input = $request->getInput();
                 $views = $this->linked()->views->linked();
                 foreach ($list as $obj) {
                     $name = preg_replace('/' . preg_quote($this->_base_uri . '/', '/') . '/u', '', $obj->uri());
                     $obj_input = [];
                     if (isset($input['REQUEST'][$name])) {
                         $obj_input['REQUEST']['value'] = $input['REQUEST'][$name];
                     }
                     if (isset($input['FILES'][$name])) {
                         $obj_input['FILES']['value'] = $input['FILES'][$name];
                     }
                     $obj_input['REQUEST']['object'] = $obj;
                     $views->start($request->mix($obj_input));
                 }
             }
             if (!$request['REQUEST']['object']->errors()->isExist()) {
                 // Выполнение действия
                 $this->process($request);
                 $this->_result = self::FORM_RESULT_OK;
                 if (!($redirect = $this->getCommands('redirect'))) {
                     $redirect = $this->redirect->inner();
                     if (!$redirect->is_draft() && $redirect->value() != '') {
                         $request->redirect(Request::url($redirect->value()));
                     }
                 }
             } else {
                 $this->_result = self::FORM_RESULT_ERROR;
             }
         } catch (\Exception $error) {
             $this->_result = self::FORM_RESULT_ERROR;
         }
         $session['result'] = $this->_result;
         if ($this->_result == self::FORM_RESULT_ERROR) {
             $session['object'] = $request['REQUEST']['object']->toArray();
             // @todo Для ajax запросов нужна развернутая информация об ошибках для каждого поля
             $session['message'] = 'Ошибки';
         } else {
             if ($this->_result == self::FORM_RESULT_ERROR) {
                 $session['message'] = 'Успех';
             }
         }
         // @todo Для ajax запросов в сессию сохранять нет смысла
         Session::set('form', array($this->uri() . $this->getToken() => $session));
         setcookie('token', $this->getToken(), 0, '/');
         return $session;
     } else {
         // Отображение формы
         $v = array();
         if (isset($request['COOKIE']['token']) && Session::is_exist('form')) {
             $form = Session::get('form');
             if (isset($form[$this->uri() . $request['COOKIE']['token']])) {
                 $form = $form[$this->uri() . $request['COOKIE']['token']];
                 Session::remove('form');
             }
             if (isset($form['object'])) {
                 $request['REQUEST']['object'] = Entity::fromArray($form['object']);
             }
             if (isset($form['result'])) {
                 $this->_result = $form['result'];
             }
         }
         $this->res->start($request);
         return $this->show($v, $request);
     }
 }