ChannelsController::getAction()   A
last analyzed

Complexity

Conditions 3
Paths 11

Size

Total Lines 22
Code Lines 16

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 22
rs 9.2
cc 3
eloc 16
nc 11
nop 0
1
<?php
2
/**
3
 * Slack.com Integration
4
 *
5
 * PHP Version 5
6
 *
7
 * @category  Steverobbins
8
 * @package   Steverobbins_Slack
9
 * @author    Steve Robbins <[email protected]>
10
 * @copyright Copyright 2015 Steve Robbins (http://steverobbins.com)
11
 * @license   http://creativecommons.org/licenses/by/3.0/deed.en_US Creative Commons Attribution 3.0 Unported License
12
 */
13
14
/**
15
 * Controller for ajax system config channel getter
16
 */
17
class Steverobbins_Slack_Adminhtml_Slack_System_Config_ChannelsController
18
    extends Mage_Adminhtml_Controller_Action
19
{
20
    /**
21
     * ACL
22
     *
23
     * @return boolean
24
     */
25
    protected function _isAllowed()
26
    {
27
        return true;
28
    }
29
30
    /**
31
     * Get channel listing from API
32
     *
33
     * @return void
34
     */
35
    public function getAction()
36
    {
37
        $response = array(
38
            'success' => 0
39
        );
40
        $channels = array();
41
        try {
42
            $list = Mage::getModel('slack/api_channels')->list();
43
            foreach ($list->getChannels() as $channel) {
44
                $channels[$channel['id']] = $channel['name'];
45
            }
46
            Mage::getSingleton('slack/config_settings')->setChannels($channels);
47
            $response = array(
48
                'success' => 1,
49
                'html'    => $this->getLayout()->createBlock('slack/adminhtml_system_config_channels_list')->toHtml()
50
            );
51
        } catch (Exception $e) {
52
            Mage::logException($e);
53
        }
54
        $this->getResponse()->clearHeaders()->setHeader('Content-type', ' application/json', true);
55
        $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($response));
56
    }
57
}
58