<?php
/**
  * Ahead WebSoft Technologies Pvt Ltd.
  * @copyright  Copyright 2006-2026 Ahead WebSoft Technologies Pvt Ltd.
  * @license    https://www.socialengine.com/policies
*/
class Payment_Plugin_Menus {

  public function onMenuInitialize_CoreMiniCurrency($row) {
  
    // Have any gateways or packages been added yet?
    if(Engine_Api::_()->getDbtable('gateways', 'payment')->getEnabledGatewayCount() <= 0)
      return false;
    
    $enabledCurrencies = Engine_Api::_()->getDbTable('currencies', 'payment')->getCurrencies(array('enabled' => 1, 'change_rate' => 1));
    if(engine_in_array(engine_count($enabledCurrencies), array(0,1)))
      return false;

    return true;
  }
  
  public function onMenuInitialize_UserSettingsPayment($row)
  {
    // Have any gateways or packages been added yet?
    if(Engine_Api::_()->getDbtable('gateways', 'payment')->getEnabledGatewayCount() <= 0) {
      return false;
    }

    if(Engine_Api::_()->getDbtable('packages', 'payment')->getEnabledAfterSignupPackageCount() <= 0)
      return false;
    
    $subscriptionsTable = Engine_Api::_()->getDbtable('subscriptions', 'payment');
    $user = Engine_Api::_()->user()->getViewer();
    $currentSubscription = $subscriptionsTable->fetchRow(array(
      'user_id = ?' => $user->getIdentity(),
      'active = ?' => true,
    ));
    
    if(!$currentSubscription) {
      return false;
    }
    return true;
  }
  
  public function onMenuInitialize_UserSettingsVerification($row) {
    $user = Engine_Api::_()->user()->getViewer();
    $package = Engine_Api::_()->getDbTable('verificationpackages', 'payment')->getPackage(array('level_id' => $user->level_id));
    if(engine_in_array($package->verified, array(0,1)))
      return false;
    return true;
  }
    
  public function onMenuInitialize_UserSettingsWallet($row) {

    // Have any gateways or packages been added yet?
    if(Engine_Api::_()->getDbtable('gateways', 'payment')->getEnabledGatewayCount() <= 0) {
      return false;
    }

    if(!Engine_Api::_()->getDbtable('gateways', 'payment')->getEnabledWalletGateway())
      return false;
    return true;
  }
  
  public function onMenuInitialize_UserSettingsTransaction($row)
  {
    $user = Engine_Api::_()->user()->getViewer();
    
    // Have any gateways or packages been added yet?
    if(Engine_Api::_()->getDbtable('gateways', 'payment')->getEnabledGatewayCount() <= 0) {
      return false;
    }
    
    $transaction = Engine_Api::_()->getDbTable('transactions', 'payment')->getTransaction(array('user_id' => $user->getIdentity(),'fromMenu'=>true));

    if(empty($transaction)) {
      return false;
    }
    return true;
  }
}
