I'm trying to refactor my code, and currently have a function in my component->controller to send slack notifications. However I want to extend notifications, so rather than have multiple functions, passing through params, i thought i'd put all notifications into a widget to be called within the controller.
I've compiled everything i need so far into a widget, but whenever i try and run this, i get the error
Undefined variable: type
Here's my widget being called in my controller when as item is actioned
$this->widget('application.components.DMNotifications', array(
'type' => 'slack',
'slack_content' => 'event_close',
));
And here's my component widget
<?php
class DMNotifications extends CWidget {
public $type = '';
public $sendPermission = 0;
//slack vars
public $slack_content = null;
public $newCompany = null;
public $company = null;
public $fullname = null;
public $newInstance = null;
public static $SLACK_REGISTRATION = "registration";
public static $SLACK_EVENTPUBLISH = "event_publish";
public static $SLACK_EVENTCLOSE = "event_close";
public static $SLACK_EVENTCAPACITYTRIP = "event_capacity_trip";
public static $SLACK_EMAILNOTIFICATIONS = "email_notifications";
public function init() {
if ($type === 1){
$this->slack();
}
parent::init();
}
public function run() {
}
public function slack(){
$sendPermission = ( Options::model()->isSlackWebhookOptDelegateReg() ? 1 : 0 );
$text = "You have a new message on the " . Options::model()->getSiteName();
$url = Options::getSlackWebhookUrl();
$json_data = json_encode(array(
"text" => $text,
"username" => "XX",
"icon_url" => "xx.png",
"channel" => Options::getSlackWebhookChannel()
));
$post_data['payload'] = $json_data;
if ($sendPermission === 1){
$output = Yii::app()->curl->post($url, $post_data);
}
}
}
if i comment out the type error, i get a different error because nothing is being passed by the params. Either i've totally missed a blinding mistake, or what i'm trying to do isn't a widget.
Can anyone help???