Skip to content

Commit

Permalink
Fixes #537 by adding the filters that allow the implementation of Cro…
Browse files Browse the repository at this point in the history
…ss-PTEs
  • Loading branch information
akirk committed Nov 29, 2016
1 parent c198aeb commit b74848e
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 12 deletions.
12 changes: 7 additions & 5 deletions gp-includes/routes/translation.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,13 @@ public function translations_post( $project_path, $locale_slug, $translation_set
$data[ "translation_$i" ] = $translations[ $i ];
}
}
$set_status = $data['status'];
$data['status'] = 'waiting';

if ( $this->can( 'approve', 'translation-set', $translation_set->id ) || $this->can( 'write', 'project', $project->id ) )
$data['status'] = 'current';
$set_status = 'current';
else
$data['status'] = 'waiting';
$set_status = 'waiting';

$original = GP::$original->get( $original_id );
$data['warnings'] = GP::$translation_warnings->check( $original->singular, $original->plural, $translations, $locale );
Expand Down Expand Up @@ -299,7 +301,7 @@ public function translations_post( $project_path, $locale_slug, $translation_set
return $this->die_with_error( $error_output, 200 );
}
else {
if ( 'current' == $data['status'] ) {
if ( 'current' === $set_status ) {
$translation->set_status( 'current' );
}

Expand All @@ -310,7 +312,7 @@ public function translations_post( $project_path, $locale_slug, $translation_set

$can_edit = $this->can( 'edit', 'translation-set', $translation_set->id );
$can_write = $this->can( 'write', 'project', $project->id );
$can_approve = $this->can( 'approve', 'translation-set', $translation_set->id );
$can_approve = $this->can( 'approve', 'translation-set', $translation_set->id ) && apply_filters( 'gp_current_user_can_set_translation_status', 'current', $t );
$output[$original_id] = gp_tmpl_get_output( 'translation-row', get_defined_vars() );
}
else {
Expand Down Expand Up @@ -524,7 +526,7 @@ private function edit_single_translation( $project_path, $locale_slug, $translat

$can_edit = $this->can( 'edit', 'translation-set', $translation_set->id );
$can_write = $this->can( 'write', 'project', $project->id );
$can_approve = $this->can( 'approve', 'translation-set', $translation_set->id );
$can_approve = $this->can( 'approve', 'translation-set', $translation_set->id ) && apply_filters( 'gp_current_user_can_set_translation_status', 'current', $t );
$this->tmpl( 'translation-row', get_defined_vars() );
} else {
return $this->die_with_error( 'Error in retrieving translation!' );
Expand Down
14 changes: 8 additions & 6 deletions gp-includes/things/translation-set.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,13 @@ public function import( $translations, $desired_status = 'current' ) {
/**
* Filter the the status of imported translations of a translation set.
*
* @since 1.0.0
* @since 2.2.0
*
* @param string $status The status of imported translations.
* @param Translation_Entry $entry Translation entry object to import.
* @param GP_Translation|false $translated The previous translation.
*/
$entry->status = apply_filters( 'gp_translation_set_import_status', $is_fuzzy ? 'fuzzy' : $desired_status );
$entry->status = apply_filters( 'gp_translation_set_import_status', $is_fuzzy ? 'fuzzy' : $desired_status, $entry, false );

$entry->warnings = maybe_unserialize( GP::$translation_warnings->check( $entry->singular, $entry->plural, $entry->translations, $locale ) );
if ( ! empty( $entry->warnings ) ) {
Expand Down Expand Up @@ -314,13 +316,13 @@ public function import( $translations, $desired_status = 'current' ) {
/**
* Filter the the status of imported translations of a translation set.
*
* @since 1.0.0
* @since 2.2.0
*
* @param string $status The status of imported translations.
* @param string $status The status of imported translations.
* @param Translation_Entry $entry Translation entry object to import.
* @param GP_Translation|false $translated The previous translation.
*/
$entry->status = apply_filters( 'gp_translation_set_import_status', $entry->status, $entry );

$entry->status = apply_filters( 'gp_translation_set_import_status', $entry->status, $entry, $translated );
// Check for errors.
$translation = GP::$translation->create( $entry );
if ( is_object( $translation ) ) {
Expand Down
13 changes: 12 additions & 1 deletion gp-includes/things/translation.php
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,18 @@ public function reject() {
}

public function set_status( $status ) {
if ( 'current' == $status ) {
/**
* Allows overriding whether the current user can set a translation to a status.
*
* @since 2.2.0
*
* @param string $status The status the translation is to be set to.
* @param GP_Translation $translated The translation in question.
*/
if ( ! apply_filters( 'gp_current_user_can_set_translation_status', $status, $this ) ) {
return false;
}
if ( 'current' === $status ) {
$updated = $this->set_as_current();
} else {
$updated = $this->save( array( 'user_id_last_modified' => get_current_user_id(), 'status' => $status ) );
Expand Down
1 change: 1 addition & 0 deletions gp-templates/translation-row.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

<tr class="preview <?php gp_translation_row_classes( $t ); ?>" id="preview-<?php echo esc_attr( $t->row_id ) ?>" row="<?php echo esc_attr( $t->row_id ); ?>">
<?php if ( $can_approve ) : ?><th scope="row" class="checkbox"><input type="checkbox" name="selected-row[]" /></th><?php endif; ?>
<?php if ( isset( $can_approve_translation_set ) && ! $can_approve && $can_approve_translation_set ) : ?><th scope="row"></th><?php endif; ?>
<?php /*
<td class="priority" style="background-color: <?php echo $priority_char[$t->priority][1] ?>; color: <?php echo $priority_char[$t->priority][2] ?>; text-align: center; font-size: 1.2em;" title="<?php echo esc_attr('Priority: '.gp_array_get( GP::$original->get_static( 'priorities' ), $t->priority )); ?>">
*/ ?>
Expand Down
3 changes: 3 additions & 0 deletions gp-templates/translations.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,15 @@
if ( $glossary ) {
$translations = map_glossary_entries_to_translations_originals( $translations, $glossary );
}
$can_approve_translation_set = $can_approve;
?>
<?php foreach( $translations as $t ):
$can_approve = $can_approve_translation_set && apply_filters( 'gp_current_user_can_set_translation_status', 'current', $t );
gp_tmpl_load( 'translation-row', get_defined_vars() );
?>
<?php endforeach; ?>
<?php
$can_approve = $can_approve_translation_set;
if ( !$translations ):
?>
<tr><td colspan="<?php echo $can_approve ? 5 : 4; ?>"><?php _e( 'No translations were found!', 'glotpress' ); ?></td></tr>
Expand Down

0 comments on commit b74848e

Please sign in to comment.