123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- <?php
- class CrudTemplate {
- function __construct($type) {
-
- $this->crud_type = $type;
-
- $this->variables = array();
-
- $this->module = $type;
-
-
- $this->children_type = false;
-
- $this->children_categories = false;
-
- $this->icon_var = false;
-
- $this->embed = false;
-
-
- $this->list_order = false;
-
- $this->list_order_direction = 'ASC';
-
- $this->list_tabs = false;
- }
-
- function getStringPrefix() {
- return "$this->module:$this->crud_type";
- }
-
- function getDefaultValue($name, $default=NULL) {
- if (isset($this->variables[$name]) && isset($this->variables[$name]['default_value'])) {
- return $this->variables[$name]['default_value'];
- }
- return $default;
- }
-
- function getVariableData($name) {
- if (isset($this->variables[$name])) {
- return $this->variables[$name];
- }
- }
-
- function getDateTabContent() {
- $tab_var = $this->variables[$this->list_tabs];
- $first_option = $tab_var->options[0];
- $selected_tab = get_input('filter', $first_option);
- $container_guid = elgg_get_page_owner_guid();
- $options = array(
- 'type' => 'object',
- 'subtype' => $this->crud_type,
- 'limit' => 10,
-
- 'container_guid' => $container_guid,
- 'full_view' => false,
- );
- if ($selected_tab == 'next') {
- $operand = '>=';
- $direction = 'ASC';
- $metadata_search = true;
- }
- elseif ($selected_tab == 'previous') {
- $operand = '<';
- $direction = 'DESC';
- $metadata_search = true;
- }
- if ($metadata_search) {
- $options['metadata_name_value_pairs'] = array(
- array('name' => 'date',
- 'operand' => $operand,
- 'value' => time())
- );
- $metadata_search = true;
- $options['order_by_metadata'] = array('name' => 'date',
- 'direction' => $direction);
- $content = elgg_list_entities_from_metadata($options);
- }
- else {
- $content = elgg_list_entities($options);
- }
- if (!$content) {
- $content = elgg_echo($this->module.':'.$this->crud_type.':none');
- }
- return $content;
- }
-
- function getListTabContent() {
- if ($this->list_tabs == 'date') {
- return $this->getDateTabContent();
- }
- $tab_var = $this->variables[$this->list_tabs];
- $first_option = $tab_var->options[0];
- $selected_tab = get_input('filter', $first_option);
- $container_guid = elgg_get_page_owner_guid();
- $options = array(
- 'type' => 'object',
- 'subtype' => $this->crud_type,
- 'limit' => 10,
-
- 'container_guid' => $container_guid,
- 'full_view' => false,
- );
- if ($this->list_tabs && $selected_tab != 'all') {
- $metadata_search = true;
- $options['metadata_name_value_pairs'] = array(
- array('name' => $this->list_tabs,
- 'value' => $selected_tab)
- );
- }
- if ($this->list_order) {
- $metadata_search = true;
- $options['order_by_metadata'] = array('name' => $this->list_order,
- 'direction' => $this->list_order_direction);
- }
- if ($metadata_search) {
- $content = elgg_list_entities_from_metadata($options);
- }
- else {
- $content = elgg_list_entities($options);
- }
- if (!$content) {
- $content = elgg_echo($this->module.':'.$this->crud_type.':none');
- }
- return $content;
- }
-
- function getDateTabFilter() {
- $tab_var = $this->variables[$this->list_tabs];
- $first_option = $tab_var->options[0];
- $selected_tab = get_input('filter', $first_option);
- $filter = elgg_view('crud/crud_date_sort_menu',
- array('selected' => $selected_tab,
- 'crud' => $this));
- return $filter;
- }
-
- function getListTabFilter() {
- if (!$this->list_tabs)
- return '';
- if ($this->list_tabs == 'date')
- return $this->getDateTabFilter();;
- $tab_var = $this->variables[$this->list_tabs];
- $first_option = $tab_var->options[0];
- $selected_tab = get_input('filter', $first_option);
- $filter = elgg_view('crud/crud_sort_menu',
- array('selected' => $selected_tab,
- 'crud' => $this));
- return $filter;
- }
- }
|