Пример #1
0
 public function fieldsAction()
 {
     $object = Request::post('object', 'string', false);
     if (!$object) {
         Response::jsonError($this->_lang->INVALID_VALUE);
     }
     try {
         $objectConfig = Db_Object_Config::getInstance($object);
     } catch (Exception $e) {
         Response::jsonError($this->_lang->INVALID_VALUE);
     }
     $builder = new Db_Object_Builder($object);
     $brokenFields = $builder->hasBrokenLinks();
     $fieldscfg = $objectConfig->getFieldsConfig();
     foreach ($fieldscfg as $k => &$v) {
         $v['name'] = $k;
         $v['unique'] = $objectConfig->isUnique($k);
         if (isset($brokenFields[$k])) {
             $v['broken'] = true;
         } else {
             $v['broken'] = false;
         }
         if (isset($v['type']) && !empty($v['type'])) {
             if ($v['type'] == 'link') {
                 $v['type'] .= ' (' . $v['link_config']['object'] . ')';
                 $v['link_type'] = $v['link_config']['link_type'];
                 $v['object'] = $v['link_config']['object'];
                 unset($v['link_config']);
             }
             continue;
         }
         $v['type'] = $v['db_type'];
         if (in_array($v['db_type'], Db_Object_Builder::$charTypes, true)) {
             $v['type'] .= ' (' . $v['db_len'] . ')';
         } elseif (in_array($v['db_type'], Db_Object_Builder::$floatTypes, true)) {
             $v['type'] .= ' (' . $v['db_scale'] . ',' . $v['db_precision'] . ')';
         }
     }
     unset($v);
     Response::jsonArray(array_values($fieldscfg));
 }