Skip to content

Commit

Permalink
adding new models
Browse files Browse the repository at this point in the history
  • Loading branch information
jturbide committed Feb 24, 2024
1 parent 12305d2 commit be06969
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/Models/Feature.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* This file is part of the Zemit Framework.
*
* (c) Zemit Team <contact@zemit.com>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

namespace Zemit\Models;

use Zemit\Models\Abstracts\AbstractFeature;
use Zemit\Models\Interfaces\FeatureInterface;

class Feature extends AbstractFeature implements FeatureInterface
{
protected $deleted = self::NO;

public function initialize(): void
{
parent::initialize();
// @todo relationships
}

public function validation(): bool
{
$validator = $this->genericValidation();

// @todo validations

return $this->validate($validator);
}
}
15 changes: 15 additions & 0 deletions src/Models/Interfaces/FeatureInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
/**
* This file is part of the Zemit Framework.
*
* (c) Zemit Team <contact@zemit.com>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

namespace Zemit\Models\Interfaces;

interface FeatureInterface extends AbstractInterface
{
}
15 changes: 15 additions & 0 deletions src/Models/Interfaces/JobInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
/**
* This file is part of the Zemit Framework.
*
* (c) Zemit Team <contact@zemit.com>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

namespace Zemit\Models\Interfaces;

interface JobInterface extends AbstractInterface
{
}
15 changes: 15 additions & 0 deletions src/Models/Interfaces/UserFeatureInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
/**
* This file is part of the Zemit Framework.
*
* (c) Zemit Team <contact@zemit.com>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

namespace Zemit\Models\Interfaces;

interface UserFeatureInterface extends AbstractInterface
{
}
34 changes: 34 additions & 0 deletions src/Models/Job.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* This file is part of the Zemit Framework.
*
* (c) Zemit Team <contact@zemit.com>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

namespace Zemit\Models;

use Zemit\Models\Abstracts\AbstractJob;
use Zemit\Models\Interfaces\JobInterface;

class Job extends AbstractJob implements JobInterface
{
protected $deleted = self::NO;

public function initialize(): void
{
parent::initialize();
// @todo relationships
}

public function validation(): bool
{
$validator = $this->genericValidation();

// @todo validations

return $this->validate($validator);
}
}
46 changes: 46 additions & 0 deletions src/Models/UserFeature.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
/**
* This file is part of the Zemit Framework.
*
* (c) Zemit Team <contact@zemit.com>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

namespace Zemit\Models;

use Zemit\Models\Abstracts\AbstractUserFeature;
use Zemit\Models\Interfaces\UserFeatureInterface;

/**
* @property User $UserEntity
* @method User getUserEntity(?array $params = null)
*
* @property Feature $FeatureEntity
* @method Feature getFeatureEntity(?array $params = null)
*/
class UserFeature extends AbstractUserFeature implements UserFeatureInterface
{
protected $deleted = self::NO;
protected $position = self::NO;

public function initialize(): void
{
parent::initialize();

$this->hasOne('userId', User::class, 'id', ['alias' => 'User']);
$this->hasOne('featureId', Feature::class, 'id', ['alias' => 'Feature']);
}

public function validation(): bool
{
$validator = $this->genericValidation();

$this->addUniquenessValidation($validator, ['userId', 'featureId']);
$this->addUnsignedIntValidation($validator, 'userId', false);
$this->addUnsignedIntValidation($validator, 'featureId', false);

return $this->validate($validator);
}
}

0 comments on commit be06969

Please sign in to comment.