value array of properties * to be set on the new resources * * Can be overriden by CsvImporters that are adapted to * import resources of a specific class * * @return array */ protected function getStaticData() { return []; } /** * Returns aditional options to be set to the * GenericAdapterCsv * * Can be overriden by CsvImporters that are adapted to * import resources of a specific class * * @see tao_helpers_data_GenerisAdapterCsv * @return array */ protected function getAdditionAdapterOptions() { return []; } /** * @return array */ protected function getClassProperties($clazz) { $topLevelClass = new \core_kernel_classes_Class(GenerisRdf::CLASS_GENERIS_RESOURCE); $classProperties = \tao_models_classes_TaoService::singleton()->getClazzProperties($clazz, $topLevelClass); return $classProperties; } /** * @param \tao_helpers_data_CsvFile $csv_data * @param boolean $firstRowAsColumnName * @return array */ protected function getColumnMapping($csv_data, $firstRowAsColumnName = true) { //build the mapping form if (!$csv_data->count()) { return []; } // 'class properties' contains an associative array(str:'propertyUri' => 'str:propertyLabel') describing properties belonging to the target class. // 'ranged properties' contains an associative array(str:'propertyUri' => 'str:propertyLabel') describing properties belonging to the target class and that have a range. // 'csv_column' contains an array(int:columnIndex => 'str:columnLabel') that will be used to create the selection of possible CSV column to map in views. // 'csv_column' might have NULL values for 'str:columnLabel' meaning that there was no header row with column names in the CSV file. // Format the column mapping option for the form. if ($firstRowAsColumnName && null != $csv_data->getColumnMapping()) { // set the column label for each entry. // $csvColMapping = array('label', 'comment', ...) return $csv_data->getColumnMapping(); } else { // set an empty value for each entry of the array // to describe that column names are unknown. // $csvColMapping = array(null, null, ...) return array_fill(0, $csv_data->getColumnCount(), null); } } /** * @return array */ public function getValidators() { return $this->validators; } /** * @param array $validators */ public function setValidators($validators) { $this->validators = $validators; } /** * Additional mapping values but that comes from another source than the CSV file. * It enables you to define a mapping that will to work along with the CSV mapping. * * @return the mapping in the same form than the staticData (uri -> val/uri) */ public function getStaticMap() { return []; } /** * @param \core_kernel_classes_Class $class where data will be imported * @param array $options contains parameters under key => value format * file => required * map => required * callbacks => optional * field_delimiter => optional * field_encloser => optional * first_row_column_names => optional * multi_values_delimiter => optional * onResourceImported => optional * staticMap => optional * @return \common_report_Report */ public function importFile($class, $options) { if (!isset($options['file'])) { throw new \BadFunctionCallException("Import file is missing"); } if (!isset($options['staticMap']) || !is_array($options['staticMap'])) { $options['staticMap'] = $this->getStaticData(); } else { $options['staticMap'] = array_merge($options['staticMap'], $this->getStaticData()); } $options = array_merge($options, $this->getAdditionAdapterOptions()); //import the file $adapter = new \tao_helpers_data_GenerisAdapterCsv($options); $adapter->setValidators($this->getValidators()); $report = $adapter->import($options['file'], $class); if ($report->getType() == \common_report_Report::TYPE_SUCCESS) { $report->setData($adapter->getOptions()); } return $report; } }