コード例 #1
0
 function __construct($attributes, $table_name, $page_name)
 {
     // table-header
     parent::__construct($attributes);
     $this->setAutoGrow(true);
     $this->setAutoFill(" ");
 }
コード例 #2
0
 function __construct()
 {
     $lang = services::getService('lang');
     // table-header
     parent::__construct(array("width" => "100%", "class" => "pools"));
     $this->setHeaderContents(0, 0, $lang->getMsg('tableheaders_name'));
     $this->setHeaderContents(0, 1, $lang->getMsg('tableheaders_area'));
     $this->setHeaderContents(0, 2, $lang->getMsg('tableheaders_adress'));
     $this->setHeaderContents(0, 3, $lang->getMsg('tableheaders_rescount'));
     $this->setRowAttributes(0, array("class" => "pools2"));
 }
コード例 #3
0
 /**
  * Create a new SortableTable
  * @param string $table_name A name for the table (default = 'table')
  * @param string $get_total_number_function A user defined function to get
  * the total number of items in the table
  * @param string $get_data_function A function to get the data to display on
  * the current page
  * @param int $default_column The default column on which the data should be
  * sorted
  * @param int $default_items_per_page The default number of items to show
  * on one page
  * @param string $default_order_direction The default order direction;
  * either the constant 'ASC' or 'DESC'
  * @param string $table_id
  */
 public function __construct($table_name = 'table', $get_total_number_function = null, $get_data_function = null, $default_column = 1, $default_items_per_page = 20, $default_order_direction = 'ASC', $table_id = null)
 {
     if (empty($table_id)) {
         $table_id = $table_name . uniqid();
     }
     $this->table_id = $table_id;
     parent::__construct(array('id' => $table_id, 'class' => 'table table-striped table-hover table-bordered'));
     $this->table_name = $table_name;
     $this->additional_parameters = array();
     $this->param_prefix = $table_name . '_';
     $this->page_nr = isset($_SESSION[$this->param_prefix . 'page_nr']) ? intval($_SESSION[$this->param_prefix . 'page_nr']) : 1;
     $this->page_nr = isset($_GET[$this->param_prefix . 'page_nr']) ? intval($_GET[$this->param_prefix . 'page_nr']) : $this->page_nr;
     $this->column = isset($_SESSION[$this->param_prefix . 'column']) ? intval($_SESSION[$this->param_prefix . 'column']) : $default_column;
     $this->column = isset($_GET[$this->param_prefix . 'column']) ? intval($_GET[$this->param_prefix . 'column']) : $this->column;
     // Default direction
     if (in_array(strtoupper($default_order_direction), array('ASC', 'DESC'))) {
         $this->direction = $default_order_direction;
     }
     if (isset($_SESSION[$this->param_prefix . 'direction'])) {
         $my_session_direction = $_SESSION[$this->param_prefix . 'direction'];
         if (!in_array($my_session_direction, array('ASC', 'DESC'))) {
             $this->direction = 'ASC';
         } else {
             if ($my_session_direction == 'ASC') {
                 $this->direction = 'ASC';
             } elseif ($my_session_direction == 'DESC') {
                 $this->direction = 'DESC';
             }
         }
     }
     if (isset($_GET[$this->param_prefix . 'direction'])) {
         $my_get_direction = $_GET[$this->param_prefix . 'direction'];
         if (!in_array($my_get_direction, array('ASC', 'DESC'))) {
             $this->direction = 'ASC';
         } else {
             if ($my_get_direction == 'ASC') {
                 $this->direction = 'ASC';
             } elseif ($my_get_direction == 'DESC') {
                 $this->direction = 'DESC';
             }
         }
     }
     // Allow to change paginate in multiples tabs
     unset($_SESSION[$this->param_prefix . 'per_page']);
     $this->per_page = isset($_SESSION[$this->param_prefix . 'per_page']) ? intval($_SESSION[$this->param_prefix . 'per_page']) : $default_items_per_page;
     $this->per_page = isset($_GET[$this->param_prefix . 'per_page']) ? intval($_GET[$this->param_prefix . 'per_page']) : $this->per_page;
     $_SESSION[$this->param_prefix . 'per_page'] = $this->per_page;
     $_SESSION[$this->param_prefix . 'direction'] = $this->direction;
     $_SESSION[$this->param_prefix . 'page_nr'] = $this->page_nr;
     $_SESSION[$this->param_prefix . 'column'] = $this->column;
     $this->pager = null;
     $this->default_items_per_page = $default_items_per_page;
     $this->total_number_of_items = -1;
     $this->get_total_number_function = $get_total_number_function;
     $this->get_data_function = $get_data_function;
     $this->column_filters = array();
     $this->form_actions = array();
     $this->checkbox_name = null;
     $this->td_attributes = array();
     $this->th_attributes = array();
     $this->other_tables = array();
 }
