diff --git a/README.md b/README.md index 4c41c4a..9a85783 100644 --- a/README.md +++ b/README.md @@ -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 ); ``` @@ -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 ) ); } } ``` diff --git a/composer.json b/composer.json index 3572e7a..9e93156 100644 --- a/composer.json +++ b/composer.json @@ -6,24 +6,24 @@ "homepage": "http://www.gyron.net", "license": "MIT", "authors": [ - { - "name": "Dave Goodchild", - "email": "dave.goodchild@gyron.net" - } + { + "name": "Dave Goodchild", + "email": "dave.goodchild@gyron.net" + } ], "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" } diff --git a/src/Net2Web/Client.php b/src/Net2Web/Client.php index 893ea67..b2fcfe8 100644 --- a/src/Net2Web/Client.php +++ b/src/Net2Web/Client.php @@ -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 = []; @@ -281,19 +282,21 @@ 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 ) ); } @@ -301,7 +304,7 @@ public function viewUserRecordByUniqueId( string $sUniqueId ): 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 ) { @@ -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 diff --git a/src/sample/advanced.php b/src/sample/advanced.php index 7a3cb4c..aeac1db 100644 --- a/src/sample/advanced.php +++ b/src/sample/advanced.php @@ -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() ) ); }