Skip to content

Commit

Permalink
Fixed the viewuser* methods to use query_db internally instead.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Goodchild committed Jan 5, 2018
1 parent 7abde37 commit 1c831d0
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 23 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ composer require gyron/net2web

Alternatively you can update the `"require": {` section in your `composer.json` with a line reading:
```
"gyron/net2web" : "v1.0.1"
"gyron/net2web" : "v1.0.2"
```

## Usage
### Quick Start
Simply copy and paste the following code, and adjust the values:
```
$oNet2Encryption = new \Gyron\Net2Web\Encryption( '1234567890123456', \Gyron\Net2Web\Encryption::OpenSSL );
$oNet2Encryption = new \Gyron\Net2Web\Encryption( 'ENCRYPTION KEY', \Gyron\Net2Web\Encryption::OpenSSL );
$oNet2Session = new \Gyron\Net2Web\Session( 'USERID', 'PASSWORD', 'NET2 SERVER IP', '7070', $oNet2Encryption );
$oNet2Client = new \Gyron\Net2Web\Client( $oNet2Session );
```
Expand Down Expand Up @@ -73,12 +73,12 @@ class AccessApiFactory {
$sSessionId = trim( file_get_contents( $sCacheFile ) );
}
$oNet2Encryption = new Encryption( '1234567890123456', Encryption::OpenSSL );
$oNet2Session = new Session( $aConfig['user_id'], $aConfig['password'], $aConfig['ip'], (string)$aConfig['port'], $oNet2Encryption, $sSessionId );
$oNet2Encryption = new Encryption( $aConfig['enckey']', Encryption::OpenSSL );
$oNet2Session = new Session( $aConfig['user'], $aConfig['password'], $aConfig['host'], (string)$aConfig['port'], $oNet2Encryption, $sSessionId );
if ( $sSessionId != $oNet2Session->getSessionId() ) {
file_put_contents( $sCacheFile, trim( $oNet2Session->getSessionId() ) );
}
return ( new Client( oNet2Session ) );
return ( new Client( $oNet2Session ) );
}
}
```
22 changes: 11 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@
"homepage": "http://www.gyron.net",
"license": "MIT",
"authors": [
{
"name": "Dave Goodchild",
"email": "[email protected]"
}
{
"name": "Dave Goodchild",
"email": "[email protected]"
}
],
"require": {
"php": ">=7.1"
"php": ">=7.1"
},
"require-dev": {
"phpunit/phpunit": "^6.4@dev"
},
"autoload": {
"psr-4": {
"Gyron\\": "src/"
},
"exclude-from-classmap": [
"/Tests/"
]
"psr-4": {
"Gyron\\": "src/"
},
"exclude-from-classmap": [
"/Tests/"
]
},
"minimum-stability": "dev"
}
54 changes: 49 additions & 5 deletions src/Net2Web/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,11 @@ public function adminTablenameList(): array {

/**
* @param string $sTablename
* @param string $sWhere
* @return array
*/
public function adminRecordList( string $sTablename ): array {
$oXmlQuery = $this->queryDb( sprintf( "SELECT * FROM %s", $sTablename ) );
public function adminRecordList( string $sTablename, $sWhere = '' ): array {
$oXmlQuery = $this->queryDb( sprintf( "SELECT * FROM %s%s", $sTablename, empty( $sWhere )? '': ' WHERE '.$sWhere ) );
$aRecords = [];
foreach ( $oXmlQuery->NewDataSet->Table as $oXmlTable ) {
$aRecord = [];
Expand Down Expand Up @@ -281,27 +282,29 @@ public function viewUserEvents( int $nUserId, int $nLimit = 20 ): array {
}

/**
* Disabled due to author of Net2Web explaining the viewuserrecord is somewhat buggy
* @param int $nUserId
* @return User
*/
public function viewUserRecord( int $nUserId ): User {
private function _viewUserRecord( int $nUserId ): User {
$oXmlUser = $this->send( 'viewuserrecords', array( 'sqlwhere' => sprintf( "userid = %s", $nUserId ) ) );
return ( new User( $oXmlUser->UsersSet->User ) );
}

/**
* Disabled due to author of Net2Web explaining the viewuserrecord is somewhat buggy
* @param string $sUniqueId
* @return User
*/
public function viewUserRecordByUniqueId( string $sUniqueId ): User {
private function _viewUserRecordByUniqueId( string $sUniqueId ): User {
$oXmlUser = $this->send( 'viewuserrecords', array( 'sqlwhere' => sprintf( "field14_50 = '%s'", $sUniqueId ) ) );
return ( new User( $oXmlUser->UsersSet->User ) );
}

/**
* @return User[]
*/
public function viewUserRecords(): array {
private function _viewUserRecords(): array {
$oXmlUsers = $this->send( 'viewuserrecords', array( 'sqlwhere' => "active = 'true'" ) );
$aUsers = [];
foreach ( $oXmlUsers->UsersSet->User as $oXmlUser ) {
Expand All @@ -310,6 +313,47 @@ public function viewUserRecords(): array {
return $aUsers;
}

/**
* @param int $nUserId
* @return User
*/
public function viewUserRecord( int $nUserId ) {
$oXmlUser = $this->queryDb( sprintf( "SELECT * FROM UsersEx WHERE UserID = '%s'", $nUserId ) );
if ( !isset( $oXmlUser->NewDataSet->Table ) ) {
throw new \Exception( 'User not found' );
}
return ( new User( $oXmlUser->NewDataSet->Table[0] ) );
}

/**
* @param string $sUniqueId
* @return User
* @throws \Exception
*/
public function viewUserRecordByUniqueId( string $sUniqueId ): User {
$oXmlUser = $this->queryDb( sprintf( "SELECT * FROM UsersEx WHERE Field14_50 = '%s'", $sUniqueId ) );
if ( !isset( $oXmlUser->NewDataSet->Table ) ) {
throw new \Exception( 'User not found' );
}
return ( new User( $oXmlUser->NewDataSet->Table[0] ) );
}

/**
* @return User[]
* @throws \Exception
*/
public function viewUserRecords(): array {
$oXmlUsers = $this->queryDb( "SELECT * FROM UsersEx WHERE Active = 'true'" );
if ( !isset( $oXmlUsers->NewDataSet->Table ) ) {
throw new \Exception( 'Active users not found' );
}
$aUsers = [];
foreach ( $oXmlUsers->NewDataSet->Table as $oXmlUser ) {
$aUsers[] = ( new User( $oXmlUser ) );
}
return $aUsers;
}

/**
* @param string $sQuery
* @return \SimpleXMLElement
Expand Down
4 changes: 2 additions & 2 deletions src/sample/advanced.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ private function session( array $aConfig ): Session {
$sSessionId = trim( file_get_contents( $sCacheFile ) );
}

$oNet2Encryption = new Encryption( '1234567890123456', Encryption::OpenSSL );
$oNet2Session = new Session( $aConfig['user_id'], $aConfig['password'], $aConfig['ip'], (string)$aConfig['port'], $oNet2Encryption, $sSessionId );
$oNet2Encryption = new Encryption( $aConfig['enckey'], Encryption::OpenSSL );
$oNet2Session = new Session( $aConfig['user'], $aConfig['password'], $aConfig['host'], (string)$aConfig['port'], $oNet2Encryption, $sSessionId );
if ( $sSessionId != $oNet2Session->getSessionId() ) {
file_put_contents( $sCacheFile, trim( $oNet2Session->getSessionId() ) );
}
Expand Down

0 comments on commit 1c831d0

Please sign in to comment.