コード例 #4
0
 public function __construct($attrs = array(), $options = array())
 {
     global $_ARRAYLANG;
     if ($attrs instanceof \Cx\Core_Modules\Listing\Model\Entity\DataSet) {
         $hasMasterTableHeader = !empty($options['header']);
         // add master table-header-row
         if ($hasMasterTableHeader) {
             $this->addRow(array(0 => $options['header']), null, 'th');
         }
         $first = true;
         $row = 1 + $hasMasterTableHeader;
         foreach ($attrs as $rowname => $rows) {
             $col = 0;
             $virtual = $rows['virtual'];
             unset($rows['virtual']);
             if (isset($options['multiActions'])) {
                 $this->setCellContents($row, $col, '<input name="select-' . $rowname . '" value="' . $rowname . '" type="checkbox" />', 'TD', '0', false);
                 $col++;
             }
             foreach ($rows as $header => $data) {
                 $encode = true;
                 if (isset($options['fields']) && isset($options['fields'][$header]) && isset($options['fields'][$header]['showOverview']) && !$options['fields'][$header]['showOverview']) {
                     continue;
                 }
                 $origHeader = $header;
                 if (isset($options['fields'][$header]['sorting'])) {
                     $sorting = $options['fields'][$header]['sorting'];
                 } else {
                     if (isset($options['functions']['sorting'])) {
                         $sorting = $options['functions']['sorting'];
                     }
                 }
                 if ($first) {
                     if (isset($options['fields'][$header]['header'])) {
                         $header = $options['fields'][$header]['header'];
                     }
                     if (isset($_ARRAYLANG[$header])) {
                         $header = $_ARRAYLANG[$header];
                     }
                     if (is_array($options['functions']) && isset($options['functions']['sorting']) && $options['functions']['sorting'] && $sorting !== false) {
                         $order = '';
                         $img = '&uarr;&darr;';
                         if (isset($_GET['order'])) {
                             $supOrder = explode('/', $_GET['order']);
                             if (current($supOrder) == $origHeader) {
                                 $order = '/DESC';
                                 $img = '&darr;';
                                 if (count($supOrder) > 1 && $supOrder[1] == 'DESC') {
                                     $order = '';
                                     $img = '&uarr;';
                                 }
                             }
                         }
                         $header = '<a href="' . \Env::get('cx')->getRequest()->getUrl() . '&order=' . $origHeader . $order . '" style="white-space: nowrap;">' . $header . ' ' . $img . '</a>';
                     }
                     if ($hasMasterTableHeader) {
                         $this->setCellContents(1, $col, $header, 'td', 0);
                     } else {
                         $this->setCellContents(0, $col, $header, 'th', 0);
                     }
                 }
                 if (isset($options['fields']) && isset($options['fields'][$origHeader]) && isset($options['fields'][$origHeader]['table']) && isset($options['fields'][$origHeader]['table']['parse']) && is_callable($options['fields'][$origHeader]['table']['parse'])) {
                     $callback = $options['fields'][$origHeader]['table']['parse'];
                     $data = $callback($data, $rows);
                     $encode = false;
                     // todo: this should be set by callback
                 } else {
                     if (is_object($data) && get_class($data) == 'DateTime') {
                         $data = $data->format(ASCMS_DATE_FORMAT);
                     } else {
                         if (isset($options['fields'][$origHeader]) && isset($options['fields'][$origHeader]['type']) && $options['fields'][$origHeader]['type'] == '\\Country') {
                             $data = \Cx\Core\Country\Controller\Country::getNameById($data);
                             if (empty($data)) {
                                 $data = \Cx\Core\Country\Controller\Country::getNameById(204);
                             }
                         } else {
                             if (gettype($data) == 'boolean') {
                                 $data = '<i>' . ($data ? $_ARRAYLANG['TXT_YES'] : $_ARRAYLANG['TXT_NO']) . '</i>';
                                 $encode = false;
                             } else {
                                 if ($data === null) {
                                     $data = '<i>' . $_ARRAYLANG['TXT_CORE_NONE'] . '</i>';
                                     $encode = false;
                                 } else {
                                     if (empty($data)) {
                                         $data = '<i>(empty)</i>';
                                         $encode = false;
                                     }
                                 }
                             }
                         }
                     }
                 }
                 $this->setCellContents($row, $col, $data, 'TD', 0, $encode);
                 $col++;
             }
             if ($this->hasRowFunctions($options['functions'], $virtual)) {
                 if ($first) {
                     $header = 'Functions';
                     if (isset($_ARRAYLANG['TXT_FUNCTIONS'])) {
                         $header = $_ARRAYLANG['TXT_FUNCTIONS'];
                     }
                     if ($hasMasterTableHeader) {
                         $this->setCellContents(1, $col, $header, 'td', 0, true);
                     } else {
                         $this->setCellContents(0, $col, $header, 'th', 0, true);
                     }
                 }
                 $this->updateColAttributes($col, array('style' => 'text-align:right;'));
                 if (empty($options['functions']['baseUrl'])) {
                     $options['functions']['baseUrl'] = clone \Env::get('cx')->getRequest()->getUrl();
                 }
                 $this->setCellContents($row, $col, $this->getFunctionsCode($rowname, $rows, $options['functions'], $virtual), 'TD', 0);
             }
             $first = false;
             $row++;
         }
         // adjust colspan of master-table-header-row
         if ($hasMasterTableHeader) {
             $this->setCellAttributes(0, 0, array('colspan' => $col + is_array($options['functions'])));
             $this->updateRowAttributes(1, array('class' => 'row3'), true);
         }
         // add multi-actions
         if (isset($options['multiActions'])) {
             $multiActionsCode = '
                 <img src="images/icons/arrow.gif" width="38" height="22" alt="^" title="^">
                 <a href="#" onclick="jQuery(\'input[type=checkbox]\').prop(\'checked\', true);return false;">' . $_ARRAYLANG['TXT_SELECT_ALL'] . '</a> /
                 <a href="#" onclick="jQuery(\'input[type=checkbox]\').prop(\'checked\', false);return false;">' . $_ARRAYLANG['TXT_DESELECT_ALL'] . '</a>
                 <img alt="-" title="-" src="images/icons/strike.gif">
             ';
             $multiActions = array('' => $_ARRAYLANG['TXT_SUBMIT_SELECT']);
             foreach ($options['multiActions'] as $actionName => $actionProperties) {
                 $actionTitle = $actionName;
                 if (isset($actionProperties['title'])) {
                     $actionTitle = $actionProperties['title'];
                 } else {
                     if (isset($_ARRAYLANG[$actionName])) {
                         $actionTitle = $_ARRAYLANG[$actionName];
                     }
                 }
                 if (isset($actionProperties['jsEvent'])) {
                     $actionName = $actionProperties['jsEvent'];
                 }
                 $multiActions[$actionName] = $actionTitle;
             }
             $select = new \Cx\Core\Html\Model\Entity\DataElement('cxMultiAction', \Html::getOptions($multiActions), \Cx\Core\Html\Model\Entity\DataElement::TYPE_SELECT);
             // this is not a nice place for this code
             // but we should cleanup this complete class and make
             // it base on templates
             $select->setAttribute('onchange', '
                     var regex = /([a-zA-Z\\/]+):([a-zA-Z\\/]+)/;
                     var matches = jQuery(this).val().match(regex);
                     if (!matches) {
                         return false;
                     }
                     var checkboxes = jQuery(this).closest("table").find("input[type=checkbox]");
                     var activeRows = [];
                     checkboxes.filter(":checked").each(function(el) {
                         activeRows.push(jQuery(this).val());
                     });
                     cx.trigger(matches[1], matches[2], activeRows);
                     checkboxes.prop("checked", false);
                     jQuery(this).val("");
                 ');
             $this->setCellContents($row, 0, $multiActionsCode . $select, 'TD', 0);
             $this->setCellAttributes($row, 0, array('colspan' => $col + is_array($options['functions'])));
         }
         $attrs = array();
     }
     parent::__construct(array_merge($attrs, array('class' => 'adminlist', 'width' => '100%')));
 }
コード例 #5
0
 public function __construct($attrs = array(), $options = array())
 {
     global $_ARRAYLANG;
     if ($attrs instanceof \Cx\Core_Modules\Listing\Model\Entity\DataSet) {
         $hasMasterTableHeader = !empty($options['header']);
         // add master table-header-row
         if ($hasMasterTableHeader) {
             $this->addRow(array(0 => $options['header']), null, 'th');
         }
         $first = true;
         $row = 1 + $hasMasterTableHeader;
         $sortBy = isset($options['functions']['sortBy']) && is_array($options['functions']['sortBy']) ? $options['functions']['sortBy'] : array();
         $sortingKey = !empty($sortBy) && isset($sortBy['sortingKey']) ? $sortBy['sortingKey'] : '';
         $sortField = !empty($sortingKey) && isset($sortBy['field']) ? key($sortBy['field']) : '';
         $component = !empty($sortBy) && isset($sortBy['component']) ? $sortBy['component'] : '';
         $entity = !empty($sortBy) && isset($sortBy['entity']) ? $sortBy['entity'] : '';
         $sortOrder = !empty($sortBy) && isset($sortBy['sortOrder']) ? $sortBy['sortOrder'] : '';
         $pagingPos = !empty($sortBy) && isset($sortBy['pagingPosition']) ? $sortBy['pagingPosition'] : '';
         foreach ($attrs as $rowname => $rows) {
             $col = 0;
             $virtual = $rows['virtual'];
             unset($rows['virtual']);
             if (isset($options['multiActions'])) {
                 $this->setCellContents($row, $col, '<input name="select-' . $rowname . '" value="' . $rowname . '" type="checkbox" />', 'TD', '0', false);
                 $col++;
             }
             foreach ($rows as $header => $data) {
                 if (!empty($sortingKey) && $header === $sortingKey) {
                     //Add the additional attribute id, for getting the updated sort order after the row sorting
                     $this->updateRowAttributes($row, array('id' => 'sorting' . $entity . '_' . $data), true);
                 }
                 $encode = true;
                 if (isset($options['fields']) && isset($options['fields'][$header]) && isset($options['fields'][$header]['showOverview']) && !$options['fields'][$header]['showOverview']) {
                     continue;
                 }
                 if (!empty($sortField) && $header === $sortField) {
                     //Add the additional attribute class, to display the updated sort order after the row sorting
                     $this->updateColAttributes($col, array('class' => 'sortBy' . $sortField));
                 }
                 $origHeader = $header;
                 if (isset($options['fields'][$header]['sorting'])) {
                     $sorting = $options['fields'][$header]['sorting'];
                 } else {
                     if (isset($options['functions']['sorting'])) {
                         $sorting = $options['functions']['sorting'];
                     }
                 }
                 if ($first) {
                     if (isset($options['fields'][$header]['header'])) {
                         $header = $options['fields'][$header]['header'];
                     }
                     if (isset($_ARRAYLANG[$header])) {
                         $header = $_ARRAYLANG[$header];
                     }
                     if (is_array($options['functions']) && isset($options['functions']['sorting']) && $options['functions']['sorting'] && $sorting !== false) {
                         $order = '';
                         $img = '&uarr;&darr;';
                         $sortParamName = !empty($sortBy) ? $entity . 'Order' : 'order';
                         if (isset($_GET[$sortParamName])) {
                             $supOrder = explode('/', $_GET[$sortParamName]);
                             if (current($supOrder) == $origHeader) {
                                 $order = '/DESC';
                                 $img = '&darr;';
                                 if (count($supOrder) > 1 && $supOrder[1] == 'DESC') {
                                     $order = '';
                                     $img = '&uarr;';
                                 }
                             }
                         }
                         $header = '<a href="' . \Env::get('cx')->getRequest()->getUrl() . '&' . $sortParamName . '=' . $origHeader . $order . '" style="white-space: nowrap;">' . $header . ' ' . $img . '</a>';
                     }
                     if ($hasMasterTableHeader) {
                         $this->setCellContents(1, $col, $header, 'td', 0);
                     } else {
                         $this->setCellContents(0, $col, $header, 'th', 0);
                     }
                 }
                 /* We use json to do parse the field function. The 'else if' is for backwards compatibility so you can declare
                  * the function directly without using json. This is not recommended and not working over session */
                 if (isset($options['fields']) && isset($options['fields'][$origHeader]) && isset($options['fields'][$origHeader]['table']) && isset($options['fields'][$origHeader]['table']['parse'])) {
                     $callback = $options['fields'][$origHeader]['table']['parse'];
                     if (is_array($callback) && isset($callback['adapter']) && isset($callback['method'])) {
                         $json = new \Cx\Core\Json\JsonData();
                         $jsonResult = $json->data($callback['adapter'], $callback['method'], array('data' => $data, 'rows' => $rows));
                         if ($jsonResult['status'] == 'success') {
                             $data = $jsonResult["data"];
                         }
                     } else {
                         if (is_callable($callback)) {
                             $data = $callback($data, $rows);
                         }
                     }
                     $encode = false;
                     // todo: this should be set by callback
                 } else {
                     if (is_object($data) && get_class($data) == 'DateTime') {
                         $data = $data->format(ASCMS_DATE_FORMAT);
                     } else {
                         if (isset($options['fields'][$origHeader]) && isset($options['fields'][$origHeader]['type']) && $options['fields'][$origHeader]['type'] == '\\Country') {
                             $data = \Cx\Core\Country\Controller\Country::getNameById($data);
                             if (empty($data)) {
                                 $data = \Cx\Core\Country\Controller\Country::getNameById(204);
                             }
                         } else {
                             if (gettype($data) == 'boolean') {
                                 $data = '<i>' . ($data ? $_ARRAYLANG['TXT_YES'] : $_ARRAYLANG['TXT_NO']) . '</i>';
                                 $encode = false;
                             } else {
                                 if ($data === null) {
                                     $data = '<i>' . $_ARRAYLANG['TXT_CORE_NONE'] . '</i>';
                                     $encode = false;
                                 } else {
                                     if (empty($data)) {
                                         $data = '<i>(empty)</i>';
                                         $encode = false;
                                     }
                                 }
                             }
                         }
                     }
                 }
                 $this->setCellContents($row, $col, $data, 'TD', 0, $encode);
                 $col++;
             }
             if ($this->hasRowFunctions($options['functions'], $virtual)) {
                 if ($first) {
                     $header = 'Functions';
                     if (isset($_ARRAYLANG['TXT_FUNCTIONS'])) {
                         $header = $_ARRAYLANG['TXT_FUNCTIONS'];
                     }
                     if ($hasMasterTableHeader) {
                         $this->setCellContents(1, $col, $header, 'td', 0, true);
                     } else {
                         $this->setCellContents(0, $col, $header, 'th', 0, true);
                     }
                 }
                 $this->updateColAttributes($col, array('style' => 'text-align:right;'));
                 if (empty($options['functions']['baseUrl'])) {
                     $options['functions']['baseUrl'] = clone \Env::get('cx')->getRequest()->getUrl();
                 }
                 $this->setCellContents($row, $col, $this->getFunctionsCode($rowname, $rows, $options['functions'], $virtual), 'TD', 0);
             }
             $first = false;
             $row++;
         }
         // adjust colspan of master-table-header-row
         if ($hasMasterTableHeader) {
             $this->setCellAttributes(0, 0, array('colspan' => $col + is_array($options['functions'])));
             $this->updateRowAttributes(1, array('class' => 'row3'), true);
         }
         // add multi-actions
         if (isset($options['multiActions'])) {
             $multiActionsCode = '
                 <img src="images/icons/arrow.gif" width="38" height="22" alt="^" title="^">
                 <a href="#" onclick="jQuery(\'input[type=checkbox]\').prop(\'checked\', true);return false;">' . $_ARRAYLANG['TXT_SELECT_ALL'] . '</a> /
                 <a href="#" onclick="jQuery(\'input[type=checkbox]\').prop(\'checked\', false);return false;">' . $_ARRAYLANG['TXT_DESELECT_ALL'] . '</a>
                 <img alt="-" title="-" src="images/icons/strike.gif">
             ';
             $multiActions = array('' => $_ARRAYLANG['TXT_SUBMIT_SELECT']);
             foreach ($options['multiActions'] as $actionName => $actionProperties) {
                 $actionTitle = $actionName;
                 if (isset($actionProperties['title'])) {
                     $actionTitle = $actionProperties['title'];
                 } else {
                     if (isset($_ARRAYLANG[$actionName])) {
                         $actionTitle = $_ARRAYLANG[$actionName];
                     }
                 }
                 if (isset($actionProperties['jsEvent'])) {
                     $actionName = $actionProperties['jsEvent'];
                 }
                 $multiActions[$actionName] = $actionTitle;
             }
             $select = new \Cx\Core\Html\Model\Entity\DataElement('cxMultiAction', \Html::getOptions($multiActions), \Cx\Core\Html\Model\Entity\DataElement::TYPE_SELECT);
             // this is not a nice place for this code
             // but we should cleanup this complete class and make
             // it base on templates
             $select->setAttribute('onchange', '
                     var regex = /([a-zA-Z\\/]+):([a-zA-Z\\/]+)/;
                     var matches = jQuery(this).val().match(regex);
                     if (!matches) {
                         return false;
                     }
                     var checkboxes = jQuery(this).closest("table").find("input[type=checkbox]");
                     var activeRows = [];
                     checkboxes.filter(":checked").each(function(el) {
                         activeRows.push(jQuery(this).val());
                     });
                     cx.trigger(matches[1], matches[2], activeRows);
                     checkboxes.prop("checked", false);
                     jQuery(this).val("");
                 ');
             $this->setCellContents($row, 0, $multiActionsCode . $select, 'TD', 0);
             $this->setCellAttributes($row, 0, array('colspan' => $col + is_array($options['functions'])));
         }
         $attrs = array();
     }
     //add the sorting parameters as table attribute
     //if the row sorting functionality is enabled
     $className = 'adminlist';
     if (!empty($sortField)) {
         $className = '\'adminlist sortable\'';
         if (!empty($component)) {
             $attrs['data-component'] = $component;
         }
         if (!empty($entity)) {
             $attrs['data-entity'] = $entity;
         }
         if (!empty($sortOrder)) {
             $attrs['data-order'] = $sortOrder;
         }
         if (!empty($sortField)) {
             $attrs['data-field'] = $sortField;
         }
         if (isset($pagingPos)) {
             $attrs['data-pos'] = $pagingPos;
         }
         $attrs['data-object'] = 'Html';
         $attrs['data-act'] = 'updateOrder';
         if (isset($sortBy['jsonadapter']) && !empty($sortBy['jsonadapter']['object']) && !empty($sortBy['jsonadapter']['act'])) {
             $attrs['data-object'] = $sortBy['jsonadapter']['object'];
             $attrs['data-act'] = $sortBy['jsonadapter']['act'];
         }
     }
     parent::__construct(array_merge($attrs, array('class' => $className, 'width' => '100%')));
 }
コード例 #6
0
 public function __construct()
 {
     parent::__construct();
     $this->setTableClasses(array('table'));
 }
コード例 #7
0
ファイル: html.php プロジェクト: pear/PEAR_Size
 /**
  * Constructor
  *
  * Set class of Table to "pear-size"
  */
 public function __construct()
 {
     parent::__construct(array("class" => "pear-size"));
 }