Ejemplo n.º 1
0
 function process_ajax()
 {
     $aColumns = array();
     foreach ($this->columns as $column) {
         if (!in_array($column['columnName'], $aColumns)) {
             $aColumns[] = $column['columnName'];
         }
     }
     $sSearch = __Request::get('sSearch');
     $filters = array();
     $it = org_glizy_ObjectFactory::createModelIterator($this->getAttribute('recordClassName'));
     if ($it->getArType() === 'document') {
         $it->setOptions(array('type' => 'PUBLISHED_DRAFT'));
     }
     if ($this->getAttribute('setFiltersToQuery')) {
         for ($i = 0; $i < count($aColumns); $i++) {
             if (__Request::get('sSearch_' . $i)) {
                 $filters[$aColumns[$i]] = __Request::get('sSearch_' . $i);
             } else {
                 if ($sSearch != '' && __Request::get('bSearchable_' . $i) == "true") {
                     $filters[$aColumns[$i]] = $sSearch;
                 }
             }
         }
         $it->load($this->getAttribute('query'), array('filters' => $filters));
     } else {
         $it->load($this->getAttribute('query'));
         if (method_exists($it, 'showAll')) {
             $it->showAll();
         }
         if ($this->getAttribute('fullTextSearch') && $sSearch) {
             $it->where('fulltext', '%' . $sSearch . '%', 'ILIKE');
         } else {
             for ($i = 0; $i < count($aColumns); $i++) {
                 if (__Request::get('sSearch_' . $i)) {
                     $filters[$aColumns[$i]] = array('value' => __Request::get('sSearch_' . $i), 'condition' => 'LIKE');
                 } else {
                     if ($sSearch != '' && __Request::get('bSearchable_' . $i) == "true") {
                         $filters[$aColumns[$i]] = array('value' => '%' . $sSearch . '%', 'condition' => 'LIKE');
                     }
                 }
             }
             if (!empty($filters)) {
                 if ($this->getAttribute('queryOperator') === 'OR') {
                     $it->setOrFilters($filters);
                 } else {
                     $it->setFilters($filters);
                 }
             }
         }
     }
     // Ordering
     if (__Request::exists('iSortCol_0')) {
         $iSortingCols = intval(__Request::get('iSortingCols'));
         for ($i = 0; $i < $iSortingCols; $i++) {
             if (__Request::get('bSortable_' . intval(__Request::get('iSortCol_' . $i))) == "true") {
                 $order = $aColumns[intval(__Request::get('iSortCol_' . $i))];
                 $order_dir = __Request::get('sSortDir_' . $i);
                 $it->orderBy($order, $order_dir);
                 break;
             }
         }
     }
     // Paging
     if (__Request::get('iDisplayStart', -1) != -1) {
         $it->limit(array(__Request::get('iDisplayStart'), __Request::get('iDisplayLength', -1)));
     }
     $aaData = array();
     if ($this->getAttribute('dbDebug')) {
         org_glizy_dataAccessDoctrine_DataAccess::enableLogging();
     }
     try {
         foreach ($it as $row) {
             $rowToInsert = array();
             foreach ($this->columns as $column) {
                 if ($column['acl']) {
                     if (!$this->_user->acl($column['acl']['service'], $column['acl']['action'])) {
                         continue;
                     }
                 }
                 $value = $row->{$column}['columnName'];
                 if ($column['renderCell']) {
                     if (!is_object($column['renderCell'])) {
                         $column['renderCell'] = org_glizy_ObjectFactory::createObject($column['renderCell'], $this->_application);
                     }
                     if (is_object($column['renderCell'])) {
                         $value = $column['renderCell']->renderCell($row->getId(), $value, $row, $column['columnName']);
                     }
                 }
                 if (is_object($value)) {
                     $value = json_encode($value);
                 }
                 $rowToInsert[] = $value;
             }
             $aaData[] = $rowToInsert;
         }
     } catch (Exception $e) {
         var_dump($e);
     }
     if ($this->getAttribute('dbDebug')) {
         org_glizy_dataAccessDoctrine_DataAccess::disableLogging();
         die;
     }
     $output = array("sEcho" => intval(__Request::get('sEcho')), "iTotalRecords" => $it->count(), "iTotalDisplayRecords" => $it->count(), "aaData" => $aaData);
     return $output;
 }
Ejemplo n.º 2
0
/**
 * @param bool $state
 * @param int $n
 */
function glz_DBdebug($state = true, $n = 0)
{
    if ($state) {
        org_glizy_dataAccessDoctrine_DataAccess::enableLogging($n);
    } else {
        org_glizy_dataAccessDoctrine_DataAccess::disableLogging($n);
    }
}