diff --git a/components/widgets/event/EventButtonWidget.php b/components/widgets/event/EventButtonWidget.php index 80ea914e..234a00cf 100644 --- a/components/widgets/event/EventButtonWidget.php +++ b/components/widgets/event/EventButtonWidget.php @@ -45,13 +45,16 @@ class EventButtonWidget extends Widget { const CONCERNED_ITEMS_URIS = "concernedItemsUris"; /** - * Defines the type of object which will be annotated. + * Defines to wich type of model the event will be create ( scientific object, vector, sensor..). * @var array */ public $type; const TYPE = "type"; + public $size=""; + + const SIZE="size"; /** * Renders the event button. * @return string the string rendered @@ -67,10 +70,10 @@ public function run() { EventController::PARAM_RETURN_URL => Url::current() ]; if (!$this->asLink) { - $linkLabel = Icon::show('flag', [], Icon::FA) . " " . Yii::t('app', self::ADD_EVENT_LABEL); + $linkLabel = Icon::show('flag', ['class'=>$this->size], Icon::FA) . " " . Yii::t('app', self::ADD_EVENT_LABEL); } else { - $linkLabel = ''; + $linkLabel =Icon::show('flag', ['class'=>$this->size], Icon::FA); } if(!isset($this->type)){ $linkAttributes = ['class' => 'btn btn-default']; diff --git a/config/params.php b/config/params.php index 96ffe266..85434f5f 100755 --- a/config/params.php +++ b/config/params.php @@ -142,11 +142,14 @@ 'labelView:side90','labelView:side120','labelView:side150','labelView:side180','labelView:side210', 'labelView:side240','labelView:side270','labelView:side300','labelView:side330', ], - ] + ], // // Image filters GENERIC // 'image.filter' => [ // 'metadata.position' => [ // 'label1:value1','label2:value2', 'label3:value3'], // ] + //Highcharts color + 'highchartsColor' =>["#7cb5ec", "#434348", "#90ed7d", "#f7a35c", "#8085e9", "#f15c80", "#e4d354", "#2b908f", + "#f45b5b", "#91e8e1", "#7cb5ec", "#434348", "#90ed7d", "#f7a35c", "#8085e9", "#f15c80", "#e4d354", "#2b908f", "#f45b5b", "#91e8e1"] ]; diff --git a/controllers/EventController.php b/controllers/EventController.php index 07dc0baf..65cc032d 100644 --- a/controllers/EventController.php +++ b/controllers/EventController.php @@ -1,4 +1,5 @@ */ -class EventController extends GenericController { - +class EventController extends GenericController { + const PARAM_ANNOTATIONS_DATA_PROVIDER = "paramAnnotations"; const PARAM_UPDATABLE = "paramUpdatable"; - const ANNOTATIONS_PAGE = "annotations-page"; const INFRASTRUCTURES_DATA = "infrastructures"; const INFRASTRUCTURES_DATA_URI = "infrastructureUri"; const INFRASTRUCTURES_DATA_LABEL = "infrastructureLabel"; const INFRASTRUCTURES_DATA_TYPE = "infrastructureType"; const EVENT_TYPES = "eventTypes"; - const SENSORS_DATA = "sensors"; const SENSOR_DATA_URI = "sensorUri"; const SENSOR_DATA_LABEL = "sensorLabel"; const SENSOR_DATA_TYPE = "sensorType"; - const PARAM_CONCERNED_ITEMS_URIS = 'concernedItemsUris'; const TYPE = 'type'; const PARAM_RETURN_URL = "returnUrl"; @@ -52,35 +52,77 @@ class EventController extends GenericController { * @var string */ public $returnUrl; - + /** * Lists the events. * @return mixed */ public function actionIndex() { $searchModel = new EventSearch(); - + $searchParams = Yii::$app->request->queryParams; - + if (isset($searchParams[WSConstants::PAGE])) { $searchParams[WSConstants::PAGE] = $searchParams[WSConstants::PAGE] - 1; } $searchParams[WSConstants::PAGE_SIZE] = Yii::$app->params['indexPageSize']; - + $searchResult = $searchModel->search(Yii::$app->session[WSConstants::ACCESS_TOKEN], $searchParams); - + if (is_string($searchResult)) { if ($searchResult === WSConstants::TOKEN_INVALID) { return $this->redirect(Yii::$app->urlManager->createUrl(SiteMessages::SITE_LOGIN_PAGE_ROUTE)); } else { return $this->render(SiteMessages::SITE_ERROR_PAGE_ROUTE, [ - SiteMessages::SITE_PAGE_NAME => SiteMessages::INTERNAL_ERROR, - SiteMessages::SITE_PAGE_MESSAGE => $searchResult]); + SiteMessages::SITE_PAGE_NAME => SiteMessages::INTERNAL_ERROR, + SiteMessages::SITE_PAGE_MESSAGE => $searchResult]); } } else { return $this->render('index', [ - 'searchModel' => $searchModel, - 'dataProvider' => $searchResult]); + 'searchModel' => $searchModel, + 'dataProvider' => $searchResult]); + } + } + + /** + * Return the detail of an event from an Ajax call. + * @param $id URI of the event + * @return mixed redirect in case of error otherwise return the "view" view + */ + public function actionAjaxView($id) { + // Get request parameters + $searchParams = Yii::$app->request->queryParams; + + // Get event + $event = (new YiiEventModel())->getEvent(Yii::$app->session[WSConstants::ACCESS_TOKEN], $id); + if (is_string($event)) { + if ($event === \app\models\wsModels\WSConstants::TOKEN_INVALID) { + return $this->redirect(Yii::$app->urlManager->createUrl("site/login")); + } else { + return $this->renderAjax('/site/error', [ + 'name' => Yii::t('app/messages', 'Internal error'), + 'message' => $event]); + } + } else { + + // Get documents + $searchDocumentModel = new DocumentSearch(); + $searchDocumentModel->concernedItemFilter = $id; + $documentProvider = $searchDocumentModel->search( + Yii::$app->session[WSConstants::ACCESS_TOKEN], [YiiEventModel::CONCERNED_ITEMS => $id]); + + // Get annotations + $annotationProvider = $event->getEventAnnotations(Yii::$app->session[WSConstants::ACCESS_TOKEN], $searchParams); + $annotationProvider->pagination->pageParam = self::ANNOTATIONS_PAGE; + + // Render the view of the event + + return $this->renderAjax('view', [ + 'model' => $event, + 'dataDocumentsProvider' => $documentProvider, + self::PARAM_ANNOTATIONS_DATA_PROVIDER => $annotationProvider, + self::PARAM_UPDATABLE => !$this->hasUnupdatableProperties($event) + ]); } } @@ -92,51 +134,56 @@ public function actionIndex() { public function actionView($id) { // Get request parameters $searchParams = Yii::$app->request->queryParams; - + // Get event $event = (new YiiEventModel())->getEvent(Yii::$app->session[WSConstants::ACCESS_TOKEN], $id); - - // Get documents - $searchDocumentModel = new DocumentSearch(); - $searchDocumentModel->concernedItemFilter = $id; - $documentProvider = $searchDocumentModel->search( - Yii::$app->session[WSConstants::ACCESS_TOKEN], - [YiiEventModel::CONCERNED_ITEMS => $id]); - - // Get annotations - $annotationProvider = $event->getEventAnnotations(Yii::$app->session[WSConstants::ACCESS_TOKEN], $searchParams); - $annotationProvider->pagination->pageParam = self::ANNOTATIONS_PAGE; - - // Render the view of the event - if (is_array($event) && isset($event[WSConstants::TOKEN_INVALID])) { - return redirectToLoginPage(); + if (is_string($event)) { + if ($event === \app\models\wsModels\WSConstants::TOKEN_INVALID) { + return $this->redirect(Yii::$app->urlManager->createUrl("site/login")); + } else { + return $this->render('/site/error', [ + 'name' => Yii::t('app/messages', 'Internal error'), + 'message' => $event]); + } } else { + + // Get documents + $searchDocumentModel = new DocumentSearch(); + $searchDocumentModel->concernedItemFilter = $id; + $documentProvider = $searchDocumentModel->search( + Yii::$app->session[WSConstants::ACCESS_TOKEN], [YiiEventModel::CONCERNED_ITEMS => $id]); + + // Get annotations + $annotationProvider = $event->getEventAnnotations(Yii::$app->session[WSConstants::ACCESS_TOKEN], $searchParams); + $annotationProvider->pagination->pageParam = self::ANNOTATIONS_PAGE; + + // Render the view of the event + return $this->render('view', [ - 'model' => $event, - 'dataDocumentsProvider' => $documentProvider, - self::PARAM_ANNOTATIONS_DATA_PROVIDER => $annotationProvider, - self::PARAM_UPDATABLE => !$this->hasUnupdatableProperties($event) + 'model' => $event, + 'dataDocumentsProvider' => $documentProvider, + self::PARAM_ANNOTATIONS_DATA_PROVIDER => $annotationProvider, + self::PARAM_UPDATABLE => !$this->hasUnupdatableProperties($event) ]); } } - - private function hasUnupdatableProperties($eventAction) : bool { - foreach($eventAction->properties as $property) { - if($property->relation !== Yii::$app->params['from'] - && $property->relation !== Yii::$app->params['to']) { + + private function hasUnupdatableProperties($eventAction): bool { + foreach ($eventAction->properties as $property) { + if ($property->relation !== Yii::$app->params['from'] && $property->relation !== Yii::$app->params['to']) { return true; } } return false; } - + /** * Gets the event types URIs. * @return event types URIs */ public function getSensorTypes() { $model = new \app\models\yiiModels\YiiSensorModel(); - + $sensorsTypes = []; $model->page = 0; $model->pageSize = Yii::$app->params['webServicePageSizeMax']; @@ -148,17 +195,17 @@ public function getSensorTypes() { $sensorsTypes[$sensorType->uri] = $sensorType->uri; } } - + return $sensorsTypes; } - + /** * Gets the event types URIs. * @return event types URIs */ public function getEventsTypes() { $model = new YiiEventModel(); - + $eventsTypes = []; $model->page = 0; $model->pageSize = Yii::$app->params['webServicePageSizeMax']; @@ -170,10 +217,10 @@ public function getEventsTypes() { $eventsTypes[$eventType->uri] = $eventType->uri; } } - + return $eventsTypes; } - + /** * Gets all infrastructures. * @return experiments @@ -187,18 +234,17 @@ public function getInfrastructuresUrisTypesLabels() { return WSConstants::TOKEN_INVALID; } else { foreach ($infrastructures->models as $infrastructure) { - $infrastructuresUrisTypesLabels[] = - [ - self::INFRASTRUCTURES_DATA_URI => $infrastructure->uri, - self::INFRASTRUCTURES_DATA_LABEL => $infrastructure->label, - self::INFRASTRUCTURES_DATA_TYPE => $infrastructure->rdfType - ]; + $infrastructuresUrisTypesLabels[] = [ + self::INFRASTRUCTURES_DATA_URI => $infrastructure->uri, + self::INFRASTRUCTURES_DATA_LABEL => $infrastructure->label, + self::INFRASTRUCTURES_DATA_TYPE => $infrastructure->rdfType + ]; } } - + return $infrastructuresUrisTypesLabels; } - + /** * Gets all sensors. * @return sensors @@ -213,18 +259,17 @@ public function getSensorsUrisTypesLabels() { return WSConstants::TOKEN_INVALID; } else { foreach ($sensors->models as $sensor) { - $sensorsUrisTypesLabels[] = - [ - self::SENSOR_DATA_URI => $sensor->uri, - self::SENSOR_DATA_LABEL => $sensor->label, - self::SENSOR_DATA_TYPE => $sensor->rdfType - ]; + $sensorsUrisTypesLabels[] = [ + self::SENSOR_DATA_URI => $sensor->uri, + self::SENSOR_DATA_LABEL => $sensor->label, + self::SENSOR_DATA_TYPE => $sensor->rdfType + ]; } } - + return $sensorsUrisTypesLabels; } - + /** * Displays the form to create an event or creates it in case of form submission. * @return mixed redirect in case of error or after successfully create @@ -234,21 +279,24 @@ public function actionCreate() { $sessionToken = Yii::$app->session[WSConstants::ACCESS_TOKEN]; $event = new EventCreation(); $event->isNewRecord = true; - // Display form if (!$event->load(Yii::$app->request->post())) { $event->load(Yii::$app->request->get(), ''); - if(Yii::$app->request->get()['type'] === "scientific-objects"){ - $event->load(array(self::PARAM_CONCERNED_ITEMS_URIS =>array_keys(Yii::$app->session['scientific-object'])),''); + if (Yii::$app->request->get()['type'] === "scientific-objects") { + $event->load(array(self::PARAM_CONCERNED_ITEMS_URIS => array_keys(Yii::$app->session['scientific-object'])), ''); + } + if (isset(Yii::$app->request->get()['dateWithoutTimezone'])) { + $validDate = explode(' ', Yii::$app->request->get()['dateWithoutTimezone'])[0]; + $event->dateWithoutTimezone = $validDate; } $event->creator = $this->getCreatorUri($sessionToken); $this->loadFormParams(); - return $this->render('create', ['model' => $event]); - - // Submit form - } else { - $dataToSend[] = $event->attributesToArray(); - $requestResults = $event->insert($sessionToken, $dataToSend); + return $this->render('create', ['model' => $event]); + + // Submit form + } else { + $dataToSend[] = $event->attributesToArray(); + $requestResults = $event->insert($sessionToken, $dataToSend); return $this->handlePostPutResponse($requestResults, $event->returnUrl); } } @@ -262,21 +310,21 @@ public function actionUpdate($id) { $sessionToken = Yii::$app->session[WSConstants::ACCESS_TOKEN]; $event = new EventUpdate(); $event->isNewRecord = false; - + // Display form if (!$event->load(Yii::$app->request->post())) { $event = $event->getEvent($sessionToken, $id); $this->loadFormParams(); - return $this->render('update', ['model' => $event]); - - // Submit form + return $this->render('update', ['model' => $event]); + + // Submit form } else { - $dataToSend[] = $event->attributesToArray(); - $requestResults = $event->update($sessionToken, $dataToSend); - return $this->handlePostPutResponse($requestResults, ['view', 'id' => $event->uri]); + $dataToSend[] = $event->attributesToArray(); + $requestResults = $event->update($sessionToken, $dataToSend); + return $this->handlePostPutResponse($requestResults, ['view', 'id' => $event->uri]); } } - + /** * Loads params used by the forms (creation or update). */ @@ -284,9 +332,8 @@ private function loadFormParams() { $this->view->params[self::EVENT_TYPES] = $this->getEventsTypes(); $this->view->params[self::INFRASTRUCTURES_DATA] = $this->getInfrastructuresUrisTypesLabels(); $this->view->params[self::SENSORS_DATA] = $this->getSensorsUrisTypesLabels(); - } - + /** * Gets the creator of an event. */ @@ -295,4 +342,5 @@ private function getCreatorUri($sessionToken) { $userModel->findByEmail($sessionToken, Yii::$app->session['email']); return $userModel->uri; } + } diff --git a/controllers/ImageController.php b/controllers/ImageController.php index 1a7690e4..1cdf0647 100755 --- a/controllers/ImageController.php +++ b/controllers/ImageController.php @@ -69,7 +69,7 @@ public function actionSearchFromLayer() { * @throws Exception */ public function actionSearchFromScientificObject() { - $searchModel = new DataFileSearch($pageSize = 100); + $searchModel = new DataFileSearch($pageSize = 8000); if ($searchModel->load(Yii::$app->request->post())) { $searchModel->startDate = Yii::$app->request->post()["startDate"]; $searchModel->endDate = Yii::$app->request->post()["endDate"]; @@ -77,11 +77,13 @@ public function actionSearchFromScientificObject() { $searchModel->jsonValueFilter = Yii::$app->request->post()["jsonValueFilter"]; $searchModel->provenance = Yii::$app->request->post()["provenance"]; $searchResult = $searchModel->search(Yii::$app->session['access_token'], Yii::$app->request->post()); - $imagesCount = Yii::$app->request->post()["imagesCount"]; + $imagesCount = Yii::$app->request->post()["imagesCount"]; return $this->renderAjax('_simple_images_visualization', [ 'model' => $searchModel, 'data' => $searchResult, - 'imagesCount' => $imagesCount + 'serieIndex' => Yii::$app->request->post()["serieIndex"], + 'pointIndex' => Yii::$app->request->post()["pointIndex"], + 'imagesCount' => $imagesCount ]); } return $this->renderAjax('_simple_images_visualization', [ diff --git a/controllers/ScientificObjectController.php b/controllers/ScientificObjectController.php index 0959c6a2..6b29fa29 100755 --- a/controllers/ScientificObjectController.php +++ b/controllers/ScientificObjectController.php @@ -17,9 +17,14 @@ use Yii; use yii\web\Controller; use yii\filters\VerbFilter; +use yii\helpers\Url; use app\models\yiiModels\YiiScientificObjectModel; use app\models\yiiModels\ScientificObjectSearch; use app\models\yiiModels\YiiExperimentModel; +use app\models\yiiModels\DataFileSearch; +use app\models\yiiModels\EventSearch; +use app\models\wsModels\WSConstants; +use app\components\helpers\SiteMessages; require_once '../config/config.php'; @@ -426,9 +431,9 @@ public function actionCreateMultipleScientificObjects() { $cpt = 0; $insertionResult = $scientificObjectModel->insert($sessionToken, $forWebService); - + $forWebService = []; - + if ($insertionResult->{\app\models\wsModels\WSConstants::METADATA}->status[0]->exception->type != "Error") { foreach ($insertionResult->{\app\models\wsModels\WSConstants::METADATA}->{\app\models\wsModels\WSConstants::DATA_FILES} as $scientificObjectUri) { $return["objectUris"][] = $scientificObjectUri; @@ -808,13 +813,13 @@ public function actionDownloadCsv() { } else { $wktGeometry = ""; } - - $stringToWrite .= $model->uri . Yii::$app->params['csvSeparator'] . - $model->label . Yii::$app->params['csvSeparator'] . - $model->rdfType . Yii::$app->params['csvSeparator'] . - $model->experiment . Yii::$app->params['csvSeparator'] . - '"' . $wktGeometry . '"' . Yii::$app->params['csvSeparator'] . - "\n"; + + $stringToWrite .= $model->uri . Yii::$app->params['csvSeparator'] . + $model->label . Yii::$app->params['csvSeparator'] . + $model->rdfType . Yii::$app->params['csvSeparator'] . + $model->experiment . Yii::$app->params['csvSeparator'] . + '"' . $wktGeometry . '"' . Yii::$app->params['csvSeparator'] . + "\n"; } $totalPage = intval($searchModel->totalPages); @@ -924,14 +929,23 @@ public function actionDataVisualization($uri, $label, $experimentUri = null) { //Get the list of the variables $variables = []; - - //If the experiment URI is empty, we get all the variables. - if (empty($experimentUri)) { + if (empty($experimentUri)) { //If the experiment URI is empty, we get all the variables. $variableModel = new \app\models\yiiModels\YiiVariableModel(); $variables = $variableModel->getInstancesDefinitionsUrisAndLabel($token); } else { //There is an experiment. Get the variables linked to the experiment. $experimentModel = new YiiExperimentModel(); - $variables = $experimentModel->getMeasuredVariables($token, $scientificObject->experiment); + $variablesSearch = $experimentModel->getMeasuredVariables($token, $scientificObject->experiment); + + if (is_string($variablesSearch)) { + if ($variablesSearch === WSConstants::TOKEN_INVALID) { + return $this->redirect(Yii::$app->urlManager->createUrl(SiteMessages::SITE_LOGIN_PAGE_ROUTE)); + } else { + return $this->render(SiteMessages::SITE_ERROR_PAGE_ROUTE, [ + SiteMessages::SITE_PAGE_NAME => SiteMessages::INTERNAL_ERROR, + SiteMessages::SITE_PAGE_MESSAGE => $variablesSearch]); + } + } + $variables = $experimentModel->variables; } // Load existing provenances @@ -944,47 +958,79 @@ public function actionDataVisualization($uri, $label, $experimentUri = null) { //Search data for the scientific object and the given variable. - if (isset($_POST['variable'])) { + if (isset($_GET['variable']) && !empty($_GET['variable'])) { $toReturn = []; - $searchModel = new \app\models\yiiModels\DataSearchLayers(); - $searchModel->pageSize = 80000; - $searchModel->object = $scientificObject->uri; - - $searchModel->variable = $_POST['variable']; - $searchModel->startDate = $_POST['dateStart']; - $searchModel->endDate = $_POST['dateEnd']; - $searchModel->provenance = $_POST['provenances']; - $searchResult = $searchModel->search($token, null); - /* Build array for highChart + /* Build array for highChart with data and photos by provenances * e.g : - * { - * "variable": "http:\/\/www.opensilex.org\/demo\/id\/variable\/v0000001", - * "scientificObjectData": [ - * "label": "Scientific object label", - * "dataFromProvenance": [ - * "provenance":"Data provenance uri", - * "data": ["1,874809","2015-02-10"], - * ["2,313261","2015-03-15"],.. - * ] - * ] + * {"ProvenanceUri1": { + * "data" :[["1500768000000","1,874809"],..], + * "photos":[ + * [{ + * "url":"", + * "date":"", + * "position":""}], + * [{ + * "url":"", + * "date":"", + * "position":""}],... + * + * + * "ProvenanceUri2": { + * "data" :[["1496793600000","2,313261"],..], + * "photos":[ + * [{ + * "url":"", + * "date":"", + * "position":""}], + * [{ * } */ $data = []; - $scientificObjectData["label"] = $label; + /* Step 1: Raw data : data from the data W.S. + * e.g : + * [{ + * "provenanceUri": "http://www.opensilex.org/demo/id/provenance/1563795626162", + * "date":"1500768000000", + * "value":"1,874809" + * }],[{ + * "provenanceUri": "http://www.opensilex.org/demo/id/provenance/1563795626162", + * "date":"1501112228000", + * "value":"1,845209" + * }],[{ + * "provenanceUri": "http://www.opensilex.org/demo/id/provenance/1563795500410", + * "date":"1496793600000", + * "value":"2,313261" + * }],[..... + */ + $searchModel = new \app\models\yiiModels\DataSearchLayers(); + $searchModel->pageSize = 80000; + $searchModel->object = $scientificObject->uri; + + $searchModel->variable = $_GET['variable']; + $searchModel->startDate = $_GET['dateStart']; + $searchModel->endDate = $_GET['dateEnd']; + $searchModel->provenance = $_GET['provenances']; + $searchModel->dateSortAsc = 'true'; //FIX HIGHCHARTS WHEN FLAGS IS ATTACHED TO A SERIE + $searchResult = $searchModel->search($token, null); foreach ($searchResult->getModels() as $model) { if (!empty($model->value)) { $dataToSave = null; - $provenanceLabel = $provenances[$model->provenanceUri]->label; - $dataToSave["provenanceUri"] = $provenanceLabel . " (prov:" . explode("id/provenance/", $model->provenanceUri)[1] . ")"; + $dataToSave["provenanceUri"] = $model->provenanceUri; $dataToSave["date"] = (strtotime($model->date)) * 1000; $dataToSave["value"] = doubleval($model->value); $data[] = $dataToSave; } } - // Transform to map based to the provenance value $dataByProvenance = array(); + /* Step 2: Transformed Raw data + * e.g : + * { + * "ProvenanceUri1":[["1498262400000","1,874809"],[],..] + * "ProvenanceUri2":[["1496793600000","2,313261"],..], + * } + */ foreach ($data as $dataEl) { $dataByProvenanceToSave = null; $dataByProvenanceToSave[] = $dataEl['date']; @@ -992,38 +1038,124 @@ public function actionDataVisualization($uri, $label, $experimentUri = null) { $dataByProvenance[$dataEl['provenanceUri']][] = $dataByProvenanceToSave; } - if (!empty($data)) { - $toReturn["variable"] = $searchModel->variable; - $scientificObjectData["dataFromProvenance"] = $dataByProvenance; - $toReturn["scientificObjectData"][] = $scientificObjectData; + + /* Step 3: Add photos serie to each provenance or null + * e.g : + * {"ProvenanceUri1": { + * "data" :[["1500768000000","1,874809"],..], + * "photosSerie":[ + * [{ + * "date":"1500768000000", + * "photos": [[url,filtre],[],[],....] }], + * [{ + * "date":"1404896300000", + * "photos": [[url,filtre],[],[],....] }],.., + * ] + * }, + * "ProvenanceUri2": { + * "data" :[["1496793600000","2,313261"],..], + * "photosSerie": null + * } + */ + $isPhotos = false; + if (isset($_GET['show']) && isset($_GET['imageType'])) { + + if (isset($_GET['filter']) && $_GET['filter'] !== "") { + $selectedPositionIndex = $_GET['filter']; + $attribut = explode(":", Yii::$app->params['image.filter']['metadata.position'][$selectedPositionIndex]); + $filterToSend = "{'metadata." . $attribut[0] . "':'" . $attribut[1] . "'}"; + } + + $photosArray = null; + $photosArray = $this->searchImagesByObject($scientificObject->uri, $_GET['imageType'], $filterToSend ? $filterToSend : null, $_GET['dateStart'], $_GET['dateEnd']); + if (isset($photosArray) && !$isPhotos) { + $isPhotos = true; + } + + foreach ($dataByProvenance as $dataFromProvenanceKey => $dataFromProvenanceValue) { + + $toReturn[$dataFromProvenanceKey] = [ + 'data' => $dataFromProvenanceValue, + 'photosSerie' => $photosArray, + ]; + } + } else { + foreach ($dataByProvenance as $dataFromProvenanceKey => $dataFromProvenanceValue) { + + $toReturn[$dataFromProvenanceKey] = [ + 'data' => $dataFromProvenanceValue, + 'photosSerie' => null, + ]; + } } + //Get the events associate to the sci. obj. to put on the Highcharts Graph + $searchModel = null; + $searchModel = new EventSearch(); + $searchModel->pageSize = 800; + $searchModel->searchConcernedItemUri = $uri; + $searchModel->searchDateRangeStart = $_GET['dateStart']; + $searchModel->searchDateRangeEnd = $_GET['dateEnd']; + $searchResult = $searchModel->search($token, null); + if (is_string($searchResult)) { + if ($searchResult === WSConstants::TOKEN_INVALID) { + return $this->redirect(Yii::$app->urlManager->createUrl(SiteMessages::SITE_LOGIN_PAGE_ROUTE)); + } else { + return $this->render(SiteMessages::SITE_ERROR_PAGE_ROUTE, [ + SiteMessages::SITE_PAGE_NAME => SiteMessages::INTERNAL_ERROR, + SiteMessages::SITE_PAGE_MESSAGE => $searchResult]); + } + } else { + foreach ($searchResult->getModels() as $model) { + $events[] = [ + 'date' => (strtotime($model->date)) * 1000, + 'title' => explode('#', $model->rdfType)[1], + 'id' => $model->uri + ]; + } + } + $eventsByTitle = $this->group_by('title', $events); + $eventCategories = array_keys($eventsByTitle); + $highchartsColorArray = Yii::$app->params['highchartsColor']; + $i = 0; + foreach ($eventCategories as $categorie) { + $colorByEventCategorie[$categorie] = $highchartsColorArray[$i]; + $i++; + } + + //info of the variable + if (!empty($experimentUri)) { + $variableModel = new \app\models\yiiModels\YiiVariableModel(); + } + $variableModel->findByURI($token, $_GET['variable']); + $variableInfo = [ + 'label' => $variableModel->label, + 'comment' => $variableModel->comment + ]; //on FORM submitted: //check if image visualization is activated - $show = isset($_POST['show']) ? $_POST['show'] : null; - $selectedVariable = isset($_POST['variable']) ? $_POST['variable'] : null; - $imageTypeSelected = isset($_POST['imageType']) ? $_POST['imageType'] : null; - $selectedProvenance = isset($_POST['provenances']) ? $_POST['provenances'] : null; - if (isset($_POST['filter']) && $_POST['filter'] !== "") { - $selectedPositionIndex = $_POST['filter']; - $attribut=explode(":",Yii::$app->params['image.filter']['metadata.position'][$selectedPositionIndex]); - $filterToSend = "{'metadata." . $attribut[0] . "':'" . $attribut[1] . "'}"; - } + $show = isset($_GET['show']) ? $_GET['show'] : null; + $selectedVariable = isset($_GET['variable']) ? $_GET['variable'] : null; + $imageTypeSelected = isset($_GET['imageType']) ? $_GET['imageType'] : null; + $selectedProvenance = isset($_GET['provenances']) ? $_GET['provenances'] : null; return $this->render('data_visualization', [ 'model' => $scientificObject, 'variables' => $variables, 'data' => $toReturn, 'show' => $show, - 'dateStart' => $searchModel->startDate, - 'dateEnd' => $searchModel->endDate, + 'isPhotos' => $isPhotos, + 'dateStart' => $_GET['dateStart'], + 'dateEnd' => $_GET['dateEnd'], 'selectedVariable' => $selectedVariable, 'imageTypeSelected' => $imageTypeSelected, 'selectedProvenance' => $selectedProvenance, 'selectedPosition' => $selectedPositionIndex, // seems that select widget use index when they are selectable number values 'filterToSend' => $filterToSend, - 'test' => $selectedPosition, + 'events' => $events, + 'colorByEventCategorie' => $colorByEventCategorie, + 'variableInfo' => $variableInfo ]); } else { //If there is no variable given, just redirect to the visualization page. return $this->render('data_visualization', [ @@ -1033,6 +1165,72 @@ public function actionDataVisualization($uri, $label, $experimentUri = null) { } } + /** + * Create an associative array of imagesUri[]/date from an scientific object for a specified object + * [ + { + "date":"1500768000000", + "photos": [[url,filtre],[],[],....] }, + { + "date":"1404896300000", + "photos": [[url,filtre],[],[],....] },.., + * ] + * @param type $objectUri + * @param type $rdfType + * @param type $filter + * @param type $date + * @return associative array + */ + private function searchImagesByObject($objectUri, $rdfType, $filter, $startDate, $endDate) { + + $searchImagesModel = new DataFileSearch($pageSize = 8000); + $searchImagesModel->rdfType = $rdfType; + $searchImagesModel->startDate = $startDate; + $searchImagesModel->endDate = $endDate; + $searchImagesModel->concernedItems = [$objectUri]; + $searchImagesModel->jsonValueFilter = $filter; + $searchResult = $searchImagesModel->search(Yii::$app->session['access_token'], null); + foreach ($searchResult->getModels() as $image) { + $images[] = [ + 'url' => Url::to(['image/get', 'imageUri' => urlencode($image->uri)]), + 'date' => (strtotime($image->date)) * 1000, + 'position' => $image->metadata->position + ]; + } + /* Transformed Raw data + * e.g : + * { + * "Date1":[["url1","1"],["url2","2"],..] + * "Date2":.... + * } + */ + foreach ($images as $imagesEl) { + $imagesByDateToSave = null; + $imagesByDateToSave[] = $imagesEl['url']; + $imagesByDateToSave[] = $imagesEl['position']; + $imagesByDate[$imagesEl['date']][] = $imagesByDateToSave; + } + return $imagesByDate; + } + + /** + * Function that groups an array of associative arrays by some key. + * + * @param {String} $key Property to sort by. + * @param {Array} $data Array that stores multiple associative arrays. + */ + function group_by($key, $array) { + $result = array(); + foreach ($array as $val) { + if (array_key_exists($key, $val)) { + $result[$val[$key]][] = $val; + } else { + $result[""][] = $val; + } + } + return $result; + } + /** * Create an associative array of the provenances objects indexed by their URI * @param type $provenances diff --git a/models/yiiModels/DataFileSearch.php b/models/yiiModels/DataFileSearch.php index f130c219..017951b3 100644 --- a/models/yiiModels/DataFileSearch.php +++ b/models/yiiModels/DataFileSearch.php @@ -18,7 +18,7 @@ * @author Vincent Migot */ class DataFileSearch extends YiiDataFileModel { - + /** * @param string $pageSize number of elements per page * (limited to 150 000) @@ -27,18 +27,18 @@ class DataFileSearch extends YiiDataFileModel { public function __construct($pageSize = null, $page = null) { parent::__construct($pageSize, $page); } - + /** * * @return array the rules of the attributes */ public function rules() { return [ - [['rdfType'], 'required'], - [['concernedItems','jsonValueFilter'], 'safe'] + [['rdfType'], 'required'], + [['concernedItems', 'jsonValueFilter'], 'safe'] ]; } - + /** * * @param array $sessionToken used for the data access @@ -47,12 +47,14 @@ public function rules() { * or string \app\models\wsModels\WSConstants::TOKEN if the user needs to log in */ public function search($sessionToken, $params) { - //1. this load the searched data - $this->load($params); + //1. this load the searched data + if (isset($params)) { + $this->load($params); + } if (isset($params[YiiModelsConstants::PAGE])) { $this->page = $params[YiiModelsConstants::PAGE]; } - + //2. Check validity of search data if (!$this->validate()) { return new ArrayDataProvider(); @@ -62,13 +64,13 @@ public function search($sessionToken, $params) { $params = $this->attributesToArray(); unset($params['uri']); $findResult = $this->find($sessionToken, $params); - if (is_string($findResult)) { return $findResult; - } else if (isset($findResult->{'metadata'}->{'status'}[0]->{'exception'}->{'details'}) - && $findResult->{'metadata'}->{'status'}[0]->{'exception'}->{'details'} === WSConstants::TOKEN_INVALID) { + } else if (isset($findResult->{'metadata'}->{'status'}[0]->{'exception'}->{'details'}) && $findResult->{'metadata'}->{'status'}[0]->{'exception'}->{'details'} === WSConstants::TOKEN_INVALID) { return WSConstants::TOKEN_INVALID; } else { + + return new ArrayDataProvider([ 'models' => $findResult, 'pagination' => [ @@ -78,8 +80,9 @@ public function search($sessionToken, $params) { //SILEX:info //totalCount must be there too to get the pagination in GridView 'totalCount' => $this->totalCount - //\SILEX:info + //\SILEX:info ]); } } + } diff --git a/models/yiiModels/DataSearchLayers.php b/models/yiiModels/DataSearchLayers.php index 59fdaf53..9491fdd9 100644 --- a/models/yiiModels/DataSearchLayers.php +++ b/models/yiiModels/DataSearchLayers.php @@ -29,10 +29,11 @@ class DataSearchLayers extends \app\models\yiiModels\YiiDataModel { /** * @inheritdoc */ + public function rules() { return [ - [['variable', 'startDate', 'endDate', 'provenance', 'object'], 'safe'] + [['variable', 'startDate', 'endDate', 'provenance', 'object','dateSortAsc'], 'safe'] ]; } @@ -89,6 +90,7 @@ public function attributesToArray() { $toReturn["endDate"] = $this->endDate; $toReturn["provenance"] = $this->provenance; $toReturn["pageSize"] = $this->pageSize; + $toReturn["dateSortAsc"] = $this->dateSortAsc; return $toReturn; } diff --git a/models/yiiModels/EventCreation.php b/models/yiiModels/EventCreation.php index 8c91b3a8..ffcfd18b 100644 --- a/models/yiiModels/EventCreation.php +++ b/models/yiiModels/EventCreation.php @@ -32,11 +32,6 @@ class EventCreation extends EventAction { public $creator; const CREATOR = 'creator'; - /** - * To kind of object ? Vector, sensor, scientific object (link to the cart functionnality) - * proposition name: target/ category .. - */ - public $category; /** * @inheritdoc */ diff --git a/models/yiiModels/EventSearch.php b/models/yiiModels/EventSearch.php index e615697b..1c02b2e7 100644 --- a/models/yiiModels/EventSearch.php +++ b/models/yiiModels/EventSearch.php @@ -17,7 +17,9 @@ /** * Search action for the events + * @update [Bonnefont Julien] 1 octobre, 2019: return exception on search action * @author Andréas Garcia + * */ class EventSearch extends YiiEventModel { @@ -124,15 +126,17 @@ public function search($sessionToken, $searchParams) { * @return request result */ private function getEventProvider($sessionToken, $searchParams) { - $results = $this->find($sessionToken, array_merge($this->attributesToArray(), $searchParams)); + $results = $this->find($sessionToken, $this->attributesToArray()); + // var_dump($results);exit; if (is_string($results)) { return $results; - } else if (isset($results->{WSConstants::DATA}->{WSConstants::STATUS}[0]->{WSConstants::EXCEPTION}->{WSConstants::DETAILS}) - && $results->{WSConstants::METADATA}->{WSConstants::STATUS}[0]->{WSConstants::EXCEPTION}->{WSConstants::DETAILS} === WSConstants::TOKEN_INVALID) { - return WSConstants::TOKEN_INVALID; + } else if (isset($results->{'metadata'}->{'status'}[0]->{'exception'}->{'details'}) + && $results->{'metadata'}->{'status'}[0]->{'exception'}->{'details'} === \app\models\wsModels\WSConstants::TOKEN_INVALID) { + return \app\models\wsModels\WSConstants::TOKEN_INVALID; + } else if (isset($results->{'metadata'}->{'status'}[0]->{'exception'}->{'details'})) { + return $results->{'metadata'}->{'status'}[0]->{'exception'}->{'details'}; } else { - $events = $this->jsonListOfArraysToArray($results); return new ArrayDataProvider([ 'models' => $events, diff --git a/models/yiiModels/YiiDataFileModel.php b/models/yiiModels/YiiDataFileModel.php index 49b42448..5a1843a8 100644 --- a/models/yiiModels/YiiDataFileModel.php +++ b/models/yiiModels/YiiDataFileModel.php @@ -73,12 +73,15 @@ class YiiDataFileModel extends WSActiveRecord { const JSON_VALUE_FILTER = "jsonValueFilter"; - + /** + * The URI of the provenance + * @var string + */ public $provenance; const PROVENANCE = "provenance"; - + /** * Initialize wsModel. In this class, wsModel is a WSImageModel @@ -159,7 +162,6 @@ public function attributesToArray() { if ($this->provenance != null) { $attributesArray[self::PROVENANCE] = $this->provenance; } - return $attributesArray; } diff --git a/models/yiiModels/YiiDataModel.php b/models/yiiModels/YiiDataModel.php index cd44dd5b..a373475e 100644 --- a/models/yiiModels/YiiDataModel.php +++ b/models/yiiModels/YiiDataModel.php @@ -30,12 +30,14 @@ class YiiDataModel extends WSActiveRecord { * @var string */ public $variable; + /** * uri of the object concerned by the data. * @example http://www.opensilex.org/demo/2018/o18000076 * @var string */ public $object; + /** * Uri of the provenance of the data. * @example http://www.opensilex.org/id/provenance/02465464 @@ -43,6 +45,12 @@ class YiiDataModel extends WSActiveRecord { */ public $provenance; + /** + * The boolean to sort the date ascending. + * @var boolean + */ + public $dateSortAsc; + /** * * @param string $pageSize number of elements per page diff --git a/models/yiiModels/YiiEventModel.php b/models/yiiModels/YiiEventModel.php index 947219f6..57468830 100644 --- a/models/yiiModels/YiiEventModel.php +++ b/models/yiiModels/YiiEventModel.php @@ -140,9 +140,10 @@ protected function arrayToAttributes($array) { public function getEvent($sessionToken, $uri) { $event = $this->wsModel->getEvent($sessionToken, $uri); if (!is_string($event)) { - if (isset($event[WSConstants::TOKEN_INVALID])) { - return $event; - } else { + if (isset($event->{'metadata'}->{'status'}[0]->{'exception'}->{'details'}) + && $event->{'metadata'}->{'status'}[0]->{'exception'}->{'details'} === \app\models\wsModels\WSConstants::TOKEN_INVALID) { + return \app\models\wsModels\WSConstants::TOKEN_INVALID; + } else { $this->arrayToAttributes($event); $this->uri = $uri; return $this; diff --git a/models/yiiModels/YiiExperimentModel.php b/models/yiiModels/YiiExperimentModel.php index 0fd11a3b..f69f1809 100755 --- a/models/yiiModels/YiiExperimentModel.php +++ b/models/yiiModels/YiiExperimentModel.php @@ -16,7 +16,6 @@ use app\models\wsModels\WSActiveRecord; use app\models\wsModels\WSExperimentModel; - use Yii; /** @@ -25,6 +24,7 @@ * (WSActiveRecord, for the web services access) * @see app\models\wsModels\WSExperimentModel * @see app\models\wsModels\WSActiveRecord + * @update [Bonnefont Julien] 3 octobre, 2019: return exception or token on findByURI * @author Morgane Vidal */ class YiiExperimentModel extends WSActiveRecord { @@ -35,77 +35,99 @@ class YiiExperimentModel extends WSActiveRecord { * @var string */ public $uri; + const URI = "uri"; + /** * the start date of the experiment * (e.g 2017-01-01) * @var string */ public $startDate; + const START_DATE = "startDate"; + /** * the end date of the experiment * (e.g 2017-07-01) * @var string */ public $endDate; + const END_DATE = "endDate"; + /** * the field * (e.g Epoisses - plot F) * @var string */ public $field; + const FIELD = "field"; + /** * the campaign (corresponds to the flowering date) * (e.g 2017) * @var string */ public $campaign; + const CAMPAIGN = "campaign"; + /** * the place of the experiment * (e.g. Bretenière) * @var string */ public $place; + const PLACE = "place"; + /** * the experiment's alias used in the platform * @var string */ public $alias; + const ALIAS = "alias"; + /** * the experiment's comments * (e.g. C17RAP) * @var string */ public $comment; + const COMMENT = "comment"; + /** * the experiment's description keywords * (e.g Colza, azote, phénotypage, capteurs, images, variables agronomiques) * @var string */ public $keywords; + const KEYWORDS = "keywords"; + /** * the experiment's objectives * (e.g Rapsodyn- phénotypage) * @var string */ public $objective; + const OBJECTIVE = "objective"; + /** * the groups (uris) in which the experiment is. * (e.g http://www.phenome-fppn.fr/diaphen/INRA-LEPSE-DROPS) * @var array */ public $groups; + const GROUPS = "groups"; const GROUPS_URIS = "groupsUris"; + /** * the experiment's crop species. It is a string but will be replace by an * array of species uri when the crop species service will be done. @@ -113,54 +135,64 @@ class YiiExperimentModel extends WSActiveRecord { * @var string */ public $cropSpecies; + const CROP_SPECIES = "cropSpecies"; + /** * the projects (uri => acronyme) in which the experiment is. * (e.g http://www.phenome-fppn.fr/phenovia/RAPSODYN => RAPSODYN) * @var array */ public $projects; + const PROJECTS = "projects"; const PROJECTS_URIS = "projectsUris"; - + /** * the project uri where the experiment is searched. * (e.g http://www.phenome-fppn.fr/phenovia/RAPSODYN) * @var string */ public $projectUri; + const PROJECT_URI = "projectUri"; - + /** * the experiment's scientific supervisors contacts (email). * (e.g john.doe[at]inra.fr) * @var array */ public $scientificSupervisorContacts; + const CONTACT_SCIENTIFIC_SUPERVISOR = "http://www.opensilex.org/vocabulary/oeso/#ScientificSupervisor"; const CONTACT_TECHNICAL_SUPERVISOR = "http://www.opensilex.org/vocabulary/oeso/#TechnicalSupervisor"; + /** * the experiment's technical supervisor contacts (email). * (e.g. john.doe[at]inra.fr) * @var array */ public $technicalSupervisorContacts; - + const CONTACTS = "contacts"; const CONTACT_TYPE = "type"; + /** * The list of the variables measured by the experiment * @var array */ public $variables; + const VARIABLES = "variables"; + /** * The list of sensors which participates in the experiment * @var array */ public $sensors; + const SENSORS = "sensors"; - + /** * Initialize wsModel. In this class, wsModel is a WSExperimentModel * @param string $pageSize number of elements per page @@ -172,21 +204,21 @@ public function __construct($pageSize = null, $page = null) { ($pageSize !== null || $pageSize !== "") ? $this->pageSize = $pageSize : $this->pageSize = null; ($page !== null || $page !== "") ? $this->page = $page : $this->page = null; } - + /** * * @return array the rules of the attributes */ public function rules() { return [ - [['uri', 'startDate', 'endDate', 'projects', 'campaign'], 'required'], - [['startDate', 'endDate', 'projects', 'groups', 'scientificSupervisorContacts', 'technicalSupervisorContacts'], 'safe'], - [['comment', 'cropSpecies'], 'string'], - [['uri', 'alias', 'keywords', 'objective'], 'string', 'max' => 255], - [['field', 'campaign', 'place'], 'string', 'max' => 50], + [['uri', 'startDate', 'endDate', 'projects', 'campaign'], 'required'], + [['startDate', 'endDate', 'projects', 'groups', 'scientificSupervisorContacts', 'technicalSupervisorContacts'], 'safe'], + [['comment', 'cropSpecies'], 'string'], + [['uri', 'alias', 'keywords', 'objective'], 'string', 'max' => 255], + [['field', 'campaign', 'place'], 'string', 'max' => 50], ]; } - + /** * * @return array the labels of the attributes @@ -212,13 +244,13 @@ public function attributeLabels() { 'sensors' => Yii::t('app', 'Sensors which participates in') ]; } - + /** * allows to fill the attributes with the informations in the array given * @param array $array array key => value which contains the metadata of * an experiment */ - public function arrayToAttributes($array) { + public function arrayToAttributes($array) { $this->uri = $array[YiiExperimentModel::URI]; $this->startDate = $array[YiiExperimentModel::START_DATE]; $this->endDate = $array[YiiExperimentModel::END_DATE]; @@ -230,15 +262,15 @@ public function arrayToAttributes($array) { $this->keywords = $array[YiiExperimentModel::KEYWORDS]; $this->objective = $array[YiiExperimentModel::OBJECTIVE]; $this->cropSpecies = $array[YiiExperimentModel::CROP_SPECIES]; - + if (isset($array[YiiExperimentModel::PROJECTS])) { foreach ($array[YiiExperimentModel::PROJECTS] as $project) { $experimentProject[YiiProjectModel::URI] = $project->{YiiProjectModel::URI}; $experimentProject[YiiProjectModel::SHORTNAME] = $project->{YiiProjectModel::SHORTNAME}; - $this->projects[] = $experimentProject; + $this->projects[] = $experimentProject; } } - + if (isset($array[YiiExperimentModel::GROUPS])) { foreach ($array[YiiExperimentModel::GROUPS] as $group) { $experimentGroup[YiiGroupModel::URI] = $group->{YiiGroupModel::URI}; @@ -246,13 +278,12 @@ public function arrayToAttributes($array) { $this->groups[] = $experimentGroup; } } - + if (isset($array[YiiExperimentModel::CONTACTS])) { foreach ($array[YiiExperimentModel::CONTACTS] as $contact) { $experimentContact[YiiUserModel::FIRST_NAME] = $contact->{YiiUserModel::FIRST_NAME}; $experimentContact[YiiUserModel::FAMILY_NAME] = $contact->{YiiUserModel::FAMILY_NAME}; $experimentContact[YiiUserModel::EMAIL] = $contact->{YiiUserModel::EMAIL}; - if ($contact->{YiiExperimentModel::CONTACT_TYPE} === YiiExperimentModel::CONTACT_SCIENTIFIC_SUPERVISOR) { $this->scientificSupervisorContacts[] = $experimentContact; } else { @@ -260,16 +291,16 @@ public function arrayToAttributes($array) { } } } - + foreach ($array[YiiExperimentModel::VARIABLES] as $variableUri => $variableLabel) { - $this->variables[$variableUri] = $variableLabel; + $this->variables[$variableUri] = $variableLabel; } - + foreach ($array[YiiExperimentModel::SENSORS] as $sensorUri => $sensorLabel) { - $this->sensors[$sensorUri] = $sensorLabel; + $this->sensors[$sensorUri] = $sensorLabel; } } - + /** * get experiment's informations by uri * @param string $sessionToken user session token @@ -278,25 +309,28 @@ public function arrayToAttributes($array) { public function findByURI($sessionToken, $uri) { $params = []; if ($this->pageSize !== null) { - $params[\app\models\wsModels\WSConstants::PAGE_SIZE] = $this->pageSize; + $params[\app\models\wsModels\WSConstants::PAGE_SIZE] = $this->pageSize; } if ($this->page !== null) { $params[\app\models\wsModels\WSConstants::PAGE] = $this->page; } $requestRes = $this->wsModel->getExperimentByURI($sessionToken, $uri, $params); - + if (!is_string($requestRes)) { - if (isset($requestRes[\app\models\wsModels\WSConstants::TOKEN_INVALID])) { - return $requestRes; + if (isset($requestRes->{'metadata'}->{'status'}[0]->{'exception'}->{'details'}) && $requestRes->{'metadata'}->{'status'}[0]->{'exception'}->{'details'} === \app\models\wsModels\WSConstants::TOKEN_INVALID) { + return \app\models\wsModels\WSConstants::TOKEN_INVALID; + } else if (isset($requestRes->{'metadata'}->{'status'}[0]->{'exception'}->{'details'})) { + return $requestRes->{'metadata'}->{'status'}[0]->{'exception'}->{'details'}; } else { $this->arrayToAttributes($requestRes); return true; } } else { + return $requestRes; } } - + /** * Get the list of uri of the experiments. * @param string $sessionToken @@ -309,25 +343,25 @@ public function findByURI($sessionToken, $uri) { public function getExperimentsURIList($sessionToken) { $experiments = $this->find($sessionToken, $this->attributesToArray()); $experimentsToReturn = []; - + if ($experiments !== null) { //1. get the URIs - foreach($experiments as $experiment) { + foreach ($experiments as $experiment) { $experimentsToReturn[] = $experiment->uri; } - + //2. if there are other pages, get the other experiments if ($this->totalPages > $this->page) { $this->page++; //next page $nextExperiments = $this->getExperimentsURIList($sessionToken); - + $experimentsToReturn = array_merge($experimentsToReturn, $nextExperiments); } - + return $experimentsToReturn; } } - + /** * Get the list of uri of the experiments. * @param string $sessionToken @@ -340,26 +374,26 @@ public function getExperimentsURIList($sessionToken) { public function getExperimentsURIAndLabelList($sessionToken) { $experiments = $this->find($sessionToken, $this->attributesToArray()); $experimentsToReturn = []; - + if ($experiments !== null) { //1. get the URIs - foreach($experiments as $experiment) { + foreach ($experiments as $experiment) { $experimentsToReturn[$experiment->uri] = $experiment->alias; } - + //2. if there are other pages, get the other experiments if ($this->totalPages > $this->page) { $this->page++; //next page $nextExperiments = $this->getExperimentsURIAndLabelList($sessionToken); - + $experimentsToReturn = array_merge($experimentsToReturn, $nextExperiments); } - + return $experimentsToReturn; } } - - /** + + /** * Create an array representing the experiment * Used for the web service for example * @return array with the attributes. @@ -372,25 +406,25 @@ public function attributesToArray() { $elementForWebService[YiiExperimentModel::FIELD] = $this->field; $elementForWebService[YiiExperimentModel::CAMPAIGN] = $this->campaign; $elementForWebService[YiiExperimentModel::PLACE] = $this->place; - $elementForWebService[YiiExperimentModel::ALIAS]= $this->alias; + $elementForWebService[YiiExperimentModel::ALIAS] = $this->alias; $elementForWebService[YiiExperimentModel::COMMENT] = $this->comment; $elementForWebService[YiiExperimentModel::KEYWORDS] = $this->keywords; - $elementForWebService[YiiExperimentModel::OBJECTIVE] = $this->objective; + $elementForWebService[YiiExperimentModel::OBJECTIVE] = $this->objective; $elementForWebService[YiiExperimentModel::GROUPS] = $this->groups; - $elementForWebService[YiiExperimentModel::PROJECTS_URIS] = $this->projects; + $elementForWebService[YiiExperimentModel::PROJECTS_URIS] = $this->projects; $elementForWebService[YiiExperimentModel::CROP_SPECIES] = $this->cropSpecies; // Project Uri is only used in case of search and not in case of posting data if ($this->projectUri != null) { - $elementForWebService[YiiExperimentModel::PROJECT_URI] = $this->projectUri; + $elementForWebService[YiiExperimentModel::PROJECT_URI] = $this->projectUri; } - + if ($this->groups != null) { foreach ($this->groups as $groupUri) { $elementForWebService[YiiExperimentModel::GROUPS_URIS][] = $groupUri; } } - + if ($this->scientificSupervisorContacts != null) { foreach ($this->scientificSupervisorContacts as $scientificSupervisor) { $contact[YiiExperimentModel::CONTACT_TYPE] = YiiExperimentModel::CONTACT_SCIENTIFIC_SUPERVISOR; @@ -398,7 +432,7 @@ public function attributesToArray() { $elementForWebService[YiiExperimentModel::CONTACTS][] = $contact; } } - + if ($this->technicalSupervisorContacts != null) { foreach ($this->technicalSupervisorContacts as $technicalSupervisor) { $contact[YiiExperimentModel::CONTACT_TYPE] = YiiExperimentModel::CONTACT_TECHNICAL_SUPERVISOR; @@ -406,10 +440,10 @@ public function attributesToArray() { $elementForWebService[YiiExperimentModel::CONTACTS][] = $contact; } } - + return $elementForWebService; } - + /** * Update variables measured by an experiment * @param string $sessionToken @@ -419,7 +453,7 @@ public function attributesToArray() { */ public function updateVariables($sessionToken, $experimentUri, $variablesUri) { $requestRes = $this->wsModel->putExperimentVariables($sessionToken, $experimentUri, $variablesUri); - + if (is_string($requestRes) && $requestRes === "token") { return $requestRes; } else if (isset($requestRes->{\app\models\wsModels\WSConstants::METADATA}->{\app\models\wsModels\WSConstants::STATUS})) { @@ -428,7 +462,7 @@ public function updateVariables($sessionToken, $experimentUri, $variablesUri) { return $requestRes; } } - + /** * Update sensors which participates in an experiment * @param string $sessionToken @@ -438,7 +472,7 @@ public function updateVariables($sessionToken, $experimentUri, $variablesUri) { */ public function updateSensors($sessionToken, $experimentUri, $sensorsUris) { $requestRes = $this->wsModel->putExperimentSensors($sessionToken, $experimentUri, $sensorsUris); - + if (is_string($requestRes) && $requestRes === "token") { return $requestRes; } else if (isset($requestRes->{\app\models\wsModels\WSConstants::METADATA}->{\app\models\wsModels\WSConstants::STATUS})) { @@ -447,7 +481,7 @@ public function updateSensors($sessionToken, $experimentUri, $sensorsUris) { return $requestRes; } } - + /** * Get the variables measured by the given experiment * @param string $sessionToken @@ -462,10 +496,11 @@ public function getMeasuredVariables($sessionToken, $experimentUri) { $variables = []; if (!empty($experimentUri)) { if ($this->findByURI($sessionToken, $experimentUri)) { - return $this->variables; + return $this->findByURI($sessionToken, $experimentUri); } } - + return $variables; } + } diff --git a/models/yiiModels/YiiVariableModel.php b/models/yiiModels/YiiVariableModel.php index b55f508a..724ec1d3 100755 --- a/models/yiiModels/YiiVariableModel.php +++ b/models/yiiModels/YiiVariableModel.php @@ -130,7 +130,7 @@ public function findByURI($sessionToken, $uri) { $params[\app\models\wsModels\WSConstants::PAGE] = $this->page; } $requestRes = $this->wsModel->getVariableByURI($sessionToken, $uri, $params); - + if (!is_string($requestRes)) { if (isset($requestRes[\app\models\wsModels\WSConstants::TOKEN_INVALID])) { return $requestRes; diff --git a/translations/fr/app.php b/translations/fr/app.php index 495e201a..fecbba55 100755 --- a/translations/fr/app.php +++ b/translations/fr/app.php @@ -46,6 +46,7 @@ // A 'Acquisition session template' => 'Gabarit de session d\'aquisition', + 'Add an event'=>'Ajouter un événement', 'Add Dataset' => 'Importer un jeu de données', 'Add Document' => 'Ajouter un document', 'Add Document Script' => 'Ajouter un script', diff --git a/translations/fr/messages.php b/translations/fr/messages.php index c44a0538..933ec63d 100755 --- a/translations/fr/messages.php +++ b/translations/fr/messages.php @@ -36,7 +36,8 @@ 'Be carefull to write all the new and the former properties of the updated object.' => 'Attention, veillez à écrire toutes les nouvelles et les anciennes propriétés de l\'objet mis à jour.', // C - 'Click and drag in the plot area to zoom in!' =>'Cliquer et faire glisser pour zoomer sur le graphique!', + 'Click on a serie to add an event!' =>'Cliquer sur une série pour ajouter un événement!', + 'Click on the circle up to the serie to see images.' =>'Cliquer sur le cercle au dessus de la série pour voir l\'image.', 'CSV file headers does not match selected variables' => 'Les en-têtes du fichier CSV ne correspondent pas aux variables sélectionnées', 'CSV separator must be' => 'Le séparateur de champs CSV doit être', @@ -139,7 +140,6 @@ 'You cannot modify already existing traits, methods and units.' => 'Vous ne pouvez pas modifier de traits, méthodes et unités déjà existantes.','Your session has expired' => 'Votre session a expirée', 'You are on PHIS, the Hybrid Information System about Phenotyping!' => 'Bienvenue dans PHIS, le Système d\'Information Hybride pour le Phénotypage !', 'You are on OpenSILEX, the Hybrid Information System about Life Science!' => 'Bienvenue dans OpenSILEX, le Système d\'Information Hybride pour les Sciences de la Vie !', - 'You have to click a graphic point to see images on that date.' => 'Vous devez clicker sur un point du graphique pour voir les images à cette date.', 'You wish to get notified when new developments are available ? You can follow us on' => 'Vous souhaitez vous tenir informé des derniers développements disponibles ? Vous pouvez nous suivre sur', 'You wish to report a bug or to get help ? OpenSILEX development team can be contacted through the email address' => 'Vous souhaitez nous signaler une erreur ou bien nous demander de l\'aide ? L\'équipe de développement d\'OpenSILEX peut être contactée via l\'adresse' ]; diff --git a/views/event/view.php b/views/event/view.php index a43c7f4a..260efc6d 100644 --- a/views/event/view.php +++ b/views/event/view.php @@ -28,7 +28,7 @@ $this->params['breadcrumbs'][] = ['label' => Yii::t('app', '{n, plural, =1{Event} other{Events}}', ['n' => 2]), 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; ?> -
+

rdfType)) ?>

