Merge branch 'develop' into exposers
This commit is contained in:
commit
0d2a01b80c
|
@ -21,4 +21,5 @@ src/assets/css/tainacan-admin.css
|
|||
src/assets/css/tainacan-admin.css.map
|
||||
cypress/videos
|
||||
cypress/screenshots
|
||||
.vscode
|
||||
.vscode
|
||||
src/pdf-viewer/pdfjs-dist
|
9
build.sh
9
build.sh
|
@ -51,6 +51,15 @@ then
|
|||
fi
|
||||
### END npm build ###
|
||||
|
||||
## Fetch PDF.js
|
||||
if [ ! -d "src/pdf-viewer/pdfjs-dist" ]; then
|
||||
echo "Fething PDF.js"
|
||||
mkdir -p src/pdf-viewer/pdfjs-dist
|
||||
wget https://github.com/mozilla/pdf.js/releases/download/v1.9.426/pdfjs-1.9.426-dist.zip
|
||||
unzip pdfjs-1.9.426-dist.zip -d src/pdf-viewer/pdfjs-dist/
|
||||
rm pdfjs-1.9.426-dist.zip
|
||||
fi
|
||||
|
||||
|
||||
echo "Updating files in $wp_plugin_dir"
|
||||
rm -rf $wp_plugin_dir
|
||||
|
|
|
@ -27,7 +27,7 @@ Logs are stored as posts. Check WP_Query docs to learn all args accepted in the
|
|||
|
||||
**Returns:** `\WP_Query|Array` — an instance of wp query OR array of entities;
|
||||
|
||||
### `public function log_inserts($new_value, $value = null)`
|
||||
### `public function insert_log($new_value, $value = null)`
|
||||
|
||||
Insert a log when a new entity is inserted
|
||||
**Parameters:**
|
||||
|
|
|
@ -57,46 +57,51 @@ class Admin {
|
|||
wp_enqueue_style( 'tainacan-admin-page', $TAINACAN_BASE_URL . '/assets/css/tainacan-admin.css' );
|
||||
|
||||
$undesired_wp_styles = [
|
||||
'admin-menu',
|
||||
'admin-bar',
|
||||
'code-editor',
|
||||
'color-picker',
|
||||
'customize-controls',
|
||||
'customize-nav-menus',
|
||||
'customize-widgets',
|
||||
'dashboard',
|
||||
'dashicons',
|
||||
'deprecated-media',
|
||||
'edit',
|
||||
'wp-pointer',
|
||||
'farbtastic',
|
||||
'forms',
|
||||
'common',
|
||||
'install',
|
||||
'wp-auth-check',
|
||||
'site-icon',
|
||||
'buttons',
|
||||
'l10n',
|
||||
'list-tables',
|
||||
'login',
|
||||
'media',
|
||||
'nav-menus',
|
||||
'revisions',
|
||||
'themes',
|
||||
'widgets',
|
||||
'wp-admin'
|
||||
//'admin-menu',
|
||||
//'admin-bar',
|
||||
//'code-editor',
|
||||
//'color-picker',
|
||||
//'customize-controls',
|
||||
//'customize-nav-menus',
|
||||
//'customize-widgets',
|
||||
//'dashboard',
|
||||
//'dashicons',
|
||||
//'deprecated-media',
|
||||
//'edit',
|
||||
//'wp-pointer',
|
||||
//'farbtastic',
|
||||
//'forms',
|
||||
//'common',
|
||||
//'install',
|
||||
//'wp-auth-check',
|
||||
//'site-icon',
|
||||
//'buttons',
|
||||
//'l10n',
|
||||
//'list-tables',
|
||||
//'login',
|
||||
//'media',
|
||||
//'nav-menus',
|
||||
//'revisions',
|
||||
//'themes',
|
||||
//'widgets',
|
||||
//'wp-admin'
|
||||
];
|
||||
|
||||
wp_dequeue_style( $undesired_wp_styles );
|
||||
wp_deregister_style( $undesired_wp_styles );
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
function add_admin_js() {
|
||||
global $TAINACAN_BASE_URL;
|
||||
|
||||
wp_enqueue_script( 'tainacan-user-admin', $TAINACAN_BASE_URL . '/assets/user_admin-components.js', [], null, true );
|
||||
|
||||
wp_enqueue_media();
|
||||
wp_enqueue_script('jcrop');
|
||||
|
||||
wp_enqueue_script( 'tainacan-user-admin', $TAINACAN_BASE_URL . '/assets/user_admin-components.js', [], null, true );
|
||||
|
||||
$settings = $this->get_admin_js_localization_params();
|
||||
|
||||
wp_localize_script( 'tainacan-user-admin', 'tainacan_plugin', $settings );
|
||||
|
@ -154,7 +159,8 @@ class Admin {
|
|||
'i18n' => $tainacan_admin_i18n,
|
||||
'user_caps' => $user_caps,
|
||||
'user_prefs' => $prefs,
|
||||
'base_url' => $TAINACAN_BASE_URL
|
||||
'base_url' => $TAINACAN_BASE_URL,
|
||||
'admin_url' => admin_url()
|
||||
];
|
||||
|
||||
$maps = [
|
||||
|
|
|
@ -52,7 +52,7 @@
|
|||
</figure>
|
||||
<div class="thumbnail-buttons-row">
|
||||
<b-upload
|
||||
model="thumbnail"
|
||||
v-model="thumbnail"
|
||||
@input="uploadThumbnail($event)">
|
||||
<a
|
||||
id="button-edit"
|
||||
|
@ -65,7 +65,87 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</b-field>
|
||||
</b-field>
|
||||
|
||||
<button
|
||||
id="frame-uploader"
|
||||
class="buttton"
|
||||
@click="openFrameUploader($event)">Enviar</button>
|
||||
|
||||
|
||||
<!-- Your image container, which can be manipulated with js -->
|
||||
<div class="custom-img-container">
|
||||
<img
|
||||
v-if="you_have_img"
|
||||
:src="your_img_src"
|
||||
alt=""
|
||||
style="max-width:100%;">
|
||||
</div>
|
||||
|
||||
<!-- Your add & remove image links -->
|
||||
<p class="hide-if-no-js">
|
||||
<a
|
||||
class="upload-custom-img"
|
||||
:class="{ 'hidden': you_have_img, 'hidden' : !you_have_img}"
|
||||
:href="upload_link">
|
||||
Set custom image
|
||||
</a>
|
||||
<a
|
||||
class="delete-custom-img"
|
||||
:class="{'hidden' : !you_have_img, 'visible' : you_have_img }"
|
||||
href="#">
|
||||
Remove this image
|
||||
</a>
|
||||
</p>
|
||||
|
||||
<!-- A hidden input to set and post the chosen image id -->
|
||||
<input
|
||||
class="custom-img-id"
|
||||
name="custom-img-id"
|
||||
type="hidden"
|
||||
:value="your_img_id">
|
||||
|
||||
<!-- Cover Image-------------------------------- -->
|
||||
<b-field
|
||||
:addons="false"
|
||||
:label="$i18n.get('label_cover_image')">
|
||||
|
||||
<div class="thumbnail-field">
|
||||
<b-upload
|
||||
v-if="collection.cover_image == undefined || collection.cover_image == false"
|
||||
v-model="cover"
|
||||
drag-drop
|
||||
@input="uploadCover($event)">
|
||||
<div class="content has-text-centered">
|
||||
<p>
|
||||
<b-icon
|
||||
icon="upload"/>
|
||||
</p>
|
||||
<p>{{ $i18n.get('instruction_image_upload_box') }}</p>
|
||||
</div>
|
||||
</b-upload>
|
||||
<div v-else>
|
||||
<figure class="image is-128x128">
|
||||
<img
|
||||
:alt="$i18n.get('label_cover_image')"
|
||||
:src="collection.cover_image">
|
||||
</figure>
|
||||
<div class="thumbnail-buttons-row">
|
||||
<b-upload
|
||||
v-model="cover"
|
||||
@input="uploadCover($event)">
|
||||
<a
|
||||
id="button-edit"
|
||||
:aria-label="$i18n.get('label_button_edit_thumb')"><b-icon icon="pencil"/></a>
|
||||
</b-upload>
|
||||
<a
|
||||
id="button-delete"
|
||||
:aria-label="$i18n.get('label_button_delete_thumb')"
|
||||
@click="deleteThumbnail()"><b-icon icon="delete"/></a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</b-field>
|
||||
|
||||
<!-- Description -------------------------------- -->
|
||||
<b-field
|
||||
|
@ -106,6 +186,71 @@
|
|||
</b-select>
|
||||
</b-field>
|
||||
|
||||
<!-- Enable Cover Page -------------------------------- -->
|
||||
<div class="field">
|
||||
<b-checkbox
|
||||
id="tainacan-checkbox-cover-page"
|
||||
size="is-small"
|
||||
true-value="yes"
|
||||
false-value="no"
|
||||
v-model="form.enable_cover_page">
|
||||
{{ $i18n.get('label_enable_cover_page') }}
|
||||
</b-checkbox>
|
||||
<help-button
|
||||
:title="$i18n.getHelperTitle('collections', 'enable_cover_page')"
|
||||
:message="$i18n.getHelperMessage('collections', 'enable_cover_page')"/>
|
||||
</div>
|
||||
|
||||
<!-- Cover Page -------------------------------- -->
|
||||
<b-field
|
||||
v-show="form.enable_cover_page == 'yes'"
|
||||
:addons="false"
|
||||
:label="$i18n.get('label_cover_page')"
|
||||
:type="editFormErrors['cover_page_id'] != undefined ? 'is-danger' : ''"
|
||||
:message="editFormErrors['cover_page_id'] != undefined ? editFormErrors['cover_page_id'] : ''">
|
||||
<help-button
|
||||
:title="$i18n.getHelperTitle('collections', 'cover_page_id')"
|
||||
:message="$i18n.getHelperMessage('collections', 'cover_page_id')"/>
|
||||
<b-autocomplete
|
||||
id="tainacan-text-cover-page"
|
||||
:data="coverPages"
|
||||
v-model="coverPageTitle"
|
||||
@select="onSelectCoverPage($event)"
|
||||
:loading="isFetchingPages"
|
||||
@input="fecthCoverPages()"
|
||||
@focus="clearErrors('cover_page_id')">
|
||||
<template slot-scope="props">
|
||||
{{ props.option.title.rendered }}
|
||||
</template>
|
||||
<template slot="empty">No esults found</template>
|
||||
</b-autocomplete>
|
||||
<br>
|
||||
<b-field
|
||||
id="tainacan-cover-page"
|
||||
v-if="coverPage != undefined && coverPage.title != undefined">
|
||||
<div class="control">
|
||||
<b-taglist attached>
|
||||
<b-tag
|
||||
size="is-medium"
|
||||
type="is-primary"
|
||||
v-html="coverPage.title.rendered" />
|
||||
<b-tag
|
||||
size="is-medium"
|
||||
type="is-tertiary"
|
||||
@close="removeCoverPage()"
|
||||
closable>
|
||||
<a
|
||||
target="blank"
|
||||
:href="coverPageEditPath">Edit</a>
|
||||
|
||||
<a
|
||||
target="_blank"
|
||||
:href="coverPage.link">View</a></b-tag>
|
||||
</b-taglist>
|
||||
</div>
|
||||
</b-field>
|
||||
</b-field>
|
||||
|
||||
<!-- Slug -------------------------------- -->
|
||||
<b-field
|
||||
:addons="false"
|
||||
|
@ -120,6 +265,8 @@
|
|||
v-model="form.slug"
|
||||
@focus="clearErrors('slug')"/>
|
||||
</b-field>
|
||||
|
||||
<!-- Form submit -------------------------------- -->
|
||||
<div class="field is-grouped form-submit">
|
||||
<div class="control">
|
||||
<button
|
||||
|
@ -139,13 +286,13 @@
|
|||
</form>
|
||||
|
||||
<b-loading
|
||||
:active.sync="isLoading"
|
||||
:can-cancel="false"/>
|
||||
:active.sync="isLoading"
|
||||
:can-cancel="false"/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { mapActions } from 'vuex'
|
||||
import { mapActions } from 'vuex';
|
||||
|
||||
export default {
|
||||
name: 'CollectionEditionForm',
|
||||
|
@ -159,10 +306,13 @@ export default {
|
|||
status: '',
|
||||
description: '',
|
||||
slug: '',
|
||||
enable_cover_page: '',
|
||||
featured_image: '',
|
||||
cover_image: '',
|
||||
files:[]
|
||||
},
|
||||
thumbnail: {},
|
||||
cover: {},
|
||||
// Can be obtained from api later
|
||||
statusOptions: [{
|
||||
value: 'publish',
|
||||
|
@ -177,9 +327,22 @@ export default {
|
|||
value: 'trash',
|
||||
label: this.$i18n.get('trash')
|
||||
}],
|
||||
isFetchingPages: false,
|
||||
coverPages: [],
|
||||
coverPage: '',
|
||||
coverPageTitle: '',
|
||||
coverPageEditPath: '',
|
||||
editFormErrors: {},
|
||||
formErrorMessage: '',
|
||||
isNewCollection: false
|
||||
isNewCollection: false,
|
||||
// Fream Uploader variables
|
||||
frameUploader: undefined,
|
||||
your_img_src: '',
|
||||
your_img_id: '',
|
||||
you_have_img: false,
|
||||
upload_link: '',
|
||||
custom_img_id: ''
|
||||
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
@ -188,13 +351,24 @@ export default {
|
|||
'updateCollection',
|
||||
'fetchCollection',
|
||||
'sendAttachment',
|
||||
'updateThumbnail'
|
||||
'updateThumbnail',
|
||||
'updateCover',
|
||||
'fetchPages',
|
||||
'fetchPage'
|
||||
]),
|
||||
onSubmit() {
|
||||
// Puts loading on Draft Collection creation
|
||||
this.isLoading = true;
|
||||
|
||||
let data = {collection_id: this.collectionId, name: this.form.name, description: this.form.description, slug: this.form.slug, status: this.form.status};
|
||||
let data = {
|
||||
collection_id: this.collectionId,
|
||||
name: this.form.name,
|
||||
description: this.form.description,
|
||||
enable_cover_page: this.form.enable_cover_page,
|
||||
cover_page_id: this.form.cover_page_id,
|
||||
slug: this.form.slug,
|
||||
status: this.form.status
|
||||
};
|
||||
this.updateCollection(data).then(updatedCollection => {
|
||||
|
||||
this.collection = updatedCollection;
|
||||
|
@ -204,6 +378,8 @@ export default {
|
|||
this.form.slug = this.collection.slug;
|
||||
this.form.description = this.collection.description;
|
||||
this.form.status = this.collection.status;
|
||||
this.form.cover_page_id = this.collection.cover_page_id;
|
||||
this.form.enable_cover_page = this.collection.enable_cover_page;
|
||||
|
||||
this.isLoading = false;
|
||||
this.formErrorMessage = '';
|
||||
|
@ -249,6 +425,9 @@ export default {
|
|||
// Fill this.form data with current data.
|
||||
this.form.name = this.collection.name;
|
||||
this.form.description = this.collection.description;
|
||||
this.form.enable_cover_page = this.collection.enable_cover_page;
|
||||
this.form.cover_page_id = this.collection.cover_page_id;
|
||||
this.form.cover_page_id = this.collection.cover_page_id;
|
||||
this.form.slug = this.collection.slug;
|
||||
|
||||
// Pre-fill status with publish to incentivate it
|
||||
|
@ -292,7 +471,95 @@ export default {
|
|||
.catch((error) => {
|
||||
this.$console.error(error);
|
||||
});
|
||||
},
|
||||
uploadCover($event) {
|
||||
|
||||
this.sendAttachment({ collection_id: this.collectionId, file: $event[0] })
|
||||
.then((res) => {
|
||||
|
||||
this.updateCover({collectionId: this.collectionId, coverId: res.id})
|
||||
.then((res) => {
|
||||
this.collection.cover_image = res.cover_image;
|
||||
})
|
||||
.catch((error) => {
|
||||
this.$console.error(error);
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
this.$console.error(error);
|
||||
});
|
||||
|
||||
},
|
||||
deleteCover() {
|
||||
|
||||
this.updateCover({collectionId: this.collectionId, coverId: 0})
|
||||
.then(() => {
|
||||
this.collection.cover_image = false;
|
||||
})
|
||||
.catch((error) => {
|
||||
this.$console.error(error);
|
||||
});
|
||||
},
|
||||
fecthCoverPages() {
|
||||
this.isFetchingPages = true;
|
||||
this.fetchPages()
|
||||
.then((pages) => {
|
||||
this.coverPages = pages;
|
||||
this.isFetchingPages = false;
|
||||
})
|
||||
.catch((error) => {
|
||||
this.$console.error(error);
|
||||
this.isFetchingPages = false;
|
||||
});
|
||||
},
|
||||
onSelectCoverPage(selectedPage) {
|
||||
this.form.cover_page_id = selectedPage.id;
|
||||
this.coverPage = selectedPage;
|
||||
this.coverPageTitle = this.coverPage.title.rendered;
|
||||
this.coverPageEditPath = tainacan_plugin.admin_url + '/post.php?post=' + selectedPage.id + '&action=edit';
|
||||
},
|
||||
removeCoverPage() {
|
||||
this.coverPage = {};
|
||||
this.coverPageTitle = '';
|
||||
this.form.cover_page_id = '';
|
||||
},
|
||||
openFrameUploader(event) {
|
||||
event.preventDefault();
|
||||
|
||||
// If the media frame already exists, reopen it.
|
||||
if ( this.frameUploader ) {
|
||||
this.frameUploader.open();
|
||||
return;
|
||||
}
|
||||
|
||||
// Create a new media frame
|
||||
this.frameUploader = wp.media.frames.frame_uploader = wp.media({
|
||||
title: 'Select or Upload Media Of Your Chosen Persuasion',
|
||||
button: {
|
||||
text: 'Use this media'
|
||||
},
|
||||
multiple: false,
|
||||
|
||||
});
|
||||
|
||||
wp.media.view.settings.post = {
|
||||
id: this.collectionId,
|
||||
featuredImageId: this.collection.featured_img_id
|
||||
}
|
||||
|
||||
//console.log(wp.wp_get_image_editor())
|
||||
|
||||
this.frameUploader.on('select', () => {
|
||||
|
||||
let media = this.frameUploader.state().get( 'selection' ).first().toJSON();
|
||||
|
||||
console.log(media);
|
||||
|
||||
});
|
||||
|
||||
this.frameUploader.open();
|
||||
}
|
||||
|
||||
},
|
||||
created(){
|
||||
|
||||
|
@ -315,6 +582,25 @@ export default {
|
|||
this.form.description = this.collection.description;
|
||||
this.form.slug = this.collection.slug;
|
||||
this.form.status = this.collection.status;
|
||||
this.form.enable_cover_page = this.collection.enable_cover_page;
|
||||
this.form.cover_page_id = this.collection.cover_page_id;
|
||||
|
||||
if (this.form.cover_page_id != undefined && this.form.cover_page_id != '') {
|
||||
|
||||
this.isFetchingPages = true;
|
||||
|
||||
this.fetchPage(this.form.cover_page_id)
|
||||
.then((page) => {
|
||||
this.coverPage = page;
|
||||
this.coverPageTitle = this.coverPage.title.rendered;
|
||||
this.coverPageEditPath = tainacan_plugin.admin_url + '/post.php?post=' + page.id + '&action=edit';
|
||||
this.isFetchingPages = false;
|
||||
})
|
||||
.catch((error) => {
|
||||
this.$console.error(error);
|
||||
this.isFetchingPages = false;
|
||||
});
|
||||
}
|
||||
|
||||
this.isLoading = false;
|
||||
});
|
||||
|
|
|
@ -51,9 +51,9 @@
|
|||
</b-field>
|
||||
|
||||
<!-- Attachments ------------------------------------------ -->
|
||||
<div class="columns is-multiline">
|
||||
<div class="column is-4">
|
||||
<b-field :label="$i18n.get('label_image')">
|
||||
<b-field :label="$i18n.get('label_attachments')">
|
||||
<div class="columns is-multiline">
|
||||
<div class="column is-8">
|
||||
<b-upload
|
||||
v-model="form.files"
|
||||
multiple
|
||||
|
@ -70,33 +70,34 @@
|
|||
</div>
|
||||
</section>
|
||||
</b-upload>
|
||||
</b-field>
|
||||
<div class="uploaded-files">
|
||||
<div
|
||||
v-for="(file, index) in form.files"
|
||||
:key="index">
|
||||
<span class="tag is-primary">
|
||||
{{ file.name }}
|
||||
<button
|
||||
class="delete is-small"
|
||||
type="button"
|
||||
@click="deleteFile(index)"/>
|
||||
</span>
|
||||
<!-- <progress class="progress is-secondary" value="15" max="100">30%</progress> -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="column is-narrow"
|
||||
v-for="(attachment, index) of item.attachments"
|
||||
:key="index">
|
||||
<figure class="image is-128x128">
|
||||
<img
|
||||
:alt="attachment.title"
|
||||
:src="attachment.url">
|
||||
</figure>
|
||||
</div>
|
||||
<div class="uploaded-files">
|
||||
<div
|
||||
v-for="(file, index) in form.files"
|
||||
:key="index">
|
||||
<span class="tag is-primary">
|
||||
{{ file.name }}
|
||||
<button
|
||||
class="delete is-small"
|
||||
type="button"
|
||||
@click="deleteFile(index)"/>
|
||||
</span>
|
||||
<!-- <progress class="progress is-secondary" value="15" max="100">30%</progress> -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="column is-narrow"
|
||||
v-for="(attachment, index) of item.attachments"
|
||||
:key="index">
|
||||
<figure class="image is-128x128">
|
||||
<img
|
||||
:alt="attachment.title"
|
||||
:src="attachment.url">
|
||||
</figure>
|
||||
</div>
|
||||
</div>
|
||||
</b-field>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="column">
|
||||
|
@ -272,8 +273,7 @@ export default {
|
|||
});
|
||||
},
|
||||
cancelBack(){
|
||||
this.$console.log(this.fieldList);
|
||||
//this.$router.push(this.$routerHelper.getCollectionPath(this.collectionId));
|
||||
this.$router.push(this.$routerHelper.getCollectionPath(this.collectionId));
|
||||
},
|
||||
uploadAttachment($event) {
|
||||
|
||||
|
|
|
@ -178,7 +178,7 @@ export default {
|
|||
},
|
||||
deleteSelectedCollections() {
|
||||
this.$dialog.confirm({
|
||||
message: this.$i18n.get('info_selected_collections_delete'),
|
||||
message: this.$i18n.get('info_warning_selected_collections_delete'),
|
||||
onConfirm: () => {
|
||||
|
||||
for (let collection of this.selectedCollections) {
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
class="clickable-row"
|
||||
tag="span"
|
||||
router-link-active
|
||||
:active="props.row.log_diff.length > 0"
|
||||
:active="props.row.log_diffs.length > 0"
|
||||
:to="{path: $routerHelper.getEventPath(props.row.id)}">
|
||||
{{ props.row.title }}
|
||||
</router-link>
|
||||
|
@ -47,7 +47,7 @@
|
|||
class="clickable-row"
|
||||
v-html="props.row.by"
|
||||
tag="span"
|
||||
:active="props.row.log_diff.length > 0"
|
||||
:active="props.row.log_diffs.length > 0"
|
||||
:to="{path: $routerHelper.getEventPath(props.row.id)}"/>
|
||||
</b-table-column>
|
||||
|
||||
|
@ -58,18 +58,22 @@
|
|||
:aria-label="$i18n.get('label_actions')">
|
||||
|
||||
<a
|
||||
v-if="props.row.status === 'pending'"
|
||||
id="button-approve"
|
||||
:aria-label="$i18n.get('approve_item')"
|
||||
@click.prevent.stop="approve(props.row.id)">
|
||||
@click.prevent.stop="approveEvent(props.row.id)">
|
||||
<b-icon
|
||||
icon="check" />
|
||||
</a>
|
||||
|
||||
<a
|
||||
v-if="props.row.status === 'pending'"
|
||||
id="button-not-approve"
|
||||
class="delete"
|
||||
:aria-label="$i18n.get('not_approve_item')"
|
||||
@click.prevent.stop="notApprove(props.row.id)" />
|
||||
@click.prevent.stop="notApproveEvent(props.row.id)" />
|
||||
|
||||
<small v-if="props.row.status !== 'pending'"> Approved </small>
|
||||
|
||||
</b-table-column>
|
||||
</template>
|
||||
|
@ -113,7 +117,13 @@
|
|||
...mapActions('event', [
|
||||
'approve',
|
||||
'notApprove'
|
||||
])
|
||||
]),
|
||||
approveEvent(eventId){
|
||||
this.approve(eventId);
|
||||
},
|
||||
notApproveEvent(eventId){
|
||||
this.notApprove(eventId);
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -154,7 +154,6 @@ export default {
|
|||
return this.getFieldTypes();
|
||||
},
|
||||
set(value) {
|
||||
console.log("OIEEE")
|
||||
return this.updateFieldTypes(value);
|
||||
}
|
||||
},
|
||||
|
|
|
@ -106,7 +106,6 @@ export default {
|
|||
message: this.$i18n.get('info_warning_item_delete'),
|
||||
onConfirm: () => {
|
||||
this.deleteItem(itemId).then(() => {
|
||||
this.loadItems();
|
||||
this.$toast.open({
|
||||
duration: 3000,
|
||||
message: this.$i18n.get('info_item_deleted'),
|
||||
|
@ -139,7 +138,6 @@ export default {
|
|||
for (let item of this.selectedItems) {
|
||||
this.deleteItem(item.id)
|
||||
.then(() => {
|
||||
this.loadItems();
|
||||
this.$toast.open({
|
||||
duration: 3000,
|
||||
message: this.$i18n.get('info_item_deleted'),
|
||||
|
|
|
@ -111,7 +111,7 @@ export default {
|
|||
transition: max-width 0.2s linear;
|
||||
max-width: $side-menu-width;
|
||||
z-index: 99;
|
||||
|
||||
.menu { padding-top: 0px; }
|
||||
.menu-header {
|
||||
background-color: rgba(0,0,0,0.1);
|
||||
height: $header-height;
|
||||
|
|
|
@ -3,11 +3,11 @@
|
|||
<div class="tile is-ancestor">
|
||||
|
||||
<div class="tile is-parent">
|
||||
<article class="tile notification is-child is-light">
|
||||
<article class="tile box is-child">
|
||||
<div class="content">
|
||||
<div class="title">{{ this.$i18n.get('info_logs_before') }}</div>
|
||||
<div
|
||||
v-for="(diff, key) in event.log_diff"
|
||||
v-for="(diff, key) in event.log_diffs"
|
||||
v-if="diff.old"
|
||||
:key="key">
|
||||
|
||||
|
@ -22,7 +22,36 @@
|
|||
v-else
|
||||
v-for="(o, ind) in diff.old"
|
||||
:key="ind">
|
||||
|
||||
<div v-if="o.hasOwnProperty('mime_type') && o.mime_type.includes('image') && key === 'attachments'">
|
||||
|
||||
|
||||
<article class="media">
|
||||
<div class="media-left bottom-space-tainacan">
|
||||
<p class="image is-64x64"><img :src="o.url"></p>
|
||||
</div>
|
||||
<div class="media-content">
|
||||
<div class="content">
|
||||
<p>
|
||||
<strong class="is-capitalized">{{ o.title }}</strong> <small>{{ o.mime_type }}</small>
|
||||
<br>
|
||||
{{ o.description }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-else-if="key === 'fields_order' || key === 'filters_order'"
|
||||
class="is-capitalized"
|
||||
:class="{ 'back-hlight': diff.diff_with_index.hasOwnProperty(i) }">
|
||||
{{ `ID: ${d.id} Enabled: ${d.enabled}` }}
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-else
|
||||
class="content is-inline is-capitalized"
|
||||
v-for="(o2, ind2) in o"
|
||||
:key="ind2">
|
||||
|
@ -35,11 +64,11 @@
|
|||
</div>
|
||||
|
||||
<div class="tile is-parent">
|
||||
<article class="tile notification is-child is-light">
|
||||
<article class="tile box is-child">
|
||||
<div class="content">
|
||||
<div class="title">{{ this.$i18n.get('info_logs_after') }}</div>
|
||||
<div
|
||||
v-for="(diff, key) in event.log_diff"
|
||||
v-for="(diff, key) in event.log_diffs"
|
||||
:key="key">
|
||||
|
||||
<p/>
|
||||
|
@ -48,16 +77,49 @@
|
|||
:class="{ 'has-text-success': !diff.old, 'back-hlight': !diff.old }">
|
||||
{{ `${key.replace('_', ' ')}:` }}
|
||||
</div>
|
||||
<div v-if="key === 'featured_image'">
|
||||
<div class="image is-128x128">
|
||||
<img :src="diff.new">
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
v-else
|
||||
v-for="(d, i) in diff.new"
|
||||
:key="i"
|
||||
:class="{ 'back-hlight': diff.diff_with_index.hasOwnProperty(i) }"
|
||||
class="content is-inline" >
|
||||
|
||||
<div v-if="d.hasOwnProperty('mime_type') && d.mime_type.includes('image') && key === 'attachments'">
|
||||
|
||||
|
||||
<article class="media">
|
||||
<div class="media-left">
|
||||
<p class="image is-64x64"><img :src="d.url"></p>
|
||||
</div>
|
||||
<div class="media-content">
|
||||
<div class="content">
|
||||
<p>
|
||||
<strong class="is-capitalized">{{ d.title }}</strong> <small>{{ d.mime_type }}</small>
|
||||
<br>
|
||||
{{ d.description }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
|
||||
</div>
|
||||
|
||||
<div
|
||||
class="is-inline has-text-success"
|
||||
v-else-if="key === 'fields_order' || key === 'filters_order'"
|
||||
class="is-capitalized"
|
||||
:class="{ 'back-hlight': diff.diff_with_index.hasOwnProperty(i) }">
|
||||
{{ `ID: ${d.id} Enabled: ${d.enabled}` }}
|
||||
</div>
|
||||
|
||||
<div
|
||||
class="is-inline"
|
||||
:class="{ 'back-hlight': diff.diff_with_index.hasOwnProperty(i) }"
|
||||
v-if="!Array.isArray(d) && d.constructor.name !== 'Object' ">{{ d }}
|
||||
v-else-if="!Array.isArray(d) && d.constructor.name !== 'Object' ">{{ d }}
|
||||
</div>
|
||||
|
||||
<div
|
||||
|
@ -67,11 +129,10 @@
|
|||
class="is-inline">
|
||||
|
||||
<div
|
||||
class="is-capitalized is-inline has-text-success"
|
||||
:class="{ 'back-hlight': diff.diff_with_index.hasOwnProperty(i) }">
|
||||
{{ `${i2.replace('_', ' ')}: ${e} ` }}
|
||||
class="is-capitalized"
|
||||
:class="{ 'back-hlight': diff.diff_with_index.hasOwnProperty(i) }">
|
||||
{{ `${i2.replace('_', ' ')}: ${e} ` }}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
|
|
@ -3,12 +3,12 @@
|
|||
<div class="tile is-ancestor">
|
||||
|
||||
<div class="tile is-parent">
|
||||
<article class="tile notification is-child is-light">
|
||||
<article class="tile box is-child">
|
||||
|
||||
<div class="content">
|
||||
<div class="title">Changes</div>
|
||||
<div class="title">{{ this.$i18n.get('info_changes') }}</div>
|
||||
<div
|
||||
v-for="(diff, key) in event.log_diff"
|
||||
v-for="(diff, key) in event.log_diffs"
|
||||
v-if="diff.old"
|
||||
:key="key">
|
||||
|
||||
|
@ -19,11 +19,41 @@
|
|||
class="content is-inline">
|
||||
{{ diff.old }}
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-else
|
||||
v-for="(o, ind) in diff.old"
|
||||
:key="ind">
|
||||
|
||||
<div v-if="o.hasOwnProperty('mime_type') && o.mime_type.includes('image') && key === 'attachments'">
|
||||
|
||||
|
||||
<article class="media">
|
||||
<div class="media-left bottom-space-tainacan">
|
||||
<p class="image is-64x64"><img :src="o.url"></p>
|
||||
</div>
|
||||
<div class="media-content">
|
||||
<div class="content">
|
||||
<p>
|
||||
<strong class="is-capitalized">{{ o.title }}</strong> <small>{{ o.mime_type }}</small>
|
||||
<br>
|
||||
{{ o.description }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-else-if="key === 'fields_order' || key === 'filters_order'"
|
||||
class="is-capitalized"
|
||||
:class="{ 'back-hlight': diff.diff_with_index.hasOwnProperty(i) }">
|
||||
{{ `ID: ${d.id} Enabled: ${d.enabled}` }}
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-else
|
||||
class="content is-inline is-capitalized"
|
||||
v-for="(o2, ind2) in o"
|
||||
:key="ind2">
|
||||
|
@ -32,8 +62,10 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<hr class="divider">
|
||||
|
||||
<div
|
||||
v-for="(diff, key) in event.log_diff"
|
||||
v-for="(diff, key) in event.log_diffs"
|
||||
:key="key">
|
||||
|
||||
<p/>
|
||||
|
@ -42,25 +74,64 @@
|
|||
:class="{ 'has-text-success': !diff.old, 'back-hlight': !diff.old }">
|
||||
{{ `${key.replace('_', ' ')}:` }}
|
||||
</div>
|
||||
<div v-if="key === 'featured_image'">
|
||||
<div class="image is-128x128">
|
||||
<img :src="diff.new">
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
v-else
|
||||
v-for="(d, i) in diff.new"
|
||||
:key="i"
|
||||
:class="{ 'back-hlight': diff.diff_with_index.hasOwnProperty(i) }"
|
||||
class="content is-inline" >
|
||||
|
||||
<div
|
||||
class="is-inline has-text-success"
|
||||
:class="{ 'back-hlight': diff.diff_with_index.hasOwnProperty(i) }"
|
||||
v-if="!Array.isArray(d) && d.constructor.name !== 'Object' ">{{ d }}
|
||||
<div v-if="d.hasOwnProperty('mime_type') && d.mime_type.includes('image') && key === 'attachments'">
|
||||
|
||||
|
||||
<article class="media">
|
||||
<div class="media-left">
|
||||
<p class="image is-64x64"><img :src="d.url"></p>
|
||||
</div>
|
||||
<div class="media-content">
|
||||
<div class="content">
|
||||
<p>
|
||||
<strong class="is-capitalized">{{ d.title }}</strong> <small>{{ d.mime_type }}</small>
|
||||
<br>
|
||||
{{ d.description }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-else-if="key === 'fields_order' || key === 'filters_order'"
|
||||
class="is-capitalized"
|
||||
:class="{ 'back-hlight': diff.diff_with_index.hasOwnProperty(i) }">
|
||||
{{ `ID: ${d.id} Enabled: ${d.enabled}` }}
|
||||
</div>
|
||||
|
||||
<div
|
||||
class="is-inline"
|
||||
:class="{ 'back-hlight': diff.diff_with_index.hasOwnProperty(i) }"
|
||||
v-else-if="!Array.isArray(d) && d.constructor.name !== 'Object' ">{{ d }}
|
||||
</div>
|
||||
|
||||
|
||||
<div
|
||||
v-else
|
||||
v-for="(e, i2) in d"
|
||||
:key="i2"
|
||||
class="is-capitalized has-text-success"
|
||||
:class="{ 'back-hlight': diff.diff_with_index.hasOwnProperty(i) }">
|
||||
{{ `${i2.replace('_', ' ')}: ${e} ` }}
|
||||
class="is-inline">
|
||||
|
||||
<div
|
||||
class="is-capitalized"
|
||||
:class="{ 'back-hlight': diff.diff_with_index.hasOwnProperty(i) }">
|
||||
{{ `${i2.replace('_', ' ')}: ${e} ` }}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<template>
|
||||
<div>
|
||||
<tainacan-filter-item
|
||||
:query="getPostQuery()"
|
||||
:query="getQuery"
|
||||
v-for="(filter, index) in filters"
|
||||
:key="index"
|
||||
:filter="filter"/>
|
||||
|
@ -19,6 +19,11 @@
|
|||
...mapGetters('search',[
|
||||
'getPostQuery'
|
||||
])
|
||||
},
|
||||
computed: {
|
||||
getQuery() {
|
||||
return this.getPostQuery();
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
|
@ -37,7 +37,6 @@
|
|||
|
||||
<script>
|
||||
import { mapGetters } from 'vuex';
|
||||
import { eventBusSearch } from '../../../js/event-bus-search';
|
||||
|
||||
export default {
|
||||
name: 'Pagination',
|
||||
|
@ -59,7 +58,7 @@ export default {
|
|||
watch: {
|
||||
page( value ){
|
||||
if (value < 1)
|
||||
eventBusSearch.setPage(1);
|
||||
this.$eventBusSearch.setPage(1);
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
@ -75,13 +74,13 @@ export default {
|
|||
}
|
||||
|
||||
let prevValue = this.itemsPerPage;
|
||||
eventBusSearch.setItemsPerPage(value);
|
||||
this.$eventBusSearch.setItemsPerPage(value);
|
||||
this.$userPrefs.set('items_per_page', value, prevValue);
|
||||
},
|
||||
onPageChange(page) {
|
||||
if(page == 0)
|
||||
return;
|
||||
eventBusSearch.setPage(page);
|
||||
this.$eventBusSearch.setPage(page);
|
||||
},
|
||||
getLastItemNumber() {
|
||||
let last = (Number(this.itemsPerPage*(this.page - 1)) + Number(this.itemsPerPage));
|
||||
|
|
|
@ -52,7 +52,6 @@
|
|||
|
||||
<script>
|
||||
import { mapGetters } from 'vuex';
|
||||
import { eventBusSearch } from '../../../js/event-bus-search';
|
||||
|
||||
export default {
|
||||
name: 'SearchControl',
|
||||
|
@ -80,10 +79,10 @@ export default {
|
|||
'getOrder'
|
||||
]),
|
||||
onChangeOrderBy(field) {
|
||||
eventBusSearch.setOrderBy(field);
|
||||
this.$eventBusSearch.setOrderBy(field);
|
||||
},
|
||||
onChangeOrder() {
|
||||
this.order == 'DESC' ? eventBusSearch.setOrder('ASC') : eventBusSearch.setOrder('DESC');
|
||||
this.order == 'DESC' ? this.$eventBusSearch.setOrder('ASC') : this.$eventBusSearch.setOrder('DESC');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,22 +27,16 @@ import FilterCategorySelectbox from '../../classes/filter-types/category/Selectb
|
|||
|
||||
import TaincanFormItem from '../../classes/field-types/tainacan-form-item.vue';
|
||||
import TaincanFiltersList from '../../classes/filter-types/tainacan-filter-item.vue';
|
||||
import ItemsPage from '../pages/lists/items-page.vue';
|
||||
|
||||
// Remaining imports
|
||||
import AdminPage from '../admin.vue'
|
||||
import HelpButton from '../components/other/help-button.vue';
|
||||
import draggable from 'vuedraggable'
|
||||
import store from '../../js/store/store'
|
||||
import router from './router'
|
||||
import { router} from './router'
|
||||
import eventBusSearch from '../../js/event-bus-search';
|
||||
import { I18NPlugin, UserPrefsPlugin, RouterHelperPlugin, ConsolePlugin } from './utilities';
|
||||
|
||||
// Changing title of pages
|
||||
router.beforeEach((to, from, next) => {
|
||||
document.title = to.meta.title;
|
||||
next();
|
||||
});
|
||||
|
||||
// Configure and Register Plugins
|
||||
Vue.use(Buefy);
|
||||
Vue.use(I18NPlugin);
|
||||
|
@ -50,8 +44,6 @@ Vue.use(UserPrefsPlugin);
|
|||
Vue.use(RouterHelperPlugin);
|
||||
Vue.use(ConsolePlugin, {visual: false});
|
||||
|
||||
// Register Components
|
||||
Vue.component('items-page',ItemsPage);
|
||||
/* Fields */
|
||||
Vue.component('tainacan-text', Text);
|
||||
Vue.component('tainacan-textarea', Textarea);
|
||||
|
@ -81,9 +73,17 @@ Vue.component('tainacan-filter-category-selectbox', FilterCategorySelectbox);
|
|||
Vue.component('help-button', HelpButton);
|
||||
Vue.component('draggable', draggable);
|
||||
|
||||
Vue.use(eventBusSearch, { store: store, router: router});
|
||||
|
||||
// Changing title of pages
|
||||
router.beforeEach((to, from, next) => {
|
||||
document.title = to.meta.title;
|
||||
next();
|
||||
});
|
||||
|
||||
new Vue({
|
||||
el: '#tainacan-admin-app',
|
||||
store,
|
||||
router,
|
||||
render: h => h(AdminPage)
|
||||
});
|
||||
});
|
||||
|
|
|
@ -67,7 +67,7 @@ const routes = [
|
|||
{ path: '*', redirect: '/'}
|
||||
];
|
||||
|
||||
export default new VueRouter ({
|
||||
export const router = new VueRouter ({
|
||||
routes,
|
||||
// set custom query resolver
|
||||
parseQuery(query) {
|
||||
|
@ -76,6 +76,21 @@ export default new VueRouter ({
|
|||
stringifyQuery(query) {
|
||||
let result = qs.stringify(query);
|
||||
|
||||
return result ? ('?' + result) : '';
|
||||
}
|
||||
});
|
||||
|
||||
const themeRoutes = [];
|
||||
|
||||
export const routerTheme = new VueRouter ({
|
||||
themeRoutes,
|
||||
// set custom query resolver
|
||||
parseQuery(query) {
|
||||
return qs.parse(query);
|
||||
},
|
||||
stringifyQuery(query) {
|
||||
let result = qs.stringify(query);
|
||||
|
||||
return result ? ('?' + result) : '';
|
||||
}
|
||||
});
|
|
@ -0,0 +1,91 @@
|
|||
// Main imports
|
||||
import Vue from 'vue';
|
||||
import Buefy from 'buefy';
|
||||
|
||||
// Custom elements
|
||||
import Text from '../../classes/field-types/text/Text.vue';
|
||||
import Textarea from '../../classes/field-types/textarea/Textarea.vue';
|
||||
import Selectbox from '../../classes/field-types/selectbox/Selectbox.vue';
|
||||
import Numeric from '../../classes/field-types/numeric/Numeric.vue';
|
||||
import Date from '../../classes/field-types/date/Date.vue';
|
||||
import Relationship from '../../classes/field-types/relationship/Relationship.vue';
|
||||
import Category from '../../classes/field-types/category/Category.vue';
|
||||
|
||||
import FormRelationship from '../../classes/field-types/relationship/FormRelationship.vue';
|
||||
import FormCategory from '../../classes/field-types/category/FormCategory.vue';
|
||||
import FormSelectbox from '../../classes/field-types/selectbox/FormSelectbox.vue';
|
||||
|
||||
import FilterCustomInterval from '../../classes/filter-types/custom-interval/CustomInterval.vue';
|
||||
import FilterSelectbox from '../../classes/filter-types/selectbox/Selectbox.vue';
|
||||
import FilterAutocomplete from '../../classes/filter-types/autocomplete/Autocomplete.vue';
|
||||
import FilterCheckbox from '../../classes/filter-types/checkbox/Checkbox.vue';
|
||||
import FilterTaginput from '../../classes/filter-types/taginput/Taginput.vue';
|
||||
|
||||
import FilterCategoryCheckbox from '../../classes/filter-types/category/Checkbox.vue';
|
||||
import FilterCategoryTaginput from '../../classes/filter-types/category/Taginput.vue';
|
||||
import FilterCategorySelectbox from '../../classes/filter-types/category/Selectbox.vue';
|
||||
|
||||
import TaincanFormItem from '../../classes/field-types/tainacan-form-item.vue';
|
||||
import TaincanFiltersList from '../../classes/filter-types/tainacan-filter-item.vue';
|
||||
import ItemsPage from '../pages/lists/items-page.vue';
|
||||
|
||||
// Remaining imports
|
||||
import HelpButton from '../components/other/help-button.vue';
|
||||
import draggable from 'vuedraggable'
|
||||
import store from '../../js/store/store'
|
||||
import { routerTheme } from './router.js'
|
||||
import eventBusSearch from '../../js/event-bus-search';
|
||||
import { I18NPlugin, UserPrefsPlugin, RouterHelperPlugin, ConsolePlugin } from './utilities';
|
||||
|
||||
// Configure and Register Plugins
|
||||
Vue.use(Buefy);
|
||||
Vue.use(I18NPlugin);
|
||||
Vue.use(UserPrefsPlugin);
|
||||
Vue.use(RouterHelperPlugin);
|
||||
Vue.use(ConsolePlugin, {visual: false});
|
||||
|
||||
/* Fields */
|
||||
Vue.component('tainacan-text', Text);
|
||||
Vue.component('tainacan-textarea', Textarea);
|
||||
Vue.component('tainacan-selectbox', Selectbox);
|
||||
Vue.component('tainacan-numeric', Numeric);
|
||||
Vue.component('tainacan-date', Date);
|
||||
Vue.component('tainacan-relationship', Relationship);
|
||||
Vue.component('tainacan-category', Category);
|
||||
|
||||
Vue.component('tainacan-form-relationship', FormRelationship);
|
||||
Vue.component('tainacan-form-category', FormCategory);
|
||||
Vue.component('tainacan-form-selectbox', FormSelectbox);
|
||||
Vue.component('tainacan-form-item', TaincanFormItem);
|
||||
Vue.component('tainacan-filter-item', TaincanFiltersList);
|
||||
|
||||
/* Filters */
|
||||
Vue.component('tainacan-filter-custom-interval', FilterCustomInterval);
|
||||
Vue.component('tainacan-filter-selectbox', FilterSelectbox);
|
||||
Vue.component('tainacan-filter-autocomplete', FilterAutocomplete);
|
||||
Vue.component('tainacan-filter-checkbox', FilterCheckbox);
|
||||
Vue.component('tainacan-filter-taginput', FilterTaginput);
|
||||
Vue.component('tainacan-filter-category-checkbox', FilterCategoryCheckbox);
|
||||
Vue.component('tainacan-filter-category-taginput', FilterCategoryTaginput);
|
||||
Vue.component('tainacan-filter-category-selectbox', FilterCategorySelectbox);
|
||||
|
||||
/* Others */
|
||||
Vue.component('help-button', HelpButton);
|
||||
Vue.component('draggable', draggable);
|
||||
Vue.component('items-page', ItemsPage);
|
||||
|
||||
Vue.use(eventBusSearch, { store: store, router: routerTheme});
|
||||
|
||||
new Vue({
|
||||
el: '#tainacan-items-page',
|
||||
store,
|
||||
router: routerTheme,
|
||||
data: {
|
||||
collectionId: ''
|
||||
},
|
||||
template: '<items-page :collection-id="collectionId"></items-page>',
|
||||
beforeMount () {
|
||||
if (this.$el.attributes['collection-id'] != undefined)
|
||||
this.collectionId = this.$el.attributes['collection-id'].value;
|
||||
}
|
||||
});
|
|
@ -11,14 +11,14 @@
|
|||
id="button-create-item"
|
||||
tag="button"
|
||||
class="button is-secondary"
|
||||
:to="{ path: $routerHelper.getNewItemPath(finalCollectionId) }">
|
||||
:to="{ path: $routerHelper.getNewItemPath(collectionId) }">
|
||||
{{ $i18n.getFrom('items', 'new_item') }}
|
||||
</router-link>
|
||||
</div>
|
||||
<search-control
|
||||
v-if="fields.length > 0 && (items.length != 0 || isLoadingItems)"
|
||||
:is-repository-level="isRepositoryLevel"
|
||||
:collection-id="finalCollectionId"
|
||||
:collection-id="collectionId"
|
||||
:table-fields="tableFields"
|
||||
:pref-table-fields="prefTableFields"/>
|
||||
</div>
|
||||
|
@ -43,7 +43,7 @@
|
|||
<p>{{ $i18n.get('info_there_is_no_filter' ) }}</p>
|
||||
<router-link
|
||||
id="button-create-filter"
|
||||
:to="isRepositoryLevel ? $routerHelper.getNewFilterPath() : $routerHelper.getNewCollectionFilterPath(finalCollectionId)"
|
||||
:to="isRepositoryLevel ? $routerHelper.getNewFilterPath() : $routerHelper.getNewCollectionFilterPath(collectionId)"
|
||||
tag="button"
|
||||
class="button is-secondary is-centered">
|
||||
{{ $i18n.getFrom('filters', 'new_item') }}</router-link>
|
||||
|
@ -57,7 +57,7 @@
|
|||
:active.sync="isLoadingItems"/>
|
||||
<items-list
|
||||
v-if="!isLoadingItems && items.length > 0"
|
||||
:collection-id="finalCollectionId"
|
||||
:collection-id="collectionId"
|
||||
:table-fields="tableFields"
|
||||
:items="items"
|
||||
:is-loading="isLoading"/>
|
||||
|
@ -76,7 +76,7 @@
|
|||
id="button-create-item"
|
||||
tag="button"
|
||||
class="button is-primary"
|
||||
:to="{ path: $routerHelper.getNewItemPath(finalCollectionId) }">
|
||||
:to="{ path: $routerHelper.getNewItemPath(collectionId) }">
|
||||
{{ $i18n.getFrom('items', 'new_item') }}
|
||||
</router-link>
|
||||
</div>
|
||||
|
@ -94,14 +94,12 @@ import SearchControl from '../../components/search/search-control.vue'
|
|||
import ItemsList from '../../components/lists/items-list.vue';
|
||||
import FiltersItemsList from '../../components/search/filters-items-list.vue';
|
||||
import Pagination from '../../components/search/pagination.vue'
|
||||
import { eventBusSearch } from '../../../js/event-bus-search'
|
||||
import { mapActions, mapGetters } from 'vuex';
|
||||
|
||||
export default {
|
||||
name: 'ItemsPage',
|
||||
data(){
|
||||
return {
|
||||
finalCollectionId: Number,
|
||||
isRepositoryLevel: false,
|
||||
tableFields: [],
|
||||
prefTableFields: [],
|
||||
|
@ -149,24 +147,24 @@ export default {
|
|||
}
|
||||
},
|
||||
created() {
|
||||
this.finalCollectionId = (this.collectionId != undefined && this.collectionId != null && this.collectionId != '' ) ? this.collectionId : this.$route.params.collectionId;
|
||||
this.isRepositoryLevel = (this.finalCollectionId == undefined);
|
||||
|
||||
eventBusSearch.$on('isLoadingItems', isLoadingItems => {
|
||||
this.isRepositoryLevel = (this.collectionId == undefined);
|
||||
|
||||
this.$eventBusSearch.$on('isLoadingItems', isLoadingItems => {
|
||||
this.isLoadingItems = isLoadingItems;
|
||||
});
|
||||
|
||||
eventBusSearch.$on('hasFiltered', hasFiltered => {
|
||||
this.$eventBusSearch.$on('hasFiltered', hasFiltered => {
|
||||
this.hasFiltered = hasFiltered;
|
||||
});
|
||||
|
||||
this.isLoadingFilters = true;
|
||||
this.fetchFilters( { collectionId: this.finalCollectionId, isRepositoryLevel: this.isRepositoryLevel, isContextEdit: true })
|
||||
this.fetchFilters( { collectionId: this.collectionId, isRepositoryLevel: this.isRepositoryLevel, isContextEdit: true })
|
||||
.then(() => this.isLoadingFilters = false)
|
||||
.catch(() => this.isLoadingFilters = false);
|
||||
|
||||
this.isLoadingFields = true;
|
||||
this.fetchFields({ collectionId: this.finalCollectionId, isRepositoryLevel: this.isRepositoryLevel, isContextEdit: false }).then(() => {
|
||||
this.fetchFields({ collectionId: this.collectionId, isRepositoryLevel: this.isRepositoryLevel, isContextEdit: false }).then(() => {
|
||||
|
||||
this.tableFields.push({ name: this.$i18n.get('label_thumbnail'), field: 'row_thumbnail', field_type: undefined, slug: 'featured_image', id: undefined, visible: true });
|
||||
for (let field of this.fields) {
|
||||
|
@ -179,12 +177,12 @@ export default {
|
|||
this.tableFields.push({ name: this.$i18n.get('label_actions'), field: 'row_actions', field_type: undefined, slug: 'actions', id: undefined, visible: true });
|
||||
|
||||
//this.prefTableFields = this.tableFields;
|
||||
// this.$userPrefs.get('table_columns_' + this.finalCollectionId)
|
||||
// this.$userPrefs.get('table_columns_' + this.collectionId)
|
||||
// .then((value) => {
|
||||
// this.prefTableFields = value;
|
||||
// })
|
||||
// .catch((error) => {
|
||||
// this.$userPrefs.set('table_columns_' + this.finalCollectionId, this.prefTableFields, null);
|
||||
// this.$userPrefs.set('table_columns_' + this.collectionId, this.prefTableFields, null);
|
||||
// });
|
||||
this.isLoadingFields = false;
|
||||
|
||||
|
@ -193,8 +191,9 @@ export default {
|
|||
});
|
||||
},
|
||||
mounted(){
|
||||
eventBusSearch.updateStoreFromURL();
|
||||
eventBusSearch.loadItems();
|
||||
this.$eventBusSearch.setCollectionId(this.collectionId);
|
||||
this.$eventBusSearch.updateStoreFromURL();
|
||||
this.$eventBusSearch.loadItems();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
<div class="columns is-fullheight">
|
||||
<section class="column is-secondary-content">
|
||||
<tainacan-subheader :id="collectionId"/>
|
||||
<router-view class="page-container"/>
|
||||
<router-view
|
||||
:collection-id="collectionId"
|
||||
class="page-container"/>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
|
@ -22,6 +24,7 @@ export default {
|
|||
},
|
||||
created(){
|
||||
this.collectionId = parseInt(this.$route.params.collectionId);
|
||||
this.$eventBusSearch.setCollectionId(this.collectionId);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,22 +2,27 @@
|
|||
<div>
|
||||
<div class="is-fullheight">
|
||||
<div class="page-container primary-page">
|
||||
|
||||
<div class="">
|
||||
<div class="field">
|
||||
<b-switch
|
||||
v-model="comp"
|
||||
true-value="Unified"
|
||||
false-value="Split"
|
||||
class="is-pulled-right">
|
||||
{{ comp }}
|
||||
</b-switch>
|
||||
<div class="title">{{ event.description }}</div>
|
||||
<div class="level">
|
||||
<div class="level-left"/>
|
||||
<div class="level-right">
|
||||
<div class="level-item">
|
||||
<b-switch
|
||||
v-model="comp"
|
||||
true-value="Unified"
|
||||
false-value="Split"
|
||||
class="is-pulled-right">
|
||||
{{ comp }}
|
||||
</b-switch>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr class="divider">
|
||||
|
||||
<component
|
||||
:is="comp"
|
||||
:event="event" />
|
||||
:event="event"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -51,8 +56,8 @@
|
|||
}
|
||||
},
|
||||
components: {
|
||||
Split,
|
||||
Unified
|
||||
Split,
|
||||
Unified
|
||||
},
|
||||
created() {
|
||||
this.eventId = parseInt(this.$route.params.eventId);
|
||||
|
@ -67,4 +72,8 @@
|
|||
.back-hlight {
|
||||
background-color: rgb(231, 255, 237);
|
||||
}
|
||||
|
||||
.bottom-space-tainacan {
|
||||
margin-bottom: 0.2rem;
|
||||
}
|
||||
</style>
|
|
@ -31,6 +31,17 @@ html {
|
|||
font-family: $family-sans-serif;
|
||||
}
|
||||
|
||||
.media-modal {
|
||||
left: 130px;
|
||||
top: 130px;
|
||||
bottom: 130px;
|
||||
right: 130px;
|
||||
z-index: 99999999999 !important;
|
||||
}
|
||||
.media-modal-backdrop {
|
||||
z-index: 9999999 !important;
|
||||
}
|
||||
|
||||
/* Rules for sizing the icon. */
|
||||
.material-icons.md-18 { font-size: 18px; }
|
||||
.material-icons.md-24 { font-size: 24px; }
|
||||
|
|
|
@ -135,6 +135,9 @@ return [
|
|||
'label_sorting' => __( 'Sorting', 'tainacan' ),
|
||||
'label_who_when' => __( 'Who and when', 'tainacan' ),
|
||||
'label_event_title' => __( 'Event', 'tainacan' ),
|
||||
'label_cover_image' => __( 'Cover Image', 'tainacan' ),
|
||||
'label_enable_cover_page' => __( 'Enable Cover Page', 'tainacan' ),
|
||||
'label_cover_page' => __( 'Cover Page', 'tainacan' ),
|
||||
|
||||
// Instructions. More complex sentences to guide user and placeholders
|
||||
'instruction_dragndrop_fields_collection' => __( 'Drag and drop Fields here to Collection.', 'tainacan' ),
|
||||
|
@ -154,7 +157,7 @@ return [
|
|||
'info_no_collection_created' => __( 'No collection was created in this repository.', 'tainacan' ),
|
||||
'info_no_category_created' => __( 'No category was created in this repository.', 'tainacan' ),
|
||||
'info_no_item_created' => __( 'No item was created in this collection.', 'tainacan' ),
|
||||
'info_no_item_found' => __( 'No item was found here with these filters.', 'tainacan' ),
|
||||
'info_no_item_found' => __( 'No item was found here with these filters.', 'tainacan' ),
|
||||
'info_error_deleting_collection' => __( 'Error on deleting collection.', 'tainacan' ),
|
||||
'info_error_deleting_category' => __( 'Error on deleting category', 'tainacan' ),
|
||||
'info_collection_deleted' => __( 'Collection deleted.', 'tainacan' ),
|
||||
|
@ -189,6 +192,7 @@ return [
|
|||
'info_logs_after' => __( 'What was updated', 'tainacan' ),
|
||||
'info_there_is_no_field' => __('There is no field here yet.', 'tainacan' ),
|
||||
'info_there_is_no_filter' => __('There is no filter here yet.', 'tainacan' ),
|
||||
'info_changes' => __( 'Changes', 'tainacan' ),
|
||||
|
||||
// Tainacan Field Types
|
||||
'tainacan-text' => __( 'Text', 'tainacan' ),
|
||||
|
|
|
@ -1,21 +1,16 @@
|
|||
<?php
|
||||
|
||||
class TAINACAN_REST_Controller extends WP_REST_Controller {
|
||||
namespace Tainacan\API;
|
||||
|
||||
class REST_Controller extends \WP_REST_Controller {
|
||||
|
||||
|
||||
/**
|
||||
* TAINACAN_REST_Controller constructor.
|
||||
* REST_Controller constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
//add_action( 'rest_api_init', function () {
|
||||
// register_rest_field( 'user',
|
||||
// 'meta',
|
||||
// array(
|
||||
// 'update_callback' => array($this, 'up_user_meta'),
|
||||
// 'get_callback' => array($this, 'gt_user_meta'),
|
||||
// )
|
||||
// );
|
||||
//} );
|
||||
$this->namespace = TAINACAN_REST_NAMESPACE;
|
||||
add_action('rest_api_init', array($this, 'register_routes'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -52,7 +47,7 @@ class TAINACAN_REST_Controller extends WP_REST_Controller {
|
|||
* @param $object
|
||||
* @param $new_values
|
||||
*
|
||||
* @return Tainacan\Entities\Entity
|
||||
* @return \Tainacan\Entities\Entity
|
||||
*/
|
||||
protected function prepare_item_for_updating($object, $new_values){
|
||||
|
||||
|
@ -72,7 +67,7 @@ class TAINACAN_REST_Controller extends WP_REST_Controller {
|
|||
* @param $request
|
||||
*
|
||||
* @return array
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function prepare_filters($request){
|
||||
$queries = [
|
||||
|
@ -161,7 +156,7 @@ class TAINACAN_REST_Controller extends WP_REST_Controller {
|
|||
* @param $field_name
|
||||
* @param $request
|
||||
*
|
||||
* @return WP_Error
|
||||
* @return \WP_Error
|
||||
*/
|
||||
function gt_user_meta( $data, $field_name, $request ) {
|
||||
if( $data['id'] ){
|
||||
|
@ -169,7 +164,7 @@ class TAINACAN_REST_Controller extends WP_REST_Controller {
|
|||
}
|
||||
|
||||
if ( !$user_meta ) {
|
||||
return new WP_Error( 'No user meta found', 'No user meta found', array( 'status' => 404 ) );
|
||||
return new \WP_Error( 'No user meta found', 'No user meta found', array( 'status' => 404 ) );
|
||||
}
|
||||
|
||||
foreach ($user_meta as $key => $value) {
|
||||
|
@ -186,11 +181,11 @@ class TAINACAN_REST_Controller extends WP_REST_Controller {
|
|||
*
|
||||
* @param $request
|
||||
*
|
||||
* @return mixed|WP_Error
|
||||
* @return mixed|\WP_Error
|
||||
*/
|
||||
public function up_user_meta( $meta, $user, $field_name, $request ) {
|
||||
if ( !$user->ID ) {
|
||||
return new WP_Error( 'No user found', 'No user found', array( 'status' => 404 ) );
|
||||
return new \WP_Error( 'No user found', 'No user found', array( 'status' => 404 ) );
|
||||
}
|
||||
|
||||
$user_id = $user->ID;
|
||||
|
@ -248,7 +243,7 @@ class TAINACAN_REST_Controller extends WP_REST_Controller {
|
|||
* @param $args
|
||||
*
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function prepare_meta($mapped, $request, $query, $mapped_v, $args){
|
||||
$request_meta_query = $request[$mapped];
|
||||
|
@ -264,7 +259,7 @@ class TAINACAN_REST_Controller extends WP_REST_Controller {
|
|||
|
||||
// handle core field
|
||||
if( is_array($a) && array_key_exists("key", $a) ){
|
||||
$field = new Tainacan\Entities\Field($a['key']);
|
||||
$field = new \Tainacan\Entities\Field($a['key']);
|
||||
if( strpos( $field->get_field_type(), 'Core_Title') !== false ){
|
||||
$args[ 'post_title_in' ] = [
|
||||
'relation' => ( isset( $request_meta_query['relation']) ) ? $request_meta_query['relation'] : 'AND' ,
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan\API\EndPoints;
|
||||
|
||||
use \Tainacan\API\REST_Controller;
|
||||
use Tainacan\Repositories;
|
||||
use Tainacan\Entities;
|
||||
|
||||
|
@ -8,19 +11,17 @@ use Tainacan\Entities;
|
|||
*
|
||||
* @uses Entities\Collection and Repositories\Collections
|
||||
* */
|
||||
class TAINACAN_REST_Collections_Controller extends TAINACAN_REST_Controller {
|
||||
class REST_Collections_Controller extends REST_Controller {
|
||||
private $collections_repository;
|
||||
private $collection;
|
||||
|
||||
/**
|
||||
* TAINACAN_REST_Collections_Controller constructor.
|
||||
* REST_Collections_Controller constructor.
|
||||
* Define the namespace, rest base and instantiate your attributes.
|
||||
*/
|
||||
public function __construct(){
|
||||
$this->namespace = 'tainacan/v2';
|
||||
$this->rest_base = 'collections';
|
||||
|
||||
add_action('rest_api_init', array($this, 'register_routes'));
|
||||
parent::__construct();
|
||||
add_action('init', array(&$this, 'init_objects'), 11);
|
||||
}
|
||||
|
||||
|
@ -38,33 +39,33 @@ class TAINACAN_REST_Collections_Controller extends TAINACAN_REST_Controller {
|
|||
public function register_routes(){
|
||||
register_rest_route($this->namespace, '/' . $this->rest_base, array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'methods' => \WP_REST_Server::READABLE,
|
||||
'callback' => array($this, 'get_items'),
|
||||
'permission_callback' => array($this, 'get_items_permissions_check'),
|
||||
'args' => $this->get_collection_params(),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::CREATABLE,
|
||||
'methods' => \WP_REST_Server::CREATABLE,
|
||||
'callback' => array($this, 'create_item'),
|
||||
'permission_callback' => array($this, 'create_item_permissions_check'),
|
||||
'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE),
|
||||
'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE),
|
||||
),
|
||||
));
|
||||
register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<collection_id>[\d]+)', array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'methods' => \WP_REST_Server::READABLE,
|
||||
'callback' => array($this, 'get_item'),
|
||||
'permission_callback' => array($this, 'get_item_permissions_check'),
|
||||
'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::READABLE),
|
||||
'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::READABLE),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'methods' => \WP_REST_Server::EDITABLE,
|
||||
'callback' => array($this, 'update_item'),
|
||||
'permission_callback' => array($this, 'update_item_permissions_check'),
|
||||
'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE),
|
||||
'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::DELETABLE,
|
||||
'methods' => \WP_REST_Server::DELETABLE,
|
||||
'callback' => array($this, 'delete_item'),
|
||||
'permission_callback' => array($this, 'delete_item_permissions_check'),
|
||||
'args' => array(
|
||||
|
@ -80,9 +81,9 @@ class TAINACAN_REST_Collections_Controller extends TAINACAN_REST_Controller {
|
|||
/**
|
||||
* Return a array of Collections objects in JSON
|
||||
*
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return WP_Error|WP_REST_Response
|
||||
* @return \WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function get_items($request){
|
||||
$args = $this->prepare_filters($request);
|
||||
|
@ -105,7 +106,7 @@ class TAINACAN_REST_Collections_Controller extends TAINACAN_REST_Controller {
|
|||
$total_collections = $collections->found_posts;
|
||||
$max_pages = ceil($total_collections / (int) $collections->query_vars['posts_per_page']);
|
||||
|
||||
$rest_response = new WP_REST_Response($response, 200);
|
||||
$rest_response = new \WP_REST_Response($response, 200);
|
||||
|
||||
$rest_response->header('X-WP-Total', (int) $total_collections);
|
||||
$rest_response->header('X-WP-TotalPages', (int) $max_pages);
|
||||
|
@ -116,9 +117,9 @@ class TAINACAN_REST_Collections_Controller extends TAINACAN_REST_Controller {
|
|||
/**
|
||||
* Return a Collection object in JSON
|
||||
*
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return WP_Error|WP_REST_Response
|
||||
* @return \WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function get_item($request){
|
||||
$collection_id = $request['collection_id'];
|
||||
|
@ -126,17 +127,17 @@ class TAINACAN_REST_Collections_Controller extends TAINACAN_REST_Controller {
|
|||
|
||||
$response = $this->prepare_item_for_response($collection, $request );
|
||||
|
||||
return new WP_REST_Response($response, 200);
|
||||
return new \WP_REST_Response($response, 200);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Receive a WP_Query or a Collection object and return both in JSON
|
||||
* Receive a \WP_Query or a Collection object and return both in JSON
|
||||
*
|
||||
* @param mixed $item
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return mixed|string|void|WP_Error|WP_REST_Response
|
||||
* @return mixed|string|void|\WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function prepare_item_for_response($item, $request){
|
||||
if(!empty($item)){
|
||||
|
@ -163,10 +164,10 @@ class TAINACAN_REST_Collections_Controller extends TAINACAN_REST_Controller {
|
|||
|
||||
/**
|
||||
*
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return bool|WP_Error
|
||||
* @throws Exception
|
||||
* @return bool|\WP_Error
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function get_items_permissions_check($request){
|
||||
$dummy = new Entities\Collection();
|
||||
|
@ -179,10 +180,10 @@ class TAINACAN_REST_Collections_Controller extends TAINACAN_REST_Controller {
|
|||
|
||||
/**
|
||||
*
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return bool|WP_Error
|
||||
* @throws Exception
|
||||
* @return bool|\WP_Error
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function get_item_permissions_check($request){
|
||||
$collection = $this->collections_repository->fetch($request['collection_id']);
|
||||
|
@ -202,15 +203,15 @@ class TAINACAN_REST_Collections_Controller extends TAINACAN_REST_Controller {
|
|||
* Receive a JSON with the structure of a Collection and return, in case of success insert
|
||||
* a Collection object in JSON
|
||||
*
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return array|WP_Error|WP_REST_Response
|
||||
* @return array|\WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function create_item( $request ) {
|
||||
$body = json_decode($request->get_body(), true);
|
||||
|
||||
if(empty($body)){
|
||||
return new WP_REST_Response([
|
||||
return new \WP_REST_Response([
|
||||
'error_message' => __('Body can not be empty.', 'tainacan'),
|
||||
'collection' => $body
|
||||
], 400);
|
||||
|
@ -219,7 +220,7 @@ class TAINACAN_REST_Collections_Controller extends TAINACAN_REST_Controller {
|
|||
try {
|
||||
$prepared_post = $this->prepare_item_for_database( $body );
|
||||
} catch (\Error $exception){
|
||||
return new WP_REST_Response($exception->getMessage(), 400);
|
||||
return new \WP_REST_Response($exception->getMessage(), 400);
|
||||
}
|
||||
|
||||
if($prepared_post->validate()) {
|
||||
|
@ -227,10 +228,10 @@ class TAINACAN_REST_Collections_Controller extends TAINACAN_REST_Controller {
|
|||
|
||||
$response = $this->prepare_item_for_response($collection, $request);
|
||||
|
||||
return new WP_REST_Response($response, 201);
|
||||
return new \WP_REST_Response($response, 201);
|
||||
}
|
||||
|
||||
return new WP_REST_Response([
|
||||
return new \WP_REST_Response([
|
||||
'error_message' => __('One or more values are invalid.', 'tainacan'),
|
||||
'errors' => $prepared_post->get_errors(),
|
||||
'collection' => $this->prepare_item_for_response($prepared_post, $request)
|
||||
|
@ -240,10 +241,10 @@ class TAINACAN_REST_Collections_Controller extends TAINACAN_REST_Controller {
|
|||
/**
|
||||
* Verify if current has permission to create a item
|
||||
*
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return bool|WP_Error
|
||||
* @throws Exception
|
||||
* @return bool|\WP_Error
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function create_item_permissions_check( $request ) {
|
||||
return $this->collection->can_edit();
|
||||
|
@ -252,9 +253,9 @@ class TAINACAN_REST_Collections_Controller extends TAINACAN_REST_Controller {
|
|||
/**
|
||||
* Prepare collection for insertion on database
|
||||
*
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return object|Entities\Collection|WP_Error
|
||||
* @return object|Entities\Collection|\WP_Error
|
||||
*/
|
||||
public function prepare_item_for_database( $request ) {
|
||||
|
||||
|
@ -269,9 +270,9 @@ class TAINACAN_REST_Collections_Controller extends TAINACAN_REST_Controller {
|
|||
/**
|
||||
* Delete a collection
|
||||
*
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return string|WP_Error|WP_REST_Response
|
||||
* @return string|\WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function delete_item( $request ) {
|
||||
$collection_id = $request['collection_id'];
|
||||
|
@ -283,16 +284,16 @@ class TAINACAN_REST_Collections_Controller extends TAINACAN_REST_Controller {
|
|||
|
||||
$prepared_collection = $this->prepare_item_for_response($collection, $request);
|
||||
|
||||
return new WP_REST_Response($prepared_collection, 200);
|
||||
return new \WP_REST_Response($prepared_collection, 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify if current user has permission to delete a collection
|
||||
*
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return bool|WP_Error
|
||||
* @throws Exception
|
||||
* @return bool|\WP_Error
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function delete_item_permissions_check( $request ) {
|
||||
$collection = $this->collections_repository->fetch($request['collection_id']);
|
||||
|
@ -307,9 +308,9 @@ class TAINACAN_REST_Collections_Controller extends TAINACAN_REST_Controller {
|
|||
/**
|
||||
* Update a collection
|
||||
*
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return string|WP_Error|WP_REST_Response
|
||||
* @return string|\WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function update_item( $request ) {
|
||||
$collection_id = $request['collection_id'];
|
||||
|
@ -333,23 +334,23 @@ class TAINACAN_REST_Collections_Controller extends TAINACAN_REST_Controller {
|
|||
|
||||
$response = $this->prepare_item_for_response($updated_collection, $request);
|
||||
|
||||
return new WP_REST_Response( $response, 200 );
|
||||
return new \WP_REST_Response( $response, 200 );
|
||||
}
|
||||
|
||||
return new WP_REST_Response([
|
||||
return new \WP_REST_Response([
|
||||
'error_message' => __('One or more values are invalid.', 'tainacan'),
|
||||
'errors' => $prepared_collection->get_errors(),
|
||||
'collection' => $this->prepare_item_for_response($prepared_collection, $request)
|
||||
], 400);
|
||||
}
|
||||
|
||||
return new WP_REST_Response([
|
||||
return new \WP_REST_Response([
|
||||
'error_message' => __('Collection with that ID not found', 'tainacan' ),
|
||||
'collection_id' => $collection_id
|
||||
], 400);
|
||||
}
|
||||
|
||||
return new WP_REST_Response([
|
||||
return new \WP_REST_Response([
|
||||
'error_message' => __('The body could not be empty', 'tainacan'),
|
||||
'body' => $body
|
||||
], 400);
|
||||
|
@ -359,10 +360,10 @@ class TAINACAN_REST_Collections_Controller extends TAINACAN_REST_Controller {
|
|||
/**
|
||||
* Verify if current user has permission to update a item
|
||||
*
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return bool|WP_Error
|
||||
* @throws Exception
|
||||
* @return bool|\WP_Error
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function update_item_permissions_check( $request ) {
|
||||
$collection = $this->collections_repository->fetch($request['collection_id']);
|
||||
|
@ -381,7 +382,7 @@ class TAINACAN_REST_Collections_Controller extends TAINACAN_REST_Controller {
|
|||
*/
|
||||
public function get_endpoint_args_for_item_schema( $method = null ) {
|
||||
$endpoint_args = [];
|
||||
if($method === WP_REST_Server::READABLE) {
|
||||
if($method === \WP_REST_Server::READABLE) {
|
||||
$endpoint_args['fetch_only'] = array(
|
||||
'type' => 'string/array',
|
||||
'description' => __( 'Fetch only specific attribute. The specifics attributes are the same in schema.' ),
|
||||
|
@ -392,7 +393,7 @@ class TAINACAN_REST_Collections_Controller extends TAINACAN_REST_Controller {
|
|||
'default' => 'view',
|
||||
'items' => array( 'view, edit' )
|
||||
);
|
||||
} elseif ($method === WP_REST_Server::CREATABLE || $method === WP_REST_Server::EDITABLE) {
|
||||
} elseif ($method === \WP_REST_Server::CREATABLE || $method === \WP_REST_Server::EDITABLE) {
|
||||
$map = $this->collections_repository->get_map();
|
||||
|
||||
foreach ($map as $mapped => $value){
|
||||
|
|
|
@ -1,22 +1,24 @@
|
|||
<?php
|
||||
|
||||
class TAINACAN_REST_Field_Types_Controller extends TAINACAN_REST_Controller {
|
||||
namespace Tainacan\API\EndPoints;
|
||||
|
||||
use \Tainacan\API\REST_Controller;
|
||||
|
||||
class REST_Field_Types_Controller extends REST_Controller {
|
||||
|
||||
/**
|
||||
* TAINACAN_REST_Field_Types_Controller constructor.
|
||||
* REST_Field_Types_Controller constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->namespace = 'tainacan/v2';
|
||||
$this->rest_base = 'field-types';
|
||||
|
||||
add_action('rest_api_init', array($this, 'register_routes'));
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function register_routes() {
|
||||
register_rest_route($this->namespace, '/' . $this->rest_base,
|
||||
array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'methods' => \WP_REST_Server::READABLE,
|
||||
'callback' => array($this, 'get_items'),
|
||||
'permission_callback' => array($this, 'get_items_permissions_check'),
|
||||
'args' => [
|
||||
|
@ -60,9 +62,9 @@ class TAINACAN_REST_Field_Types_Controller extends TAINACAN_REST_Controller {
|
|||
|
||||
/**
|
||||
* @param $item
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return mixed|WP_Error|WP_REST_Response
|
||||
* @return mixed|\WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function prepare_item_for_response( $item, $request ) {
|
||||
$name = "\Tainacan\Field_Types\\$item";
|
||||
|
@ -75,9 +77,9 @@ class TAINACAN_REST_Field_Types_Controller extends TAINACAN_REST_Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return WP_Error|WP_REST_Response
|
||||
* @return \WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function get_items( $request ) {
|
||||
$Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
|
||||
|
@ -89,13 +91,13 @@ class TAINACAN_REST_Field_Types_Controller extends TAINACAN_REST_Controller {
|
|||
array_push($prepared, $this->prepare_item_for_response($field_type, $request));
|
||||
}
|
||||
|
||||
return new WP_REST_Response($prepared, 200);
|
||||
return new \WP_REST_Response($prepared, 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return bool|WP_Error
|
||||
* @return bool|\WP_Error
|
||||
*/
|
||||
public function get_items_permissions_check( $request ) {
|
||||
return true;
|
||||
|
|
|
@ -1,26 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan\API\EndPoints;
|
||||
|
||||
use \Tainacan\API\REST_Controller;
|
||||
use Tainacan\Entities;
|
||||
use Tainacan\Repositories;
|
||||
|
||||
class TAINACAN_REST_Fields_Controller extends TAINACAN_REST_Controller {
|
||||
class REST_Fields_Controller extends REST_Controller {
|
||||
private $item_metadata_repository;
|
||||
private $item_repository;
|
||||
private $collection_repository;
|
||||
private $field_repository;
|
||||
|
||||
public function __construct() {
|
||||
$this->namespace = 'tainacan/v2';
|
||||
$this->rest_base = 'fields';
|
||||
|
||||
add_action('rest_api_init', array($this, 'register_routes'));
|
||||
parent::__construct();
|
||||
add_action('init', array(&$this, 'init_objects'), 11);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize objects after post_type register
|
||||
*
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function init_objects() {
|
||||
$this->field_repository = Repositories\Fields::get_instance();
|
||||
|
@ -38,57 +39,57 @@ class TAINACAN_REST_Fields_Controller extends TAINACAN_REST_Controller {
|
|||
*
|
||||
* Both of GETs return the field of matched objects
|
||||
*
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function register_routes() {
|
||||
register_rest_route($this->namespace, '/collection/(?P<collection_id>[\d]+)/' . $this->rest_base . '/(?P<field_id>[\d]+)',
|
||||
array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'methods' => \WP_REST_Server::EDITABLE,
|
||||
'callback' => array($this, 'update_item'),
|
||||
'permission_callback' => array($this, 'update_item_permissions_check'),
|
||||
'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE)
|
||||
'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE)
|
||||
),
|
||||
// ENDPOINT X. THIS ENDPOINT DO THE SAME THING OF ENDPOINT Z. I hope in a brief future it function changes.
|
||||
array(
|
||||
'methods' => WP_REST_Server::DELETABLE,
|
||||
'methods' => \WP_REST_Server::DELETABLE,
|
||||
'callback' => array($this, 'delete_item'),
|
||||
'permission_callback' => array($this, 'delete_item_permissions_check'),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'methods' => \WP_REST_Server::READABLE,
|
||||
'callback' => array($this, 'get_item'),
|
||||
'permission_callback' => array($this, 'get_item_permissions_check'),
|
||||
'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::READABLE),
|
||||
'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::READABLE),
|
||||
),
|
||||
)
|
||||
);
|
||||
register_rest_route($this->namespace, '/collection/(?P<collection_id>[\d]+)/' . $this->rest_base,
|
||||
array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'methods' => \WP_REST_Server::READABLE,
|
||||
'callback' => array($this, 'get_items'),
|
||||
'permission_callback' => array($this, 'get_items_permissions_check'),
|
||||
'args' => $this->get_collection_params(),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::CREATABLE,
|
||||
'methods' => \WP_REST_Server::CREATABLE,
|
||||
'callback' => array($this, 'create_item'),
|
||||
'permission_callback' => array($this, 'create_item_permissions_check'),
|
||||
'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE),
|
||||
'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE),
|
||||
),
|
||||
)
|
||||
);
|
||||
register_rest_route($this->namespace, '/' . $this->rest_base,
|
||||
array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::CREATABLE,
|
||||
'methods' => \WP_REST_Server::CREATABLE,
|
||||
'callback' => array($this, 'create_item'),
|
||||
'permission_callback' => array($this, 'create_item_permissions_check'),
|
||||
'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE),
|
||||
'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'methods' => \WP_REST_Server::READABLE,
|
||||
'callback' => array($this, 'get_items'),
|
||||
'permission_callback' => array($this, 'get_items_permissions_check'),
|
||||
'args' => $this->get_collection_params(),
|
||||
|
@ -99,24 +100,24 @@ class TAINACAN_REST_Fields_Controller extends TAINACAN_REST_Controller {
|
|||
array(
|
||||
// ENDPOINT Z.
|
||||
array(
|
||||
'methods' => WP_REST_Server::DELETABLE,
|
||||
'methods' => \WP_REST_Server::DELETABLE,
|
||||
'callback' => array($this, 'delete_item'),
|
||||
'permission_callback' => array($this, 'delete_item_permissions_check')
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'methods' => \WP_REST_Server::EDITABLE,
|
||||
'callback' => array($this, 'update_item'),
|
||||
'permission_callback' => array($this, 'update_item_permissions_check'),
|
||||
'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE)
|
||||
'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE)
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return WP_Error|WP_REST_Response
|
||||
* @return \WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function get_item( $request ) {
|
||||
$collection_id = $request['collection_id'];
|
||||
|
@ -125,19 +126,19 @@ class TAINACAN_REST_Fields_Controller extends TAINACAN_REST_Controller {
|
|||
if($request['fetch'] === 'all_field_values'){
|
||||
$results = $this->field_repository->fetch_all_field_values($collection_id, $field_id);
|
||||
|
||||
return new WP_REST_Response($results, 200);
|
||||
return new \WP_REST_Response($results, 200);
|
||||
}
|
||||
|
||||
$result = $this->field_repository->fetch($field_id, 'OBJECT');
|
||||
|
||||
return new WP_REST_Response($this->prepare_item_for_response($result, $request), 200);
|
||||
return new \WP_REST_Response($this->prepare_item_for_response($result, $request), 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return bool|WP_Error
|
||||
* @throws Exception
|
||||
* @return bool|\WP_Error
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function get_item_permissions_check( $request ) {
|
||||
$collection = $this->collection_repository->fetch($request['collection_id']);
|
||||
|
@ -154,12 +155,12 @@ class TAINACAN_REST_Fields_Controller extends TAINACAN_REST_Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @param null $collection_id
|
||||
*
|
||||
* @return object|void|WP_Error
|
||||
* @throws Exception
|
||||
* @return object|void|\WP_Error
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function prepare_item_for_database( $request, $collection_id = null ) {
|
||||
$field = new Entities\Field();
|
||||
|
@ -181,10 +182,10 @@ class TAINACAN_REST_Fields_Controller extends TAINACAN_REST_Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return WP_Error|WP_REST_Response
|
||||
* @throws Exception
|
||||
* @return \WP_Error|\WP_REST_Response
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function create_item( $request ) {
|
||||
if(!empty($request->get_body()) && isset($request['collection_id'])){
|
||||
|
@ -193,7 +194,7 @@ class TAINACAN_REST_Fields_Controller extends TAINACAN_REST_Controller {
|
|||
try {
|
||||
$prepared = $this->prepare_item_for_database( $request->get_body(), $collection_id );
|
||||
} catch (\Error $exception){
|
||||
return new WP_REST_Response($exception->getMessage(), 400);
|
||||
return new \WP_REST_Response($exception->getMessage(), 400);
|
||||
}
|
||||
|
||||
if($prepared->validate()) {
|
||||
|
@ -201,9 +202,9 @@ class TAINACAN_REST_Fields_Controller extends TAINACAN_REST_Controller {
|
|||
|
||||
$response = $this->prepare_item_for_response($field, $request);
|
||||
|
||||
return new WP_REST_Response($response, 201);
|
||||
return new \WP_REST_Response($response, 201);
|
||||
} else {
|
||||
return new WP_REST_Response([
|
||||
return new \WP_REST_Response([
|
||||
'error_message' => __('One or more values are invalid.', 'tainacan'),
|
||||
'errors' => $prepared->get_errors(),
|
||||
'field' => $this->prepare_item_for_response($prepared, $request),
|
||||
|
@ -213,7 +214,7 @@ class TAINACAN_REST_Fields_Controller extends TAINACAN_REST_Controller {
|
|||
try {
|
||||
$prepared = $this->prepare_item_for_database( $request->get_body() );
|
||||
} catch ( \Error $exception ) {
|
||||
return new WP_REST_Response( $exception->getMessage(), 400 );
|
||||
return new \WP_REST_Response( $exception->getMessage(), 400 );
|
||||
}
|
||||
|
||||
if ( $prepared->validate() ) {
|
||||
|
@ -221,9 +222,9 @@ class TAINACAN_REST_Fields_Controller extends TAINACAN_REST_Controller {
|
|||
|
||||
$response = $this->prepare_item_for_response($field, $request);
|
||||
|
||||
return new WP_REST_Response($response, 201);
|
||||
return new \WP_REST_Response($response, 201);
|
||||
} else {
|
||||
return new WP_REST_Response([
|
||||
return new \WP_REST_Response([
|
||||
'error_message' => __('One or more values are invalid.', 'tainacan'),
|
||||
'errors' => $prepared->get_errors(),
|
||||
'field' => $this->prepare_item_for_response($prepared, $request),
|
||||
|
@ -232,7 +233,7 @@ class TAINACAN_REST_Fields_Controller extends TAINACAN_REST_Controller {
|
|||
|
||||
}
|
||||
|
||||
return new WP_REST_Response([
|
||||
return new \WP_REST_Response([
|
||||
'error_message' => __('Body can not be empty.', 'tainacan'),
|
||||
'item' => $request->get_body()
|
||||
], 400);
|
||||
|
@ -242,8 +243,8 @@ class TAINACAN_REST_Fields_Controller extends TAINACAN_REST_Controller {
|
|||
/**
|
||||
* @param $request
|
||||
*
|
||||
* @return bool|WP_Error
|
||||
* @throws Exception
|
||||
* @return bool|\WP_Error
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function create_item_permissions_check( $request ) {
|
||||
if(isset($request['collection_id'])) {
|
||||
|
@ -255,9 +256,9 @@ class TAINACAN_REST_Fields_Controller extends TAINACAN_REST_Controller {
|
|||
|
||||
/**
|
||||
* @param mixed $item
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return array|WP_Error|WP_REST_Response
|
||||
* @return array|\WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function prepare_item_for_response( $item, $request ) {
|
||||
if(!empty($item)){
|
||||
|
@ -281,9 +282,9 @@ class TAINACAN_REST_Fields_Controller extends TAINACAN_REST_Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return WP_Error|WP_REST_Response
|
||||
* @return \WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function get_items( $request ) {
|
||||
if(isset($request['collection_id'])) {
|
||||
|
@ -317,14 +318,14 @@ class TAINACAN_REST_Fields_Controller extends TAINACAN_REST_Controller {
|
|||
$prepared_item[] = $this->prepare_item_for_response( $item, $request );
|
||||
}
|
||||
|
||||
return new WP_REST_Response($prepared_item, 200);
|
||||
return new \WP_REST_Response($prepared_item, 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return bool|WP_Error
|
||||
* @throws Exception
|
||||
* @return bool|\WP_Error
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function get_items_permissions_check( $request ) {
|
||||
if ( 'edit' === $request['context'] && ! current_user_can('edit_tainacan-fields') ) {
|
||||
|
@ -335,9 +336,9 @@ class TAINACAN_REST_Fields_Controller extends TAINACAN_REST_Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return WP_Error|WP_REST_Response
|
||||
* @return \WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function delete_item( $request ) {
|
||||
$field_id = $request['field_id'];
|
||||
|
@ -346,14 +347,14 @@ class TAINACAN_REST_Fields_Controller extends TAINACAN_REST_Controller {
|
|||
|
||||
$prepared = $this->prepare_item_for_response($field_trashed, $request);
|
||||
|
||||
return new WP_REST_Response($prepared, 200);
|
||||
return new \WP_REST_Response($prepared, 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return bool|WP_Error
|
||||
* @throws Exception
|
||||
* @return bool|\WP_Error
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function delete_item_permissions_check( $request ) {
|
||||
if (isset($request['collection_id'])) {
|
||||
|
@ -368,9 +369,9 @@ class TAINACAN_REST_Fields_Controller extends TAINACAN_REST_Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return WP_Error|WP_REST_Response
|
||||
* @return \WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function update_item( $request ) {
|
||||
$collection_id = is_numeric($request['collection_id']) ? $request['collection_id'] : null;
|
||||
|
@ -395,14 +396,14 @@ class TAINACAN_REST_Fields_Controller extends TAINACAN_REST_Controller {
|
|||
if(!$collection_id && $field->get_collection_id() !== 'default') {
|
||||
$error_message = __('That field is not a default field', 'tainacan');
|
||||
|
||||
return new WP_REST_Response( [
|
||||
return new \WP_REST_Response( [
|
||||
'error_message' => $error_message,
|
||||
'field_id' => $field_id
|
||||
] );
|
||||
} elseif ($collection_id && $field->get_collection_id() === 'default'){
|
||||
$error_message = __('That field is not a collection field', 'tainacan');
|
||||
|
||||
return new WP_REST_Response( [
|
||||
return new \WP_REST_Response( [
|
||||
'error_message' => $error_message,
|
||||
'field_id' => $field_id
|
||||
] );
|
||||
|
@ -415,33 +416,33 @@ class TAINACAN_REST_Fields_Controller extends TAINACAN_REST_Controller {
|
|||
|
||||
$response = $this->prepare_item_for_response($updated_metadata, $request);
|
||||
|
||||
return new WP_REST_Response($response, 200);
|
||||
return new \WP_REST_Response($response, 200);
|
||||
}
|
||||
|
||||
return new WP_REST_Response([
|
||||
return new \WP_REST_Response([
|
||||
'error_message' => __('One or more values are invalid.', 'tainacan'),
|
||||
'errors' => $prepared_metadata->get_errors(),
|
||||
'metadata' => $this->prepare_item_for_response($prepared_metadata, $request)
|
||||
], 400);
|
||||
}
|
||||
|
||||
return new WP_REST_Response( [
|
||||
return new \WP_REST_Response( [
|
||||
'error_message' => $error_message,
|
||||
'field_id' => $field_id
|
||||
] );
|
||||
}
|
||||
|
||||
return new WP_REST_Response([
|
||||
return new \WP_REST_Response([
|
||||
'error_message' => __('The body could not be empty', 'tainacan'),
|
||||
'body' => $body
|
||||
], 400);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return bool|WP_Error
|
||||
* @throws Exception
|
||||
* @return bool|\WP_Error
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function update_item_permissions_check( $request ) {
|
||||
if(isset($request['collection_id'])) {
|
||||
|
@ -480,11 +481,11 @@ class TAINACAN_REST_Fields_Controller extends TAINACAN_REST_Controller {
|
|||
* @param null $method
|
||||
*
|
||||
* @return array
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function get_endpoint_args_for_item_schema( $method = null ) {
|
||||
$endpoint_args = [];
|
||||
if($method === WP_REST_Server::READABLE) {
|
||||
if($method === \WP_REST_Server::READABLE) {
|
||||
$endpoint_args['fetch'] = [
|
||||
'type' => 'string',
|
||||
'description' => __('Fetch all values of a field from a collection in all it collection items'),
|
||||
|
@ -495,7 +496,7 @@ class TAINACAN_REST_Fields_Controller extends TAINACAN_REST_Controller {
|
|||
'default' => 'view',
|
||||
'items' => array( 'view, edit' )
|
||||
);
|
||||
} elseif ($method === WP_REST_Server::CREATABLE || $method === WP_REST_Server::EDITABLE) {
|
||||
} elseif ($method === \WP_REST_Server::CREATABLE || $method === \WP_REST_Server::EDITABLE) {
|
||||
$map = $this->field_repository->get_map();
|
||||
|
||||
foreach ($map as $mapped => $value){
|
||||
|
|
|
@ -1,22 +1,24 @@
|
|||
<?php
|
||||
|
||||
class TAINACAN_REST_Filter_Types_Controller extends TAINACAN_REST_Controller {
|
||||
namespace Tainacan\API\EndPoints;
|
||||
|
||||
use \Tainacan\API\REST_Controller;
|
||||
|
||||
class REST_Filter_Types_Controller extends REST_Controller {
|
||||
|
||||
/**
|
||||
* TAINACAN_REST_Filter_Types_Controller constructor.
|
||||
* REST_Filter_Types_Controller constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->namespace = 'tainacan/v2';
|
||||
$this->rest_base = 'filter-types';
|
||||
|
||||
add_action('rest_api_init', array($this, 'register_routes'));
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function register_routes() {
|
||||
register_rest_route($this->namespace, '/' . $this->rest_base,
|
||||
array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'methods' => \WP_REST_Server::READABLE,
|
||||
'callback' => array($this, 'get_items'),
|
||||
'permission_callback' => array($this, 'get_items_permissions_check'),
|
||||
'args' => [
|
||||
|
@ -45,9 +47,9 @@ class TAINACAN_REST_Filter_Types_Controller extends TAINACAN_REST_Controller {
|
|||
|
||||
/**
|
||||
* @param mixed $item
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return mixed|WP_Error|WP_REST_Response
|
||||
* @return mixed|\WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function prepare_item_for_response( $item, $request ) {
|
||||
$name = "\Tainacan\Filter_Types\\$item";
|
||||
|
@ -60,9 +62,9 @@ class TAINACAN_REST_Filter_Types_Controller extends TAINACAN_REST_Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return WP_Error|WP_REST_Response
|
||||
* @return \WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function get_items( $request ) {
|
||||
$Tainacan_Filters = \Tainacan\Repositories\Filters::get_instance();
|
||||
|
@ -74,13 +76,13 @@ class TAINACAN_REST_Filter_Types_Controller extends TAINACAN_REST_Controller {
|
|||
array_push($prepared, $this->prepare_item_for_response($filter_type, $request));
|
||||
}
|
||||
|
||||
return new WP_REST_Response($prepared, 200);
|
||||
return new \WP_REST_Response($prepared, 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return bool|WP_Error
|
||||
* @return bool|\WP_Error
|
||||
*/
|
||||
public function get_items_permissions_check( $request ) {
|
||||
return true;
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan\API\EndPoints;
|
||||
|
||||
use \Tainacan\API\REST_Controller;
|
||||
use Tainacan\Entities;
|
||||
use Tainacan\Repositories;
|
||||
|
||||
class TAINACAN_REST_Filters_Controller extends TAINACAN_REST_Controller {
|
||||
class REST_Filters_Controller extends REST_Controller {
|
||||
private $collection;
|
||||
private $collection_repository;
|
||||
|
||||
|
@ -13,13 +16,11 @@ class TAINACAN_REST_Filters_Controller extends TAINACAN_REST_Controller {
|
|||
private $filter_repository;
|
||||
|
||||
/**
|
||||
* TAINACAN_REST_Filters_Controller constructor.
|
||||
* REST_Filters_Controller constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->namespace = 'tainacan/v2';
|
||||
$this->rest_base = 'filters';
|
||||
|
||||
add_action('rest_api_init', array($this, 'register_routes'));
|
||||
parent::__construct();
|
||||
add_action('init', array(&$this, 'init_objects'), 11);
|
||||
}
|
||||
|
||||
|
@ -38,43 +39,43 @@ class TAINACAN_REST_Filters_Controller extends TAINACAN_REST_Controller {
|
|||
public function register_routes() {
|
||||
register_rest_route($this->namespace, '/collection/(?P<collection_id>[\d]+)/field/(?P<field_id>[\d]+)/' . $this->rest_base, array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::CREATABLE,
|
||||
'methods' => \WP_REST_Server::CREATABLE,
|
||||
'callback' => array($this, 'create_item'),
|
||||
'permission_callback' => array($this, 'create_item_permissions_check'),
|
||||
'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE)
|
||||
'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE)
|
||||
),
|
||||
));
|
||||
register_rest_route($this->namespace, '/collection/(?P<collection_id>[\d]+)/' . $this->rest_base, array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'methods' => \WP_REST_Server::READABLE,
|
||||
'callback' => array($this, 'get_items'),
|
||||
'permission_callback' => array($this, 'get_items_permissions_check'),
|
||||
'args' => $this->get_collection_params()
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::CREATABLE,
|
||||
'methods' => \WP_REST_Server::CREATABLE,
|
||||
'callback' => array($this, 'create_item'),
|
||||
'permission_callback' => array($this, 'create_item_permissions_check'),
|
||||
'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE)
|
||||
'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE)
|
||||
)
|
||||
));
|
||||
register_rest_route($this->namespace, '/' . $this->rest_base, array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'methods' => \WP_REST_Server::READABLE,
|
||||
'callback' => array($this, 'get_items'),
|
||||
'permission_callback' => array($this, 'get_items_permissions_check'),
|
||||
'args' => $this->get_collection_params()
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::CREATABLE,
|
||||
'methods' => \WP_REST_Server::CREATABLE,
|
||||
'callback' => array($this, 'create_item'),
|
||||
'permission_callback' => array($this, 'create_item_permissions_check'),
|
||||
'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE)
|
||||
'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE)
|
||||
)
|
||||
));
|
||||
register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<filter_id>[\d]+)', array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::DELETABLE,
|
||||
'methods' => \WP_REST_Server::DELETABLE,
|
||||
'callback' => array($this, 'delete_item'),
|
||||
'permission_callback' => array($this, 'delete_item_permissions_check'),
|
||||
'args' => array(
|
||||
|
@ -85,25 +86,25 @@ class TAINACAN_REST_Filters_Controller extends TAINACAN_REST_Controller {
|
|||
)
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'methods' => \WP_REST_Server::EDITABLE,
|
||||
'callback' => array($this, 'update_item'),
|
||||
'permission_callback' => array($this, 'update_item_permissions_check'),
|
||||
'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE)
|
||||
'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE)
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'methods' => \WP_REST_Server::READABLE,
|
||||
'callback' => array($this, 'get_item'),
|
||||
'permission_callback' => array($this, 'get_item_permissions_check'),
|
||||
'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::READABLE)
|
||||
'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::READABLE)
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return object|void|WP_Error
|
||||
* @return object|void|\WP_Error
|
||||
*/
|
||||
public function prepare_item_for_database( $request ) {
|
||||
$body = json_decode($request->get_body(), true);
|
||||
|
@ -115,7 +116,7 @@ class TAINACAN_REST_Filters_Controller extends TAINACAN_REST_Controller {
|
|||
$received_type = $body['filter_type'];
|
||||
|
||||
if(empty($received_type)){
|
||||
throw new \InvalidArgumentException('The type can\'t be empty');
|
||||
throw new \InvalidArgument\Exception('The type can\'t be empty');
|
||||
} elseif(!strrchr($received_type, '_')){
|
||||
$received_type = ucfirst(strtolower($received_type));
|
||||
} else {
|
||||
|
@ -157,9 +158,9 @@ class TAINACAN_REST_Filters_Controller extends TAINACAN_REST_Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return WP_Error|WP_REST_Response
|
||||
* @return \WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function create_item( $request ) {
|
||||
|
||||
|
@ -169,26 +170,26 @@ class TAINACAN_REST_Filters_Controller extends TAINACAN_REST_Controller {
|
|||
if ($filter_obj->validate()){
|
||||
$filter_inserted = $this->filter_repository->insert($filter_obj);
|
||||
|
||||
return new WP_REST_Response($this->prepare_item_for_response($filter_inserted, $request), 200);
|
||||
return new \WP_REST_Response($this->prepare_item_for_response($filter_inserted, $request), 200);
|
||||
}
|
||||
|
||||
return new WP_REST_Response([
|
||||
return new \WP_REST_Response([
|
||||
'error_message' => __('One or more attributes are invalid', 'tainacan'),
|
||||
'error' => $filter_obj->get_errors()
|
||||
], 400);
|
||||
}
|
||||
|
||||
return new WP_REST_Response([
|
||||
return new \WP_REST_Response([
|
||||
'error_message' => __('The body could not be empty', 'tainacan'),
|
||||
'body' => $request->get_body()
|
||||
], 400);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return bool|WP_Error
|
||||
* @throws Exception
|
||||
* @return bool|\WP_Error
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function create_item_permissions_check( $request ) {
|
||||
if(isset($request['collection_id']) && isset($request['field_id'])) {
|
||||
|
@ -212,9 +213,9 @@ class TAINACAN_REST_Filters_Controller extends TAINACAN_REST_Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return WP_Error|WP_REST_Response
|
||||
* @return \WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function delete_item( $request ) {
|
||||
$filter_id = $request['filter_id'];
|
||||
|
@ -224,13 +225,13 @@ class TAINACAN_REST_Filters_Controller extends TAINACAN_REST_Controller {
|
|||
|
||||
$filter = $this->filter_repository->delete($args);
|
||||
|
||||
return new WP_REST_Response($this->prepare_item_for_response($filter, $request), 200);
|
||||
return new \WP_REST_Response($this->prepare_item_for_response($filter, $request), 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return bool|WP_Error
|
||||
* @return bool|\WP_Error
|
||||
*/
|
||||
public function delete_item_permissions_check( $request ) {
|
||||
$filter = $this->filter_repository->fetch($request['filter_id']);
|
||||
|
@ -245,7 +246,7 @@ class TAINACAN_REST_Filters_Controller extends TAINACAN_REST_Controller {
|
|||
/**
|
||||
* @param $request
|
||||
*
|
||||
* @return WP_Error|WP_REST_Response
|
||||
* @return \WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function update_item( $request ) {
|
||||
$filter_id = $request['filter_id'];
|
||||
|
@ -267,24 +268,24 @@ class TAINACAN_REST_Filters_Controller extends TAINACAN_REST_Controller {
|
|||
if($prepared_filter->validate()) {
|
||||
$updated_filter = $this->filter_repository->update( $prepared_filter );
|
||||
|
||||
return new WP_REST_Response($this->prepare_item_for_response($updated_filter, $request), 200);
|
||||
return new \WP_REST_Response($this->prepare_item_for_response($updated_filter, $request), 200);
|
||||
}
|
||||
|
||||
return new WP_REST_Response([
|
||||
return new \WP_REST_Response([
|
||||
'error_message' => __('One or more values are invalid.', 'tainacan'),
|
||||
'errors' => $prepared_filter->get_errors(),
|
||||
'filters' => $this->prepare_item_for_response($prepared_filter, $request)
|
||||
], 400);
|
||||
}
|
||||
|
||||
return new WP_REST_Response([
|
||||
return new \WP_REST_Response([
|
||||
'error_message' => __('Filter with that ID not found', 'tainacan' ),
|
||||
'filter_id' => $filter_id
|
||||
], 400);
|
||||
|
||||
}
|
||||
|
||||
return new WP_REST_Response([
|
||||
return new \WP_REST_Response([
|
||||
'error_message' => __('The body could not be empty', 'tainacan'),
|
||||
'body' => $body
|
||||
], 400);
|
||||
|
@ -292,9 +293,9 @@ class TAINACAN_REST_Filters_Controller extends TAINACAN_REST_Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return bool|WP_Error
|
||||
* @return bool|\WP_Error
|
||||
*/
|
||||
public function update_item_permissions_check( $request ) {
|
||||
$filter = $this->filter_repository->fetch($request['filter_id']);
|
||||
|
@ -308,9 +309,9 @@ class TAINACAN_REST_Filters_Controller extends TAINACAN_REST_Controller {
|
|||
|
||||
/**
|
||||
* @param $item
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return array|mixed|WP_Error|WP_REST_Response
|
||||
* @return array|mixed|\WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function prepare_item_for_response( $item, $request ) {
|
||||
if(!empty($item)) {
|
||||
|
@ -328,9 +329,9 @@ class TAINACAN_REST_Filters_Controller extends TAINACAN_REST_Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return WP_Error|WP_REST_Response
|
||||
* @return \WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function get_items( $request ) {
|
||||
$args = $this->prepare_filters( $request );
|
||||
|
@ -353,13 +354,13 @@ class TAINACAN_REST_Filters_Controller extends TAINACAN_REST_Controller {
|
|||
array_push( $response, $this->prepare_item_for_response( $filter, $request ) );
|
||||
}
|
||||
|
||||
return new WP_REST_Response($response, 200);
|
||||
return new \WP_REST_Response($response, 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return bool|WP_Error
|
||||
* @return bool|\WP_Error
|
||||
*/
|
||||
public function get_items_permissions_check( $request ) {
|
||||
if(!isset($request['collection_id'])) {
|
||||
|
@ -384,22 +385,22 @@ class TAINACAN_REST_Filters_Controller extends TAINACAN_REST_Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return WP_Error|WP_REST_Response
|
||||
* @return \WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function get_item( $request ) {
|
||||
$filter_id = $request['filter_id'];
|
||||
|
||||
$filter = $this->filter_repository->fetch($filter_id);
|
||||
|
||||
return new WP_REST_Response($this->prepare_item_for_response($filter, $request), 200);
|
||||
return new \WP_REST_Response($this->prepare_item_for_response($filter, $request), 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return bool|WP_Error
|
||||
* @return bool|\WP_Error
|
||||
*/
|
||||
public function get_item_permissions_check( $request ) {
|
||||
$filter = $this->filter_repository->fetch($request['filter_id']);
|
||||
|
@ -422,13 +423,13 @@ class TAINACAN_REST_Filters_Controller extends TAINACAN_REST_Controller {
|
|||
*/
|
||||
public function get_endpoint_args_for_item_schema( $method = null ) {
|
||||
$endpoint_args = [];
|
||||
if($method === WP_REST_Server::READABLE) {
|
||||
if($method === \WP_REST_Server::READABLE) {
|
||||
$endpoint_args['context'] = array(
|
||||
'type' => 'string',
|
||||
'default' => 'view',
|
||||
'items' => array( 'view, edit' )
|
||||
);
|
||||
} elseif ($method === WP_REST_Server::CREATABLE || $method === WP_REST_Server::EDITABLE) {
|
||||
} elseif ($method === \WP_REST_Server::CREATABLE || $method === \WP_REST_Server::EDITABLE) {
|
||||
$map = $this->filter_repository->get_map();
|
||||
|
||||
foreach ($map as $mapped => $value){
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan\API\EndPoints;
|
||||
|
||||
use \Tainacan\API\REST_Controller;
|
||||
use Tainacan\Entities;
|
||||
use Tainacan\Repositories;
|
||||
|
||||
class TAINACAN_REST_Item_Metadata_Controller extends TAINACAN_REST_Controller {
|
||||
class REST_Item_Metadata_Controller extends REST_Controller {
|
||||
private $field;
|
||||
private $item_metadata_repository;
|
||||
private $item_repository;
|
||||
|
@ -11,10 +14,8 @@ class TAINACAN_REST_Item_Metadata_Controller extends TAINACAN_REST_Controller {
|
|||
private $field_repository;
|
||||
|
||||
public function __construct() {
|
||||
$this->namespace = 'tainacan/v2';
|
||||
$this->rest_base = 'metadata';
|
||||
|
||||
add_action('rest_api_init', array($this, 'register_routes'));
|
||||
parent::__construct();
|
||||
add_action('init', array(&$this, 'init_objects'), 11);
|
||||
}
|
||||
|
||||
|
@ -42,17 +43,17 @@ class TAINACAN_REST_Item_Metadata_Controller extends TAINACAN_REST_Controller {
|
|||
register_rest_route($this->namespace, '/item/(?P<item_id>[\d]+)/' . $this->rest_base . '/(?P<metadata_id>[\d]+)',
|
||||
array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'methods' => \WP_REST_Server::EDITABLE,
|
||||
'callback' => array($this, 'update_item'),
|
||||
'permission_callback' => array($this, 'update_item_permissions_check'),
|
||||
'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE)
|
||||
'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE)
|
||||
)
|
||||
)
|
||||
);
|
||||
register_rest_route($this->namespace, '/item/(?P<item_id>[\d]+)/'. $this->rest_base,
|
||||
array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'methods' => \WP_REST_Server::READABLE,
|
||||
'callback' => array($this, 'get_items'),
|
||||
'permission_callback' => array($this, 'get_items_permissions_check'),
|
||||
'args' => $this->get_collection_params(),
|
||||
|
@ -62,7 +63,7 @@ class TAINACAN_REST_Item_Metadata_Controller extends TAINACAN_REST_Controller {
|
|||
register_rest_route($this->namespace, '/item/(?P<item_id>[\d]+)/'. $this->rest_base. '/(?P<metadata_id>[\d]+)',
|
||||
array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'methods' => \WP_REST_Server::READABLE,
|
||||
'callback' => array($this, 'get_item_field_value'),
|
||||
'permission_callback' => array($this, 'get_items_permissions_check'),
|
||||
)
|
||||
|
@ -71,9 +72,9 @@ class TAINACAN_REST_Item_Metadata_Controller extends TAINACAN_REST_Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return object|void|WP_Error
|
||||
* @return object|void|\WP_Error
|
||||
*/
|
||||
public function prepare_item_for_database( $request ) {
|
||||
$meta = json_decode($request[0]->get_body(), true);
|
||||
|
@ -90,9 +91,9 @@ class TAINACAN_REST_Item_Metadata_Controller extends TAINACAN_REST_Controller {
|
|||
|
||||
/**
|
||||
* @param mixed $item
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return array|WP_Error|WP_REST_Response
|
||||
* @return array|\WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function prepare_item_for_response( $item, $request ) {
|
||||
$item_arr = $item->__toArray();
|
||||
|
@ -105,9 +106,9 @@ class TAINACAN_REST_Item_Metadata_Controller extends TAINACAN_REST_Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return WP_Error|WP_REST_Response
|
||||
* @return \WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function get_items( $request ) {
|
||||
$item_id = $request['item_id'];
|
||||
|
@ -123,13 +124,13 @@ class TAINACAN_REST_Item_Metadata_Controller extends TAINACAN_REST_Controller {
|
|||
$prepared_item[$index-1]['field']['field_type_object'] = $this->prepare_item_for_response( $item_metadata->get_field()->get_field_type_object(), $request);
|
||||
}
|
||||
|
||||
return new WP_REST_Response(apply_filters('tainacan-rest-response', $prepared_item, $request), 200);
|
||||
return new \WP_REST_Response(apply_filters('tainacan-rest-response', $prepared_item, $request), 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return WP_Error|WP_REST_Response
|
||||
* @return \WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function get_item_field_value( $request ) {
|
||||
$item_id = $request['item_id'];
|
||||
|
@ -149,14 +150,14 @@ class TAINACAN_REST_Item_Metadata_Controller extends TAINACAN_REST_Controller {
|
|||
}
|
||||
}
|
||||
|
||||
return new WP_REST_Response(apply_filters('tainacan-rest-response', $prepared_item, $request), 200);
|
||||
return new \WP_REST_Response(apply_filters('tainacan-rest-response', $prepared_item, $request), 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return bool|WP_Error
|
||||
* @throws Exception
|
||||
* @return bool|\WP_Error
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function get_items_permissions_check( $request ) {
|
||||
$item = $this->item_repository->fetch($request['item_id']);
|
||||
|
@ -173,9 +174,9 @@ class TAINACAN_REST_Item_Metadata_Controller extends TAINACAN_REST_Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return WP_Error|WP_REST_Response
|
||||
* @return \WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function update_item( $request ) {
|
||||
$body = json_decode( $request->get_body(), true );
|
||||
|
@ -211,14 +212,14 @@ class TAINACAN_REST_Item_Metadata_Controller extends TAINACAN_REST_Controller {
|
|||
$prepared_item = $log->__toArray();
|
||||
}
|
||||
else {
|
||||
return new WP_REST_Response( [
|
||||
return new \WP_REST_Response( [
|
||||
'error_message' => __( 'Field do not accept suggestion.', 'tainacan' ),
|
||||
], 400 );
|
||||
}
|
||||
|
||||
return new WP_REST_Response( $prepared_item, 200 );
|
||||
return new \WP_REST_Response( $prepared_item, 200 );
|
||||
} else {
|
||||
return new WP_REST_Response( [
|
||||
return new \WP_REST_Response( [
|
||||
'error_message' => __( 'One or more values are invalid.', 'tainacan' ),
|
||||
'errors' => $item_metadata->get_errors(),
|
||||
'item_metadata' => $this->prepare_item_for_response($item_metadata, $request),
|
||||
|
@ -226,17 +227,17 @@ class TAINACAN_REST_Item_Metadata_Controller extends TAINACAN_REST_Controller {
|
|||
}
|
||||
}
|
||||
|
||||
return new WP_REST_Response([
|
||||
return new \WP_REST_Response([
|
||||
'error_message' => 'The body could not be empty',
|
||||
'body' => $body
|
||||
], 400);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return bool|WP_Error
|
||||
* @throws Exception
|
||||
* @return bool|\WP_Error
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function update_item_permissions_check( $request ) {
|
||||
if (isset($request['item_id'])) {
|
||||
|
@ -266,7 +267,7 @@ class TAINACAN_REST_Item_Metadata_Controller extends TAINACAN_REST_Controller {
|
|||
public function get_endpoint_args_for_item_schema( $method = null ) {
|
||||
$endpoint_args = [];
|
||||
|
||||
if ($method === WP_REST_Server::EDITABLE) {
|
||||
if ($method === \WP_REST_Server::EDITABLE) {
|
||||
$endpoint_args['values'] = [
|
||||
'type' => 'array/string/object/integer',
|
||||
'items' => [
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan\API\EndPoints;
|
||||
|
||||
use \Tainacan\API\REST_Controller;
|
||||
use Tainacan\Repositories;
|
||||
use Tainacan\Entities;
|
||||
|
||||
|
@ -8,21 +11,19 @@ use Tainacan\Entities;
|
|||
* @uses Tainacan\Repositories\
|
||||
* @uses Tainacan\Entities\
|
||||
*/
|
||||
class TAINACAN_REST_Items_Controller extends TAINACAN_REST_Controller {
|
||||
class REST_Items_Controller extends REST_Controller {
|
||||
private $items_repository;
|
||||
private $item;
|
||||
private $item_metadata;
|
||||
private $collections_repository;
|
||||
|
||||
/**
|
||||
* TAINACAN_REST_Items_Controller constructor.
|
||||
* REST_Items_Controller constructor.
|
||||
* Define the namespace, rest base and instantiate your attributes.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->namespace = 'tainacan/v2';
|
||||
$this->rest_base = 'items';
|
||||
|
||||
add_action('rest_api_init', array($this, 'register_routes'));
|
||||
parent::__construct();
|
||||
add_action('init', array(&$this, 'init_objects'), 11);
|
||||
}
|
||||
|
||||
|
@ -44,16 +45,16 @@ class TAINACAN_REST_Items_Controller extends TAINACAN_REST_Controller {
|
|||
$this->namespace, '/collection/(?P<collection_id>[\d]+)/' . $this->rest_base,
|
||||
array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'methods' => \WP_REST_Server::READABLE,
|
||||
'callback' => array($this, 'get_items'),
|
||||
'permission_callback' => array($this, 'get_items_permissions_check'),
|
||||
'args' => $this->get_collection_params(),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::CREATABLE,
|
||||
'methods' => \WP_REST_Server::CREATABLE,
|
||||
'callback' => array($this, 'create_item'),
|
||||
'permission_callback' => array($this, 'create_item_permissions_check'),
|
||||
'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE),
|
||||
'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
@ -61,19 +62,19 @@ class TAINACAN_REST_Items_Controller extends TAINACAN_REST_Controller {
|
|||
$this->namespace, '/' . $this->rest_base . '/(?P<item_id>[\d]+)',
|
||||
array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'methods' => \WP_REST_Server::READABLE,
|
||||
'callback' => array($this, 'get_item'),
|
||||
'permission_callback' => array($this, 'get_item_permissions_check'),
|
||||
'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::READABLE),
|
||||
'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::READABLE),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'methods' => \WP_REST_Server::EDITABLE,
|
||||
'callback' => array($this, 'update_item'),
|
||||
'permission_callback' => array($this, 'update_item_permissions_check'),
|
||||
'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE),
|
||||
'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::DELETABLE,
|
||||
'methods' => \WP_REST_Server::DELETABLE,
|
||||
'callback' => array($this, 'delete_item'),
|
||||
'permission_callback' => array($this, 'delete_item_permissions_check'),
|
||||
'args' => array(
|
||||
|
@ -113,9 +114,9 @@ class TAINACAN_REST_Items_Controller extends TAINACAN_REST_Controller {
|
|||
|
||||
/**
|
||||
* @param mixed $item
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return mixed|string|void|WP_Error|WP_REST_Response
|
||||
* @return mixed|string|void|\WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function prepare_item_for_response( $item, $request ) {
|
||||
if(!empty($item)){
|
||||
|
@ -139,9 +140,9 @@ class TAINACAN_REST_Items_Controller extends TAINACAN_REST_Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return WP_Error|WP_REST_Response
|
||||
* @return \WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function get_item( $request ) {
|
||||
$item_id = $request['item_id'];
|
||||
|
@ -150,13 +151,13 @@ class TAINACAN_REST_Items_Controller extends TAINACAN_REST_Controller {
|
|||
|
||||
$response = $this->prepare_item_for_response($item, $request);
|
||||
|
||||
return new WP_REST_Response(apply_filters('tainacan-rest-response', $response, $request), 200);
|
||||
return new \WP_REST_Response(apply_filters('tainacan-rest-response', $response, $request), 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return WP_Error|WP_REST_Response
|
||||
* @return \WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function get_items( $request ) {
|
||||
$args = $this->prepare_filters($request);
|
||||
|
@ -182,7 +183,7 @@ class TAINACAN_REST_Items_Controller extends TAINACAN_REST_Controller {
|
|||
$total_items = $items->found_posts;
|
||||
$max_pages = ceil($total_items / (int) $items->query_vars['posts_per_page']);
|
||||
|
||||
$rest_response = new WP_REST_Response($response, 200);
|
||||
$rest_response = new \WP_REST_Response($response, 200);
|
||||
|
||||
$rest_response->header('X-WP-Total', (int) $total_items);
|
||||
$rest_response->header('X-WP-TotalPages', (int) $max_pages);
|
||||
|
@ -191,9 +192,9 @@ class TAINACAN_REST_Items_Controller extends TAINACAN_REST_Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return bool|WP_Error
|
||||
* @return bool|\WP_Error
|
||||
*/
|
||||
public function get_item_permissions_check( $request ) {
|
||||
$item = $this->items_repository->fetch($request['item_id']);
|
||||
|
@ -210,9 +211,9 @@ class TAINACAN_REST_Items_Controller extends TAINACAN_REST_Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return bool|WP_Error
|
||||
* @return bool|\WP_Error
|
||||
*/
|
||||
public function get_items_permissions_check( $request ) {
|
||||
$collection = $this->collections_repository->fetch($request['collection_id']);
|
||||
|
@ -229,10 +230,10 @@ class TAINACAN_REST_Items_Controller extends TAINACAN_REST_Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return object|Entities\Item|WP_Error
|
||||
* @throws Exception
|
||||
* @return object|Entities\Item|\WP_Error
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function prepare_item_for_database( $request ) {
|
||||
|
||||
|
@ -251,17 +252,17 @@ class TAINACAN_REST_Items_Controller extends TAINACAN_REST_Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return WP_Error|WP_REST_Response
|
||||
* @throws Exception
|
||||
* @return \WP_Error|\WP_REST_Response
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function create_item( $request ) {
|
||||
$collection_id = $request['collection_id'];
|
||||
$item = json_decode($request->get_body(), true);
|
||||
|
||||
if(empty($item)){
|
||||
return new WP_REST_Response([
|
||||
return new \WP_REST_Response([
|
||||
'error_message' => __('Body can not be empty.', 'tainacan'),
|
||||
'item' => $item
|
||||
], 400);
|
||||
|
@ -270,17 +271,17 @@ class TAINACAN_REST_Items_Controller extends TAINACAN_REST_Controller {
|
|||
try {
|
||||
$this->prepare_item_for_database( [ $item, $collection_id ] );
|
||||
} catch (\Error $exception){
|
||||
return new WP_REST_Response($exception->getMessage(), 400);
|
||||
return new \WP_REST_Response($exception->getMessage(), 400);
|
||||
}
|
||||
|
||||
if($this->item->validate()) {
|
||||
$item = $this->items_repository->insert($this->item );
|
||||
|
||||
return new WP_REST_Response($this->prepare_item_for_response($item, $request), 201 );
|
||||
return new \WP_REST_Response($this->prepare_item_for_response($item, $request), 201 );
|
||||
}
|
||||
|
||||
|
||||
return new WP_REST_Response([
|
||||
return new \WP_REST_Response([
|
||||
'error_message' => __('One or more values are invalid.', 'tainacan'),
|
||||
'errors' => $this->item->get_errors(),
|
||||
'item' => $this->prepare_item_for_response($this->item, $request)
|
||||
|
@ -288,10 +289,10 @@ class TAINACAN_REST_Items_Controller extends TAINACAN_REST_Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return bool|WP_Error
|
||||
* @throws Exception
|
||||
* @return bool|\WP_Error
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function create_item_permissions_check( $request ) {
|
||||
$collection = $this->collections_repository->fetch($request['collection_id']);
|
||||
|
@ -304,9 +305,9 @@ class TAINACAN_REST_Items_Controller extends TAINACAN_REST_Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return WP_Error|WP_REST_Response
|
||||
* @return \WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function delete_item( $request ) {
|
||||
$item_id = $request['item_id'];
|
||||
|
@ -318,14 +319,14 @@ class TAINACAN_REST_Items_Controller extends TAINACAN_REST_Controller {
|
|||
|
||||
$prepared_item = $this->prepare_item_for_response($item, $request);
|
||||
|
||||
return new WP_REST_Response($prepared_item, 200);
|
||||
return new \WP_REST_Response($prepared_item, 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return bool|WP_Error
|
||||
* @throws Exception
|
||||
* @return bool|\WP_Error
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function delete_item_permissions_check( $request ) {
|
||||
$item = $this->items_repository->fetch($request['item_id']);
|
||||
|
@ -338,9 +339,9 @@ class TAINACAN_REST_Items_Controller extends TAINACAN_REST_Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return WP_Error|WP_REST_Response
|
||||
* @return \WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function update_item( $request ) {
|
||||
$item_id = $request['item_id'];
|
||||
|
@ -362,33 +363,33 @@ class TAINACAN_REST_Items_Controller extends TAINACAN_REST_Controller {
|
|||
if($prepared_item->validate()){
|
||||
$updated_item = $this->items_repository->update($prepared_item);
|
||||
|
||||
return new WP_REST_Response($this->prepare_item_for_response($updated_item, $request), 200);
|
||||
return new \WP_REST_Response($this->prepare_item_for_response($updated_item, $request), 200);
|
||||
}
|
||||
|
||||
return new WP_REST_Response([
|
||||
return new \WP_REST_Response([
|
||||
'error_message' => __('One or more values are invalid.', 'tainacan'),
|
||||
'errors' => $prepared_item->get_errors(),
|
||||
'item' => $this->prepare_item_for_response($prepared_item, $request)
|
||||
], 400);
|
||||
}
|
||||
|
||||
return new WP_REST_Response([
|
||||
return new \WP_REST_Response([
|
||||
'error_message' => __('Item with that ID not found', 'tainacan' ),
|
||||
'item_id' => $item_id
|
||||
], 400);
|
||||
}
|
||||
|
||||
return new WP_REST_Response([
|
||||
return new \WP_REST_Response([
|
||||
'error_message' => __('The body could not be empty', 'tainacan'),
|
||||
'body' => $body
|
||||
], 400);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return bool|WP_Error
|
||||
* @throws Exception
|
||||
* @return bool|\WP_Error
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function update_item_permissions_check( $request ) {
|
||||
$item = $this->items_repository->fetch($request['item_id']);
|
||||
|
@ -409,7 +410,7 @@ class TAINACAN_REST_Items_Controller extends TAINACAN_REST_Controller {
|
|||
public function get_endpoint_args_for_item_schema( $method = null ){
|
||||
$endpoint_args = [];
|
||||
|
||||
if($method === WP_REST_Server::READABLE) {
|
||||
if($method === \WP_REST_Server::READABLE) {
|
||||
$endpoint_args['fetch_only'] = array(
|
||||
'type' => 'string/array',
|
||||
'description' => __( 'Fetch only specific attribute. The specifics attributes are the same in schema.' ),
|
||||
|
@ -420,7 +421,7 @@ class TAINACAN_REST_Items_Controller extends TAINACAN_REST_Controller {
|
|||
'default' => 'view',
|
||||
'items' => array( 'view, edit' )
|
||||
);
|
||||
} elseif ($method === WP_REST_Server::CREATABLE || $method === WP_REST_Server::EDITABLE) {
|
||||
} elseif ($method === \WP_REST_Server::CREATABLE || $method === \WP_REST_Server::EDITABLE) {
|
||||
$map = $this->items_repository->get_map();
|
||||
|
||||
foreach ($map as $mapped => $value){
|
||||
|
|
|
@ -1,21 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan\API\EndPoints;
|
||||
|
||||
use \Tainacan\API\REST_Controller;
|
||||
use Tainacan\Entities;
|
||||
use Tainacan\Repositories;
|
||||
use Tainacan\Repositories\Repository;
|
||||
|
||||
class TAINACAN_REST_Logs_Controller extends TAINACAN_REST_Controller {
|
||||
class REST_Logs_Controller extends REST_Controller {
|
||||
private $logs_repository;
|
||||
private $log;
|
||||
|
||||
/**
|
||||
* TAINACAN_REST_Logs_Controller constructor.
|
||||
* REST_Logs_Controller constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->namespace = 'tainacan/v2';
|
||||
$this->rest_base = 'logs';
|
||||
|
||||
add_action('rest_api_init', array($this, 'register_routes'));
|
||||
parent::__construct();
|
||||
add_action('init', array($this, 'init_objects'));
|
||||
}
|
||||
|
||||
|
@ -28,7 +29,7 @@ class TAINACAN_REST_Logs_Controller extends TAINACAN_REST_Controller {
|
|||
register_rest_route($this->namespace, '/' . $this->rest_base . '/',
|
||||
array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'methods' => \WP_REST_Server::READABLE,
|
||||
'callback' => array($this, 'get_items'),
|
||||
'permission_callback' => array($this, 'get_items_permissions_check'),
|
||||
'args' => $this->get_collection_params()
|
||||
|
@ -38,17 +39,17 @@ class TAINACAN_REST_Logs_Controller extends TAINACAN_REST_Controller {
|
|||
register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<log_id>[\d]+)',
|
||||
array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'methods' => \WP_REST_Server::READABLE,
|
||||
'callback' => array($this, 'get_item'),
|
||||
'permission_callback' => array($this, 'get_item_permissions_check'),
|
||||
'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::READABLE)
|
||||
'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::READABLE)
|
||||
)
|
||||
)
|
||||
);
|
||||
register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<log_id>[\d]+)/approve',
|
||||
array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'methods' => \WP_REST_Server::EDITABLE,
|
||||
'callback' => array($this, 'approve_item'),
|
||||
'permission_callback' => array($this, 'approve_item_permissions_check'),
|
||||
)
|
||||
|
@ -58,9 +59,9 @@ class TAINACAN_REST_Logs_Controller extends TAINACAN_REST_Controller {
|
|||
|
||||
/**
|
||||
* @param mixed $item
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return array|WP_Error|WP_REST_Response
|
||||
* @return array|\WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function prepare_item_for_response( $item, $request ) {
|
||||
if(!empty($item)){
|
||||
|
@ -68,11 +69,11 @@ class TAINACAN_REST_Logs_Controller extends TAINACAN_REST_Controller {
|
|||
if(!isset($request['fetch_only'])) {
|
||||
$item_array = $item->__toArray();
|
||||
|
||||
if ( $request['context'] === 'edit' ) {
|
||||
$log_diff = $item->diff();
|
||||
|
||||
$item_array['log_diff'] = $log_diff;
|
||||
}
|
||||
// if ( $request['context'] === 'edit' ) {
|
||||
// $log_diff = $item->diff();
|
||||
//
|
||||
// $item_array['log_diff'] = $log_diff;
|
||||
// }
|
||||
|
||||
unset($item_array['value']);
|
||||
unset($item_array['old_value']);
|
||||
|
@ -89,10 +90,10 @@ class TAINACAN_REST_Logs_Controller extends TAINACAN_REST_Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return WP_Error|WP_REST_Response
|
||||
* @throws Exception
|
||||
* @return \WP_Error|\WP_REST_Response
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function get_items( $request ) {
|
||||
$args = $this->prepare_filters($request);
|
||||
|
@ -115,7 +116,7 @@ class TAINACAN_REST_Logs_Controller extends TAINACAN_REST_Controller {
|
|||
$total_logs = $logs->found_posts;
|
||||
$max_pages = ceil($total_logs / (int) $logs->query_vars['posts_per_page']);
|
||||
|
||||
$rest_response = new WP_REST_Response($response, 200);
|
||||
$rest_response = new \WP_REST_Response($response, 200);
|
||||
|
||||
$rest_response->header('X-WP-Total', (int) $total_logs);
|
||||
$rest_response->header('X-WP-TotalPages', (int) $max_pages);
|
||||
|
@ -124,18 +125,18 @@ class TAINACAN_REST_Logs_Controller extends TAINACAN_REST_Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return bool|WP_Error
|
||||
* @return bool|\WP_Error
|
||||
*/
|
||||
public function get_items_permissions_check( $request ) {
|
||||
return $this->logs_repository->can_read($this->log);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return WP_Error|WP_REST_Response
|
||||
* @return \WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function get_item( $request ) {
|
||||
$log_id = $request['log_id'];
|
||||
|
@ -144,13 +145,13 @@ class TAINACAN_REST_Logs_Controller extends TAINACAN_REST_Controller {
|
|||
|
||||
$prepared_log = $this->prepare_item_for_response( $log, $request );
|
||||
|
||||
return new WP_REST_Response($prepared_log, 200);
|
||||
return new \WP_REST_Response($prepared_log, 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return bool|WP_Error
|
||||
* @return bool|\WP_Error
|
||||
*/
|
||||
public function get_item_permissions_check( $request ) {
|
||||
$log = $this->logs_repository->fetch($request['log_id']);
|
||||
|
@ -167,9 +168,9 @@ class TAINACAN_REST_Logs_Controller extends TAINACAN_REST_Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return bool|WP_Error
|
||||
* @return bool|\WP_Error
|
||||
*/
|
||||
public function approve_item_permissions_check( $request ) {
|
||||
$log = $this->logs_repository->fetch($request['log_id']);
|
||||
|
@ -188,7 +189,7 @@ class TAINACAN_REST_Logs_Controller extends TAINACAN_REST_Controller {
|
|||
}
|
||||
}
|
||||
|
||||
return new WP_Error();
|
||||
return new \WP_Error();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -197,9 +198,9 @@ class TAINACAN_REST_Logs_Controller extends TAINACAN_REST_Controller {
|
|||
|
||||
/**
|
||||
* approve a logged modification
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return WP_Error|WP_REST_Response
|
||||
* @return \WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function approve_item($request) {
|
||||
$log = $this->logs_repository->fetch($request['log_id']);
|
||||
|
@ -208,7 +209,7 @@ class TAINACAN_REST_Logs_Controller extends TAINACAN_REST_Controller {
|
|||
$entity = $log->approve();
|
||||
$prepared_entity = $this->prepare_item_for_response( $entity, $request );
|
||||
|
||||
return new WP_REST_Response($prepared_entity, 200);
|
||||
return new \WP_REST_Response($prepared_entity, 200);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -219,7 +220,7 @@ class TAINACAN_REST_Logs_Controller extends TAINACAN_REST_Controller {
|
|||
*/
|
||||
public function get_endpoint_args_for_item_schema( $method = null ) {
|
||||
$endpoint_args = [];
|
||||
if($method === WP_REST_Server::READABLE) {
|
||||
if($method === \WP_REST_Server::READABLE) {
|
||||
$endpoint_args['context'] = array(
|
||||
'type' => 'string',
|
||||
'default' => 'view',
|
||||
|
|
|
@ -1,20 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan\API\EndPoints;
|
||||
|
||||
use \Tainacan\API\REST_Controller;
|
||||
use Tainacan\Entities;
|
||||
use Tainacan\Repositories;
|
||||
|
||||
class TAINACAN_REST_Taxonomies_Controller extends TAINACAN_REST_Controller {
|
||||
class REST_Taxonomies_Controller extends REST_Controller {
|
||||
private $taxonomy;
|
||||
private $taxonomy_repository;
|
||||
|
||||
/**
|
||||
* TAINACAN_REST_Taxonomies_Controller constructor.
|
||||
* REST_Taxonomies_Controller constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->namespace = 'tainacan/v2';
|
||||
$this->rest_base = 'taxonomies';
|
||||
|
||||
add_action('rest_api_init', array($this, 'register_routes'));
|
||||
parent::__construct();
|
||||
add_action('init', array(&$this, 'init_objects'), 11);
|
||||
}
|
||||
|
||||
|
@ -31,16 +32,16 @@ class TAINACAN_REST_Taxonomies_Controller extends TAINACAN_REST_Controller {
|
|||
$this->namespace, '/' . $this->rest_base,
|
||||
array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'methods' => \WP_REST_Server::READABLE,
|
||||
'callback' => array($this, 'get_items'),
|
||||
'permission_callback' => array($this, 'get_items_permissions_check'),
|
||||
'args' => $this->get_collection_params()
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::CREATABLE,
|
||||
'methods' => \WP_REST_Server::CREATABLE,
|
||||
'callback' => array($this, 'create_item'),
|
||||
'permission_callback' => array($this, 'create_item_permissions_check'),
|
||||
'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE)
|
||||
'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
@ -48,13 +49,13 @@ class TAINACAN_REST_Taxonomies_Controller extends TAINACAN_REST_Controller {
|
|||
$this->namespace, '/' . $this->rest_base . '/(?P<taxonomy_id>[\d]+)',
|
||||
array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'methods' => \WP_REST_Server::READABLE,
|
||||
'callback' => array($this, 'get_item'),
|
||||
'permission_callback' => array($this, 'get_item_permissions_check'),
|
||||
'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::READABLE)
|
||||
'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::READABLE)
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::DELETABLE,
|
||||
'methods' => \WP_REST_Server::DELETABLE,
|
||||
'callback' => array($this, 'delete_item'),
|
||||
'permission_callback' => array($this, 'delete_item_permissions_check'),
|
||||
'args' => array(
|
||||
|
@ -65,10 +66,10 @@ class TAINACAN_REST_Taxonomies_Controller extends TAINACAN_REST_Controller {
|
|||
)
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'methods' => \WP_REST_Server::EDITABLE,
|
||||
'callback' => array($this, 'update_item'),
|
||||
'permission_callback' => array($this, 'update_item_permissions_check'),
|
||||
'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE)
|
||||
'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
@ -76,10 +77,10 @@ class TAINACAN_REST_Taxonomies_Controller extends TAINACAN_REST_Controller {
|
|||
$this->namespace, '/' . $this->rest_base . '/(?P<taxonomy_id>[\d]+)/collection/(?P<collection_id>[\d]+)',
|
||||
array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'methods' => \WP_REST_Server::EDITABLE,
|
||||
'callback' => array($this, 'update_item'),
|
||||
'permission_callback' => array($this, 'update_item_permissions_check'),
|
||||
'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE)
|
||||
'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
@ -87,9 +88,9 @@ class TAINACAN_REST_Taxonomies_Controller extends TAINACAN_REST_Controller {
|
|||
|
||||
/**
|
||||
* @param mixed $item
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return array|WP_Error|WP_REST_Response
|
||||
* @return array|\WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function prepare_item_for_response( $item, $request ) {
|
||||
if(!empty($item)) {
|
||||
|
@ -112,9 +113,9 @@ class TAINACAN_REST_Taxonomies_Controller extends TAINACAN_REST_Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return object|void|WP_Error
|
||||
* @return object|void|\WP_Error
|
||||
*/
|
||||
public function prepare_item_for_database( $request ) {
|
||||
foreach ($request as $key => $value){
|
||||
|
@ -124,9 +125,9 @@ class TAINACAN_REST_Taxonomies_Controller extends TAINACAN_REST_Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return WP_Error|WP_REST_Response
|
||||
* @return \WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function get_item( $request ) {
|
||||
$taxonomy_id = $request['taxonomy_id'];
|
||||
|
@ -135,13 +136,13 @@ class TAINACAN_REST_Taxonomies_Controller extends TAINACAN_REST_Controller {
|
|||
|
||||
$taxonomy_prepared = $this->prepare_item_for_response($taxonomy, $request);
|
||||
|
||||
return new WP_REST_Response($taxonomy_prepared, 200);
|
||||
return new \WP_REST_Response($taxonomy_prepared, 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return bool|WP_Error
|
||||
* @return bool|\WP_Error
|
||||
*/
|
||||
public function get_item_permissions_check( $request ) {
|
||||
$taxonomy = $this->taxonomy_repository->fetch($request['taxonomy_id']);
|
||||
|
@ -158,9 +159,9 @@ class TAINACAN_REST_Taxonomies_Controller extends TAINACAN_REST_Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return WP_Error|WP_REST_Response
|
||||
* @return \WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function delete_item( $request ) {
|
||||
$taxonomy_id = $request['taxonomy_id'];
|
||||
|
@ -175,30 +176,30 @@ class TAINACAN_REST_Taxonomies_Controller extends TAINACAN_REST_Controller {
|
|||
|
||||
$deleted = $this->taxonomy_repository->delete( $args );
|
||||
|
||||
if($deleted instanceof WP_Error) {
|
||||
return new WP_REST_Response( $deleted->get_error_message(), 400 );
|
||||
if($deleted instanceof \WP_Error) {
|
||||
return new \WP_REST_Response( $deleted->get_error_message(), 400 );
|
||||
} elseif(!$deleted){
|
||||
return new WP_REST_Response( [
|
||||
return new \WP_REST_Response( [
|
||||
'error_message' => __('Failure on deleted.', 'tainacan'),
|
||||
'deleted' => $deleted
|
||||
], 400 );
|
||||
} elseif (!$deleted){
|
||||
return new WP_REST_Response($deleted, 400);
|
||||
return new \WP_REST_Response($deleted, 400);
|
||||
}
|
||||
|
||||
return new WP_REST_Response($this->prepare_item_for_response($deleted, $request), 200);
|
||||
return new \WP_REST_Response($this->prepare_item_for_response($deleted, $request), 200);
|
||||
}
|
||||
|
||||
return new WP_REST_Response([
|
||||
return new \WP_REST_Response([
|
||||
'error_message' => __('Taxonomy with this id ('. $taxonomy_id .') not found.', 'tainacan'),
|
||||
'taxonomy' => $this->prepare_item_for_response($taxonomy, $request)
|
||||
], 400);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return bool|WP_Error
|
||||
* @return bool|\WP_Error
|
||||
*/
|
||||
public function delete_item_permissions_check( $request ) {
|
||||
$taxonomy = $this->taxonomy_repository->fetch($request['taxonomy_id']);
|
||||
|
@ -212,9 +213,9 @@ class TAINACAN_REST_Taxonomies_Controller extends TAINACAN_REST_Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return WP_Error|WP_REST_Response
|
||||
* @return \WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function get_items( $request ) {
|
||||
$args = $this->prepare_filters($request);
|
||||
|
@ -237,7 +238,7 @@ class TAINACAN_REST_Taxonomies_Controller extends TAINACAN_REST_Controller {
|
|||
$total_taxonomies = (int) $taxonomies->found_posts;
|
||||
$max_pages = ceil($total_taxonomies / (int) $taxonomies->query_vars['posts_per_page']);
|
||||
|
||||
$rest_response = new WP_REST_Response($response, 200);
|
||||
$rest_response = new \WP_REST_Response($response, 200);
|
||||
|
||||
$rest_response->header('X-WP-Total', $total_taxonomies);
|
||||
$rest_response->header('X-WP-TotalPages', (int) $max_pages);
|
||||
|
@ -246,9 +247,9 @@ class TAINACAN_REST_Taxonomies_Controller extends TAINACAN_REST_Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return bool|WP_Error
|
||||
* @return bool|\WP_Error
|
||||
*/
|
||||
public function get_items_permissions_check( $request ) {
|
||||
if('edit' === $request['context'] && !$this->taxonomy_repository->can_read($this->taxonomy)) {
|
||||
|
@ -259,9 +260,9 @@ class TAINACAN_REST_Taxonomies_Controller extends TAINACAN_REST_Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return WP_Error|WP_REST_Response
|
||||
* @return \WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function create_item( $request ) {
|
||||
$body = json_decode($request->get_body(), true);
|
||||
|
@ -272,16 +273,16 @@ class TAINACAN_REST_Taxonomies_Controller extends TAINACAN_REST_Controller {
|
|||
if($this->taxonomy->validate()){
|
||||
$taxonomy = $this->taxonomy_repository->insert($this->taxonomy);
|
||||
|
||||
return new WP_REST_Response($this->prepare_item_for_response($taxonomy, $request), 201);
|
||||
return new \WP_REST_Response($this->prepare_item_for_response($taxonomy, $request), 201);
|
||||
} else {
|
||||
return new WP_REST_Response([
|
||||
return new \WP_REST_Response([
|
||||
'error_message' => __('One or more values are invalid.', 'tainacan'),
|
||||
'errors' => $this->taxonomy->get_errors(),
|
||||
'item_metadata' => $this->prepare_item_for_response($this->taxonomy, $request),
|
||||
], 400);
|
||||
}
|
||||
} else {
|
||||
return new WP_REST_Response([
|
||||
return new \WP_REST_Response([
|
||||
'error_message' => __('Body can not be empty.', 'tainacan'),
|
||||
'body' => $body
|
||||
], 400);
|
||||
|
@ -289,18 +290,18 @@ class TAINACAN_REST_Taxonomies_Controller extends TAINACAN_REST_Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return bool|WP_Error
|
||||
* @return bool|\WP_Error
|
||||
*/
|
||||
public function create_item_permissions_check( $request ) {
|
||||
return $this->taxonomy_repository->can_edit($this->taxonomy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return WP_Error|WP_REST_Response
|
||||
* @return \WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function update_item( $request ) {
|
||||
$taxonomy_id = $request['taxonomy_id'];
|
||||
|
@ -328,32 +329,32 @@ class TAINACAN_REST_Taxonomies_Controller extends TAINACAN_REST_Controller {
|
|||
if($prepared_taxonomy->validate()){
|
||||
$updated_taxonomy = $this->taxonomy_repository->update($prepared_taxonomy);
|
||||
|
||||
return new WP_REST_Response($this->prepare_item_for_response($updated_taxonomy, $request), 200);
|
||||
return new \WP_REST_Response($this->prepare_item_for_response($updated_taxonomy, $request), 200);
|
||||
}
|
||||
|
||||
return new WP_REST_Response([
|
||||
return new \WP_REST_Response([
|
||||
'error_message' => __('One or more values are invalid.', 'tainacan'),
|
||||
'errors' => $prepared_taxonomy->get_errors(),
|
||||
'taxonomy' => $this->prepare_item_for_response($prepared_taxonomy, $request)
|
||||
], 400);
|
||||
}
|
||||
|
||||
return new WP_REST_Response([
|
||||
return new \WP_REST_Response([
|
||||
'error_message' => __('Taxonomy with that ID not found', 'tainacan' ),
|
||||
'taxonomy_id' => $taxonomy_id
|
||||
], 400);
|
||||
}
|
||||
|
||||
return new WP_REST_Response([
|
||||
return new \WP_REST_Response([
|
||||
'error_message' => __('The body could not be empty', 'tainacan'),
|
||||
'body' => $body
|
||||
], 400);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return bool|WP_Error
|
||||
* @return bool|\WP_Error
|
||||
*/
|
||||
public function update_item_permissions_check( $request ) {
|
||||
$taxonomy = $this->taxonomy_repository->fetch($request['taxonomy_id']);
|
||||
|
@ -372,7 +373,7 @@ class TAINACAN_REST_Taxonomies_Controller extends TAINACAN_REST_Controller {
|
|||
*/
|
||||
public function get_endpoint_args_for_item_schema( $method = null ) {
|
||||
$endpoint_args = [];
|
||||
if($method === WP_REST_Server::READABLE) {
|
||||
if($method === \WP_REST_Server::READABLE) {
|
||||
$endpoint_args['fetch_only'] = array(
|
||||
'type' => 'string/array',
|
||||
'description' => __( 'Fetch only specific attribute. The specifics attributes are the same in schema.' ),
|
||||
|
@ -383,7 +384,7 @@ class TAINACAN_REST_Taxonomies_Controller extends TAINACAN_REST_Controller {
|
|||
'default' => 'view',
|
||||
'items' => array( 'view, edit' )
|
||||
);
|
||||
} elseif ($method === WP_REST_Server::CREATABLE || $method === WP_REST_Server::EDITABLE) {
|
||||
} elseif ($method === \WP_REST_Server::CREATABLE || $method === \WP_REST_Server::EDITABLE) {
|
||||
$map = $this->taxonomy_repository->get_map();
|
||||
|
||||
foreach ($map as $mapped => $value){
|
||||
|
|
|
@ -1,22 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan\API\EndPoints;
|
||||
|
||||
use \Tainacan\API\REST_Controller;
|
||||
use Tainacan\Entities;
|
||||
use Tainacan\Repositories;
|
||||
|
||||
class TAINACAN_REST_Terms_Controller extends TAINACAN_REST_Controller {
|
||||
class REST_Terms_Controller extends REST_Controller {
|
||||
private $term;
|
||||
private $terms_repository;
|
||||
private $taxonomy;
|
||||
private $taxonomy_repository;
|
||||
|
||||
/**
|
||||
* TAINACAN_REST_Terms_Controller constructor.
|
||||
* REST_Terms_Controller constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->namespace = 'tainacan/v2';
|
||||
$this->rest_base = 'terms';
|
||||
|
||||
add_action('rest_api_init', array($this, 'register_routes'));
|
||||
parent::__construct();
|
||||
add_action('init', array(&$this, 'init_objects'), 11);
|
||||
}
|
||||
|
||||
|
@ -34,13 +35,13 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_REST_Controller {
|
|||
register_rest_route($this->namespace, '/taxonomy/(?P<taxonomy_id>[\d]+)/' . $this->rest_base,
|
||||
array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::CREATABLE,
|
||||
'methods' => \WP_REST_Server::CREATABLE,
|
||||
'callback' => array($this, 'create_item'),
|
||||
'permission_callback' => array($this, 'create_item_permissions_check'),
|
||||
'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE)
|
||||
'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE)
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'methods' => \WP_REST_Server::READABLE,
|
||||
'callback' => array($this, 'get_items'),
|
||||
'permission_callback' => array($this, 'get_items_permissions_check'),
|
||||
'args' => $this->get_collection_params()
|
||||
|
@ -50,7 +51,7 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_REST_Controller {
|
|||
register_rest_route($this->namespace,'/taxonomy/(?P<taxonomy_id>[\d]+)/'. $this->rest_base . '/(?P<term_id>[\d]+)' ,
|
||||
array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::DELETABLE,
|
||||
'methods' => \WP_REST_Server::DELETABLE,
|
||||
'callback' => array($this, 'delete_item'),
|
||||
'permission_callback' => array($this, 'delete_item_permissions_check'),
|
||||
'args' => [
|
||||
|
@ -60,25 +61,25 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_REST_Controller {
|
|||
]
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'methods' => \WP_REST_Server::EDITABLE,
|
||||
'callback' => array($this, 'update_item'),
|
||||
'permission_callback' => array($this, 'update_item_permissions_check'),
|
||||
'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE)
|
||||
'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE)
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'methods' => \WP_REST_Server::READABLE,
|
||||
'callback' => array($this, 'get_item'),
|
||||
'permission_callback' => array($this, 'get_item_permissions_check'),
|
||||
'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::READABLE)
|
||||
'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::READABLE)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $to_prepare
|
||||
* @param \WP_REST_Request $to_prepare
|
||||
*
|
||||
* @return object|void|WP_Error
|
||||
* @return object|void|\WP_Error
|
||||
*/
|
||||
public function prepare_item_for_database( $to_prepare ) {
|
||||
$attributes = $to_prepare[0];
|
||||
|
@ -98,9 +99,9 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_REST_Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return WP_Error|WP_REST_Response
|
||||
* @return \WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function create_item( $request ) {
|
||||
$taxonomy_id = $request['taxonomy_id'];
|
||||
|
@ -116,25 +117,25 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_REST_Controller {
|
|||
if($this->term->validate()){
|
||||
$term_inserted = $this->terms_repository->insert($this->term);
|
||||
|
||||
return new WP_REST_Response($this->prepare_item_for_response($term_inserted, $request), 200);
|
||||
return new \WP_REST_Response($this->prepare_item_for_response($term_inserted, $request), 200);
|
||||
} else {
|
||||
return new WP_REST_Response([
|
||||
return new \WP_REST_Response([
|
||||
'error_message' => 'One or more attributes are invalid.',
|
||||
'errors' => $this->term->get_errors(),
|
||||
], 400);
|
||||
}
|
||||
}
|
||||
|
||||
return new WP_REST_Response([
|
||||
return new \WP_REST_Response([
|
||||
'error_message' => 'The body couldn\'t be empty.',
|
||||
'body' => $body,
|
||||
], 400);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return bool|WP_Error
|
||||
* @return bool|\WP_Error
|
||||
*/
|
||||
public function create_item_permissions_check( $request ) {
|
||||
$taxonomy = $this->taxonomy_repository->fetch($request['taxonomy_id']);
|
||||
|
@ -147,9 +148,9 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_REST_Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return WP_Error|WP_REST_Response
|
||||
* @return \WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function delete_item( $request ) {
|
||||
$term_id = $request['term_id'];
|
||||
|
@ -158,7 +159,7 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_REST_Controller {
|
|||
$taxonomy_name = $this->taxonomy_repository->fetch( $taxonomy_id )->get_db_identifier();
|
||||
|
||||
if(!$taxonomy_name){
|
||||
return new WP_REST_Response([
|
||||
return new \WP_REST_Response([
|
||||
'error_message' => 'The ID of taxonomy may be incorrect.'
|
||||
]);
|
||||
}
|
||||
|
@ -167,13 +168,13 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_REST_Controller {
|
|||
|
||||
$is_deleted = $this->terms_repository->delete($args);
|
||||
|
||||
return new WP_REST_Response($is_deleted, 200);
|
||||
return new \WP_REST_Response($is_deleted, 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return bool|WP_Error
|
||||
* @return bool|\WP_Error
|
||||
*/
|
||||
public function delete_item_permissions_check( $request ) {
|
||||
$taxonomy = $this->taxonomy_repository->fetch($request['taxonomy_id']);
|
||||
|
@ -186,9 +187,9 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_REST_Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return WP_Error|WP_REST_Response
|
||||
* @return \WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function update_item( $request ) {
|
||||
$term_id = $request['term_id'];
|
||||
|
@ -214,33 +215,33 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_REST_Controller {
|
|||
if($prepared_term->validate()){
|
||||
$updated_term = $this->terms_repository->update($prepared_term, $tax_name);
|
||||
|
||||
return new WP_REST_Response($this->prepare_item_for_response($updated_term, $request), 200);
|
||||
return new \WP_REST_Response($this->prepare_item_for_response($updated_term, $request), 200);
|
||||
}
|
||||
|
||||
return new WP_REST_Response([
|
||||
return new \WP_REST_Response([
|
||||
'error_message' => __('One or more values are invalid.', 'tainacan'),
|
||||
'errors' => $prepared_term->get_errors(),
|
||||
'term' => $this->prepare_item_for_response($prepared_term, $request)
|
||||
], 400);
|
||||
}
|
||||
|
||||
return new WP_REST_Response([
|
||||
return new \WP_REST_Response([
|
||||
'error_message' => __('Term or Taxonomy with that IDs not found', 'tainacan' ),
|
||||
'term_id' => $term_id,
|
||||
'taxonomy_id' => $taxonomy_id
|
||||
], 400);
|
||||
}
|
||||
|
||||
return new WP_REST_Response([
|
||||
return new \WP_REST_Response([
|
||||
'error_message' => __('The body could not be empty', 'tainacan'),
|
||||
'body' => $body
|
||||
], 400);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return bool|WP_Error
|
||||
* @return bool|\WP_Error
|
||||
*/
|
||||
public function update_item_permissions_check( $request ) {
|
||||
$taxonomy = $this->taxonomy_repository->fetch($request['taxonomy_id']);
|
||||
|
@ -254,9 +255,9 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_REST_Controller {
|
|||
|
||||
/**
|
||||
* @param mixed $item
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return array|mixed|WP_Error|WP_REST_Response
|
||||
* @return array|mixed|\WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function prepare_item_for_response( $item, $request ) {
|
||||
if(!empty($item)){
|
||||
|
@ -279,9 +280,9 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_REST_Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return WP_Error|WP_REST_Response
|
||||
* @return \WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function get_items( $request ) {
|
||||
$taxonomy_id = $request['taxonomy_id'];
|
||||
|
@ -297,13 +298,13 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_REST_Controller {
|
|||
array_push($response, $this->prepare_item_for_response( $term, $request ));
|
||||
}
|
||||
|
||||
return new WP_REST_Response($response, 200);
|
||||
return new \WP_REST_Response($response, 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return bool|WP_Error
|
||||
* @return bool|\WP_Error
|
||||
*/
|
||||
public function get_items_permissions_check( $request ) {
|
||||
$taxonomy = $this->taxonomy_repository->fetch($request['taxonomy_id']);
|
||||
|
@ -320,9 +321,9 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_REST_Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return WP_Error|WP_REST_Response
|
||||
* @return \WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function get_item( $request ) {
|
||||
$term_id = $request['term_id'];
|
||||
|
@ -332,13 +333,13 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_REST_Controller {
|
|||
|
||||
$term = $this->terms_repository->fetch($term_id, $taxonomy);
|
||||
|
||||
return new WP_REST_Response($this->prepare_item_for_response($term, $request), 200);
|
||||
return new \WP_REST_Response($this->prepare_item_for_response($term, $request), 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return bool|WP_Error
|
||||
* @return bool|\WP_Error
|
||||
*/
|
||||
public function get_item_permissions_check( $request ) {
|
||||
$taxonomy = $this->taxonomy_repository->fetch($request['taxonomy_id']);
|
||||
|
@ -361,13 +362,13 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_REST_Controller {
|
|||
*/
|
||||
public function get_endpoint_args_for_item_schema( $method = null ) {
|
||||
$endpoint_args = [];
|
||||
if($method === WP_REST_Server::READABLE) {
|
||||
if($method === \WP_REST_Server::READABLE) {
|
||||
$endpoint_args['context'] = array(
|
||||
'type' => 'string',
|
||||
'default' => 'view',
|
||||
'items' => array( 'view, edit' )
|
||||
);
|
||||
} elseif ($method === WP_REST_Server::CREATABLE || $method === WP_REST_Server::EDITABLE) {
|
||||
} elseif ($method === \WP_REST_Server::CREATABLE || $method === \WP_REST_Server::EDITABLE) {
|
||||
$map = $this->terms_repository->get_map();
|
||||
|
||||
foreach ($map as $mapped => $value){
|
||||
|
|
|
@ -1,16 +1,18 @@
|
|||
<?php
|
||||
|
||||
$rest_controller = new TAINACAN_REST_Controller();
|
||||
$rest_collections_controller = new TAINACAN_REST_Collections_Controller();
|
||||
$rest_items_controller = new TAINACAN_REST_Items_Controller();
|
||||
$rest_fields_controller = new TAINACAN_REST_Fields_Controller();
|
||||
$rest_taxonomies_controller = new TAINACAN_REST_Taxonomies_Controller();
|
||||
$rest_terms_controller = new TAINACAN_REST_Terms_Controller();
|
||||
$rest_filters_controller = new TAINACAN_REST_Filters_Controller();
|
||||
$rest_item_metadata_controller = new TAINACAN_REST_Item_Metadata_Controller();
|
||||
$rest_logs_controller = new TAINACAN_REST_Logs_Controller();
|
||||
$rest_field_types_controller = new TAINACAN_REST_Field_Types_Controller();
|
||||
$rest_filter_types_controller = new TAINACAN_REST_Filter_Types_Controller();
|
||||
const TAINACAN_REST_NAMESPACE = 'tainacan/v2';
|
||||
|
||||
//$rest_controller = new \Tainacan\API\REST_Controller();
|
||||
$rest_collections_controller = new \Tainacan\API\EndPoints\REST_Collections_Controller();
|
||||
$rest_items_controller = new \Tainacan\API\EndPoints\REST_Items_Controller();
|
||||
$rest_fields_controller = new \Tainacan\API\EndPoints\REST_Fields_Controller();
|
||||
$rest_taxonomies_controller = new \Tainacan\API\EndPoints\REST_Taxonomies_Controller();
|
||||
$rest_terms_controller = new \Tainacan\API\EndPoints\REST_Terms_Controller();
|
||||
$rest_filters_controller = new \Tainacan\API\EndPoints\REST_Filters_Controller();
|
||||
$rest_item_metadata_controller = new \Tainacan\API\EndPoints\REST_Item_Metadata_Controller();
|
||||
$rest_logs_controller = new \Tainacan\API\EndPoints\REST_Logs_Controller();
|
||||
$rest_field_types_controller = new \Tainacan\API\EndPoints\REST_Field_Types_Controller();
|
||||
$rest_filter_types_controller = new \Tainacan\API\EndPoints\REST_Filter_Types_Controller();
|
||||
// Add here other endpoints imports
|
||||
|
||||
?>
|
|
@ -309,7 +309,7 @@ class Capabilities {
|
|||
*
|
||||
* @return array Tainacan roles
|
||||
*/
|
||||
private function get_tainacan_roles() {
|
||||
public function get_tainacan_roles() {
|
||||
$tainacan_roles = [
|
||||
'editor' => [
|
||||
'slug' => 'tainacan-editor',
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
namespace Tainacan;
|
||||
|
||||
class Embed {
|
||||
|
||||
private static $instance = null;
|
||||
|
||||
public static function get_instance() {
|
||||
if(!isset(self::$instance)) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
protected function __construct() {
|
||||
|
||||
/**
|
||||
* Replace default WordPress embedders with HTML 5 tags instead of shortcodes
|
||||
*/
|
||||
add_filter('wp_embed_handler_video', [&$this, 'filter_video_embed'], 10, 4);
|
||||
add_filter('wp_embed_handler_audio', [&$this, 'filter_audio_embed'], 10, 4);
|
||||
|
||||
/**
|
||||
* ADD PDF Embed handler using PDF.js
|
||||
* @var [type]
|
||||
*/
|
||||
wp_embed_register_handler( 'pdf', '#^https?://.+?\.(pdf)$#i', [&$this, 'pdf_embed_handler'] );
|
||||
|
||||
}
|
||||
|
||||
public function filter_video_embed($video, $attr, $url, $rawattr) {
|
||||
|
||||
|
||||
$dimensions = '';
|
||||
if ( ! empty( $attr['width'] ) && ! empty( $attr['height'] ) ) {
|
||||
$dimensions .= sprintf( 'width="%d" ', (int) $attr['width'] );
|
||||
//$dimensions .= sprintf( 'height="%d" ', (int) $attr['height'] );
|
||||
}
|
||||
$video = sprintf( '<video controls="" %s src="%s"></video>', $dimensions, esc_url( $url ) );
|
||||
|
||||
return $video;
|
||||
|
||||
}
|
||||
|
||||
public function filter_audio_embed($audio, $attr, $url, $rawattr) {
|
||||
|
||||
|
||||
if ( ! empty( $attr['width'] ) ) {
|
||||
$dimensions = sprintf( 'width="%d" ', (int) $attr['width'] );
|
||||
}
|
||||
|
||||
$audio = sprintf('<audio controls="" src="%s" %s></audio>', $url, $dimensions);
|
||||
|
||||
return $audio;
|
||||
|
||||
}
|
||||
|
||||
public function pdf_embed_handler($matches, $attr, $url, $rawattr) {
|
||||
global $TAINACAN_BASE_URL;
|
||||
$viewer_url = $TAINACAN_BASE_URL . '/pdf-viewer/pdf-viewer.html?file=' . $url;
|
||||
//$viewer_url = $TAINACAN_BASE_URL . '/assets/pdfjs-dist/web/viewer.html?file=' . $url;
|
||||
|
||||
$defaults = array(
|
||||
'width' => 800,
|
||||
'height' => 1000
|
||||
);
|
||||
|
||||
$args = array_merge($defaults, $attr);
|
||||
|
||||
$dimensions = '';
|
||||
if ( ! empty( $args['width'] ) && ! empty( $args['height'] ) ) {
|
||||
$dimensions .= sprintf( "width='%d' ", (int) $args['width'] );
|
||||
$dimensions .= sprintf( "height='%d' ", (int) $args['height'] );
|
||||
}
|
||||
|
||||
$pdf = "<iframe id='iframePDF' name='iframePDF' src='$viewer_url' $dimensions allowfullscreen webkitallowfullscreen></iframe>";
|
||||
return $pdf;
|
||||
}
|
||||
|
||||
}
|
|
@ -153,16 +153,24 @@ class Collection extends Entity {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param null $exclude
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function get_attachments() {
|
||||
function get_attachments($exclude = null) {
|
||||
$collection_id = $this->get_id();
|
||||
|
||||
if(!$exclude){
|
||||
$to_exclude = get_post_thumbnail_id( $collection_id );
|
||||
} else {
|
||||
$to_exclude = $exclude;
|
||||
}
|
||||
|
||||
$attachments_query = [
|
||||
'post_type' => 'attachment',
|
||||
'post_per_page' => - 1,
|
||||
'post_per_page' => -1,
|
||||
'post_parent' => $collection_id,
|
||||
'exclude' => get_post_thumbnail_id( $collection_id )
|
||||
'exclude' => $to_exclude
|
||||
];
|
||||
|
||||
$attachments = get_posts( $attachments_query );
|
||||
|
|
|
@ -125,8 +125,7 @@ class Entity {
|
|||
}
|
||||
}
|
||||
|
||||
public function get_repository()
|
||||
{
|
||||
public function get_repository() {
|
||||
$namespace = '\Tainacan\Repositories\\'.$this->repository;
|
||||
$repository = $namespace::get_instance();
|
||||
|
||||
|
|
|
@ -75,16 +75,24 @@ class Item extends Entity {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param null $exclude
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function get_attachments() {
|
||||
function get_attachments($exclude = null){
|
||||
$item_id = $this->get_id();
|
||||
|
||||
if(!$exclude){
|
||||
$to_exclude = get_post_thumbnail_id( $item_id );
|
||||
} else {
|
||||
$to_exclude = $exclude;
|
||||
}
|
||||
|
||||
$attachments_query = [
|
||||
'post_type' => 'attachment',
|
||||
'post_per_page' => - 1,
|
||||
'post_per_page' => -1,
|
||||
'post_parent' => $item_id,
|
||||
'exclude' => get_post_thumbnail_id( $item_id )
|
||||
'exclude' => $to_exclude,
|
||||
];
|
||||
|
||||
$attachments = get_posts( $attachments_query );
|
||||
|
@ -132,14 +140,6 @@ class Item extends Entity {
|
|||
/**
|
||||
* @return int|string
|
||||
*/
|
||||
/*function get_featured_img_id() {
|
||||
$featured_img_id = $this->get_featured_img_id();
|
||||
if ( isset( $featured_img_id ) ) {
|
||||
return $featured_img_id;
|
||||
}
|
||||
|
||||
return get_post_thumbnail_id( $this->get_id() );
|
||||
}*/
|
||||
function get_featured_img_id() {
|
||||
$featured_img_id = $this->get_mapped_property("featured_img_id");
|
||||
if ( isset( $featured_img_id ) ) {
|
||||
|
@ -433,7 +433,7 @@ class Item extends Entity {
|
|||
return $return;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the item metadata as a HTML string to be used as output.
|
||||
*
|
||||
|
@ -441,10 +441,12 @@ class Item extends Entity {
|
|||
*
|
||||
* If an ID, a slug or a Tainacan\Entities\Field object is passed, it returns only one metadata, otherwise
|
||||
* it returns all metadata
|
||||
*
|
||||
*
|
||||
* @param int|string|Tainacan\Entities\Field $field Field object, ID or slug to retrieve only one field. empty returns all fields
|
||||
* @param bool $hide_empty Wether to hide or not fields the item has no value to
|
||||
*
|
||||
* @return string The HTML output
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function get_metadata_as_html($field = null, $hide_empty = true) {
|
||||
|
||||
|
@ -494,4 +496,49 @@ class Item extends Entity {
|
|||
|
||||
}
|
||||
|
||||
public function get_document_html($img_size = 'large') {
|
||||
|
||||
$type = $this->get_document_type();
|
||||
|
||||
$output = '';
|
||||
|
||||
if ( $type == 'url' ) {
|
||||
$output .= apply_filters('the_content', $this->get_document());
|
||||
} elseif ( $type == 'text' ) {
|
||||
$output .= $this->get_document();
|
||||
} elseif ( $type == 'attachment' ) {
|
||||
|
||||
if ( wp_attachment_is_image($this->get_document()) ) {
|
||||
|
||||
$img = wp_get_attachment_image($this->get_document(), $img_size);
|
||||
$img_full = wp_get_attachment_url($this->get_document());
|
||||
|
||||
$output .= sprintf("<a href='%s' target='blank'>%s</a>", $img_full, $img);
|
||||
|
||||
} else {
|
||||
|
||||
global $wp_embed;
|
||||
|
||||
$url = wp_get_attachment_url($this->get_document());
|
||||
|
||||
$embed = $wp_embed->autoembed($url);
|
||||
|
||||
if ( $embed == $url ) {
|
||||
|
||||
// No embed handler found
|
||||
// TODO: Add filter to allow customization
|
||||
$output .= sprintf("<a href='%s' target='blank'>%s</a>", $url, $url);
|
||||
} else {
|
||||
$output .= $embed;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $output;
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -132,16 +132,16 @@ class Log extends Entity {
|
|||
return maybe_unserialize( base64_decode( $this->get_mapped_property( 'value' ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get old value of log entry object
|
||||
*
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function get_old_value() {
|
||||
return maybe_unserialize( base64_decode( $this->get_mapped_property( 'old_value' ) ) );
|
||||
}
|
||||
// /**
|
||||
// * Get old value of log entry object
|
||||
// *
|
||||
// * @param mixed $value
|
||||
// *
|
||||
// * @return void
|
||||
// */
|
||||
// public function get_old_value() {
|
||||
// return maybe_unserialize( base64_decode( $this->get_mapped_property( 'old_value' ) ) );
|
||||
// }
|
||||
|
||||
/**
|
||||
* Set log tittle
|
||||
|
@ -226,15 +226,29 @@ class Log extends Entity {
|
|||
$this->set_mapped_property( 'value', base64_encode( maybe_serialize( $value ) ) );
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Set old value of log entry
|
||||
// *
|
||||
// * @param [mixed] $value
|
||||
// *
|
||||
// * @return void
|
||||
// */
|
||||
// protected function set_old_value( $value = null ) {
|
||||
// $this->set_mapped_property( 'old_value', base64_encode( maybe_serialize( $value ) ) );
|
||||
// }
|
||||
|
||||
/**
|
||||
* Set old value of log entry
|
||||
*
|
||||
* @param [mixed] $value
|
||||
*
|
||||
* @return void
|
||||
* @param $diffs
|
||||
*/
|
||||
protected function set_old_value( $value = null ) {
|
||||
$this->set_mapped_property( 'old_value', base64_encode( maybe_serialize( $value ) ) );
|
||||
public function set_log_diffs($diffs){
|
||||
$this->set_mapped_property( 'log_diffs', $diffs );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed|null
|
||||
*/
|
||||
public function get_log_diffs(){
|
||||
return $this->get_mapped_property('log_diffs');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -242,24 +256,22 @@ class Log extends Entity {
|
|||
* @param boolean|string $msn
|
||||
* @param string $desc
|
||||
* @param mixed $new_value
|
||||
* @param mixed $old_value
|
||||
* @param array $diffs
|
||||
* @param string $status 'publish', 'private' or 'pending'
|
||||
*
|
||||
* @throws \Exception
|
||||
* @return \Tainacan\Entities\Log
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function create( $msn = false, $desc = '', $new_value = null, $old_value = null, $status = 'publish' ) {
|
||||
public static function create( $msn = false, $desc = '', $new_value = null, $diffs = [], $status = 'publish' ) {
|
||||
|
||||
$log = new Log();
|
||||
$log->set_title( $msn );
|
||||
$log->set_description( $desc );
|
||||
$log->set_status( $status );
|
||||
$log->set_log_diffs( $diffs );
|
||||
|
||||
if ( ! is_null( $new_value ) ) {
|
||||
$log->set_value( $new_value );
|
||||
|
||||
if ( ! is_null( $old_value ) ) {
|
||||
$log->set_old_value( $old_value );
|
||||
}
|
||||
} elseif ( $msn === false ) {
|
||||
throw new \Exception( 'msn or new_value is need to log' );
|
||||
}
|
||||
|
@ -283,21 +295,4 @@ class Log extends Entity {
|
|||
|
||||
return $repository->approve( $this );
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* {@inheritDoc}
|
||||
* @see \Tainacan\Entities\Entity::diff()
|
||||
*/
|
||||
public function diff($which = 0) {
|
||||
$log = $this;
|
||||
|
||||
if($which != 0) {
|
||||
$log = new self($which);
|
||||
}
|
||||
|
||||
$value = $log->get_value();
|
||||
$old = $log->get_old_value();
|
||||
return $value->diff($old);
|
||||
}
|
||||
}
|
|
@ -26,7 +26,7 @@ export const filter_type_mixin = {
|
|||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error);
|
||||
this.$console.error(error);
|
||||
});
|
||||
},
|
||||
getValuesRelationship(collectionTarget, search) {
|
||||
|
@ -45,7 +45,7 @@ export const filter_type_mixin = {
|
|||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error);
|
||||
this.$console.error(error);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
<div class="block">
|
||||
<b-select
|
||||
:id = "id"
|
||||
:laoding = "isLoading"
|
||||
:loading = "isLoading"
|
||||
v-model = "selected"
|
||||
@input = "onSelect()"
|
||||
@input = "onSelect($event)"
|
||||
expanded>
|
||||
<option value="">{{ $i18n.get('label_selectbox_init') }}...</option>
|
||||
<option
|
||||
|
@ -36,7 +36,7 @@
|
|||
}
|
||||
})
|
||||
.catch(error => {
|
||||
this.$console.log(error);
|
||||
this.$console.error(error);
|
||||
});
|
||||
},
|
||||
data(){
|
||||
|
@ -45,41 +45,50 @@
|
|||
options: [],
|
||||
type: '',
|
||||
collection: '',
|
||||
field: '',
|
||||
selected: '',
|
||||
field: ''
|
||||
}
|
||||
},
|
||||
mixins: [filter_type_mixin],
|
||||
computed: {
|
||||
selected() {
|
||||
if ( this.query && this.query.metaquery && Array.isArray( this.query.metaquery ) ) {
|
||||
|
||||
let index = this.query.metaquery.findIndex(newField => newField.key === this.field );
|
||||
if ( index >= 0){
|
||||
let metadata = this.query.metaquery[ index ];
|
||||
return metadata.value;
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
loadOptions(){
|
||||
let promise = null;
|
||||
this.isLoading = true;
|
||||
let instance = this;
|
||||
|
||||
let promise = null;
|
||||
|
||||
if ( this.type === 'Tainacan\\Field_Types\\Relationship' ) {
|
||||
let collectionTarget = ( this.field_object && this.field_object.field_type_options.collection_id ) ?
|
||||
this.field_object.field_type_options.collection_id : this.collection_id;
|
||||
let collectionTarget = ( this.field_object && this.field_object.field_type_options.collection_id ) ? this.field_object.field_type_options.collection_id : this.collection_id;
|
||||
promise = this.getValuesRelationship( collectionTarget );
|
||||
|
||||
} else {
|
||||
promise = this.getValuesPlainText( this.field );
|
||||
}
|
||||
|
||||
promise.then(() => {
|
||||
this.isLoading = false;
|
||||
instance.selectedValues();
|
||||
})
|
||||
.catch( error => {
|
||||
this.$console.log('error select', error );
|
||||
this.$console.error('error select', error );
|
||||
this.isLoading = false;
|
||||
});
|
||||
},
|
||||
onSelect(){
|
||||
onSelect(value){
|
||||
this.$emit('input', {
|
||||
filter: 'selectbox',
|
||||
field_id: this.field,
|
||||
collection_id: ( this.collection_id ) ? this.collection_id : this.filter.collection_id,
|
||||
value: this.selected
|
||||
value: value
|
||||
});
|
||||
},
|
||||
selectedValues(){
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<component
|
||||
:id="filter.filter_type_object.component + '-' + filter.slug"
|
||||
:is="filter.filter_type_object.component"
|
||||
:filter="getFilter"
|
||||
:filter="filter"
|
||||
:query="query"
|
||||
@input="listen( $event )"/>
|
||||
</div>
|
||||
|
@ -15,8 +15,7 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import { eventBusSearch } from '../../js/event-bus-search'
|
||||
import { mapActions, mapGetters } from 'vuex';
|
||||
import { mapActions } from 'vuex';
|
||||
|
||||
export default {
|
||||
name: 'TainacanFilterItem',
|
||||
|
@ -33,7 +32,7 @@
|
|||
computed: {
|
||||
getErrorMessage() {
|
||||
let msg = '';
|
||||
let errors = eventBusSearch.getErrors( this.filter.id );
|
||||
let errors = this.$eventBusSearch.getErrors( this.filter.id );
|
||||
if ( errors) {
|
||||
this.setFilterTypeMessage('is-danger');
|
||||
for (let index in errors) {
|
||||
|
@ -43,21 +42,14 @@
|
|||
this.setFilterTypeMessage('');
|
||||
}
|
||||
return msg;
|
||||
},
|
||||
getFilter(){
|
||||
return this.filter;
|
||||
}
|
||||
|
||||
},
|
||||
methods: {
|
||||
...mapActions('search', [
|
||||
'setPage'
|
||||
]),
|
||||
...mapGetters('search', [
|
||||
'getPostQuery'
|
||||
]),
|
||||
listen( event ){
|
||||
eventBusSearch.$emit( 'input', ( event.field_id ) ? event : event.detail[0] );
|
||||
this.$eventBusSearch.$emit( 'input', ( event.field_id ) ? event : event.detail[0] );
|
||||
},
|
||||
setFilterTypeMessage( message ){
|
||||
this.filterTypeMessage = message;
|
||||
|
|
|
@ -119,11 +119,11 @@ class Collections extends Repository {
|
|||
'default' => 'ASC',
|
||||
'validation' => v::stringType()->in( [ 'ASC', 'DESC' ] ),
|
||||
],
|
||||
'columns' => [
|
||||
'default_displayed_fields' => [
|
||||
'map' => 'meta',
|
||||
'title' => __( 'Columns', 'tainacan' ),
|
||||
'title' => __( 'Default Displayed Fields', 'tainacan' ),
|
||||
'type' => 'string',
|
||||
'description' => __( 'List of collections property that will be displayed in the table view', 'tainacan' ),
|
||||
'description' => __( 'List of collections property that will be displayed in the table view.', 'tainacan' ),
|
||||
//'validation' => v::stringType(),
|
||||
],
|
||||
'default_view_mode' => [
|
||||
|
@ -307,9 +307,21 @@ class Collections extends Repository {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: Implement this method
|
||||
public function fetch_by_db_identifier( $db_identifier ) {
|
||||
|
||||
if ( $id = $this->get_id_by_db_identifier($db_identifier) ) {
|
||||
return $this->fetch($id);
|
||||
}
|
||||
}
|
||||
|
||||
public function get_id_by_db_identifier($db_identifier) {
|
||||
$prefix = \Tainacan\Entities\Collection::$db_identifier_prefix;
|
||||
$sufix = \Tainacan\Entities\Collection::$db_identifier_sufix;
|
||||
$id = str_replace($prefix, '', $db_identifier);
|
||||
$id = str_replace($sufix, '', $id);
|
||||
if (is_numeric($id)) {
|
||||
return (int) $id;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function pre_update_moderators( $collection ) {
|
||||
|
|
|
@ -12,18 +12,15 @@ class Filters extends Repository {
|
|||
|
||||
private static $instance = null;
|
||||
|
||||
public static function get_instance()
|
||||
{
|
||||
if(!isset(self::$instance))
|
||||
{
|
||||
public static function get_instance() {
|
||||
if(!isset(self::$instance)) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
protected function __construct()
|
||||
{
|
||||
protected function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
|
|
@ -7,8 +7,7 @@ defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
|
|||
|
||||
class Item_Metadata extends Repository {
|
||||
|
||||
protected function __construct()
|
||||
{
|
||||
protected function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
@ -16,10 +15,8 @@ class Item_Metadata extends Repository {
|
|||
|
||||
private static $instance = null;
|
||||
|
||||
public static function get_instance()
|
||||
{
|
||||
if(!isset(self::$instance))
|
||||
{
|
||||
public static function get_instance() {
|
||||
if(!isset(self::$instance)) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
|
||||
|
@ -33,12 +30,19 @@ class Item_Metadata extends Repository {
|
|||
// TODO: Throw Warning saying you must validate object before insert()
|
||||
}
|
||||
|
||||
$old = $item_metadata;
|
||||
$is_update = false;
|
||||
// TODO get props obj before update
|
||||
if( $item_metadata->get_id() ) {
|
||||
$is_update = true;
|
||||
$old = $item_metadata->get_repository()->fetch( $item_metadata->get_id() );
|
||||
$diffs = [];
|
||||
if ( $item_metadata->get_id() ) {
|
||||
|
||||
if($item_metadata->get_status() === 'auto-draft') {
|
||||
$is_update = false;
|
||||
} else {
|
||||
$is_update = true;
|
||||
}
|
||||
|
||||
$old = $item_metadata->get_repository()->fetch( $item_metadata->get_id() );
|
||||
|
||||
$diffs = $this->diff($old, $item_metadata);
|
||||
}
|
||||
|
||||
$unique = !$item_metadata->is_multiple();
|
||||
|
@ -84,12 +88,10 @@ class Item_Metadata extends Repository {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
do_action('tainacan-insert', $item_metadata, $diffs, $is_update);
|
||||
do_action('tainacan-insert-Item_Metadata_Entity', $item_metadata);
|
||||
}
|
||||
|
||||
|
||||
|
||||
do_action('tainacan-insert', $item_metadata, $old, $is_update);
|
||||
do_action('tainacan-insert-Item_Metadata_Entity', $item_metadata);
|
||||
|
||||
$new_entity = new Entities\Item_Metadata_Entity($item_metadata->get_item(), $item_metadata->get_field());
|
||||
|
||||
|
@ -133,11 +135,18 @@ class Item_Metadata extends Repository {
|
|||
if ($field_type->get_primitive_type() == 'term') {
|
||||
$new_terms = $item_metadata->get_value();
|
||||
$taxonomy = new Entities\Taxonomy( $field_type->get_option('taxonomy_id') );
|
||||
|
||||
if( $taxonomy ){
|
||||
wp_set_object_terms($item_metadata->get_item()->get_id(), $new_terms, $taxonomy->get_db_identifier() );
|
||||
$old = $item_metadata;
|
||||
|
||||
$success = wp_set_object_terms($item_metadata->get_item()->get_id(), $new_terms, $taxonomy->get_db_identifier() );
|
||||
|
||||
if(!$success instanceof \WP_Error) {
|
||||
$diffs = $this->diff($old, $item_metadata);
|
||||
|
||||
do_action( 'tainacan-insert', $item_metadata, $diffs, true );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -168,12 +168,19 @@ class Items extends Repository {
|
|||
|
||||
public function insert( $item ) {
|
||||
|
||||
$old = $item;
|
||||
$is_update = false;
|
||||
// TODO get props obj before update
|
||||
if( $item->get_id() ) {
|
||||
$is_update = true;
|
||||
$old = $item->get_repository()->fetch( $item->get_id() );
|
||||
$diffs = [];
|
||||
if ( $item->get_id() ) {
|
||||
|
||||
$old = $item->get_repository()->fetch( $item->get_id() );
|
||||
|
||||
if($old->get_status() === 'auto-draft') {
|
||||
$is_update = false;
|
||||
} else {
|
||||
$is_update = true;
|
||||
}
|
||||
|
||||
$diffs = $this->diff($old, $item);
|
||||
}
|
||||
|
||||
$map = $this->get_map();
|
||||
|
@ -181,7 +188,7 @@ class Items extends Repository {
|
|||
// get collection to determine post type
|
||||
$collection = $item->get_collection();
|
||||
|
||||
if ( ! $collection ) {
|
||||
if ( !$collection ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -219,10 +226,45 @@ class Items extends Repository {
|
|||
}
|
||||
|
||||
if ( method_exists( $item, 'get_featured_img_id' ) ) {
|
||||
set_post_thumbnail( $item->WP_Post, $item->get_featured_img_id( $item->WP_Post->ID ) );
|
||||
if ( ! get_post_thumbnail_id( $item->WP_Post->ID ) ) {
|
||||
// was added a thumbnail
|
||||
|
||||
$settled = set_post_thumbnail( $item->WP_Post, $item->get_featured_img_id( $item->WP_Post->ID ) );
|
||||
|
||||
if ( $settled ) {
|
||||
|
||||
$thumbnail_url = get_the_post_thumbnail_url( $item->WP_Post->ID );
|
||||
|
||||
$diffs['featured_image'] = [
|
||||
'new' => $thumbnail_url,
|
||||
'old' => '',
|
||||
'diff_with_index' => 0,
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
// was update a thumbnail
|
||||
|
||||
$old_thumbnail = get_the_post_thumbnail_url( $item->WP_Post->ID );
|
||||
|
||||
$settled = set_post_thumbnail( $item->WP_Post, $item->get_featured_img_id( $item->WP_Post->ID ) );
|
||||
|
||||
if ( $settled ) {
|
||||
|
||||
$thumbnail_url = get_the_post_thumbnail_url( $item->WP_Post->ID );
|
||||
|
||||
$diffs['featured_image'] = [
|
||||
'new' => $thumbnail_url,
|
||||
'old' => $old_thumbnail,
|
||||
'diff_with_index' => 0,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
do_action( 'tainacan-insert', $item, $old, $is_update );
|
||||
do_action( 'tainacan-insert', $item, $diffs, $is_update );
|
||||
do_action( 'tainacan-insert-Item', $item );
|
||||
|
||||
// return a brand new object
|
||||
|
|
|
@ -28,7 +28,10 @@ class Logs extends Repository {
|
|||
|
||||
protected function __construct() {
|
||||
parent::__construct();
|
||||
add_action( 'tainacan-insert', array( $this, 'log_inserts' ), 10, 3 );
|
||||
add_action( 'tainacan-insert', array( $this, 'insert_log' ), 10, 3 );
|
||||
|
||||
add_action( 'add_attachment', array( $this, 'prepare_attachment_log_before_insert' ), 10, 3 );
|
||||
// add_action( 'attachment_updated', array( $this, 'prepare_attachment_log_before_insert' ), 10, 3);
|
||||
}
|
||||
|
||||
public function get_map() {
|
||||
|
@ -104,13 +107,10 @@ class Logs extends Repository {
|
|||
'description' => __( 'The actual log value' ),
|
||||
'validation' => ''
|
||||
],
|
||||
'old_value' => [
|
||||
'map' => 'meta',
|
||||
'title' => __( 'Old value', 'tainacan' ),
|
||||
'type' => 'string',
|
||||
'description' => __( 'The old log value' ),
|
||||
'validation' => ''
|
||||
],
|
||||
'log_diffs' => [
|
||||
'map' => 'meta',
|
||||
'title' => __( 'Log differences', 'tainacan' ),
|
||||
]
|
||||
] );
|
||||
}
|
||||
|
||||
|
@ -186,7 +186,7 @@ class Logs extends Repository {
|
|||
|
||||
} elseif ( is_array( $args ) ) {
|
||||
$args = array_merge( [
|
||||
'posts_per_page' => -1,
|
||||
'posts_per_page' => - 1,
|
||||
], $args );
|
||||
|
||||
$args = $this->parse_fetch_args( $args );
|
||||
|
@ -217,7 +217,53 @@ class Logs extends Repository {
|
|||
|
||||
$logs = $this->fetch( $args, 'OBJECT' );
|
||||
|
||||
return array_pop($logs);
|
||||
return array_pop( $logs );
|
||||
}
|
||||
|
||||
|
||||
public function prepare_attachment_log_before_insert( $post_ID, $post_after = null, $post_before = null ) {
|
||||
|
||||
if ( ! $post_after && ! $post_before ) {
|
||||
// is add attachment
|
||||
$attachment = get_post( $post_ID );
|
||||
$post = $attachment->post_parent;
|
||||
|
||||
if ( $post ) {
|
||||
// was added attachment on a tainacan object
|
||||
|
||||
$tainacan_post = Repository::get_entity_by_post( $post );
|
||||
|
||||
if($tainacan_post) {
|
||||
// was added a normal attachment
|
||||
|
||||
// get all attachments except the new
|
||||
$old_attachments = $tainacan_post->get_attachments( $post_ID );
|
||||
|
||||
foreach ( $old_attachments as $attachment ) {
|
||||
unset( $attachment['id'] );
|
||||
}
|
||||
|
||||
$new_attachments[] = [
|
||||
'title' => $attachment->post_title,
|
||||
'description' => $attachment->post_content,
|
||||
'mime_type' => $attachment->post_mime_type,
|
||||
'url' => $attachment->guid,
|
||||
];
|
||||
|
||||
$array_diff_with_index = array_map( 'unserialize',
|
||||
array_diff_assoc( array_map( 'serialize', $new_attachments ), array_map( 'serialize', $old_attachments ) ) );
|
||||
|
||||
$diff['attachments'] = [
|
||||
'new' => $new_attachments,
|
||||
'old' => $old_attachments,
|
||||
'diff_with_index' => $array_diff_with_index
|
||||
];
|
||||
|
||||
$this->insert_log( $tainacan_post, $diff, true );
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -230,59 +276,57 @@ class Logs extends Repository {
|
|||
*
|
||||
* @return Entities\Log new created log
|
||||
*/
|
||||
public function log_inserts( $new_value, $old_value = null, $is_update = null ) {
|
||||
$msn = "";
|
||||
public function insert_log( $new_value, $diffs, $is_update = null ) {
|
||||
$msn = "";
|
||||
$description = "";
|
||||
|
||||
if ( is_object( $new_value ) ) {
|
||||
// do not log a log
|
||||
if ( method_exists( $new_value, 'get_post_type' ) && $new_value->get_post_type() == 'tainacan-log' || $new_value->get_status() === 'auto-draft' ) {
|
||||
return;
|
||||
if ( ( method_exists( $new_value, 'get_post_type' ) && $new_value->get_post_type() === 'tainacan-log' ) || $new_value->get_status() === 'auto-draft' ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if($new_value instanceof Entities\Field){
|
||||
if ( $new_value instanceof Entities\Field ) {
|
||||
$type = $new_value->get_field_type();
|
||||
|
||||
if($type === 'Tainacan\Field_Types\Core_Title' || $type === 'Tainacan\Field_Types\Core_Description'){
|
||||
return;
|
||||
if ( $type === 'Tainacan\Field_Types\Core_Title' || $type === 'Tainacan\Field_Types\Core_Description' ) {
|
||||
return false;
|
||||
}
|
||||
} elseif (!$is_update && $new_value instanceof Entities\Item || $new_value instanceof Entities\Collection) {
|
||||
return;
|
||||
}
|
||||
|
||||
$type = get_class( $new_value );
|
||||
$class_name = explode('\\', $type)[2];
|
||||
$type = get_class( $new_value );
|
||||
$class_name = explode( '\\', $type )[2];
|
||||
|
||||
$name = method_exists($new_value, 'get_name') ? $new_value->get_name() :
|
||||
(method_exists($new_value, 'get_title') ? $new_value->get_title() : $new_value->get_field()->get_name());
|
||||
$name = method_exists( $new_value, 'get_name' ) ? $new_value->get_name() :
|
||||
( method_exists( $new_value, 'get_title' ) ? $new_value->get_title() : $new_value->get_field()->get_name() );
|
||||
|
||||
if(!$name){
|
||||
if ( ! $name ) {
|
||||
$name = $new_value->get_status();
|
||||
}
|
||||
|
||||
$articleA = 'A';
|
||||
$articleA = 'A';
|
||||
$articleAn = 'An';
|
||||
$vowels = 'aeiou';
|
||||
$vowels = 'aeiou';
|
||||
|
||||
if($is_update){
|
||||
if(substr_count($vowels, strtolower(substr($class_name, 0, 1))) > 0){
|
||||
$msn = sprintf( __( '%s %s has been updated.', 'tainacan' ), $articleAn, $class_name);
|
||||
if ( $is_update ) {
|
||||
if ( substr_count( $vowels, strtolower( substr( $class_name, 0, 1 ) ) ) > 0 ) {
|
||||
$msn = sprintf( __( '%s %s has been updated.', 'tainacan' ), $articleAn, $class_name );
|
||||
} else {
|
||||
$msn = sprintf( __( '%s %s has been updated.', 'tainacan' ), $articleA, $class_name);
|
||||
$msn = sprintf( __( '%s %s has been updated.', 'tainacan' ), $articleA, $class_name );
|
||||
}
|
||||
$description = sprintf( __("The \"%s\" %s has been updated.", 'tainacan' ), $name, strtolower($class_name));
|
||||
$description = sprintf( __( "The \"%s\" %s has been updated.", 'tainacan' ), $name, strtolower( $class_name ) );
|
||||
} else {
|
||||
if(substr_count($vowels, strtolower(substr($class_name, 0, 1))) > 0){
|
||||
$msn = sprintf( __( '%s %s has been created.', 'tainacan' ), $articleAn, $class_name);
|
||||
if ( substr_count( $vowels, strtolower( substr( $class_name, 0, 1 ) ) ) > 0 ) {
|
||||
$msn = sprintf( __( '%s %s has been created.', 'tainacan' ), $articleAn, $class_name );
|
||||
} else {
|
||||
$msn = sprintf( __( '%s %s has been created.', 'tainacan' ), $articleA, $class_name);
|
||||
$msn = sprintf( __( '%s %s has been created.', 'tainacan' ), $articleA, $class_name );
|
||||
}
|
||||
|
||||
if($new_value instanceof Entities\Field){
|
||||
$collection = $new_value->get_collection();
|
||||
$parent = $collection;
|
||||
if ( $new_value instanceof Entities\Field ) {
|
||||
$collection = $new_value->get_collection();
|
||||
$parent = $collection;
|
||||
|
||||
if($collection) {
|
||||
if ( $collection ) {
|
||||
$parent = $collection->get_name();
|
||||
|
||||
if ( ! $parent ) {
|
||||
|
@ -297,10 +341,12 @@ class Logs extends Repository {
|
|||
}
|
||||
}
|
||||
|
||||
$msn = apply_filters( 'tainacan-insert-log-message-title', $msn, $type, $new_value );
|
||||
$description = apply_filters('tainacan-insert-log-description', $description, $type, $new_value);
|
||||
$msn = apply_filters( 'tainacan-insert-log-message-title', $msn, $type, $new_value );
|
||||
$description = apply_filters( 'tainacan-insert-log-description', $description, $type, $new_value );
|
||||
|
||||
return Entities\Log::create( $msn, $description, $new_value, $old_value );
|
||||
if ( ! empty( $diffs ) ) {
|
||||
return Entities\Log::create( $msn, $description, $new_value, $diffs );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -76,14 +76,21 @@ abstract class Repository {
|
|||
// TODO: Throw Warning saying you must validate object before insert()
|
||||
}
|
||||
|
||||
$old = $obj;
|
||||
$is_update = false;
|
||||
// TODO get props obj before update
|
||||
if( $obj->get_id() ) {
|
||||
$is_update = true;
|
||||
$diffs = [];
|
||||
if ( $obj->get_id() ) {
|
||||
|
||||
$old = $obj->get_repository()->fetch( $obj->get_id() );
|
||||
|
||||
if ( method_exists( $old, 'get_status' ) && $old->get_status() === 'auto-draft' ) {
|
||||
$is_update = false;
|
||||
} else {
|
||||
$is_update = true;
|
||||
}
|
||||
|
||||
$diffs = $this->diff( $old, $obj );
|
||||
}
|
||||
|
||||
|
||||
$map = $this->get_map();
|
||||
|
||||
// First iterate through the native post properties
|
||||
|
@ -115,10 +122,45 @@ abstract class Repository {
|
|||
}
|
||||
|
||||
if ( method_exists( $obj, 'get_featured_img_id' ) ) {
|
||||
set_post_thumbnail( $obj->WP_Post, $obj->get_featured_img_id( $obj->WP_Post->ID ) );
|
||||
if ( ! get_post_thumbnail_id( $obj->WP_Post->ID ) ) {
|
||||
// was added a thumbnail
|
||||
|
||||
$settled = set_post_thumbnail( $obj->WP_Post, $obj->get_featured_img_id( $obj->WP_Post->ID ) );
|
||||
|
||||
if ( $settled ) {
|
||||
|
||||
$thumbnail_url = get_the_post_thumbnail_url( $obj->WP_Post->ID );
|
||||
|
||||
$diffs['featured_image'] = [
|
||||
'new' => $thumbnail_url,
|
||||
'old' => '',
|
||||
'diff_with_index' => 0,
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
// was update a thumbnail
|
||||
|
||||
$old_thumbnail = get_the_post_thumbnail_url( $obj->WP_Post->ID );
|
||||
|
||||
$settled = set_post_thumbnail( $obj->WP_Post, $obj->get_featured_img_id( $obj->WP_Post->ID ) );
|
||||
|
||||
if ( $settled ) {
|
||||
|
||||
$thumbnail_url = get_the_post_thumbnail_url( $obj->WP_Post->ID );
|
||||
|
||||
$diffs['featured_image'] = [
|
||||
'new' => $thumbnail_url,
|
||||
'old' => $old_thumbnail,
|
||||
'diff_with_index' => 0,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
do_action( 'tainacan-insert', $obj, $old, $is_update );
|
||||
do_action( 'tainacan-insert', $obj, $diffs, $is_update );
|
||||
do_action( 'tainacan-insert-' . $obj->get_post_type(), $obj );
|
||||
|
||||
// return a brand new object
|
||||
|
@ -343,8 +385,8 @@ abstract class Repository {
|
|||
*/
|
||||
public static function get_collections_db_identifiers() {
|
||||
$Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance();
|
||||
$collections = $Tainacan_Collections->fetch( [], 'OBJECT' );
|
||||
$cpts = [];
|
||||
$collections = $Tainacan_Collections->fetch( [], 'OBJECT' );
|
||||
$cpts = [];
|
||||
foreach ( $collections as $col ) {
|
||||
$cpts[] = $col->get_db_identifier();
|
||||
}
|
||||
|
@ -366,9 +408,10 @@ abstract class Repository {
|
|||
return $post;
|
||||
}
|
||||
|
||||
if (!$post instanceof \WP_Post)
|
||||
if ( ! $post instanceof \WP_Post ) {
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
$post_type = $post->post_type;
|
||||
|
||||
return self::get_entity_by_post_type( $post_type, $post );
|
||||
|
@ -393,15 +436,15 @@ abstract class Repository {
|
|||
} else {
|
||||
throw new \Exception( 'Collection object not found for this post' );
|
||||
}
|
||||
} elseif ($post_type === \Tainacan\Repositories\Item_Metadata::get_instance()->entities_type::get_post_type()){
|
||||
return new Entities\Item_Metadata_Entity(null, null);
|
||||
} elseif ( $post_type === \Tainacan\Repositories\Item_Metadata::get_instance()->entities_type::get_post_type() ) {
|
||||
return new Entities\Item_Metadata_Entity( null, null );
|
||||
} else {
|
||||
$Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance();
|
||||
$Tainacan_Filters = \Tainacan\Repositories\Filters::get_instance();
|
||||
$Tainacan_Logs = \Tainacan\Repositories\Logs::get_instance();
|
||||
$Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
|
||||
$Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance();
|
||||
$Tainacan_Terms = \Tainacan\Repositories\Terms::get_instance();
|
||||
$Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance();
|
||||
$Tainacan_Filters = \Tainacan\Repositories\Filters::get_instance();
|
||||
$Tainacan_Logs = \Tainacan\Repositories\Logs::get_instance();
|
||||
$Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
|
||||
$Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance();
|
||||
$Tainacan_Terms = \Tainacan\Repositories\Terms::get_instance();
|
||||
|
||||
$tnc_globals = [
|
||||
$Tainacan_Collections,
|
||||
|
@ -439,13 +482,13 @@ abstract class Repository {
|
|||
|
||||
return $Tainacan_Items;
|
||||
} else {
|
||||
$Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance();
|
||||
$Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
|
||||
$Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance();
|
||||
$Tainacan_Filters = \Tainacan\Repositories\Filters::get_instance();
|
||||
$Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance();
|
||||
$Tainacan_Terms = \Tainacan\Repositories\Terms::get_instance();
|
||||
$Tainacan_Logs = \Tainacan\Repositories\Logs::get_instance();
|
||||
$Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance();
|
||||
$Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
|
||||
$Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance();
|
||||
$Tainacan_Filters = \Tainacan\Repositories\Filters::get_instance();
|
||||
$Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance();
|
||||
$Tainacan_Terms = \Tainacan\Repositories\Terms::get_instance();
|
||||
$Tainacan_Logs = \Tainacan\Repositories\Logs::get_instance();
|
||||
|
||||
$tnc_globals = [
|
||||
$Tainacan_Collections,
|
||||
|
@ -624,11 +667,11 @@ abstract class Repository {
|
|||
$entity_type = get_class( $new );
|
||||
$old_entity = new $entity_type; // there is no saved entity, let compare with a new empty one
|
||||
}
|
||||
} else { // get entity from repository
|
||||
$old_entity = $this->get_entity_by_post( $old );
|
||||
} else {
|
||||
$old_entity = $old;
|
||||
}
|
||||
|
||||
$new_entity = $this->get_entity_by_post( $new );
|
||||
$new_entity = $new;
|
||||
|
||||
$map = $this->get_map();
|
||||
|
||||
|
@ -637,29 +680,35 @@ abstract class Repository {
|
|||
foreach ( $map as $prop => $mapped ) {
|
||||
if ( $old_entity->get_mapped_property( $prop ) != $new_entity->get_mapped_property( $prop ) ) {
|
||||
|
||||
if ( $mapped['map'] == 'meta_multi' || is_array($new_entity->get_mapped_property( $prop ))) {
|
||||
if ( $mapped['map'] === 'meta_multi' || ( $mapped['map'] === 'meta' && is_array( $new_entity->get_mapped_property( $prop ) ) ) ) {
|
||||
|
||||
// Array of diffs with index of diff in new array
|
||||
$array_diff_with_index = array_diff_assoc($new_entity->get_mapped_property( $prop ), $old_entity->get_mapped_property( $prop ));
|
||||
$new_v = $new_entity->get_mapped_property( $prop );
|
||||
$old_v = $old_entity->get_mapped_property( $prop );
|
||||
|
||||
$old_v = ! is_array( $old_v ) && empty( $old_v ) && ! is_string( $old_v ) ? array() : ( ! is_string( $old_v ) ? $old_v : [ $old_v ] );
|
||||
|
||||
$array_diff_with_index = array_map( 'unserialize',
|
||||
array_diff_assoc( array_map( 'serialize', $new_v ), array_map( 'serialize', $old_v ) ) );
|
||||
|
||||
if ( ! empty( $array_diff_with_index ) ) {
|
||||
|
||||
$diff[ $prop ] = [
|
||||
'new' => $new_entity->get_mapped_property( $prop ),
|
||||
'old' => $old_entity->get_mapped_property( $prop ),
|
||||
'new' => $new_entity->get_mapped_property( $prop ),
|
||||
'old' => $old_entity->get_mapped_property( $prop ),
|
||||
'diff_with_index' => $array_diff_with_index,
|
||||
];
|
||||
}
|
||||
} elseif($mapped['map'] !== 'post_modified') {
|
||||
$new_as_array = explode(' ', $new_entity->get_mapped_property( $prop ));
|
||||
$old_as_array = explode(' ', $old_entity->get_mapped_property( $prop ));
|
||||
} elseif ( $mapped['map'] !== 'post_modified' ) {
|
||||
$new_as_array = explode( ' ', $new_entity->get_mapped_property( $prop ) );
|
||||
$old_as_array = explode( ' ', $old_entity->get_mapped_property( $prop ) );
|
||||
|
||||
// Array of diffs with index of diff in new array
|
||||
$array_diff_with_index = array_diff_assoc($new_as_array, $old_as_array);
|
||||
$array_diff_with_index = array_diff_assoc( $new_as_array, $old_as_array );
|
||||
|
||||
$diff[ $prop ] = [
|
||||
'new' => $new_as_array,
|
||||
'old' => $old_entity->get_mapped_property( $prop ),
|
||||
'new' => $new_as_array,
|
||||
'old' => $old_entity->get_mapped_property( $prop ),
|
||||
'diff_with_index' => $array_diff_with_index,
|
||||
];
|
||||
}
|
||||
|
|
|
@ -98,15 +98,18 @@ class Terms extends Repository {
|
|||
* @param Entities\Entity $term
|
||||
*
|
||||
* @return Entities\Entity|Entities\Term
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function insert($term){
|
||||
|
||||
$old = $term;
|
||||
$is_update = false;
|
||||
// TODO get props obj before update
|
||||
if( $term->get_id() ) {
|
||||
$diffs = [];
|
||||
if ( $term->get_id() ) {
|
||||
$is_update = true;
|
||||
$old = $term->get_repository()->fetch( $term->get_id() );
|
||||
|
||||
$old = $this->fetch( $term->get_id(), $term->get_taxonomy() );
|
||||
|
||||
$diffs = $this->diff($old, $term);
|
||||
}
|
||||
|
||||
// First iterate through the native post properties
|
||||
|
@ -147,7 +150,7 @@ class Terms extends Repository {
|
|||
}
|
||||
}
|
||||
|
||||
do_action('tainacan-insert', $term, $old, $is_update);
|
||||
do_action('tainacan-insert', $term, $diffs, $is_update);
|
||||
do_action('tainacan-insert-Term', $term);
|
||||
|
||||
return new Entities\Term($term_saved['term_id'], $term->get_taxonomy());
|
||||
|
@ -188,8 +191,12 @@ class Terms extends Repository {
|
|||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
return [];
|
||||
} elseif (is_string($taxonomies) && is_numeric($args)){ // if taxonomy is taxonomy_db_identifier
|
||||
$cpt = $taxonomies;
|
||||
|
||||
$term = get_term_by('id', $args, $cpt);
|
||||
|
||||
return new Entities\Term($term);
|
||||
}
|
||||
|
||||
if(is_array( $args ) && !empty( $cpt ) ){ // if an array of arguments is
|
||||
|
|
|
@ -53,6 +53,9 @@ function tainacan_autoload($class_name){
|
|||
} else if( isset( $class_path[1] ) && $class_path[1] === 'Exposers' ){
|
||||
$dir = EXPOSERS_DIR;
|
||||
if(count($class_path) > 3) $dir .= strtolower($class_path[2]).DIRECTORY_SEPARATOR;
|
||||
} else if( isset( $class_path[1] ) && $class_path[1] === 'API' ){
|
||||
$dir = TAPI_DIR;
|
||||
if(count($class_path) > 3) $dir .= strtolower($class_path[2]).DIRECTORY_SEPARATOR;
|
||||
} else if($sliced) {
|
||||
$lower = $sliced[0];
|
||||
$sliced[0] = strtolower( $lower );
|
||||
|
@ -73,7 +76,7 @@ function tainacan_autoload($class_name){
|
|||
}
|
||||
|
||||
$file = $dir . 'class-tainacan-'. strtolower(str_replace('_', '-' , $class_name)) . '.php';
|
||||
|
||||
|
||||
if(file_exists($file)) {
|
||||
require_once($file);
|
||||
}
|
||||
|
@ -118,4 +121,6 @@ $Tainacan_Logs = \Tainacan\Repositories\Logs::get_instance();
|
|||
|
||||
$Tainacan_Exposers = \Tainacan\Exposers\Exposers::get_instance();
|
||||
|
||||
$Tainacan_Embed = \Tainacan\Embed::get_instance();
|
||||
|
||||
?>
|
||||
|
|
|
@ -20,6 +20,58 @@ class Old_Tainacan extends Importer
|
|||
$this->import_structure_and_mapping = $import_structure_and_mapping;
|
||||
}
|
||||
|
||||
public function fetch_from_remote( $url ){
|
||||
$url_json = explode('/colecao/', $url)[0] . "/wp-json/tainacan/v1/collections";
|
||||
$all_collections_info = wp_remote_get($url_json);
|
||||
|
||||
if(isset($all_collections_info['body']))
|
||||
{
|
||||
$all_collections_array = json_decode($all_collections_info['body']);
|
||||
|
||||
$collection_name = explode('/', $url);
|
||||
$collection_name = array_filter($collection_name, function($item){
|
||||
if(empty($item)) return false;
|
||||
|
||||
return true;
|
||||
});
|
||||
$collection_name = end($collection_name);
|
||||
|
||||
foreach($all_collections_array as $collection)
|
||||
{
|
||||
if(strcmp($collection->post_name, $collection_name) === 0)
|
||||
{
|
||||
$link = $collection->link[0]->href;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(!empty($link))
|
||||
{
|
||||
$items = wp_remote_get( $link."/items/?includeMetadata=1" );
|
||||
|
||||
if(isset($items['body']))
|
||||
{
|
||||
$items_array = json_decode($items['body']);
|
||||
|
||||
//Get Metatype
|
||||
$meta_type = wp_remote_get($link."/metadata");
|
||||
if(isset($meta_type['body']))
|
||||
{
|
||||
$meta_type_array = json_decode($meta_type['body']);
|
||||
$file_info['items'] = $items_array;
|
||||
$file_info['meta'] = $meta_type_array;
|
||||
|
||||
$file = fopen( $this->get_id().'.txt', 'w' );
|
||||
fwrite( $file, serialize($file_info) );
|
||||
fclose( $file );
|
||||
return $this->set_file( $this->get_id().'.txt' );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get the fields of file/url to allow mapping
|
||||
* should return an array
|
||||
|
@ -29,10 +81,18 @@ class Old_Tainacan extends Importer
|
|||
public function get_fields()
|
||||
{
|
||||
$file = new \SplFileObject( $this->tmp_file, 'r' );
|
||||
$json = json_decode($file->fread($file->getSize()), true);
|
||||
$file_content = unserialize($file->fread($file->getSize()));
|
||||
|
||||
$item = $json['items'][0]['item'];
|
||||
return array_keys($item);
|
||||
|
||||
foreach($file_content['meta'] as $tab)
|
||||
{
|
||||
foreach($tab->{"tab-properties"} as $meta)
|
||||
{
|
||||
$fields[] = ['name' => $meta->name, 'type' => $meta->type];
|
||||
}
|
||||
}
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -51,16 +111,17 @@ class Old_Tainacan extends Importer
|
|||
|
||||
// search the index in the file and get values
|
||||
$file = new \SplFileObject( $this->tmp_file, 'r' );
|
||||
$json = json_decode($file->fread($file->getSize()), true);
|
||||
$file_content = unserialize($file->fread($file->getSize()));
|
||||
|
||||
$values = $json['items'][$index]['item'];
|
||||
/*to fix this*/
|
||||
$values = $file_content['items']->items[$index]->item;
|
||||
|
||||
if( count( $headers ) !== count( $values ) ){
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($headers as $header) {
|
||||
$processedItem[ $header ] = $values[ $header ];
|
||||
$processedItem[ $header['name'] ] = $values[ $header['name'] ];
|
||||
}
|
||||
|
||||
return $processedItem;
|
||||
|
@ -68,12 +129,10 @@ class Old_Tainacan extends Importer
|
|||
|
||||
function create_fields_and_mapping() {
|
||||
|
||||
$file = new \SplFileObject( $this->tmp_file, 'r' );
|
||||
$json = json_decode($file->fread($file->getSize()), true);
|
||||
$item = $json['items'][0]['item'];
|
||||
$fields_repository = \Tainacan\Repositories\Fields::get_instance();
|
||||
|
||||
$avoid = [
|
||||
$file_fields = $this->get_fields();
|
||||
/*$avoid = [
|
||||
'ID',
|
||||
'post_author',
|
||||
'post_date',
|
||||
|
@ -94,29 +153,27 @@ class Old_Tainacan extends Importer
|
|||
'filter',
|
||||
'link',
|
||||
'thumbnail'
|
||||
];
|
||||
];*/
|
||||
|
||||
foreach($item as $field_name => $value)
|
||||
foreach($file_fields as $index => $meta_info)
|
||||
{
|
||||
if(!in_array($field_name, $avoid))
|
||||
{
|
||||
$newField = new \Tainacan\Entities\Field();
|
||||
$newField = new \Tainacan\Entities\Field();
|
||||
|
||||
$newField->set_name($field_name);
|
||||
$newField->set_field_type('Tainacan\Field_Types\Text');
|
||||
$newField->set_name($meta_info['name']);
|
||||
|
||||
$newField->set_collection($this->collection);
|
||||
$newField->validate(); // there is no user input here, so we can be sure it will validate.
|
||||
$type = 'Text';
|
||||
|
||||
$newField = $fields_repository->insert($newField);
|
||||
$newField->set_field_type('Tainacan\Field_Types\\'.$type);
|
||||
|
||||
$source_fields = $this->get_fields();
|
||||
$newField->set_collection($this->collection);
|
||||
$newField->validate(); // there is no user input here, so we can be sure it will validate.
|
||||
|
||||
$source_id = array_search($field_name, $source_fields);
|
||||
$this->set_mapping([
|
||||
$newField->get_id() => $source_fields[$source_id]
|
||||
]);
|
||||
}
|
||||
$newField = $fields_repository->insert($newField);
|
||||
|
||||
|
||||
$this->set_mapping([
|
||||
$newField->get_id() => $file_fields[$index]
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -128,8 +185,8 @@ class Old_Tainacan extends Importer
|
|||
public function get_total_items_from_source()
|
||||
{
|
||||
$file = new \SplFileObject( $this->tmp_file, 'r' );
|
||||
$json = json_decode($file->fread($file->getSize()), true);
|
||||
$file_content = unserialize($file->fread($file->getSize()));
|
||||
|
||||
return $this->total_items = $json['found_items'];
|
||||
return $this->total_items = $file_content['items']->found_items;
|
||||
}
|
||||
}
|
|
@ -1,123 +1,131 @@
|
|||
import Vue from 'vue';
|
||||
import store from './store/store'
|
||||
import router from './../admin/js/router.js';
|
||||
export default {
|
||||
|
||||
export const eventBusSearch = new Vue({
|
||||
router,
|
||||
store,
|
||||
data: {
|
||||
componentsTag: [],
|
||||
errors : [],
|
||||
query: {}
|
||||
},
|
||||
created(){
|
||||
this.$on('input', data => {
|
||||
store.dispatch('search/setPage', 1);
|
||||
install(Vue, options = {}) {
|
||||
|
||||
if( data.taxonomy ){
|
||||
this.add_taxquery(data);
|
||||
} else {
|
||||
this.add_metaquery(data);
|
||||
}
|
||||
|
||||
this.updateURLQueries();
|
||||
});
|
||||
},
|
||||
watch: {
|
||||
'$route.query' () {
|
||||
if (this.$route.name == 'CollectionItemsPage' || this.$route.name == 'ItemsPage') {
|
||||
if (this.$route.query.perpage == undefined)
|
||||
this.$route.query.perpage = 12;
|
||||
if (this.$route.query.paged == undefined)
|
||||
this.$route.query.paged = 1;
|
||||
if (this.$route.query.order == undefined)
|
||||
this.$route.query.order = 'DESC';
|
||||
if (this.$route.query.orderby == undefined)
|
||||
this.$route.query.orderby = 'date';
|
||||
|
||||
store.dispatch('search/set_postquery', this.$route.query);
|
||||
//console.log(this.$route.query);
|
||||
this.loadItems();
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
add_metaquery( data ){
|
||||
if ( data && data.collection_id ){
|
||||
store.dispatch('search/add_metaquery', data );
|
||||
}
|
||||
},
|
||||
add_taxquery( data ){
|
||||
if ( data && data.collection_id ){
|
||||
store.dispatch('search/add_taxquery', data );
|
||||
}
|
||||
},
|
||||
getErrors( filter_id ){
|
||||
let error = this.errors.find( errorItem => errorItem.field_id === filter_id );
|
||||
return ( error ) ? error.errors : false
|
||||
},
|
||||
listener(){
|
||||
const components = this.getAllComponents();
|
||||
for (let eventElement of components){
|
||||
eventElement.addEventListener('input', (event) => {
|
||||
if( event.detail ) {
|
||||
this.add_metaquery( event.detail[0] );
|
||||
Vue.prototype.$eventBusSearch = new Vue({
|
||||
router: options.router,
|
||||
store: options.store,
|
||||
data: {
|
||||
componentsTag: [],
|
||||
errors : [],
|
||||
query: {},
|
||||
collectionId: undefined
|
||||
},
|
||||
created(){
|
||||
this.$on('input', data => {
|
||||
this.$store.dispatch('search/setPage', 1);
|
||||
|
||||
if( data.taxonomy ){
|
||||
this.add_taxquery(data);
|
||||
} else {
|
||||
this.add_metaquery(data);
|
||||
}
|
||||
|
||||
this.updateURLQueries();
|
||||
});
|
||||
}
|
||||
},
|
||||
setPage(page) {
|
||||
store.dispatch('search/setPage', page);
|
||||
this.updateURLQueries();
|
||||
},
|
||||
setItemsPerPage(itemsPerPage) {
|
||||
store.dispatch('search/setItemsPerPage', itemsPerPage);
|
||||
this.updateURLQueries();
|
||||
},
|
||||
setOrderBy(newOrderBy) {
|
||||
store.dispatch('search/setOrderBy', newOrderBy);
|
||||
this.updateURLQueries();
|
||||
},
|
||||
setOrder(newOrder) {
|
||||
store.dispatch('search/setOrder', newOrder);
|
||||
this.updateURLQueries();
|
||||
},
|
||||
updateURLQueries() {
|
||||
router.push({ query: {} });
|
||||
router.push({ query: store.getters['search/getPostQuery'] });
|
||||
},
|
||||
updateStoreFromURL() {
|
||||
store.dispatch('search/set_postquery', this.$route.query);
|
||||
},
|
||||
loadItems() {
|
||||
this.$emit( 'isLoadingItems', true);
|
||||
store.dispatch('collection/fetchItems', this.$route.params.collectionId).then((res) => {
|
||||
this.$emit( 'isLoadingItems', false);
|
||||
this.$emit( 'hasFiltered', res.hasFiltered);
|
||||
})
|
||||
.catch(() => {
|
||||
this.$emit( 'isLoadingItems', false);
|
||||
});
|
||||
},
|
||||
},
|
||||
watch: {
|
||||
'$route' () {
|
||||
if (this.$route.params.collectionId)
|
||||
this.collectionId = parseInt(this.$route.params.collectionId);
|
||||
|
||||
if (this.$route.name == null || this.$route.name == undefined || this.$route.name == 'CollectionItemsPage' || this.$route.name == 'ItemsPage') {
|
||||
if (this.$route.query.perpage == undefined)
|
||||
this.$route.query.perpage = 12;
|
||||
if (this.$route.query.paged == undefined)
|
||||
this.$route.query.paged = 1;
|
||||
if (this.$route.query.order == undefined)
|
||||
this.$route.query.order = 'DESC';
|
||||
if (this.$route.query.orderby == undefined)
|
||||
this.$route.query.orderby = 'date';
|
||||
|
||||
/* Dev interfaces methods */
|
||||
|
||||
registerComponent( name ){
|
||||
if (this.componentsTag.indexOf(name) < 0) {
|
||||
this.componentsTag.push( name );
|
||||
}
|
||||
},
|
||||
getAllComponents(){
|
||||
const components = [];
|
||||
for( let component of this.componentsTag ){
|
||||
const eventElements = document.getElementsByTagName( component );
|
||||
if( eventElements ) {
|
||||
for (let eventElement of eventElements){
|
||||
components.push( eventElement );
|
||||
this.$store.dispatch('search/set_postquery', this.$route.query);
|
||||
this.loadItems();
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
add_metaquery( data ){
|
||||
if ( data && data.collection_id ){
|
||||
this.$store.dispatch('search/add_metaquery', data );
|
||||
}
|
||||
},
|
||||
add_taxquery( data ){
|
||||
if ( data && data.collection_id ){
|
||||
this.$store.dispatch('search/add_taxquery', data );
|
||||
}
|
||||
},
|
||||
getErrors( filter_id ){
|
||||
let error = this.errors.find( errorItem => errorItem.field_id === filter_id );
|
||||
return ( error ) ? error.errors : false
|
||||
},
|
||||
listener(){
|
||||
const components = this.getAllComponents();
|
||||
for (let eventElement of components){
|
||||
eventElement.addEventListener('input', (event) => {
|
||||
if( event.detail ) {
|
||||
this.add_metaquery( event.detail[0] );
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
setPage(page) {
|
||||
this.$store.dispatch('search/setPage', page);
|
||||
this.updateURLQueries();
|
||||
},
|
||||
setItemsPerPage(itemsPerPage) {
|
||||
this.$store.dispatch('search/setItemsPerPage', itemsPerPage);
|
||||
this.updateURLQueries();
|
||||
},
|
||||
setOrderBy(newOrderBy) {
|
||||
this.$store.dispatch('search/setOrderBy', newOrderBy);
|
||||
this.updateURLQueries();
|
||||
},
|
||||
setOrder(newOrder) {
|
||||
this.$store.dispatch('search/setOrder', newOrder);
|
||||
this.updateURLQueries();
|
||||
},
|
||||
updateURLQueries() {
|
||||
this.$router.push({ query: {} });
|
||||
this.$router.push({ query: this.$store.getters['search/getPostQuery'] });
|
||||
},
|
||||
updateStoreFromURL() {
|
||||
this.$store.dispatch('search/set_postquery', this.$route.query);
|
||||
},
|
||||
loadItems() {
|
||||
|
||||
this.$emit( 'isLoadingItems', true);
|
||||
this.$store.dispatch('collection/fetchItems', this.collectionId).then((res) => {
|
||||
this.$emit( 'isLoadingItems', false);
|
||||
this.$emit( 'hasFiltered', res.hasFiltered);
|
||||
})
|
||||
.catch(() => {
|
||||
this.$emit( 'isLoadingItems', false);
|
||||
});
|
||||
},
|
||||
setCollectionId(collectionId) {
|
||||
this.collectionId = collectionId;
|
||||
},
|
||||
/* Dev interfaces methods */
|
||||
|
||||
registerComponent( name ){
|
||||
if (this.componentsTag.indexOf(name) < 0) {
|
||||
this.componentsTag.push( name );
|
||||
}
|
||||
},
|
||||
getAllComponents(){
|
||||
const components = [];
|
||||
for( let component of this.componentsTag ){
|
||||
const eventElements = document.getElementsByTagName( component );
|
||||
if( eventElements ) {
|
||||
for (let eventElement of eventElements){
|
||||
components.push( eventElement );
|
||||
}
|
||||
}
|
||||
}
|
||||
return components;
|
||||
},
|
||||
}
|
||||
return components;
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
|
@ -4,7 +4,7 @@ import Buefy from 'buefy'
|
|||
// include vue-custom-element plugin to Vue
|
||||
import VueCustomElement from 'vue-custom-element';
|
||||
import { eventBus } from './event-bus-web-components';
|
||||
import { eventBusSearch } from './event-bus-search';
|
||||
import eventBusSearch from './event-bus-search';
|
||||
|
||||
Vue.use(Buefy);
|
||||
|
||||
|
@ -25,47 +25,48 @@ import FilterAutocomplete from '../classes/filter-types/autocomplete/Autocomplet
|
|||
import FilterCheckbox from '../classes/filter-types/checkbox/Checkbox.vue';
|
||||
import FilterTaginput from '../classes/filter-types/taginput/Taginput.vue';
|
||||
|
||||
Vue.use(eventBusSearch);
|
||||
|
||||
Vue.customElement('tainacan-text', Text);
|
||||
eventBus.registerComponent( 'tainacan-text' );
|
||||
//eventBus.registerComponent( 'tainacan-text' );
|
||||
|
||||
Vue.customElement('tainacan-textarea', Textarea);
|
||||
eventBus.registerComponent( 'tainacan-textarea' );
|
||||
//eventBus.registerComponent( 'tainacan-textarea' );
|
||||
|
||||
Vue.customElement('tainacan-selectbox', Selectbox);
|
||||
eventBus.registerComponent( 'tainacan-selectbox' );
|
||||
//eventBus.registerComponent( 'tainacan-selectbox' );
|
||||
|
||||
Vue.customElement('tainacan-numeric', Numeric);
|
||||
eventBus.registerComponent( 'tainacan-numeric' );
|
||||
//eventBus.registerComponent( 'tainacan-numeric' );
|
||||
|
||||
Vue.customElement('tainacan-date', Date);
|
||||
eventBus.registerComponent( 'tainacan-date' );
|
||||
//eventBus.registerComponent( 'tainacan-date' );
|
||||
|
||||
Vue.customElement('tainacan-relationship', Relationship);
|
||||
eventBus.registerComponent( 'tainacan-relationship' );
|
||||
//eventBus.registerComponent( 'tainacan-relationship' );
|
||||
|
||||
eventBus.listener();
|
||||
//eventBus.listener();
|
||||
|
||||
/* Form */
|
||||
|
||||
Vue.customElement('tainacan-form-relationship', FormRelationship);
|
||||
eventBus.registerComponent( 'tainacan-form-relationship' );
|
||||
//eventBus.registerComponent( 'tainacan-form-relationship' );
|
||||
|
||||
/* Filters */
|
||||
|
||||
Vue.customElement('tainacan-filter-custom-interval', FilterCustomInterval);
|
||||
eventBusSearch.registerComponent( 'tainacan-filter-custom-interval' );
|
||||
//eventBusSearch.registerComponent( 'tainacan-filter-custom-interval' );
|
||||
|
||||
Vue.customElement('tainacan-filter-selectbox', FilterSelectbox);
|
||||
eventBusSearch.registerComponent( 'tainacan-filter-selectbox' );
|
||||
|
||||
//eventBusSearch.registerComponent( 'tainacan-filter-selectbox' );
|
||||
|
||||
Vue.customElement('tainacan-filter-autocomplete', FilterAutocomplete);
|
||||
eventBusSearch.registerComponent( 'tainacan-filter-autocomplete' );
|
||||
//eventBusSearch.registerComponent( 'tainacan-filter-autocomplete' );
|
||||
|
||||
Vue.customElement('tainacan-filter-checkbox', FilterCheckbox);
|
||||
eventBusSearch.registerComponent( 'tainacan-filter-checkbox' );
|
||||
//eventBusSearch.registerComponent( 'tainacan-filter-checkbox' );
|
||||
|
||||
Vue.customElement('tainacan-filter-taginput', FilterTaginput);
|
||||
eventBusSearch.registerComponent( 'tainacan-filter-taginput' );
|
||||
//eventBusSearch.registerComponent( 'tainacan-filter-taginput' );
|
||||
|
||||
eventBusSearch.listener();
|
||||
//eventBusSearch.listener();
|
||||
|
|
|
@ -15,6 +15,7 @@ export const fetchItems = ({ rootGetters, dispatch, commit }, collectionId) => {
|
|||
|
||||
// Differentiates between repository level and collection level queries
|
||||
let endpoint = '/collection/'+collectionId+'/items?'
|
||||
|
||||
if (collectionId == undefined)
|
||||
endpoint = '/items?'
|
||||
|
||||
|
@ -102,15 +103,17 @@ export const deleteCollection = ({ commit }, id) => {
|
|||
});
|
||||
}
|
||||
|
||||
export const updateCollection = ({ commit }, { collection_id, name, description, slug, status }) => {
|
||||
export const updateCollection = ({ commit }, { collection_id, name, description, slug, status, enable_cover_page, cover_page_id }) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.tainacan.patch('/collections/' + collection_id, {
|
||||
name: name,
|
||||
description: description,
|
||||
status: status,
|
||||
slug: slug
|
||||
slug: slug,
|
||||
cover_page_id: "" + cover_page_id,
|
||||
enable_cover_page: enable_cover_page
|
||||
}).then( res => {
|
||||
commit('setCollection', { id: collection_id, name: name, description: description, slug: slug, status: status });
|
||||
commit('setCollection', { id: collection_id, name: name, description: description, slug: slug, status: status, enable_cover_page: enable_cover_page, cover_page_id: cover_page_id });
|
||||
resolve( res.data );
|
||||
}).catch( error => {
|
||||
reject({ error_message: error['response']['data'].error_message, errors: error['response']['data'].errors });
|
||||
|
@ -189,4 +192,46 @@ export const updateThumbnail = ({ commit }, { collectionId, thumbnailId }) => {
|
|||
});
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
export const updateCover = ({ commit }, { collectionId, coverId }) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.tainacan.patch('/collections/' + collectionId, {
|
||||
cover_img_id: coverId
|
||||
}).then( res => {
|
||||
let collection = res.data
|
||||
commit('setCollection', collection);
|
||||
resolve( collection );
|
||||
}).catch( error => {
|
||||
reject({ error_message: error['response']['data'].error_message, errors: error['response']['data'].errors });
|
||||
});
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
// Collection Cover Page
|
||||
export const fetchPages = () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.wp.get('/pages/')
|
||||
.then(res => {
|
||||
let pages = res.data;
|
||||
resolve( pages );
|
||||
})
|
||||
.catch(error => {
|
||||
reject( error );
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export const fetchPage = ({ commit }, pageId ) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.wp.get('/pages/' + pageId)
|
||||
.then(res => {
|
||||
let page = res.data;
|
||||
resolve( page );
|
||||
})
|
||||
.catch(error => {
|
||||
reject( error );
|
||||
});
|
||||
});
|
||||
};
|
|
@ -1,40 +1,5 @@
|
|||
import Vue from 'vue';
|
||||
|
||||
// METAQUERIES ----------------------------------------------------------------------------
|
||||
export const setPostQueryAttribute = ( state, { attr, value }) => {
|
||||
Vue.set( state.postquery, attr , value );
|
||||
};
|
||||
|
||||
export const setPostQuery = ( state, postquery ) => {
|
||||
state.postquery = postquery;
|
||||
};
|
||||
|
||||
export const addMetaQuery = ( state, filter ) => {
|
||||
let index = state.postquery.metaquery.findIndex( item => item.key === filter.field_id);
|
||||
if ( index >= 0){
|
||||
Vue.set( state.postquery.metaquery, index, {
|
||||
key: filter.field_id,
|
||||
value: filter.value,
|
||||
compare: filter.compare,
|
||||
type: filter.type
|
||||
} );
|
||||
}else{
|
||||
state.postquery.metaquery.push({
|
||||
key: filter.field_id,
|
||||
value: filter.value,
|
||||
compare: filter.compare,
|
||||
type: filter.type
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const removeMetaQuery = ( state, filter ) => {
|
||||
let index = state.postquery.metaquery.findIndex( item => item.key === filter.field_id);
|
||||
if (index >= 0) {
|
||||
state.postquery.metaquery.splice(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
// FILTERS ------------------------------------------------------------------------
|
||||
export const deleteFilter = ( state, filter ) => {
|
||||
let index = state.filters.findIndex(deletedFilter => deletedFilter.id === filter.id);
|
||||
|
|
|
@ -0,0 +1,359 @@
|
|||
<!DOCTYPE html>
|
||||
<!--
|
||||
Copyright 2012 Mozilla Foundation
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
Adobe CMap resources are covered by their own copyright but the same license:
|
||||
|
||||
Copyright 1990-2015 Adobe Systems Incorporated.
|
||||
|
||||
See https://github.com/adobe-type-tools/cmap-resources
|
||||
-->
|
||||
<html dir="ltr" mozdisallowselectionprint moznomarginboxes>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
|
||||
<meta name="google" content="notranslate">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<title>PDF.js viewer</title>
|
||||
|
||||
|
||||
<link rel="stylesheet" href="pdfjs-dist/web/viewer.css">
|
||||
|
||||
|
||||
|
||||
<!-- This snippet is used in production (included from viewer.html) -->
|
||||
<link rel="resource" type="application/l10n" href="pdfjs-dist/web/locale/locale.properties">
|
||||
<script src="pdfjs-dist/build/pdf.js"></script>
|
||||
|
||||
|
||||
<script src="pdf-viewer.js"></script>
|
||||
|
||||
</head>
|
||||
|
||||
<body tabindex="1" class="loadingInProgress">
|
||||
<div id="outerContainer">
|
||||
|
||||
<div id="sidebarContainer">
|
||||
<div id="toolbarSidebar">
|
||||
<div class="splitToolbarButton toggled">
|
||||
<button id="viewThumbnail" class="toolbarButton toggled" title="Show Thumbnails" tabindex="2" data-l10n-id="thumbs">
|
||||
<span data-l10n-id="thumbs_label">Thumbnails</span>
|
||||
</button>
|
||||
<button id="viewOutline" class="toolbarButton" title="Show Document Outline (double-click to expand/collapse all items)" tabindex="3" data-l10n-id="document_outline">
|
||||
<span data-l10n-id="document_outline_label">Document Outline</span>
|
||||
</button>
|
||||
<button id="viewAttachments" class="toolbarButton" title="Show Attachments" tabindex="4" data-l10n-id="attachments">
|
||||
<span data-l10n-id="attachments_label">Attachments</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div id="sidebarContent">
|
||||
<div id="thumbnailView">
|
||||
</div>
|
||||
<div id="outlineView" class="hidden">
|
||||
</div>
|
||||
<div id="attachmentsView" class="hidden">
|
||||
</div>
|
||||
</div>
|
||||
</div> <!-- sidebarContainer -->
|
||||
|
||||
<div id="mainContainer">
|
||||
<div class="findbar hidden doorHanger" id="findbar">
|
||||
<div id="findbarInputContainer">
|
||||
<input id="findInput" class="toolbarField" title="Find" placeholder="Find in document…" tabindex="91" data-l10n-id="find_input">
|
||||
<div class="splitToolbarButton">
|
||||
<button id="findPrevious" class="toolbarButton findPrevious" title="Find the previous occurrence of the phrase" tabindex="92" data-l10n-id="find_previous">
|
||||
<span data-l10n-id="find_previous_label">Previous</span>
|
||||
</button>
|
||||
<div class="splitToolbarButtonSeparator"></div>
|
||||
<button id="findNext" class="toolbarButton findNext" title="Find the next occurrence of the phrase" tabindex="93" data-l10n-id="find_next">
|
||||
<span data-l10n-id="find_next_label">Next</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="findbarOptionsContainer">
|
||||
<input type="checkbox" id="findHighlightAll" class="toolbarField" tabindex="94">
|
||||
<label for="findHighlightAll" class="toolbarLabel" data-l10n-id="find_highlight">Highlight all</label>
|
||||
<input type="checkbox" id="findMatchCase" class="toolbarField" tabindex="95">
|
||||
<label for="findMatchCase" class="toolbarLabel" data-l10n-id="find_match_case_label">Match case</label>
|
||||
<span id="findResultsCount" class="toolbarLabel hidden"></span>
|
||||
</div>
|
||||
|
||||
<div id="findbarMessageContainer">
|
||||
<span id="findMsg" class="toolbarLabel"></span>
|
||||
</div>
|
||||
</div> <!-- findbar -->
|
||||
|
||||
<div id="secondaryToolbar" class="secondaryToolbar hidden doorHangerRight">
|
||||
<div id="secondaryToolbarButtonContainer">
|
||||
<button id="secondaryPresentationMode" class="secondaryToolbarButton presentationMode visibleLargeView" title="Switch to Presentation Mode" tabindex="51" data-l10n-id="presentation_mode">
|
||||
<span data-l10n-id="presentation_mode_label">Presentation Mode</span>
|
||||
</button>
|
||||
|
||||
<button id="secondaryOpenFile" class="secondaryToolbarButton openFile visibleLargeView" title="Open File" tabindex="52" data-l10n-id="open_file">
|
||||
<span data-l10n-id="open_file_label">Open</span>
|
||||
</button>
|
||||
|
||||
<button id="secondaryPrint" class="secondaryToolbarButton print visibleMediumView" title="Print" tabindex="53" data-l10n-id="print">
|
||||
<span data-l10n-id="print_label">Print</span>
|
||||
</button>
|
||||
|
||||
<button id="secondaryDownload" class="secondaryToolbarButton download visibleMediumView" title="Download" tabindex="54" data-l10n-id="download">
|
||||
<span data-l10n-id="download_label">Download</span>
|
||||
</button>
|
||||
|
||||
<a href="#" id="secondaryViewBookmark" class="secondaryToolbarButton bookmark visibleSmallView" title="Current view (copy or open in new window)" tabindex="55" data-l10n-id="bookmark">
|
||||
<span data-l10n-id="bookmark_label">Current View</span>
|
||||
</a>
|
||||
|
||||
<div class="horizontalToolbarSeparator visibleLargeView"></div>
|
||||
|
||||
<button id="firstPage" class="secondaryToolbarButton firstPage" title="Go to First Page" tabindex="56" data-l10n-id="first_page">
|
||||
<span data-l10n-id="first_page_label">Go to First Page</span>
|
||||
</button>
|
||||
<button id="lastPage" class="secondaryToolbarButton lastPage" title="Go to Last Page" tabindex="57" data-l10n-id="last_page">
|
||||
<span data-l10n-id="last_page_label">Go to Last Page</span>
|
||||
</button>
|
||||
|
||||
<div class="horizontalToolbarSeparator"></div>
|
||||
|
||||
<button id="pageRotateCw" class="secondaryToolbarButton rotateCw" title="Rotate Clockwise" tabindex="58" data-l10n-id="page_rotate_cw">
|
||||
<span data-l10n-id="page_rotate_cw_label">Rotate Clockwise</span>
|
||||
</button>
|
||||
<button id="pageRotateCcw" class="secondaryToolbarButton rotateCcw" title="Rotate Counterclockwise" tabindex="59" data-l10n-id="page_rotate_ccw">
|
||||
<span data-l10n-id="page_rotate_ccw_label">Rotate Counterclockwise</span>
|
||||
</button>
|
||||
|
||||
<div class="horizontalToolbarSeparator"></div>
|
||||
|
||||
<button id="cursorSelectTool" class="secondaryToolbarButton selectTool toggled" title="Enable Text Selection Tool" tabindex="60" data-l10n-id="cursor_text_select_tool">
|
||||
<span data-l10n-id="cursor_text_select_tool_label">Text Selection Tool</span>
|
||||
</button>
|
||||
<button id="cursorHandTool" class="secondaryToolbarButton handTool" title="Enable Hand Tool" tabindex="61" data-l10n-id="cursor_hand_tool">
|
||||
<span data-l10n-id="cursor_hand_tool_label">Hand Tool</span>
|
||||
</button>
|
||||
|
||||
<div class="horizontalToolbarSeparator"></div>
|
||||
|
||||
<button id="documentProperties" class="secondaryToolbarButton documentProperties" title="Document Properties…" tabindex="62" data-l10n-id="document_properties">
|
||||
<span data-l10n-id="document_properties_label">Document Properties…</span>
|
||||
</button>
|
||||
</div>
|
||||
</div> <!-- secondaryToolbar -->
|
||||
|
||||
<div class="toolbar">
|
||||
<div id="toolbarContainer">
|
||||
<div id="toolbarViewer">
|
||||
<div id="toolbarViewerLeft">
|
||||
<button id="sidebarToggle" class="toolbarButton" title="Toggle Sidebar" tabindex="11" data-l10n-id="toggle_sidebar">
|
||||
<span data-l10n-id="toggle_sidebar_label">Toggle Sidebar</span>
|
||||
</button>
|
||||
<div class="toolbarButtonSpacer"></div>
|
||||
<button id="viewFind" class="toolbarButton" title="Find in Document" tabindex="12" data-l10n-id="findbar">
|
||||
<span data-l10n-id="findbar_label">Find</span>
|
||||
</button>
|
||||
<div class="splitToolbarButton hiddenSmallView">
|
||||
<button class="toolbarButton pageUp" title="Previous Page" id="previous" tabindex="13" data-l10n-id="previous">
|
||||
<span data-l10n-id="previous_label">Previous</span>
|
||||
</button>
|
||||
<div class="splitToolbarButtonSeparator"></div>
|
||||
<button class="toolbarButton pageDown" title="Next Page" id="next" tabindex="14" data-l10n-id="next">
|
||||
<span data-l10n-id="next_label">Next</span>
|
||||
</button>
|
||||
</div>
|
||||
<input type="number" id="pageNumber" class="toolbarField pageNumber" title="Page" value="1" size="4" min="1" tabindex="15" data-l10n-id="page">
|
||||
<span id="numPages" class="toolbarLabel"></span>
|
||||
</div>
|
||||
<div id="toolbarViewerRight">
|
||||
<button id="presentationMode" class="toolbarButton presentationMode hiddenLargeView" title="Switch to Presentation Mode" tabindex="31" data-l10n-id="presentation_mode">
|
||||
<span data-l10n-id="presentation_mode_label">Presentation Mode</span>
|
||||
</button>
|
||||
|
||||
<button id="openFile" class="toolbarButton openFile hiddenLargeView" title="Open File" tabindex="32" data-l10n-id="open_file">
|
||||
<span data-l10n-id="open_file_label">Open</span>
|
||||
</button>
|
||||
|
||||
<button id="print" class="toolbarButton print hiddenMediumView" title="Print" tabindex="33" data-l10n-id="print">
|
||||
<span data-l10n-id="print_label">Print</span>
|
||||
</button>
|
||||
|
||||
<button id="download" class="toolbarButton download hiddenMediumView" title="Download" tabindex="34" data-l10n-id="download">
|
||||
<span data-l10n-id="download_label">Download</span>
|
||||
</button>
|
||||
<a href="#" id="viewBookmark" class="toolbarButton bookmark hiddenSmallView" title="Current view (copy or open in new window)" tabindex="35" data-l10n-id="bookmark">
|
||||
<span data-l10n-id="bookmark_label">Current View</span>
|
||||
</a>
|
||||
|
||||
<div class="verticalToolbarSeparator hiddenSmallView"></div>
|
||||
|
||||
<button id="secondaryToolbarToggle" class="toolbarButton" title="Tools" tabindex="36" data-l10n-id="tools">
|
||||
<span data-l10n-id="tools_label">Tools</span>
|
||||
</button>
|
||||
</div>
|
||||
<div id="toolbarViewerMiddle">
|
||||
<div class="splitToolbarButton">
|
||||
<button id="zoomOut" class="toolbarButton zoomOut" title="Zoom Out" tabindex="21" data-l10n-id="zoom_out">
|
||||
<span data-l10n-id="zoom_out_label">Zoom Out</span>
|
||||
</button>
|
||||
<div class="splitToolbarButtonSeparator"></div>
|
||||
<button id="zoomIn" class="toolbarButton zoomIn" title="Zoom In" tabindex="22" data-l10n-id="zoom_in">
|
||||
<span data-l10n-id="zoom_in_label">Zoom In</span>
|
||||
</button>
|
||||
</div>
|
||||
<span id="scaleSelectContainer" class="dropdownToolbarButton">
|
||||
<select id="scaleSelect" title="Zoom" tabindex="23" data-l10n-id="zoom">
|
||||
<option id="pageAutoOption" title="" value="auto" selected="selected" data-l10n-id="page_scale_auto">Automatic Zoom</option>
|
||||
<option id="pageActualOption" title="" value="page-actual" data-l10n-id="page_scale_actual">Actual Size</option>
|
||||
<option id="pageFitOption" title="" value="page-fit" data-l10n-id="page_scale_fit">Page Fit</option>
|
||||
<option id="pageWidthOption" title="" value="page-width" data-l10n-id="page_scale_width">Page Width</option>
|
||||
<option id="customScaleOption" title="" value="custom" disabled="disabled" hidden="true"></option>
|
||||
<option title="" value="0.5" data-l10n-id="page_scale_percent" data-l10n-args='{ "scale": 50 }'>50%</option>
|
||||
<option title="" value="0.75" data-l10n-id="page_scale_percent" data-l10n-args='{ "scale": 75 }'>75%</option>
|
||||
<option title="" value="1" data-l10n-id="page_scale_percent" data-l10n-args='{ "scale": 100 }'>100%</option>
|
||||
<option title="" value="1.25" data-l10n-id="page_scale_percent" data-l10n-args='{ "scale": 125 }'>125%</option>
|
||||
<option title="" value="1.5" data-l10n-id="page_scale_percent" data-l10n-args='{ "scale": 150 }'>150%</option>
|
||||
<option title="" value="2" data-l10n-id="page_scale_percent" data-l10n-args='{ "scale": 200 }'>200%</option>
|
||||
<option title="" value="3" data-l10n-id="page_scale_percent" data-l10n-args='{ "scale": 300 }'>300%</option>
|
||||
<option title="" value="4" data-l10n-id="page_scale_percent" data-l10n-args='{ "scale": 400 }'>400%</option>
|
||||
</select>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div id="loadingBar">
|
||||
<div class="progress">
|
||||
<div class="glimmer">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<menu type="context" id="viewerContextMenu">
|
||||
<menuitem id="contextFirstPage" label="First Page"
|
||||
data-l10n-id="first_page"></menuitem>
|
||||
<menuitem id="contextLastPage" label="Last Page"
|
||||
data-l10n-id="last_page"></menuitem>
|
||||
<menuitem id="contextPageRotateCw" label="Rotate Clockwise"
|
||||
data-l10n-id="page_rotate_cw"></menuitem>
|
||||
<menuitem id="contextPageRotateCcw" label="Rotate Counter-Clockwise"
|
||||
data-l10n-id="page_rotate_ccw"></menuitem>
|
||||
</menu>
|
||||
|
||||
<div id="viewerContainer" tabindex="0">
|
||||
<div id="viewer" class="pdfViewer"></div>
|
||||
</div>
|
||||
|
||||
<div id="errorWrapper" hidden='true'>
|
||||
<div id="errorMessageLeft">
|
||||
<span id="errorMessage"></span>
|
||||
<button id="errorShowMore" data-l10n-id="error_more_info">
|
||||
More Information
|
||||
</button>
|
||||
<button id="errorShowLess" data-l10n-id="error_less_info" hidden='true'>
|
||||
Less Information
|
||||
</button>
|
||||
</div>
|
||||
<div id="errorMessageRight">
|
||||
<button id="errorClose" data-l10n-id="error_close">
|
||||
Close
|
||||
</button>
|
||||
</div>
|
||||
<div class="clearBoth"></div>
|
||||
<textarea id="errorMoreInfo" hidden='true' readonly="readonly"></textarea>
|
||||
</div>
|
||||
</div> <!-- mainContainer -->
|
||||
|
||||
<div id="overlayContainer" class="hidden">
|
||||
<div id="passwordOverlay" class="container hidden">
|
||||
<div class="dialog">
|
||||
<div class="row">
|
||||
<p id="passwordText" data-l10n-id="password_label">Enter the password to open this PDF file:</p>
|
||||
</div>
|
||||
<div class="row">
|
||||
<input type="password" id="password" class="toolbarField">
|
||||
</div>
|
||||
<div class="buttonRow">
|
||||
<button id="passwordCancel" class="overlayButton"><span data-l10n-id="password_cancel">Cancel</span></button>
|
||||
<button id="passwordSubmit" class="overlayButton"><span data-l10n-id="password_ok">OK</span></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="documentPropertiesOverlay" class="container hidden">
|
||||
<div class="dialog">
|
||||
<div class="row">
|
||||
<span data-l10n-id="document_properties_file_name">File name:</span> <p id="fileNameField">-</p>
|
||||
</div>
|
||||
<div class="row">
|
||||
<span data-l10n-id="document_properties_file_size">File size:</span> <p id="fileSizeField">-</p>
|
||||
</div>
|
||||
<div class="separator"></div>
|
||||
<div class="row">
|
||||
<span data-l10n-id="document_properties_title">Title:</span> <p id="titleField">-</p>
|
||||
</div>
|
||||
<div class="row">
|
||||
<span data-l10n-id="document_properties_author">Author:</span> <p id="authorField">-</p>
|
||||
</div>
|
||||
<div class="row">
|
||||
<span data-l10n-id="document_properties_subject">Subject:</span> <p id="subjectField">-</p>
|
||||
</div>
|
||||
<div class="row">
|
||||
<span data-l10n-id="document_properties_keywords">Keywords:</span> <p id="keywordsField">-</p>
|
||||
</div>
|
||||
<div class="row">
|
||||
<span data-l10n-id="document_properties_creation_date">Creation Date:</span> <p id="creationDateField">-</p>
|
||||
</div>
|
||||
<div class="row">
|
||||
<span data-l10n-id="document_properties_modification_date">Modification Date:</span> <p id="modificationDateField">-</p>
|
||||
</div>
|
||||
<div class="row">
|
||||
<span data-l10n-id="document_properties_creator">Creator:</span> <p id="creatorField">-</p>
|
||||
</div>
|
||||
<div class="separator"></div>
|
||||
<div class="row">
|
||||
<span data-l10n-id="document_properties_producer">PDF Producer:</span> <p id="producerField">-</p>
|
||||
</div>
|
||||
<div class="row">
|
||||
<span data-l10n-id="document_properties_version">PDF Version:</span> <p id="versionField">-</p>
|
||||
</div>
|
||||
<div class="row">
|
||||
<span data-l10n-id="document_properties_page_count">Page Count:</span> <p id="pageCountField">-</p>
|
||||
</div>
|
||||
<div class="buttonRow">
|
||||
<button id="documentPropertiesClose" class="overlayButton"><span data-l10n-id="document_properties_close">Close</span></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="printServiceOverlay" class="container hidden">
|
||||
<div class="dialog">
|
||||
<div class="row">
|
||||
<span data-l10n-id="print_progress_message">Preparing document for printing…</span>
|
||||
</div>
|
||||
<div class="row">
|
||||
<progress value="0" max="100"></progress>
|
||||
<span data-l10n-id="print_progress_percent" data-l10n-args='{ "progress": 0 }' class="relative-progress">0%</span>
|
||||
</div>
|
||||
<div class="buttonRow">
|
||||
<button id="printCancel" class="overlayButton"><span data-l10n-id="print_progress_close">Cancel</span></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div> <!-- overlayContainer -->
|
||||
|
||||
</div> <!-- outerContainer -->
|
||||
<div id="printContainer"></div>
|
||||
</body>
|
||||
</html>
|
||||
|
File diff suppressed because it is too large
Load Diff
|
@ -40,8 +40,11 @@ class Theme_Helper {
|
|||
}
|
||||
|
||||
public function print_scripts() {
|
||||
global $TAINACAN_BASE_URL;
|
||||
if ( is_post_type_archive( \Tainacan\Repositories\Repository::get_collections_db_identifiers() ) ) {
|
||||
\Tainacan\Admin::get_instance()->add_admin_js();
|
||||
//\Tainacan\Admin::get_instance()->add_admin_js();
|
||||
wp_enqueue_script('tainacan-search', $TAINACAN_BASE_URL . '/assets/user_search-components.js' , [] , null, true);
|
||||
wp_localize_script('tainacan-search', 'tainacan_plugin', \Tainacan\Admin::get_instance()->get_admin_js_localization_params());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan;
|
||||
use Tainacan\Entities;
|
||||
use \Tainacan\Entities;
|
||||
use \Tainacan\Repositories;
|
||||
|
||||
/**
|
||||
* To be used inside The Loop
|
||||
|
@ -17,7 +17,7 @@ use Tainacan\Entities;
|
|||
* @param bool $hide_empty Wether to hide or not fields the item has no value to
|
||||
* @return string The HTML output
|
||||
*/
|
||||
function get_tainacan_the_metadata($field = null, $hide_empty = true) {
|
||||
function tainacan_get_the_metadata($field = null, $hide_empty = true) {
|
||||
$post = get_post();
|
||||
$theme_helper = \Tainacan\Theme_Helper::get_instance();
|
||||
|
||||
|
@ -32,4 +32,13 @@ function get_tainacan_the_metadata($field = null, $hide_empty = true) {
|
|||
|
||||
function tainacan_the_metadata($field = null, $hide_empty = true) {
|
||||
echo get_tainacan_the_metadata($field, $hide_empty);
|
||||
}
|
||||
|
||||
/**
|
||||
* When visiting a collection archive or single, returns the current collection id
|
||||
*
|
||||
* @uses get_post_type() WordPress function, which looks for the global $wp_query variable
|
||||
*/
|
||||
function tainacan_get_collection_id() {
|
||||
return Repositories\Collections::get_instance()->get_id_by_db_identifier(get_post_type());
|
||||
}
|
|
@ -24,6 +24,8 @@ class DefaultCapabilities extends TAINACAN_UnitTestCase {
|
|||
|
||||
$defaults_caps = $Tainacan_Capabilities->defaults;
|
||||
|
||||
$tainacan_roles = $Tainacan_Capabilities->get_tainacan_roles();
|
||||
|
||||
foreach ($defaults_caps as $post_type => $wp_append_roles) {
|
||||
if($post_type == 'tainacan-items') continue;
|
||||
$entity = Repository::get_entity_by_post_type($post_type);
|
||||
|
@ -42,8 +44,10 @@ class DefaultCapabilities extends TAINACAN_UnitTestCase {
|
|||
$new_user = $this->factory()->user->create(array( 'role' => 'tainacan-' . $role_name ));
|
||||
wp_set_current_user($new_user);
|
||||
|
||||
foreach ($caps as $cap) {
|
||||
$this->assertTrue(current_user_can($entity_cap->$cap), "tainacan-$role_name does not have capability {$entity_cap->$cap}");
|
||||
if(in_array($role_name, $tainacan_roles) ) {
|
||||
foreach ($caps as $cap) {
|
||||
$this->assertTrue(current_user_can($entity_cap->$cap), "tainacan-$role_name does not have capability {$entity_cap->$cap}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ class ImporterTests extends TAINACAN_UnitTestCase {
|
|||
$this->assertEquals( $collection->get_id(), $_SESSION['tainacan_importer'][$id]->collection->get_id() );
|
||||
}
|
||||
|
||||
public function test_automapping_old_tainacan()
|
||||
/*public function test_automapping_old_tainacan()
|
||||
{
|
||||
$Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
|
||||
$Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
|
||||
|
@ -47,7 +47,7 @@ class ImporterTests extends TAINACAN_UnitTestCase {
|
|||
$_SESSION['tainacan_importer'][$id]->set_file( './tests/attachment/json_old_tainacan.txt' );
|
||||
|
||||
$_SESSION['tainacan_importer'][$id]->run();
|
||||
}
|
||||
}*/
|
||||
|
||||
public function test_file_old_tainacan () {
|
||||
$Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
|
||||
|
@ -63,14 +63,16 @@ class ImporterTests extends TAINACAN_UnitTestCase {
|
|||
return false;
|
||||
}
|
||||
|
||||
$_SESSION['tainacan_importer'][$id]->set_file( './tests/attachment/json_old_tainacan.txt' );
|
||||
//$_SESSION['tainacan_importer'][$id]->set_file( './tests/attachment/json_old_tainacan.txt' );
|
||||
|
||||
//$_SESSION['tainacan_importer'][$id]->fetch_from_remote( 'http://localhost/wp-json/tainacan/v1/collections/970/items' );
|
||||
$_SESSION['tainacan_importer'][$id]->fetch_from_remote( 'http://localhost/colecao/colecao-to-import/' );
|
||||
|
||||
// file isset on importer
|
||||
$this->assertTrue( isset( $_SESSION['tainacan_importer'][$id]->tmp_file ) );
|
||||
|
||||
// count size of old tainacan file
|
||||
$_SESSION['tainacan_importer'][$id]->run();
|
||||
/*// count size of old tainacan file
|
||||
$this->assertEquals( 5, $_SESSION['tainacan_importer'][$id]->get_total_items() );
|
||||
|
||||
// get fields to mapping
|
||||
|
@ -117,7 +119,7 @@ class ImporterTests extends TAINACAN_UnitTestCase {
|
|||
|
||||
$items = $Tainacan_Items->fetch( [], $collection, 'OBJECT' );
|
||||
|
||||
$this->assertEquals( $_SESSION['tainacan_importer'][$id]->get_total_items(), count( $items ) );
|
||||
$this->assertEquals( $_SESSION['tainacan_importer'][$id]->get_total_items(), count( $items ) );*/
|
||||
}
|
||||
/**
|
||||
* @group importer
|
||||
|
|
|
@ -22,7 +22,6 @@ class Logs extends TAINACAN_UnitTestCase {
|
|||
*/
|
||||
function test_add() {
|
||||
$Tainacan_Logs = \Tainacan\Repositories\Logs::get_instance();
|
||||
$Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance();
|
||||
|
||||
$log = $this->tainacan_entity_factory->create_entity(
|
||||
'log',
|
||||
|
@ -43,44 +42,6 @@ class Logs extends TAINACAN_UnitTestCase {
|
|||
$this->assertEquals( 'someone did that', $test->get_description() );
|
||||
$this->assertEquals( $user_id, $test->get_user_id() );
|
||||
$this->assertEquals( $blog_id, $test->get_blog_id() );
|
||||
|
||||
$value = $this->tainacan_entity_factory->create_entity(
|
||||
'collection',
|
||||
array(
|
||||
'name' => 'testeLogs',
|
||||
'description' => 'adasdasdsa123',
|
||||
'default_order' => 'DESC'
|
||||
),
|
||||
true
|
||||
);
|
||||
|
||||
$old_value = $value;
|
||||
|
||||
$value->set_name( 'newtesteLogs' );
|
||||
|
||||
$new_value = $Tainacan_Collections->update( $value );
|
||||
|
||||
$create_log = Log::create( 'teste create', 'testing a log creation function', $new_value, $old_value );
|
||||
|
||||
$this->assertEquals( 'teste create', $create_log->get_title() );
|
||||
$this->assertEquals( 'testing a log creation function', $create_log->get_description() );
|
||||
$this->assertEquals( $new_value, $create_log->get_value() );
|
||||
$this->assertEquals( $old_value, $create_log->get_old_value() );
|
||||
|
||||
$testDB = $Tainacan_Logs->fetch( $create_log->get_id() );
|
||||
|
||||
$this->assertEquals( 'teste create', $testDB->get_title() );
|
||||
$this->assertEquals( 'testing a log creation function', $testDB->get_description() );
|
||||
$this->assertEquals( $new_value, $testDB->get_value() );
|
||||
$this->assertEquals( $old_value, $testDB->get_old_value() );
|
||||
|
||||
$last_log = $Tainacan_Logs->fetch_last();
|
||||
|
||||
$collection = $last_log->get_value();
|
||||
|
||||
$this->assertEquals( 'newtesteLogs', $collection->get_name() );
|
||||
$this->assertEquals( 'adasdasdsa123', $collection->get_description() );
|
||||
$this->assertEquals( 'DESC', $collection->get_default_order() );
|
||||
}
|
||||
|
||||
public function test_log_diff() {
|
||||
|
@ -102,7 +63,7 @@ class Logs extends TAINACAN_UnitTestCase {
|
|||
|
||||
$log = $Tainacan_Logs->fetch_last();
|
||||
|
||||
$diff = $log->diff();
|
||||
$diff = $log->get_log_diffs();
|
||||
|
||||
$this->assertEquals( 'With name', "{$diff['name']['new'][0]} {$diff['name']['new'][1]}" );
|
||||
$this->assertEquals( 'No name', $diff['name']['old'] );
|
||||
|
|
|
@ -4,6 +4,7 @@ let webpack = require('webpack');
|
|||
module.exports = {
|
||||
entry: {
|
||||
dev_admin: './src/js/main.js',
|
||||
user_search: './src/admin/js/theme-main.js',
|
||||
user_admin: './src/admin/js/main.js'
|
||||
},
|
||||
output: {
|
||||
|
|
Loading…
Reference in New Issue