����JFIFXX�����    $.' ",#(7),01444'9=82<.342  2!!22222222222222222222222222222222222222222222222222����"��4�� ���,�PG"Z_�4�˷����kjز�Z�,F+��_z�,�© �����zh6�٨�ic�fu���#ډb���_�N�?��wQ���5-�~�I���8����TK<5o�Iv-�����k�_U_�����~b�M��d����Ӝ�U�Hh��?]��E�w��Q���k�{��_}qFW7HTՑ��Y��F�?_�'ϔ��_�Ջt��=||I ��6�έ"�����D���/[�k�9���Y�8ds|\���Ҿp6�Ҵ���]��.����6�z<�v��@]�i%��$j��~�g��J>��no����pM[me�i$[����s�o�ᘨ�˸ nɜG-�ĨU�ycP�3.DB�li�;��hj���x7Z^�N�h������N3u{�:j�x�힞��#M&��jL P@_���� P��&��o8������9�����@Sz6�t7#O�ߋ �s}Yf�T���lmr����Z)'N��k�۞p����w\�Tȯ?�8`�O��i{wﭹW�[�r�� ��Q4F�׊���3m&L�=��h3����z~��#�\�l :�F,j@�� ʱ�wQT����8�"kJO���6�֚l����}���R�>ډK���]��y����&����p�}b��;N�1�m�r$�|��7�>e�@B�TM*-iH��g�D�)� E�m�|�ؘbҗ�a��Ҿ����t4���o���G��*oCN�rP���Q��@z,|?W[0�����:�n,jWiE��W��$~/�hp\��?��{(�0���+�Y8rΟ�+����>S-S����VN;�}�s?.����� w�9��˟<���Mq4�Wv'��{)0�1mB��V����W[�����8�/<� �%���wT^�5���b��)iM� pg�N�&ݝ��VO~�q���u���9� ����!��J27����$O-���! �:�%H��� ـ����y�ΠM=t{!S�� oK8������t<����è:a������[�����ա�H���~��w��Qz`�po�^ ����Q��n� �,uu�C�$ ^���,������8�#��:�6��e�|~���!�3�3.�\0��q��o�4`.|� ����y�Q�`~;�d�ׯ,��O�Zw�������`73�v�܋�<���Ȏ�� ـ4k��5�K�a�u�=9Yd��$>x�A�&�� j0� ���vF��� Y�|�y��� ~�6�@c��1vOp�Ig����4��l�OD���L����� R���c���j�_�uX6��3?nk��Wy�f;^*B� ��@�~a�`��Eu������+���6�L��.ü>��}y���}_�O�6�͐�:�YrG�X��kG�����l^w���~㒶sy��Iu�!� W ��X��N�7BV��O��!X�2����wvG�R�f�T#�����t�/?���%8�^�W�aT��G�cL�M���I��(J����1~�8�?aT ���]����AS�E��(��*E}� 2��#I/�׍qz��^t�̔���b�Yz4x���t�){ OH��+(E��A&�N�������XT��o��"�XC��'���)}�J�z�p� ��~5�}�^����+�6����w��c��Q�|Lp�d�H��}�(�.|����k��c4^�"�����Z?ȕ ��a<�L�!039C� �Eu�C�F�Ew�ç ;�n?�*o���B�8�bʝ���'#Rqf���M}7����]����s2tcS{�\icTx;�\��7K���P���ʇ Z O-��~��c>"��?�������P��E��O�8��@�8��G��Q�g�a�Վ���󁶠�䧘��_%#r�>�1�z�a��eb��qcPѵ��n���#L��� =��׀t� L�7�`��V���A{�C:�g���e@�w1 Xp3�c3�ġ����p��M"'-�@n4���fG��B3�DJ�8[Jo�ߐ���gK)ƛ��$���� ���8�3�����+���� �����6�ʻ���� ���S�kI�*KZlT _`���?��K����QK�d����B`�s}�>���`��*�>��,*@J�d�oF*����弝��O}�k��s��]��y�ߘ��c1G�V���<=�7��7����6�q�PT��tXԀ�!9*4�4Tހ3XΛex�46���Y��D ����� �BdemDa����\�_l,��G�/���֌7���Y�](�xTt^%�GE�����4�}bT���ڹ�����;Y)���B�Q��u��>J/J �⮶.�XԄ��j�ݳ�+E��d ��r�5�_D�1 ��o�� �B�x�΢�#���<��W�����8���R6�@g�M�.��� dr�D��>(otU��@x=��~v���2� ӣ�d�oBd��3�eO�6�㣷�����ݜ6��6Y��Qz`��S��{���\P�~z m5{J/L��1������<�e�ͅPu�b�]�ϔ���'������f�b� Zpw��c`"��i���BD@:)ִ�:�]��hv�E�w���T�l��P���"Ju�}��وV J��G6��. J/�Qgl߭�e�����@�z�Zev2u�)]կ�����7x���s�M�-<ɯ�c��r�v�����@��$�ޮ}lk���a���'����>x��O\�ZFu>�����ck#��&:��`�$�ai�>2Δ����l���oF[h��lE�ܺ�Πk:)���`�� $[6�����9�����kOw�\|���8}������ބ:��񶐕��I�A1/�=�2[�,�!��.}gN#�u����b��� ~��݊��}34q����d�E��Lc��$��"�[q�U�硬g^��%B �z���r�pJ�ru%v\h1Y�ne`ǥ:g���pQM~�^�Xi� ��`S�:V29.�P���V�?B�k�� AEvw%�_�9C�Q����wKekPؠ�\�;Io d�{ ߞo�c1eP����\� `����E=���@K<�Y���eڼ�J���w����{av�F�'�M�@/J��+9p���|]�����Iw &`��8���&M�hg��[�{��Xj��%��Ӓ�$��(����ʹN���<>�I���RY���K2�NPlL�ɀ)��&e����B+ь����( � �JTx���_?EZ� }@ 6�U���뙢ط�z��dWI�n` D����噥�[��uV��"�G&Ú����2g�}&m��?ċ�"����Om#��������� ��{�ON��"S�X��Ne��ysQ���@Fn��Vg���dX�~nj�]J�<�K]:��FW��b�������62�=��5f����JKw��bf�X�55��~J �%^����:�-�QIE��P��v�nZum� z � ~ə ���� ���ة����;�f��\v���g�8�1��f24;�V���ǔ�)����9���1\��c��v�/'Ƞ�w�������$�4�R-��t���� e�6�/�ġ �̕Ecy�J���u�B���<�W�ַ~�w[B1L۲�-JS΂�{���΃������A��20�c#��@ 0!1@AP"#2Q`$3V�%45a6�FRUq��� ����^7ׅ,$n�������+��F�`��2X'��0vM��p�L=������5��8������u�p~���.�`r�����\���O��,ư�0oS ��_�M�����l���4�kv\JSd���x���SW�<��Ae�IX����������$I���w�:S���y���›R��9�Q[���,�5�;�@]�%���u�@ *ro�lbI �� ��+���%m:�͇ZV�����u�̉����θau<�fc�.����{�4Ա� �Q����*�Sm��8\ujqs]{kN���)qO�y�_*dJ�b�7���yQqI&9�ԌK!�M}�R�;������S�T���1���i[U�ɵz�]��U)V�S6���3$K{�ߊ<�(� E]Զ[ǼENg�����'�\?#)Dkf��J���o��v���'�%ƞ�&K�u�!��b�35LX�Ϸ��63$K�a�;�9>,R��W��3�3� d�JeTYE.Mϧ��-�o�j3+y��y^�c�������VO�9NV\nd�1 ��!͕_)a�v;����թ�M�lWR1��)El��P;��yوÏ�u 3�k�5Pr6<�⒲l�!˞*��u־�n�!�l:����UNW ��%��Chx8vL'��X�@��*��)���̮��ˍ��� ���D-M�+J�U�kvK����+�x8��cY������?�Ԡ��~3mo��|�u@[XeY�C�\Kp�x8�oC�C�&����N�~3-H���� ��MX�s�u<`���~"WL��$8ξ��3���a�)|:@�m�\���^�`�@ҷ)�5p+��6���p�%i)P M���ngc�����#0Aruz���RL+xSS?���ʮ}()#�t��mˇ!��0}}y����<�e� �-ή�Ԩ��X������ MF���ԙ~l L.3���}�V뽺�v�����멬��Nl�)�2����^�Iq��a��M��qG��T�����c3#������3U�Ǎ���}��לS�|qa��ڃ�+���-��2�f����/��bz��ڐ�� �ݼ[2�ç����k�X�2�* �Z�d���J�G����M*9W���s{��w���T��x��y,�in�O�v��]���n����P�$�JB@=4�OTI�n��e�22a\����q�d���%�$��(���:���: /*�K[PR�fr\nڙdN���F�n�$�4�[�� U�zƶ����� �mʋ���,�ao�u 3�z� �x��Kn����\[��VFmbE;�_U��&V�Gg�]L�۪&#n%�$ɯ�dG���D�TI=�%+AB�Ru#��b4�1�»x�cs�YzڙJG��f��Il��d�eF'T� iA��T���uC�$����Y��H?����[!G`}���ͪ� �纤Hv\������j�Ex�K���!���OiƸ�Yj�+u-<���'q����uN�*�r\��+�]���<�wOZ.fp�ێ��,-*)V?j-kÊ#�`�r��dV����(�ݽBk�����G�ƛk�QmUڗe��Z���f}|����8�8��a���i��3'J�����~G_�^���d�8w������ R�`(�~�.��u���l�s+g�bv���W���lGc}��u���afE~1�Ue������Z�0�8�=e�� f@/�jqEKQQ�J��oN��J���W5~M>$6�Lt�;$ʳ{���^��6�{����v6���ķܰg�V�cnn �~z�x�«�,2�u�?cE+Ș�H؎�%�Za�)���X>uW�Tz�Nyo����s���FQƤ��$��*�&�LLXL)�1�" L��eO��ɟ�9=���:t��Z���c��Ž���Y?�ӭV�wv�~,Y��r�ۗ�|�y��GaF�����C�����.�+� ���v1���fήJ�����]�S��T��B��n5sW}y�$��~z�'�c ��8 ��� ,! �p��VN�S��N�N�q��y8z˱�A��4��*��'������2n<�s���^ǧ˭P�Jޮɏ�U�G�L�J�*#��<�V��t7�8����TĜ>��i}K%,���)[��z�21z ?�N�i�n1?T�I�R#��m-�����������������1����lA�`��fT5+��ܐ�c�q՝��ʐ��,���3�f2U�եmab��#ŠdQ�y>\��)�SLY����w#��.���ʑ�f��� ,"+�w�~�N�'�c�O�3F�������N<���)j��&��,-� �љ���֊�_�zS���TǦ����w�>��?�������n��U仆�V���e�����0���$�C�d���rP �m�׈e�Xm�Vu� �L��.�bֹ��� �[Դaզ���*��\y�8�Է:�Ez\�0�Kq�C b��̘��cө���Q��=0Y��s�N��S.���3.���O�o:���#���v7�[#߫ ��5�܎�L���Er4���9n��COWlG�^��0k�%<���ZB���aB_���������'=��{i�v�l�$�uC���mƎҝ{�c㱼�y]���W�i ��ߧc��m�H� m�"�"�����;Y�ߝ�Z�Ǔ�����:S#��|}�y�,/k�Ld� TA�(�AI$+I3��;Y*���Z��}|��ӧO��d�v��..#:n��f>�>���ȶI�TX��� 8��y����"d�R�|�)0���=���n4��6ⲑ�+��r<�O�܂~zh�z����7ܓ�HH�Ga롏���nCo�>������a ���~]���R���̲c?�6(�q�;5%� |�uj�~z8R=X��I�V=�|{v�Gj\gc��q����z�؋%M�ߍ����1y��#��@f^���^�>N�����#x#۹��6�Y~�?�dfPO��{��P�4��V��u1E1J �*|���%���JN��`eWu�zk M6���q t[�� ��g�G���v��WIG��u_ft����5�j�"�Y�:T��ɐ���*�;� e5���4����q$C��2d�}���� _S�L#m�Yp��O�.�C�;��c����Hi#֩%+) �Ӎ��ƲV���SYź��g |���tj��3�8���r|���V��1#;.SQ�A[���S������#���`n�+���$��$I �P\[�@�s��(�ED�z���P��])8�G#��0B��[ى��X�II�q<��9�~[Z멜�Z�⊔IWU&A>�P~�#��dp<�?����7���c��'~���5 ��+$���lx@�M�dm��n<=e�dyX��?{�|Aef ,|n3�<~z�ƃ�uۧ�����P��Y,�ӥQ�*g�#먙R�\���;T��i,��[9Qi歉����c>]9�� ��"�c��P�� �Md?٥��If�ت�u��k��/����F��9�c*9��Ǎ:�ØF���z�n*�@|I�ށ9����N3{'��[�'ͬ�Ҳ4��#}��!�V� Fu��,�,mTIk���v C�7v���B�6k�T9��1�*l� '~��ƞF��lU��'�M ����][ΩũJ_�{�i�I�n��$���L�� j��O�dx�����kza۪��#�E��Cl����x˘�o�����V���ɞ�ljr��)�/,�߬h�L��#��^��L�ф�,íMƁe�̩�NB�L�����iL����q�}��(��q��6IçJ$�W�E$��:������=#����(�K�B����zђ <��K(�N�۫K�w��^O{!����)�H���>x�������lx�?>Պ�+�>�W���,Ly!_�D���Ō�l���Q�!�[ �S����J��1��Ɛ�Y}��b,+�Lo�x�ɓ)����=�y�oh�@�꥟/��I��ѭ=��P�y9��� �ۍYӘ�e+�p�Jnϱ?V\SO%�(�t� ���=?MR�[Ș�����d�/ ��n�l��B�7j� ��!�;ӥ�/�[-���A�>�dN�sLj ��,ɪv��=1c�.SQ�O3�U���ƀ�ܽ�E����������̻��9G�ϷD�7(�}��Ävӌ\�y�_0[w ���<΍>����a_��[0+�L��F.�޺��f�>oN�T����q;���y\��bՃ��y�jH�<|q-eɏ�_?_9+P���Hp$�����[ux�K w�Mw��N�ی'$Y2�=��q���KB��P��~������Yul:�[<����F1�2�O���5=d����]Y�sw:���Ϯ���E��j,_Q��X��z`H1,#II ��d�wr��P˂@�ZJV����y$�\y�{}��^~���[:N����ߌ�U�������O��d�����ؾe��${p>G��3c���Ė�lʌ�� ת��[��`ϱ�-W����dg�I��ig2��� ��}s ��ؤ(%#sS@���~���3�X�nRG�~\jc3�v��ӍL��M[JB�T��s3}��j�Nʖ��W����;7��ç?=X�F=-�=����q�ߚ���#���='�c��7���ڑW�I(O+=:uxq�������������e2�zi+�kuG�R��������0�&e�n���iT^J����~\jy���p'dtG��s����O��3����9* �b#Ɋ�� p������[Bws�T�>d4�ۧs���nv�n���U���_�~,�v����ƜJ1��s�� �QIz��)�(lv8M���U=�;����56��G���s#�K���MP�=��LvyGd��}�VwWBF�'�à �?MH�U�g2�� ����!�p�7Q��j��ڴ����=��j�u��� Jn�A s���uM������e��Ɔ�Ҕ�!)'��8Ϣ�ٔ��ޝ(��Vp���צ֖d=�IC�J�Ǡ{q������kԭ�߸���i��@K����u�|�p=..�*+����x�����z[Aqġ#s2a�Ɗ���RR�)*HRsi�~�a &f��M��P����-K�L@��Z��Xy�'x�{}��Zm+���:�)�) IJ�-i�u���� ���ܒH��'�L(7�y�GӜq���� j��� 6ߌg1�g�o���,kر���tY�?W,���p���e���f�OQS��!K�۟cҒA�|ս�j�>��=⬒��˧L[�� �߿2JaB~R��u�:��Q�] �0H~���]�7��Ƽ�I���(}��cq '�ήET���q�?f�ab���ӥvr� �)o��-Q��_'����ᴎo��K������;��V���o��%���~OK ����*��b�f:���-ťIR��`B�5!RB@���ï�� �u �̯e\�_U�_������� g�ES��3�������QT��a����x����U<~�c?�*�#]�MW,[8O�a�x��]�1bC|踤�P��lw5V%�)�{t�<��d��5���0i�XSU��m:��Z�┵�i�"��1�^B�-��P�hJ��&)O��*�D��c�W��vM��)����}���P��ܗ-q����\mmζZ-l@�}��a��E�6��F�@��&Sg@���ݚ�M����� ȹ 4����#p�\H����dYDo�H���"��\��..R�B�H�z_�/5˘����6��KhJR��P�mƶi�m���3�,#c�co��q�a)*Pt����R�m�k�7x�D�E�\Y�閣_X�<���~�)���c[[�BP����6�Yq���S��0����%_����;��Àv�~�| VS؇ ��'O0��F0��\���U�-�d@�����7�SJ*z��3n��y��P����O���������m�~�P�3|Y��ʉr#�C�<�G~�.,! ���bqx���h~0=��!ǫ�jy����l�O,�[B��~��|9��ٱ����Xly�#�i�B��g%�S��������tˋ���e���ې��\[d�t)��.+u�|1 ������#�~Oj����hS�%��i.�~X���I�H�m��0n���c�1uE�q��cF�RF�o���7� �O�ꮧ� ���ۛ{��ʛi5�rw?׌#Qn�TW��~?y$��m\�\o����%W� ?=>S�N@�� �Ʈ���R����N�)�r"C�:��:����� �����#��qb��Y�. �6[��2K����2u�Ǧ�HYR��Q�MV��� �G�$��Q+.>�����nNH��q�^��� ����q��mM��V��D�+�-�#*�U�̒ ���p욳��u:�������IB���m���PV@O���r[b= �� ��1U�E��_Nm�yKbN�O���U�}�the�`�|6֮P>�\2�P�V���I�D�i�P�O;�9�r�mAHG�W�S]��J*�_�G��+kP�2����Ka�Z���H�'K�x�W�MZ%�O�YD�Rc+o��?�q��Ghm��d�S�oh�\�D�|:W������UA�Qc yT�q������~^�H��/��#p�CZ���T�I�1�ӏT����4��"�ČZ�����}��`w�#�*,ʹ�� ��0�i��課�Om�*�da��^gJ݅{���l�e9uF#T�ֲ��̲�ٞC"�q���ߍ ոޑ�o#�XZTp����@ o�8��(jd��xw�]�,f���`~�|,s��^����f�1���t��|��m�򸄭/ctr��5s��7�9Q�4�H1꠲BB@l9@���C�����+�wp�xu�£Yc�9��?`@#�o�mH�s2��)�=��2�.�l����jg�9$�Y�S�%*L������R�Y������7Z���,*=�䷘$�������arm�o�ϰ���UW.|�r�uf����IGw�t����Zwo��~5 ��YյhO+=8fF�)�W�7�L9lM�̘·Y���֘YLf�큹�pRF���99.A �"wz��=E\Z���'a� 2��Ǚ�#;�'}�G���*��l��^"q��+2FQ� hj��kŦ��${���ޮ-�T�٭cf�|�3#~�RJ����t��$b�(R��(����r���dx� >U b�&9,>���%E\� Ά�e�$��'�q't��*�א���ެ�b��-|d���SB�O�O��$�R+�H�)�܎�K��1m`;�J�2�Y~9��O�g8=vqD`K[�F)k�[���1m޼c��n���]s�k�z$@��)!I �x՝"v��9=�ZA=`Ɠi �:�E��)`7��vI��}d�YI�_ �o�:ob���o ���3Q��&D&�2=�� �Ά��;>�h����y.*ⅥS������Ӭ�+q&����j|UƧ����}���J0��WW< ۋS�)jQR�j���Ư��rN)�Gű�4Ѷ(�S)Ǣ�8��i��W52���No˓� ۍ%�5brOn�L�;�n��\G����=�^U�dI���8$�&���h��'���+�(������cȁ߫k�l��S^���cƗjԌE�ꭔ��gF���Ȓ��@���}O���*;e�v�WV���YJ\�]X'5��ղ�k�F��b 6R�o՜m��i N�i����>J����?��lPm�U��}>_Z&�KK��q�r��I�D�Չ~�q�3fL�:S�e>���E���-G���{L�6p�e,8��������QI��h��a�Xa��U�A'���ʂ���s�+טIjP�-��y�8ۈZ?J$��W�P� ��R�s�]��|�l(�ԓ��sƊi��o(��S0��Y� 8�T97.�����WiL��c�~�dxc�E|�2!�X�K�Ƙਫ਼�$((�6�~|d9u+�qd�^3�89��Y�6L�.I�����?���iI�q���9�)O/뚅����O���X��X�V��ZF[�یgQ�L��K1���RҖr@v�#��X�l��F���Нy�S�8�7�kF!A��sM���^rkp�jP�DyS$N���q��nxҍ!U�f�!eh�i�2�m���`�Y�I�9r�6� �TF���C}/�y�^���Η���5d�'��9A-��J��>{�_l+�`��A���[�'��յ�ϛ#w:݅�%��X�}�&�PSt�Q�"�-��\縵�/����$Ɨh�Xb�*�y��BS����;W�ջ_mc�����vt?2}1�;qS�d�d~u:2k5�2�R�~�z+|HE!)�Ǟl��7`��0�<�,�2*���Hl-��x�^����'_TV�gZA�'j� ^�2Ϊ��N7t�����?w�� �x1��f��Iz�C-Ȗ��K�^q�;���-W�DvT�7��8�Z�������� hK�(P:��Q- �8�n�Z���܃e貾�<�1�YT<�,�����"�6{/ �?�͟��|1�:�#g��W�>$����d��J��d�B��=��jf[��%rE^��il:��B���x���Sּ�1հ��,�=��*�7 fcG��#q� �eh?��2�7�����,�!7x��6�n�LC�4x��},Geǝ�tC.��vS �F�43��zz\��;QYC,6����~;RYS/6���|2���5���v��T��i����������mlv��������&� �nRh^ejR�LG�f���? �ۉҬܦƩ��|��Ȱ����>3����!v��i�ʯ�>�v��オ�X3e���_1z�Kȗ\<������!�8���V��]��?b�k41�Re��T�q��mz��TiOʦ�Z��Xq���L������q"+���2ۨ��8}�&N7XU7Ap�d�X��~�׿��&4e�o�F��� �H����O���č�c�� 懴�6���͉��+)��v;j��ݷ�� �UV�� i��� j���Y9GdÒJ1��詞�����V?h��l����l�cGs�ځ�������y�Ac�����\V3�? �� ܙg�>qH�S,�E�W�[�㺨�uch�⍸�O�}���a��>�q�6�n6����N6�q������N ! 1AQaq�0@����"2BRb�#Pr���3C`��Scst���$4D���%Td�� ?���N����a��3��m���C���w��������xA�m�q�m���m������$����4n淿t'��C"w��zU=D�\R+w�p+Y�T�&�պ@��ƃ��3ޯ?�Aﶂ��aŘ���@-�����Q�=���9D��ռ�ѻ@��M�V��P��܅�G5�f�Y<�u=,EC)�<�Fy'�"�&�չ�X~f��l�KԆV��?�� �W�N����=(� �;���{�r����ٌ�Y���h{�١������jW����P���Tc�����X�K�r��}���w�R��%��?���E��m�� �Y�q|����\lEE4���r���}�lsI�Y������f�$�=�d�yO����p�����yBj8jU�o�/�S��?�U��*������ˍ�0������u�q�m [�?f����a�� )Q�>����6#������� ?����0UQ����,IX���(6ڵ[�DI�MNލ�c&���υ�j\��X�R|,4��� j������T�hA�e��^���d���b<����n�� �즇�=!���3�^�`j�h�ȓr��jẕ�c�,ٞX����-����a�ﶔ���#�$��]w�O��Ӫ�1y%��L�Y<�wg#�ǝ�̗`�x�xa�t�w��»1���o7o5��>�m뭛C���Uƃߜ}�C���y1Xνm�F8�jI���]����H���ۺиE@I�i;r�8ӭ����V�F�Շ| ��&?�3|x�B�MuS�Ge�=Ӕ�#BE5G�����Y!z��_e��q�р/W>|-�Ci߇�t�1ޯќd�R3�u��g�=0 5��[?�#͏��q�cf���H��{ ?u�=?�?ǯ���}Z��z���hmΔ�BFTW�����<�q�(v� ��!��z���iW]*�J�V�z��gX֧A�q�&��/w���u�gYӘa���; �i=����g:��?2�dž6�ى�k�4�>�Pxs����}������G�9��3 ���)gG�R<>r h�$��'nc�h�P��Bj��J�ҧH� -��N1���N��?��~��}-q!=��_2hc�M��l�vY%UE�@|�v����M2�.Y[|y�"Eï��K�ZF,�ɯ?,q�?v�M 80jx�"�;�9vk�����+ ֧�� �ȺU��?�%�vcV��mA�6��Qg^M����A}�3�nl� QRN�l8�kkn�'�����(��M�7m9و�q���%ޟ���*h$Zk"��$�9��: �?U8�Sl��,,|ɒ��xH(ѷ����Gn�/Q�4�P��G�%��Ա8�N��!� �&�7�;���eKM7�4��9R/%����l�c>�x;������>��C�:�����t��h?aKX�bhe�ᜋ^�$�Iհ �hr7%F$�E��Fd���t��5���+�(M6�t����Ü�UU|zW�=a�Ts�Tg������dqP�Q����b'�m���1{|Y����X�N��b �P~��F^F:����k6�"�j!�� �I�r�`��1&�-$�Bevk:y���#yw��I0��x��=D�4��tU���P�ZH��ڠ底taP��6����b>�xa����Q�#� WeF��ŮNj�p�J* mQ�N����*I�-*�ȩ�F�g�3 �5��V�ʊ�ɮ�a��5F���O@{���NX��?����H�]3��1�Ri_u��������ѕ�� ����0��� F��~��:60�p�͈�S��qX#a�5>���`�o&+�<2�D����: �������ڝ�$�nP���*)�N�|y�Ej�F�5ټ�e���ihy�Z �>���k�bH�a�v��h�-#���!�Po=@k̆IEN��@��}Ll?j�O������߭�ʞ���Q|A07x���wt!xf���I2?Z��<ץ�T���cU�j��]��陎Ltl �}5�ϓ��$�,��O�mˊ�;�@O��jE��j(�ا,��LX���LO���Ц�90�O �.����a��nA���7������j4 ��W��_ٓ���zW�jcB������y՗+EM�)d���N�g6�y1_x��p�$Lv:��9�"z��p���ʙ$��^��JԼ*�ϭ����o���=x�Lj�6�J��u82�A�H�3$�ٕ@�=Vv�]�'�qEz�;I˼��)��=��ɯ���x �/�W(V���p�����$ �m�������u�����񶤑Oqˎ�T����r��㠚x�sr�GC��byp�G��1ߠ�w e�8�$⿄����/�M{*}��W�]˷.�CK\�ުx���/$�WPw���r� |i���&�}�{�X� �>��$-��l���?-z���g����lΆ���(F���h�vS*���b���߲ڡn,|)mrH[���a�3�ר�[1��3o_�U�3�TC�$��(�=�)0�kgP���� ��u�^=��4 �WYCҸ:��vQ�ר�X�à��tk�m,�t*��^�,�}D*� �"(�I��9R����>`�`��[~Q]�#af��i6l��8���6�:,s�s�N6�j"�A4���IuQ��6E,�GnH��zS�HO�uk�5$�I�4��ؤ�Q9�@��C����wp�BGv[]�u�Ov���0I4���\��y�����Q�Ѹ��~>Z��8�T��a��q�ޣ;z��a���/��S��I:�ܫ_�|������>=Z����8:�S��U�I�J��"IY���8%b8���H��:�QO�6�;7�I�S��J��ҌAά3��>c���E+&jf$eC+�z�;��V����� �r���ʺ������my�e���aQ�f&��6�ND��.:��NT�vm�<- u���ǝ\MvZY�N�NT��-A�>jr!S��n�O 1�3�Ns�%�3D@���`������ܟ 1�^c<���� �a�ɽ�̲�Xë#�w�|y�cW�=�9I*H8�p�^(4���՗�k��arOcW�tO�\�ƍR��8����'�K���I�Q�����?5�>[�}��yU�ײ -h��=��% q�ThG�2�)���"ו3]�!kB��*p�FDl�A���,�eEi�H�f�Ps�����5�H:�Փ~�H�0Dت�D�I����h�F3�������c��2���E��9�H��5�zԑ�ʚ�i�X�=:m�xg�hd(�v����׊�9iS��O��d@0ڽ���:�p�5�h-��t�&���X�q�ӕ,��ie�|���7A�2���O%P��E��htj��Y1��w�Ѓ!����  ���� ࢽ��My�7�\�a�@�ţ�J �4�Ȼ�F�@o�̒?4�wx��)��]�P��~�����u�����5�����7X ��9��^ܩ�U;Iꭆ 5 �������eK2�7(�{|��Y׎ �V��\"���Z�1� Z�����}��(�Ǝ"�1S���_�vE30>���p;� ΝD��%x�W�?W?v����o�^V�i�d��r[��/&>�~`�9Wh��y�;���R��� ;;ɮT��?����r$�g1�K����A��C��c��K��l:�'��3 c�ﳯ*"t8�~l��)���m��+U,z��`(�>yJ�?����h>��]��v��ЍG*�{`��;y]��I�T� ;c��NU�fo¾h���/$���|NS���1�S�"�H��V���T���4��uhǜ�]�v;���5�͠x��'C\�SBpl���h}�N����� A�Bx���%��ޭ�l��/����T��w�ʽ]D�=����K���ž�r㻠l4�S�O?=�k �M:� ��c�C�a�#ha���)�ѐxc�s���gP�iG��{+���x���Q���I= �� z��ԫ+ �8"�k�ñ�j=|����c ��y��CF��/��*9ж�h{ �?4�o� ��k�m�Q�N�x��;�Y��4膚�a�w?�6�>e]�����Q�r�:����g�,i"�����ԩA�*M�<�G��b�if��l^M��5� �Ҩ�{����6J��ZJ�����P�*�����Y���ݛu�_4�9�I8�7���������,^ToR���m4�H��?�N�S�ѕw��/S��甍�@�9H�S�T��t�ƻ���ʒU��*{Xs�@����f�����֒Li�K{H�w^���������Ϥm�tq���s� ���ք��f:��o~s��g�r��ט� �S�ѱC�e]�x���a��) ���(b-$(�j>�7q�B?ӕ�F��hV25r[7 Y� }L�R��}����*sg+��x�r�2�U=�*'WS��ZDW]�WǞ�<��叓���{�$�9Ou4��y�90-�1�'*D`�c�^o?(�9��u���ݐ��'PI&� f�Jݮ�������:wS����jfP1F:X �H�9dԯ���˝[�_54 �}*;@�ܨ�� ð�yn�T���?�ןd�#���4rG�ͨ��H�1�|-#���Mr�S3��G�3�����)�.᧏3v�z֑��r����$G"�`j �1t��x0<Ɔ�Wh6�y�6��,œ�Ga��gA����y��b��)��h�D��ß�_�m��ü �gG;��e�v��ݝ�nQ� ��C����-�*��o���y�a��M��I�>�<���]obD��"�:���G�A��-\%LT�8���c�)��+y76���o�Q�#*{�(F�⽕�y����=���rW�\p���۩�c���A���^e6��K������ʐ�cVf5$�'->���ՉN"���F�"�UQ@�f��Gb~��#�&�M=��8�ט�JNu9��D��[̤�s�o�~������ G��9T�tW^g5y$b��Y'��س�Ǵ�=��U-2 #�MC�t(�i� �lj�@Q 5�̣i�*�O����s�x�K�f��}\��M{E�V�{�υ��Ƈ�����);�H����I��fe�Lȣr�2��>��W�I�Ȃ6������i��k�� �5�YOxȺ����>��Y�f5'��|��H+��98pj�n�.O�y�������jY��~��i�w'������l�;�s�2��Y��:'lg�ꥴ)o#'Sa�a�K��Z� �m��}�`169�n���"���x��I ��*+� }F<��cГ���F�P�������ֹ*�PqX�x۩��,� ��N�� �4<-����%����:��7����W���u�`����� $�?�I��&����o��o��`v�>��P��"��l���4��5'�Z�gE���8���?��[�X�7(��.Q�-��*���ތL@̲����v��.5���[��=�t\+�CNܛ��,g�SQnH����}*F�G16���&:�t��4ُ"A��̣��$�b �|����#rs��a�����T�� ]�<�j��BS�('$�ɻ� �wP;�/�n��?�ݜ��x�F��yUn�~mL*-�������Xf�wd^�a�}��f�,=t�׵i�.2/wpN�Ep8�OР���•��R�FJ� 55TZ��T �ɭ�<��]��/�0�r�@�f��V��V����Nz�G��^���7hZi����k��3�,kN�e|�vg�1{9]_i��X5y7� 8e]�U����'�-2,���e"����]ot�I��Y_��n�(JҼ��1�O ]bXc���Nu�No��pS���Q_���_�?i�~�x h5d'�(qw52] ��'ޤ�q��o1�R!���`ywy�A4u���h<קy���\[~�4�\ X�Wt/� 6�����n�F�a8��f���z �3$�t(���q��q�x��^�XWeN'p<-v�!�{�(>ӽDP7��ո0�y)�e$ٕv�Ih'Q�EA�m*�H��RI��=:��� ���4牢) �%_iN�ݧ�l]� �Nt���G��H�L��� ɱ�g<���1V�,�J~�ٹ�"K��Q�� 9�HS�9�?@��k����r�;we݁�]I�!{ �@�G�[�"��`���J:�n]�{�cA�E����V��ʆ���#��U9�6����j�#Y�m\��q�e4h�B�7��C�������d<�?J����1g:ٳ���=Y���D�p�ц� ׈ǔ��1�]26؜oS�'��9�V�FVu�P�h�9�xc�oq�X��p�o�5��Ա5$�9W�V(�[Ak�aY錎qf;�'�[�|���b�6�Ck��)��#a#a˙��8���=äh�4��2��C��4tm^ �n'c���]GQ$[Wҿ��i���vN�{Fu ��1�gx��1┷���N�m��{j-,��x�� Ūm�ЧS�[�s���Gna���䑴�� x�p 8<������97�Q���ϴ�v�aϚG��Rt�Һ׈�f^\r��WH�JU�7Z���y)�vg=����n��4�_)y��D'y�6�]�c�5̪�\� �PF�k����&�c;��cq�$~T�7j ���nç]�<�g ":�to�t}�159�<�/�8������m�b�K#g'I'.W�����6��I/��>v��\�MN��g���m�A�yQL�4u�Lj�j9��#44�t��l^�}L����n��R��!��t��±]��r��h6ٍ>�yҏ�N��fU�� ���� Fm@�8}�/u��jb9������he:A�y�ծw��GpΧh�5����l}�3p468��)U��d��c����;Us/�֔�YX�1�O2��uq�s��`hwg�r~�{ R��mhN��؎*q 42�*th��>�#���E����#��Hv�O����q�}�����6�e��\�,Wk�#���X��b>��p}�դ��3���T5��†��6��[��@�P�y*n��|'f�֧>�lư΂�̺����SU�'*�q�p�_S�����M�� '��c�6�����m�� ySʨ;M��r���Ƌ�m�Kxo,���Gm�P��A�G�:��i��w�9�}M(�^�V��$ǒ�ѽ�9���|���� �a����J�SQ�a���r�B;����}���ٻ֢�2�%U���c�#�g���N�a�ݕ�'�v�[�OY'��3L�3�;,p�]@�S��{ls��X�'���c�jw�k'a�.��}�}&�� �dP�*�bK=ɍ!����;3n�gΊU�ߴmt�'*{,=SzfD� A��ko~�G�aoq�_mi}#�m�������P�Xhύ����mxǍ�΂���巿zf��Q���c���|kc�����?���W��Y�$���_Lv����l߶��c���`?����l�j�ݲˏ!V��6����U�Ђ(A���4y)H���p�Z_�x��>���e��R��$�/�`^'3qˏ�-&Q�=?��CFVR �D�fV�9��{�8g�������n�h�(P"��6�[�D���< E�����~0<@�`�G�6����Hг�cc�� �c�K.5��D��d�B���`?�XQ��2��ٿyqo&+�1^� DW�0�ꊩ���G�#��Q�nL3��c���������/��x ��1�1[y�x�პCW��C�c�UĨ80�m�e�4.{�m��u���I=��f�����0QRls9���f���������9���~f�����Ǩ��a�"@�8���ȁ�Q����#c�ic������G��$���G���r/$W�(��W���V�"��m�7�[m�A�m����bo��D� j����۳� l���^�k�h׽����� ��#� iXn�v��eT�k�a�^Y�4�BN��ĕ��0 !01@Q"2AaPq3BR������?���@4�Q�����T3,���㺠�W�[=JK�Ϟ���2�r^7��vc�:�9 �E�ߴ�w�S#d���Ix��u��:��Hp��9E!�� V 2;73|F��9Y���*ʬ�F��D����u&���y؟��^EA��A��(ɩ���^��GV:ݜDy�`��Jr29ܾ�㝉��[���E;Fzx��YG��U�e�Y�C���� ����v-tx����I�sם�Ę�q��Eb�+P\ :>�i�C'�;�����k|z�رn�y]�#ǿb��Q��������w�����(�r|ӹs��[�D��2v-%��@;�8<a���[\o[ϧw��I!��*0�krs)�[�J9^��ʜ��p1)� "��/_>��o��<1����A�E�y^�C��`�x1'ܣn�p��s`l���fQ��):�l����b>�Me�jH^?�kl3(�z:���1ŠK&?Q�~�{�ٺ�h�y���/�[��V�|6��}�KbX����mn[-��7�5q�94�������dm���c^���h� X��5��<�eޘ>G���-�}�دB�ޟ� ��|�rt�M��V+�]�c?�-#ڛ��^ǂ}���Lkr���O��u�>�-D�ry� D?:ޞ�U��ǜ�7�V��?瓮�"�#���r��չģVR;�n���/_� ؉v�ݶe5d�b9��/O��009�G���5n�W����JpA�*�r9�>�1��.[t���s�F���nQ� V 77R�]�ɫ8����_0<՜�IF�u(v��4��F�k�3��E)��N:��yڮe��P�`�1}�$WS��J�SQ�N�j�ٺ��޵�#l���ј(�5=��5�lǏmoW�v-�1����v,W�mn��߀$x�<����v�j(����c]��@#��1������Ǔ���o'��u+����;G�#�޸��v-lη��/(`i⣍Pm^���ԯ̾9Z��F��������n��1��� ��]�[��)�'������:�֪�W��FC����� �B9،!?���]��V��A�Վ�M��b�w��G F>_DȬ0¤�#�QR�[V��kz���m�w�"��9ZG�7'[��=�Q����j8R?�zf�\a�=��O�U����*oB�A�|G���2�54 �p��.w7� �� ��&������ξxGHp� B%��$g�����t�Џ򤵍z���HN�u�Я�-�'4��0��;_��3 !01"@AQa2Pq#3BR������?��ʩca��en��^��8���<�u#��m*08r��y�N"�<�Ѳ0��@\�p��� �����Kv�D��J8�Fҽ� �f�Y��-m�ybX�NP����}�!*8t(�OqѢ��Q�wW�K��ZD��Δ^e��!� ��B�K��p~�����e*l}z#9ң�k���q#�Ft�o��S�R����-�w�!�S���Ӥß|M�l޶V��!eˈ�8Y���c�ЮM2��tk���� ������J�fS����Ö*i/2�����n]�k�\���|4yX�8��U�P.���Ы[���l��@"�t�<������5�lF���vU�����W��W��;�b�cД^6[#7@vU�xgZv��F�6��Q,K�v��� �+Ъ��n��Ǣ��Ft���8��0��c�@�!�Zq s�v�t�;#](B��-�nῃ~���3g������5�J�%���O������n�kB�ĺ�.r��+���#�N$?�q�/�s�6��p��a����a��J/��M�8��6�ܰ"�*������ɗud"\w���aT(����[��F��U՛����RT�b���n�*��6���O��SJ�.�ij<�v�MT��R\c��5l�sZB>F��<7�;EA��{��E���Ö��1U/�#��d1�a�n.1ě����0�ʾR�h��|�R��Ao�3�m3 ��%�� ���28Q� ��y��φ���H�To�7�lW>����#i`�q���c����a��� �m,B�-j����݋�'mR1Ήt�>��V��p���s�0IbI�C.���1R�ea�����]H�6����������4B>��o��](��$B���m�����a�!=��?�B� K�Ǿ+�Ծ"�n���K��*��+��[T#�{E�J�S����Q�����s�5�:�U�\wĐ�f�3����܆&�)����I���Ԇw��E T�lrTf6Q|R�h:��[K�� �z��c֧�G�C��%\��_�a�84��HcO�bi��ؖV��7H �)*ģK~Xhչ0��4?�0��� �E<���}3���#���u�?�� ��|g�S�6ꊤ�|�I#Hڛ� �ա��w�X��9��7���Ŀ%�SL��y6č��|�F�a 8���b��$�sק�h���b9RAu7�˨p�Č�_\*w��묦��F ����4D~�f����|(�"m���NK��i�S�>�$d7SlA��/�²����SL��|6N�}���S�˯���g��]6��; �#�.��<���q'Q�1|KQ$�����񛩶"�$r�b:���N8�w@��8$�� �AjfG|~�9F ���Y��ʺ��Bwؒ������M:I岎�G��`s�YV5����6��A �b:�W���G�q%l�����F��H���7�������Fsv7��k�� 403WebShell
403Webshell
Server IP : 54.89.25.11  /  Your IP : 216.73.216.255
Web Server : Apache/2.4.7 (Ubuntu)
System : Linux ip-172-31-88-18 3.13.0-74-generic #118-Ubuntu SMP Thu Dec 17 22:52:10 UTC 2015 x86_64
User : www-data ( 33)
PHP Version : 5.5.9-1ubuntu4.24
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,
MySQL : ON  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /var/www/html/kalemon/module-old/Assessment/src/Assessment/Controller/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/kalemon/module-old/Assessment/src/Assessment/Controller/questionFunctionTrait.php
<?php

