public function getOptions($_model = '', $_field = '', $_action = '', $_function = '', $_smarty_params = array(), $_depends = array(), $_identifierField = '') { if (empty($_action)) { $_action = 'getOptions'; } if (empty($_function)) { $_function = 'getOptions'; } if (empty($_model)) { $_model = $this->_templateobject; } elseif (is_string($_model)) { // $_model=new $_model; $_model = DataObjectFactory::Factory($_model); } if (empty($_field)) { if (!empty($this->_data['field'])) { $_field = $this->_data['field']; } else { return array(); } } $field_options = new fieldOptions(); if (isset($this->_data['autocomplete'])) { $field_options->_autocomplete = true; $field_options->_autocomplete_value = $this->_data['id']; } if (!empty($_depends)) { $field_options->_depends = $_depends; } elseif (!empty($this->_data['depends'])) { $array = explode(',', $this->_data['depends']); foreach ($array as $key) { if (!empty($this->_data[$key])) { $_depends[$key] = $this->_data[$key]; } } if (empty($_smarty_params['depends'])) { $_smarty_params['depends'] = $this->_data['depends']; } $field_options->_depends = $_depends; } if (!empty($_identifierField)) { $field_options->_identifierField = $_identifierField; } elseif (!empty($this->_data['identifierfield'])) { $field_options->_identifierField = explode(',', $this->_data['identifierfield']); } if (isset($_smarty_params['use_collection']) && $_smarty_params['use_collection']) { $field_options->_use_collection = true; } if (isset($this->_data['use_collection']) && $this->_data['use_collection']) { $field_options->_use_collection = true; } $field_options->_modules = $this->_modules; $field_options->_controller = $this->name; $field_options->_action = $_action; $_model->setOptions($_field, $field_options); $options = $_model->{$_function}($_field); // // Need to return in one of four ways:- // 1) response to autocomplete request - return encoded data // 2) indirect ajax request - return html to calling function // 3) direct ajax request - echo html and exit // 4) not an ajax call - just return the data array // if (isset($this->_data['autocomplete']) && $options->_autocomplete) { // 1) response to autocomplete request is autocomplete // - return encoded data echo json_encode(DataObject::toJSONArray($options->_data)); exit; } elseif (isset($this->_data['ajax']) || isset($this->_data['ajax_call'])) { $this->view->set('model', $_model); $this->view->set('attribute', $_field); foreach ($_smarty_params as $key => $value) { $this->view->set($key, $value); } if (current($options->_data) == 'None') { $this->view->set('nonone', true); } $html = $this->view->fetch('select'); if (isset($this->_data['ajax_call'])) { // 2) indirect ajax request - return html to calling function return $html; } else { // 3) direct ajax request - echo html and exit $output[$_field] = array('data' => $html, 'is_array' => is_array($html)); $this->view->set('data', $output); echo $this->view->fetch('ajax_multiple'); exit; } } else { // 4) not an ajax call - just return the data array return $options->_data; } }