Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\CabinetBundle\Controller;
- use App\CoreBundle\Entity\Anketa;
- use Symfony\Bundle\FrameworkBundle\Controller\Controller;
- use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
- use Symfony\Component\HttpFoundation\Request;
- class AnketaController extends Controller
- {
- /** @Template() */
- public function indexAction(Request $request)
- {
- $anketa=$this->get('repo.anketa')->find($this->getUser()->getId());
- if (!$anketa) return $this->redirect($this->generateUrl('cabinet_anketa_add'));
- return array(
- 'anketa'=>$anketa
- );
- }
- /** @Template() */
- public function editAction(Request $request)
- {
- $anketa=$this->get('repo.anketa')->find($this->getUser()->getId());
- if (!$anketa) return $this->redirect($this->generateUrl('cabinet_anketa_add'));
- $form=$this->createForm($this->get('cabinet.form.anketa'), $anketa, array(
- 'action' => $this->generateUrl($request->get('_route')),
- 'method' => 'POST',
- 'attr' => array(
- 'class' => 'form-horizontal',
- 'id' => 'form'
- )
- ));
- if ($request->getMethod() == 'POST') {
- $form->submit($request);
- if ($form->isValid()) {
- try {
- $town=$this->get('repo.town')->find($request->get('town'));
- $region=$this->get('repo.region')->find($request->get('region'));
- $country=$this->get('repo.country')->find($request->get('country'));
- $anketa->setTown($town);
- $anketa->setRegion($region);
- $anketa->setCountry($country);
- $anketa->setUser($this->getUser());
- $this->getDoctrine()->getManager()->persist($anketa);
- $this->getDoctrine()->getManager()->flush();
- $this->getDoctrine()->getManager()->clear();
- $this->get('session')->getFlashBag()->add('success', $this->get('translator')->trans('cabinet.flash.saved'));
- } catch (\Exception $e) {
- $this->get('session')->getFlashBag()->add('danger', $this->get('translator')->trans('cabinet.flash.saved_error'));
- }
- return $this->redirect($this->generateUrl('cabinet_anketa_index'));
- }
- }
- return array(
- 'form'=>$form->createView(),
- 'town'=>$anketa->getTown(),
- 'countries'=>$this->get('repo.country')->findAll()
- );
- }
- /** @Template() */
- public function addAction(Request $request)
- {
- $anketa=$this->get('repo.anketa')->find($this->getUser()->getId());
- if ($anketa instanceof Anketa) return $this->redirect($this->generateUrl('cabinet_anketa_edit'));
- $anketa=$this->get('entity.anketa');
- $form=$this->createForm($this->get('cabinet.form.anketa'), $anketa, array(
- 'action' => $this->generateUrl($request->get('_route')),
- 'method' => 'POST',
- 'attr' => array(
- 'class' => 'form-horizontal',
- 'id' => 'form'
- )
- ));
- if ($request->getMethod() == 'POST') {
- $form->submit($request);
- if ($form->isValid()) {
- try {
- $town=$this->get('repo.town')->find($request->get('town'));
- $region=$this->get('repo.region')->find($request->get('region'));
- $country=$this->get('repo.country')->find($request->get('country'));
- $anketa->setTown($town);
- $anketa->setRegion($region);
- $anketa->setCountry($country);
- $anketa->setUser($this->getUser());
- $this->getDoctrine()->getManager()->persist($anketa);
- $this->getDoctrine()->getManager()->flush();
- $this->getDoctrine()->getManager()->clear();
- $this->get('session')->getFlashBag()->add('success', $this->get('translator')->trans('cabinet.flash.saved'));
- } catch (\Exception $e) {
- $this->get('session')->getFlashBag()->add('danger', $this->get('translator')->trans('cabinet.flash.saved_error'));
- }
- return $this->redirect($this->generateUrl('cabinet_anketa_index'));
- }
- }
- return array(
- 'form'=>$form->createView(),
- 'countries'=>$this->get('repo.country')->findAll()
- );
- }
- }
- <script type="text/javascript">
- $('#save').click(function () {
- $('#save').attr('disabled', 'disabled');
- $('#gbox_table_user').showLoading();
- $.getJSON( Routing.generate('back_default_setUsersByProgram', {'id':{{ app.request.get('id') }}, 'users_ids': idsOfSelectedRows.join() }), function( data ) {
- $('#save').removeAttr('disabled');
- $('#gbox_table_user').hideLoading();
- noty({type: 'success', layout: 'topRight', timeout: 5000, text: '{{ 'flash.saved'|trans }}'});
- });
- });
- var idsOfSelectedRows=[{{ users }}];
- function updateIdsOfSelectedRows(id, isSelected){
- var index = $.inArray(parseInt(id), idsOfSelectedRows);
- if (!isSelected && index >= 0) {
- idsOfSelectedRows.splice(index, 1); // remove id from the list
- } else if (index < 0) {
- idsOfSelectedRows.push(parseInt(id));
- }
- }
- $("#table_user").jqGrid({
- url: Routing.generate('back_default_getUsers'),
- datatype: "json",
- colNames: [
- '{{ 'back.page.programConfig.user.grid.username'|trans }}',
- '{{ 'back.page.programConfig.user.grid.firstname'|trans }}',
- '{{ 'back.page.programConfig.user.grid.lastname'|trans }}'
- ],
- colModel: [
- {
- name: 'username',
- index: 'username',
- searchoptions:{
- sopt:['eq','ne','bw','cn']
- }
- },
- {
- name: 'firstname',
- index: 'firstname',
- searchoptions:{
- sopt:['eq','ne','bw','cn']
- }
- },
- {
- name: 'lastname',
- index: 'lastname',
- searchoptions:{
- sopt:['eq','ne','bw','cn']
- }
- }
- ],
- rowNum: 30,
- pager: '#pager_user',
- multiselect: true,
- rownumbers: true,
- rowList:[ 10, 30, 50, 100],
- onSelectAll: function (aRowids, isSelected) {
- var i, count, id;
- for (i = 0, count = aRowids.length; i < count; i++) {
- id = aRowids[i];
- updateIdsOfSelectedRows(id, isSelected);
- }
- },
- onSelectRow: function(id, isSelected){
- updateIdsOfSelectedRows(id, isSelected);
- },
- loadComplete: function () {
- var $this = $(this), i, count;
- for (i = 0, count = idsOfSelectedRows.length; i < count; i++) {
- $this.jqGrid('setSelection', idsOfSelectedRows[i], false);
- }
- },
- caption: "{{ 'back.page.programConfig.user.grid.title'|trans }}"
- }).navGrid('#pager_user',
- {edit:false, add:false, del:false, view:false}, {}, {}, {}, {/*closeAfterSearch:true*/}
- );
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement