diff --git a/plugins/ProfileColor/Controller/ProfileColor.php b/plugins/ProfileColor/Controller/ProfileColor.php index 0689af6149..12c2820ff2 100644 --- a/plugins/ProfileColor/Controller/ProfileColor.php +++ b/plugins/ProfileColor/Controller/ProfileColor.php @@ -21,20 +21,23 @@ namespace Plugin\ProfileColor\Controller; +use App\Core\DB\DB; use App\Core\Form; use function App\Core\I18n\_m; +use App\Entity\ProfileColor as PColor; +use App\Util\Common; use App\Util\Exception\ClientException; use App\Util\Exception\ServerException; +use Symfony\Component\Form\Extension\Core\Type\ColorType; use Symfony\Component\Form\Extension\Core\Type\HiddenType; use Symfony\Component\Form\Extension\Core\Type\SubmitType; -use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\HttpFoundation\Request; /** - * Cover controller + * Profile Color controller * * @package GNUsocial - * @category CoverPlugin + * @category ProfileColor * * @author Daniel Brandao * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org @@ -54,8 +57,19 @@ class ProfileColor */ public function profileColorSettings(Request $request) { + $user = Common::user(); + $actor_id = $user->getId(); + $pcolor = DB::find('profile_color', ['gsactor_id' => $actor_id]); + $color = '#000000'; + if ($pcolor != null) { + $color = $pcolor->getColor(); + } + + //print_r("STORED: " ); + //var_dump($color); + $form = Form::create([ - ['color', TextType::class, ['label' => _m('Color')]], + ['color', ColorType::class, ['data' => $color, 'label' => _m('Profile Color')]], ['hidden', HiddenType::class, []], ['save', SubmitType::class, ['label' => _m('Submit')]], ]); @@ -63,6 +77,17 @@ class ProfileColor $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $data = $form->getData(); + //var_dump($data['color']); + + // Must get old id before inserting another one + if ($pcolor != null) { + DB::remove($pcolor); + DB::flush(); + } + + $pcolor = PColor::create(['gsactor_id' => $actor_id, 'color' => $data['color']]); + DB::persist($pcolor); + DB::flush(); } return ['_template' => 'profilecolor/profilecolor.html.twig', 'form' => $form->createView()]; diff --git a/plugins/ProfileColor/ProfileColor.php b/plugins/ProfileColor/ProfileColor.php index 716313e9eb..6451df627e 100644 --- a/plugins/ProfileColor/ProfileColor.php +++ b/plugins/ProfileColor/ProfileColor.php @@ -20,17 +20,15 @@ namespace Plugin\ProfileColor; -use App\Core\DB\DB; use App\Core\Event; use App\Core\Module; use App\Core\Router\RouteLoader; -use App\Util\Common; /** * Profile Color plugin main class * * @package GNUsocial - * @category CoverPlugin + * @category ProfileColor * * @author Daniel Brandao * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org @@ -63,16 +61,6 @@ class ProfileColor extends Module $vars['profile_tabs'][] = ['title' => 'Color', 'route' => 'settings_profile_color', ]; - /* - if (Common::user() != null) { - $cover = DB::find('cover', ['gsactor_id' => Common::user()->getId()]); - if ($cover != null) { - $vars['profile_extras'][] = ['name' => 'cover', 'vars' => ['img' => '/cover']]; - } else { - $vars['profile_extras'][] = ['name' => 'cover', 'vars' => []]; - } - } - */ return Event::next; } @@ -86,7 +74,7 @@ class ProfileColor extends Module public function onStartShowStyles(array &$styles): bool { - //$styles[] = 'cover/cover.css'; + //$styles[] = 'profilecolor/profilecolor.css'; return Event::next; } } diff --git a/src/Entity/ProfileColor.php b/src/Entity/ProfileColor.php new file mode 100644 index 0000000000..1f2f437fcc --- /dev/null +++ b/src/Entity/ProfileColor.php @@ -0,0 +1,107 @@ +. + +// }}} + +namespace App\Entity; + +use App\Core\Entity; +use DateTimeInterface; + +/** + * For storing a profile Color + * + * @package GNUsocial + * @category CoverPlugin + * + * @author Daniel Brandao + * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org + * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later + */ +class ProfileColor extends Entity +{ + // {{{ Autocode + + private int $gsactor_id; + private string $color; + private DateTimeInterface $created; + private DateTimeInterface $modified; + + public function setGsactorId(int $gsactor_id): self + { + $this->gsactor_id = $gsactor_id; + return $this; + } + + public function getGsactorId(): int + { + return $this->gsactor_id; + } + + public function setColor(string $color): self + { + $this->color = $color; + return $this; + } + + public function getColor(): string + { + return $this->color; + } + + public function setCreated(DateTimeInterface $created): self + { + $this->created = $created; + return $this; + } + + public function getCreated(): DateTimeInterface + { + return $this->created; + } + + public function setModified(DateTimeInterface $modified): self + { + $this->modified = $modified; + return $this; + } + + public function getModified(): DateTimeInterface + { + return $this->modified; + } + + // }}} Autocode + public static function schemaDef(): array + { + return [ + 'name' => 'profile_color', + 'fields' => [ + 'gsactor_id' => ['type' => 'int', 'not null' => true, 'description' => 'foreign key to gsactor table'], + 'color' => ['type' => 'text', 'not null' => true, 'description' => 'color hex code'], + 'created' => ['type' => 'datetime', 'not null' => true, 'description' => 'date this record was created', 'default' => 'CURRENT_TIMESTAMP'], + 'modified' => ['type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified', 'default' => 'CURRENT_TIMESTAMP'], + ], + 'primary key' => ['gsactor_id'], + 'foreign keys' => [ + 'cover_gsactor_id_fkey' => ['gsactor', ['gsactor_id' => 'id']], + ], + ]; + } +}