Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
6393e9b
fix: :bug: fix change method that gets path on artisan call in paymen…
gunesbizim Jan 23, 2025
a0214a7
fix: :bug: fix SpreadableTrait && HasSpreadable && refactor Spreadabl…
gunesbizim Feb 3, 2025
f7d18eb
fix: :bug: fix spreadable and spreadsheet && refactor spreadable
gunesbizim Feb 4, 2025
1fe8306
feat: :sparkles: introduce reporting module && spreadsheet features
gunesbizim Feb 4, 2025
2cc5a29
Merge branch '7-feature-add-reporter-module' into 126-feature-excel-p…
gunesbizim Feb 6, 2025
f6daf82
feat: :sparkles: introduce spreadsheet feature && fix small bug at in…
gunesbizim Feb 7, 2025
4b3de7a
fix: :bug: fix variable name typo && update migrationg with role, loc…
gunesbizim Feb 13, 2025
c392047
refactor: :recycle: remove unnecessary line of code
gunesbizim Feb 13, 2025
7490975
refactor: :recycle: clean unnecessary comment lines
gunesbizim Feb 13, 2025
52de313
refactor: :recycle: clean unnecessary comment lines
gunesbizim Feb 13, 2025
b0b8380
refactor: :recycle: wrap spreadsheet input with v-input
gunesbizim Feb 13, 2025
c2f3c45
fix: :bug: fix processTableData function on spreadsheet input && add …
gunesbizim Feb 13, 2025
8847623
feat: :sparkles: introduce translateable spreadsheets
gunesbizim Feb 13, 2025
fedc790
feat: :sparkles: merge 126-feature-excel-processor for spreadable && …
gunesbizim Feb 14, 2025
f287b93
refactor: :recycle: refactor HasSpreadable && SpreadableTrait
gunesbizim Feb 14, 2025
9635ee7
test: :white_check_mark: write tests for spread feature
gunesbizim Feb 14, 2025
7d4a433
build: :heavy_plus_sign: add maatwebsite/excel dependency for excel f…
gunesbizim Feb 14, 2025
25165c6
build: :heavy_plus_sign: add xlsx dependency
gunesbizim Feb 14, 2025
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
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
"torann/geoip": "^3.0",
"tymon/jwt-auth": "^1.0|^2.0",
"unusualify/payable": "^0",
"wikimedia/composer-merge-plugin": "^2.1"
"wikimedia/composer-merge-plugin": "^2.1",
"maatwebsite/excel": "^3.1"
},
"require-dev": {
"doctrine/dbal": "^3.9",
Expand Down
2 changes: 2 additions & 0 deletions config/merges/tables.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@
'chats' => 'umod_chats',
'chat_messages' => 'umod_chat_messages',
'spreads' => 'umod_spreads',
'spreadsheets' => 'umod_spreadsheets',

];
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ public function up()
createDefaultTableFields($table);
$table->uuidMorphs('spreadable');
$table->json('content')->default(new Expression('(JSON_ARRAY())'));
$table->timestamps();
$table->softDeletes();
createDefaultExtraTableFields($table);
});

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Query\Expression;
use Illuminate\Support\Str;



class CreateSpreadsheetsTable extends Migration
{
public function up()
{
$modularitySpreadsheetsTable = modularityConfig('tables.spreadsheets', 'modularity_spreadsheets');

Schema::create($modularitySpreadsheetsTable, function (Blueprint $table) {
// this will create an id, name field
createDefaultTableFields($table);
$table->uuidMorphs('spreadsheetable');
$table->json('content')->default(new Expression('(JSON_ARRAY())'));
$table->string('role')->nullable();
$table->string('locale')->nullable();
// a "published" column, and soft delete and timestamps columns
createDefaultExtraTableFields($table);
});

Schema::create('spreadsheet_translations', function (Blueprint $table) {
// createDefaultTranslationsTableFields($table, Str::singular(modularityConfig('tables.spreadsheets', 'modularity_spreadsheets')));
createDefaultTranslationsTableFields($table, 'spreadsheet');

$table->json('content')->default(new Expression('(JSON_ARRAY())'));;
});


}

public function down()
{
Schema::dropIfExists('spreadsheet_translations');
Schema::dropIfExists(modularityConfig('tables.spreadsheets', 'modularity_spreadsheets'));

}
}
60 changes: 60 additions & 0 deletions operations/2025_01_23_203858_payments_table_operation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

use Illuminate\Console\Concerns\InteractsWithIO;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\Artisan;
use Symfony\Component\Console\Output\ConsoleOutput;
use TimoKoerber\LaravelOneTimeOperations\OneTimeOperation;
use Unusualify\Modularity\Facades\Modularity;

return new class extends OneTimeOperation
{
use InteractsWithIO;

public function __construct()
{
$this->output = new ConsoleOutput;
}

/**
* Determine if the operation is being processed asynchronously.
*/
protected bool $async = true;

/**
* The queue that the job will be dispatched to.
*/
protected string $queue = 'default';

/**
* A tag name, that this operation can be filtered by.
*/
protected ?string $tag = null;

/**
* Process the operation.
*/
public function process(): void
{
if (! Schema::hasTable('umod_payments')
&& Schema::hasTable('unfy_payments')) {

Schema::rename('unfy_payments', 'umod_payments');

$this->output->writeln('');
$this->output->writeln('');

$this->info("\tunfy_payments table changed as " . 'umod_payments');

$this->output->writeln('');
}else {

Artisan::call('migrate', [
'--path' => Modularity::getVendorPath('database/migrations/default/2024_06_24_125121_create_payments_table.php')
]);

$this->info("\tumod_payments created");

}
}
};
4 changes: 2 additions & 2 deletions src/Entities/Spread.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ class Spread extends Model
protected $fillable = [
'name',
'published',
'content',
'content'
];

