-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1660 from dmetzner2/patch-5
SHARE-487 Achievement events + admin
- Loading branch information
Showing
74 changed files
with
2,916 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DoctrineMigrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
/** | ||
* Auto-generated Migration: Please modify to your needs! | ||
*/ | ||
final class Version20210531200855 extends AbstractMigration | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return ''; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
// this up() migration is auto-generated, please modify it to your needs | ||
$this->addSql('CREATE TABLE cronjob (name VARCHAR(255) NOT NULL, state VARCHAR(255) DEFAULT \'idle\' NOT NULL, cron_interval VARCHAR(255) DEFAULT \'1 days\' NOT NULL, priority INT DEFAULT 0 NOT NULL, start_at DATETIME DEFAULT NULL, end_at DATETIME DEFAULT NULL, result_code INT DEFAULT NULL, PRIMARY KEY(name)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
// this down() migration is auto-generated, please modify it to your needs | ||
$this->addSql('DROP TABLE cronjob'); | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
namespace App\Admin\DB_Updater; | ||
|
||
use App\Manager\AchievementManager; | ||
use Sonata\AdminBundle\Admin\AbstractAdmin; | ||
use Sonata\AdminBundle\Datagrid\ListMapper; | ||
use Sonata\AdminBundle\Route\RouteCollection; | ||
|
||
class AchievementsAdmin extends AbstractAdmin | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $baseRouteName = 'admin_catrobat_adminbundle_achievementsadmin'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $baseRoutePattern = 'achievements'; | ||
|
||
protected AchievementManager $achievement_manager; | ||
|
||
public function __construct($code, $class, $baseControllerName, AchievementManager $achievement_manager) | ||
{ | ||
parent::__construct($code, $class, $baseControllerName); | ||
|
||
$this->achievement_manager = $achievement_manager; | ||
} | ||
|
||
protected function configureRoutes(RouteCollection $collection): void | ||
{ | ||
$collection | ||
->remove('export') | ||
->remove('acl') | ||
->remove('delete') | ||
->remove('create') | ||
->add('update_achievements') | ||
; | ||
} | ||
|
||
/** | ||
* @param mixed $object | ||
*/ | ||
public function getUnlockedByCount($object): int | ||
{ | ||
$id = $object->getId(); | ||
|
||
return $this->achievement_manager->countUserAchievementsOfAchievement($id); | ||
} | ||
|
||
/** | ||
* @param ListMapper $list | ||
* | ||
* Fields to be shown on lists | ||
*/ | ||
protected function configureListFields(ListMapper $list): void | ||
{ | ||
$list | ||
->add('priority') | ||
->add('internal_title') | ||
->add('internal_description') | ||
->add('badge', null, ['template' => 'Admin/achievement_badge_image.html.twig']) | ||
->add('badge_locked', null, ['template' => 'Admin/achievement_badge_locked_image.html.twig']) | ||
->add('banner_color') | ||
->add('enabled') | ||
->add('unlocked_by', 'string', ['template' => 'Admin/achievement_unlocked_by.html.twig']) | ||
; | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
src/Admin/DB_Updater/Controller/AchievementsAdminController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
namespace App\Admin\DB_Updater\Controller; | ||
|
||
use App\Commands\Helpers\CommandHelper; | ||
use App\Manager\AchievementManager; | ||
use Exception; | ||
use Sonata\AdminBundle\Controller\CRUDController; | ||
use Symfony\Component\Console\Output\BufferedOutput; | ||
use Symfony\Component\HttpFoundation\RedirectResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\HttpKernel\KernelInterface; | ||
use Symfony\Component\Security\Core\Exception\AccessDeniedException; | ||
|
||
class AchievementsAdminController extends CRUDController | ||
{ | ||
protected AchievementManager $achievement_manager; | ||
|
||
public function __construct(AchievementManager $achievement_manager) | ||
{ | ||
$this->achievement_manager = $achievement_manager; | ||
} | ||
|
||
public function listAction(Request $request = null): Response | ||
{ | ||
$achievements = $this->achievement_manager->findAllAchievements(); | ||
|
||
$numberOfUserAchievements = []; | ||
foreach ($achievements as $achievement) { | ||
$id = $achievement->getId(); | ||
$numberOfUserAchievements[$id] = $this->achievement_manager->countUserAchievementsOfAchievement($id); | ||
} | ||
|
||
return $this->renderWithExtraParams('Admin/DB_Updater/admin_achievements.html.twig', [ | ||
'action' => 'update_achievements', | ||
'numberOfUserAchievements' => $numberOfUserAchievements, | ||
'updateAchievementsUrl' => $this->admin->generateUrl('update_achievements'), | ||
]); | ||
} | ||
|
||
/** | ||
* @throws Exception | ||
*/ | ||
public function updateAchievementsAction(KernelInterface $kernel): RedirectResponse | ||
{ | ||
if (!$this->admin->isGranted('ACHIEVEMENTS')) { | ||
throw new AccessDeniedException(); | ||
} | ||
|
||
$output = new BufferedOutput(); | ||
$result = CommandHelper::executeShellCommand( | ||
['bin/console', 'catrobat:update:achievements'], ['timeout' => 86400], '', $output, $kernel | ||
); | ||
|
||
if (0 === $result) { | ||
$this->addFlash('sonata_flash_success', 'Achievements have been successfully updated'); | ||
} else { | ||
$this->addFlash('sonata_flash_error', "Updating achievements failed!\n".$output->fetch()); | ||
} | ||
|
||
return new RedirectResponse($this->admin->generateUrl('list')); | ||
} | ||
} |
Oops, something went wrong.