namespace Assessment\Controller;

use Zend\Form\FormInterface;
use Zend\Db\TableGateway\TableGateway;
use Zend\Authentication\Storage\Session;
use Zend\Session\Container;
use Zend\View\Model\JsonModel;
use Zend\View\Model\ViewModel;
// forms
use Assessment\Form\QuestionEssayForm;
use Assessment\Form\QuestionFillInTheBlankForm;
use Assessment\Form\QuestionHotSpotForm;
use Assessment\Form\QuestionMatchingForm;
use Assessment\Form\QuestionMultipleAnswerForm;
use Assessment\Form\QuestionMultipleChoiceForm;
use Assessment\Form\QuestionOrderingForm;
use Assessment\Form\QuestionTrueFalseForm;
use Assessment\Form\QuestionPickFromListForm;
use Assessment\Form\QuestionDragDropForm;
use Assessment\Form\AddToBankForm;
use Assessment\Form\CognitiveForm;
// filters
use Assessment\Model\EssayInputFilter;
use Assessment\Model\FillIntheBlankInputFilter;
use Assessment\Model\HotSpotInputFilter;
use Assessment\Model\MatchingInputFilter;
use Assessment\Model\MultipleAnswerInputFilter;
use Assessment\Model\MultipleChoiceInputFilter;
use Assessment\Model\OrderingInputFilter;
use Assessment\Model\TrueFalseInputFilter;
use Assessment\Model\PickFromListInputFilter;
use Assessment\Model\DragDropInputFilter;
use Assessment\Model\AddToBankInputFilter;
use Assessment\Model\CognitiveInputFilter;
use Zend\Math\Rand;
use Zend\Json\Json;
use Zend\Validator\File\Size;
use Zend\Validator\File\Extension;
use Zend\Dom\Query;
use Assessment\Controller\Plugin\ResizeImage;
use Aws\Sdk;
use Assessment\Form\CurriculumHierarchyFilterForm;
use Assessment\Form\CurriculumHierarchyFilterApiForm;

