src/ApplicationBundle/Twig/GeneralExtension.php line 27

Open in your IDE?
  1. <?php
  2. namespace ApplicationBundle\Twig;
  3. use ApplicationBundle\Constants\BuddybeeConstant;
  4. use ApplicationBundle\Constants\GeneralConstant;
  5. use ApplicationBundle\Constants\TaskConstant;
  6. use ApplicationBundle\Modules\Authentication\Constants\UserConstants;
  7. use ApplicationBundle\Modules\Comment\Comment;
  8. use ApplicationBundle\Modules\HumanResource\HumanResource;
  9. use ApplicationBundle\Modules\Inventory\Inventory;
  10. use ApplicationBundle\Modules\Purchase\Purchase;
  11. use ApplicationBundle\Modules\Purchase\Supplier;
  12. use ApplicationBundle\Modules\Sales\Client;
  13. use ApplicationBundle\Modules\Sales\SalesOrderM;
  14. use ApplicationBundle\Modules\System\System;
  15. use ApplicationBundle\Modules\User\Company;
  16. use ApplicationBundle\Modules\User\Department;
  17. use ApplicationBundle\Modules\User\Module;
  18. use ApplicationBundle\Modules\User\Position;
  19. use ApplicationBundle\Modules\User\Users;
  20. use Symfony\Component\HttpFoundation\Session\Session;
  21. use Symfony\Component\Serializer\Encoder\JsonEncoder;
  22. use Symfony\Component\Serializer\Encoder\XmlEncoder;
  23. use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
  24. use Symfony\Component\Serializer\Serializer;
  25. class GeneralExtension extends \Twig_Extension implements \Twig_Extension_GlobalsInterface
  26. {
  27.     protected $em;
  28.     protected $em_goc;
  29.     protected $dm;
  30.     protected $encryptDecrypt;
  31.     public function __construct(\Doctrine\ORM\EntityManager $em, \Doctrine\ORM\EntityManager $em_goc, \ApplicationBundle\Helper\EncryptDecrypt $encryptDecrypt)
  32.     {
  33.         $this->em $em;
  34.         $this->em_goc $em_goc;
  35.         //        $this->dm = $dm;
  36.         $this->encryptDecrypt $encryptDecrypt;
  37.     }
  38.     public function getFilters()
  39.     {
  40.         return array(
  41.             'functionExists' => new \Twig_SimpleFilter('functionExists', array($this'functionExists')),
  42.             'getMicroTime' => new \Twig_SimpleFilter('getMicroTime', array($this'getMicroTime')),
  43.             'isPhpSeven' => new \Twig_SimpleFilter('isPhpSeven', array($this'isPhpSeven')),
  44.             'getGlobalEncryptedDocInfo' => new \Twig_SimpleFilter('getGlobalEncryptedDocInfo', array($this'getGlobalEncryptedDocInfo')),
  45.             'getConvMultFromToWithdrawable' => new \Twig_SimpleFilter('getConvMultFromToWithdrawable', array($this'getConvMultFromToWithdrawable')),
  46.             'getCurrencyListByMarker' => new \Twig_SimpleFilter('getCurrencyListByMarker', array($this'getCurrencyListByMarker')),
  47.             'getDocumentDataDetails' => new \Twig_SimpleFilter('getDocumentDataDetails', array($this'getDocumentDataDetails')),
  48.             'getDocumentDataDetailsForView' => new \Twig_SimpleFilter('getDocumentDataDetailsForView', array($this'getDocumentDataDetailsForView')),
  49.             'getCurrencyList' => new \Twig_SimpleFilter('getCurrencyList', array($this'getCurrencyList')),
  50.             'imageToBase64Encode' => new \Twig_SimpleFilter('imageToBase64Encode', array($this'imageToBase64Encode')),
  51.             'strToHex' => new \Twig_SimpleFilter('strToHex', array($this'strToHex')),
  52.             'toHex' => new \Twig_SimpleFilter('toHex', array($this'toHex')),
  53. //            'getGlobalVars'   => new \Twig_SimpleFilter('getGlobalVars', array($this, 'getGlobals')),
  54.             'jsonDecode' => new \Twig_SimpleFilter('jsonDecode', array($this'jsonDecode')),
  55.             'strpad' => new \Twig_SimpleFilter('strpad', array($this'strpad')),
  56.             'getRandomColor' => new \Twig_SimpleFilter('getRandomColor', array($this'getRandomColor')),
  57.             'getCommentsForDocument' => new \Twig_SimpleFilter('getCommentsForDocument', array($this'getCommentsForDocument')),
  58.             'doSerialize' => new \Twig_SimpleFilter('doSerialize', array($this'doSerialize')),
  59.             'getUsers' => new \Twig_SimpleFilter('getUsers', array($this'getUsers')),
  60.             'getExpSubTypes' => new \Twig_SimpleFilter('getExpSubTypes', array($this'getExpSubTypes')),
  61.             'getUserRestrictions' => new \Twig_SimpleFilter('getUserRestrictions', array($this'getUserRestrictions')),
  62.             'PendingDocList' => new \Twig_SimpleFilter('PendingDocList', array($this'PendingDocList')),
  63.             'getSystemNotice' => new \Twig_SimpleFilter('getSystemNotice', array($this'getSystemNotice')),
  64.             'getProductDataFromFDM' => new \Twig_SimpleFilter('getProductDataFromFDM', array($this'getProductDataFromFDM')),
  65.             'getPositions' => new \Twig_SimpleFilter('getPositions', array($this'getPositions')),
  66.             'getSegregationSettings' => new \Twig_SimpleFilter('getSegregationSettings', array($this'getSegregationSettings')),
  67.             'getLeaveSettings' => new \Twig_SimpleFilter('getLeaveSettings', array($this'getLeaveSettings')),
  68.             'getDepartments' => new \Twig_SimpleFilter('getDepartments', array($this'getDepartments')),
  69.             'getCompanies' => new \Twig_SimpleFilter('getCompanies', array($this'getCompanies')),
  70.             'getCountries' => new \Twig_SimpleFilter('getCountries', array($this'getCountries')),
  71.             'getCountriesBuddyBee' => new \Twig_SimpleFilter('getCountriesBuddyBee', array($this'getCountriesBuddyBee')),
  72.             'getLanguagesBuddyBee' => new \Twig_SimpleFilter('getLanguagesBuddyBee', array($this'getLanguagesBuddyBee')),
  73.             'getBranchList' => new \Twig_SimpleFilter('getBranchList', array($this'getBranchList')),
  74.             'getRegionList' => new \Twig_SimpleFilter('getRegionList', array($this'getRegionList')),
  75.             'getGeographicalRegionList' => new \Twig_SimpleFilter('getGeographicalRegionList', array($this'getGeographicalRegionList')),
  76.             'getClientList' => new \Twig_SimpleFilter('getClientList', array($this'getClientList')),
  77.             'getClientTypeList' => new \Twig_SimpleFilter('getClientTypeList', array($this'getClientTypeList')),
  78.             'getSalesPersonList' => new \Twig_SimpleFilter('getSalesPersonList', array($this'getSalesPersonList')),
  79.             'getColors' => new \Twig_SimpleFilter('getColors', array($this'getColors')),
  80.             'getCountriesIndexed' => new \Twig_SimpleFilter('getCountriesIndexed', array($this'getCountriesIndexed')),
  81.             'getUserCompany' => new \Twig_SimpleFilter('getUserCompany', array($this'getUserCompany')),
  82.             'getSupplierDataForSupplierLogin' => new \Twig_SimpleFilter('getSupplierDataForSupplierLogin', array($this'getSupplierDataForSupplierLogin')),
  83.             'getClientDataForClientLogin' => new \Twig_SimpleFilter('getClientDataForClientLogin', array($this'getClientDataForClientLogin')),
  84.             'getMonthlySummary' => new \Twig_SimpleFilter('getMonthlySummary', array($this'getMonthlySummary')),
  85.             'getRecentSales' => new \Twig_SimpleFilter('getRecentSales', array($this'getRecentSales')),
  86.             'getSoCountAndMore' => new \Twig_SimpleFilter('getSoCountAndMore', array($this'getSoCountAndMore')),
  87.             'getRecentPurchase' => new \Twig_SimpleFilter('getRecentPurchase', array($this'getRecentPurchase')),
  88.             'getPositionModuleTree' => new \Twig_SimpleFilter('getPositionModuleTree', array($this'getPositionModuleTree')),
  89.             'showNecessaryMenu' => new \Twig_SimpleFilter('showNecessaryMenu', array($this'showNecessaryMenu')),
  90.             'showMenuIfAdmin' => new \Twig_SimpleFilter('showMenuIfAdmin', array($this'showMenuIfAdmin')),
  91.             'showNecessaryMenuGeneral' => new \Twig_SimpleFilter('showNecessaryMenuGeneral', array($this'showNecessaryMenuGeneral')),
  92.             'showNecessaryCreateBtn' => new \Twig_SimpleFilter('showNecessaryCreateBtn', array($this'showNecessaryCreateBtn')),
  93.             'todoSummaryList' => new \Twig_SimpleFilter('todoSummaryList', array($this'todoSummaryList')),
  94.             'getEntityDetailsByName' => new \Twig_SimpleFilter('getEntityDetailsByName', array($this'getEntityDetailsByName')),
  95.             'inArray' => new \Twig_SimpleFilter('inArray', array($this'inArray')),
  96.             'encryptMe' => new \Twig_SimpleFilter('encryptMe', array($this'encryptMe')),
  97.             'decryptMe' => new \Twig_SimpleFilter('decryptMe', array($this'decryptMe')),
  98.         );
  99.     }
  100.     public function getFunctions(): array
  101.     {
  102.         return [
  103.             new \Twig\TwigFunction('call_method', [$this'callMethod']),
  104.         ];
  105.     }
  106. //    function qr_code_data_uri($qr_data, $options){
  107. //        qr_code_data_uri($qr_data, $options);
  108. //    }
  109.     public function isPhpSeven($gg='')
  110.     {
  111.         if (version_compare(PHP_VERSION'7.3.0''>=')) {
  112.             return true;
  113.         } else {
  114.             return false;
  115.         }
  116.     }
  117.     public function isMethodExist($object$method)
  118.     {
  119.         return method_exists($object$method);
  120.     }
  121.     public function functionExists($method)
  122.     {
  123.         return function_exists($method) ? $method 'pika' $method 'chu';
  124.     }
  125.     public function getGlobals()
  126.     {
  127.         $session = new Session();
  128.         $class = new \ReflectionClass('ApplicationBundle\Modules\Authentication\Constants\UserConstants');
  129.         $UserConstants $class->getConstants();
  130.         $class = new \ReflectionClass('ApplicationBundle\Constants\BuddybeeConstant');
  131.         $BuddybeeConstant $class->getConstants();
  132.         $classToDoConstant = new \ReflectionClass('ApplicationBundle\Constants\TaskConstant');
  133.         $ToDoConstant $classToDoConstant->getConstants();
  134.         $classTicketConstant = new \ReflectionClass('ApplicationBundle\Constants\TicketConstant');
  135.         $TicketConstant $classTicketConstant->getConstants();
  136.         //        $classReportConstant = new \ReflectionClass('ApplicationBundle\Constants\ReportConstant');
  137.         $classReportConstant = new \ReflectionClass('ApplicationBundle\Constants\ReportConstant');
  138.         return array(
  139.             'session' => $session->all(),
  140.             'url_get' => $_GET,
  141.             'UserConstants' => $UserConstants,
  142.             'BuddybeeConstant' => $BuddybeeConstant,
  143.             'TaskConstant' => $ToDoConstant,
  144.             'TicketConstant' => $TicketConstant,
  145.             'globalReportTypeList' => $classReportConstant->getStaticPropertyValue('reportTypeList'),
  146.             'enabled_report_types' => ['pika' => 'chu']
  147.         );
  148.     }
  149.     function imageToBase64Encode($imagePath)
  150.     {
  151.         $img file_get_contents(
  152.             $imagePath
  153.         );
  154.         return base64_encode($img);
  155.     }
  156.     function getConvMultFromToWithdrawable()
  157.     {
  158.         return BuddybeeConstant::$convMultFromToWithdrawable;
  159.     }
  160.     function getEntityDetailsByName($entityName)
  161.     {
  162.        return GeneralConstant::$Entity_list_details[array_flip(GeneralConstant::$Entity_list)[$entityName]];
  163.     }
  164.     function getCurrencyListByMarker()
  165.     {
  166.         return BuddybeeConstant::$currency_List_by_marker;
  167.     }
  168.     function strpad($input$padlength$padstring ''$pad_type STR_PAD_LEFT)
  169.     {
  170.         return str_pad($input$padlength$padstring$pad_type);
  171.     }
  172.     function getRandomColor($rmax 200$gmax 200$bmax 200$a 1)
  173.     {
  174.         return '' rand(0$rmax) . ',' rand(0$gmax) . ',' rand(0$bmax);
  175.     }
  176.     public function doSerialize($str)
  177.     {
  178.         $encoders = array(new XmlEncoder(), new JsonEncoder());
  179.         $normalizers = array(new ObjectNormalizer());
  180.         $serializer = new Serializer($normalizers$encoders);
  181.         return $serializer->serialize($str'json');
  182.     }
  183.     public function jsonDecode($str$assoc true$bias JSON_BIGINT_AS_STRING)
  184.     {
  185.         if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  186.             $obj json_decode($str$assoc512JSON_BIGINT_AS_STRING);
  187.         } else {
  188.             $max_int_length strlen((string)PHP_INT_MAX) - 1;
  189.             $json_without_bigints preg_replace('/:\s*(-?\d{' $max_int_length ',})/'': "$1"'$str);
  190.             $obj json_decode($json_without_bigints$assoc);
  191.         }
  192.         //        return json_decode($str,$assoc,512,$bias);
  193.         if ($obj == null)
  194.             $obj = [];
  195.         return $obj;
  196.     }
  197.     public function getUserRestrictions()
  198.     {
  199.         $session = new Session();
  200.         return Users::getUserApplicationAccessSettings($this->em$session->get(UserConstants::USER_ID))['options'];
  201.     }
  202.     public function getGlobalEncryptedDocInfo($entityName='',$docId=0,$appId='_auto_')
  203.     {
  204.         $session = new Session();
  205.         $golbalId='';
  206.         $companyHash='';
  207.         if($appId=='_auto_')
  208.             $appId$session->get(UserConstants::USER_APP_ID);
  209.        $companyHereCompany::getCurrentCompanyInfo($this->em,$appId);
  210.        $entityIdentifier=0;
  211.        $entityList=GeneralConstant::$Entity_list;
  212.        if($entityName!='')
  213.            $entityIdentifier=array_flip(GeneralConstant::$Entity_list)[$entityName];
  214.        if(isset($companyHere['id']))
  215.        {
  216.            $golbalId'D'.str_pad($appId50STR_PAD_LEFT).str_pad($entityIdentifier20STR_PAD_LEFT).str_pad($docId80STR_PAD_LEFT);
  217.            $companyHash=$companyHere['companyHash'];
  218.        }
  219.         return array(
  220.             'id'=>$golbalId,
  221.             'companyHash'=>$companyHash,
  222.         );
  223.     }
  224.     public function getCurrencyList()
  225.     {
  226.         $session = new Session();
  227.         return Inventory::CurrencyList($this->em);
  228.     }
  229. public function getDocumentDataDetailsForView($documentDataId,$columnsEnabled=[],$viewType='view')
  230.     {
  231.         $session = new Session();
  232.         return SalesOrderM::GetDocumentDataDetailsForView($this->em,$documentDataId,$columnsEnabled,$viewType);
  233.     }
  234.     public function getDocumentDataDetails($documentDataId,$skipRowData=0)
  235.     {
  236.         $session = new Session();
  237.         return SalesOrderM::GetDocumentDataDetails($this->em,$documentDataId,$skipRowData);
  238.     }
  239.     public function getCountries()
  240.     {
  241.         return Company::getCountryList($this->em);
  242.     }
  243.     public function getCountriesBuddyBee($type ""$returnType '')
  244.     {
  245.         if ($type == '_ALL_')
  246.             return Company::getCountryList($this->em_goc'_BUDDYBEE_ALL_'$returnType);
  247.         else if ($type == '_HAS_CONSULTANT_')
  248.             return Company::getCountryList($this->em_goc'_HAS_CONSULTANT_'$returnType);
  249.         else
  250.             return Company::getCountryList($this->em_goc'_BUDDYBEE_'$returnType);
  251. //        return BuddybeeConstant::$buddybee_country_List;
  252.     }
  253.     public function getLanguagesBuddyBee($type ""$returnType '')
  254.     {
  255.         if ($type == '_ALL_')
  256.             return Company::getLanguageList($this->em_goc'_BUDDYBEE_ALL_'$returnType);
  257.         else
  258.             return Company::getLanguageList($this->em_goc'_BUDDYBEE_'$returnType);
  259. //        return BuddybeeConstant::$buddybee_country_List;
  260.     }
  261.     public function getBranchList($types ''$companyId = [])
  262.     {
  263.         if ($types == ''$types = [];
  264.         return Client::BranchList($this->em$companyId$types);
  265.     }
  266.     public function getRegionList($types '')
  267.     {
  268.         if ($types == ''$types = [];
  269.         $session = new Session();
  270.         return Client::RegionList($this->em$session->get(UserConstants::USER_COMPANY_ID));
  271.     }
  272.     public function getGeographicalRegionList($types '')
  273.     {
  274.         if ($types == ''$types = [];
  275.         $session = new Session();
  276.         return Client::GeographicalRegionList($this->em$session->get(UserConstants::USER_COMPANY_ID));
  277.     }
  278.     public function getClientList($types '')
  279.     {
  280.         if ($types == ''$types = [];
  281.         $session = new Session();
  282.         return Client::GetExistingClientList($this->em$session->get(UserConstants::USER_COMPANY_ID));
  283.     }
  284.     public function getClientTypeList($types '')
  285.     {
  286.         if ($types == ''$types = [];
  287.         $session = new Session();
  288.         return Client::ClientTypeList($this->em$session->get(UserConstants::USER_COMPANY_ID));
  289.     }
  290.     public function getSalesPersonList($types '')
  291.     {
  292.         if ($types == ''$types = [];
  293.         $session = new Session();
  294.         return Client::SalesPersonList($this->em$session->get(UserConstants::USER_COMPANY_ID));
  295.     }
  296.     public function getColors()
  297.     {
  298.         return Inventory::GetColorList($this->em);
  299.     }
  300.     public function getCommentsForDocument($entity$entityId$appId$isEntityComment 0$conversationHash '')
  301.     {
  302.         if ($isEntityComment == 1)
  303.         {
  304.             if ($conversationHash == '')
  305.                 $conversationHash 'D' . (str_pad($appId5'0'STR_PAD_LEFT)) . (str_pad($entity2'0'STR_PAD_LEFT)) . (str_pad($entityId8'0'STR_PAD_LEFT));
  306.             return array(
  307.                 'commentList' => Comment::getCommentsByConversationHash($this->em_goc$conversationHash$isEntityComment),
  308.                 'hash' => $conversationHash
  309.             );
  310.         }
  311.         else {
  312.             if ($conversationHash == '')
  313.                 $conversationHash 'D' . (str_pad($appId5'0'STR_PAD_LEFT)) . (str_pad($entity2'0'STR_PAD_LEFT)) . (str_pad($entityId8'0'STR_PAD_LEFT));
  314.             return array(
  315.                 'commentList' => Comment::getCommentsByConversationHash($this->em$conversationHash$isEntityComment),
  316.                 'hash' => $conversationHash
  317.             );
  318.         }
  319.     }
  320.     public function getCountriesIndexed()
  321.     {
  322.         return Company::getCountryListIndexed($this->em);
  323.     }
  324.     public function getProductDataFromFDM($FDM)
  325.     {
  326.         $ret_data = array(
  327.             'igId' => 0,
  328.             'categoryId' => 0,
  329.             'subCategoryId' => 0,
  330.             'brandId' => 0,
  331.             'productId' => 0,
  332.             'FDM_MODIFIED' => $FDM
  333.         );
  334.         $session = new Session();
  335.         return Inventory::GetProductDataFromFdm($this->em$FDM$session->get(UserConstants::USER_COMPANY_ID));
  336. //        $FDM_ARRAY = explode('_', $FDM);
  337. //
  338. //        $ret_data['igId'] = isset($FDM_ARRAY[0]) ? (1 * $FDM_ARRAY[0]) : 0;
  339. //        $ret_data['categoryId'] = isset($FDM_ARRAY[1]) ? (1 * $FDM_ARRAY[1]) : 0;
  340. //        $ret_data['subCategoryId'] = isset($FDM_ARRAY[2]) ? (1 * $FDM_ARRAY[2]) : 0;
  341. //        $ret_data['brandId'] = isset($FDM_ARRAY[3]) ? (1 * $FDM_ARRAY[3]) : 0;
  342. //        $ret_data['productId'] = isset($FDM_ARRAY[4]) ? (1 * $FDM_ARRAY[4]) : 0;
  343. //
  344. //
  345. //
  346. //
  347. //        return $ret_data;
  348.     }
  349.     public function callMethod($object$method)
  350.     {
  351.         return call_user_func([$object$method]);
  352.     }
  353.     public function getPositions($department_id)
  354.     {
  355.         return Position::getPositionByDepartment($this->em$department_id);
  356.     }
  357.     public function getSegregationSettings()
  358.     {
  359.         return HumanResource::getSegregationSettings($this->em);
  360.     }
  361.     public function getLeaveSettings()
  362.     {
  363.         return HumanResource::getLeaveSettings($this->em);
  364.     }
  365.     public function getUsers($company_id '')
  366.     {
  367.         return Users::getUserListById($this->em);
  368.     }
  369.     public function getExpSubTypes($company_id '')
  370.     {
  371.         return GeneralConstant::$expenseSubTypes;
  372.     }
  373.     public function PendingDocList()
  374.     {
  375.         $session = new Session();
  376.         //        return $session;
  377.         return System::getPendingApprovalListByUserLoginId($this->em$session->get(UserConstants::USER_LOGIN_ID));
  378.     }
  379.     public function getDepartments($company_id '')
  380.     {
  381.         return Department::getDepartmentList($this->em);
  382.     }
  383.     public function getCompanies()
  384.     {
  385.         return Company::getCompanyList($this->em);
  386.     }
  387.     public function getUserCompany()
  388.     {
  389.         $session = new Session();
  390.         //        return $session;
  391.         return Company::getCompanyData($this->em$session->get(UserConstants::USER_COMPANY_ID1));
  392.         //        return $session->get(UserConstants::USER_COMPANY_ID);
  393.     }
  394.     public function getSupplierDataForSupplierLogin($supplierId 0)
  395.     {
  396.         $session = new Session();
  397.         if ($supplierId == 0)
  398.             $supplierId $session->get('supplierId');
  399.         //        return $session;
  400.         return Supplier::GetSupplierForSupplierLogin($this->em$supplierId);
  401.         //        return Company::getCompanyData($this->em, $session->get(UserConstants::USER_COMPANY_ID, 1));
  402.         //        return $session->get(UserConstants::USER_COMPANY_ID);
  403.     }
  404.     public function getClientDataForClientLogin()
  405.     {
  406.         $session = new Session();
  407.         $clientId $session->get('clientId');
  408.         //        return $session;
  409.         return Client::GetClientForClientLogin($this->em$clientId);
  410.         //        return Company::getCompanyData($this->em, $session->get(UserConstants::USER_COMPANY_ID, 1));
  411.         //        return $session->get(UserConstants::USER_COMPANY_ID);
  412.     }
  413.     public function getMonthlySummary()
  414.     {
  415.         $session = new Session();
  416.         return Company::getMonthlyDataForDashboard($this->em$session->get(UserConstants::USER_COMPANY_ID1));
  417.         //        return $session;
  418.         //        $list_data=
  419.         //        return $session->get(UserConstants::USER_COMPANY_ID);
  420.     }
  421.     public function getRecentSales()
  422.     {
  423.         $session = new Session();
  424.         //        return $session;
  425.         return SalesOrderM::RecentSalesList($this->em$session->get(UserConstants::USER_COMPANY_ID), 5true);
  426.         //        return $session->get(UserConstants::USER_COMPANY_ID);
  427.     }
  428.     public function getSoCountAndMore($limit 5)
  429.     {
  430.         $session = new Session();
  431.         //        return $session;
  432.         return SalesOrderM::getSoCountAndMore($this->em$session->get(UserConstants::USER_COMPANY_ID), $limittrue);
  433.         //        return $session->get(UserConstants::USER_COMPANY_ID);
  434.     }
  435.     public function getRecentPurchase()
  436.     {
  437.         $session = new Session();
  438.         //        return $session;
  439.         return Purchase::RecentPurchaseList($this->em$session->get(UserConstants::USER_COMPANY_ID), 5true);
  440.         //        return $session->get(UserConstants::USER_COMPANY_ID);
  441.     }
  442.     public function getPositionModuleTree($PositionID)
  443.     {
  444.         $list "<ul>";
  445.         $Position $this->em->getRepository('ApplicationBundle:SysDepartmentPosition')->findOneBy(array(
  446.             'status' => GeneralConstant::ACTIVE,
  447.             'positionId' => $PositionID
  448.         ));
  449.         if ($Position) {
  450.             $PositionModules $this->em->getRepository('ApplicationBundle:SysDeptPositionDefaultModule')->findOneBy(array(
  451.                 'status' => GeneralConstant::ACTIVE,
  452.                 'positionId' => $Position->getPositionId()
  453.             ));
  454.             $Modules json_decode($PositionModules->getModuleIds(), true);
  455.             foreach ($Modules as &$ModuleID) {
  456.                 $ModuleInfo Module::getModuleName($this->em$ModuleID);
  457.                 $name $ModuleInfo['name'];
  458.                 self::SeekingLevel($this->em$ModuleInfo['parent_id'], $name);
  459.                 $list .= "<li>" $name "</li>";
  460.             }
  461.         }
  462.         $list .= "</ul>";
  463.         return $list;
  464.     }
  465.     public function getSystemNotice()
  466.     {
  467.         $session = new Session();
  468.         if($session->get('userType')!=8)
  469.             $notice $this->em->getRepository('ApplicationBundle:SystemNotice')->findOneBy(array(
  470.                 'enabled' => GeneralConstant::ACTIVE,
  471.                 'showAsNotification' => GeneralConstant::ACTIVE,
  472.                 //            'CompanyId'=>$session->get(UserConstants::USER_COMPANY_ID),
  473.                 //            'appId'=>$session->get(UserConstants::USER_COMPANY_ID),
  474.             ));
  475.         else
  476.             $notice=null;
  477.         $systemMessage = array();
  478.         if ($notice) {
  479.             $systemMessage[] = array(
  480.                 'title' => $notice->getTitle(),
  481.                 'desc' => $notice->getDesc(),
  482.                 'countDownEnds' => $notice->getCountDownEnds(),
  483.             );
  484.         }
  485.         return $systemMessage;
  486.     }
  487.     private function SeekingLevel($em$module_id, &$name)
  488.     {
  489.         $ModuleInfo Module::getModuleName($em$module_id);
  490.         if (!empty($ModuleInfo)) {
  491.             $name .= " < " $ModuleInfo['name'];
  492.             if ($ModuleInfo['level'] > 0) {
  493.                 self::SeekingLevel($em$ModuleInfo['parent_id'], $name);
  494.             }
  495.         }
  496.         return $name;
  497.     }
  498.     /**
  499.      * This function list all the allowed route for current logged user. I have used this function on left_menu.html.twig.
  500.      *
  501.      * @return string
  502.      */
  503.     public function showNecessaryMenu()
  504.     {
  505.         $session = new Session();
  506.         $list json_decode($session->get(UserConstants::USER_ROUTE_LIST), true);
  507.         //        $list="";
  508.         $r "";
  509.         if ($list) {
  510.             foreach ($list as &$listContent) {
  511.                 $r .= ", .accessible-menu ." $listContent;
  512.             }
  513.         }
  514.         return $r;
  515.     }
  516.     public function strToHex($str)
  517.     {
  518.         return System::strtohex($str);
  519. //        $s = '';
  520. //        foreach (str_split($x) as $c) $s .= sprintf("%02X", ord($c));
  521. //        return ($s);
  522.     }
  523.     public function toHex($number)
  524.     {
  525.         return dechex($number);
  526. //        return $number;
  527. //        $s = '';
  528. //        foreach (str_split($x) as $c) $s .= sprintf("%02X", ord($c));
  529. //        return ($s);
  530.     }
  531.     public function showNecessaryCreateBtn()
  532.     {
  533.         $session = new Session();
  534.         $list json_decode($session->get(UserConstants::USER_ROUTE_LIST), true);
  535.         //        $list="";
  536.         $r "";
  537.         if ($list) {
  538.             foreach ($list as &$listContent) {
  539.                 $r .= ", .btn." $listContent;
  540.             }
  541.         }
  542.         return $r;
  543.     }
  544.     public function showMenuIfAdmin()
  545.     {
  546.         $session = new Session();
  547.         $list Company::getCompanyRouteList($this->em$session->get(UserConstants::USER_COMPANY_ID));
  548.         //        $list=json_decode($session->get(UserConstants::USER_ROUTE_LIST), true);
  549.         //        $list="";
  550.         $r "";
  551.         if ($list) {
  552.             foreach ($list as &$listContent) {
  553.                 $r .= ", .accessible-menu ." $listContent;
  554.             }
  555.         }
  556.         return $r;
  557.     }
  558.     public function showNecessaryMenuGeneral()
  559.     {
  560.         $session = new Session();
  561.         $list json_decode($session->get(UserConstants::USER_ROUTE_LIST), true);
  562.         $r "";
  563.         if ($list) {
  564.             foreach ($list as &$listContent) {
  565.                 $r .= ", ." $listContent;
  566.             }
  567.         }
  568.         return $r;
  569.     }
  570.     public function todoSummaryList($assigned_to$types = [])
  571.     {
  572.         $todoList = array();
  573.         $ToDos $this->em->getRepository('ApplicationBundle:Ticket')->findBy(
  574.             array(
  575.                 'status' => TaskConstant::ACTIVE,
  576.                 'type' => $types,
  577.                 'assignedToUserId' => intval($assigned_to)
  578.             )
  579.         );
  580.         if (count($ToDos) > 0) {
  581.             foreach ($ToDos as &$ToDo) {
  582.                 $todoList[] = array(
  583.                     'id' => $ToDo->getId(),
  584.                     'title' => $ToDo->getTitle(),
  585.                     'type' => $ToDo->getType(),
  586.                     'urgency' => $ToDo->getUrgency()
  587.                 );
  588.             }
  589.         }
  590.         return $todoList;
  591.     }
  592.     public function inArray($key$array)
  593.     {
  594.         if($array==null)
  595.             $array=[];
  596.         return in_array($key$array);
  597.     }
  598.     public function encryptMe($str)
  599.     {
  600.         $session = new Session();
  601.         $allSessionsArray $session->all();
  602.         /*return Crypto::Encrypt($str, $allSessionsArray[ACLConstants::SESSION_SALT]);*/
  603.         return $this->encryptDecrypt->encrypt($str$allSessionsArray[GeneralConstant::SESSION_SALT]);
  604.     }
  605.     public function decryptMe($str)
  606.     {
  607.         $session = new Session();
  608.         $allSessionsArray $session->all();
  609.         /*return Crypto::Decrypt($str, $allSessionsArray[ACLConstants::SESSION_SALT]);*/
  610.         return $this->encryptDecrypt->decrypt($str$allSessionsArray[GeneralConstant::SESSION_SALT]);
  611.     }
  612.     public function getMicroTime($str)
  613.     {
  614.         return floor(microtime(true) * 1000);
  615.     }
  616.     public function getName()
  617.     {
  618.         return 'general_extension';
  619.     }
  620. }