public function test_getInstance()
 {
     $this->_datatable->setDatatableId('test')->setEntity('Ali\\DatatableBundle\\Entity\\Product', 'p')->setFields(array("title" => 'p.name', "_identifier_" => 'p.id'));
     $i = $this->_datatable->getInstance('test');
     $this->assertInstanceOf('\\Ali\\DatatableBundle\\Util\\Datatable', $i);
     $this->assertEquals('p', $i->getEntityAlias());
 }
 /**
  * Converts a string to time
  * 
  * @param string $string
  * @return int 
  */
 public function datatable($options)
 {
     if (!isset($options['id'])) {
         $options['id'] = 'ali-dta_' . md5(rand(1, 100));
     }
     $dt = Datatable::getInstance($options['id']);
     $config = $dt->getConfiguration();
     $options['js_conf'] = json_encode($config['js']);
     $options['js'] = json_encode($options['js']);
     $options['action'] = $dt->getHasAction();
     $options['action_twig'] = $dt->getHasRendererAction();
     $options['fields'] = $dt->getFields();
     $options['delete_form'] = $this->createDeleteForm('_id_')->createView();
     $options['search'] = $dt->getSearch();
     $options['search_fields'] = $dt->getSearchFields();
     $options['multiple'] = $dt->getMultiple();
     $options['sort'] = is_null($dt->getOrderField()) ? NULL : array(array_search($dt->getOrderField(), array_values($dt->getFields())), $dt->getOrderType());
     $main_template = 'AliDatatableBundle:Main:index.html.twig';
     if (isset($options['main_template'])) {
         $main_template = $options['main_template'];
     }
     $session = $this->_container->get('session');
     $rawjs = $this->_container->get('templating')->render('AliDatatableBundle:Internal:script.html.twig', $options);
     $sess_dtb = $session->get('datatable', array());
     $sess_dtb[$options['id']] = $rawjs;
     $session->set('datatable', $sess_dtb);
     return $this->_container->get('templating')->render($main_template, $options);
 }
 /**
  * Converts a string to time
  *
  * @param string $string
  * @return int
  */
 public function datatable($options)
 {
     if (!isset($options['id'])) {
         $options['id'] = 'ali-dta_' . md5(str_replace("/", '-', $options['js']['sAjaxSource']));
     }
     $dt = Datatable::getInstance($options['id']);
     $config = $dt->getConfiguration();
     $options['js_conf'] = json_encode($config['js']);
     $options['js'] = json_encode($options['js']);
     $options['action'] = $dt->getHasAction();
     $options['action_twig'] = $dt->getHasRendererAction();
     $options['fields'] = $dt->getFields();
     $options['delete_form'] = $this->createDeleteForm('_id_')->createView();
     $options['search'] = $dt->getSearch();
     $options['search_fields'] = $dt->getSearchFields();
     $options['multiple'] = $dt->getMultiple();
     $options['sort'] = is_null($dt->getOrderField()) ? NULL : array(array_search($dt->getOrderField(), array_values($dt->getFields())), $dt->getOrderType());
     $main_template = 'AliDatatableBundle:Main:index.html.twig';
     if (isset($options['main_template'])) {
         $main_template = $options['main_template'];
     }
     return $this->_container->get('templating')->render($main_template, $options);
 }
 public function testSetDatatableId()
 {
     $dta1 = $this->_container->get('datatable');
     $dta1->setEntity('Ali\\DatatableBundle\\Tests\\TestBundle\\Entity\\Product', 'p')->setFields(array("description" => 'p.description', "_identifier_" => 'p.id'))->setDatatableId('dta1');
     $dta2 = $this->_container->get('datatable');
     $dta2->setEntity('Ali\\DatatableBundle\\Tests\\TestBundle\\Entity\\Product', 'p')->setFields(array("title" => 'p.name', "_identifier_" => 'p.id'))->setDatatableId("dta2");
     $this->assertNotEquals(Datatable::getInstance('dta1'), Datatable::getInstance('dta2'));
     $this->assertNotEquals(Datatable::getInstance('dta1')->getFields(), Datatable::getInstance('dta2')->getFields());
 }