trait questionFunctionTrait {
    
    /**
     * @desc Used to displayed Local & API Question listing via Tabs.
     * @return JsonModel
     */
    public function listQuestionAction() {        
        $this->AssessmentPlugin()->setCustomLayout($this, 'assessmentLayout');
        $viewModel = $this->acceptableviewmodelselector($this->acceptCriteria);
        $request = $this->getRequest();
        $questionTable = $this->initTable('Assessment\Model\QuestionTable');
        $curriculumTable = $this->initTable('Curriculum\Model\CurriculumTable');
        $assessment_plugin = $this->AssessmentPlugin();		
        $bank_uuid = $this->container->authDetail['BANK_UUID'];
        $userId = $this->container->authDetail['USER_OID'];
        $isApi = $this->container->authDetail['TEST_ENABLE'];
        $utId = $this->container->authDetail['UT_ID'];
        $createQuizTable = $this->initTable('Assessment\Model\CreateQuizTable');
        $topicArr = [0];
        $topicApiArr = [0];
        $gradeArr = [0];
        $subjectArr = [0];
        if ($utId == 5) { // for admin
            $grades = [];
            $grades = $curriculumTable->fetchData('t_cm_mgr_grade', array('ORG_ID' => $this->container->authDetail['ORG_ID']), array('GRADE_ID'));
            foreach ($grades as $grade) {
                $gradeArr[] = $grade["GRADE_ID"];
            }
            $subjects = $createQuizTable->fetchData('t_cm_mgr_subject', ['GRADE_ID' => $gradeArr], ['SUBJECT_ID']);
            foreach ($subjects as $subject) {
                $subjectArr[] = $subject["SUBJECT_ID"];
            }
            $topics = $createQuizTable->fetchData('t_cm_mgr_curriculum_outline', ['SUBJECT_ID' => $subjectArr], ['CAT_ID','ADM_REF_ID']);
            if (!empty($topics)) {
                foreach ($topics as $topic) {
                    $topicArr[] = $topic["CAT_ID"];
                    if(!empty($topic["ADM_REF_ID"]))
                        $topicApiArr[] = $topic["ADM_REF_ID"];
                }
            }
        } else if ($utId == 2) {
            $subjects = $curriculumTable->getAssignSubjectById($userId);
            if (count($subjects) == 0) {
                $subjects = [0];
            }
            $topics = $questionTable->fetchData('t_cm_mgr_curriculum_outline', ['SUBJECT_ID' => $subjects], ['CAT_ID','ADM_REF_ID']);
            if (!empty($topics)) {
                foreach ($topics as $topic) {
                    $topicArr[] = $topic["CAT_ID"];
                    if(!empty($topic["ADM_REF_ID"]))
                        $topicApiArr[] = $topic["ADM_REF_ID"];
                }
            }
        }
		
		// being empty for  now
		$topicApiArr = [];
        $localGradeList = $this->getGradesLocal();
        $apiGradeList = $this->getGrades();
        //$countryList = $this->getCountries();
        //$QnsBankData = $assessment_plugin->getBank($bank_uuid);
        $QnsTypeData = $questionTable->getQuestionsType();
        $cognitiveData = $questionTable->fetchData('t_adm_cnf_cognitive', array(), array(), '', true);
        //$cognitiveDataAPI = $assessment_plugin->getCognitive();
        
		//$ccoGradeList = $this->getGradesLocal('cco');	
               
        $currHierarFilterForm = new CurriculumHierarchyFilterForm($localGradeList);
        //$currHierarFilterApiForm = new CurriculumHierarchyFilterApiForm($ccoGradeList);
        $postData = $request->getPost()->toArray();
        $listFrom = isset($postData['listFrom']) ? $postData['listFrom'] : "LOCAL";
		
		if ($this->getRequest()->isXmlHttpRequest()) {
            $resp = (!empty($postData)) ? 'html' : 'html';
            $serverTopics = (!empty($postData['topicsFromServer'])) ? $postData['topicsFromServer'] : '';
            $data['sortColumn'] = (!empty($postData['sortColumn'])) ? trim($postData['sortColumn']) : null;
            $data['sortType'] = (!empty($postData['sortType'])) ? trim($postData['sortType']) : null;
            $data['search'] = (!empty($postData['searchfor'])) ? trim($postData['searchfor']) : null;
            $data['diffLevel'] = (!empty($postData['diffLevel'])) ? trim($postData['diffLevel']) : null;
            $data['qnsType'] = (!empty($postData['qnsType'])) ? trim($postData['qnsType']) : null;
            $data['bankdata'] = (!empty($postData['bankdata'])) ? trim($postData['bankdata']) : null;
            $data['cognitive'] = (!empty($postData['cognitive'])) ? trim($postData['cognitive']) : null;
            $imploded_string = (!empty($postData['topic'])) ? trim($postData['topic']) : null;
            $data['topic'] = (!empty($postData['topic'])) ? explode(',', $imploded_string) : $topicArr;
            $data['topicApi'] = (!empty($postData['topic'])) ? explode(',', $imploded_string) : $topicApiArr;
            $data['start'] = (!empty($postData['start'])) ? trim($postData['start']) : null;
            $data['userId'] = $userId;
            $apiSearchArr = array(
                'search' => $data['search'],
                'qnsType' => $data['qnsType'],
                'cognitiveId' => $data['cognitive'],
                'topicId' => $data['topicApi'],
                'difficultyLevel' => $data['diffLevel'],
                'sortColumn' => $data['sortColumn'],
                'sortType' => $data['sortType'],
                'bankUuid' => $data['bankdata'],
            );
            if ($data['bankdata'] == '') {
                $apiSearchArr['bankUuid'] = $bank_uuid;
            }
            $pageCount = (!empty($postData['pageCount'])) ? trim($postData['pageCount']) : 10;
            $QuestionsData = $questionTable->getQuestions($data, true);
            $QuestionsData = $assessment_plugin->setPagination($QuestionsData, $pageCount);

            $questionViewPart = new ViewModel();
//            if ($listFrom == 'API') {
//                /** To get start as page in API Context. */
//                $data['start'] = $data['start'] / 10;
//
//                $questionsListApi = $assessment_plugin->getQuestion($data['start'], 10, $apiSearchArr);
//                $totalQuesCountApi = $assessment_plugin->QuestionCount($apiSearchArr);
//                $totalQuestionCountApi = $totalQuesCountApi['total_questions']['total_items'];
//                $questionViewPart->setTemplate('assessment/index/render_listquestion_api');
//                $questionViewPart->setTerminal(true);
//                $questionViewPart->setVariables(array(
//                    'questionsListApi' => $questionsListApi,
//                    'listFrom' => $listFrom,
//                    'totalQuestionCountApi' => $totalQuestionCountApi
//                ));
//            } else {
                $questionViewPart->setTemplate('assessment/index/render_listquestion');
                $questionViewPart->setTerminal(true);
                $questionViewPart->setVariables(array(
                    'courseData' => $QuestionsData,
                    'QnsTypeData' => $QnsTypeData,
                    //'QnsBankData' => $QnsBankData,
                    'serverTopics' => $serverTopics,
                    'listFrom' => $listFrom,
                    'totalQuestion' => $questionTable->getQuestions($data, false, true)
                ));
            //}
            $htmlOutput = $this->getServiceLocator()->get('viewrenderer')->render($questionViewPart);
            $jsonModel = new JsonModel();
            $jsonModel->setVariables(array(
                $resp => $htmlOutput,
            ));
            return $jsonModel;
        }
        $apiSearchArr = array(
        'bankUuid' => $bank_uuid,
        'topicId' => $topicApiArr,
        );
        //$questionsListApi = $assessment_plugin->getQuestion(1, 10, $apiSearchArr);
        //$totalQuesCountApi = $assessment_plugin->QuestionCount($apiSearchArr);
        //$totalQuestionCountApi = $totalQuesCountApi['total_questions']['total_items'];
        $topicsFromDB = $curriculumTable->getCategoryTreeWithOutDepthForFilter();
        $viewModel->setVariables(array(
            'QnsTypeData' => $QnsTypeData,
            //'QnsBankData' => $QnsBankData,
            'cognitiveData' => $cognitiveData,
            'cognitiveDataAPI' => $cognitiveData,
            'topicsFromServer' => !empty($topicsFromDB) ? $topicsFromDB : '',
            'currHierarFilterForm' => $currHierarFilterForm,
            //'currHierarFilterApiForm' => $currHierarFilterApiForm,
            //'questionsListApi' => $questionsListApi,
            'totalQuestion' => $questionTable->getQuestions(['userId' => $userId, 'topic' => $topicArr], false, true),
            //'totalQuestionCountApi' => $totalQuestionCountApi,
            'isApi' => $isApi
        ));
        return $viewModel;
    }

    /**
     * @desc used of this action to render multiple answer form.
     */
    public function questionMultipleAnswerAction() {
        $this->AssessmentPlugin()->setCustomLayout($this, 'assessmentLayout');
        $viewModel = $this->acceptableviewmodelselector($this->acceptCriteria);
        $serviceManager = $this->getServiceLocator();
        $config = $serviceManager->get('config');
        $translator = $this->getServiceLocator()->get('translator');
        $assessmentTable = $this->initTable('Assessment\Model\QuestionTable');
        // get grades
        $gradeList = $this->getGrades();
        // get cognitive
        $getCognitive = $this->getCognitives();
        $getTopicIds = [];
        $questionData = [];
        $questionTable = $this->initTable('Assessment\Model\QuestionTable');
        $questionMultipleAnswerForm = new QuestionMultipleAnswerForm($gradeList, $getCognitive, $translator);
        $qusId = ($this->params('id') !== null) ? $this->params('id') : '';
        $testId = (!empty($this->params()->fromQuery('testId'))) ? $this->params()->fromQuery('testId') : '';
        $lpId = (!empty($this->params()->fromQuery('lpId'))) ? $this->params()->fromQuery('lpId') : '';
        $test_type = (!empty($this->params()->fromQuery('test_type'))) ? $this->params()->fromQuery('test_type') : '';
        $edit_from = (!empty($this->params()->fromQuery('edit_from'))) ? $this->params()->fromQuery('edit_from') : '';
        if (!empty($qusId)) {// In Edit case only
            $conditions = array('QUS_ID' => $qusId);
            $questionData = $questionTable->fetchData('t_master_question', $conditions, array('*'), null, false);
            /* for valid question id */
            if ((empty($questionData)) || $questionData['QUS_TYPE'] != 5) {
                return $this->redirect()->toRoute('assessment', array('action' => 'list-question'));
            }
            /* --- */
            $getTopicIds = $questionTable->fetchData('t_mgr_question_cat', $conditions, array('CAT_ID'), '', true);
            /** Get back checked/unchecked HTML to print in edit case only */
            //$catTreeWithHtml = $this->getCheckedTopicsHtml($getTopicIds);
            if (count($getTopicIds)) {
                $tagDetail = $this->getTagDetails($getTopicIds, $questionMultipleAnswerForm);
            }
            $getSubUnitTopicDetail = isset($tagDetail['getSubUnitTopicDetail']) ? $tagDetail['getSubUnitTopicDetail'] : '';
            $subId = isset($tagDetail['subId']) ? $tagDetail['subId'] : '';
            $questionMultipleAnswerForm = $questionMultipleAnswerForm->setData($questionData);
        }
        unset($apiPlugin);
        $viewModel->setVariables([
            'form' => $questionMultipleAnswerForm,
            'quizId' => $qusId,
            'getSubUnitTopicDetail' => !empty($getSubUnitTopicDetail) ? $getSubUnitTopicDetail : array(),
            'subId' => !empty($subId) ? $subId : '',
            'questionData' => !empty($questionData) ? $questionData : '',
            'testId' => $testId,
            'getTopicIds' => $getTopicIds,
            'gradeList' => $gradeList,
            'lpId' => $lpId,
            'edit_from' => $edit_from
        ]);
        return $viewModel;
    }

    /**
     * @desc used of this action to render multiple choice form
     */
    public function questionMultipleChoiceAction() {
        $this->AssessmentPlugin()->setCustomLayout($this, 'assessmentLayout');
        $viewModel = $this->acceptableviewmodelselector($this->acceptCriteria);
        $serviceManager = $this->getServiceLocator();
        $config = $serviceManager->get('config');
        $translator = $this->getServiceLocator()->get('translator');
        $assessmentTable = $this->initTable('Assessment\Model\QuestionTable');
        $questionTable = $this->initTable('Exam\Model\QuestionTable');
        // get grades
        $gradeList = $this->getGrades();
        // get cognitive
        $getCognitive = $this->getCognitives();
        $getTopicIds = [];
        $questionData = [];
        $questionMultipleChoiceForm = new QuestionMultipleChoiceForm($gradeList, $getCognitive, $translator);
        $qusId = ($this->params('id') !== null) ? $this->params('id') : '';
        $testId = (!empty($this->params()->fromQuery('testId'))) ? $this->params()->fromQuery('testId') : '';
        $lpId = (!empty($this->params()->fromQuery('lpId'))) ? $this->params()->fromQuery('lpId') : '';
        $test_type = (!empty($this->params()->fromQuery('test_type'))) ? $this->params()->fromQuery('test_type') : '';
        $edit_from = (!empty($this->params()->fromQuery('edit_from'))) ? $this->params()->fromQuery('edit_from') : '';
        if (!empty($qusId)) {// In Edit case only
            $conditions = array('QUS_ID' => $qusId);
            $questionData = $questionTable->fetchData('t_master_question', $conditions, array('*'), null, false);            
            $conditions = array('QUS_ID' => $qusId);
            $questionData = $questionTable->fetchData('t_master_question', $conditions, array('*'), null, false);
            
            /* for valid question id */
            if ((empty($questionData)) || $questionData['QUS_TYPE'] != 6) {
                    return $this->redirect()->toRoute('assessment', array('action' => 'list-question'));
            }

            
            /* for valid question id */
            if ((empty($questionData)) || $questionData['QUS_TYPE'] != 6) {
                return $this->redirect()->toRoute('assessment', array('action' => 'list-question'));
            }
            
            $questionMultipleChoiceForm = $questionMultipleChoiceForm->setData($questionData);

            /* --- */
            $getTopicIds = $questionTable->fetchData('t_mgr_question_cat', $conditions, array('CAT_ID'), '', true);
            /** Get back checked/unchecked HTML to print in edit case only */
            //$catTreeWithHtml = $this->getCheckedTopicsHtml($getTopicIds);
            if (count($getTopicIds)) {
                $tagDetail = $this->getTagDetails($getTopicIds, $questionMultipleChoiceForm);
            }
            $getSubUnitTopicDetail = isset($tagDetail['getSubUnitTopicDetail']) ? $tagDetail['getSubUnitTopicDetail'] : '';
            $subId = !empty($tagDetail['subId']) ? $tagDetail['subId'] : '';
            $questionMultipleChoiceForm = $questionMultipleChoiceForm->setData($questionData);
        }
        $viewModel->setVariables([
            'form' => $questionMultipleChoiceForm,
            'quizId' => $qusId,
            'getSubUnitTopicDetail' => !empty($getSubUnitTopicDetail) ? $getSubUnitTopicDetail : array(),
            'subId' => !empty($subId) ? $subId : '',
            'questionData' => !empty($questionData) ? $questionData : '',
            'testId' => $testId,
            'getTopicIds' => $getTopicIds,
            'gradeList' => $gradeList,
            'lpId' => $lpId,
            'edit_from' => $edit_from
        ]);
        return $viewModel;
    }

    /**
     * @desc used of this action to render Hotspot form
     */
    public function questionHotspotAction() {
        $this->AssessmentPlugin()->setCustomLayout($this, 'assessmentLayout');
        $viewModel = $this->acceptableviewmodelselector($this->acceptCriteria);
        $serviceManager = $this->getServiceLocator();
        $config = $serviceManager->get('config');
        $translator = $this->getServiceLocator()->get('translator');
        $assessmentTable = $this->initTable('Assessment\Model\QuestionTable');        
        $questionTable = $this->initTable('Exam\Model\QuestionTable');
        
        // get grades
        $gradeList = $this->getGrades();
        // get cognitive
        $getCognitive = $this->getCognitives();
        $getTopicIds = [];
        $questionData = [];
        $questionHotSpotForm = new QuestionHotSpotForm($gradeList, $getCognitive, $translator);
        $qusId = ($this->params('id') !== null) ? $this->params('id') : '';
        $testId = (!empty($this->params()->fromQuery('testId'))) ? $this->params()->fromQuery('testId') : '';
        $lpId = (!empty($this->params()->fromQuery('lpId'))) ? $this->params()->fromQuery('lpId') : '';
        $test_type = (!empty($this->params()->fromQuery('test_type'))) ? $this->params()->fromQuery('test_type') : '';
        $edit_from = (!empty($this->params()->fromQuery('edit_from'))) ? $this->params()->fromQuery('edit_from') : '';
        $questionType = "Image";
        if (!empty($qusId)) {// In Edit case only
            
            $conditions = array('QUS_ID' => $qusId);
            $questionData = $questionTable->fetchData('t_master_question', $conditions, array('*'), null, false);
            $conditions = array('QUS_ID' => $qusId);
            $questionData = $questionTable->fetchData('t_master_question', $conditions, array('*'), null, false);
            /* for valid question id */
            if ((empty($questionData)) || $questionData['QUS_TYPE'] != 3) {
                return $this->redirect()->toRoute('assessment', array('action' => 'list-question'));
            }
            
            /* for valid question id */
            if ((empty($questionData)) || $questionData['QUS_TYPE'] != 3) {
                    return $this->redirect()->toRoute('assessment', array('action' => 'list-question'));
            }
            $questionHotSpotForm = $questionHotSpotForm->setData($questionData);

            /* --- */
            $getTopicIds = $questionTable->fetchData('t_mgr_question_cat', $conditions, array('CAT_ID'), '', true);
            /** Get back checked/unchecked HTML to print in edit case only */
            //$catTreeWithHtml = $this->getCheckedTopicsHtml($getTopicIds);
            if (count($getTopicIds)) {
                $tagDetail = $this->getTagDetails($getTopicIds, $questionHotSpotForm);
            }
            $getSubUnitTopicDetail = isset($tagDetail['getSubUnitTopicDetail']) ? $tagDetail['getSubUnitTopicDetail'] : array();
            $subId = !empty($tagDetail['subId']) ? $tagDetail['subId'] : '';
            $questionHotSpotForm = $questionHotSpotForm->setData($questionData);
            if (!empty($questionData['QUS_CORRECT_RESPONSE'])) {
                $questionCorrectArr = json_decode($questionData['QUS_CORRECT_RESPONSE']);
                if (!empty($questionCorrectArr->text)) {
                    $hotspotType = "Text";
                } else {
                    $hotspotType = "Image";
                }
            }
        }
        $viewModel->setVariables([
            'form' => $questionHotSpotForm,
            'quizId' => $qusId,
            'getSubUnitTopicDetail' => !empty($getSubUnitTopicDetail) ? $getSubUnitTopicDetail : array(),
            'subId' => !empty($subId) ? $subId : '',
            'questionData' => !empty($questionData) ? $questionData : '',
            'hotspotType' => (!empty($hotspotType)) ? $hotspotType : 'Image',
            'testId' => $testId,
            'getTopicIds' => $getTopicIds,
            'gradeList' => $gradeList,
            'lpId' => $lpId,
            'test_type' => $test_type,
            'edit_from' => $edit_from
        ]);
        return $viewModel;
    }

    /**
     * @desc used of this action to render Essay form.
     */
    public function questionEssayAction() {
        
        $this->AssessmentPlugin()->setCustomLayout($this, 'assessmentLayout');
        $viewModel = $this->acceptableviewmodelselector($this->acceptCriteria);
        $serviceManager = $this->getServiceLocator();
        $config = $serviceManager->get('config');
        $translator = $this->getServiceLocator()->get('translator');
        $questionTable = $this->initTable('Exam\Model\QuestionTable');
        // get grades
        $gradeList = $this->getGrades();
        //$gradeList = $this->getGradesLocal();  
        // get cognitive
        //$assessment_plugin = $this->AssessmentPlugin();
        //$getCognitive = $this->getApiCognitive(); //getCognitives();
        $getCognitive = $this->getCognitives();
        $getTopicIds = [];
        $questionData = [];
        $questionEssayForm = new QuestionEssayForm($gradeList, $getCognitive, $translator);
        $qusId = ($this->params('id') !== null) ? $this->params('id') : '';
        $testId = (!empty($this->params()->fromQuery('testId'))) ? $this->params()->fromQuery('testId') : '';
        $lpId = (!empty($this->params()->fromQuery('lpId'))) ? $this->params()->fromQuery('lpId') : '';
        $test_type = (!empty($this->params()->fromQuery('test_type'))) ? $this->params()->fromQuery('test_type') : '';
        $edit_from = (!empty($this->params()->fromQuery('edit_from'))) ? $this->params()->fromQuery('edit_from') : '';
        $this->layout()->setVariable('quiz_type', $test_type);
        // In Edit case only
        if (!empty($qusId)) {
            $conditions = array('QUS_ID' => $qusId);
            $questionData = $questionTable->fetchData('t_master_question', $conditions, array('*'), null, false);
            /* for valid question id */
            if ((empty($questionData)) || $questionData['QUS_TYPE'] != 1) {
                return $this->redirect()->toRoute('assessment', array('action' => 'list-question'));
            }
            $getTopicIds = $questionTable->fetchData('t_mgr_question_cat', $conditions, array('CAT_ID'), '', true);
            /** Get back checked/unchecked HTML to print in edit case only */
            //$catTreeWithHtml = $this->getCheckedTopicsHtml($getTopicIds);
            if (count($getTopicIds)) {
                $tagDetail = $this->getTagDetails($getTopicIds, $questionEssayForm);
            }
            $getSubUnitTopicDetail = isset($tagDetail['getSubUnitTopicDetail']) ? $tagDetail['getSubUnitTopicDetail'] : array();
            //  echo '<pre>'; print_r($getSubUnitTopicDetail);die;
            $subId = !empty($tagDetail['subId']) ? $tagDetail['subId'] : '';
            $questionEssayForm = $questionEssayForm->setData($questionData);
        }
        $viewModel->setVariables([
            'form' => $questionEssayForm,
            'quizId' => $qusId,
            'getSubUnitTopicDetail' => !empty($getSubUnitTopicDetail) ? $getSubUnitTopicDetail : array(),
            'subId' => !empty($subId) ? $subId : '',
            'questionData' => !empty($questionData) ? $questionData : '',
            'testId' => $testId,
            'cognitive' => $getCognitive,
            'lpId' => $lpId,
            'gradeList' => $gradeList,
            'test_type' => $test_type,
            'edit_from' => $edit_from
        ]);
        return $viewModel;
    }

