public function prepareData() { parent::prepareData(); $this->wellId = CoreServices2::getRequest()->getFromPost('wellId'); $this->wellType = CoreServices2::getRequest()->getFromPost('wellType'); $this->wellPoints = CoreServices2::getRequest()->getFromPost('wellPoints'); $this->messageManager = new CoreFormValidationMessageContainer(); CoreServices2::getDB()->transactionStart(); if (!$this->hasUserPermissionsForRecord()) { $this->messageManager->addMessage('fileDeleteErrorNoPermission'); return; } $pointsData = json_decode($this->wellPoints); foreach ($pointsData as $key => $pointData) { if ($pointData == "") { return false; } $keyValue = explode("_", $key); if ($keyValue[1] != "rowOrder") { $wellPoints[$keyValue[2]][$keyValue[1]] = $pointData; } else { $pointsOrder = explode(',', $pointData); } } // find old points connectet with welll $well3dDAO = new Well3DPointDAO(); $oldPoints = $well3dDAO->getWellPointsByWellId($this->wellId); // delete old points if (!empty($oldPoints)) { foreach ($oldPoints as $point) { $well3dDAO->delete($point); } } $pointsCounter = 1; foreach ($pointsOrder as $order) { // save new points into table $recordTemplate = $well3dDAO->getRecordTemplate(); $recordTemplate['wellId'] = $this->wellId; $recordTemplate['number'] = $pointsCounter; $recordTemplate['X'] = $wellPoints[$order]['X']; $recordTemplate['Y'] = $wellPoints[$order]['Y']; $recordTemplate['Z'] = $wellPoints[$order]['Z']; $recordTemplate['LP'] = $wellPoints[$order]['LP']; $recordTemplate['alfa'] = $wellPoints[$order]['alfa']; $recordTemplate['beta'] = $wellPoints[$order]['beta']; $well3dDAO->save($recordTemplate); $pointsCounter++; } CoreServices2::getDB()->transactionCommit(); }
/** * Check what kind of action should be executed on DAO and execute it. This function doesn't * check if the action is permitted for the current user with submitted data. * The action should be valid, because it is one of the possible actions passed to the * constructor of the '_action' field. If there are some data-related limitations for * possible actions, a validator can be added to the '_action' field. */ protected function handleRequest() { $action = $this->getAction(); if (empty($action) || !in_array($action, $this->availableActions)) { $this->errorMessageContainer = new CoreFormValidationMessageContainer(); $this->errorMessageContainer->addMessage('invalidAction'); } else { $this->runRequestHandler(); if (empty($this->errorMessageContainer) || !$this->errorMessageContainer->isAnyErrorMessage()) { $this->logAction($action); } } }
protected function checkDataConsistency() { $attachmentTypes = CoreConfig::get('FileUpload', 'swfUploadAttachmentTypes'); $fileCategory = $this->fileRecord['fileCategory']; $recordType = $this->fileRecord['recordType']; if ($recordType == '_tmpRecord') { return; } $filePosition = $this->fileRecord['filePosition']; CoreUtils::checkConstraint(is_array($attachmentTypes[$recordType][$filePosition])); $minItems = $attachmentTypes[$recordType][$filePosition]['minItems']; if (!empty($minItems)) { $currentItems = $this->fileDAO->getCountByRecord($recordType, $this->baseRecord['id'], $fileCategory, $filePosition); if ($currentItems - 1 < $minItems) { $this->messageManager->addMessage('fileDeleteErrorTooFewAttachments'); return; } } }
protected function checkDataConsistency() { $attachmentTypes = CoreConfig::get('FileUpload', 'swfUploadAttachmentTypes'); $fileCategory = $this->form->getField('fileCategory')->getValue(); $recordType = $this->form->getField('recordType')->getValue(); CoreUtils::checkConstraint($recordType != '_tmpRecord'); $filePosition = $this->form->getField('filePosition')->getValue(); $record = $this->getBaseRecord(); if (empty($record)) { $this->messageManager->addMessage('fileUploadErrorInvalidBaseRecordId'); return; } if (!$this->hasUserPermissionsForRecord($recordType, $record)) { $this->messageManager->addMessage('fileUploadErrorNoPermission'); return; } if (!array_key_exists($recordType, $attachmentTypes)) { $this->messageManager->addMessage('fileUploadErrorInvalidRecordType'); return; } if (!array_key_exists($filePosition, $attachmentTypes[$recordType])) { $this->messageManager->addMessage('fileUploadErrorInvalidFilePosition'); return; } if ($fileCategory != $attachmentTypes[$recordType][$filePosition]['fileCategory']) { $this->messageManager->addMessage('fileUploadErrorWrongCategory'); return; } $maxItems = $attachmentTypes[$recordType][$filePosition]['maxItems']; if (!empty($maxItems)) { $currentItems = $this->fileDAO->getCountByRecord($recordType, $record['id'], $fileCategory, $filePosition); if ($currentItems + 1 > $maxItems) { $this->messageManager->addMessage('fileUploadErrorTooManyAttachments'); return; } } }