/**
  * constructor: initialize the service and the default data
  * @return Results
  */
 public function __construct()
 {
     parent::__construct();
     $this->service = ResultsService::singleton();
     $this->deliveryService = DeliveryAssemblyService::singleton();
     $this->defaultData();
 }
 /**
  * Short description of method prepare
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param array resources results
  * @param array columns variables
  * @return mixed
  */
 public function prepare($resources, $columns)
 {
     $resultsService = ResultsService::singleton();
     /**
      * @var \taoDelivery_models_classes_execution_DeliveryExecution $result
      */
     foreach ($resources as $result) {
         $itemresults = $resultsService->getVariables($result, false);
         foreach ($itemresults as $itemResultUri => $vars) {
             // cache the item information pertaining to a given itemResult (stable over time)
             if (common_cache_FileCache::singleton()->has('itemResultItemCache' . $itemResultUri)) {
                 $itemUri = common_cache_FileCache::singleton()->get('itemResultItemCache' . $itemResultUri);
                 $object = new core_kernel_classes_Resource($itemUri);
             } else {
                 $object = $resultsService->getItemFromItemResult($itemResultUri);
                 if (is_null($object)) {
                     $object = $resultsService->getVariableFromTest($itemResultUri);
                 }
                 if (!is_null($object)) {
                     common_cache_FileCache::singleton()->put($object->getUri(), 'itemResultItemCache' . $itemResultUri);
                 }
             }
             if (get_class($object) == "core_kernel_classes_Resource") {
                 $contextIdentifier = (string) $object->getUri();
             } else {
                 if (!is_null($object)) {
                     $contextIdentifier = (string) $object->__toString();
                 }
             }
             foreach ($vars as $var) {
                 $var = $var[0];
                 // cache the variable data
                 /**
                  * @var \taoResultServer_models_classes_Variable $varData
                  */
                 $varData = $var->variable;
                 if (common_cache_FileCache::singleton()->has('variableDataCache' . $var->uri . '_' . $varData->getIdentifier())) {
                     $varData = common_cache_FileCache::singleton()->get('variableDataCache' . $var->uri . '_' . $varData->getIdentifier());
                 } else {
                     common_cache_FileCache::singleton()->put($varData, 'variableDataCache' . $var->uri . '_' . $varData->getIdentifier());
                 }
                 if ($varData->getBaseType() === 'file') {
                     $decodedFile = Datatypes::decodeFile($varData->getValue());
                     $varData->setValue($decodedFile['name']);
                 }
                 $variableIdentifier = (string) $varData->getIdentifier();
                 foreach ($columns as $column) {
                     if ($variableIdentifier == $column->getIdentifier() and $contextIdentifier == $column->getContextIdentifier()) {
                         $epoch = $varData->getEpoch();
                         $readableTime = "";
                         if ($epoch != "") {
                             $readableTime = "@" . tao_helpers_Date::displayeDate(tao_helpers_Date::getTimeStamp($epoch), tao_helpers_Date::FORMAT_VERBOSE);
                         }
                         $this->cache[get_class($varData)][$result][$column->getContextIdentifier() . $variableIdentifier][(string) $epoch] = array($varData->getValue(), $readableTime);
                     }
                 }
             }
         }
     }
 }
 private function getIrregularities($delivery, $from = '', $to = '')
 {
     $export = array(array(__('date'), __('author'), __('test taker'), __('category'), __('subcategory'), __('comment')));
     $deliveryLog = ServiceManager::getServiceManager()->get(DeliveryLog::SERVICE_ID);
     $service = ResultsService::singleton();
     $implementation = $service->getReadableImplementation($delivery);
     $service->setImplementation($implementation);
     $results = $service->getImplementation()->getResultByDelivery(array($delivery->getUri()));
     foreach ($results as $res) {
         $deliveryExecution = \taoDelivery_models_classes_execution_ServiceProxy::singleton()->getDeliveryExecution($res['deliveryResultIdentifier']);
         $logs = $deliveryLog->get($deliveryExecution->getIdentifier(), 'TEST_IRREGULARITY');
         foreach ($logs as $data) {
             $exportable = array();
             if ((empty($from) || $data['created_at'] > $from) && (empty($to) || $data['created_at'] < $to)) {
                 $testTaker = new \core_kernel_classes_Resource($res['testTakerIdentifier']);
                 $author = new \core_kernel_classes_Resource($data['created_by']);
                 $exportable[] = \tao_helpers_Date::displayeDate($data['created_at']);
                 $exportable[] = $author->getLabel();
                 $exportable[] = $testTaker->getLabel();
                 $exportable[] = $data['data']['reason']['reasons']['category'];
                 $exportable[] = isset($data['data']['reason']['reasons']['subCategory']) ? $data['data']['reason']['reasons']['subCategory'] : '';
                 $exportable[] = $data['data']['reason']['comment'];
                 $export[] = $exportable;
             }
         }
     }
     return $export;
 }
 /**
  * @depends testGetItemVariableDataFromDeliveryResult
  * 
  * @author Lionel Lecaque, lionel@taotesting.com
  */
 public function testGetItemVariableDataStatsFromDeliveryResult()
 {
     $prophet = new Prophet();
     $deliveryResultProphecy = $prophet->prophesize('core_kernel_classes_Resource');
     $deliveryResultProphecy->getUri()->willReturn('#fakeUri');
     $deliveryResult = $deliveryResultProphecy->reveal();
     $itemVar = $this->service->getItemVariableDataStatsFromDeliveryResult($deliveryResult, 'lastSubmitted');
     $this->assertArrayHasKey('nbResponses', $itemVar);
     $this->assertEquals(2, $itemVar['nbResponses']);
     $this->assertArrayHasKey('nbCorrectResponses', $itemVar);
     $this->assertEquals(1, $itemVar['nbCorrectResponses']);
     $this->assertArrayHasKey('nbIncorrectResponses', $itemVar);
     $this->assertEquals(1, $itemVar['nbIncorrectResponses']);
     $this->assertArrayHasKey('nbUnscoredResponses', $itemVar);
     $this->assertEquals(0, $itemVar['nbUnscoredResponses']);
     $this->assertArrayHasKey('data', $itemVar);
 }
 public function __construct()
 {
     parent::__construct();
     $this->service = ResultsService::singleton();
 }
 /**
  * @return array
  */
 private function getData()
 {
     $delivery = new \core_kernel_classes_Resource($this->params[0]);
     $resultsService = ResultsService::singleton();
     $filter = 'lastSubmitted';
     $columns = [];
     $testtaker = new \tao_models_classes_table_PropertyColumn(new \core_kernel_classes_Property(PROPERTY_RESULT_OF_SUBJECT));
     $testTakerColumn[] = $testtaker->toArray();
     $cols = array_merge($testTakerColumn, $resultsService->getVariableColumns($delivery, CLASS_OUTCOME_VARIABLE, $filter), $resultsService->getVariableColumns($delivery, CLASS_RESPONSE_VARIABLE, $filter));
     $dataProvider = new VariableDataProvider();
     foreach ($cols as $col) {
         $column = \tao_models_classes_table_Column::buildColumnFromArray($col);
         if (!is_null($column)) {
             if ($column instanceof VariableColumn) {
                 $column->setDataProvider($dataProvider);
             }
             $columns[] = $column;
         }
     }
     $columns[0]->label = __("Test taker");
     $rows = $resultsService->getResultsByDelivery($delivery, $columns, $filter);
     $columnNames = array_reduce($columns, function ($carry, $item) {
         $carry[] = $item->label;
         return $carry;
     });
     $result = [];
     foreach ($rows as $row) {
         $rowResult = [];
         foreach ($row['cell'] as $rowKey => $rowVal) {
             $rowResult[$columnNames[$rowKey]] = $rowVal[0];
         }
         $result[] = $rowResult;
     }
     //If there are no executions yet, the file is exported but contains only the header
     if (empty($result)) {
         $result = [array_fill_keys($columnNames, '')];
     }
     return $result;
 }
 /**
  * Data provider for the table, returns json encoded data according to the parameter
  * @author Bertrand Chevrier, <*****@*****.**>,
  */
 public function data()
 {
     $filterData = $this->hasRequestParameter('filter') ? $this->getRequestParameter('filter') : array();
     $deliveryUri = \tao_helpers_Uri::decode($this->getRequestParameter('uri'));
     $columns = $this->hasRequestParameter('columns') ? $this->getColumns('columns') : array();
     $page = $this->getRequestParameter('page');
     $limit = $this->getRequestParameter('rows');
     $sidx = $this->getRequestParameter('sidx');
     $sord = $this->getRequestParameter('sord');
     $start = $limit * $page - $limit;
     $options = array('recursive' => true, 'like' => false, 'offset' => $start, 'limit' => $limit, 'order' => $sidx, 'orderdir' => $sord);
     $response = new \stdClass();
     $storage = $this->getServiceManager()->get(ResultServerService::SERVICE_ID)->getResultStorage($deliveryUri);
     $this->service->setImplementation($storage);
     $deliveryResults = $storage->getResultByDelivery(array($deliveryUri), $options);
     $counti = $storage->countResultByDelivery(array($deliveryUri));
     $results = array();
     foreach ($deliveryResults as $deliveryResult) {
         $results[] = $deliveryResult['deliveryResultIdentifier'];
     }
     $dpmap = array();
     foreach ($columns as $column) {
         $dataprovider = $column->getDataProvider();
         $found = false;
         foreach ($dpmap as $k => $dp) {
             if ($dp['instance'] == $dataprovider) {
                 $found = true;
                 $dpmap[$k]['columns'][] = $column;
             }
         }
         if (!$found) {
             $dpmap[] = array('instance' => $dataprovider, 'columns' => array($column));
         }
     }
     foreach ($dpmap as $arr) {
         $arr['instance']->prepare($results, $arr['columns']);
     }
     /** @var \taoDelivery_models_classes_execution_DeliveryExecution $result */
     foreach ($results as $result) {
         $data = array('id' => $result);
         foreach ($columns as $column) {
             $key = null;
             if ($column instanceof tao_models_classes_table_PropertyColumn) {
                 $key = $column->getProperty()->getUri();
             } else {
                 if ($column instanceof VariableColumn) {
                     $key = $column->getContextIdentifier() . '_' . $column->getIdentifier();
                 }
             }
             if (!is_null($key)) {
                 if (count($column->getDataProvider()->cache) > 0) {
                     $data[$key] = ResultsService::filterCellData($column->getDataProvider()->getValue(new core_kernel_classes_Resource($result), $column), $filterData);
                 } else {
                     $data[$key] = ResultsService::filterCellData((string) $this->service->getTestTaker($result)->getOnePropertyValue(new \core_kernel_classes_Property(PROPERTY_USER_LOGIN)), $filterData);
                 }
             } else {
                 \common_Logger::w('KEY IS NULL');
             }
         }
         $response->data[] = $data;
     }
     $response->page = (int) $page;
     if ($limit != 0) {
         $response->total = ceil($counti / $limit);
     } else {
         $response->total = 1;
     }
     $response->records = count($results);
     $this->returnJSON($response);
 }
 /**
  * @return ResultsService
  */
 protected function getClassService()
 {
     return ResultsService::singleton();
 }
 public function __construct()
 {
     parent::__construct();
     $this->resultClass = new \core_kernel_classes_Class(TAO_DELIVERY_RESULT);
     $this->resultService = ResultsService::singleton();
 }
 /**
  * Get result service instance.
  * @return \oat\taoOutcomeUi\model\ResultsService;
  */
 protected function getResultService(\core_kernel_classes_Resource $delivery)
 {
     $resultsService = ResultsService::singleton();
     $implementation = $resultsService->getReadableImplementation($delivery);
     $resultsService->setImplementation($implementation);
     return $resultsService;
 }
 /**
  * Short description of method prepare
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  array resources  results
  * @param  array columns    variables
  * @return mixed
  */
 public function prepare($resources, $columns)
 {
     $resultsService = ResultsService::singleton();
     foreach ($resources as $result) {
         $itemresults = $resultsService->getVariables($result, false);
         $cellData = array();
         foreach ($itemresults as $itemResultUri => $vars) {
             //cache the item information pertaining to a given itemResult (stable over time)
             if (common_cache_FileCache::singleton()->has('itemResultItemCache' . tao_helpers_Uri::encode($itemResultUri))) {
                 $itemUri = common_cache_FileCache::singleton()->get('itemResultItemCache' . tao_helpers_Uri::encode($itemResultUri));
                 $object = new core_kernel_classes_Resource($itemUri);
             } else {
                 $object = $resultsService->getItemFromItemResult($itemResultUri);
                 if (is_null($object)) {
                     $object = $resultsService->getVariableFromTest($itemResultUri);
                 }
                 if (!is_null($object)) {
                     common_cache_FileCache::singleton()->put($object->getUri(), 'itemResultItemCache' . tao_helpers_Uri::encode($itemResultUri));
                 }
             }
             if (get_class($object) == "core_kernel_classes_Resource") {
                 $contextIdentifier = (string) $object->getUri();
             } else {
                 if (!is_null($object)) {
                     $contextIdentifier = (string) $object->__toString();
                 }
             }
             foreach ($vars as $var) {
                 $var = $var[0];
                 //cache the variable data
                 $varData = (array) $var->variable;
                 if (common_cache_FileCache::singleton()->has('variableDataCache' . $var->uri . '_' . $varData["identifier"])) {
                     $varData = common_cache_FileCache::singleton()->get('variableDataCache' . $var->uri . '_' . $varData["identifier"]);
                 } else {
                     $varData["class"] = $var->class;
                     common_cache_FileCache::singleton()->put($varData, 'variableDataCache' . $var->uri . '_' . $varData["identifier"]);
                 }
                 $type = $varData["class"];
                 if (isset($varData["value"])) {
                     if (is_array($varData["value"])) {
                         $varData["value"] = json_encode($varData["value"]);
                     }
                 } else {
                     $varData["value"] = $varData["candidateResponse"];
                 }
                 $varData["value"] = base64_decode($varData["value"]);
                 if ($varData["baseType"] === 'file') {
                     $decodedFile = Datatypes::decodeFile($varData['value']);
                     $varData['value'] = $decodedFile['name'];
                 }
                 $variableIdentifier = (string) $varData["identifier"];
                 foreach ($columns as $column) {
                     if ($variableIdentifier == $column->getIdentifier() and $contextIdentifier == $column->getContextIdentifier()) {
                         $value = (string) $varData["value"];
                         $epoch = $varData["epoch"];
                         $readableTime = "";
                         if ($epoch != "") {
                             $readableTime = "@" . tao_helpers_Date::displayeDate(tao_helpers_Date::getTimeStamp($epoch), tao_helpers_Date::FORMAT_VERBOSE);
                         }
                         $this->cache[$type][$result->getUri()][$column->getContextIdentifier() . $variableIdentifier][(string) $epoch] = array($value, $readableTime);
                     }
                 }
             }
         }
     }
 }