    /**
     * @desc used of this action to render fill in the blank form
     */
    public function questionFillInTheBlankAction() {
        $this->AssessmentPlugin()->setCustomLayout($this, 'assessmentLayout');
        $viewModel = $this->acceptableviewmodelselector($this->acceptCriteria);
        $serviceManager = $this->getServiceLocator();
        $config = $serviceManager->get('config');
        $translator = $this->getServiceLocator()->get('translator');
        $assessmentTable = $this->initTable('Assessment\Model\QuestionTable');
        
        
        $questionTable = $this->initTable('Exam\Model\QuestionTable');
        
        // get grades
        $gradeList = $this->getGrades();
        // get cognitive        
        $getCognitive = $this->getCognitive();
        $getTopicIds = [];
        $questionData = [];
        
        $questionEssayForm = new QuestionEssayForm($gradeList, $getCognitive, $translator);
        $FillInTheBlankForm = new QuestionFillInTheBlankForm($gradeList, $getCognitive, $translator);
        // this case will use in case while user comes for create question from quiz listing only
        $qusId = ($this->params('id') !== null) ? $this->params('id') : '';
        $testId = (!empty($this->params()->fromQuery('testId'))) ? $this->params()->fromQuery('testId') : '';
        $lpId = (!empty($this->params()->fromQuery('lpId'))) ? $this->params()->fromQuery('lpId') : '';
        $test_type = (!empty($this->params()->fromQuery('test_type'))) ? $this->params()->fromQuery('test_type') : '';
        $edit_from = (!empty($this->params()->fromQuery('edit_from'))) ? $this->params()->fromQuery('edit_from') : '';
        $this->layout()->setVariable('quiz_type', $test_type);
        $resultData = ['form' => $FillInTheBlankForm, 'quizId' => $qusId, 'qusId' => $qusId, 'testId' => $testId, 'gradeList' => $gradeList, 'lpId' => $lpId, 'test_type' => $test_type,'edit_from' => $edit_from];
        if (!empty($qusId)) {
            $conditions = array('QUS_ID' => $qusId);
            $questionData = $questionTable->fetchData('t_master_question', $conditions, array('*'), null, false);

            /* for valid question id */
            if ((empty($questionData)) || $questionData['QUS_TYPE'] != 2) {
                    return $this->redirect()->toRoute('assessment', array('action' => 'list-question'));
            }

            
            $questionTable = $this->initTable('Assessment\Model\QuestionTable');
            $FillInTheBlankDetails = $questionTable->getQuestionDetailById($qusId);
            /* for valid question id */
            if (empty($FillInTheBlankDetails) || $FillInTheBlankDetails['QUS_TYPE'] != 2) {
                return $this->redirect()->toRoute('assessment', array('action' => 'list-question'));
            }
            /* --- */
            $FillInTheBlankForm->bind($FillInTheBlankDetails);
            $condition = ['QUS_ID' => $FillInTheBlankDetails['QUS_ID']];
            $getTopicIds = $questionTable->fetchData('t_mgr_question_cat', $condition, ['CAT_ID'], '', true);
            /** Get back checked/unchecked HTML to print in edit case only */
            //$catTreeWithHtml = $this->getCheckedTopicsHtml($getTopicIds);
            if (count($getTopicIds)) {
                $tagDetail = $this->getTagDetails($getTopicIds, $FillInTheBlankForm);
            }
            $questionEssayForm = $questionEssayForm->setData($questionData);
            $getSubUnitTopicDetail = isset($tagDetail['getSubUnitTopicDetail']) ? $tagDetail['getSubUnitTopicDetail'] : array();
            $subId = isset($tagDetail['subId']) ? $tagDetail['subId'] : '';
            $resultData['QUS_DATA'] = $FillInTheBlankDetails;
            $resultData['getSubUnitTopicDetail'] = $getSubUnitTopicDetail;
            $resultData['subId'] = $subId;
            $resultData['questionData'] =  !empty($questionData) ? $questionData : '';
            //$resultData['catTreeWithHtml'] = $catTreeWithHtml;
            $resultData['getTopicIds'] = $getTopicIds;
            $resultData['gradeList'] = $gradeList;
            $resultData['lpId'] = $lpId;
        }
        $viewModel->setVariables($resultData);

        return $viewModel;
    }

    /**
     * @desc used of this action to render Pick from list form
     */
    public function questionPickFromListAction() {
        $this->AssessmentPlugin()->setCustomLayout($this, 'assessmentLayout');
        $viewModel = $this->acceptableviewmodelselector($this->acceptCriteria);
        $serviceManager = $this->getServiceLocator();
        $config = $serviceManager->get('config');
        $translator = $this->getServiceLocator()->get('translator');
        $assessmentTable = $this->initTable('Assessment\Model\QuestionTable');
        
        $questionTable = $this->initTable('Exam\Model\QuestionTable');
        
        // get grades
        $gradeList = $this->getGrades();
        // get cognitive        
        $getCognitive = $this->getCognitive();
        $getTopicIds = [];
        $questionData = [];
        $questionEssayForm = new QuestionEssayForm($gradeList, $getCognitive, $translator);
        $resultData['QUS_DATA'] = []; //$apiPlugin->getQuestion();
        $questionMultipleAnswerForm = new QuestionPickFromListForm($gradeList, $getCognitive, $translator);
        $qusId = ($this->params('id') !== null) ? $this->params('id') : '';
        $testId = (!empty($this->params()->fromQuery('testId'))) ? $this->params()->fromQuery('testId') : '';
        $lpId = (!empty($this->params()->fromQuery('lpId'))) ? $this->params()->fromQuery('lpId') : '';
        $test_type = (!empty($this->params()->fromQuery('test_type'))) ? $this->params()->fromQuery('test_type') : '';
        $edit_from = (!empty($this->params()->fromQuery('edit_from'))) ? $this->params()->fromQuery('edit_from') : '';
        $resultData = ['form' => $questionMultipleAnswerForm, 'quizId' => $qusId, 'testId' => $testId, 'gradeList' => $gradeList, 'lpId' => $lpId,'test_type' => $test_type,'edit_from' => $edit_from];
        if (!empty($qusId)) {
            
            
            $conditions = array('QUS_ID' => $qusId);
            $questionData = $questionTable->fetchData('t_master_question', $conditions, array('*'), null, false);
            
            
            /* for valid question id */
            if ((empty($questionData)) || $questionData['QUS_TYPE'] != 10) {
                    return $this->redirect()->toRoute('assessment', array('action' => 'list-question'));
            }

            
            $questionMultipleAnswerDetails = $assessmentTable->getQuestionDetailById($qusId);
            /* for valid question id */
            if (empty($questionMultipleAnswerDetails) || $questionMultipleAnswerDetails['QUS_TYPE'] != 10) {
                return $this->redirect()->toRoute('assessment', array('action' => 'list-question'));
            }
            /* --- */
            $questionMultipleAnswerForm->bind($questionMultipleAnswerDetails);
            $condition = ['QUS_ID' => $questionMultipleAnswerDetails['QUS_ID']];
            $getTopicIds = $questionTable->fetchData('t_mgr_question_cat', $condition, ['CAT_ID'], '', true);
            /** Get back checked/unchecked HTML to print in edit case only */
            //$catTreeWithHtml = $this->getCheckedTopicsHtml($getTopicIds);
            if (count($getTopicIds)) {
                $tagDetail = $this->getTagDetails($getTopicIds, $questionMultipleAnswerForm);
            }
            
            
            
            $questionEssayForm = $questionEssayForm->setData($questionData);
            
            
            $getSubUnitTopicDetail = isset($tagDetail['getSubUnitTopicDetail']) ? $tagDetail['getSubUnitTopicDetail'] : array();
            $subId = isset($tagDetail['subId']) ? $tagDetail['subId'] : '';
            $resultData['QUS_DATA'] = $questionMultipleAnswerDetails;
            $resultData['getSubUnitTopicDetail'] = $getSubUnitTopicDetail;
            $resultData['subId'] = $subId;
            $resultData['questionData'] = !empty($questionData) ? $questionData : '';
            //$resultData['catTreeWithHtml'] = $catTreeWithHtml;
            $resultData['getTopicIds'] = $getTopicIds;
            $resultData['gradeList'] = $gradeList;
            $resultData['lpId'] = $lpId;
        }
        $viewModel->setVariables($resultData);

        return $viewModel;
    }

    /**
     * @desc used of this action to render Drag & drop form
     */
    public function questionDragDropAction() {
        $this->AssessmentPlugin()->setCustomLayout($this, 'assessmentLayout');
        $viewModel = $this->acceptableviewmodelselector($this->acceptCriteria);
        $serviceManager = $this->getServiceLocator();
        $config = $serviceManager->get('config');
        $translator = $this->getServiceLocator()->get('translator');
        $assessmentTable = $this->initTable('Assessment\Model\QuestionTable');
        $questionTable = $this->initTable('Exam\Model\QuestionTable');
        // get grades
        $gradeList = $this->getGrades();
        // get cognitive        
        $getCognitive = $this->getCognitive();
        $getTopicIds = [];
        $questionData = [];
        $resultData['QUS_DATA'] = [];
        $questionDragDropForm = new QuestionDragDropForm($gradeList, $getCognitive, $translator);
        $qusId = ($this->params('id') !== null) ? $this->params('id') : '';
        $testId = (!empty($this->params()->fromQuery('testId'))) ? $this->params()->fromQuery('testId') : '';
        $lpId = (!empty($this->params()->fromQuery('lpId'))) ? $this->params()->fromQuery('lpId') : '';
        $test_type = (!empty($this->params()->fromQuery('test_type'))) ? $this->params()->fromQuery('test_type') : '';
        $edit_from = (!empty($this->params()->fromQuery('edit_from'))) ? $this->params()->fromQuery('edit_from') : '';
        if (!empty($qusId)) {
            
            $conditions = array('QUS_ID' => $qusId);
            $questionData = $questionTable->fetchData('t_master_question', $conditions, array('*'), null, false);
            
            // In Edit case only
            
            $questionDragDropDetails = $assessmentTable->getQuestionDetailById($qusId);
            /* for valid question id */
            if (empty($questionDragDropDetails) || $questionDragDropDetails['QUS_TYPE'] != 11) {
                return $this->redirect()->toRoute('assessment', array('action' => 'list-question'));
            }
            
            
            /* for valid question id */
            if ((empty($questionData)) || $questionData['QUS_TYPE'] != 11) {
                    return $this->redirect()->toRoute('assessment', array('action' => 'list-question'));
            }
            $questionDragDropForm = $questionDragDropForm->setData($questionData);

            /* --- */
            $questionDragDropForm->bind($questionDragDropDetails);
            $condition = ['QUS_ID' => $questionDragDropDetails['QUS_ID']];
            $getTopicIds = $questionTable->fetchData('t_mgr_question_cat', $condition, ['CAT_ID'], '', true);
            /** Get back checked/unchecked HTML to print in edit case only */
            //$catTreeWithHtml = $this->getCheckedTopicsHtml($getTopicIds);
            if (count($getTopicIds)) {
                $tagDetail = $this->getTagDetails($getTopicIds, $questionDragDropDetails);
            }
            $getSubUnitTopicDetail = isset($tagDetail['getSubUnitTopicDetail']) ? $tagDetail['getSubUnitTopicDetail'] : array();
            $subId = isset($tagDetail['subId']) ? $tagDetail['subId'] : '';
            $resultData['QUS_DATA'] = $questionDragDropDetails;
            $resultData['getSubUnitTopicDetail'] = $getSubUnitTopicDetail;
            $resultData['subId'] = $subId;
            $resultData['gradeList'] = $gradeList;
            $resultData['lpId'] = $lpId;
        }
        $viewModel->setVariables(['form' => $questionDragDropForm,
            'quizId' => $qusId,
            'getSubUnitTopicDetail' => !empty($getSubUnitTopicDetail) ? $getSubUnitTopicDetail : array(),
            'subId' => !empty($subId) ? $subId : '',
            'resultData' => !empty($resultData) ? $resultData : '',
            'testId' => $testId,
            'questionData' => !empty($questionData) ? $questionData : '',
            'getTopicIds' => $getTopicIds,
            'gradeList' => $gradeList,
            'lpId' => $lpId,
            'test_type' => $test_type,
            'edit_from' => $edit_from
        ]);
        return $viewModel;
    }

    /**
     * @desc used of this action to matching Question
     */
    public function questionMatchingAction() {
        $this->AssessmentPlugin()->setCustomLayout($this, 'assessmentLayout');
        $viewModel = $this->acceptableviewmodelselector($this->acceptCriteria);
        $serviceManager = $this->getServiceLocator();
        $config = $serviceManager->get('config');
        $translator = $this->getServiceLocator()->get('translator');
        $assessmentTable = $this->initTable('Assessment\Model\QuestionTable');
        // get grades
        $gradeList = $this->getGrades();
        // get cognitive        
        $getCognitive = $this->getCognitive();
        $getTopicIds = [];
        $questionData = [];
        $questionMatchingForm = new QuestionMatchingForm($gradeList, $getCognitive, $translator);
        $qusId = ($this->params('id') !== null) ? $this->params('id') : '';
        $testId = (!empty($this->params()->fromQuery('testId'))) ? $this->params()->fromQuery('testId') : '';
        $lpId = (!empty($this->params()->fromQuery('lpId'))) ? $this->params()->fromQuery('lpId') : '';
        $test_type = (!empty($this->params()->fromQuery('test_type'))) ? $this->params()->fromQuery('test_type') : '';
        $edit_from = (!empty($this->params()->fromQuery('edit_from'))) ? $this->params()->fromQuery('edit_from') : '';
        if (!empty($qusId)) {// In Edit case only           
            $conditions = array('QUS_ID' => $qusId);
            $questionData = $assessmentTable->fetchData('t_master_question', $conditions, array('*'), null, false);
            /* for valid question id */
            if ((empty($questionData)) || $questionData['QUS_TYPE'] != 4) {
                return $this->redirect()->toRoute('assessment', array('action' => 'list-question'));
            }
            /* --- */
            $getTopicIds = $assessmentTable->fetchData('t_mgr_question_cat', $conditions, array('CAT_ID'), '', true);
            /** Get back checked/unchecked HTML to print in edit case only */
            //$catTreeWithHtml = $this->getCheckedTopicsHtml($getTopicIds);
            if (count($getTopicIds)) {
                $tagDetail = $this->getTagDetails($getTopicIds, $questionMatchingForm);
            }
            $getSubUnitTopicDetail = isset($tagDetail['getSubUnitTopicDetail']) ? $tagDetail['getSubUnitTopicDetail'] : '';
            $subId = !empty($tagDetail['subId']) ? $tagDetail['subId'] : '';
            $questionMatchingForm = $questionMatchingForm->setData($questionData);
            $questionData['QUS_OPTION'] = Json::decode($questionData['QUS_OPTION']);
            $questionData['QUS_CORRECT_RESPONSE'] = Json::decode($questionData['QUS_CORRECT_RESPONSE']);
            $array = array();
            $questionData['QUS_CORRECT_RESPONSE'] = $this->objToArray($questionData['QUS_CORRECT_RESPONSE'], $array);
        }
        $viewModel->setVariables([
            'form' => $questionMatchingForm,
            'quizId' => $qusId,
            'getSubUnitTopicDetail' => !empty($getSubUnitTopicDetail) ? $getSubUnitTopicDetail : array(),
            'subId' => !empty($subId) ? $subId : '',
            'questionData' => !empty($questionData) ? $questionData : '',
            'testId' => $testId,
            'getTopicIds' => $getTopicIds,
            'gradeList' => $gradeList,
            'lpId' => $lpId,
            'test_type' => $test_type,
            'edit_from' => $edit_from
        ]);
        return $viewModel;
    }

    /**
     * @desc used of this action to Ordering Question
     */
    public function questionOrderingAction() {
        $this->AssessmentPlugin()->setCustomLayout($this, 'assessmentLayout');
        $viewModel = $this->acceptableviewmodelselector($this->acceptCriteria);
        $serviceManager = $this->getServiceLocator();
        $config = $serviceManager->get('config');
        $translator = $this->getServiceLocator()->get('translator');
        $assessmentTable = $this->initTable('Assessment\Model\QuestionTable');
        
        
        
        $questionTable = $this->initTable('Assessment\Model\QuestionTable');
        
        
        // get grades
        $gradeList = $this->getGrades();
        // get cognitive        
        $getCognitive = $this->getCognitive();
        $getTopicIds = [];
        $questionData = [];
        $questionEssayForm = new QuestionEssayForm($gradeList, $getCognitive, $translator);
        $questionOrderingForm = new QuestionOrderingForm($gradeList, $getCognitive, $translator);
        $qusId = ($this->params('id') !== null) ? $this->params('id') : '';
        $testId = (!empty($this->params()->fromQuery('testId'))) ? $this->params()->fromQuery('testId') : '';
        $lpId = (!empty($this->params()->fromQuery('lpId'))) ? $this->params()->fromQuery('lpId') : '';
        $test_type = (!empty($this->params()->fromQuery('test_type'))) ? $this->params()->fromQuery('test_type') : '';
        $edit_from = (!empty($this->params()->fromQuery('edit_from'))) ? $this->params()->fromQuery('edit_from') : '';
        $resultData = ['form' => $questionOrderingForm, 'quizId' => $qusId, 'testId' => $testId, 'gradeList' => $gradeList, 'lpId' => $lpId,'test_type' => $test_type,'edit_from' => $edit_from];
        if (!empty($qusId)) {
            $conditions = array('QUS_ID' => $qusId);
            $questionData = $questionTable->fetchData('t_master_question', $conditions, array('*'), null, false);
            $questionOrderingDetails = $questionTable->getQuestionDetailById($qusId);
            /* for valid question id */
            if (empty($questionOrderingDetails) || $questionOrderingDetails['QUS_TYPE'] != 7) {
                return $this->redirect()->toRoute('assessment', array('action' => 'list-question'));
            }
            /* for valid question id */
            if ((empty($questionData)) || $questionData['QUS_TYPE'] != 7) {
                    return $this->redirect()->toRoute('assessment', array('action' => 'list-question'));
            }

            /* --- */
            $questionOrderingForm->bind($questionOrderingDetails);
            $condition = ['QUS_ID' => $questionOrderingDetails['QUS_ID']];
            $getTopicIds = $questionTable->fetchData('t_mgr_question_cat', $condition, ['CAT_ID'], '', true);
            /** Get back checked/unchecked HTML to print in edit case only */
            //$catTreeWithHtml = $this->getCheckedTopicsHtml($getTopicIds);
            if (count($getTopicIds)) {
                $tagDetail = $this->getTagDetails($getTopicIds, $questionOrderingForm);
            }
            $questionEssayForm = $questionEssayForm->setData($questionData);
            
            $getSubUnitTopicDetail = isset($tagDetail['getSubUnitTopicDetail']) ? $tagDetail['getSubUnitTopicDetail'] : array();
            $subId = isset($tagDetail['subId']) ? $tagDetail['subId'] : '';
            $resultData['QUS_DATA'] = $questionOrderingDetails;
            $resultData['getSubUnitTopicDetail'] = $getSubUnitTopicDetail;
            $resultData['subId'] = $subId;
            $resultData['questionData'] = !empty($questionData) ? $questionData : '';
            //$resultData['catTreeWithHtml'] = $catTreeWithHtml;
            $resultData['getTopicIds'] = $getTopicIds;
            $resultData['gradeList'] = $gradeList;
            $resultData['lpId'] = $lpId;
        }
        $viewModel->setVariables($resultData);

        return $viewModel;
    }

