Пример #1
0
 public function generateFields()
 {
     $qTableFields = $this->application->dataLink->select("DESCRIBE `" . $this->name . "`;");
     while ($tableField = $qTableFields->nextObject()) {
         $tableField->Property = $this->getPropertyNameByFieldName($tableField->Field);
         $tableField->FFType = $this->mysqlTypeToFFType($tableField->Type);
         if ($tableField->Default === null) {
             switch ($tableField->FFType) {
                 case 'BM_VT_INTEGER':
                 case 'BM_VT_FLOAT':
                     $tableField->FFDefault = 0;
                     break;
                 case 'BM_VT_STRING':
                     $tableField->FFDefault = '';
                     break;
                 case 'BM_VT_DATETIME':
                     $tableField->FFDefault = '0000-01-01 00:00:00';
                     break;
                 case 'BM_VT_ANY':
                     $tableField->FFDefault = '';
                     break;
             }
         } else {
             $tableField->FFDefault = $tableField->Default;
         }
         $dataField = new bmDataObjectField($this->application);
         if ($tableField->Property == 'id') {
             $tableField->Property = 'identifier';
         }
         $dataField->propertyName = $tableField->Property;
         $dataField->fieldName = $tableField->Field;
         $dataField->type = constant($tableField->FFType);
         $dataField->defaultValue = $tableField->FFDefault;
         $dataField->setDataObjectMap($this->properties['identifier'], $tableField->Property == 'identifier' ? 1 : 0);
         unset($dataField);
     }
 }
Пример #2
0
 public function execute()
 {
     $dataLink = $this->application->dataLink;
     if ($this->dataObjectId != 0) {
         $dataObjectMap = new bmDataObjectMap($this->application, array('identifier' => $this->dataObjectId));
         foreach ($this->dataFields as &$item) {
             if ($item->action != 'delete') {
                 $inflectionNames = array('nominative', 'genitive', 'dative', 'accusive', 'creative', 'prepositional');
                 if ($item->localName != '') {
                     $inflections = file_get_contents('http://export.yandex.ru/inflect.xml?name=' . urlencode($item->localName));
                     $xml = simplexml_load_string($inflections);
                     $inflections = array();
                     if (count($xml->inflection) == 6) {
                         $i = 0;
                         foreach ($xml->inflection as $inflection) {
                             $inflections[$inflectionNames[$i]] = (string) $inflection;
                             $i++;
                         }
                     } else {
                         foreach ($inflectionNames as $i => $inflection) {
                             $inflections[$inflectionNames[$i]] = (string) $xml->inflection;
                         }
                     }
                 } else {
                     $inflections = array();
                     foreach ($inflectionNames as $i => $inflection) {
                         $inflections[$inflectionNames[$i]] = $item->propertyName;
                     }
                 }
                 $item->localName = serialize($inflections);
                 if ($item->dataType == BM_VT_DATETIME) {
                     if (!preg_match('/^\\d{4}-\\d{2}-\\d{2}\\s+\\d{2}:\\d{2}:\\d{2}$/', $item->defaultValue)) {
                         $item->defaultValue = '0000-01-01 00:00:00';
                     }
                 }
                 $dataField = new bmDataObjectField($this->application, array('identifier' => $item->identifier));
                 $dataField->propertyName = $item->propertyName;
                 $dataField->fieldName = $item->fieldName;
                 $dataField->dataType = $item->dataType;
                 $dataField->defaultValue = $item->defaultValue;
                 $dataField->localName = $item->localName;
                 $dataField->store();
                 $item->identifier = $dataField->identifier;
             }
             $dataObjectMap->beginUpdate();
             switch ($item->action) {
                 case 'add':
                     $dataObjectMap->addField($item->identifier, $item->dataType);
                     break;
                 case 'delete':
                     $dataObjectMap->removeField($item->identifier);
                     break;
                 case 'change':
                     $dataObjectMap->renameField($item->identifier, $item->oldFieldName);
                     break;
             }
             $dataObjectMap->endUpdate();
         }
     }
     $dataObjectMap->save();
     $dataObjectMap->generateFiles();
     unset($dataObjectMap);
     parent::execute();
 }