Skip to content

Commit 0ee7d4d

Browse files
committed
added ChannelModel
1 parent 79b9173 commit 0ee7d4d

File tree

4 files changed

+206
-19
lines changed

4 files changed

+206
-19
lines changed

README.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,27 @@ $result = $driver->getTeamModel()->createTeam($requestOptions);
7575
$result = $driver->getTeamModel()->getTeamByName('new_team');
7676
```
7777

78+
### Channel data model
79+
```php
80+
//Create a channel
81+
$teamID = 'team_id_to_add_the_channel_to';
82+
$requestOptions = [
83+
'name' => 'new_channel',
84+
'display_name' => 'New Channel',
85+
'type' => 'O',
86+
];
87+
$result = $driver->getChannelModel($teamId)->createChannel($requestOptions);
88+
89+
90+
//Get a channel
91+
$teamID = 'team_id_of_the_channels_to_return';
92+
$result = $driver->getChannelModel($teamId)->getChannelByName('new_channel');
93+
```
94+
7895
## ToDo
7996
[x] Add Team data model
80-
[ ] Add Channel data model (in development)
81-
[ ] Add Post data model
97+
[x] Add Channel data model
98+
[ ] Add Post data model (in development)
8299
[ ] Add File data model
83100
[ ] Add Admin data model
84101
[ ] Add Preference data model

src/Driver.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
* This Driver is based entirely on official documentation of the Mattermost Web
44
* Services API and you can extend it by following the directives of the documentation.
55
*
6-
* For the full copyright and license information, please read the LICENSE.txt
7-
* file that was distributed with this source code. For the full list of
8-
* contributors, visit https://github.com/gnello/php-mattermost-driver/contributors
9-
*
106
* God bless this mess.
117
*
128
* @author Luca Agnello <[email protected]>
@@ -15,6 +11,7 @@
1511

1612
namespace Gnello\Mattermost;
1713

14+
use Gnello\Mattermost\Models\ChannelModel;
1815
use Gnello\Mattermost\Models\TeamModel;
1916
use Gnello\Mattermost\Models\UserModel;
2017
use Pimple\Container;
@@ -112,4 +109,17 @@ public function getTeamModel()
112109

113110
return $this->models['team'];
114111
}
112+
113+
/**
114+
* @param $teamId
115+
* @return ChannelModel
116+
*/
117+
public function getChannelModel($teamId)
118+
{
119+
if (!isset($this->models['channel'])) {
120+
$this->models['channel'] = new ChannelModel($this->container['client'], $teamId);
121+
}
122+
123+
return $this->models['channel'];
124+
}
115125
}

src/Models/ChannelModel.php

Lines changed: 167 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
namespace Gnello\Mattermost\Models;
1717

18+
use Gnello\Mattermost\Client;
19+
1820
/**
1921
* Class ChannelModel
2022
*
@@ -28,12 +30,174 @@ class ChannelModel extends AbstractModel
2830
public static $endpoint = '/channels';
2931

3032
/**
31-
* @param $teamId
33+
* @var string
34+
*/
35+
private $teamId;
36+
37+
/**
38+
* ChannelModel constructor.
39+
*
40+
* @param Client $client
41+
* @param $teamID
42+
*/
43+
public function __construct(Client $client, $teamID)
44+
{
45+
$this->teamId = $teamID;
46+
parent::__construct($client);
47+
}
48+
49+
/**
50+
* @param array $requestOptions
51+
* @return \Psr\Http\Message\ResponseInterface
52+
*/
53+
public function createChannel(array $requestOptions)
54+
{
55+
return $this->client->post(TeamModel::$endpoint . '/' . $this->teamId . '/' . self::$endpoint . '/create', $requestOptions);
56+
}
57+
58+
/**
59+
* @param array $requestOptions
60+
* @return \Psr\Http\Message\ResponseInterface
61+
*/
62+
public function updateChannel(array $requestOptions)
63+
{
64+
return $this->client->post(TeamModel::$endpoint . '/' . $this->teamId . '/' . self::$endpoint . '/update', $requestOptions);
65+
}
66+
67+
/**
68+
* @param array $requestOptions
69+
* @return \Psr\Http\Message\ResponseInterface
70+
*/
71+
public function viewChannel(array $requestOptions)
72+
{
73+
return $this->client->post(TeamModel::$endpoint . '/' . $this->teamId . '/' . self::$endpoint . '/view', $requestOptions);
74+
}
75+
76+
/**
77+
* @return \Psr\Http\Message\ResponseInterface
78+
*/
79+
public function getChannelsForTheUser()
80+
{
81+
return $this->client->get(TeamModel::$endpoint . '/' . $this->teamId . '/' . self::$endpoint . '/');
82+
}
83+
84+
/**
85+
* @param $channelName
86+
* @return \Psr\Http\Message\ResponseInterface
87+
*/
88+
public function getChannelByName($channelName)
89+
{
90+
return $this->client->get(TeamModel::$endpoint . '/' . $this->teamId . '/' . self::$endpoint . '/name/' . $channelName);
91+
}
92+
93+
/**
94+
* @param $offset
95+
* @param $limit
96+
* @return \Psr\Http\Message\ResponseInterface
97+
*/
98+
public function getPageOfChannelsTheUserHasNotJoined($offset, $limit)
99+
{
100+
return $this->client->get(TeamModel::$endpoint . '/' . $this->teamId . '/' . self::$endpoint . '/more/' . $offset . '/' . $limit);
101+
}
102+
103+
/**
104+
* @return \Psr\Http\Message\ResponseInterface
105+
*/
106+
public function getChannelMembersForTheUser()
107+
{
108+
return $this->client->get(TeamModel::$endpoint . '/' . $this->teamId . '/' . self::$endpoint . '/members');
109+
}
110+
111+
/**
112+
* @return \Psr\Http\Message\ResponseInterface
113+
*/
114+
public function getChannelsPinnedPosts()
115+
{
116+
return $this->client->get(TeamModel::$endpoint . '/' . $this->teamId . '/' . self::$endpoint . '/pinned');
117+
}
118+
119+
/**
120+
* @param $channelId
121+
* @return \Psr\Http\Message\ResponseInterface
122+
*/
123+
public function getChannel($channelId)
124+
{
125+
return $this->client->get(TeamModel::$endpoint . '/' . $this->teamId . '/' . self::$endpoint . '/' . $channelId);
126+
}
127+
128+
/**
129+
* @param $channelId
130+
* @return \Psr\Http\Message\ResponseInterface
131+
*/
132+
public function getStatsOfChannel($channelId)
133+
{
134+
return $this->client->get(TeamModel::$endpoint . '/' . $this->teamId . '/' . self::$endpoint . '/' . $channelId . '/stats');
135+
}
136+
137+
/**
138+
* @param $channelId
139+
* @return \Psr\Http\Message\ResponseInterface
140+
*/
141+
public function deleteChannel($channelId)
142+
{
143+
return $this->client->post(TeamModel::$endpoint . '/' . $this->teamId . '/' . self::$endpoint . '/' . $channelId . '/delete');
144+
}
145+
146+
/**
147+
* @param $channelId
148+
* @param array $requestOptions
149+
* @return \Psr\Http\Message\ResponseInterface
150+
*/
151+
public function addUser($channelId, array $requestOptions)
152+
{
153+
return $this->client->post(TeamModel::$endpoint . '/' . $this->teamId . '/' . self::$endpoint . '/' . $channelId . '/add', $requestOptions);
154+
}
155+
156+
/**
157+
* @param $channelId
158+
* @param $userId
159+
* @return \Psr\Http\Message\ResponseInterface
160+
*/
161+
public function getChannelMember($channelId, $userId)
162+
{
163+
return $this->client->get(TeamModel::$endpoint . '/' . $this->teamId . '/' . self::$endpoint . '/' . $channelId . '/members/' . $userId);
164+
}
165+
166+
/**
167+
* @param $channelId
168+
* @param array $requestOptions
169+
* @return \Psr\Http\Message\ResponseInterface
170+
*/
171+
public function getChannelMembersByIds($channelId, array $requestOptions)
172+
{
173+
return $this->client->post(TeamModel::$endpoint . '/' . $this->teamId . '/' . self::$endpoint . '/' . $channelId . '/members/ids', $requestOptions);
174+
}
175+
176+
/**
177+
* @param $channelId
178+
* @param array $requestOptions
179+
* @return \Psr\Http\Message\ResponseInterface
180+
*/
181+
public function updateRolesOfChannelMember($channelId, array $requestOptions)
182+
{
183+
return $this->client->post(TeamModel::$endpoint . '/' . $this->teamId . '/' . self::$endpoint . '/' . $channelId . '/update_member_roles', $requestOptions);
184+
}
185+
186+
/**
187+
* @param array $requestOptions
188+
* @return \Psr\Http\Message\ResponseInterface
189+
*/
190+
public function autocompleteChannelsInATeam(array $requestOptions)
191+
{
192+
return $this->client->post(TeamModel::$endpoint . '/' . $this->teamId . '/' . self::$endpoint . '/autocomplete', $requestOptions);
193+
}
194+
195+
/**
32196
* @param array $requestOptions
33197
* @return \Psr\Http\Message\ResponseInterface
34198
*/
35-
public function createChannel($teamId, array $requestOptions)
199+
public function searchForMoreChannels(array $requestOptions)
36200
{
37-
return $this->client->post(TeamModel::$endpoint . '/' . $teamId . '/' . self::$endpoint . '/create', $requestOptions);
201+
return $this->client->post(TeamModel::$endpoint . '/' . $this->teamId . '/' . self::$endpoint . '/more/search', $requestOptions);
38202
}
39203
}

src/Models/UserModel.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
* This Driver is based entirely on official documentation of the Mattermost Web
44
* Services API and you can extend it by following the directives of the documentation.
55
*
6-
* For the full copyright and license information, please read the LICENSE.txt
7-
* file that was distributed with this source code. For the full list of
8-
* contributors, visit https://github.com/gnello/php-mattermost-driver/contributors
9-
*
106
* God bless this mess.
117
*
128
* @author Luca Agnello <[email protected]>
@@ -127,9 +123,9 @@ public function getUsersListByIds(array $requestOptions)
127123
* @param $limit
128124
* @return \Psr\Http\Message\ResponseInterface
129125
*/
130-
public function getUserOfChannel($team_id, $channel_id, $offset, $limit)
126+
public function getUserInChannel($team_id, $channel_id, $offset, $limit)
131127
{
132-
$uri = TeamModel::$endpoint . '/' . $team_id . ChannelModel::$endpoint . '/' . $channel_id . '/' . self::$endpoint . '/' . $offset . '/' . $limit;
128+
$uri = TeamModel::$endpoint . '/' . $team_id . '/channels/' . $channel_id . '/' . self::$endpoint . '/' . $offset . '/' . $limit;
133129
return $this->client->get($uri);
134130
}
135131

@@ -140,9 +136,9 @@ public function getUserOfChannel($team_id, $channel_id, $offset, $limit)
140136
* @param $limit
141137
* @return \Psr\Http\Message\ResponseInterface
142138
*/
143-
public function getUserNotOfChannel($team_id, $channel_id, $offset, $limit)
139+
public function getUserNotInChannel($team_id, $channel_id, $offset, $limit)
144140
{
145-
$uri = TeamModel::$endpoint . '/' . $team_id . ChannelModel::$endpoint . '/' . $channel_id . '/' . self::$endpoint . '/not_in_channel/' . $offset . '/' . $limit;
141+
$uri = TeamModel::$endpoint . '/' . $team_id . '/channels/' . $channel_id . '/' . self::$endpoint . '/not_in_channel/' . $offset . '/' . $limit;
146142
return $this->client->post($uri);
147143
}
148144

@@ -204,7 +200,7 @@ public function sendPasswordResetEmail(array $requestOptions)
204200
* @param $requestOptions
205201
* @return \Psr\Http\Message\ResponseInterface
206202
*/
207-
public function restUserPassword(array $requestOptions)
203+
public function resetUserPassword(array $requestOptions)
208204
{
209205
return $this->client->post(self::$endpoint . '/reset_password', $requestOptions);
210206
}
@@ -237,7 +233,7 @@ public function autocompleteUsersOfTeam($team_id, array $requestOptions)
237233
*/
238234
public function autocompleteUsersOfChannel($team_id, $channel_id, array $requestOptions)
239235
{
240-
$uri = TeamModel::$endpoint . '/' . $team_id . ChannelModel::$endpoint . '/' . $channel_id . '/' . self::$endpoint . '/autocomplete';
236+
$uri = TeamModel::$endpoint . '/' . $team_id . '/channels/' . $channel_id . '/' . self::$endpoint . '/autocomplete';
241237
return $this->client->get($uri, $requestOptions);
242238
}
243239
}

0 commit comments

Comments
 (0)