    /**
     * @desc used of this action to True & False Question
     */
    public function questionTrueFalseAction() {
        $this->AssessmentPlugin()->setCustomLayout($this, 'assessmentLayout');
        $viewModel = $this->acceptableviewmodelselector($this->acceptCriteria);
        $serviceManager = $this->getServiceLocator();
        $config = $serviceManager->get('config');
        $translator = $this->getServiceLocator()->get('translator');
        $assessmentTable = $this->initTable('Assessment\Model\QuestionTable');
        // get grades
        $gradeList = $this->getGrades();
        // get cognitive
        //$getCognitive = $this->getApiCognitive();
        $getCognitive = $this->getCognitive();
        
       
        $getTopicIds = [];
        $questionData = [];
        $questionTrueFalseForm = new QuestionTrueFalseForm($gradeList, $getCognitive, $translator);
        $qusId = ($this->params('id') !== null) ? $this->params('id') : '';
        $testId = (!empty($this->params()->fromQuery('testId'))) ? $this->params()->fromQuery('testId') : '';
        $lpId = (!empty($this->params()->fromQuery('lpId'))) ? $this->params()->fromQuery('lpId') : '';
        $test_type = (!empty($this->params()->fromQuery('test_type'))) ? $this->params()->fromQuery('test_type') : '';
        $edit_from = (!empty($this->params()->fromQuery('edit_from'))) ? $this->params()->fromQuery('edit_from') : '';
        if (!empty($qusId)) {// In Edit case only            
            $conditions = array('QUS_ID' => $qusId);
            $questionData = $assessmentTable->fetchData('t_master_question', $conditions, array('*'), null, false);
            /* for valid question id */
            if ((empty($questionData)) || $questionData['QUS_TYPE'] != 8) {
                return $this->redirect()->toRoute('assessment', array('action' => 'list-question'));
            }
            /* --- */
            $getTopicIds = $assessmentTable->fetchData('t_mgr_question_cat', $conditions, array('CAT_ID'), '', true);
            /** Get back checked/unchecked HTML to print in edit case only */
            //$catTreeWithHtml = $this->getCheckedTopicsHtml($getTopicIds);
            if (count($getTopicIds)) {
                $tagDetail = $this->getTagDetails($getTopicIds, $questionTrueFalseForm);
            }
            $getSubUnitTopicDetail = isset($tagDetail['getSubUnitTopicDetail']) ? $tagDetail['getSubUnitTopicDetail'] : array();
            $subId = !empty($tagDetail['subId']) ? $tagDetail['subId'] : '';
            $questionTrueFalseForm = $questionTrueFalseForm->setData($questionData);
        }
        $viewModel->setVariables([
            'form' => $questionTrueFalseForm,
            'quizId' => $qusId,
            'getSubUnitTopicDetail' => !empty($getSubUnitTopicDetail) ? $getSubUnitTopicDetail : array(),
            'subId' => !empty($subId) ? $subId : '',
            'questionData' => !empty($questionData) ? $questionData : '',
            'testId' => $testId,
            'getTopicIds' => $getTopicIds,
            'gradeList' => $gradeList,
            'lpId' => $lpId,
            'test_type' => $test_type,
            'edit_from' => $edit_from
        ]);
        return $viewModel;
    }

    /**
     * @desc used of this action to Add to bank
     */
//    public function addToBankAction() {
//        $this->AssessmentPlugin()->setCustomLayout($this, 'assessmentLayout');
//        $viewModel = $this->acceptableviewmodelselector($this->acceptCriteria);
//        $questionTable = $this->initTable('Assessment\Model\QuestionTable');
//        $request = $this->getRequest();
//        $getPostData = $request->getPost()->toArray();
//        // get Query string by autocomplete plugin
//        $getRequestData = $request->getQuery()->toArray();
//        $bankId = !empty($getPostData['BANK_ID']) ? $getPostData['BANK_ID'] : (isset($getRequestData['id']) ? $getRequestData['id'] : '');
//        $bankFlag = !empty($getPostData['FLAG']) ? $getPostData['FLAG'] : '';
//        $bankName = !empty($getPostData['BANK_NAME']) ? $getPostData['BANK_NAME'] : (isset($getRequestData['name']) ? $getRequestData['name'] : '');
//        $bankData = $questionTable->fetchData('t_adm_cnf_bank', null, array('*'), 'BANK_ID DESC', true);
//        $result = ['result' => false, 'message' => ''];
//        if ($request->isXmlHttpRequest()) {
//            if (isset($bankFlag) && $bankFlag == 1) {
//                $form = new AddToBankForm();
//                $formFilter = new AddToBankInputFilter();
//                $form->setInputFilter($formFilter->getInputFilter());
//                $form->setData($request->getPost());
//                if ($form->isValid()) {
//                    $viewModel->setTerminal(true);
//                    if (empty($bankId)) {
//                        $isInserted = $questionTable->insertData('t_adm_cnf_bank', ['BANK_NAME' => trim($bankName)]);
//                        if ($isInserted) {
//                            $result = ['result' => true, 'current_path_redirect' => 'Y', 'message' => 'Bank Added Successfully.'];
//                        }
//                    } else {
//                        $isUpdated = $questionTable->updateData('t_adm_cnf_bank', ['BANK_NAME' => $bankName], ['BANK_ID' => $bankId]);
//                        if ($isUpdated) {
//                            $result = ['result' => true, 'current_path_redirect' => 'Y', 'message' => 'Bank Updated Successfully.'];
//                        }
//                    }
//                } else {
//                    $errMsg = $form->getMessages();
//                    $result = ['result' => false, 'message' => $errMsg];
//                }
//            } else {
//                $viewModel->setTerminal(true);
//                if (empty($bankId)) {
//                    $isInserted = $questionTable->insertData('t_adm_cnf_bank', ['BANK_NAME' => trim($bankName)]);
//                    if ($isInserted) {
//                        $result = ['result' => true, 'current_path_redirect' => 'Y', 'message' => 'Bank Added Successfully.'];
//                    }
//                } else {
//                    $isUpdated = $questionTable->updateData('t_adm_cnf_bank', ['BANK_NAME' => $bankName], ['BANK_ID' => $bankId]);
//                    if ($isUpdated) {
//                        $result = ['result' => true, 'current_path_redirect' => 'Y', 'message' => 'Bank Updated Successfully.'];
//                    }
//                }
//            }
//        }
//        $viewModel->setVariables([
//            'data' => $result,
//            'bankData' => $bankData,
//        ]);
//        return $viewModel;
//    }

    /**
     * @Desc used of this action to Add/Update/Display Cognitive
     */
    public function cognitiveAction() {
        $this->AssessmentPlugin()->setCustomLayout($this, 'assessmentLayout');
        $viewModel = $this->acceptableviewmodelselector($this->acceptCriteria);
        $questionTable = $this->initTable('Assessment\Model\QuestionTable');
        $request = $this->getRequest();
        $getPostData = $request->getPost()->toArray();
        $cognitiveId = !empty($getPostData['COGNITIVE_ID']) ? $getPostData['COGNITIVE_ID'] : '';
        $cognitiveName = !empty($getPostData['COGNITIVE_NAME']) ? $getPostData['COGNITIVE_NAME'] : '';
        $cognitiveData = $questionTable->fetchData('t_adm_cnf_cognitive', null, array('*'), 'COGNITIVE_ID DESC', true);
        $result = ['result' => false, 'message' => ''];
        if ($request->isXmlHttpRequest()) {
            $form = new CognitiveForm();
            $formFilter = new CognitiveInputFilter();
            $form->setInputFilter($formFilter->getInputFilter());
            $form->setData($request->getPost());
            if ($form->isValid()) {
                $viewModel->setTerminal(true);
                if (empty($cognitiveId)) {
                    $isInserted = $questionTable->insertData('t_adm_cnf_cognitive', ['COGNITIVE_NAME' => trim($cognitiveName)]);
                    if ($isInserted) {
                        $result = ['result' => true, 'current_path_redirect' => 'Y', 'message' => 'Cognitive Added Successfully.'];
                    }
                } else {
                    $isUpdated = $questionTable->updateData('t_adm_cnf_cognitive', ['COGNITIVE_NAME' => $cognitiveName], ['COGNITIVE_ID' => $cognitiveId]);
                    if ($isUpdated) {
                        $result = ['result' => true, 'current_path_redirect' => 'Y', 'message' => 'Cognitive Updated Successfully.'];
                    }
                }
            } else {
                $errMsg = $form->getMessages();
                $result = ['result' => false, 'message' => $errMsg];
            }
        }
        $viewModel->setVariables([
            'data' => $result,
            'cognitiveData' => $cognitiveData,
        ]);
        return $viewModel;
    }

    /**
     * @Desc To upload temp image
     * @Note    This function being used only for 'Matching' Question Type only. 
     * So don't be confused with upload other files functionality.
     */
    public function uploadImagesAction() {
        $chunkData = $_REQUEST;
        $repos = "";
        $id = $this->params('id');
        if (!empty($id)) {
            $viewHelperManager = $this->getServiceLocator()->get('ViewHelperManager');
            $configF = $viewHelperManager->get('repoConfig');
            $repos = $configF->getQuestionTypeRepo($id);
        }
        $viewModel = $this->acceptableviewmodelselector($this->acceptCriteria);
        $viewModel->setTerminal(true);
        $request = $this->getRequest();
        $postData = $request->getFiles()->toArray();
        $config = $this->getServiceLocator()->get('config');
        $fileName = "";
        $path = isset($postData['file']['name']) ? $postData['file']['name'] : "";
        $postRequest = $request->getPost()->toArray();
        $text = empty($postRequest['text']) ? "" : $postRequest['text'];
        $mathJs = (!empty($postRequest['mathJs']) && $postRequest['mathJs'] == 'true') ? true : false;
        $container = (!empty($postRequest['container']) && $postRequest['container'] == 'Left') ? 'Left' : 'Right';
        $dataType = isset($postRequest['dataType']) ? $postRequest['dataType'] : "";
        $questionType = isset($postRequest['questionType']) ? $postRequest['questionType'] : "";
        $length = $postRequest['length'] + 1;
        $ext = pathinfo($path, PATHINFO_EXTENSION);
        $file = 'file_' . rand() . '_' . time() . '.' . $ext;
        if (!empty($path)) {
            $movefile = move_uploaded_file($postData['file']['tmp_name'], getcwd() . "/public/upload/" . $file);
            if ($movefile) {
                $fileName = $this->returnBasePath() . "/upload/" . $file;
                $dataPath = $this->returnBasePath();
                $filedetails['path'] = $dataPath . '/upload/' . $file;
                $filedetails['type'] = $postData['file']['name'];
            } else {
                $filedetails['path'] = "";
                $filedetails['upload_error'] = "1";
            }
        }
        if ($container == 'Left') {
            $containerSide = array(
                'input' => 'CONTAINER_A_TEXT_INPUT_' . $length,
                'preview' => 'CONTAINER_A_TEXT_PREVIEW_' . $length,
                'buffer' => 'CONTAINER_A_TEXT_BUFER_' . $length
            );
        } else {
            $containerSide = array(
                'input' => 'CONTAINER_B_TEXT_INPUT_' . $length,
                'preview' => 'CONTAINER_B_TEXT_PREVIEW_' . $length,
                'buffer' => 'CONTAINER_B_TEXT_BUFER_' . $length
            );
        }
        if (!empty($path)) {
            $movefile = move_uploaded_file($postData['file']['tmp_name'], getcwd() . "/public/upload/" . $file);
            if ($movefile) {
                $fileName = $this->returnBasePath() . "/upload/" . $file;
                $dataPath = $this->returnBasePath();
                $filedetails['path'] = $dataPath . '/upload/' . $file;
                $filedetails['type'] = $postData['file']['name'];
            } else {
                $filedetails['path'] = "";
                $filedetails['upload_error'] = "1";
            }
        }
        $html = "";
        switch ($questionType) {
            case "matching":
                if (!empty($text) || !empty($fileName)) {
                    if ($dataType == "QUE") {
                        $char = chr(64 + $length);
                    } else {
                        $char = $length;
                    }
                    if ($mathJs) {
                        $chkText = str_replace("<mathJx>", '', $text);
                        $chkText = str_replace("</mathJx>", '', $chkText);
                        if (empty(trim($chkText))) {
                            $html = "";
                            break;
                        }
                    }
                    $html .= '<li class="media">
                         
                           <div class="media-left media-middle">
                                <i class="icon-dots dragula-handle"></i>
                            </div>
                           <div class="media-left media-middle count" >
                                ' . $char . '.                              
                            </div>                            
                         ';
                    if (!empty($fileName)) {
                        $html .= '<div class="media-left">
				 <a href="#"><img src="' . $fileName . '"  class="img-circle" alt=""></a>
		              </div>';
                    }
                    if (!empty($text) && ($mathJs)) {
                        $html .= '<div class="media-body">' .
                                '<div class="media-heading text-semibold">' .
                                '<div id="' . $containerSide['preview'] . '" class="math-jx-preview"></div>
                                <div id="' . $containerSide['buffer'] . '"  visibility:hidden; position:absolute; top:0; left: 0"></div>
                                </div>' .
                                '</div>';
                    }
                    if (!($mathJs)) {
                        $html .= '<div class="media-body">
                              <div class="media-heading text-semibold">' . $text . '</div>
                          </div>';
                    }
                    $html .= '<div class="media-right media-middle">
                                            <ul class="icons-list text-nowrap">
                                                <li>
                                                    <!--<a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="icon-cross3"></i></a>-->
                                                    <ul class="icons-list">
                                                        <li><a data-action="close" class="delete delete-' . $length . '" ></a></li>
                                                    </ul>
                                                </li>
                                            </ul>
                                        </div>';
                    $file = !empty($fileName) ? $file : "";
                    $html .= ' <input id="' . $containerSide['input'] . '" type="hidden" class="' . $dataType . '_TEXT_' . $length . '" name="' . $dataType . '_TEXT[' . $length . ']" value="' . $text . '"> 
                <input type="hidden" class="' . $dataType . '_IMAGE_' . $length . '" name="' . $dataType . '_IMAGE[' . $length . ']" value="' . $file . '">'
                            . '';
                    $html .= '</li>';
                }
                break;
            default:
                if (!empty($text) || !empty($fileName)) {
                    $html = "";
                    if ($mathJs) {
                        $chkText = str_replace("<mathJx>", '', $text);
                        $chkText = str_replace("</mathJx>", '', $chkText);
                        if (empty(trim($chkText))) {
                            $html = "";
                            break;
                        }
                    }
                    $html .= '<li class="media">
			    <div class="media-left media-middle">
			        <i class="icon-dots dragula-handle"></i>
		            </div>';
                    if (!empty($fileName)) {
                        $html .= '<div class="media-left">
				<a href="#"><img src="' . $fileName . '"  class="img-circle" alt=""></a>
		            </div>';
                    }
//                    // if (!empty($text)) {
//                    $html .= '<div class="media-body">
//	                	<div class="media-heading text-semibold">' . $text . '</div>
//		            </div>';
//                    // }
                    if (!empty($text) && ($mathJs)) {
                        $html .= '<div class="media-body">' .
                                '<div class="media-heading text-semibold">' .
                                '<div id="' . $containerSide['preview'] . '" class="math-jx-preview"></div>
                                <div id="' . $containerSide['buffer'] . '"  visibility:hidden; position:absolute; top:0; left: 0"></div>
                                </div>' .
                                '</div>';
                    }
                    if (!($mathJs)) {
                        $html .= '<div class="media-body">
                              <div class="media-heading text-semibold">' . $text . '</div>
                          </div>';
                    }
                    $file = !empty($fileName) ? $file : "";
                    $html .= '<div class="media-right media-middle">
                                            <ul class="icons-list text-nowrap">
                                                <li>
                                                    <!--<a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="icon-cross3"></i></a>-->
                                                    <ul class="icons-list">
                                                        <li><a data-action="close" class="delete delete-' . $length . '" ></a></li>
                                                    </ul>
                                                </li>
                                            </ul>
                                        </div>
                            <input type="hidden" id="' . $containerSide['input'] . '" class="QUES_TEXT_' . $length . '" name="QUS_TEXT[' . $length . ']" value="' . $text . '"> 
                            <input type="hidden" class="QUES_IMAGE_' . $length . '" name="QUS_IMAGE[' . $length . ']" value="' . $file . '">
	                </li>';
                }
        }
        $result = array('html' => $html);
        echo json_encode($result);
        die;
    }

