Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions lib/Model/Chunks/ChunkCompletionEventDao.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,22 @@ public static function createFromChunk( $chunk, CompletionEventStruct $params )
return $conn->lastInsertId();
}


/**
* @param Jobs_JobStruct $chunk
* @return string
* @throws Exception
*/
public function currentPhase( Jobs_JobStruct $chunk ) {
$lastTranslate = $this->lastCompletionRecord( $chunk, [ 'is_review' => false ] );

if ( $lastTranslate ) {
$lastRevise = $this->lastCompletionRecord( $chunk, [ 'is_review' => true ] );

if ( $lastRevise && new DateTime( $lastTranslate[ 'create_date' ] ) < new DateTime( $lastRevise[ 'create_date' ] ) ) {
return self::TRANSLATE;
} else {
return self::REVISE;
}

return self::REVISE;
}

return self::TRANSLATE;
Expand Down
8 changes: 6 additions & 2 deletions lib/Model/Translations/SegmentTranslationDao.php
Original file line number Diff line number Diff line change
Expand Up @@ -806,8 +806,7 @@ static function rebuildFromReplaceEvents( $events ) {
* @param $id_segment
* @param $suggestions
*/
public
static function updateSuggestionsArray( $id_segment, $suggestions ) {
public static function updateSuggestionsArray( $id_segment, $suggestions ) {

if ( empty( $suggestions ) ) {
return;
Expand All @@ -826,4 +825,9 @@ static function updateSuggestionsArray( $id_segment, $suggestions ) {

$stmt->execute( $params );
}

public static function getLastModifiedSegmentEvent(int $id_job, int $ttl = 0)
{

}
}
41 changes: 39 additions & 2 deletions lib/Plugins/Features/ProjectCompletion/Decorator/CatDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

use AbstractDecorator;
use catController;
use CatUtils;
use Chunks_ChunkCompletionEventDao;
use Constants_TranslationStatus;
use Features\TranslationEvents\Model\TranslationEventDao;
use Projects_MetadataDao;

class CatDecorator extends AbstractDecorator {
Expand Down Expand Up @@ -73,10 +76,19 @@ private function varsForUncomplete() {
private function varsForComplete() {
$this->template->job_marked_complete = true;
$this->template->header_main_button_class = 'isMarkedComplete';
$this->template->header_main_button_enabled = false;
$this->template->mark_as_complete_button_enabled = false;

if($this->markAsCompleteIsEnabled()){
$this->template->header_main_button_enabled = true;
$this->template->mark_as_complete_button_enabled = true;
} else {
$this->template->header_main_button_enabled = false;
$this->template->mark_as_complete_button_enabled = false;
}
}

/**
* @return bool
*/
private function completable() {

if ( $this->controller->getChunk()->getProject()->getWordCountType() != Projects_MetadataDao::WORD_COUNT_RAW ) {
Expand Down Expand Up @@ -108,4 +120,29 @@ private function completable() {
return $completable;
}

/**
* @return bool
*/
private function markAsCompleteIsEnabled()
{
$revisionNumber = CatUtils::getRevisionNumberFromRequestUri();
$lastEvent = (new TranslationEventDao())->getLatestEventForAJob($this->controller->getChunk()->id);

if(empty($lastEvent)){
return false;
}

switch($lastEvent->status){
case Constants_TranslationStatus::STATUS_TRANSLATED:
return true;

case Constants_TranslationStatus::STATUS_APPROVED:
return $revisionNumber === 1 or $revisionNumber === 2;

case Constants_TranslationStatus::STATUS_APPROVED2:
return $revisionNumber === 2;
}

return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,34 @@ public function getLatestEventForSegment( $id_job, $id_segment ): ?TranslationEv

}

/**
* @param $id_job
*
* @return TranslationEventStruct|null
*/
public function getLatestEventForAJob( $id_job ): ?TranslationEventStruct {

$sql = "SELECT * FROM segment_translation_events
WHERE id_job = :id_job
AND status != :draft
ORDER BY id DESC
LIMIT 1
";

$conn = $this->getDatabaseHandler()->getConnection();
$stmt = $conn->prepare( $sql );
$stmt->setFetchMode( PDO::FETCH_CLASS, TranslationEventStruct::class );
$stmt->execute( [
'id_job' => $id_job,
'draft' => Constants_TranslationStatus::STATUS_DRAFT
] );

$res = $stmt->fetchAll();

return $res[ 0 ] ?? null;

}

/**
* @param array $id_segment_list
* @param int $id_job
Expand Down
33 changes: 33 additions & 0 deletions lib/Utils/CatUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,39 @@ private static function isARevisePath( string $path ): bool {
return strpos( $path, "/revise" ) === 0;
}

/**
* @return int
*/
public static function getRevisionNumberFromRequestUri(): int
{

if ( !isset( $_SERVER[ 'REQUEST_URI' ] ) ) {
return 0;
}

$_from_url = explode("/", @$_SERVER[ 'REQUEST_URI' ] );

if(empty($_from_url)){
return 0;
}

if(!isset($_from_url[1])){
return 0;
}

if($_from_url[1] === "revise"){
return 1;
}

if($_from_url[1] === "revise2"){
return 2;
}

return 0;
}



/**
* Get a job from a combination of ID and ANY password (t,r1 or r2)
*
Expand Down
8 changes: 8 additions & 0 deletions public/css/sass/components/MarkAsCompleteButton.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ input#markAsCompleteButton[disabled] {
background: transparent;
border: none;

&:disabled {
cursor: not-allowed;

&:hover {
opacity: 0.8;
}
}

&.isMarkedComplete {
background-image: url('/public/img/icons/icon-mark-active.svg');
background-size: cover;
Expand Down