Fix conclict.

This commit is contained in:
mateuswetah 2018-09-28 14:04:22 -03:00
commit a9c7add5b1
23 changed files with 962 additions and 786 deletions

View File

@ -14,8 +14,8 @@ This method takes an array as argument, with the defintion of your importer. The
```
@type string $name The name of the importer. e.g. 'Example Importer'
@type string $slug A unique slug for the importer. e.g. 'This is an example importer description'
@type string $description The importer description. e.g. 'example-importer'
@type string $slug A unique slug for the importer. e.g. 'example-importer'
@type string $description The importer description. e.g. 'This is an example importer description'
@type string $class_name The Importer Class. e.g. '\Tainacan\Importer\Test_Importer'
@type bool $manual_mapping Wether Tainacan must present the user with an interface to manually map
the metadata from the source to the target collection.

938
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -34,7 +34,7 @@
"css-loader": "^1.0.0",
"element-theme-chalk": "^2.4.7",
"eslint": "^5.6.0",
"eslint-loader": "^2.1.0",
"eslint-loader": "^2.1.1",
"eslint-plugin-vue": "^4.7.1",
"file-loader": "^2.0.0",
"postcss-loader": "^3.0.0",
@ -44,8 +44,8 @@
"vue-custom-element": "^3.2.5",
"vue-loader": "^15.4.2",
"vue-template-compiler": "^2.5.17",
"webpack": "^4.19.1",
"webpack-cli": "^3.1.0",
"webpack-dev-server": "^3.1.8"
"webpack": "^4.20.2",
"webpack-cli": "^3.1.1",
"webpack-dev-server": "^3.1.9"
}
}

View File

@ -19,104 +19,157 @@
</span>
</div>
<div
v-if="!isSearching && !isTaxonomy"
class="modal-card-body tainacan-checkbox-list-container">
<a
v-if="checkboxListOffset"
role="button"
class="tainacan-checkbox-list-page-changer"
@click="beforePage">
<b-icon
icon="chevron-left"/>
</a>
<ul
:class="{
<b-tabs
v-if="!isSearching"
size="is-small"
expanded
animated
@input="fetchSelectedLabels()"
v-model="activeTab">
<b-tab-item :label="$i18n.get('label_all_terms')">
<div
v-if="!isSearching && !isTaxonomy"
class="modal-card-body tainacan-checkbox-list-container">
<a
v-if="checkboxListOffset"
role="button"
class="tainacan-checkbox-list-page-changer"
@click="beforePage">
<b-icon
icon="chevron-left"/>
</a>
<ul
:class="{
'tainacan-modal-checkbox-list-body-dynamic-m-l': !checkboxListOffset,
'tainacan-modal-checkbox-list-body-dynamic-m-r': noMorePage,
}"
class="tainacan-modal-checkbox-list-body">
<li
class="tainacan-li-checkbox-list"
v-for="(option, key) in options"
:key="key">
<b-checkbox
v-model="selected"
:native-value="option.value">
{{ `${ limitChars(option.label) }` }}
</b-checkbox>
</li>
<b-loading
:is-full-page="false"
:active.sync="isCheckboxListLoading"/>
</ul>
<a
v-if="!noMorePage"
role="button"
class="tainacan-checkbox-list-page-changer"
@click="nextPage">
<b-icon
icon="chevron-right"/>
</a>
</div>
<div
v-if="!isSearching && isTaxonomy"
class="modal-card-body tainacan-finder-columns-container">
<ul
class="tainacan-finder-column"
v-for="(finderColumn, key) in finderColumns"
:key="key">
<b-field
role="li"
:addons="false"
v-if="finderColumn.length"
class="tainacan-li-checkbox-modal"
v-for="(option, index) in finderColumn"
:id="`${key}.${index}-tainacan-li-checkbox-model`"
:ref="`${key}.${index}-tainacan-li-checkbox-model`"
:key="index">
<b-checkbox
v-if="isCheckbox"
v-model="selected"
:native-value="option.value">
{{ `${option.label}` }}
</b-checkbox>
<b-radio
v-else
v-model="selected"
:native-value="option.value">
{{ `${option.label}` }}
</b-radio>
class="tainacan-modal-checkbox-list-body">
<li
class="tainacan-li-checkbox-list"
v-for="(option, key) in options"
:key="key">
<b-checkbox
v-model="selected"
:native-value="option.value">
{{ `${ limitChars(option.label) }` }}
</b-checkbox>
</li>
<b-loading
:is-full-page="false"
:active.sync="isCheckboxListLoading"/>
</ul>
<a
v-if="option.total_children > 0"
@click="getOptionChildren(option, key, index)">
v-if="!noMorePage"
role="button"
class="tainacan-checkbox-list-page-changer"
@click="nextPage">
<b-icon
class="is-pulled-right"
icon="menu-right"
/>
icon="chevron-right"/>
</a>
</b-field>
<li v-if="finderColumn.length">
<div
v-if="finderColumn.length < totalRemaining[key].remaining"
@click="getMoreOptions(finderColumn, key)"
class="tainacan-show-more">
<b-icon
size="is-small"
icon="chevron-down"/>
</div>
</li>
<b-loading
:is-full-page="false"
:active.sync="isColumnLoading"/>
</ul>
</div>
</div>
<div
v-if="!isSearching && isTaxonomy"
class="modal-card-body tainacan-finder-columns-container">
<ul
class="tainacan-finder-column"
v-for="(finderColumn, key) in finderColumns"
:key="key">
<b-field
role="li"
:addons="false"
v-if="finderColumn.length"
class="tainacan-li-checkbox-modal"
v-for="(option, index) in finderColumn"
:id="`${key}.${index}-tainacan-li-checkbox-model`"
:ref="`${key}.${index}-tainacan-li-checkbox-model`"
:key="index">
<b-checkbox
v-if="isCheckbox"
v-model="selected"
:native-value="option.value">
{{ `${option.label}` }}
</b-checkbox>
<b-radio
v-else
v-model="selected"
:native-value="option.value">
{{ `${option.label}` }}
</b-radio>
<a
v-if="option.total_children > 0"
@click="getOptionChildren(option, key, index)">
<b-icon
class="is-pulled-right"
icon="menu-right"
/>
</a>
</b-field>
<li v-if="finderColumn.length">
<div
v-if="finderColumn.length < totalRemaining[key].remaining"
@click="getMoreOptions(finderColumn, key)"
class="tainacan-show-more">
<b-icon
size="is-small"
icon="chevron-down"/>
</div>
</li>
</ul>
<b-loading
:is-full-page="false"
:active.sync="isColumnLoading"/>
</div>
<nav
style="margin-top: 10px;"
class="breadcrumb is-small has-succeeds-separator"
aria-label="breadcrumbs">
<ul>
<li
v-for="(pathItem, pi) in hierarchicalPath"
:class="{'is-active': pi === hierarchicalPath.length-1}"
:key="pi">
<a
@click="getOptionChildren(pathItem.option, pathItem.column, pathItem.element)">
{{ pathItem.option.label }}
</a>
</li>
</ul>
</nav>
</b-tab-item>
<b-tab-item
:label="$i18n.get('label_selected_terms')">
<div class="modal-card-body tainacan-tags-container">
<b-field
grouped
group-multiline>
<div
v-for="(term, index) in (selected instanceof Array ? selected : [this.selected])"
:key="index"
class="control">
<b-tag
attached
closable
@close="selected.splice(index, 1)">
{{ isTaxonomy ? selectedTagsName[term] : term }}
</b-tag>
</div>
</b-field>
<b-loading
:is-full-page="false"
:active.sync="isSelectedTermsLoading"/>
</div>
</b-tab-item>
</b-tabs>
<!--<pre>{{ hierarchicalPath }}</pre>-->
<!--<pre>{{ totalRemaining }}</pre>-->
<!--<pre>{{ selected }}</pre>-->
<!--<pre>{{ options }}</pre>-->
<!--<pre>{{ searchResults }}</pre>-->
<!--<pre>{{ selectedTagsName }}</pre>-->
<div
v-if="isSearching"
@ -219,6 +272,9 @@
isSearchingLoading: false,
noMorePage: 0,
maxTextToShow: 47,
activeTab: 0,
selectedTagsName: {},
isSelectedTermsLoading: false,
}
},
updated(){
@ -236,6 +292,37 @@
}
},
methods: {
fetchSelectedLabels() {
this.isSelectedTermsLoading = true;
let selected = this.selected instanceof Array ? this.selected : [this.selected];
if(this.taxonomy_id && selected.length) {
for (const term of selected) {
if(!this.isSelectedTermsLoading){
this.isSelectedTermsLoading = true;
}
axios.get(`/taxonomy/${this.taxonomy_id}/terms/${term}`)
.then((res) => {
this.saveSelectedTagName(res.data.id, res.data.name);
this.isSelectedTermsLoading = false;
})
.catch((error) => {
this.$console.log(error);
this.isSelectedTermsLoading = false;
});
}
} else {
this.isSelectedTermsLoading = false;
}
},
saveSelectedTagName(value, label){
if(!this.selectedTagsName[value]) {
this.$set(this.selectedTagsName, `${value}`, label);
}
},
limitChars(label){
if(label.length > this.maxTextToShow){
return label.slice(0, this.maxTextToShow)+'...';
@ -342,12 +429,13 @@
}
}
},
addToHierarchicalPath(column, element){
addToHierarchicalPath(column, element, option){
let found = undefined;
let toBeAdded = {
column: column,
element: element
element: element,
option: option,
};
for (let f in this.hierarchicalPath) {
@ -418,7 +506,7 @@
let query_items = { 'current_query': this.query };
if(key != undefined) {
this.addToHierarchicalPath(key, index);
this.addToHierarchicalPath(key, index, option);
}
let parent = 0;
@ -514,6 +602,10 @@
@import "../../scss/variables.scss";
.breadcrumb {
background-color: white !important;
}
@media screen and (max-width: 768px) {
.tainacan-modal-content {
flex-direction: column;
@ -644,7 +736,9 @@
list-style: none;
margin: 0;
padding: 0rem;
}
ul {
// For Safari
-webkit-margin-after: 0;
-webkit-margin-start: 0;
@ -662,7 +756,7 @@
}
.tainacan-checkbox-search-section {
margin-bottom: 40px;
margin-bottom: 25px;
display: flex;
align-items: center;
position: relative;
@ -725,19 +819,17 @@
min-height: 253px;
}
.tainacan-tags-container {
padding: 0 20px !important;
min-height: 253px;
}
.tainacan-modal-checkbox-search-results-body {
list-style: none;
display: flex;
flex-direction: column;
flex-wrap: wrap;
max-height: 253px;
// For Safari
-webkit-margin-after: 0;
-webkit-margin-start: 0;
-webkit-margin-end: 0;
-webkit-padding-start: 0;
-webkit-margin-before: 0;
}
.tainacan-li-no-children {

View File

@ -0,0 +1,93 @@
<template>
<form action="">
<div
class="tainacan-modal-content"
style="width: auto">
<header class="tainacan-modal-title">
<h2>{{ this.$i18n.get('collections') }}</h2>
<hr>
</header>
<section class="tainacan-form">
<p>{{ $i18n.get('instruction_select_a_target_collection') }}</p>
<div
v-if="!isLoading"
class="collection-types-container">
<div
class="collection-type"
v-for="(collection, index) in collections"
:key="index"
@click="onSelectCollection(collection)">
<h4>{{ collection.name }}</h4>
<p>{{ collection.length > 200 ? (collection.description.substring(0,197) + '...') : collection.description }}</p>
</div>
</div>
<b-loading
:active.sync="isLoading"
:can-cancel="false"/>
</section>
</div>
</form>
</template>
<script>
import { mapActions } from 'vuex';
export default {
name: 'CollectionsModal',
data(){
return {
collections: [],
isLoading: false
}
},
methods: {
...mapActions('collection', [
'fetchCollections'
]),
onSelectCollection(collection) {
this.$router.push(this.$routerHelper.getNewItemPath(collection.id));
this.$parent.close();
}
},
mounted() {
this.isLoading = true;
this.fetchCollections({ page: 1, collectionsPerPage: 96 })
.then((res) => {
this.collections = res.collections;
this.isLoading = false;
}).catch((error) => {
this.$console.log(error);
this.isLoading = false;
});
}
}
</script>
<style lang="scss" scoped>
@import "../../scss/_variables.scss";
.collection-types-container {
.collection-type {
border-bottom: 1px solid $gray2;
padding: 15px 8.3333333%;
cursor: pointer;
&:first-child {
margin-top: 15px;
}
&:last-child {
border-bottom: none;
}
&:hover {
background-color: $gray2;
}
}
}
</style>

View File

@ -148,7 +148,7 @@
<b-icon icon="menu-down"/>
</button>
<b-dropdown-item>
<b-dropdown-item v-if="!isRepositoryLevel">
<router-link
id="a-create-item"
tag="div"
@ -156,6 +156,14 @@
{{ $i18n.get('add_one_item') }}
</router-link>
</b-dropdown-item>
<b-dropdown-item v-if="isRepositoryLevel">
<div
id="a-create-item"
tag="div"
@click="onOpenCollectionsModal">
{{ $i18n.get('add_one_item') }}
</div>
</b-dropdown-item>
<b-dropdown-item disabled>
{{ $i18n.get('add_items_bulk') + ' (Not ready)' }}
</b-dropdown-item>
@ -669,6 +677,7 @@
import Pagination from '../../components/search/pagination.vue'
import AdvancedSearch from '../../components/advanced-search/advanced-search.vue';
import AvailableImportersModal from '../../components/other/available-importers-modal.vue';
import CollectionsModal from '../../components/other/collections-modal.vue';
import { mapActions, mapGetters } from 'vuex';
export default {
@ -810,6 +819,13 @@
}
});
},
onOpenCollectionsModal() {
this.$modal.open({
parent: this,
component: CollectionsModal,
hasModalCard: true
});
},
updateSearch() {
this.$eventBusSearch.setSearchQuery(this.futureSearchQuery);
},

View File

@ -1,14 +1,19 @@
.tainacan-cards-container {
min-height: 50vh;
padding: 0;
display: flex;
flex-wrap: wrap;
flex-grow: 1;
flex-shrink: 1;
display: -ms-grid;
display: grid;
grid-template-columns: repeat(auto-fill, 455px);
grid-gap: 0px;
justify-content: space-evenly;
animation-name: item-appear;
animation-duration: 0.5s;
@media screen and (max-width: 480px) {
width: 91.666666667%;
grid-template-columns: repeat(auto-fill, 100%);
}
.selected-card {
background-color: $turquoise1;
.metadata-title {

View File

@ -1,10 +1,10 @@
.tainacan-grid-container {
min-height: 50vh;
padding: 0;
display: flex;
flex-wrap: wrap;
flex-grow: 1;
flex-shrink: 1;
display: -ms-grid;
display: grid;
grid-template-columns: repeat(auto-fill, 285px);
grid-gap: 0px;
justify-content: space-evenly;
animation-name: item-appear;
animation-duration: 0.5s;
@ -18,7 +18,6 @@
flex-basis: 0;
margin: 15px;
text-align: center;
height: 100%;
&:hover {
background-color: $gray2;

View File

@ -8,3 +8,4 @@
@import "../../../node_modules/bulma/sass/elements/button.sass"
@import "../../../node_modules/bulma/sass/grid/columns.sass"
@import "../../../node_modules/bulma/sass/components/modal.sass"
@import "../../../node_modules/bulma/sass/components/breadcrumb.sass"

View File

@ -308,6 +308,8 @@ return apply_filters( 'tainacan-admin-i18n', [
'label_description_not_informed' => __( 'Description not informed.', 'tainacan' ),
'label_hide_metadata' => __( 'Hide metadata', 'tainacan' ),
'label_show_metadata' => __( 'Show metadata', 'tainacan' ),
'label_all_terms' => __( 'All terms', 'tainacan' ),
'label_selected_terms' => __( 'Selected terms', 'tainacan'),
// Instructions. More complex sentences to guide user and placeholders
'instruction_delete_selected_collections' => __( 'Delete selected collections', 'tainacan' ),

View File

@ -137,7 +137,7 @@ class REST_Facets_Controller extends REST_Controller {
wp_reset_postdata();
}
$this->total_items = $items->found_posts;
$this->total_items = $items->found_posts;
$this->total_pages = ceil($this->total_items / (int) $items->query_vars['posts_per_page']);
}
@ -168,7 +168,6 @@ class REST_Facets_Controller extends REST_Controller {
$term_selected = $this->terms_repository->fetch($term_id, $this->taxonomy);
$realResponse[] = $term_selected;
}
foreach( $terms as $index => $term ){
@ -423,7 +422,6 @@ class REST_Facets_Controller extends REST_Controller {
if( $metaquery['key'] == $metadatum_id ){
return $metaquery['value'];
}
}
@ -448,7 +446,6 @@ class REST_Facets_Controller extends REST_Controller {
if( $metaquery['key'] == $metadatum_id ){
return $metaquery['value'];
}
}
@ -482,6 +479,70 @@ class REST_Facets_Controller extends REST_Controller {
return $values;
}
/**
* method responsible to return the total of items for the facet value
*
* @param value string/int the facet value
* @param reference_id int the taxonomy or the metadataid
* @param is_taxonomy (default) false if the value param is a term
* @param query the actual request query to filter the items
*
* @return int total of items found
*/
private function add_items_count( $value, $reference_id, $is_taxonomy = false, $query, $collection_id){
$new_args = $query;
$has_value = false;
if( !$is_taxonomy ){
if( isset( $query['metaquery'] ) ){
foreach( $query['metaquery'] as $index => $metaquery ){
if( $metaquery['key'] == $metadatum_id ){
$has_value = true;
if( is_array($metaquery['value']) )
$new_args['metaquery'][$index]['value'][] = $value;
else
$new_args['metaquery'][$index]['value'] = $value;
}
}
}
if( !$has_value ){
$new_args['metaquery'][] = [
'key' => $reference_id,
'value' => $value
];
}
} else {
if( isset( $query['taxquery'] ) ){
foreach( $query['taxquery'] as $taxquery ){
if( $taxquery['taxonomy'] === 'tnc_tax_' . $reference_id ){
$has_value = true;
$new_args['taxquery'][$index]['terms'][] = $value;
}
}
}
if( !$has_value ){
$new_args['taxquery'][] = [
'taxonomy' => 'tnc_tax_' . $reference_id,
'value' => [$value]
];
}
}
$items = $this->items_repository->fetch($new_args, $collection_id, 'WP_Query');
return $items->found_posts;
}
}
?>

View File

@ -283,7 +283,7 @@ class REST_Importers_Controller extends REST_Controller {
$files = $request->get_file_params();
$headers = $request->get_headers();
if ( $importer->add_file($files['file']) ) {
if ( isset($files['file']) && $importer->add_file($files['file']) ) {
$response = $importer->_to_Array();
return new \WP_REST_Response( $response, 200 );
} else {

View File

@ -633,7 +633,11 @@ class Item extends Entity {
if ( $type == 'url' ) {
global $wp_embed;
$output .= $wp_embed->autoembed($this->get_document());
$_embed = $wp_embed->autoembed($this->get_document());
if ( $_embed == $this->get_document() ) {
$_embed = sprintf('<a href="%s" target="blank">%s</a>', $this->get_document(), $this->get_document());
}
$output .= $_embed;
} elseif ( $type == 'text' ) {
$output .= $this->get_document();
} elseif ( $type == 'attachment' ) {

View File

@ -28,7 +28,7 @@
<script>
import { tainacan as axios } from '../../../js/axios/axios';
import { filter_type_mixin } from '../filter-types-mixin';
import CheckboxFilterModal from '../../../admin/components/other/checkbox-filter-modal.vue';
import CheckboxRadioModal from '../../../admin/components/other/checkbox-radio-modal.vue';
export default {
created(){
@ -195,7 +195,7 @@
openCheckboxModal() {
this.$modal.open({
parent: this,
component: CheckboxFilterModal,
component: CheckboxRadioModal,
props: {
//parent: parent,
filter: this.filter,

View File

@ -28,7 +28,7 @@
<script>
import qs from 'qs';
import { tainacan as axios } from '../../../js/axios/axios';
import CheckboxFilterModal from '../../../admin/components/other/checkbox-filter-modal.vue';
import CheckboxRadioModal from '../../../admin/components/other/checkbox-radio-modal.vue';
export default {
created(){
@ -220,7 +220,7 @@
openCheckboxModal(parent) {
this.$modal.open({
parent: this,
component: CheckboxFilterModal,
component: CheckboxRadioModal,
props: {
parent: parent,
filter: this.filter,

View File

@ -35,7 +35,7 @@
import TainacanTaxonomyCheckbox from './TaxonomyCheckbox.vue'
import TainacanTaxonomyTagInput from './TaxonomyTaginput.vue'
import AddNewTerm from './AddNewTerm.vue'
import HierarchicalCheckboxModal from '../../../admin/components/other/checkbox-filter-modal.vue'
import CheckboxRadioModal from '../../../admin/components/other/checkbox-radio-modal.vue'
export default {
created(){
@ -114,7 +114,7 @@
openCheckboxModal(){
this.$modal.open({
parent: this,
component: HierarchicalCheckboxModal,
component: CheckboxRadioModal,
props: {
isFilter: false,
parent: 0,

View File

@ -187,7 +187,7 @@ class Metadata extends Repository {
'type' => __( 'string' ),
'validation' => v::stringType()->in( [ 'yes', 'no', 'never' ] ),
'description' => __( 'Display by default on listing or do not display or never display.', 'tainacan' ),
'default' => 'yes'
'default' => 'no'
],
'semantic_uri' => [
'map' => 'meta',

View File

@ -55,7 +55,11 @@ function tainacan_autoload($class_name){
$sliced = array_slice($class_path, 1, count($class_path) -2);
if( isset( $class_path[1] ) && $class_path[1] === 'Importer' ){
$dir = TAINACAN_IMPORTER_DIR;
$dir = TAINACAN_IMPORTER_DIR;
$dir_import = strtolower(str_replace('_', '-' , $class_name));
if (file_exists("$dir$dir_import/")) {
$dir .= "$dir_import/";
}
} else if( isset( $class_path[1] ) && $class_path[1] === 'Exposers' ){
$dir = TAINACAN_EXPOSERS_DIR;
if(count($class_path) > 3) $dir .= strtolower($class_path[2]).DIRECTORY_SEPARATOR;

View File

@ -43,8 +43,23 @@ class Importer_Handler {
'manual_mapping' => false,
]);
$this->register_importer([
'name' => 'Vocabulary CSV',
'description' => __('Import a vaculary from a CSV file into a taxonomy', 'tainacan'),
'slug' => 'terms',
'class_name' => '\Tainacan\Importer\Term_Importer',
'manual_collection' => false,
'manual_mapping' => false,
]);
do_action('tainacan_register_importers');
add_action( 'tainacan-enqueue-admin-scripts', array($this, 'enqueue_scripts') );
}
function enqueue_scripts() {
global $TAINACAN_BASE_URL;
wp_enqueue_script('import_term_csv_script', $TAINACAN_BASE_URL . '/importer/term-importer/js/term.js', false, false, true);
}
function add_to_queue(\Tainacan\Importer\Importer $importer_object) {

View File

@ -356,6 +356,33 @@ class Old_Tainacan extends Importer{
if( in_array($metadatum->type,['text', 'textarea', 'numeric', 'date']) ){
if($metadatum->type === 'date'){
if(is_array($value)){
$values = [];
foreach( $value as $day){
$v = explode('/',$day);
$v[1]= ( $v[1] < 10 ) ? '0'.$v[1] : $v[1];
$v[0]= ( $v[0] < 10 ) ? '0'.$v[0] : $v[0];
$values[] = $v[2] . '-' . $v[1] . '-' . $v[0];
}
} else {
$v = explode('/',$value);
$v[1]= ( $v[1] < 10 ) ? '0'. $v[1] : $v[1];
$v[0]= ( $v[0] < 10 ) ? '0'. $v[0] : $v[0];
$values = $v[2] . '-' . $v[1] . '-' . $v[0];
}
$value = $values;
}
$item_metadata->set_value($value);
} else if( $metadatum->type === 'item' ){ // RELATIONSHIPS
@ -371,7 +398,7 @@ class Old_Tainacan extends Importer{
if( is_array($value) ) {
$values = [];
foreach( is_array($value) as $cat){
foreach( $value as $cat){
$id = $this->get_transient('term_' . $cat . '_id');
if( $id )
@ -392,9 +419,9 @@ class Old_Tainacan extends Importer{
$inserted = $this->item_metadata_repo->insert( $item_metadata );
$this->add_log('Item Metadata inserted for item ' .$item->get_title() . ' and metadata ' . $newMetadatum->get_name() );
} else {
$this->add_error_log( 'Error inserting metadatum' );
$this->add_error_log( $item_metadata->get_errors() );
return false;
$this->add_log( 'Error inserting metadatum' . $newMetadatum->get_name() );
$this->add_log( 'Values' . $value );
$this->add_log( $item_metadata->get_errors() );
}
}
@ -737,7 +764,7 @@ class Old_Tainacan extends Importer{
if(!empty($meta->metadata->cardinality)){
if($meta->metadata->cardinality > 1){
if($meta->metadata->cardinality === 'n'){
$newMetadatum->set_multiple('yes');
}
@ -860,7 +887,7 @@ class Old_Tainacan extends Importer{
$item->set_document_type( 'attachment' );
$this->add_log('Document imported from ' . $node_old->content_tainacan->guid);
}
} else if(filter_var($node_old->content_tainacan, FILTER_VALIDATE_URL)){
} else if( isset($node_old->type_tainacan) && in_array( $node_old->type_tainacan, ['audio','video','image']) ){
$item->set_document( $node_old->content_tainacan );
$item->set_document_type( 'url' );
$this->add_log('URL imported from ' . $node_old->content_tainacan);

View File

@ -0,0 +1,209 @@
<?php
/**
* @author: MediaLab-UFG(Vinicius Nunes).
* Term Importer
*
* Class to import files CSV with terms
*
*/
namespace Tainacan\Importer;
use \Tainacan\Entities;
class Term_Importer extends Importer {
protected $steps = [
[
'name' => 'Create Taxonomy',
'progress_label' => 'Creating taxonomy',
'callback' => 'create_taxonomy'
],
[
'name' => 'Import Terms',
'progress_label' => 'Creating terms',
'callback' => 'create_terms'
]
];
public function __construct($attributes = array()) {
parent::__construct($attributes);
$this->add_import_method('file');
$this->remove_import_method('url');
$this->set_default_options([
'delimiter' => ',',
'new_taxonomy' => ''
]);
}
public function options_form() {
ob_start();
?>
<div class="field">
<label class="label"><?php _e('CSV Delimiter', 'tainacan'); ?></label>
<span class="help-wrapper">
<a class="help-button has-text-secondary">
<span class="icon is-small">
<i class="mdi mdi-help-circle-outline" ></i>
</span>
</a>
<div class="help-tooltip">
<div class="help-tooltip-header">
<h5><?php _e('CSV Delimiter', 'tainacan'); ?></h5>
</div>
<div class="help-tooltip-body">
<p><?php _e('The character used to separate each column in your CSV (e.g. , or ;)', 'tainacan'); ?></p>
</div>
</div>
</span>
<div class="control is-clearfix">
<input class="input" type="text" name="delimiter" value="<?php echo $this->get_option('delimiter'); ?>">
</div>
</div>
<div class="field import_term_csv_taxonomies">
<label class="label"><?php _e('Target taxonomy:', 'tainacan'); ?></label>
<span class="help-wrapper">
<a class="help-button has-text-secondary">
<span class="icon is-small">
<i class="mdi mdi-help-circle-outline" ></i>
</span>
</a>
<div class="help-tooltip">
<div class="help-tooltip-header">
<h5><?php _e('Existing Taxonomy', 'tainacan'); ?></h5>
</div>
<div class="help-tooltip-body">
<p><?php _e('Inform the taxonomy you want to import the terms to.', 'tainacan'); ?></p>
<p><?php _e('Select an existing taxonomy or create a new one on the fly.', 'tainacan'); ?></p>
</div>
</div>
</span>
<div class="control is-clearfix">
<div class="select">
<select name="select_taxonomy" class="select_taxonomy">
<option value="" selected><?php _e('Create a new taxonomy', 'tainacan'); ?></option>
<?php
$Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance();
$taxonomies = $Tainacan_Taxonomies->fetch( ['nopaging' => true], 'OBJECT' );
foreach( $taxonomies as $taxonomie) {
?>
<option value="<?php echo $taxonomie->get_db_identifier();?>"><?php echo $taxonomie->get_name() ?> </option>
<?php
}
?>
</select>
</div>
<input class="input new_taxonomy" type="text" name="new_taxonomy" value="<?php echo $this->get_option('new_taxonomy'); ?>" placeholder="<?php _e('New taxonomy name', 'tainacan'); ?>" >
</div>
</div>
<?php
return ob_get_clean();
}
public function process_item($index, $collection_definition) {
return true;
}
public function create_terms( ) {
if (($handle = fopen($this->tmp_file, "r")) !== false) {
$file = $handle;
$this->set_current_step_total( filesize($this->tmp_file) );
} else {
$this->add_error_log(' Error reading the file ');
return false;
}
$parent = $this->get_transient('parent');
if ($parent == null) $parent = array();
$position = $this->get_transient('position') == null ? 0: $this->get_transient('position');
$last_term = $this->get_transient('last_term') == null ? 0: $this->get_transient('last_term');
$id_taxonomy= $this->get_transient('new_taxonomy');
$position_file = $this->get_in_step_count();
fseek($file, $position_file);
if (($values = fgetcsv($file, 0, $this->get_option('delimiter'), '"')) !== FALSE) {
$position_file = ftell($file);
if ($values[$position] == '') { // next degree
$position++;
array_push($parent, $last_term);
}
while( $position > 0 && !($values[$position] != '' && $values[$position-1] == '' )) { // back degree
$position--;
array_pop($parent);
}
if ($position == 0 && $values[$position] == '') {
$this->add_error_log("incorrect formatted csv");
$this->abort();
return false;
}
$term = new \Tainacan\Entities\Term();
$term->set_name($values[$position]);
$term->set_description($values[$position+1]);
$term->set_taxonomy($id_taxonomy);
$term_repo = \Tainacan\Repositories\Terms::get_instance();
if(end($parent))
$term->set_parent(end($parent));
if ($term->validate()) {
$term_insert = $term_repo->insert($term);
$last_term = $term_insert->get_id();
$this->add_log('Added term: id=' . $last_term . ' name=' . $term->get_name() . ' id parent=' . $term->get_parent());
} else {
$validationErrors = $term->get_errors();
$err_msg = json_encode($validationErrors);
$this->add_error_log("erro=>$err_msg");
$this->abort();
return false;
}
$this->add_transient('parent', $parent);
$this->add_transient('last_term', $last_term);
$this->add_transient('position', $position);
return $position_file;
} else {
return true;
}
}
public function create_taxonomy() {
if ( $this->get_option('select_taxonomy') != '' ) {
$this->add_transient('new_taxonomy', $this->get_option('select_taxonomy'));
return false;
}
if ( $this->get_option('select_taxonomy') == '' && $this->get_option('new_taxonomy') == '' ) {
$this->abort();
$this->add_error_log('No taxonomy selected');
return false;
}
$tax1 = new Entities\Taxonomy();
$tax1->set_name($this->get_option('new_taxonomy'));
$tax1->set_allow_insert('yes');
$tax1->set_status('publish');
if ($tax1->validate()) {
$tax_repo = \Tainacan\Repositories\Taxonomies::get_instance();
$tax1 = $tax_repo->insert($tax1);
$name = $tax1->get_name();
$this->add_transient('new_taxonomy', $tax1->get_db_identifier());
$this->add_log("taxonomy $name Created.");
return true;
} else {
$this->add_error_log('Error creating taxonomy');
$this->add_error_log($tax1->get_errors());
$this->abort();
}
return false;
}
}

View File

@ -0,0 +1,10 @@
jQuery(document).ready(function() {
jQuery('body').on('change', '.import_term_csv_taxonomies select.select_taxonomy', function(e) {
var new_name = jQuery('.import_term_csv_taxonomies input.new_taxonomy');
if ( jQuery(this).val() == '' ) {
new_name.show();
} else {
new_name.hide();
}
});
});