    /**
     * @desc used of this action for save data incase of add/edit
     */
    public function saveQuestionAction() {
        $viewModel = $this->acceptableviewmodelselector($this->acceptCriteria);
        $result = ['result' => false, 'message' => ''];
        $config = $this->getServiceLocator()->get('config');
        $translator = $this->getServiceLocator()->get('translator');
        $questionTable = $this->initTable('Assessment\Model\QuestionTable');
        $request = $this->getRequest();
        $data = $request->getPost()->toArray();
        $jsonDataForOption = '';
        $jsonDataForOptionFileName = '';
        $jsonDataForCorrectResponse = '';
        $errorInValidation = [];
        $errorField = array();
        $emptyMsg = $translator->translate("Value is required and can't be empty");
        $data['INCORRECT_ANS_FEEDBACK'] = isset($data['INCORRECT_ANS_FEEDBACK']) ? $data['INCORRECT_ANS_FEEDBACK'] : "";
        $data['CORRECT_ANS_FEEDBACK']   = isset($data['CORRECT_ANS_FEEDBACK']) ? $data['CORRECT_ANS_FEEDBACK'] : "";
        switch ($data['QUS_TYPE']) {
            case 1: //ESSAY
                $form = new QuestionEssayForm(array(), array(), $translator);
                $formFilter = new EssayInputFilter(array(), array(), $translator);
                break;
            case 2: //FILL_IN_BLANK
                $form = new QuestionFillInTheBlankForm(array(), array(), $translator);
                $formFilter = new FillIntheBlankInputFilter();
                $correctVal = array();
                $errorField = array();
                $index = 0;
                if (!empty($data['CORRECT_ANSWER'])) {
                    foreach ($data['CORRECT_ANSWER'] as $ind => $ansItem) {
                        if (!empty($ansItem)) {
                            $index++;
                            $case = (isset($data['onoffswitch'][$ind]) && $data['onoffswitch'][$ind] == 'on') ? 'Y' : 'N';
                            $optionArr = (!empty($ansItem)) ? explode(',', $ansItem) : array();
                            $refArr = array();
                            for ($j = 0; $j < count($optionArr); $j++) {
                                $refArr['ref' . ($j + 1)] = ['Option' => $optionArr[$j], 'Case' => $case];
                            }
                            $correctVal[$index] = $refArr;
                        } else {
                            $errorField["input_answer"] = array("isEmpty" => $emptyMsg);
                        }
                    }
                }
                if (count($errorField)) {
                    $errorInValidation = $errorField;
                }
                $jsonDataForCorrectResponse = json_encode($correctVal);
                break;
            case 3: //HOTSPOT
                $form = new QuestionHotSpotForm(array(), array(), $translator);
                $formFilter = new HotSpotInputFilter();
                if (!empty($data['top']) && !empty($data['left']) && !empty($data['imagefilename']) && !empty($data['HOTSPOT_TYPE']) && $data['HOTSPOT_TYPE'] == 'IMAGE') {
                    $arr['image'] = array(
                        'pagex' => $data['top'],
                        'pagey' => $data['left'],
                        'height' => $data['height'],
                        'width' => $data['width'],
                    );
                    $jsonDataForCorrectResponse = json_encode($arr);
                    $jsonDataForOption = $data['imagefilename'];
                }
                if (!empty($data['QUESTION_OPT']) && !empty($data['HOTSPOT_TYPE']) && $data['HOTSPOT_TYPE'] == 'TEXT') {
                    $qsn['text'] = $data['QUESTION_OPT'];
                    $jsonDataForOption = json_encode($qsn);
                    $correct['text'] = $data['rightanswer'];
                    $jsonDataForCorrectResponse = stripslashes(json_encode($correct));
                }
                break;
            case 4: //MATCHING
                $data['QUE_TEXT'] = isset($data['QUE_TEXT']) ? (array_combine(range(1, count(array_values($data['QUE_TEXT']))), array_values($data['QUE_TEXT']))) : array();
                $data['QUE_IMAGE'] = isset($data['QUE_IMAGE']) ? (array_combine(range(1, count(array_values($data['QUE_IMAGE']))), array_values($data['QUE_IMAGE']))) : array();
                $data['ANS_TEXT'] = isset($data['ANS_TEXT']) ? (array_combine(range(1, count(array_values($data['ANS_TEXT']))), array_values($data['ANS_TEXT']))) : array();
                $data['ANS_IMAGE'] = isset($data['ANS_IMAGE']) ? (array_combine(range(1, count(array_values($data['ANS_IMAGE']))), array_values($data['ANS_IMAGE']))) : array();
                $arrleng = count($data['QUE_TEXT']);
                if (count($data['QUE_TEXT']) < count($data['ANS_TEXT']))
                    $arrleng = count($data['ANS_TEXT']);
                $listname = array($data['container'][1], $data['container'][2]);
                $listname = array($data['container'][1], $data['container'][2]);
                $listOption = array();
                $columnA = array();
//                $data['QUE_TEXT']=isset($data['QUE_TEXT'])?$data['QUE_TEXT']:array();
                foreach ($data['QUE_TEXT'] as $keyQueText => $valueQueText) {
                    $columnA[$keyQueText] = $data['QUE_TEXT'][$keyQueText] . '###' . $data['QUE_IMAGE'][$keyQueText];
                }
                if (count($columnA) == 0) {
                    $errorField["input_question"] = array("isEmpty" => $emptyMsg);
                }
                $columnB = array();
                foreach ($data['ANS_TEXT'] as $keyQueText => $valueQueText) {
                    $columnB[$keyQueText] = $data['ANS_TEXT'][$keyQueText] . '###' . $data['ANS_IMAGE'][$keyQueText];
                }
                if (count($columnB) == 0) {
                    $errorField["input_answer"] = array("isEmpty" => $emptyMsg);
                }
                if (empty($data['ANSWER_TYPE'])) {
                    $errorField["ANSWER_TYPE_ERROR"] = array("isEmpty" => $emptyMsg);
                }
                $qusCorrectRequest = array();
                $data['answer'] = isset($data['answer']) ? $data['answer'] : array();
                foreach ($data['answer'] as $keyAns => $valueAns) {
                    $keyAnswer = $keyAns;
                    $valueAnswer = $valueAns;
                    $qusCorrectRequest[$keyAns] = array(array($keyAnswer => $columnA[$keyAnswer]), array($valueAnswer => $columnB[$valueAnswer]));
                }
                $data['QUS_CORRECT_RESPONSE'] = $qusCorrectRequest;
                $data['QUS_OPTION'] = array('listname' => $listname, 'list' => array('columnA' => $columnA, 'columnB' => $columnB));
                $jsonDataForOption = json_encode($data['QUS_OPTION']);
                $jsonDataForCorrectResponse = json_encode($data['QUS_CORRECT_RESPONSE']);
                $form = new QuestionMatchingForm(array(), array(), $translator);
                $formFilter = new MatchingInputFilter();
                if (count($errorField)) {
                    $errorInValidation = $errorField;
                }
                break;
            case 5: // MCQ_SINGLE
            case 6: // MCQ_MULTIPLE
                if ($data['QUS_TYPE'] == 5) {
                    $form = new QuestionMultipleAnswerForm(array(), array(), $translator);
                    $formFilter = new MultipleAnswerInputFilter();
                } else {
                    $form = new QuestionMultipleChoiceForm(array(), array(), $translator);
                    $formFilter = new MultipleChoiceInputFilter();
                }
                // QUS_OPTION
                $qusOpt = [];
                foreach ($data['QUS_OPTION'] as $dataK => $dataV) {
                    if (!empty($dataV)) {
                        $qusOpt[$dataK] = str_replace(array('<pre>', '</pre>'), array('', ''), preg_replace('/(<[^>]+) style=".*?"/i', '$1', trim($dataV)));
                    } else {
                        $errorField["QUS_OPTION"] = array("isEmpty" => $translator->translate('Option and value both are required,they can\'t empty'));
                    }
                }
                $jsonDataForOption = json_encode($qusOpt);
                unset($qusOpt);
                // QUS_OPTION_FILE_NAME
                $qusOptFiles = [];
                foreach ($data['QUS_OPTION_FILE_NAME'] as $dataK => $dataV) {
                    if (!empty($dataV)) {
                        $qusOptFiles[$dataK] = trim($dataV);
                    }
                }
                $jsonDataForOptionFileName = json_encode($qusOptFiles);
                unset($qusOptFiles);
                if (isset($data['QUS_CORRECT_RESPONSE']) && !empty($data['QUS_CORRECT_RESPONSE'])) {
                    $qusCorrectResponse = [];
                    // decode option array to get its value
                    $optionArray = json_decode($jsonDataForOption);
                    if (is_array($data['QUS_CORRECT_RESPONSE'])) {
                        foreach ($data['QUS_CORRECT_RESPONSE'] as $dataResK => $dataResV) {
                            if (!empty($optionArray->$dataResK)) {
                                $qusCorrectResponse[$dataResK] = $optionArray->$dataResV;
                            } else {
                                $errorField["QUS_OPTION"] = array("isEmpty" => $translator->translate('Option and value both are required,they can\'t empty'));
                            }
                        }
                    } else {
                        if (!empty($optionArray->$data['QUS_CORRECT_RESPONSE'])) {
                            $qusCorrectResponse[$data['QUS_CORRECT_RESPONSE']] = $optionArray->$data['QUS_CORRECT_RESPONSE'];
                        } else {
                            $errorField["QUS_OPTION"] = array("isEmpty" => $translator->translate('Option and value both are required,they can\'t empty'));
                        }
                    }
                    $jsonDataForCorrectResponse = json_encode($qusCorrectResponse);
                    unset($qusCorrectResponse);
                } else {
                    $errorField["QUS_OPTION"] = array("isEmpty" => $translator->translate('Option and value both are required,they can\'t empty'));
                }
                if (count($errorField)) {
                    $errorInValidation = $errorField;
                }
                break;
            case 7: //ORDERING
                $form = new QuestionOrderingForm(array(), array(), $translator);
                $formFilter = new OrderingInputFilter();
                $errorValidation = array();
                $errorField = array();
                $QUS_OPTIONS = [];
                $QUS_CORRECT_RESPONSE = [];
                if (!empty($data['QUS_TEXT'])) {
                    $index = 0;
                    foreach ($data['QUS_TEXT'] as $optKey => $optVal) {
                        $index++;
                        $img = (!empty($data['QUS_IMAGE'][$optKey])) ? ('###' . $data['QUS_IMAGE'][$optKey] . '### ') : '';
                        $QUS_OPTIONS[$optKey + 1] = $img . $optVal;
                    }
                } else {// Validation For INPUT QUESTIONS Ordering
                    $errorField["input_question"] = array("isEmpty" => $emptyMsg);
                }
                if (!empty($data['ANS_TEXT'])) {
                    $index = 0;
                    foreach ($data['ANS_TEXT'] as $optKey => $optVal) {
                        $index++;
                        $img = (!empty($data['ANS_IMAGE'][$optKey])) ? ('###' . $data['ANS_IMAGE'][$optKey] . '### ') : '';
                        $QUS_CORRECT_RESPONSE[$optKey + 1] = $img . $optVal;
                    }
                } else {// Validation For INPUT ANSWER Ordering
                    $errorField["input_answer"] = array("isEmpty" => $emptyMsg);
                }
                if (count($errorField)) {
                    $errorInValidation = $errorField;
                }
                $jsonDataForOption = json_encode($QUS_OPTIONS);
                $jsonDataForCorrectResponse = json_encode($QUS_CORRECT_RESPONSE);
                break;
            case 8: //TRUE_FALSE
                $form = new QuestionTrueFalseForm(array(), array(), $translator);
                $formFilter = new TrueFalseInputFilter();
                $dataReady = [];
                $qusOpt = [];
                // Sub-Question's Json encoded files               
                foreach ($data['QUS_OPTION_FILE_NAME'] as $dataK => $dataV) {
                    $qusOpt[$dataK] = trim($dataV);
                }
                $jsonDataForOptionFileName = json_encode($qusOpt);
                unset($qusOpt);
                // Sub-Questions & synoname Json formatted data
                if (isset($data['synoname'])) {
                    if (!empty($data['synoname'])) {
                        foreach ($data['synoname'] as $dataK => $dataV) {
                            $qusOpt[$dataK] = trim($dataV);
                        }
                        $dataReady['synoname'] = $qusOpt;
                        unset($qusOpt);
                    }
                }
                // sub_question is a checkbox element which show & hides subquestion's element set
                if (!empty($data['sub_question']) && $data['sub_question'] == 'on') {
                    // sub-question texarea's Json data for QUS_OPTION column
                    if (isset($data['QUS_OPTION']) && !empty($data['QUS_OPTION']) && count($data['QUS_OPTION']) >= 1) {
                        foreach ($data['QUS_OPTION'] as $dataK => $dataV) {
                            if (!empty($dataV)) {
                                $qusOpt[$dataK] = trim($dataV);
                            } else {
                                $errorField["QUS_OPTION[$dataK]"] = array("isEmpty" => $translator->translate('Sub question can\'t be empty'));
                            }
                        }
                        $dataReady['subquestion'] = !empty($qusOpt) ? $qusOpt : '';
                        $jsonDataForOption = json_encode($dataReady);
                        unset($dataReady);
                        unset($qusOpt);
                    } else {
                        $errorField["QUS_OPTION"] = array("isEmpty" => $translator->translate('Option and value both are required,they can\'t empty'));
                    }
                    // Arrange Json Data for QUS_CORRECT_RESPONSE ( QUS_OPTION_ANSWER : True False radio buttons) with sub-question
                    if (isset($data['QUS_OPTION_ANSWER']) && isset($data['QUS_OPTION'])) {
                        $optionArray = (!empty($data['QUS_OPTION']) && count($data['QUS_OPTION']) >= 1) ? $data['QUS_OPTION'] : array();
//                        if ($optionArray) {
                        $optionAnswerArray = (!empty($data['QUS_OPTION_ANSWER'])) ? $data['QUS_OPTION_ANSWER'] : array();
                        //} 
                        for ($j = 0; $j < count($optionArray); $j++) {
                            if (!empty($optionArray[$j + 1]) && isset($optionArray[$j + 1])) {
                                if (!empty($optionAnswerArray[$j + 1])) {
                                    $qusOpt[($j + 1)] = ['Question' => $optionArray[$j + 1], 'Answer' => $optionAnswerArray[$j + 1]];
                                } else {
                                    $ind = $j + 1;
                                    $errorField["QUS_OPTION_ANSWER[$ind]"] = array("isEmpty" => $translator->translate('Synonyms value can\'t empty'));
                                }
                            }
                        }
                        if (isset($qusOpt)) {
                            $jsonDataForCorrectResponse = json_encode($qusOpt);
                            unset($qusOpt);
                        }
                    } else {
                        $errorField["QUS_OPTION_ANSWER[1]"] = array("isEmpty" => $translator->translate('Synonyms value can\'t empty'));
                    }
                } else {// when sub-question button is unchecked
//                    if (!empty($data['QUESTION_TEXT'])) {
//                        $qusOpt[1] = trim($data['QUESTION_TEXT']);
//                        $dataReady['subquestion'] = $qusOpt;
                    $jsonDataForOption = json_encode($dataReady);
//                        unset($qusOpt);
//                        unset($dataReady);
//                    }
                    // Arrange Json Data for QUS_CORRECT_RESPONSE with Main Question Only
                    if (isset($data['QUS_MAIN_ANSWER'])) {
                        $optionArray = !empty($data['QUESTION_TEXT']) ? $data['QUESTION_TEXT'] : array();
                        if (count($optionArray)) {
                            $optionAnswerArray = (!empty($data['QUS_MAIN_ANSWER'])) ? $data['QUS_MAIN_ANSWER'] : array();
                        }
                        $qusOpt[1] = ['Question' => $optionArray, 'Answer' => $optionAnswerArray[1]];
                        $jsonDataForCorrectResponse = json_encode($qusOpt);
                        unset($optionArray);
                        unset($optionAnswerArray);
                        unset($qusOpt);
                    } else {
                        $errorField["QUS_MAIN_ANSWER[1]"] = array("isEmpty" => $translator->translate('Value is required and can\'t be empty'));
                    }
                }
                if (count($errorField)) {
                    $errorInValidation = $errorField;
                }
                break;
            case 9: //JUMBLE_WORD
                $form = '';
                $formFilter = '';
                break;
            case 10: //PICK_FROM_LIST
                $form = new QuestionPickFromListForm(array(), array(), $translator);
                $formFilter = new PickFromListInputFilter();
                $QUS_OPTIONS = [];
                $QUS_CORRECT_RESPONSE = [];
                if (!empty($data['QUS_OPTION']) && (!empty($data['QUS_CORRECT_RESPONSE']) && (!empty($data['QUS_OPTION'][$data['QUS_CORRECT_RESPONSE']])))) {
                    foreach ($data['QUS_OPTION'] as $optionKey => $optVal) {
                        $QUS_OPTIONS[$optionKey] = $optVal;
                        if (!empty($data['QUS_CORRECT_RESPONSE']) && $optionKey == $data['QUS_CORRECT_RESPONSE']) {
                            $QUS_CORRECT_RESPONSE[$optionKey] = $optVal;
                        }
                    }
                } else {// Validation For INPUT ANSWER Ordering
                    $errorInValidation["input_validation"] = array("isEmpty" => $translator->translate('Option and ') . ' ' . $emptyMsg);
                }
                $jsonDataForOption = json_encode($QUS_OPTIONS);
                $jsonDataForCorrectResponse = json_encode($QUS_CORRECT_RESPONSE);
                break;
            case 11: //drag drop
                $form = new QuestionDragDropForm(array(), array(), $translator);
                $formFilter = new DragDropInputFilter();
                $qusOption = [];
                $qusCorrectAnsResp = [];
                if (isset($data['option']) && count($data['option'])) {
                    $index = 0;
                    foreach ($data['option'] as $optKey => $optVal) {
                        $index++;
                        if (!empty($optVal['optionFile']) && !empty($optVal['optionText'])) {
                            $qusOption[$index] = $optVal['optionText'] . '  ' . '###' . $optVal['optionFile'] . '###';
                        } else if (!empty($optVal['optionText']) && empty($optVal['optionFile'])) {
                            $qusOption[$index] = $optVal['optionText'];
                        } else if (empty($optVal['optionText']) && !empty($optVal['optionFile'])) {
                            $qusOption[$index] = '###' . $optVal['optionFile'] . '###';
                        }
                        if (!empty($optVal['correct']) && $optVal['correct'] == 'on') {
                            $qusCorrectAnsResp[$index] = $optVal['optionText'];
                        }
                    }
                }
                $jsonDataForOption = json_encode($qusOption);
                $jsonDataForCorrectResponse = json_encode($qusCorrectAnsResp);
                if (count($qusCorrectAnsResp) != $data['ANSWER_LENGHT']) {
                    $mess = Array('ANSWER_LENGHT' => Array('isEmpty' => $translator->translate('No of container always equal to no of correct options')));
//                    $result = ['result' => false, 'message' => $mess];
//                    $viewModel->setVariables(['data' => $result]);
//                    return $viewModel;
                }
                if (count($qusOption) == $data['ANSWER_LENGHT']) {
                    $mess = Array('ANSWER_LENGHT' => Array('isEmpty' => $translator->translate('No of container always less then to no of options')));
//                    $result = ['result' => false, 'message' => $mess];
//                    $viewModel->setVariables(['data' => $result]);
//                    return $viewModel;
                }
                if (!empty($mess) && count($mess)) {
                    $errorInValidation = (count($errorInValidation)) ? array_merge($errorInValidation, $mess) : $mess;
                    unset($mess);
                }
                break;
            default:
                $form = '';
                $formFilter = '';
                break;
        }
        if ($request->isXmlHttpRequest()) {
            $errorFieldSubject = [];
            $data['topic'] = isset($data['topic']) ? $data['topic'] : array();
            $data['topic'] = array_unique($data['topic']);
            if (!count($data['topic'])) {
                $errorFieldSubject["TOPIC_TYPE"] = array("isEmpty" => $translator->translate("Value is required and can't be empty"));
            }
            if (count($errorFieldSubject)) {
                $errorInValidation = (count($errorInValidation)) ? array_merge($errorInValidation, $errorFieldSubject) : $errorFieldSubject;
                unset($errorFieldSubject);
            }
            // Custom validation message for hotspot type		 
            if (!empty($data['HOTSPOT_TYPE'])) {
                $err = "";
                if ($data['HOTSPOT_TYPE'] == 'IMAGE') {
                    if (empty($data['top'])) {
                        $err = "Invalid image hotspot";
                    }
                } else if ($data['HOTSPOT_TYPE'] == 'TEXT') {
                    if (empty($data['rightanswer'])) {
                        $err = "Invalid text hotspot";
                    }
                }
                if ($err != "") {
                    $errorFieldHotspot['input_hotspot_valid'] = array("isEmpty" => $translator->translate($err));
                    if (count($errorFieldHotspot)) {
                        $errorInValidation = (count($errorInValidation)) ? array_merge($errorInValidation, $errorFieldHotspot) : $errorFieldHotspot;
                        unset($errorFieldHotspot);
                    }
                }
            }
            $form->setInputFilter($formFilter->getInputFilter());
            if (isset($data['QUESTION_FILE_NAME']) && $data['QUESTION_FILE_NAME'] != null) {
                $formFilter->getInputFilter()->get('QUESTION_TEXT')->setRequired(false);
            }
            $form->setData($request->getPost());
            if ($form->isValid() && !count($errorInValidation)) {
                $nextId = $questionTable->getId();
                $string = strtoupper(Rand::getString(8, 'abcdefghijklmnopqrstuvwxyz', true));
                $QUK = substr($string . $nextId, -8);
                if ($data['QUS_ID']) { // if request comes for edit record
                    $dataToBeSave = [
                        'QUS_ID' => $data['QUS_ID'],
                        'QUESTION_NAME' => $data['QUESTION_NAME'],
                        'QUESTION_TEXT' => isset($data['QUESTION_TEXT']) ? trim($data['QUESTION_TEXT']) : '',
                        'ANSWER_EXPLANATION' => isset($data['ANSWER_EXPLANATION']) ? trim($data['ANSWER_EXPLANATION']) : '',
                        'DIFFICULTY' => $data['DIFFICULTY'],
                        'INCORRECT_ANS_FEEDBACK' => $data['INCORRECT_ANS_FEEDBACK'],
                        'CORRECT_ANS_FEEDBACK' => $data['CORRECT_ANS_FEEDBACK'],
                        'RESPONSE_FORMAT' => isset($data['RESPONSE_FORMAT']) ? $data['RESPONSE_FORMAT'] : '',
                        'ANSWER_LENGHT' => isset($data['ANSWER_LENGHT']) ? $data['ANSWER_LENGHT'] : '',
                        'QUS_OPTION' => $jsonDataForOption,
                        'QUS_OPTION_FILE_NAME' => $jsonDataForOptionFileName,
                        'QUS_CORRECT_RESPONSE' => $jsonDataForCorrectResponse,
                        'ANSWER_TYPE' => isset($data['ANSWER_TYPE']) ? $data['ANSWER_TYPE'] : '',
                        'LAST_UPDATED_ON' => date('Y-m-d H:i:s'),
                        'COGNITIVE_ID' => $data['COGNITIVE_ID'],
                        'QUES_MARK' => $data['QUES_MARK']
                    ];
                    if (!empty($data['QUESTION_FILE_NAME'])) {
                        $dataToBeSave['QUESTION_FILE_NAME'] = $data['QUESTION_FILE_NAME'];
                    }
                } else { // if request comes for add record
                    $dataToBeSave = [
                        'QUS_ID' => '',
                        'QUK' => $QUK,
                        'QUS_TYPE' => $data['QUS_TYPE'],
                        'QUESTION_NAME' => $data['QUESTION_NAME'],
                        'QUESTION_TEXT' => isset($data['QUESTION_TEXT']) ? trim($data['QUESTION_TEXT']) : '',
                        'ANSWER_EXPLANATION' => isset($data['ANSWER_EXPLANATION']) ? trim($data['ANSWER_EXPLANATION']) : '',
                        'DIFFICULTY' => $data['DIFFICULTY'],
                        'INCORRECT_ANS_FEEDBACK' => $data['INCORRECT_ANS_FEEDBACK'],
                        'CORRECT_ANS_FEEDBACK' => $data['CORRECT_ANS_FEEDBACK'],
                        'RESPONSE_FORMAT' => isset($data['RESPONSE_FORMAT']) ? $data['RESPONSE_FORMAT'] : '',
                        'ANSWER_LENGHT' => isset($data['ANSWER_LENGHT']) ? $data['ANSWER_LENGHT'] : '',
                        'QUESTION_FILE_NAME' => isset($data['QUESTION_FILE_NAME']) ? $data['QUESTION_FILE_NAME'] : '',
                        'QUS_OPTION' => $jsonDataForOption,
                        'QUS_OPTION_FILE_NAME' => $jsonDataForOptionFileName,
                        'QUS_CORRECT_RESPONSE' => $jsonDataForCorrectResponse,
                        'ANSWER_TYPE' => isset($data['ANSWER_TYPE']) ? $data['ANSWER_TYPE'] : '',
                        'QUES_STATUS' => 'A',
                        'CREATED_BY' => $this->authContainer->authDetail['USER_OID'],
                        'COGNITIVE_ID' => $data['COGNITIVE_ID'],
                        'QUES_MARK' => $data['QUES_MARK']
                    ];
                }
                $quesId = $questionTable->addEditQuestion($dataToBeSave);
//                if ($quesId) {
//                    $questionTable->deleteData('t_mgr_question_bank', ['QUS_ID' => $quesId]);
//                    if (!empty($data['BANK_IDS']) && count($data['BANK_IDS']) > 0) {
//                        foreach ($data['BANK_IDS'] as $bankid) {
//                            $dataBank = [
//                                'QUS_ID' => $quesId,
//                                'BANK_ID' => $bankid,
//                            ];
//                            $questionTable->insertData('t_mgr_question_bank', $dataBank);
//                        }
//                    }
//                }
                // Upload on S3 if aws is enable(Send file to S3)
                $viewHelperManager = $this->getServiceLocator()->get('ViewHelperManager');
                $ConfigHelper = $viewHelperManager->get('repoconfig');
                if ($config['AWS_ENABLE']) {
                    if (!empty($data['QUESTION_FILE_NAME'])) {
                        $this->uploadS3File($dataToBeSave['QUESTION_FILE_NAME'], $ConfigHelper->getQuestionTypeRepo($data['QUS_TYPE']));
                    }
                    // drag and drop files
                    if (isset($data['option']) && count($data['option'])) {
                        $index = 0;
                        foreach ($data['option'] as $optKey => $optVal) {
                            $index++;
                            if (!empty($optVal['optionFile'])) {
                                $this->uploadS3File($optVal['optionFile'], $ConfigHelper->getQuestionTypeRepo($data['QUS_TYPE']));
                            }
                        }
                    }
                    if (!empty($data['QUS_OPTION_FILE_NAME'])) {
                        foreach ($data['QUS_OPTION_FILE_NAME'] as $val) {
                            if (!empty($val)) {
                                $this->uploadS3File($val, $ConfigHelper->getQuestionTypeRepo($data['QUS_TYPE']));
                            }
                        }
                    }
                    if (!empty($data['QUS_IMAGE'])) {
                        foreach ($data['QUS_IMAGE'] as $val) {
                            if (!empty($val)) {
                                $this->uploadS3File($val, $ConfigHelper->getQuestionTypeRepo($data['QUS_TYPE']));
                            }
                        }
                    }
                    if (!empty($data['QUE_IMAGE'])) {
                        foreach ($data['QUE_IMAGE'] as $val) {
                            if (!empty($val)) {
                                $this->uploadS3File($val, $ConfigHelper->getQuestionTypeRepo($data['QUS_TYPE']));
                            }
                        }
                    }
                    if (!empty($data['ANS_IMAGE'])) {
                        foreach ($data['ANS_IMAGE'] as $val) {
                            if (!empty($val)) {
                                $this->uploadS3File($val, $ConfigHelper->getQuestionTypeRepo($data['QUS_TYPE']));
                            }
                        }
                    }
                    if (!empty($data['imagefilename']) && !empty($data['imagefilename']) && $data['newupload'] == 'Yes') {
                        $this->uploadS3File($data['imagefilename'], $ConfigHelper->getQuestionTypeRepo($data['QUS_TYPE']));
                    }
                    if (isset($data['QUS_OPTION']) && !empty($data['QUS_OPTION'])) {
                        if (!empty($data['QUS_OPTION']['list']['columnA'])) {
                            foreach ($data['QUS_OPTION']['list']['columnA'] as $dataA) {
                                $exDataA = explode('$$', $dataA);
                                if (!empty($exDataA[1])) {
                                    $this->uploadS3File($exDataA[1], $ConfigHelper->getQuestionTypeRepo($data['QUS_TYPE']));
                                }
                            }
                        }
                        if (!empty($data['QUS_OPTION']['list']['columnB'])) {
                            foreach ($data['QUS_OPTION']['list']['columnB'] as $dataB) {
                                $exDataB = explode('$$', $dataB);
                                if (!empty($exDataB[1])) {
                                    $this->uploadS3File($exDataB[1], $ConfigHelper->getQuestionTypeRepo($data['QUS_TYPE']));
                                }
                            }
                        }
                    }
                }
                // First of all Here we are deleting all topics linked with this question
                if (!empty($data['QUS_ID'])) {
                    $questionTable->deleteData('t_mgr_question_cat', array('QUS_ID' => $data['QUS_ID']));
                }
                // Here we are doing fresh enteries for topics
                if (!empty($quesId) || !empty($data['QUS_ID'])) {
                    if (!empty(array_unique($data['topic']))) {
                        $i = 1;
                        foreach (array_unique($data['topic']) as $value) {
                            $saveLOData = array();
                            $saveLOData['QUS_ID'] = !empty($data['QUS_ID']) ? $data['QUS_ID'] : $quesId;
                            $saveLOData['CAT_ID'] = $value;
                            if (!empty($value)) {
                                $questionTable->insertData('t_mgr_question_cat', $saveLOData);
                            }
                            $i++;
                        }
                    }
                }
                // this case will use in case while user comes for create question from quiz listing only
                if (isset($data['testId']) && !empty($data['testId'])) {
                    // new question was inserted in 't_master_question' table now linked this ques with quiz
                    $createQuizTable = $this->initTable('Assessment\Model\CreateQuizTable');
                    $res = $createQuizTable->checkQusExist($quesId, $data['testId']);
                    if (empty($res)) {
                        $insertData = ['QUS_ID' => $quesId, 'QUZ_ID' => $data['testId']];
                        $createQuizTable->insertDataQuizQus($insertData);
                    }
                }
                $redirectUrl = $this->returnBasePath() . '/assessment/list-question';
                if (!empty($data['testId'])) {
                    $insertData = ['QUS_ID' => $quesId, 'QUZ_ID' => $data['testId']];
                    $questionTable->insertData('t_mgr_test_question',$insertData);
                        
                    $isAPI = $this->container->authDetail['TEST_ENABLE'];
                    $lpId = $data['lpId'];
                    $test_type = !empty($data['test_type'])? $data['test_type'] : '';
                    $edit_from = !empty($data['edit_from'])? $data['edit_from'] : '';
                    if ($lpId) {
                        $str = '&lpId=' . $lpId;
                    } else {
                        $str = '';
                    }
                    
                    if($edit_from){
                        $edit_from = '&edit_from='.$edit_from;
                    }
                    
                    if($test_type){
                        $test_type = '&test_type='.$test_type;
                    }
                    
                    if ($isAPI == 'Y') {
                        $redirectUrl = $this->returnBasePath() . '/test/edit/' . $data['testId'] . '/2?lastQusId=' . $quesId . $str . $test_type . $edit_from;
                    } else {
                        $redirectUrl = $this->returnBasePath() . '/assessment/add/' . $data['testId'] . '/2' . "?lastQusId=" . $quesId . $str . $test_type . $edit_from;
                    }
                }
                $result = ['result' => true, 'redirectUrl' => $redirectUrl];
            } else {
                $validationMsg = $form->getMessages();
                $errMsg = (count($errorInValidation)) ? array_merge($errorInValidation, $validationMsg) : $validationMsg;
                $activeTab = '';
                if (array_key_exists('CORRECT_ANS_FEEDBACK', $validationMsg) || array_key_exists('INCORRECT_ANS_FEEDBACK', $validationMsg)) {
                    if (array_key_exists('CORRECT_ANS_FEEDBACK', $validationMsg)) {
                        $activeTab = '#bottom-divided-tab1';
                    } else {
                        $activeTab = '#bottom-divided-tab2';
                    }
                }
                $result = ['result' => false, 'message' => $errMsg, 'activeTab' => $activeTab];
            }
        }
        $viewModel->setVariables(['data' => $result]);
        return $viewModel;
    }

