2013-10-08 14:03:31 -07:00

70 lines
1.4 KiB
PHP

<?php
class Crunchbutton_Support_Note extends Cana_Table {
public function __construct($id = null) {
parent::__construct();
$this
->table('support_note')
->idVar('id_support_note')
->load($id);
}
public function notify() {
self::notify_by_sms();
}
public function notify_by_sms() {
$env = c::getEnv();
$twilio = new Twilio(
c::config()->twilio->{$env}->sid,
c::config()->twilio->{$env}->token
);
$support = $this->support();
$phone = $this->support()->phone;
if (!$phone) return;
$rep_name = $support->rep()->name;
$msg = ''.($rep_name ? $rep_name.': ' : '').$this->text;
$msgs = str_split($msg, 160);
foreach($msgs as $msg) {
$twilio->account->sms_messages->create(
c::config()->twilio->{$env}->outgoingTextCustomer,
'+1'.$phone,
$msg
);
}
}
public function save() {
date_default_timezone_set('UTC'); // always save in utc
$this->datetime = date('Y-m-d H:i:s e');
parent::save();
}
public function support() {
$note = Support::o($this->id_support);
return $note;
}
public function relativeTime() {
return Crunchbutton_Util::relativeTime($this->datetime);
}
public function date() {
if (!isset($this->_date)) {
$this->_date = new DateTime($this->date, new DateTimeZone(c::config()->timezone));
}
return $this->_date;
}
public function repTime() {
$date = $this->date();
$date->setTimezone(c::admin()->timezone());
return $date;
}
}