예제 #1
0
 public function renameDataObjectMap($oldName, $newName)
 {
     if (!$this->application->dataLink->tableExists($oldName)) {
         if ($this->isLogMode) {
             echo 'DB table "' . $oldName . '" does not exist.' . "\n";
         }
     }
     if ($this->application->dataLink->tableExists($newName)) {
         if ($this->isLogMode) {
             echo 'DB table "' . $newName . '" already exists.' . "\n";
         }
     }
     $dataObjectMapId = $this->application->getObjectIdByFieldName('dataObjectMap', 'name', $oldName);
     $dataObjectMap = new bmDataObjectMap($this->application, array('identifier' => $dataObjectMapId));
     $newDataObjectMapId = $this->application->getObjectIdByFieldName('dataObjectMap', 'name', $newName);
     if ($dataObjectMap && !$newDataObjectMapId) {
         $dataObjectMap->name = $newName;
         $dataObjectMap->save();
         if ($this->isLogMode !== true) {
             $this->log('$application->api->renameDataObjectMap(\'' . $oldName . '\', \'' . $newName . '\');');
         }
     } else {
         if ($this->isLogMode) {
             if (!$dataObjectMap) {
                 echo 'DataObject "' . $oldName . '" does not exist.' . "\n";
             }
             if ($newDataObjectMapId) {
                 echo 'DataObject "' . $newName . '" already exists.' . "\n";
             }
         }
     }
 }
예제 #2
0
파일: save.php 프로젝트: NickMitin/P-W
 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();
 }
예제 #3
0
파일: save.php 프로젝트: NickMitin/P-W
 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();
 }