getOptions( 'type' ); break; case 'devices': $upnf = TTNew( 'UserPreferenceNotificationFactory' ); $retval = $upnf->getOptions( 'devices' ); break; case 'status': $upnf = TTNew( 'UserPreferenceNotificationFactory' ); $retval = $upnf->getOptions( 'status' ); break; case 'priority': $upnf = TTNew( 'UserPreferenceNotificationFactory' ); $retval = $upnf->getOptions( 'priority' ); break; } return $retval; } /** * @param $data * @return array */ function _getVariableToFunctionMap( $data ) { $variable_function_map = [ 'id' => 'ID', 'user_id' => 'User', 'type_id' => 'Type', 'priority_id' => 'Priority', 'status_id' => 'Status', 'device_id' => 'Device', 'reminder_delay' => 'ReminderDelay', 'user_default_id' => 'UserDefault', 'deleted' => 'Deleted', ]; return $variable_function_map; } /** * @return bool|mixed */ function getUserDefault() { return $this->getGenericDataValue( 'user_default_id' ); } /** * @param string $value UUID * @return bool */ function setUserDefault( $value ) { $value = TTUUID::castUUID( $value ); Debug::Text( 'ID: ' . $value, __FILE__, __LINE__, __METHOD__, 10 ); return $this->setGenericDataValue( 'user_default_id', $value ); } /** * @return int */ function getStatus() { return $this->getGenericDataValue( 'status_id' ); } /** * @param $value * @return bool */ function setStatus( $value ) { $value = (int)trim( $value ); return $this->setGenericDataValue( 'status_id', $value ); } /** * @return int */ function getPriority() { return $this->getGenericDataValue( 'priority_id' ); } /** * @param $value * @return bool */ function setPriority( $value ) { $value = (int)$value; return $this->setGenericDataValue( 'priority_id', $value ); } /** * @return bool|string */ function getType() { return $this->getGenericDataValue( 'type_id' ); } /** * @param $value * @return bool */ function setType( $value ) { $value = trim( $value ); return $this->setGenericDataValue( 'type_id', $value ); } /** * @return array */ function getDevice() { $value = $this->getGenericDataValue( 'device_id' ); if ( $value !== false ) { //getArrayByBitMask returns array or false - but frontend and other areas expect an array. //Because of that I am making sure to always return an array. $retarr = Option::getArrayByBitMask( $value, $this->getOptions( 'devices' ) ); if ( $retarr !== false ) { return $retarr; } } return []; } /** * @param $value * @return bool */ function setDevice( $arr ) { $value = Option::getBitMaskByArray( $arr, $this->getOptions( 'devices' ) ); return $this->setGenericDataValue( 'device_id', $value ); } /** * @return int */ function getReminderDelay() { return $this->getGenericJSONDataValue( 'reminder_delay' ); } /** * @param int $value Seconds. * @return bool */ function setReminderDelay( $value ) { $value = (int)trim( $value ); return $this->setGenericJSONDataValue( 'reminder_delay', $value ); } /** * @param string $user_default_id UUID * @param string $type_id * @param string $id UUID * @return bool */ function isUnique( $user_default_id, $type_id ) { $ph = [ 'user_default_id' => TTUUID::castUUID( $user_default_id ), 'type_id' => (string)$type_id, ]; $query = 'select id from ' . $this->getTable() . ' where user_default_id = ? AND type_id = ? AND deleted = 0'; $id = $this->db->GetOne( $query, $ph ); if ( $id === false ) { return true; } else { if ( $id == $this->getId() ) { return true; } } return false; } /** * @return bool */ function Validate() { if ( $this->getDeleted() == false ) { $ulf = TTnew( 'UserDefaultListFactory' ); /** @var UserDefaultListFactory $ulf */ $this->Validator->isResultSetWithRows( 'user_default', $ulf->getByID( $this->getUserDefault() ), TTi18n::gettext( 'Invalid User Default' ) ); } // Type $this->Validator->inArrayKey( 'type', $this->getType(), TTi18n::gettext( 'Incorrect Type' ), $this->getOptions( 'type' ) ); // Status $this->Validator->inArrayKey( 'status', $this->getStatus(), TTi18n::gettext( 'Incorrect Status.' ), $this->getOptions( 'status' ) ); // Priority if ( $this->getPriority() != '' ) { $this->Validator->inArrayKey( 'priority', $this->getPriority(), TTi18n::gettext( 'Incorrect Priority.' ), $this->getOptions( 'priority' ) ); } if ( $this->getReminderDelay() != '' ) { $this->Validator->isNumeric( 'reminder_delay', $this->getReminderDelay(), TTi18n::gettext( 'Reminder Delay must only be digits' ) ); } if ( $this->isUnique( $this->getUserDefault(), $this->getType() ) == false ) { $this->Validator->isTrue( 'type_id', false, TTi18n::gettext( 'Type already exists for this user default notification' ) ); } 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; } } ?>