$model->uri] : false, diff --git a/views/image/_simple_images_visualization.php b/views/image/_simple_images_visualization.php index c5765be7..82775299 100644 --- a/views/image/_simple_images_visualization.php +++ b/views/image/_simple_images_visualization.php @@ -54,6 +54,8 @@ 'title' => 'Position: ' . $position . '
Date: ' . $date, 'data-toggle' => 'tooltip', 'data-placement' => 'bottom', + 'data-serie'=>$serieIndex, + 'data-point'=>$pointIndex, ]) . ''; $first = false; diff --git a/views/scientific-object/data_visualization.php b/views/scientific-object/data_visualization.php index 193a1870..387e7de6 100644 --- a/views/scientific-object/data_visualization.php +++ b/views/scientific-object/data_visualization.php @@ -10,9 +10,12 @@ use Yii; use yii\widgets\ActiveForm; use yii\helpers\Html; -use miloschuman\highcharts\Highcharts; +use miloschuman\highcharts\Highstock; use yii\web\JsExpression; use yii\helpers\Url; +use app\controllers\EventController; +use app\components\widgets\AnnotationButtonWidget; +use app\components\widgets\event\EventButtonWidget; $this->title = $model->label; $this->params['breadcrumbs'][] = ['label' => Yii::t('app', '{n, plural, =1{Scientific Object} other{Scientific Objects}}', ['n' => 2]), 'url' => ['index']]; @@ -27,26 +30,28 @@ ?>
-
'get', + 'action' => Url::to(['data-visualization', 'uri' => $model->uri, 'label' => $model->label, 'experimentUri' => $model->experiment]), //ensure you don't repeat get parameters + ]); + if (empty($variables)) { echo "

" . Yii::t('app/messages', 'No variables linked to the experiment of the scientific object.') . "

"; } else { ?>
-
-
-
- +
+ 'variable', @@ -93,6 +98,7 @@ ]); ?>
+
@@ -135,9 +141,7 @@
- 'showWidget', 'label' => Yii::t('app', 'Show Images'), 'onchange' => 'onShow(this);']) ?> -
@@ -146,11 +150,12 @@ -
+
- + 'imageType', @@ -169,10 +174,10 @@ ]); ?>
-
- - +
+ 'filter', @@ -201,46 +206,46 @@
-
- -
-

".Yii::t('app/messages', 'You have to click a graphic point to see images on that date.')."

"; - } - ?> - -
    - -
- -