Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
jeyroik committed Jan 20, 2020
1 parent cd11499 commit 27f3815
Show file tree
Hide file tree
Showing 8 changed files with 268 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
# extas-bv-profiles

BV profiles for Extas

# install

`# vendor/bin/extas i`
13 changes: 13 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "jeyroik/extas-bv-profiles",
"description": "Extas bv profiles package",
"require": {
"jeyroik/extas-base": "*",
"jeyroik/extas-bv": "*"
},
"autoload": {
"psr-4": {
"extas\\": "src/"
}
}
}
92 changes: 92 additions & 0 deletions extas.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
{
"name": "extas/bv-api",
"plugins": [
{
"class": "extas\\components\\plugins\\PluginInstallBVProfiles",
"stage": "expand.install"
}
],
"bv_profiles": [
{
"name": "default",
"title": "По умолчанию",
"description": "Профиль по умолчанию: все веса равны единице",
"weights": {
"more_buyers": 1,
"more_products": 1,
"higher_price": 1,
"too_hard_to_deny": 1,
"happiness": 1,
"fans": 1,
"education": 1,
"hold_users": 1,
"active_users": 1,
"fewer_bugs": 1,
"deploy": 1,
"new_development": 1,
"support": 1,
"marketing": 1,
"new_possibilities": 1,
"promise": 1,
"law": 1,
"align_with_plans": 1,
"economy": 1,
"help": 1
}
},
{
"name": "support",
"title": "Поддержка",
"description": "Веса повышают значимость категорий, удешевляющих поддержку",
"weights": {
"more_buyers": 1,
"more_products": 1,
"higher_price": 1,
"too_hard_to_deny": 2,
"happiness": 1,
"fans": 1,
"education": 1,
"hold_users": 3,
"active_users": 2,
"fewer_bugs": 3,
"deploy": 3,
"new_development": 1,
"support": 3,
"marketing": 1,
"new_possibilities": 1,
"promise": 1,
"law": 1,
"align_with_plans": 1,
"economy": 3,
"help": 1
}
},
{
"name": "startup",
"title": "Стартап",
"description": "Веса повышают значимость категорий, привлекающих пользователей",
"weights": {
"more_buyers": 3,
"more_products": 3,
"higher_price": 3,
"too_hard_to_deny": 3,
"happiness": 2,
"fans": 3,
"education": 3,
"hold_users": 1,
"active_users": 3,
"fewer_bugs": 1,
"deploy": 3,
"new_development": 3,
"support": 1,
"marketing": 3,
"new_possibilities": 3,
"promise": 1,
"law": 1,
"align_with_plans": 2,
"economy": 1,
"help": 1
}
}
]
}
62 changes: 62 additions & 0 deletions src/components/bv/profiles/Profile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
namespace extas\components\bv\profiles;

use extas\components\Item;
use extas\components\THasDescription;
use extas\components\THasName;
use extas\interfaces\bv\profiles\IProfile;

/**
* Class Profile
*
* @package extas\components\bv\profiles
* @author jeyroik@gmail.com
*/
class Profile extends Item implements IProfile
{
use THasName;
use THasDescription;

/**
* @param array $default
*
* @return array
*/
public function getWeights(array $default = []): array
{
return $this->config[static::FIELD__WEIGHTS] ?? $default;
}

/**
* @param array $weights
*
* @return IProfile
*/
public function setWeights(array $weights): IProfile
{
$this->config[static::FIELD__WEIGHTS] = $weights;

return $this;
}

/**
* @param string $subcategoryName
* @param int $defaultWeight
*
* @return int
*/
public function getSubcategoryWeight(string $subcategoryName, int $defaultWeight = 1): int
{
$weights = $this->getWeights();

return $weights[$subcategoryName] ?? $defaultWeight;
}

/**
* @return string
*/
protected function getSubjectForExtension(): string
{
return static::SUBJECT;
}
}
20 changes: 20 additions & 0 deletions src/components/bv/profiles/ProfileRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
namespace extas\components\bv\profiles;

use extas\components\repositories\Repository;
use extas\interfaces\bv\profiles\IProfileRepository;

/**
* Class ProfileRepository
*
* @package extas\components\bv\profiles
* @author jeyroik@gmail.com
*/
class ProfileRepository extends Repository implements IProfileRepository
{
protected $itemClass = Profile::class;
protected $name = 'bv_profiles';
protected $pk = Profile::FIELD__NAME;
protected $scope = 'extas';
protected $idAs = '';
}
20 changes: 20 additions & 0 deletions src/components/plugins/PluginInstallBVProfiles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
namespace extas\components\plugins;

use extas\components\bv\profiles\Profile;
use extas\interfaces\bv\profiles\IProfileRepository;

/**
* Class PluginInstallBVProfiles
*
* @package extas\components\plugins
* @author jeyroik@gmail.com
*/
class PluginInstallBVProfiles extends PluginInstallDefault
{
protected $selfItemClass = Profile::class;
protected $selfName = 'business value profile';
protected $selfSection = 'bv_profiles';
protected $selfUID = Profile::FIELD__NAME;
protected $selfRepositoryClass = IProfileRepository::class;
}
41 changes: 41 additions & 0 deletions src/interfaces/bv/profiles/IProfile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
namespace extas\interfaces\bv\profiles;

use extas\interfaces\IHasDescription;
use extas\interfaces\IHasName;
use extas\interfaces\IItem;

/**
* Interface IProfile
*
* @package extas\interfaces\bv\profiles
* @author jeyroik@gmail.com
*/
interface IProfile extends IItem, IHasName, IHasDescription
{
const SUBJECT = 'extas.bv.profile';

const FIELD__WEIGHTS = 'weights';

/**
* @param array $default
*
* @return array [subCat0 => weight0, ...]
*/
public function getWeights(array $default = []): array;

/**
* @param array $weights
*
* @return IProfile
*/
public function setWeights(array $weights): IProfile;

/**
* @param string $subcategoryName
* @param int $defaultWeight
*
* @return int
*/
public function getSubcategoryWeight(string $subcategoryName, int $defaultWeight = 1): int;
}
15 changes: 15 additions & 0 deletions src/interfaces/bv/profiles/IProfileRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
namespace extas\interfaces\bv\profiles;

use extas\interfaces\repositories\IRepository;

/**
* Interface IProfileRepository
*
* @package extas\interfaces\bv\profiles
* @author jeyroik@gmail.com
*/
interface IProfileRepository extends IRepository
{

}

0 comments on commit 27f3815

Please sign in to comment.