diff --git a/README.md b/README.md index 39572b5..96fec17 100644 --- a/README.md +++ b/README.md @@ -22,9 +22,10 @@ Here is an example on how to use it: $chat->disableSendEmailTranscript(); $chat->enableRating('advanced', true); $chat->setBoxPosition('left', 'side', 20, 120); - $chat->setUserBasicInformation('Johny Depp', 'johny@depp.com'); - $chat->addUserExtraInformation('orderTotal', 'Total orders', 150); - $chat->addUserExtraInformation('lastOrder', 'Last ordered', '2015-07-09'); + $chat->setName('Johny Depp'); + $chat->setEmail('johny@depp.com'); + $chat->setVariable('orderTotal', 'Total orders', 150); + $chat->setVariable('lastOrder', 'Last ordered', '2015-07-09'); $chat->setGoogleAnalytics('UA-123456'); $data = $chat->render(); ``` diff --git a/src/Smartsupp/ChatGenerator.php b/src/Smartsupp/ChatGenerator.php index d593e33..6e0e86a 100644 --- a/src/Smartsupp/ChatGenerator.php +++ b/src/Smartsupp/ChatGenerator.php @@ -15,12 +15,6 @@ */ class ChatGenerator { - /** - * @var array Values which are allowed for language param. - */ - protected $allowed_languages = array('en', 'fr', 'es', 'de', 'ru', 'cs', 'sk', 'pl', 'hu', 'cn', 'da', 'nl', 'it', - 'pt', 'hi', 'ro', 'no'); - /** * @var array Values which are allowed for ratingType param. */ @@ -52,7 +46,7 @@ class ChatGenerator protected $cookie_domain = null; /** - * @var string Chat language. Can have any value from $this->allowed_language. + * @var string Chat language. */ protected $language = 'en'; @@ -150,11 +144,6 @@ public function __construct($key = null) */ public function setLanguage($language) { - if (!in_array($language, $this->allowed_languages)) { - throw new \Exception("Language $language is not allowed value. You can use only one of values: " . - implode(', ', $this->allowed_languages) . "."); - } - $this->language = $language; } @@ -225,16 +214,24 @@ public function enableRating($rating_type = 'simple', $rating_comment = false) } /** - * You can send basic information about web visitors from your database to Smartsupp (name, email). So your visitors - * won't be anonymous and your chat agents will see info about every visitor, enabling agents to better focus on VIP - * visitors and provide customized answers. + * You can send visitor name. So your visitors won't be anonymous and your chat agents will see info about every + * visitor, enabling agents to better focus on VIP visitors and provide customized answers. * - * @param $name User name. - * @param $email User e-mail address. + * @param string $name */ - public function setUserBasicInformation($name, $email) + public function setName($name) { $this->name = $name; + } + + /** + * You can send visitor email. So your visitors won't be anonymous and your chat agents will see info about every + * visitor, enabling agents to better focus on VIP visitors and provide customized answers. + * + * @param string $name + */ + public function setEmail($email) + { $this->email = $email; } @@ -245,7 +242,7 @@ public function setUserBasicInformation($name, $email) * @param $label Parameter label. * @param $value Parameter value. */ - public function addUserExtraInformation($id, $label, $value) + public function setVariable($id, $label, $value) { $variable = array('id' => $id, 'label' => $label, 'value' => $value); @@ -262,7 +259,7 @@ public function addUserExtraInformation($id, $label, $value) * @param int $offset_y Offset from top. * @throws \Exception When params are not correct. */ - public function setBoxPosition($align_x = 'right', $align_y = 'bottom', $offset_x = 10, $offset_y = 100) + public function setAlign($align_x = 'right', $align_y = 'bottom', $offset_x = 10, $offset_y = 100) { if (!in_array($align_x, $this->allowed_align_x)) { throw new \Exception("AllignX value $align_x is not allowed value. You can use only one of values: " . diff --git a/tests/ChatGeneratorTest.php b/tests/ChatGeneratorTest.php index 93ab07b..a4cb3df 100644 --- a/tests/ChatGeneratorTest.php +++ b/tests/ChatGeneratorTest.php @@ -77,7 +77,7 @@ public function test_widget_badParam() public function test_setBoxPosition() { - $this->chat->setBoxPosition('left', 'side', 20, 120); + $this->chat->setAlign('left', 'side', 20, 120); $this->assertEquals('left', self::getPrivateField($this->chat, 'align_x')); $this->assertEquals('side', self::getPrivateField($this->chat, 'align_y')); @@ -91,7 +91,7 @@ public function test_setBoxPosition() */ public function test_setBoxPosition_badParam() { - $this->chat->setBoxPosition('foo', 'side', 20, 120); + $this->chat->setAlign('foo', 'side', 20, 120); } /** @@ -100,13 +100,13 @@ public function test_setBoxPosition_badParam() */ public function test_setBoxPosition_badParam2() { - $this->chat->setBoxPosition('left', 'foo', 20, 120); + $this->chat->setAlign('left', 'foo', 20, 120); } - public function test_addUserExtraInformation() + public function test_setVariable() { - $this->chat->addUserExtraInformation('userId', 'User ID', 123); - $this->chat->addUserExtraInformation('orderedPrice', 'Ordered Price in Eshop', '128 000'); + $this->chat->setVariable('userId', 'User ID', 123); + $this->chat->setVariable('orderedPrice', 'Ordered Price in Eshop', '128 000'); $this->assertEquals( array( @@ -119,7 +119,8 @@ public function test_addUserExtraInformation() public function test_setUserBasicInformation() { - $this->chat->setUserBasicInformation('Johny Depp', 'johny@depp.com'); + $this->chat->setName('Johny Depp'); + $this->chat->setEmail('johny@depp.com'); $this->assertEquals('Johny Depp', self::getPrivateField($this->chat, 'name')); $this->assertEquals('johny@depp.com', self::getPrivateField($this->chat, 'email')); @@ -178,15 +179,6 @@ public function test_setLanguage() $this->assertEquals('cs', self::getPrivateField($this->chat, 'language')); } - /** - * @expectedException \Exception - * @expectedExceptionMessage Language us is not allowed value. You can use only one of values: en, fr, es, de, ru, cs, sk, pl, hu, cn, da, nl, it, pt, hi, ro, no. - */ - public function test_setLanguage_badParam() - { - $this->chat->setLanguage('us'); - } - /** * @expectedException \Exception * @expectedExceptionMessage At least KEY param must be set! @@ -235,11 +227,12 @@ public function test_render_allParams() $this->chat->setCookieDomain('.foo.bar'); $this->chat->disableSendEmailTranscript(); $this->chat->enableRating('advanced', true); - $this->chat->setBoxPosition('left', 'side', 20, 120); + $this->chat->setAlign('left', 'side', 20, 120); $this->chat->setWidget('button'); - $this->chat->setUserBasicInformation('Johny Depp', 'johny@depp.com'); - $this->chat->addUserExtraInformation('orderTotal', 'Total orders', 150); - $this->chat->addUserExtraInformation('lastOrder', 'Last ordered', '2015-07-09'); + $this->chat->setName('Johny Depp'); + $this->chat->setEmail('johny@depp.com'); + $this->chat->setVariable('orderTotal', 'Total orders', 150); + $this->chat->setVariable('lastOrder', 'Last ordered', '2015-07-09'); $this->chat->setGoogleAnalytics('UA-123456', array('cookieDomain' => '.foo.bar')); $this->chat->hideWidget();