Ejemplo n.º 1
0
 public function register()
 {
     $require = array('device_id' => true);
     $params = $this->controller->getParams($require);
     $device = GcmDevices::model()->create($this->controller->identity->getId(), $params['device_id']);
     if ($device) {
         $this->controller->data = $device;
     } else {
         throw new ApiException($device->errors, 500);
     }
 }
Ejemplo n.º 2
0
 public function unregister()
 {
     $require = array('device_id' => true);
     $params = $this->controller->getParams($require);
     /**
      * @var GcmDevices $device
      */
     $device = GcmDevices::model()->findByDeviceId($params['device_id']);
     if (!$device) {
         throw new NotFoundApiException('DeviceNotFound');
     }
     if ($device->_id != $this->controller->identity->getId()) {
         throw new AccessDeniedApiException('DeviceRegisterToForeignUser');
     }
     $device->delete();
     $this->controller->setMessage('DeviceDeleted');
 }
Ejemplo n.º 3
0
 /**
  * Use only for one user
  *
  * @param int $userId;
  * @param array $config
  */
 public function __construct($userId, $config)
 {
     $this->devices = GcmDevices::model()->findByPk($userId);
     $this->data = array();
     $this->config = $config;
 }