mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-22 22:38:41 +00:00
Add NPS
This commit is contained in:
parent
44d0878bbc
commit
f0174dd56a
91
Business/Marketing/NetPromoterScore.php
Normal file
91
Business/Marketing/NetPromoterScore.php
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.1
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @copyright 2013 Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
namespace phpOMS\Business\Marketing;
|
||||
|
||||
/**
|
||||
* Net Promoter Score
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\Business
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class NetPromoterScore {
|
||||
/**
|
||||
* Score values
|
||||
*
|
||||
* @var int[]
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private $scores = [];
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add score.
|
||||
*
|
||||
* @param int $score Net promoter score
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function add(int $score) /* : void */
|
||||
{
|
||||
$this->scores[] = $score;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get total NPS.
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function getScore() : int
|
||||
{
|
||||
$promoters = 0;
|
||||
$passives = 0;
|
||||
$detractors = 0;
|
||||
|
||||
foreach($this->scores as $score) {
|
||||
if($score > 8) {
|
||||
$promoters++;
|
||||
} elseif($score > 6) {
|
||||
$passives++;
|
||||
} else {
|
||||
$detractors++;
|
||||
}
|
||||
}
|
||||
|
||||
$total = $promoters + $passives + $detractors;
|
||||
|
||||
return ((int) ($promoters / $total)) - ((int) ($detractors / $total));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user