    /**
     * @desc used of this function for delete question bank
     * @return json message
     */
    public function questionDeleteDataAction() {
        $request = $this->getRequest();
        $viewHelperManager = $this->getServiceLocator()->get('ViewHelperManager');
        $ConfigHelper = $viewHelperManager->get('Repoconfig');
        if ($request->isXmlHttpRequest()) {
            $viewModel = $this->acceptableviewmodelselector($this->acceptCriteria);
            $viewModel->setTerminal(true);
            $requestData = $request->getQuery()->toArray();
            $QUS_ID = $requestData['ID'];
            $QUS_TYPE = !empty($requestData['QUS_TYPE']) ? $requestData['QUS_TYPE'] : '';
            $deleteAction = $requestData['deleteAction'];
            $questionTable = $this->initTable('Assessment\Model\QuestionTable');
            if ($deleteAction == 'delete_question') {
                /* Remove linked files from s3 */
                $qus_data = $questionTable->fetchData('t_master_question', ['QUS_ID' => $QUS_ID], ['QUESTION_FILE_NAME'], null, false);
                $key = $ConfigHelper->getQuestionTypeRepo($QUS_TYPE) . $qus_data->QUESTION_FILE_NAME;
                $this->removeS3File($key);
                $isDeleted = $questionTable->deleteQues($QUS_ID);
                $success = 1;
            }
            if ($deleteAction == 'delete_congintive') {
                $isDeleted = $questionTable->deleteData('t_adm_cnf_cognitive', ['COGNITIVE_ID' => $QUS_ID]);
                $success = ($isDeleted) ? 1 : 0;
            }
//            if ($deleteAction == 'delete_bank') {
//                $isDeleted = $questionTable->deleteData('t_adm_cnf_bank', ['BANK_ID' => $QUS_ID]);
//                $success = 1;
//            }
            if ($deleteAction == 'delete_content') {
                /** means request come to delete ques text audio/video file */
                if (empty($requestData['QUS_OPTION_FILE_NAME'])) {
                    $qus_data = $questionTable->fetchData('t_master_question', ['QUS_ID' => $QUS_ID], ['QUESTION_FILE_NAME'], null, false);
                    $key = $ConfigHelper->getQuestionTypeRepo($QUS_TYPE) . $qus_data->QUESTION_FILE_NAME;
                    $data = [
                        'QUESTION_FILE_NAME' => 'NULL'
                    ];
                    $this->removeS3File($key);
                    /** means request come to delete ques options audio/video file */
                } else {
                    $qus_data = $questionTable->fetchData('t_master_question', ['QUS_ID' => $QUS_ID], ['QUS_OPTION_FILE_NAME'], null, true);
                    $jsonArrayForOptionFiles = json_decode($qus_data[0]['QUS_OPTION_FILE_NAME']);
                    $key = $ConfigHelper->getQuestionTypeRepo($QUS_TYPE) . $jsonArrayForOptionFiles->$requestData['OPTION_FILE_KEY'];
                    unset($jsonArrayForOptionFiles->$requestData['OPTION_FILE_KEY']);
                    $this->removeS3File($key);
                    $data = [
                        'QUS_OPTION_FILE_NAME' => json_encode($jsonArrayForOptionFiles)
                    ];
                }
                $conditions = ['QUS_ID' => $QUS_ID];
                $questionTable->updateData('t_master_question', $data, $conditions);
                unset($qus_data);
                unset($key);
                $success = 1;
            }
            if ($deleteAction == 'delete_drag_drop_file') {
                $qus_option = $requestData['qus_options'];
                $deletefileoption = $requestData['fileoptions'];
                $qusOption = [];
                $index = 0;
                foreach ($qus_option as $key => $option) {
                    $textoption = explode('  ', $option);
                    $filename = '';
                    if (!empty($textoption[1])) {
                        $fileoption = explode('###', $textoption[1]);
                        $filename = $fileoption[1];
                    }
                    if ($deletefileoption == $filename) {
                        $filename = '';
                    }
                    if (!empty($filename)) {
                        $qusOption[$index] = $textoption[0] . '  ' . '###' . $filename . '###';
                    } else {
                        $qusOption[$index] = $textoption[0];
                    }
                    $index++;
                }
                $jsonDataForOption = json_encode($qusOption);
                $key = $ConfigHelper->getQuestionTypeRepo($QUS_TYPE) . $deletefileoption;
                unset($deletefileoption);
                $this->removeS3File($key);
                $data = [
                    'QUS_OPTION' => $jsonDataForOption
                ];
                $conditions = ['QUS_ID' => $QUS_ID];
                $questionTable->updateData('t_master_question', $data, $conditions);
                $success = 1;
            }
            $jsonModel = new JsonModel();
            $jsonModel->setVariables(array(
                'result' => $success
            ));
            return $jsonModel;
        }
    }

    /*
     * @upload Courses on cloud search
     */

    function deleteQuestionAction() {
        $request = $this->getRequest();
        $postData = $request->getPost()->toArray();
        $viewModel = $this->acceptableviewmodelselector($this->acceptCriteria);
        $questionTable = $this->initTable('Assessment\Model\QuestionTable');
        if ($request->isXmlHttpRequest()) {
            $viewModel->setTerminal(true);
            $qusId = $postData['quesIds'];
            $questionData = $questionTable->getQuestionsByIds($qusId);
            foreach ($questionData as $quesId) {
                $result = $questionTable->deleteQues($quesId['QUS_ID']);
            }
            if ($result == '1') {
                $success = true;
                $msg = 'Selected Questions have been deleted successfully';
            } else {
                $success = false;
                $msg = "Something happen wrong!";
            }
            //return msg
            $jsonModel = new JsonModel();
            $jsonModel->setVariables(array(
                'result' => $success,
                'msg' => $msg
            ));
            return $jsonModel;
        }
    }

    /**
     * @desc used of this function for open popup
     * @return render page
     */
    public function popupConfirmAction() {
        $viewModel = $this->acceptableviewmodelselector($this->acceptCriteria);
        $viewModel->setTerminal(true)->setTemplate("assessment/index/popup_delete_confirmation.phtml");
        $viewModel->setVariables(array(
            'result' => 'questionids',
        ));
        return $viewModel;
    }

    private function getQustionTypeUrlByTypeId($qusTypeId) {
        if ($qusTypeId > 0) {
            $config = $this->getServiceLocator()->get('Config');
            return $config['QUES_TYPE_URL'][$qusTypeId];
        } else {
            return '';
        }
    }

    public function questionOpenPopupAction() {
        $viewModel = $this->acceptableviewmodelselector($this->acceptCriteria);
        $requestData = $this->getRequest()->getQuery()->toArray();
        $viewModel = $this->AssessmentPlugin()->openPopUp($viewModel, $requestData, 'questions');
        $fileName = $requestData['file'];
        $list_from = isset($requestData['listFrom']) || !empty($requestData['listFrom']) ? $requestData['listFrom'] : 'LOCAL';
        
        $questionCCOTaggingData = [];        
        if ($list_from == 'API') { // if ques preview for Api question
			if(!empty($requestData['id'])){
				$id = $requestData['id'];
				$taggedQuesTopics = $this->AssessmentPlugin()->getQuesTopicsFromAssess($id);
				$questionCCOTaggingData = $this->AssessmentPlugin()->getStandardHeirarchyFromCCO($taggedQuesTopics); 
			}
			
        }
        switch ($fileName) {
            case "preview-question-essay"://QUS_TYPE = 1
                $id = $requestData['id'];
                /** get question detail to pre populate on preview page by getting data conditionally from local or from API. */
                if ($list_from == 'API') {
                    $questionData = $this->AssessmentPlugin()->getQuestionByIds($id);                    
                } else {
                    $questionTable = $this->initTable('Assessment\Model\QuestionTable');
                    $conditions = array('QUS_ID' => $id);
                    $questionData = $questionTable->fetchData('t_master_question', $conditions, array('*'), '', false);
                }
                $viewModel->setVariables(array(
                    'questionCCOTaggingData' => $questionCCOTaggingData,
                    'result' => $questionData
                ));
                $templateUrl = 'assessment/index/preview/' . $this->getQustionTypeUrlByTypeId($questionData['QUS_TYPE']) . '.phtml';
                $viewModel->setTemplate($templateUrl);
                break;

            case "preview-question-fill-in-the-blank"://QUS_TYPE = 2
                $qusId = $requestData['id'];
                if ($list_from == 'API') {
                    $questionData = $this->AssessmentPlugin()->getQuestionByIds($qusId);
                } else {
                    $questionTable = $this->initTable('Assessment\Model\QuestionTable');
                    $conditions = array('QUS_ID' => $qusId);
                    $questionData = $questionTable->fetchData('t_master_question', $conditions, array('*'), null, false);
                }
                if (!empty($questionData['QUS_OPTION'])) {
                    $questionOptionArr = json_decode($questionData['QUS_OPTION'], TRUE);
                }
                if (!empty($questionData['QUS_CORRECT_RESPONSE'])) {
                    $questionCorrectArr = json_decode(!empty($questionData['QUS_CORRECT_RESPONSE']), TRUE);
                }
                $viewModel->setVariables(array(
                    'questionCCOTaggingData' => $questionCCOTaggingData,
                    'questionData' => $questionData,
                    'questionText' => $questionData['QUESTION_TEXT']
                ));
                $templateUrl = 'assessment/index/preview/' . $this->getQustionTypeUrlByTypeId($questionData['QUS_TYPE']) . '.phtml';
                $viewModel->setTemplate($templateUrl);
                break;

            case "preview-question-hotspot"://QUS_TYPE = 3
                $qusId = $requestData['id'];
                if ($list_from == 'API') {
                    $questionData = $this->AssessmentPlugin()->getQuestionByIds($qusId);
                } else {
                    $questionTable = $this->initTable('Assessment\Model\QuestionTable');
                    $conditions = array('QUS_ID' => $qusId);
                    $questionData = $questionTable->fetchData('t_master_question', $conditions, array('*'), null, false);
                }

                if (!empty($questionData['QUS_CORRECT_RESPONSE'])) {
                    $questionCorrectArr = !empty($questionData['QUS_CORRECT_RESPONSE']) ? json_decode($questionData['QUS_CORRECT_RESPONSE'], true) : '';
                }
                $questionOption = $imagePath = "";
                if (!empty($questionCorrectArr['text'])) {
                    $questionType = "Text";
                    $questionOption = $questionCorrectArr['text'];
                } else {
                    $questionType = "Image";
                    $imagePath = $questionData['QUS_OPTION'];
                }
                $viewModel->setVariables(array(
                    'questionCCOTaggingData' => $questionCCOTaggingData,
                    'questionType' => $questionType,
                    'imagePath' => $imagePath,
                    'questionOption' => $questionOption,
                    'questionText' => $questionData['QUESTION_TEXT'],
                    'questionData' => $questionData
                ));
                $templateUrl = 'assessment/index/preview/' . $this->getQustionTypeUrlByTypeId($questionData['QUS_TYPE']) . '.phtml';
                $viewModel->setTemplate($templateUrl);
                break;

            case "preview-question-matching"://QUS_TYPE = 4
                $id = $requestData['id'];
                if ($list_from == 'API') {
                    $questionData = $this->AssessmentPlugin()->getQuestionByIds($id);
                } else {
                    $questionTable = $this->initTable('Assessment\Model\QuestionTable');
                    $conditions = array('QUS_ID' => $id);
                    $questionData = $questionTable->fetchData('t_master_question', $conditions, array('*'), '', false);
                }

                $viewModel->setVariables(array(
                    'questionCCOTaggingData' => $questionCCOTaggingData,
                    'result' => $questionData,
                    'answerType' => $questionData['ANSWER_TYPE']
                ));
                $templateUrl = 'assessment/index/preview/' . $this->getQustionTypeUrlByTypeId($questionData['QUS_TYPE']) . '.phtml';
                $viewModel->setTemplate($templateUrl);
                break;

            case "preview-question-multiple-answer"://QUS_TYPE = 5
                $id = $requestData['id'];
                if ($list_from == 'API') {
                    $questionData = $this->AssessmentPlugin()->getQuestionByIds($id);
                } else {
                    $questionTable = $this->initTable('Assessment\Model\QuestionTable');
                    $conditions = array('QUS_ID' => $id);
                    $questionData = $questionTable->fetchData('t_master_question', $conditions, array('*'), '', false);
                }

                $viewModel->setVariables(array(
                    'questionCCOTaggingData' => $questionCCOTaggingData,
                    'result' => $questionData
                ));
                $templateUrl = 'assessment/index/preview/' . $this->getQustionTypeUrlByTypeId($questionData['QUS_TYPE']) . '.phtml';
                $viewModel->setTemplate($templateUrl);
                break;

            case "preview-question-multiple-choice"://QUS_TYPE = 6
                $id = $requestData['id'];
                if ($list_from == 'API') {
                    $questionData = $this->AssessmentPlugin()->getQuestionByIds($id);
                } else {
                    $questionTable = $this->initTable('Assessment\Model\QuestionTable');
                    $conditions = array('QUS_ID' => $id);
                    $questionData = $questionTable->fetchData('t_master_question', $conditions, array('*'), '', false);
                }

                $viewModel->setVariables(array(
                    'questionCCOTaggingData' => $questionCCOTaggingData,
                    'result' => $questionData
                ));
                $templateUrl = 'assessment/index/preview/' . $this->getQustionTypeUrlByTypeId($questionData['QUS_TYPE']) . '.phtml';
                $viewModel->setTemplate($templateUrl);
                break;

            case "preview-question-ordering"://QUS_TYPE = 7
                $id = $requestData['id'];
                if ($list_from == 'API') {
                    $questionData = $this->AssessmentPlugin()->getQuestionByIds($id);
                } else {
                    $questionTable = $this->initTable('Assessment\Model\QuestionTable');
                    $conditions = array('QUS_ID' => $id);
                    $questionData = $questionTable->fetchData('t_master_question', $conditions, array('*'), '', false);
                }

                $viewModel->setVariables(array(
                    'questionCCOTaggingData' => $questionCCOTaggingData,
                    'result' => $questionData
                ));
                $templateUrl = 'assessment/index/preview/' . $this->getQustionTypeUrlByTypeId($questionData['QUS_TYPE']) . '.phtml';
                $viewModel->setTemplate($templateUrl);
                break;

            case "preview-question-true-false"://QUS_TYPE = 8
                $qusId = $requestData['id'];
                if ($list_from == 'API') {
                    $questionData = $this->AssessmentPlugin()->getQuestionByIds($qusId);
                } else {
                    $questionTable = $this->initTable('Assessment\Model\QuestionTable');
                    $conditions = array('QUS_ID' => $qusId);
                    $questionData = $questionTable->fetchData('t_master_question', $conditions, array('*'), null, false);
                }

                $questionOptionArr = [];
                $questionCorrectArr = [];
                if (!empty($questionData['QUS_OPTION'])) {
                    $questionOptionArr = json_decode($questionData['QUS_OPTION'], TRUE);
                }
                if (!empty($questionData['QUS_CORRECT_RESPONSE'])) {
                    $questionCorrectArr = json_decode($questionData['QUS_CORRECT_RESPONSE'], TRUE);
                }
                $viewModel->setVariables(array(
                    'questionCCOTaggingData' => $questionCCOTaggingData,
                    'questionData' => $questionData,
                    'questionOptionArr' => $questionOptionArr,
                    'questionCorrectArr' => $questionCorrectArr,
                ));
                $templateUrl = 'assessment/index/preview/' . $this->getQustionTypeUrlByTypeId($questionData['QUS_TYPE']) . '.phtml';
                $viewModel->setTemplate($templateUrl);
                break;

            case "preview-question-pick-from-list"://QUS_TYPE = 9
                $qusId = $requestData['id'];
                if ($list_from == 'API') {
                    $questionData = $this->AssessmentPlugin()->getQuestionByIds($qusId);
                } else {
                    $questionTable = $this->initTable('Assessment\Model\QuestionTable');
                    $conditions = array('QUS_ID' => $qusId);
                    $questionData = $questionTable->fetchData('t_master_question', $conditions, array('*'), null, false);
                }

                if (!empty($questionData['QUS_OPTION'])) {
                    $questionOptionArr = json_decode($questionData['QUS_OPTION'], TRUE);
                }
                if (!empty($questionData['QUS_CORRECT_RESPONSE'])) {
                    $questionCorrectArr = json_decode($questionData['QUS_CORRECT_RESPONSE'], TRUE);
                }
                $viewModel->setVariables(array(
                    'questionCCOTaggingData' => $questionCCOTaggingData,
                    'questionData' => $questionData,
                    'questionOptionArr' => $questionOptionArr,
                    'questionCorrectArr' => $questionCorrectArr,
                    'questionText' => $questionData['QUESTION_TEXT']
                ));
                $templateUrl = 'assessment/index/preview/' . $this->getQustionTypeUrlByTypeId($questionData['QUS_TYPE']) . '.phtml';
                $viewModel->setTemplate($templateUrl);
                break;

            case "preview-question-drag-drop"://QUS_TYPE = 10
                $qusId = $requestData['id'];
                if ($list_from == 'API') {
                    $questionData = $this->AssessmentPlugin()->getQuestionByIds($qusId);
                } else {
                    $questionTable = $this->initTable('Assessment\Model\QuestionTable');
                    $conditions = array('QUS_ID' => $qusId);
                    $questionData = $questionTable->fetchData('t_master_question', $conditions, array('*'), '', false);
                }

                $viewModel->setVariables(array(
                    'questionCCOTaggingData' => $questionCCOTaggingData,
                    'result' => $questionData
                ));
                $templateUrl = 'assessment/index/preview/' . $this->getQustionTypeUrlByTypeId($questionData['QUS_TYPE']) . '.phtml';
                $viewModel->setTemplate($templateUrl);
                break;

            case "quspreview":
                $id = $requestData['id'];
                $questionTable = $this->initTable('Assessment\Model\QuestionTable');
                $conditions = array('QUS_ID' => $id);
                $resArr = $questionTable->fetchData('t_master_question', $conditions, array('*'), '', true);
                $viewModel->setVariables(array(
                    'result' => $resArr[0]
                ));
                break;

            case "popup_delete_confirmation":
                $createQuizTable = $this->initTable('Assessment\Model\CreateQuizTable');
                $quesId = $requestData['id'];
                $res = $createQuizTable->fetchData('t_mgr_test_question', ['QUS_ID' => $quesId], array('*'), '', true);
                $viewModel->setVariables(array(
                    'result' => $res,
                ));
                break;

//            case "popup_delete_bank":
//                $questionTable = $this->initTable('Assessment\Model\QuestionTable');
//                $bankId = $requestData['id'];
//                $mgr_qusbank_id = $questionTable->fetchData('t_mgr_question_bank', ['BANK_ID' => $bankId], ['QUSBANK_ID'], null, false);
//                $res = !empty($mgr_qusbank_id) ? $questionTable->fetchData('t_adm_cnf_bank', ['BANK_ID' => $bankId], array('*'), '', true) : '';
//                $viewModel->setVariables(array(
//                    'result' => $res,
//                ));
//                break;

            case "popup_delete_option_file":
                $quesId = $requestData['id'];
                $viewModel->setVariables(array(
                    'result' => '',
                ));
                break;

            case "all_question_type": 
                $requestCameFromTest = (isset($requestData['requestCameFromTest']) && $requestData['requestCameFromTest'] == true) ? $requestData['requestCameFromTest'] : false;
                $createQuizTable = $this->initTable('Assessment\Model\CreateQuizTable');
                $quesType = $createQuizTable->fetchData('t_master_question_type', array('STATUS' => 'A'), array('*'));
                $viewModel->setVariables(array(
                    'quesType' => $quesType,
                    'requestCameFromTest' => $requestCameFromTest,
                    'QUIZ_ID' => isset($requestData['QUIZ_ID']) ? $requestData['QUIZ_ID'] : '',
                    'testId' => isset($requestData['testId']) ? $requestData['testId'] : '',
                    'lpId' => isset($requestData['lpId']) ? $requestData['lpId'] : '',
                    'test_type' => isset($requestData['test_type']) ? $requestData['test_type'] : '',
                    'edit_from' => isset($requestData['edit_from']) ? $requestData['edit_from'] : ''
                ));
                break;

//            case "popup_add_bank":
//                $id = !empty($requestData['id']) ? $requestData['id'] : '';
//                $questionTable = $this->initTable('Assessment\Model\QuestionTable');
//                $addToBankForm = new AddToBankForm();
//                if (!empty($id)) {
//                    $conditions = array('BANK_ID' => $id);
//                    $bankData = $questionTable->fetchData('t_adm_cnf_bank', $conditions, array('*'), null, false);
//                    $addToBankForm = $addToBankForm->setData($bankData);
//                }
//                $viewModel->setVariables(array(
//                    'form' => $addToBankForm,
//                ));
//                break;

            case "popup_add_cognitive":
                $id = !empty($requestData['id']) ? $requestData['id'] : '';
                $questionTable = $this->initTable('Assessment\Model\QuestionTable');
                $cognitiveForm = new CognitiveForm();
                if (!empty($id)) {
                    $conditions = array('COGNITIVE_ID' => $id);
                    $cognitiveData = $questionTable->fetchData('t_adm_cnf_cognitive', $conditions, array('*'), null, false);
                    $cognitiveForm = $cognitiveForm->setData($cognitiveData);
                }
                $viewModel->setVariables(array(
                    'form' => $cognitiveForm,
                ));
                break;

            case "popup_delete_cognitive":
                $questionTable = $this->initTable('Assessment\Model\QuestionTable');
                $cognitiveId = $requestData['id'];
                $mgr_qusbank_id = $questionTable->fetchData('t_master_question', ['COGNITIVE_ID' => $cognitiveId], [], null, false);
                $res = !empty($mgr_qusbank_id) ? $mgr_qusbank_id : '';
                $viewModel->setVariables(array(
                    'result' => $res,
                ));
                break;
        }
        return $viewModel;
    }

