1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Coco\SourceWatcher\Vendors\StackOverflow; |
4
|
|
|
|
5
|
|
|
use Coco\SourceWatcher\Watcher\Communicator\SlackCommunicator; |
6
|
|
|
|
7
|
|
|
class StackOverflowSlackCommunicator extends SlackCommunicator |
8
|
|
|
{ |
9
|
|
|
private array $dataArray; |
10
|
|
|
|
11
|
|
|
public function __construct ( array $listOfJobs ) |
12
|
|
|
{ |
13
|
|
|
parent::__construct(); |
14
|
|
|
|
15
|
|
|
$this->buildDataArray( $listOfJobs ); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
public function setListOfJobs ( array $listOfJobs ) : void |
19
|
|
|
{ |
20
|
|
|
$this->buildDataArray( $listOfJobs ); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
private function buildDataArray ( array $listOfJobs ) : void |
24
|
|
|
{ |
25
|
|
|
$this->dataArray = array(); |
26
|
|
|
|
27
|
|
|
foreach ( $listOfJobs as $currentJob ) { |
28
|
|
|
$currentArray = array( "blocks" => array() ); |
29
|
|
|
|
30
|
|
|
array_push( $currentArray["blocks"], array( "type" => "divider" ) ); |
31
|
|
|
|
32
|
|
|
$currentSection = array( "type" => "section", "text" => null, "accessory" => null ); |
33
|
|
|
|
34
|
|
|
$text = "*" . $currentJob->getTitle() . "*" . PHP_EOL; |
35
|
|
|
$text .= $currentJob->getCompany() . " | " . $currentJob->getLocation() . PHP_EOL; |
36
|
|
|
$text .= "<" . $currentJob->getRefinedUrl() . ">"; |
37
|
|
|
$currentSection["text"] = array( "type" => "mrkdwn", "text" => $text ); |
38
|
|
|
|
39
|
|
|
$currentSection["accessory"] = array( "type" => "image", "image_url" => $currentJob->getLogo(), "alt_text" => $currentJob->getCompany() ); |
40
|
|
|
|
41
|
|
|
array_push( $currentArray["blocks"], $currentSection ); |
42
|
|
|
|
43
|
|
|
array_push( $currentArray["blocks"], array( "type" => "divider" ) ); |
44
|
|
|
|
45
|
|
|
array_push( $this->dataArray, $currentArray ); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function getDatArray () : array |
50
|
|
|
{ |
51
|
|
|
return $this->dataArray; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function send () |
55
|
|
|
{ |
56
|
|
|
foreach ( $this->dataArray as $currentSlackMessageBlock ) { |
57
|
|
|
$this->data = json_encode( $currentSlackMessageBlock ); |
58
|
|
|
parent::send(); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|