protected $casts = [
'content' => 'array',
'content' => 'array'
];

// protected function casts(): array
Expand Down
43 changes: 43 additions & 0 deletions src/Entities/Spreadsheet.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Unusualify\Modularity\Entities;

use Unusualify\Modularity\Entities\Model;
use Modules\PressRelease\Entities\Report;
use Unusualify\Modularity\Entities\Traits\HasTranslation;

class Spreadsheet extends Model
{
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
use HasTranslation;

public $translatedAttributes = [
'content'
];

protected $fillable = [
'published',
// 'content',
'role',
'locale'
];

protected $casts = [
'content' => 'array'
];

public function __construct(array $attributes = [])
{
$this->table = $this->getTable();
parent::__construct($attributes);
}

public function getTable()
{
return modularityConfig('tables.spreadsheets', 'modularity_spreads');
}
}
94 changes: 28 additions & 66 deletions src/Entities/Traits/HasSpreadable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,112 +9,74 @@ trait HasSpreadable
{
use ManageEloquent;

protected $_pendingSpreadData;
protected $_pendingSpreadData = [];



public static function bootHasSpreadable()
{
// TODO: Keep the old spreadable data from model and remove attributes based on that don't remove all column fields
self::saving(static function (Model $model) {
// Store the spread data before cleaning
if (! $model->exists) {
// Set property to preserve data through events
$model->_pendingSpreadData = $model->_spread ?: $model->prepareSpreadableJson();
} elseif ($model->_spread) {
// Handle existing spread updates
self::saving(static function(Model $model) {

if (!$model->exists) {
// For new models, preserve the spread data for after creation.

$model->_pendingSpreadData = array_merge($model->_pendingSpreadData, $model->_spread ?? []);

} else if($model->_spread){
// For existing models, rebuild the _spread attribute from the spreadable fillable inputs,
// and clean those fillables from the model.

$model->spreadable()->update([
'content' => $model->_spread,
'content' => $model->_spread
]);
}

$model->cleanSpreadableAttributes();
$model->offsetUnset('_spread');
});

self::created(static function (Model $model) {
$model->spreadable()->create($model->_pendingSpreadData ?? []);
self::created(static function(Model $model) {
$model->spreadable()->create([
'content' => $model->_pendingSpreadData ?? []
]);
});

self::retrieved(static function (Model $model) {
// If there's a spread model, load its attributes
// dd('text');
// dd($model);
self::retrieved(static function(Model $model) {
if ($model->spreadable) {
$jsonData = $model->spreadable->content ?? [];

// Set spreadable attributes on model, excluding protected attributes
foreach ($jsonData as $key => $value) {
if (! $model->isProtectedAttribute($key)) {
if (! $model->isProtectedSpreadableAttribute($key)) {
$model->setAttribute($key, $value);
}
}

// Set _spread attribute
$model->setAttribute('_spread', $jsonData);
// dd($model->_spread);

} else {
// dd('here');
// Initialize empty _spread if no spreadable exists
$model->setAttribute('_spread', []);
}
});

}

public function initializeHasSpreadable()
{
$this->mergeFillable(['_spread']);
$spreadableFields = ['_spread'];
$this->mergeFillable($spreadableFields);
}

// TODO: rename relation to spread as well
public function spreadable(): \Illuminate\Database\Eloquent\Relations\MorphOne
{
return $this->morphOne(\Unusualify\Modularity\Entities\Spread::class, 'spreadable');
}

protected function isProtectedAttribute(string $key): bool
protected function isProtectedSpreadableAttribute(string $key): bool
{

return in_array($key, $this->getReservedKeys());
return in_array($key, $this->getSpreadableReservedKeys());
}

public function getReservedKeys(): array
public function getSpreadableReservedKeys(): array
{

return array_merge(
$this->getColumns(), // Using ManageEloquent's getColumns
$this->definedRelations(), // Using ManageEloquent's definedRelations
array_keys($this->getMutatedAttributes()),
['spreadable', '_spread']
['_spread']
);
}

protected function prepareSpreadableJson(): array
{
$attributes = $this->getAttributes();
$protectedKeys = array_merge(
$this->getColumns(), // Using ManageEloquent's getColumns
$this->definedRelations(), // Using ManageEloquent's definedRelations
array_keys($this->getMutatedAttributes()),
['spreadable', '_spread']
);

return array_diff_key(
$attributes,
array_flip($protectedKeys)
);
}

protected function cleanSpreadableAttributes(): void
{
$columns = $this->getColumns();
$attributes = $this->getAttributes();
// TODO: Instead of removing any attribute remove the ones that you know that needs to be removed
// Remove any attributes that aren't database columns
foreach ($attributes as $key => $value) {
if (! in_array($key, $columns)) {
unset($this->attributes[$key]);
}
}

}
}
Loading