Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -12,30 +12,46 @@
|
||||
namespace IPS\nexus\extensions\core\LiveSearch;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\core\extensions\core\LiveSearch\Members;
|
||||
use IPS\Db;
|
||||
use IPS\Dispatcher;
|
||||
use IPS\Extensions\LiveSearchAbstract;
|
||||
use IPS\Member;
|
||||
use IPS\nexus\Customer;
|
||||
use IPS\nexus\Invoice;
|
||||
use IPS\nexus\Purchase;
|
||||
use IPS\nexus\Purchase\LicenseKey;
|
||||
use IPS\nexus\Transaction;
|
||||
use IPS\Patterns\ActiveRecordIterator;
|
||||
use IPS\Theme;
|
||||
use OutOfRangeException;
|
||||
use function defined;
|
||||
use function is_numeric;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ACP Live Search Extension
|
||||
*/
|
||||
class _Nexus
|
||||
class Nexus extends LiveSearchAbstract
|
||||
{
|
||||
/**
|
||||
* Check we have access
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasAccess()
|
||||
public function hasAccess(): bool
|
||||
{
|
||||
return \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'invoices_manage' )
|
||||
or \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'transactions_manage' )
|
||||
or \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'customers', 'purchases_view' )
|
||||
or \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'support', 'requests_manage' )
|
||||
or \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'customers', 'customers_view' )
|
||||
or \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'customers', 'lkeys_view' );
|
||||
return Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'invoices_manage' )
|
||||
or Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'transactions_manage' )
|
||||
or Member::loggedIn()->hasAcpRestriction( 'nexus', 'customers', 'purchases_view' )
|
||||
or Member::loggedIn()->hasAcpRestriction( 'nexus', 'customers', 'customers_view' )
|
||||
or Member::loggedIn()->hasAcpRestriction( 'nexus', 'customers', 'lkeys_view' );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -44,69 +60,55 @@ class _Nexus
|
||||
* @param string $searchTerm Search Term
|
||||
* @return array Array of results
|
||||
*/
|
||||
public function getResults( $searchTerm )
|
||||
public function getResults( string $searchTerm ): array
|
||||
{
|
||||
$results = array();
|
||||
|
||||
/* Numeric */
|
||||
if ( \is_numeric( $searchTerm ) )
|
||||
if ( is_numeric( $searchTerm ) )
|
||||
{
|
||||
/* Invoice */
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'invoices_manage' ) )
|
||||
if ( Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'invoices_manage' ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
$results[] = \IPS\Theme::i()->getTemplate('livesearch', 'nexus')->invoice( \IPS\nexus\Invoice::load( $searchTerm ) );
|
||||
$results[] = Theme::i()->getTemplate('livesearch', 'nexus')->invoice( Invoice::load( $searchTerm ) );
|
||||
}
|
||||
catch ( \OutOfRangeException $e ) { }
|
||||
catch ( OutOfRangeException ) { }
|
||||
}
|
||||
|
||||
/* Transaction */
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'transactions_manage' ) )
|
||||
if ( Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'transactions_manage' ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
$results[] = \IPS\Theme::i()->getTemplate('livesearch', 'nexus')->transaction( \IPS\nexus\Transaction::load( $searchTerm ) );
|
||||
$results[] = Theme::i()->getTemplate('livesearch', 'nexus')->transaction( Transaction::load( $searchTerm ) );
|
||||
}
|
||||
catch ( \OutOfRangeException $e ) { }
|
||||
catch ( OutOfRangeException ) { }
|
||||
}
|
||||
|
||||
/* Purchase */
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'customers', 'purchases_view' ) )
|
||||
if ( Member::loggedIn()->hasAcpRestriction( 'nexus', 'customers', 'purchases_view' ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
$results[] = \IPS\Theme::i()->getTemplate('livesearch', 'nexus')->purchase( \IPS\nexus\Purchase::load( $searchTerm ) );
|
||||
$results[] = Theme::i()->getTemplate('livesearch', 'nexus')->purchase( Purchase::load( $searchTerm ) );
|
||||
}
|
||||
catch ( \OutOfRangeException $e ) { }
|
||||
}
|
||||
|
||||
/* Support */
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'support', 'requests_manage' ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
$supportRequest = \IPS\nexus\Support\Request::load( $searchTerm );
|
||||
if ( $supportRequest->canView() )
|
||||
{
|
||||
$results[] = \IPS\Theme::i()->getTemplate('livesearch', 'nexus')->support( $supportRequest );
|
||||
}
|
||||
}
|
||||
catch ( \OutOfRangeException $e ) { }
|
||||
catch ( OutOfRangeException ) { }
|
||||
}
|
||||
|
||||
/* Customer */
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'customers', 'customers_view' ) )
|
||||
if ( Member::loggedIn()->hasAcpRestriction( 'nexus', 'customers', 'customers_view' ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
$customer = \IPS\nexus\Customer::load( $searchTerm );
|
||||
$customer = Customer::load( $searchTerm );
|
||||
if ( $customer->member_id )
|
||||
{
|
||||
$results[] = \IPS\Theme::i()->getTemplate('livesearch', 'nexus')->customer( $customer );
|
||||
$results[] = Theme::i()->getTemplate('livesearch', 'nexus')->customer( $customer );
|
||||
}
|
||||
}
|
||||
catch ( \OutOfRangeException $e ) { }
|
||||
catch ( OutOfRangeException ) { }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,38 +116,38 @@ class _Nexus
|
||||
else
|
||||
{
|
||||
/* License Key */
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'customers', 'lkeys_view' ) )
|
||||
if ( Member::loggedIn()->hasAcpRestriction( 'nexus', 'customers', 'lkeys_view' ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
$results[] = \IPS\Theme::i()->getTemplate('livesearch', 'nexus')->licensekey( \IPS\nexus\Purchase\LicenseKey::load( $searchTerm ) );
|
||||
$results[] = Theme::i()->getTemplate('livesearch', 'nexus')->licensekey( LicenseKey::load( $searchTerm ) );
|
||||
}
|
||||
catch ( \OutOfRangeException $e ) { }
|
||||
catch ( OutOfRangeException ) { }
|
||||
}
|
||||
|
||||
/* Customers */
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'customers', 'customers_view' ) )
|
||||
if ( Member::loggedIn()->hasAcpRestriction( 'nexus', 'customers', 'customers_view' ) )
|
||||
{
|
||||
if( \IPS\core\extensions\core\LiveSearch\Members::canPerformInlineSearch() )
|
||||
if( Members::canPerformInlineSearch() )
|
||||
{
|
||||
$query = \IPS\Db::i()->select( '*', 'nexus_customers', array( \IPS\Db::i()->like( array( 'core_members.name', 'core_members.email', "CONCAT( LOWER( nexus_customers.cm_first_name ), ' ', LOWER( nexus_customers.cm_last_name ) )" ), $searchTerm, TRUE, TRUE, TRUE ) ), NULL, 50 )->join( 'core_members', 'core_members.member_id=nexus_customers.member_id' );
|
||||
$query = Db::i()->select( '*', 'nexus_customers', array( Db::i()->like( array( 'core_members.name', 'core_members.email', "CONCAT( LOWER( nexus_customers.cm_first_name ), ' ', LOWER( nexus_customers.cm_last_name ) )" ), $searchTerm, TRUE, TRUE, TRUE ) ), NULL, 50 )->join( 'core_members', 'core_members.member_id=nexus_customers.member_id' );
|
||||
}
|
||||
else
|
||||
{
|
||||
$query = \IPS\Db::i()->select( '*', 'nexus_customers', array( \IPS\Db::i()->like( array( 'core_members.name', 'core_members.email', 'nexus_customers.cm_first_name', 'nexus_customers.cm_last_name', "CONCAT( LOWER( nexus_customers.cm_first_name ), ' ', LOWER( nexus_customers.cm_last_name ) )" ), $searchTerm, TRUE, TRUE, FALSE ) ), NULL, 50 )->join( 'core_members', 'core_members.member_id=nexus_customers.member_id' );
|
||||
$query = Db::i()->select( '*', 'nexus_customers', array( Db::i()->like( array( 'core_members.name', 'core_members.email', 'nexus_customers.cm_first_name', 'nexus_customers.cm_last_name', "CONCAT( LOWER( nexus_customers.cm_first_name ), ' ', LOWER( nexus_customers.cm_last_name ) )" ), $searchTerm ) ), NULL, 50 )->join( 'core_members', 'core_members.member_id=nexus_customers.member_id' );
|
||||
}
|
||||
|
||||
foreach ( new \IPS\Patterns\ActiveRecordIterator( $query, 'IPS\nexus\Customer' ) as $customer )
|
||||
foreach ( new ActiveRecordIterator( $query, 'IPS\nexus\Customer' ) as $customer )
|
||||
{
|
||||
$results[] = \IPS\Theme::i()->getTemplate('livesearch', 'nexus')->customer( $customer );
|
||||
$results[] = Theme::i()->getTemplate('livesearch', 'nexus')->customer( $customer );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* For either, search for transaction gateway IDs */
|
||||
foreach ( \IPS\Db::i()->select( '*', 'nexus_transactions', array( 't_gw_id=?', $searchTerm ) ) as $transactionData )
|
||||
foreach ( Db::i()->select( '*', 'nexus_transactions', array( 't_gw_id=?', $searchTerm ) ) as $transactionData )
|
||||
{
|
||||
$results[] = \IPS\Theme::i()->getTemplate( 'livesearch', 'nexus' )->transaction( \IPS\nexus\Transaction::constructFromData( $transactionData ) );
|
||||
$results[] = Theme::i()->getTemplate( 'livesearch', 'nexus' )->transaction( Transaction::constructFromData( $transactionData ) );
|
||||
}
|
||||
|
||||
/* Return */
|
||||
@@ -157,8 +159,8 @@ class _Nexus
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isDefault()
|
||||
public function isDefault(): bool
|
||||
{
|
||||
return \IPS\Dispatcher::i()->application->directory == 'nexus';
|
||||
return Dispatcher::i()->application->directory == 'nexus';
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user