diff --git a/composer.json b/composer.json index 8b4b565b..abee2773 100755 --- a/composer.json +++ b/composer.json @@ -40,7 +40,8 @@ "fortawesome/font-awesome": "v4.7.0", "opensilex/opencpu-client-php": "dev-master", "himiklab/yii2-handsontable-widget" : "v1.1.1", - "phayes/geophp": "1.2" + "phayes/geophp": "1.2", + "antkaz/yii2-vue": "^1.0" }, "require-dev": { "yiisoft/yii2-debug": "2.0.14", diff --git a/composer.lock b/composer.lock index 5b1dfd05..76d673e7 100644 --- a/composer.lock +++ b/composer.lock @@ -4,9 +4,51 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "a81ff6872bbd8b0fdf3f387ebc99092a", - "content-hash": "05c766297ee7a05e6c5a1c1b8da57159", + "content-hash": "c1a3ce2e444177eef1da5e0ce5a3cb00", "packages": [ + { + "name": "antkaz/yii2-vue", + "version": "v1.0", + "source": { + "type": "git", + "url": "https://github.com/antkaz/yii2-vue.git", + "reference": "ba341bdbcfffa96662f49fe83152a867191d3b72" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/antkaz/yii2-vue/zipball/ba341bdbcfffa96662f49fe83152a867191d3b72", + "reference": "ba341bdbcfffa96662f49fe83152a867191d3b72", + "shasum": "" + }, + "require": { + "npm-asset/vue": "~2.5.13", + "yiisoft/yii2": "~2.0.14" + }, + "type": "yii2-extension", + "autoload": { + "psr-4": { + "antkaz\\vue\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Anton Kazarinov", + "email": "askazarinov@gmail.com" + } + ], + "description": "The Vue.js extension for the Yii framework", + "homepage": "https://github.com/antkaz/yii2-vue", + "keywords": [ + "Vue.js", + "vue", + "yii2" + ], + "time": "2018-03-01T19:37:33+00:00" + }, { "name": "borales/yii2-phone-input", "version": "0.1.2", @@ -2213,6 +2255,76 @@ ], "time": "2019-01-21T22:06:44+00:00" }, + { + "name": "npm-asset/vue", + "version": "2.5.22", + "dist": { + "type": "tar", + "url": "https://registry.npmjs.org/vue/-/vue-2.5.22.tgz", + "shasum": "3bf88041af08b8539c37b268b70ca79245e9cc30" + }, + "type": "npm-asset-library", + "extra": { + "npm-asset-bugs": { + "url": "https://github.com/vuejs/vue/issues" + }, + "npm-asset-main": "dist/vue.runtime.common.js", + "npm-asset-directories": [], + "npm-asset-repository": { + "type": "git", + "url": "git+https://github.com/vuejs/vue.git" + }, + "npm-asset-scripts": { + "dev": "rollup -w -c scripts/config.js --environment TARGET:web-full-dev", + "dev:cjs": "rollup -w -c scripts/config.js --environment TARGET:web-runtime-cjs", + "dev:esm": "rollup -w -c scripts/config.js --environment TARGET:web-runtime-esm", + "dev:test": "karma start test/unit/karma.dev.config.js", + "dev:ssr": "rollup -w -c scripts/config.js --environment TARGET:web-server-renderer", + "dev:compiler": "rollup -w -c scripts/config.js --environment TARGET:web-compiler ", + "dev:weex": "rollup -w -c scripts/config.js --environment TARGET:weex-framework", + "dev:weex:factory": "rollup -w -c scripts/config.js --environment TARGET:weex-factory", + "dev:weex:compiler": "rollup -w -c scripts/config.js --environment TARGET:weex-compiler ", + "build": "node scripts/build.js", + "build:ssr": "npm run build -- web-runtime-cjs,web-server-renderer", + "build:weex": "npm run build -- weex", + "test": "npm run lint && flow check && npm run test:types && npm run test:cover && npm run test:e2e -- --env phantomjs && npm run test:ssr && npm run test:weex", + "test:unit": "karma start test/unit/karma.unit.config.js", + "test:cover": "karma start test/unit/karma.cover.config.js", + "test:e2e": "npm run build -- web-full-prod,web-server-basic-renderer && node test/e2e/runner.js", + "test:weex": "npm run build:weex && jasmine JASMINE_CONFIG_PATH=test/weex/jasmine.js", + "test:ssr": "npm run build:ssr && jasmine JASMINE_CONFIG_PATH=test/ssr/jasmine.js", + "test:sauce": "npm run sauce -- 0 && npm run sauce -- 1 && npm run sauce -- 2", + "test:types": "tsc -p ./types/test/tsconfig.json", + "lint": "eslint src scripts test", + "flow": "flow check", + "sauce": "karma start test/unit/karma.sauce.config.js", + "bench:ssr": "npm run build:ssr && node benchmarks/ssr/renderToString.js && node benchmarks/ssr/renderToStream.js", + "release": "bash scripts/release.sh", + "release:weex": "bash scripts/release-weex.sh", + "release:note": "node scripts/gen-release-note.js", + "commit": "git-cz" + }, + "npm-asset-config": { + "commitizen": { + "path": "./node_modules/cz-conventional-changelog" + } + } + }, + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Evan You" + } + ], + "description": "Reactive, component-oriented view layer for modern web interfaces.", + "homepage": "https://github.com/vuejs/vue#readme", + "keywords": [ + "vue" + ], + "time": "2019-01-11T23:18:40+00:00" + }, { "name": "oomphinc/composer-installers-extender", "version": "v1.1.2", diff --git a/config/params.php b/config/params.php index 96ffe266..fdceacdf 100755 --- a/config/params.php +++ b/config/params.php @@ -38,6 +38,12 @@ 'webServicePageSizeMax' => 2097152, // ONTOLOGY ----------------------------------------------------------------- + //-------- Provenance NameSpaces + 'provenanceNamespaces' => [ + "prov"=>"http://www.w3.org/ns/prov#", + "oeso"=>"http://www.opensilex.org/vocabulary/oeso#", + "rdf"=>"http://www.w3.org/1999/02/22-rdf-syntax-ns#" + ], //-------- Concepts 'Actuator' => 'http://www.opensilex.org/vocabulary/oeso#Actuator', 'Lens' => 'http://www.opensilex.org/vocabulary/oeso#Lens', diff --git a/controllers/DatasetController.php b/controllers/DatasetController.php index 03c22cf0..be4c223a 100755 --- a/controllers/DatasetController.php +++ b/controllers/DatasetController.php @@ -19,14 +19,12 @@ use yii\web\Controller; use yii\web\UploadedFile; use yii\filters\VerbFilter; -use Exception; -use app\models\yiiModels\YiiDocumentModel; use app\models\wsModels\WSProvenanceModel; -use app\models\yiiModels\VariableSearch; use app\models\wsModels\WSDataModel; -use app\models\yiiModels\YiiConcernedItemModel; use openSILEX\handsontablePHP\adapter\HandsontableSimple; use openSILEX\handsontablePHP\classes\ColumnConfig; +use app\models\wsModels\WSConstants; +use app\models\yiiModels\YiiExperimentModel; require_once '../config/config.php'; @@ -42,7 +40,7 @@ class DatasetController extends Controller { //create a global configuration file for the csv files //\SILEX:TODO - const AGRONOMICAL_OBJECT_URI = "ScientificObjectURI"; + const AGRONOMICAL_OBJECT_URI = "ScientificObjectAlias"; const DATE = "Date"; const VALUE = "Value"; const ERRORS_MISSING_COLUMN = "Missing Columns"; @@ -50,7 +48,7 @@ class DatasetController extends Controller { const ERRORS_LINE = "Line"; const ERRORS_COLUMN = "Column"; const ERRORS_MESSAGE = "Message"; - + /** * define the behaviors * @return array @@ -125,17 +123,16 @@ public function actionGenerateAndDownloadDatasetCreationFile() { foreach ($variables as $variableAlias) { $fileColumns[] = $variableAlias; } - - $csvPath = "coma"; - if (Yii::$app->params['csvSeparator'] == ";") { - $csvPath = "semicolon"; - } - $file = fopen('./documents/DatasetFiles/' . $csvPath . '/datasetTemplate.csv', 'w'); - fputcsv($file, $fileColumns, $delimiter = Yii::$app->params['csvSeparator']); - fclose($file); + $csvString = implode(Yii::$app->params['csvSeparator'], $fileColumns); + return json_encode($csvString); } - + + + + + + /** * * @param array $csvErrors the errors founded. @@ -309,19 +306,23 @@ private function addColumnErrorsAndMissingToArray($arrayData, $arrayErrors) { */ public function actionCreate() { $datasetModel = new \app\models\yiiModels\YiiDatasetModel(); - $variablesModel = new \app\models\yiiModels\YiiVariableModel(); - - $token = Yii::$app->session['access_token']; - - // Load existing variables - $variables = $variablesModel->getInstancesDefinitionsUrisAndLabel($token); - $this->view->params["variables"] = $this->getVariablesListLabelToShowFromVariableList($variables); + $token = Yii::$app->session[WSConstants::ACCESS_TOKEN]; // Load existing provenances $provenanceService = new WSProvenanceModel(); $provenances = $this->mapProvenancesByUri($provenanceService->getAllProvenances($token)); $this->view->params["provenances"] = $provenances; + // Load existing agents + $userModel = new \app\models\yiiModels\YiiUserModel(); + $users = $userModel->getPersonsURIAndName($token); + $this->view->params['agents'] = $users; + + // Load experiments + $experimentModel = new YiiExperimentModel(); + $experiments = $experimentModel->getExperimentsURIAndLabelList($token); + $this->view->params['experiments'] = $experiments; + //If the form is complete, register data if ($datasetModel->load(Yii::$app->request->post())) { //Store uploaded CSV file @@ -335,55 +336,60 @@ public function actionCreate() { unlink($serverFilePath); //Loaded given variables - $givenVariables = $datasetModel->variables; - + $experimentController = new ExperimentController(); + $experimentVariables = $experimentController->getExperimentMesuredVariablesSelectList($datasetModel->experiment) ; + $csvRawVariables = array_slice($csvHeaders, 2); + // clean variables name + $csvVariables = array_map('trim', $csvRawVariables); + // select all variables that don"t exist in experiment variables + $variablesNotInExperiment = array_diff($csvVariables, array_values($experimentVariables)); // Check CSV header with variables - if (array_slice($csvHeaders, 2) === $givenVariables) { - - // Get selected or create Provenance URI - if (!array_key_exists($datasetModel->provenanceUri, $provenances)) { - $provenanceUri = $this->createProvenance( - $datasetModel->provenanceUri, - $datasetModel->provenanceComment - ); - $datasetModel->provenanceUri = $provenanceUri; - $provenances = $this->mapProvenancesByUri($provenanceService->getAllProvenances($token)); - $this->view->params["provenances"] = $provenances; - } else { + if (count($variablesNotInExperiment) === 0) { $provenanceUri = $datasetModel->provenanceUri; - } - - // If provenance sucessfully created - if ($provenanceUri) { - // Link uploaded documents to provenance URI - $linkDocuments = true; - if (is_array($datasetModel->documentsURIs) && is_array($datasetModel->documentsURIs["documentURI"])) { - $linkDocuments = $this->linkDocumentsToProvenance( - $provenanceUri, - $datasetModel->documentsURIs["documentURI"] - ); + $SciencitificObjectSearch = new \app\models\yiiModels\ScientificObjectSearch(); + $SciencitificObjectSearch->experiment = $datasetModel->experiment; + $SciencitificObjectSearch->pageSize = 30000; + $SciencitificObjectSearch->setWithProperties(false); + $SciencitificObjectSearchResults = $SciencitificObjectSearch->search($token); + + $objectUris = []; + foreach ($SciencitificObjectSearchResults->getModels() as $object){ + $objectUris[$object->uri]=$object->label; } - $datasetModel->documentsURIs = null; - - if ($linkDocuments === true) { + $objectsErrors = []; // Save CSV data linked to provenance URI $values = []; foreach ($fileContent as $rowStr) { $row = str_getcsv($rowStr, Yii::$app->params['csvSeparator']); - $scientifObjectUri = $row[0]; + $scientifObjectAlias = $row[0]; + if(!array_search($scientifObjectAlias, $objectUris)){ + $objectsErrors[] = $scientifObjectAlias . Yii::t("app/messages", " Object does not exists in this experiment"); + $scientifObjectUri = null; + }else{ + $scientifObjectUri = array_search($scientifObjectAlias, $objectUris); + } $date = $row[1]; for ($i = 2; $i < count($row); $i++) { $values[] = [ "provenanceUri" => $provenanceUri, "objectUri" => $scientifObjectUri, - "variableUri" => array_search($givenVariables[$i - 2], $variables), + "variableUri" => array_search($csvVariables[$i - 2], $experimentVariables), "date" => $date, "value" => $row[$i] ]; } } - + + if(!empty($objectsErrors)){ + return $this->render('create', [ + 'model' => $datasetModel, + 'errors' => $objectsErrors + ] + ); + } + + $dataService = new WSDataModel(); $result = $dataService->post($token, "/", $values); @@ -402,27 +408,12 @@ public function actionCreate() { 'errors' => $result->metadata->status ]); } - } else { - return $this->render('create', [ - 'model' => $datasetModel, - 'errors' => [ - Yii::t("app/messages", "Error while creating linked documents") - ] - ]); - } - } else { - return $this->render('create', [ - 'model' => $datasetModel, - 'errors' => [ - Yii::t("app/messages", "Error while creating provenance") - ] - ]); - } + } else { return $this->render('create', [ 'model' => $datasetModel, 'errors' => [ - Yii::t("app/messages", "CSV file headers does not match selected variables") + Yii::t("app/messages", "CSV file headers does not match variables used in this experiment. The following Variables are not associated to this experiment " ) . "(" . implode(",", $variablesNotInExperiment) . ")" ] ]); } @@ -432,65 +423,5 @@ public function actionCreate() { ]); } } - - /** - * Create provenance from an alias and a comment - * @param type $alias - * @param type $comment - * @return boolean - */ - private function createProvenance($alias, $comment) { - $provenanceService = new WSProvenanceModel(); - $date = new \DateTime(); - $provenanceUri = $provenanceService->createProvenance( - Yii::$app->session['access_token'], - $alias, - $comment, - [ - "creationDate" => $date->format("Y-m-d\TH:i:sO") - ] - ); - - if (is_string($provenanceUri) && $provenanceUri != "token") { - return $provenanceUri; - } else { - return false; - } - } - - /** - * Link list of documents to the given provenance uri - * (unlinked -> linked) - * @param string $provenanceUri - * @param array $documents - * @return boolean - */ - private function linkDocumentsToProvenance($provenanceUri, $documents) { - $documentModel = new YiiDocumentModel(null, null); - - // associated documents update - foreach ($documents as $documentURI) { - $documentModel = new YiiDocumentModel(null, null); - $documentModel->findByURI(Yii::$app->session['access_token'], $documentURI); - $documentModel->status = "linked"; - $concernedItem = new YiiConcernedItemModel(); - $concernedItem->uri = $provenanceUri; - $concernedItem->rdfType = Yii::$app->params["Provenance"]; - $documentModel->concernedItems = [$concernedItem]; - $dataToSend[] = $documentModel->attributesToArray(); - } - - if (isset($dataToSend)) { - $requestRes = $documentModel->update(Yii::$app->session['access_token'], $dataToSend); - - if (is_string($requestRes) && $requestRes === "token") { - return false; - } else { - return true; - } - } else { - return true; - } - } - + } diff --git a/controllers/ExperimentController.php b/controllers/ExperimentController.php index 69944dca..629fb557 100755 --- a/controllers/ExperimentController.php +++ b/controllers/ExperimentController.php @@ -404,4 +404,42 @@ public function actionUpdateSensors() { return json_encode($res, JSON_UNESCAPED_SLASHES); } + + + /** + * Return an array of variable label mapped with variable uri + * @return array + */ + public function actionAjaxGetExperimentMesuredVariablesSelectList($experimentUri){ + + Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; + $variables = []; + $variables["data"] = []; + $experimentVariable = $this->getExperimentMesuredVariablesSelectList($experimentUri); + foreach ($experimentVariable as $key => $value) { + $variables["data"][] = ["id" => $key, "text" => $value]; + } + + return($variables); + } + + /** + * Prepare a variable list associated to an experiment + * @param string $experimentUri + * @return array + */ + public function getExperimentMesuredVariablesSelectList($experimentUri) { + if(!isset($experimentUri) || empty($experimentUri)){ + return []; + } + $experimentModel = new YiiExperimentModel(); + $variables = $experimentModel->getMeasuredVariables( + Yii::$app->session[WSConstants::ACCESS_TOKEN], + $experimentUri + ); + if(isset($variables) && is_array($variables)){ + return $variables; + } + return []; + } } diff --git a/controllers/ProvenanceController.php b/controllers/ProvenanceController.php new file mode 100644 index 00000000..1baeec5b --- /dev/null +++ b/controllers/ProvenanceController.php @@ -0,0 +1,213 @@ + + */ +class ProvenanceController extends Controller { + + /** + * Define the behaviors + * + * @return array + */ + public function behaviors() { + return [ + 'verbs' => [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ]; + } + + /** + * Create a provenance from post data with documents Uri associated + * [ + * provenance : { label, comment, metadata:{ ... } }, + * documents : { uri1,uri2} + * ] + */ + public function actionAjaxCreateProvenanceFromDataset(){ + + Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; + $data = Yii::$app->request->post(); + + $documents = []; + + $provenance = $data["provenance"]; + if(isset($data["documents"])){ + $documents = $data["documents"]; + } + $provenanceUri = $this->createProvenance( + $provenance['label'], + $provenance['comment'], + $provenance['sensingDevices'], + $provenance['agents'] + ); + + $this->linkDocumentsToProvenance($provenanceUri, $documents); + + if($provenanceUri != false){ + return $provenanceUri; + } + return false; + } + + /** + * Update provenance documents from post data + * [ + * provenance : { label, comment, metadata:{ ... } }, + * documents : { uri1,uri2} + * ] + */ + public function actionAjaxUpdateProvenanceDocumentsFromDataset(){ + + Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; + $data = Yii::$app->request->post(); + + $documents = []; + + $provenanceUri = $data["provenanceUri"]; + if(isset($data["documents"])){ + $documents = $data["documents"]; + } + + return $this->linkDocumentsToProvenance($provenanceUri, $documents); + } + + /** + * Return an array with provenance list with all characteristics + * and provenance label mapped with provenance uri + * @return array + */ + public function actionAjaxGetProvenancesSelectList(){ + $token = Yii::$app->session[WSConstants::ACCESS_TOKEN]; + + Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; + $provenanceService = new WSProvenanceModel(); + + $provenances = $this->mapProvenancesByUri($provenanceService->getAllProvenances($token)); + + foreach ($provenances as $uri => $provenance) { + $provenancesArray[$uri] = $provenance->label . " (" . $uri . ")"; + } + $result['provenances'] = $provenances; + $result['provenancesByUri'] = $provenancesArray; + return $result; + } + + + /** + * Create provenance from an alias and a comment + * @param string $alias label of the provenance + * @param string $comment comment linked to the provenance + * @param array $sensingDevices uri of the sensor + * @param array $agents uri of the agent + * @return boolean + */ + private function createProvenance($alias, $comment,$sensingDevices = [], $agents = []) { + $provenanceService = new WSProvenanceModel(); + $date = new \DateTime(); + $createdDate = $date->format("Y-m-d\TH:i:sO"); + $metadata = []; + foreach ($sensingDevices as $sensingDevice) { + if(!isset($metadata["prov:Agent"])){ + $metadata["prov:Agent"] = []; + } + $metadata["prov:Agent"][] = [ + "prov:id" => $sensingDevice, + "rdf:type" => "oeso:SensingDevice" + ]; + } + foreach ($agents as $agent) { + if(!isset($metadata["prov:Agent"])){ + $metadata["prov:Agent"] = []; + } + $metadata["prov:Agent"][] = [ + "prov:id" => $agent, + "rdf:type" => "oeso:Operator" + ]; + } + + $provenanceUri = $provenanceService->createProvenance( + Yii::$app->session['access_token'], + $alias, + $comment, + $createdDate, + $metadata + ); + + if (is_string($provenanceUri) && $provenanceUri != "token") { + return $provenanceUri; + } else { + return false; + } + } + + /** + * Create an associative array of the provenances objects indexed by their URI + * @param type $provenances + * @return array + */ + private function mapProvenancesByUri($provenances) { + $provenancesMap = []; + if ($provenances !== null) { + foreach ($provenances as $provenance) { + $provenancesMap[$provenance->uri] = $provenance; + } + } + + return $provenancesMap; + } + + /** + * Link list of documents to the given provenance uri + * (unlinked -> linked) + * @param string $provenanceUri + * @param array $documents + * @return boolean + */ + private function linkDocumentsToProvenance($provenanceUri, $documents) { + $documentModel = new YiiDocumentModel(null, null); + + // associated documents update + foreach ($documents as $documentURI) { + $documentModel = new YiiDocumentModel(null, null); + $documentModel->findByURI(Yii::$app->session['access_token'], $documentURI); + $documentModel->status = "linked"; + $concernedItem = new YiiConcernedItemModel(); + $concernedItem->uri = $provenanceUri; + $concernedItem->rdfType = Yii::$app->params["Provenance"]; + $documentModel->concernedItems = [$concernedItem]; + $dataToSend[] = $documentModel->attributesToArray(); + } + + if (isset($dataToSend)) { + $requestRes = $documentModel->update(Yii::$app->session['access_token'], $dataToSend); + + if (is_string($requestRes) && $requestRes === "token") { + return false; + } else { + return true; + } + } else { + return true; + } + } +} \ No newline at end of file diff --git a/models/wsModels/WSDataModel.php b/models/wsModels/WSDataModel.php index 8cdbc79b..00ffada8 100644 --- a/models/wsModels/WSDataModel.php +++ b/models/wsModels/WSDataModel.php @@ -19,6 +19,12 @@ */ class WSDataModel extends\openSILEX\guzzleClientPHP\WSModel { + /** + * Date format for the webservice filters with timezone + * @example: 2017-05-03T12:35:00+2000 + */ + const DATE_FORMAT = "Y-m-d\TH:i:sO"; + /** * initialize access to the projects service. Calls super constructor */ diff --git a/models/wsModels/WSProvenanceModel.php b/models/wsModels/WSProvenanceModel.php index e1e7c13c..a64b5aa9 100644 --- a/models/wsModels/WSProvenanceModel.php +++ b/models/wsModels/WSProvenanceModel.php @@ -34,19 +34,24 @@ public function __construct() { * @param type $sessionToken * @param type $label * @param type $comment + * @param type $createdDate Description * @param type $metadata * @return type */ - public function createProvenance($sessionToken, $label, $comment, $metadata) { + public function createProvenance($sessionToken, $label, $comment,$createdDate, $metadata) { $subService = "/"; + if(empty($metadata)){ + $metadata = (object) array(); + } $provenance = $this->post($sessionToken, $subService, [[ "label" => $label, "comment" => $comment, + "created" => $createdDate, "metadata" => $metadata, ]]); if ( - isset($provenance->{WSConstants::METADATA}->{WSConstants::DATA_FILES}) && count($provenance->{WSConstants::METADATA}->{WSConstants::DATA_FILES}) == 1 + isset($provenance->{WSConstants::METADATA}->{WSConstants::DATA_FILES}) && count($provenance->{WSConstants::METADATA}->{WSConstants::DATA_FILES}) == 1 ) { return $provenance->{WSConstants::METADATA}->{WSConstants::DATA_FILES}[0]; } else { @@ -54,6 +59,46 @@ public function createProvenance($sessionToken, $label, $comment, $metadata) { } } + /** + * Return an array of existing provenances match with criteria + * + * @param string $sessionToken + * @param array $userCriteria array of citeria + * @return type + */ + public function getSpecificProvenancesByCriteria($sessionToken,$userCriteria = []) { + $pageSize = 200; + $subService = "/"; + $params = array_merge($userCriteria,[ + WSConstants::PAGE => 0, + WSConstants::PAGE_SIZE => $pageSize + ]); + + $provenanceResult = $this->get($sessionToken, $subService, $params); + + if (isset($provenanceResult->{WSConstants::METADATA}->{WSConstants::PAGINATION}) && isset($provenanceResult->{WSConstants::METADATA}->{WSConstants::PAGINATION}->{WSConstants::TOTAL_COUNT}) && $provenanceResult->{WSConstants::METADATA}->{WSConstants::PAGINATION}->{WSConstants::TOTAL_COUNT} > 0) { + + $result = $provenanceResult->{WSConstants::RESULT}->{WSConstants::DATA}; + + $totalPages = $provenanceResult->{WSConstants::METADATA}->{WSConstants::PAGINATION}->{WSConstants::TOTAL_PAGES}; + + for ($currentPage = 1; $currentPage < $totalPages; $currentPage++) { + $params[WSConstants::PAGE] = $currentPage; + $params[WSConstants::PAGE_SIZE] = $pageSize; + + $provenanceResult = $this->get($sessionToken, $subService, $params); + + $result = array_merge($result, $provenanceResult->{WSConstants::RESULT}->{WSConstants::DATA}); + } + + return $result; + }elseif(isset($provenanceResult->{WSConstants::RESULT}->{WSConstants::DATA})){ + return $provenanceResult->{WSConstants::RESULT}->{WSConstants::DATA}; + }else{ + return []; + } + } + /** * Return an array of all existing provenances * diff --git a/models/yiiModels/ScientificObjectSearch.php b/models/yiiModels/ScientificObjectSearch.php index 478694c4..2aa620c6 100755 --- a/models/yiiModels/ScientificObjectSearch.php +++ b/models/yiiModels/ScientificObjectSearch.php @@ -27,6 +27,8 @@ class ScientificObjectSearch extends YiiScientificObjectModel { //create a trait (?) with methods search and jsonListOfArray and use it in //each class ElementNameSearch //\SILEX:refactor + private $withProperties; + const WITH_PROPERTIES = "withProperties"; /** * @inheritdoc @@ -34,7 +36,7 @@ class ScientificObjectSearch extends YiiScientificObjectModel { public function rules() { return [ - [['uri', 'label', 'experiment', 'alias', 'type'], 'safe'], + [['uri', 'label', 'experiment', 'alias', 'type', 'withProperties'], 'safe'], ]; } @@ -82,4 +84,27 @@ public function search($sessionToken, $params) { ]); } } + + function getWithProperties() { + return $this->withProperties; + } + + function setWithProperties($withProperties) { + if(is_bool($withProperties)){ + $this->withProperties = $withProperties; + }else{ + $this->withProperties = true; + } + } + + /** + * Add with properties parameters + * @return array + */ + public function attributesToArray() { + $elementForWebService = parent::attributesToArray(); + $elementForWebService[ScientificObjectSearch::WITH_PROPERTIES] = $this->getWithProperties(); + + return $elementForWebService; + } } \ No newline at end of file diff --git a/models/yiiModels/YiiDatasetModel.php b/models/yiiModels/YiiDatasetModel.php index 2cb084af..ab754348 100755 --- a/models/yiiModels/YiiDatasetModel.php +++ b/models/yiiModels/YiiDatasetModel.php @@ -25,8 +25,8 @@ class YiiDatasetModel extends WSActiveRecord { /** - * Uri de la provenance - * @var type + * Provenance uri + * @var string */ public $provenanceUri; @@ -73,6 +73,24 @@ class YiiDatasetModel extends WSActiveRecord { * @var file */ public $file; + + /** + * Sensor uris + * @var array + */ + public $provenanceSensingDevices; + + /** + * Agent uris + * @var array + */ + public $provenanceAgents; + + /** + * Experiment uri + * @var string + */ + public $experiment; const PROVENANCE = "provenance"; const DATA = "data"; @@ -94,8 +112,10 @@ public function __construct($pageSize = null, $page = null) { */ public function rules() { return [ - [['variables', 'provenanceAlias', 'file', 'provenanceUri'], 'required'], + [['provenanceAlias', 'file', 'provenanceUri','experiment'], 'required'], + [['variables','provenanceSensingDevices','provenanceAgents'], 'safe'], [['provenanceComment'], 'string'], + [['experiment'], 'string'], [['provenanceUri', 'provenanceComment', 'documentsURIs', 'data', 'file'], 'safe'], [['file'], 'file', 'extensions' => 'csv'] ]; @@ -107,11 +127,14 @@ public function rules() { */ public function attributeLabels() { return [ - 'provenanceUri' => Yii::t('app', 'Provenance (URI)'), + 'provenanceUri' => Yii::t('app', 'Provenance label'), 'provenanceComment' => Yii::t('app', 'Provenance comment'), - 'variables' => Yii::t('app', 'Variable(s)'), + 'provenanceSensingDevices' => Yii::t('app', 'Provenance sensor(s)'), + 'provenanceAgents' => Yii::t('app', 'Provenance operator(s)'), + 'variables' => Yii::t('app', 'Experiment associated variable(s)'), 'file' => Yii::t('app', 'Data file'), - 'documentsUris' => Yii::t('app', 'Documents') + 'documentsUris' => Yii::t('app', 'Documents'), + 'experiment' => Yii::t('app', 'Experiment') ]; } diff --git a/translations/fr/app.php b/translations/fr/app.php index 495e201a..aa8cecec 100755 --- a/translations/fr/app.php +++ b/translations/fr/app.php @@ -49,6 +49,7 @@ 'Add Dataset' => 'Importer un jeu de données', 'Add Document' => 'Ajouter un document', 'Add Document Script' => 'Ajouter un script', + 'Add on scientific object' => 'Importer pour un objet scientifique', 'Add row' => 'Ajouter une ligne', 'Add Sensors' => 'Ajouter des Capteurs', 'Add Vectors' => 'Ajouter des Vecteurs', @@ -66,6 +67,7 @@ 'Availability' => 'Disponibilité', // B + 'Back' => 'Retour', 'Back to sensor view' => 'Retour à la vue du capteur', 'Brand' => 'Marque', 'BRDF coefficient P1' => 'Coefficient BRDF P1', @@ -80,6 +82,7 @@ 'Characterize Sensor' => 'Caractériser un Capteur', 'Characterize' => 'Caractériser', 'Circular' => 'Circulaire', + 'Choose experiment' => 'Choisir une expérimentation' , 'Contact' => 'Contact', 'Contact / Help' => 'Contact / Aide', 'Column' => 'Colonne', @@ -96,6 +99,7 @@ 'Comment' => 'Commentaire', 'Creation Date' => 'Date de Création', 'Creator' => 'Auteur', + 'Create provenance' => 'Créer la provenance', 'Creator of the annotation' => 'Auteur de l\'annotation', 'Crop Species' => 'Espèce', @@ -105,12 +109,14 @@ 'Data Search'=>'Recherche de données', 'Dataset' => 'Jeux de données', 'Dataset Creation Date' => 'Données Insérées', + 'Dataset input file' => 'Fichier de jeu de données', 'Date' => 'Date', 'Date End' => 'Date de fin', 'Date Of Last Calibration' => 'Date de Dernier Étalonnage', 'Date Of Purchase' => 'Date d\'Achat', 'Date Start' => 'Date de début', 'Description' => 'Description', + 'Describe the produced dataset' => 'Décrire le jeu de données', 'Diameter' => 'Diamètre', 'Diameter (m)' => 'Diamètre (m)', 'Document Type' => 'Type du Document', @@ -130,6 +136,7 @@ 'Experimental Organization' => 'Organisation expérimentale', 'Experiment'=>'Expérimentation', 'Experiment Modalities' => 'Modalités Expérimentales', + 'Experiment associated variable(s)' => 'Variable(s) associées à l\'expérimentation', EventAction::EVENT_UNUPDATABLE_DUE_TO_UNUPDATABLE_PROPRTY_LABEL => "L'événement ne peut être mis à jour que via le web service car une de " . "ses propriétés spécifiques n'est actuellement pas compatible avec la webapp.", @@ -159,6 +166,8 @@ 'Generate Layer' => 'Générer la Couche', 'Generate Map' => 'Générer la Carte', 'Generated URI' => 'URI générée', + 'Generate dataset template' => 'Générer le gabarit du jeux de données', + 'Generate dataset template (Optional)' => 'Generer le gabarit du jeu de données (Optionnel)', 'Geographic Location' => 'Localisation géographique', 'Geometry' => 'Géométrie', 'Graphic visualization' => 'Visualisation graphique', @@ -210,6 +219,8 @@ // N 'Name' => 'Nom', + 'Need a dataset template ? (Optional)'=> 'Besoin d\'un gabarit jeu de données ? (Optionnel)', + 'Next' => 'Suivant', 'No' => 'Non', 'No item concerned' => 'Aucun élément concerné', 'No Specific Property' => 'Aucune Propriété Spécifique', @@ -236,7 +247,10 @@ 'Properties'=>'Propriétés', PropertyWidget::NO_PROPERTY_LABEL => 'Aucune propriété spécifique', 'Provenance comment' => 'Commentaire de la provenance', - 'Provenance (URI)' => 'Provenance (URI)', + 'Provenance (URI)' => 'Identifiant de la provenance', + 'Provenance label' => 'Label de la provenance', + 'Provenance operator(s)' => 'Opérateur(s) lié(s) à la provenance', + 'Provenance sensor(s)' => 'Capteur(s) lié(s) à la provenance', 'Public Access' => 'Accès Public', // Q @@ -302,7 +316,8 @@ 'Update event' => 'Modifier l\'événement', 'Update sensors' => 'Mise à jour des capteurs', 'Update measured variables' => 'Mise à jour des variables mesurées', - + 'Upload dataset' => 'Soumettre le jeu de données', + // V 'Value' => 'Valeur', 'Value Labels' => 'Labels de la Valeur', @@ -312,6 +327,7 @@ 'Variety' => 'Variété', 'Verification Code' => 'Code de vérification', 'View / Download' => 'Visualiser / Télécharger', + 'View' => 'Visualiser', // W 'Was Generated By' => 'Généré Par', diff --git a/translations/fr/messages.php b/translations/fr/messages.php index c44a0538..1599f842 100755 --- a/translations/fr/messages.php +++ b/translations/fr/messages.php @@ -98,7 +98,7 @@ 'Select image view...' => 'Sélectionnez la vue de l\'image...', 'Select provenance...'=>'Sélectionnez la provenance...', 'Select type...' => 'Sélectionnez le type...', - 'Select one or many variables' => 'Sélectionnez une ou plusieurs variables', + 'Select one or more variables' => 'Sélectionnez une ou plusieurs variables', 'Select existing provenance or create a new one' => 'Selectionnez une provenance existante où créez en une nouvelle', 'Software is licensed under AGPL-3.0 and data under CC BY-NC-SA 4.0' => 'Le logiciel est sous licence AGPL-3.0 et les données sous CC BY-NC-SA 4.0', 'Some required fields are missings' => 'Des champs requis sont manquants.', @@ -119,6 +119,7 @@ 'The variety used in the plot (e.g. apache)' => 'La variété du plot (ex. apache)', 'To assign scientific objects to two experiments: (1) create the scientific objects on one of the experiments and (2) update them with the uri of the second experiment.' => 'Pour affecter des objets scientifiques à deux expériences: (1) créez les objets scientifiques sur l\'une des expériences et (2) mettez-les à jour avec l\'uri de la deuxième expérience.', 'to get more information about the columns content' => 'pour obtenir davantage d\'information sur le contenu de chaque colonne', + 'The variables associated to the choosen experiment' => 'Les variables associées à l\'expérimentation choisie', // U 'Unknown error' => 'Erreur inconnue', diff --git a/views/dataset/_form.php b/views/dataset/_form.php old mode 100755 new mode 100644 index b9215a2a..f1cd99c1 --- a/views/dataset/_form.php +++ b/views/dataset/_form.php @@ -25,13 +25,306 @@ /* @var $handsontable openSILEX\handsontablePHP\adapter\HandsontableSimple */ /* @var $handsontableErrorsCellsSettings string */ - if ($handsontable !== null) { - echo $handsontable->loadJSLibraries(true); - echo $handsontable->loadCSSLibraries(); - } - +if ($handsontable !== null) { + echo $handsontable->loadJSLibraries(true); + echo $handsontable->loadCSSLibraries(); +} +use antkaz\vue\VueAsset; +VueAsset::register($this); +$this->registerJsFile("https://rawgit.com/cristijora/vue-form-wizard/master/dist/vue-form-wizard.js"); +$this->registerCssFile("https://rawgit.com/cristijora/vue-form-wizard/master/dist/vue-form-wizard.min.css"); +$this->registerCssFile("https://rawgit.com/lykmapipo/themify-icons/master/css/themify-icons.css"); ?> + +
= Yii::t('app/messages', 'The variables associated to the choosen experiment'); ?>
+ Yii::t('app/messages', 'Select one or more variables') . ' ...', + 'id' => 'uriVariable-selector', + 'multiple' => true + ]; + ?> + + = + $form->field($model, 'variables')->widget(\kartik\select2\Select2::classname(), [ + 'data' => [], + 'options' => $select2VariablesOptions, 'pluginOptions' => [ 'allowClear' => true, - 'tags' => true + 'tags' => false ], - ]); ?> - -= Yii::t('app/messages', 'To create a new provenance, write the provenance label in the research field and press `Enter`. After you will be able to fill provenance input fields and create it by press `Create provenance` button.'); ?>
- = $form->field($model, 'provenanceComment')->textarea(['rows' => 6]) ?> - -| ScientificObjectURI * | -= Yii::t('app/messages', 'The URI of the scientific object (e.g http://www.phenome-fppn.fr/phenovia/2017/o1028649)')?> | -
|---|---|
| Date * | -= Yii::t('app/messages', 'Acquisition date of the data') ?> (format ISO 8601: YYYY-MM-DD or YYYY-MM-DDTHH:mm:ssZ) |
-
| Value * | -= Yii::t('app', 'Value') ?> (= Yii::t('app', 'Real number, String or Date') ?>) | -
- params['csvSeparator'] == ";") { - $csvPath = "semicolon"; - } + = + $form->field($model, 'provenanceUri')->widget(\kartik\select2\Select2::classname(), [ + 'data' => $provenancesArray, + 'options' => [ + 'placeholder' => Yii::t('app/messages', 'Select existing provenance or create a new one') . ' ...', + 'id' => 'provenance-selector', + 'multiple' => false + ], + 'pluginOptions' => [ + 'allowClear' => true, + 'tags' => true + ], + ]); ?> - = Html::a(" " . Yii::t('app', 'Download Template'), \config::path()['basePath'] . 'documents/DatasetFiles/' . $csvPath . '/datasetTemplate.csv', ['id' => 'downloadDatasetTemplate']) ?> - = Html::a(" " . Yii::t('app', 'Download Example'), \config::path()['basePath'] . 'documents/DatasetFiles/' . $csvPath . '/datasetExemple.csv') ?> -
- = $form->field($model, 'file')->widget(FileInput::classname(), [ - 'options' => [ - 'maxFileSize' => 2000, - 'pluginOptions'=>['allowedFileExtensions'=>['csv'],'showUpload' => false], - ] - ]); - ?> -