src/ApplicationBundle/Twig/GeneralExtension.php line 27

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