TTi18n::gettext( 'Web' ), 200 => TTi18n::gettext( 'iOS' ), 300 => TTi18n::gettext( 'Android' ), ]; break; } return $retval; } /** * @param $data * @return array */ function _getVariableToFunctionMap( $data ) { $variable_function_map = [ 'id' => 'ID', 'platform_id' => 'Platform', 'device_token' => 'DeviceToken', 'user_agent' => 'UserAgent', 'user_id' => 'User', 'deleted' => 'Deleted', ]; return $variable_function_map; } /** * @return bool|string */ function getPlatform() { return $this->getGenericDataValue( 'platform_id' ); } /** * @param $value * @return bool */ function setPlatform( $value ) { $value = (int)$value; return $this->setGenericDataValue( 'platform_id', $value ); } /** * @return bool|string */ function getDeviceToken() { return (string)$this->getGenericDataValue( 'device_token' ); } /** * @param $value * @return bool */ function setDeviceToken( $value ) { $value = trim( $value ); return $this->setGenericDataValue( 'device_token', $value ); } /** * @return bool|string */ function getUserAgent() { return (string)$this->getGenericDataValue( 'user_agent' ); } /** * @param $value * @return bool */ function setUserAgent( $value ) { $value = trim( $value ); return $this->setGenericDataValue( 'user_agent', $value ); } /** * @return bool */ function getUserObject() { return $this->getGenericObject( 'UserListFactory', $this->getUser(), 'user_obj' ); } /** * @return bool|mixed */ function getUser() { return $this->getGenericDataValue( 'user_id' ); } /** * @param string $value UUID * @return bool */ function setUser( $value ) { $value = TTUUID::castUUID( $value ); return $this->setGenericDataValue( 'user_id', $value ); } /** * @param string $user_id UUID * @param string $device_token * @param string $id UUID * @return bool */ function isUnique($user_id, $device_token, $id ) { $ph = [ 'id' => TTUUID::castUUID( $id ), 'user_id' => TTUUID::castUUID( $user_id ), 'device_token' => (string)$device_token ]; $query = 'select id from ' . $this->getTable() . ' where id != ? AND user_id = ? AND device_token = ? AND deleted = 0'; $id = $this->db->GetOne( $query, $ph ); if ( $id === false ) { return true; } else { if ( $id == $this->getId() ) { return true; } } return false; } /** * @param bool $ignore_warning * @return bool */ function Validate( $ignore_warning = true ) { // // BELOW: Validation code moved from set*() functions. // if ( $this->getUser() != TTUUID::getZeroID() ) { $ulf = TTnew( 'UserListFactory' ); /** @var UserListFactory $ulf */ $this->Validator->isResultSetWithRows( 'user', $ulf->getByID( $this->getUser() ), TTi18n::gettext( 'Invalid Employee' ) ); } // Platform $this->Validator->inArrayKey( 'platform', $this->getPlatform(), TTi18n::gettext( 'Incorrect Platform for device token.' ), $this->getOptions( 'platform' ) ); if ( $this->isUnique($this->getUser(), $this->getDeviceToken(), $this->getID() ) == false ) { $this->Validator->isTrue( 'device_id', false, TTi18n::gettext( 'Duplicate device token already exists' ) ); } return true; } /** * @param $data * @return bool */ function setObjectFromArray( $data ) { if ( is_array( $data ) ) { $variable_function_map = $this->getVariableToFunctionMap(); foreach ( $variable_function_map as $key => $function ) { if ( isset( $data[$key] ) ) { $function = 'set' . $function; switch ( $key ) { default: if ( method_exists( $this, $function ) ) { $this->$function( $data[$key] ); } break; } } } $this->setCreatedAndUpdatedColumns( $data ); return true; } return false; } /** * @param null $include_columns * @return array * @noinspection PhpMissingBreakStatementInspection */ function getObjectAsArray( $include_columns = null ) { $data = []; $variable_function_map = $this->getVariableToFunctionMap(); if ( is_array( $variable_function_map ) ) { foreach ( $variable_function_map as $variable => $function_stub ) { if ( $include_columns == null || ( isset( $include_columns[$variable] ) && $include_columns[$variable] == true ) ) { $function = 'get' . $function_stub; switch ( $variable ) { default: if ( method_exists( $this, $function ) ) { $data[$variable] = $this->$function(); } break; } } } $this->getCreatedAndUpdatedColumns( $data, $include_columns ); } return $data; } /** * This is called for every record everytime, and doesn't help much because of that. * This has to be enabled to properly log modifications though. * @param $log_action * @return bool */ function addLog( $log_action ) { return TTLog::addEntry( $this->getId(), $log_action, TTi18n::getText( 'Notification Device Token' ) . ' - ' . TTi18n::getText( 'Type' ) . ': ' . Option::getByKey( $this->getPlatform(), $this->getOptions( 'platform' ) ), null, $this->getTable(), $this ); } }