    /*
     * @desc    Save image annotation
     */

    public function startAnnotationAction() {
        $viewModel = $this->acceptableviewmodelselector($this->acceptCriteria);
        $viewModel->setTerminal(true);
        $qusId = ($this->params('id') !== null) ? $this->params('id') : '';
        if ($qusId == '')
            die;
        $questionTable = $this->initTable('Assessment\Model\QuestionTable');
        $conditions = array('QUS_ID' => $qusId);
        $qus_correct_response = $questionTable->fetchData('t_master_question', $conditions, array('QUS_CORRECT_RESPONSE'), '', true);
        if (!empty($qus_correct_response[0]['QUS_CORRECT_RESPONSE'])) {
            $arr = json_decode($qus_correct_response[0]['QUS_CORRECT_RESPONSE']);
        }
        $response = array(array("top" => $arr->image->pagex, "left" => $arr->image->pagey, "width" => $arr->image->width, "height" => $arr->image->height, "id" => "e7f44ac5-bcf2-412d-b440-6dbb8b19ffbe", "editable" => true));
        echo json_encode($response);
        die();
    }

    /*
     * @desc    Save image annotation
     */

    public function saveAnnotationAction() {
        $viewModel = $this->acceptableviewmodelselector($this->acceptCriteria);
        $viewModel->setTerminal(true);
        $response = array("top" => @$_GET['top'], "left" => @$_GET['left'], "width" => @$_GET['width'], "height" => @$_GET['height'], "text" => "National Gallery Dome", "id" => "e7f44ac5-bcf2-412d-b440-6dbb8b19ffbe", "editable" => true);
        echo json_encode($response);
        die();
    }

    /*
     * @desc    Delete image annotation
     */

    public function deleteAnnotationAction() {
        $viewModel = $this->acceptableviewmodelselector($this->acceptCriteria);
        $viewModel->setTerminal(true);
        die();
    }

    public function saveBase64ImageAction() {
        $viewModel = $this->acceptableviewmodelselector($this->acceptCriteria);
        $viewModel->setTerminal(true);
        $img = $_POST['base64str'];
        $imgext = explode(';', $img);
        $ext = trim(str_replace("data:image/", "", $imgext[0]));
        $img = str_replace($imgext[0] . ';base64,', '', $img);
        $img = str_replace(' ', '+', $img);
        $data = base64_decode($img);
        $filename = time() . "." . $ext;
        $sourceFile = getcwd() . '/public/upload/' . $filename;
        $success = file_put_contents($sourceFile, $data);
        $defaultSize['width'] = 624;
        $defaultSize['height'] = null;
        $resizeThumb = new ResizeImage($sourceFile);
        $resizeThumb->resizeTo($defaultSize['width'], $defaultSize['height'], 'maxwidth');
        $resizeThumb->saveImage($sourceFile);
        $arr['filename'] = $filename;
        $arr['filepath'] = $this->returnBasePath() . "/upload/" . $filename;
        echo json_encode($arr);
        die();
    }

    /**
     * @Desc This function is used to auto-complete for text input request 
     */
    function getAutoDataAction() {
        $request = $this->getRequest();
        $questionTable = $this->initTable('Assessment\Model\QuestionTable');
        if ($request->isXmlHttpRequest()) {
            $viewModel = $this->acceptableviewmodelselector($this->acceptCriteria);
            $viewModel->setTerminal(true);
            $requestData = $request->getQuery()->toArray();
            $term = (!empty($requestData['q'])) ? $requestData['q'] : '';
            $QUS_ID = (!empty($requestData['QUS_ID'])) ? $requestData['QUS_ID'] : '';
            $qsn_bank_array[] = [0];
//            if ($QUS_ID) {
//                $banks = $questionTable->fetchData('t_mgr_question_bank', ['QUS_ID' => $QUS_ID], ['BANK_ID'], $orderBy = '');
//                if (count($banks)) {
//                    foreach ($banks as $val) {
//                        $qsn_bank_array[] = $val['BANK_ID'];
//                    }
//                }
//            }
            $mode = $requestData['mode'];
//            if ($mode == 'bank') {
//                $isApi = $this->container->authDetail['TEST_ENABLE'];
//                if ($isApi == 'Y') {
//                    $ORG_ID = $this->container->authDetail['ORG_ID'];
//                    $questionTable = $this->initTable('Assessment\Model\QuestionTable');
//                    $bankData = $questionTable->getBankUUidByOrgId($ORG_ID);
//                    $uuid = !empty($bankData) ? $bankData['BANK_UUID'] : "";
//                    $QnsBankData = $this->getTestPlugin()->getBank($uuid);
//                } else {
//                    $dbadapter = $this->getServiceLocator()->get('Zend\Db\Adapter\Adapter');
//                    $questionTable = $this->initTable('Assessment\Model\QuestionTable');
//                    $AutoData = $questionTable->getBankDataByTerm($term);
//                }
//            }

            $newArr = array();
            if ($isApi == 'Y') {
                if (count($QnsBankData)) {
                    foreach ($QnsBankData as $key => $data) {
                        $newArr[$key]['BANK_IDS'][] = $data['BANK_ID'];
                        $newArr[$key]['NAME'][] = $data['BANK_NAME'];
                        $newArr[$key]['SELECTED'][] = (in_array($data['BANK_ID'], $qsn_bank_array)) ? 'checked' : '';
                    }
                }
            } else {
                if (count($AutoData)) {
                    foreach ($AutoData as $key => $data) {
                        $newArr[$key]['BANK_IDS'][] = $data['ID'];
                        $newArr[$key]['NAME'][] = $data['NAME'];
                        $newArr[$key]['SELECTED'][] = (in_array($data['ID'], $qsn_bank_array)) ? 'checked' : '';
                    }
                }
            }
            echo json_encode($newArr);
            die;
        }
    }

    function getCognitive() {
        $getCognitive = [];
        $questionTable = $this->initTable('Assessment\Model\QuestionTable');
        $translator = $this->getServiceLocator()->get('translator');
        $getCognitive = $questionTable->fetchData('t_adm_cnf_cognitive', array(), array(), '', true);
        $result = ['' => $translator->translate('Select Cognitive')];
        if (count($getCognitive)) {
            foreach ($getCognitive as $getValue) {
                $result[$getValue['COGNITIVE_ID']] = $getValue['COGNITIVE_NAME'];
            }
        }
        return $result;
    }
    
    function getApiCognitive() {
        $getCognitive = [];
        $translator = $this->getServiceLocator()->get('translator');
        //$assessment_plugin = $this->AssessmentPlugin();
        //$getCognitive = $assessment_plugin->getCognitive();
        $result = ['' => $translator->translate('Select Cognitive')];
        if (count($getCognitive)) {
            foreach ($getCognitive as $getValue) {
                $result[$getValue['COGNITIVE_ID']] = $getValue['COGNITIVE_NAME'];
            }
        }
        return $result;
    }

    /*
     * @desc Used of this function to Display syllabus tree
     */

    public function printCategoryTree($getTopicIdArr = []) {
        $translator = $this->getServiceLocator()->get('translator');
        $curriculumTable = $this->initTable('Curriculum\Model\CurriculumTable');
        $tree = $curriculumTable->getCategoryTreeWithOutDepth();
        $result = '';
        $currDepth = 0;
        $lastNodeIndex = count($tree) - 1;
        if (count($tree)) {
            foreach ($tree as $index => $currNode) {
                if (in_array($currNode['CAT_ID'], $getTopicIdArr)) {
                    $checkedClass = 'checked';
                } else {
                    $checkedClass = '';
                }

                if ($currNode['DEPTH'] > $currDepth || $index == 0) {
                    $result .= '<ul>';
                }
                if ($currNode['DEPTH'] < $currDepth) {
                    $result .= str_repeat('</ul></li>', $currDepth - $currNode['DEPTH']);
                }
                $t = ($index == 0) ? 1 : 2;
                $catname = $currNode['CAT_NAME'];
                $result .= '<li class="expanded level"><input type="checkbox" class="pr-10 single-checkbox-topic styled" onchange="clickSelected(this);" name="topic[]" value="' . $currNode['CAT_ID'] . '" ' . $checkedClass . '> ' . strtoupper($catname);
                if ($index != $lastNodeIndex && $tree[$index + 1]['DEPTH'] <= $tree[$index]['DEPTH']) {
                    $result .= '</li>'; // If not, close the <li>
                }
                $currDepth = $currNode['DEPTH'];
                if ($index == $lastNodeIndex) {
                    // $result .= '<ul></ul>' . str_repeat('</li></ul>', $currDepth);
                    $result .= str_repeat('</li></ul>', $currDepth);
                }
            }
        }
        return $result;
    }

    public function getCategoryLanguage() {
        return ($this->container->language == 'ar_AE') ? 'ar_AE' : 'en_US';
    }

    /*
     * @desc Use of this action to upload file on AWS server
     * @param string $filename
     * @param string $repositoryName
     * @return json
     */

    public function uploadS3File($filename, $repositoryName, $api = null) {
        if (empty($api)) {
            $viewModel = $this->acceptableviewmodelselector($this->acceptCriteria);
            $viewModel->setTerminal(true);
        }
        $config = $this->serviceLocator->get('config');
        $bucket = $config['s3bucket'];
        $aws = $this->getServiceLocator()->get(Sdk::class);
        $client = $aws->createS3();
        $sourceFile = getcwd() . '/public/upload/' . $filename;
        $src = 'public/upload/' . $filename;
        if (!file_exists($sourceFile)) {
            return ['BACKING_FILE' => $filename, 'message' => 'File not exist'];
        }
        $key = $repositoryName . $filename;
        //if AWS enable,use aws client object
        if ($config['AWS_ENABLE']) {
            $result = $client->putObject(array(
                'Bucket' => $bucket,
                'Key' => $key,
                'SourceFile' => $sourceFile,
                'ACL' => 'public-read'
            ));
            // delete file after upload on s3 
            if (file_exists($src)) {
                unlink($src);
            }
        }

        return ['BACKING_FILE' => $filename, 'message' => 'File uploaded successfully'];
    }

    /**
     * @desc Use of this action to Remove file from AWS server
     */
    public function removeS3File($keyname) {
        $aws = $this->getServiceLocator()->get(Sdk::class);
        $client = $aws->createS3();
        $config = $this->serviceLocator->get('config');
        $bucket = $config['s3bucket'];
        //if AWS enable,use aws client object
        if ($config['AWS_ENABLE']) {
            $result = $client->deleteObject(array(
                'Bucket' => $bucket,
                'Key' => $keyname
            ));
        }
        return 1;
    }

    /**
     * 
     * @param type $getTopicIds
     * @param type $form
     * @return type return data includes subject, unit, topic and subId
     */
    public function getTagDetails($getTopicIds, $form) {
        $translator = $this->getServiceLocator()->get('translator');
        $topicList = array();
        if (count($getTopicIds)) {
            foreach ($getTopicIds as $data) {
                $topicList[] = $data['CAT_ID'];
            }
        }
        $topic = implode(',', $topicList);
        $questionTable = $this->initTable('Assessment\Model\QuestionTable');
        $getGradeSubTopicDetail = $questionTable->getQuestionsTopicByTopicID($topic);

        return ['getSubUnitTopicDetail' => $getGradeSubTopicDetail];
    }

    /*
     * @desc Use of this function for get subject list
     */

    public function getSubjectUnitTopicByTopicID($topicIds = null) {
        $result = array();
        $translator = $this->getServiceLocator()->get('translator');
        $config = $this->serviceLocator->get('config');
        $this->dropDownApiUrl = $config['CCO_URL'];
        $response = $this->HttpClientRequest()->clientRequest($this->dropDownApiUrl . '/api/standard?topicIds=' . $topicIds, '', 'GET');
        if ($response->isSuccess()) {
            $getSubject = json_decode($response->getBody(), true);
            if (count($getSubject['detail'])) {
                foreach ($getSubject['detail'] as $getSubjectK => $getSubjectV) {
                    $result[$getSubjectV['TOPIC_ID']] = $getSubjectV;
                }
            }
        }
        return $result;
    }

    /**
     * @desc Use of this function for get All Grades detail by imploded grade-id`s from CCO API
     * @param string $imploded_grade_ids
     * @return array
     */
    public function getContentFromTebian($imploded_topic_ids) {
        $config = $this->serviceLocator->get('config');
        $response = $this->HttpClientRequest()->clientRequest($config['TEBIAN_API_URL'] . '/api/content?topicIds=' . $imploded_topic_ids, '', 'GET');
        $result = [];
        if ($response->isSuccess()) {
            $getGrades = json_decode($response->getBody(), true);
            if (count($getGrades['detail'])) {
                $result = $getGrades['detail'];
            }
        }

        return $result;
    }

    /**
     * @desc used to get all content types via tebian API.
     * @param boolean $is_content_types | used to flag in API URL
     * @return array
     */
    public function getContentTypesFromTebian($is_content_types = 'true') {
        $result = [];
        $config = $this->serviceLocator->get('config');
        $response = $this->HttpClientRequest()->clientRequest($config['TEBIAN_API_URL'] . '/api/content?contentTypes=' . $is_content_types, '', 'GET');
        if ($response->isSuccess()) {
            $get_content_types = json_decode($response->getBody(), true);
            $result = $get_content_types['detail'];
        }
        return $result;
    }

    public function objToArray($obj, &$arr) {
        if (!is_object($obj) && !is_array($obj)) {
            $arr = $obj;
            return $arr;
        }
        foreach ($obj as $key => $value) {
            if (!empty($value)) {
                $arr[$key] = array();
                $this->objToArray($value, $arr[$key]);
            } else {
                $arr[$key] = $value;
            }
        }
        return $arr;
    }

    /**
     * @desc used only to get fine topic id's array and print category tree with checked/unchecked element in Edit case.
     * @param {array} $getTopicIds.
     */
    function getCheckedTopicsHtml($getTopicIds) {
        $getTopicIdArr = [];
        if (count($getTopicIds)) {
            foreach ($getTopicIds as $val) {
                $getTopicIdArr[] = $val['CAT_ID'];
            }
            $getTopicIdArr = count($getTopicIdArr) ? $getTopicIdArr : [];
        }
        return $catTreeWithHtml = (!empty($getTopicIdArr)) ? $this->printCategoryTree($getTopicIdArr) : '';
    }

    /**
     * @desc Use of this function for get All Grades detail by imploded grade-id`s from CCO API
     * @param string $imploded_grade_ids
     * @return array
     */
    public function getGradesById($imploded_grade_ids) {
        try {
            $translator = $this->getServiceLocator()->get('translator');
            $config = $this->serviceLocator->get('config');
            $this->dropDownApiUrl = $config['CCO_URL'];
            $api = new \Checkondispatch\Custom\ApiReader($this->dropDownApiUrl . 'api/standard?gradeIds=' . $imploded_grade_ids);
            $api->setMethod('GET');
            $response = $api->getResponseData();
            $result = [];
            if (!empty($response['title']) && $response['title'] == 'Success') {
                if (count($response['detail'])) {
                    $result = $response['detail'];
                }
            }
            return $result;
        } catch (\Exception $e) {
            echo $e->getMessage();
            die();
        }
    }

    /**
     * @desc Use of this function for get countries from CCO API
     * @return array
     */
    public function getCountries() {
        $translator = $this->getServiceLocator()->get('translator');
        $config = $this->serviceLocator->get('config');
        $this->dropDownApiUrl = $config['CCO_URL'];
        $result = ['' => $translator->translate('Country')];
        $response = $this->HttpClientRequest()->clientRequest($this->dropDownApiUrl . '/api/country', '', 'GET');
        if ($response->isSuccess()) {
            $getCountries = json_decode($response->getBody(), true);
            if (count($getCountries['detail'])) {
                foreach ($getCountries['detail'] as $countryK => $countryV) {
                    $result[$countryV['COUNTRY_ID']] = $countryV['SHORT_NAME'];
                }
            }
        }
        return $result;
    }

    /**
     * @desc Use of this function for get all grades by school from Local.
     * @return array
     */
    public function getGradesLocal($cco=null) {
	$teacherid = $this->container->authDetail['USER_OID'];
        $questionTable = $this->initTable('Assessment\Model\QuestionTable');
        $curriculumTable = $this->initTable('Curriculum\Model\CurriculumTable');
        $translator = $this->getServiceLocator()->get('translator');
        $orgId = $this->container->authDetail['ORG_ID'];
        $utid = $this->container->authDetail['UT_ID'];
		
		if(empty($cco)){
			if ($utid == 2) {
				$subjects = $curriculumTable->getAssignSubjectById($teacherid);
			if (empty($subjects)) {
                $subjects = [0];
            }
				$join[] = ['t_cm_mgr_grade', 't_cm_mgr_grade.GRADE_ID = t_cm_mgr_subject.GRADE_ID'];
				$getAllgrades = $questionTable->fetchData('t_cm_mgr_subject', ['t_cm_mgr_subject.SUBJECT_ID' => $subjects], ['*'], '', true, '', '', '', '', '', '', $join);
	//             echo'<pre>';print_r($getAllgrades);die;
            }
            else {
				$getAllgrades = $questionTable->fetchData('t_cm_mgr_grade', ['ORG_ID' => $orgId], ['*']);
			}

			$result = ['' => $translator->translate('Select Grade')];
		
		
		
			if (count($getAllgrades)) {
			if(empty($cco)){
				foreach ($getAllgrades as $grade_data) {
					$result[$grade_data['GRADE_ID']] = $grade_data['GRADE_NAME'];
				}
			}else{
				foreach ($getAllgrades as $grade_data) {
					if(!empty($grade_data['ADM_REF_ID'])){
						$result[$grade_data['GRADE_ID']] = $grade_data['GRADE_NAME'];
					}					
				}
			}
            
			}
		}else{
			$result = ['' => $translator->translate('Select Grade')];
			$config = $this->serviceLocator->get('config');
			$this->dropDownApiUrl = $config['CCO_URL'];
			$selected_id = 1;
			 $response = $this->HttpClientRequest()->clientRequest($this->dropDownApiUrl . 'standard?standardId=' . $selected_id . '&flag=1', '', 'GET');
                $html = '<option value="">' . $translator->translate('Grade') . '</option>';
                if ($response->isSuccess()) {
                    $grades = json_decode($response->getBody(), true);
                    foreach ($grades['detail'] as $data) {
                        $html .= '<option value="' . $data['GRADE_ID'] . '">' . $data['GRADE_Name'] . '</option>';
                    }
                }
		}
		
        
           
        return $result;
    }

}

Youez - 2016 - github.com/yon3zu
LinuXploit