Exemplo n.º 1
0
 public function execute()
 {
     foreach ($this->dataObjectNames as $dataObjectMapId => $dataObjectName) {
         if ($dataObjectMapId != 0 || $dataObjectName != '') {
             $dataObjectName = trim($dataObjectName);
             $pattern = '/^[a-zA-Z][a-zA-Z0-9]+$/';
             if (preg_match($pattern, $dataObjectName)) {
                 $dataObjectMap = new bmDataObjectMap($this->application, array('identifier' => $dataObjectMapId));
                 $dataObjectMap->beginUpdate();
                 if ($dataObjectMap->type != 1) {
                     $dataObjectMap->name = $dataObjectName;
                 }
                 $dataObjectMap->endUpdate();
                 $dataObjectMap->save();
                 // $dataObjectMap->generateFiles(C_ADMIN_ANCESTOR_PAGE);
                 unset($dataObjectMap);
             } else {
                 echo 'Ошибка: имя объекта может состоять из строчных и прописных латинских букв и цифр и должно начинаться с буквы';
             }
         }
     }
     parent::execute();
 }
Exemplo n.º 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();
 }