diff --git a/application/controllers/api/v1/system/Phrase.php b/application/controllers/api/v1/system/Phrase.php new file mode 100644 index 000000000..5d4eefdca --- /dev/null +++ b/application/controllers/api/v1/system/Phrase.php @@ -0,0 +1,98 @@ +load->library('PhrasesLib', array('uid' => $this->_getUID())); + } + + /** + * @return void + */ + public function getPhrase() + { + $phrase_id = $this->get('phrase_id'); + + if (isset($phrase_id)) + { + $result = $this->phraseslib->getPhrase($phrase_id); + + $this->response($result, REST_Controller::HTTP_OK); + } + else + { + $this->response(); + } + } + + /** + * @return void + */ + public function getPhrases() + { + $app = $this->get('app'); + $sprache = $this->get('sprache'); + $phrase = $this->get('phrase'); + $orgeinheit_kurzbz = $this->get('orgeinheit_kurzbz'); + $orgform_kurzbz = $this->get('orgform_kurzbz'); + + if (isset($app) && isset($sprache)) + { + $result = $this->phraseslib->getPhrases($app, $sprache, $phrase, $orgeinheit_kurzbz, $orgform_kurzbz); + + $this->response($result, REST_Controller::HTTP_OK); + } + else + { + $this->response(); + } + } + + /** + * @return void + */ + public function postPhrase() + { + if ($this->_validate($this->post())) + { + if (isset($this->post()['phrase_id'])) + { + $result = $this->PhraseModel->update($this->post()['phrase_id'], $this->post()); + } + else + { + $result = $this->PhraseModel->insert($this->post()); + } + + $this->response($result, REST_Controller::HTTP_OK); + } + else + { + $this->response(); + } + } + + private function _validate($phrase = null) + { + return false; + } +} \ No newline at end of file diff --git a/application/libraries/PhrasesLib.php b/application/libraries/PhrasesLib.php index 1cc023863..ee3cb88b5 100644 --- a/application/libraries/PhrasesLib.php +++ b/application/libraries/PhrasesLib.php @@ -9,16 +9,27 @@ class PhrasesLib { - - public function __construct() + /* + * + */ + public function __construct($params = null) { //require_once APPPATH.'config/message.php'; $this->ci =& get_instance(); $this->ci->load->library('parser'); + $this->ci->load->model('system/Phrase_model', 'PhraseModel'); $this->ci->load->model('system/Phrase_inhalt_model', 'PhraseInhaltModel'); + + if (is_array($params) && isset($params['uid'])) + { + $this->ci->PhraseModel->setUID($params['uid']); + $this->ci->PhraseInhaltModel->setUID($params['uid']); + } + $this->ci->load->helper('language'); + $this->ci->load->helper('Message'); //$this->ci->lang->load('fhcomplete'); } @@ -88,6 +99,25 @@ class PhrasesLib $phrase_inhalt = $this->ci->PhraseInhaltModel->loadWhere(array('phrase_inhalt_id' =>$phrase_inhalt_id)); return $phrase_inhalt; } + + /** + * getPhrases() - + * + * @return struct + */ + function getPhrases($app, $sprache, $phrase = null, $orgeinheit_kurzbz = null, $orgform_kurzbz = null) + { + if (isset($app) && isset($sprache)) + { + $result = $this->ci->PhraseModel->getPhrases($app, $sprache, $phrase, $orgeinheit_kurzbz, $orgform_kurzbz); + } + else + { + $result = $this->_error('app and sprache parameters are required'); + } + + return $result; + } /** * loadVorlagetext() - will load the best fitting Template. @@ -156,4 +186,20 @@ class PhrasesLib $text = $this->ci->parser->parse_string($text, $data, TRUE); return $text; } -} + + /* + * + */ + protected function _error($retval = '', $message = EXIT_ERROR) + { + return error($retval, $message); + } + + /* + * + */ + protected function _success($retval, $message = EXIT_SUCCESS) + { + return success($retval, $message); + } +} \ No newline at end of file diff --git a/application/models/system/Phrase_model.php b/application/models/system/Phrase_model.php index 051ef170c..7b845780b 100644 --- a/application/models/system/Phrase_model.php +++ b/application/models/system/Phrase_model.php @@ -1,7 +1,7 @@ pk = 'phrase_id'; } -} + /** + * + */ + public function getPhrases($app, $sprache, $phrase = null, $orgeinheit_kurzbz = null, $orgform_kurzbz = null) + { + // Checks if the operation is permitted by the API caller + if (! $this->fhc_db_acl->isBerechtigt($this->acl['public.tbl_phrase'], 's')) + return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->acl['public.tbl_phrase'], FHC_MODEL_ERROR); + if (! $this->fhc_db_acl->isBerechtigt($this->acl['public.tbl_phrase_inhalt'], 's')) + return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->acl['public.tbl_phrase_inhalt'], FHC_MODEL_ERROR); + + $parametersArray = array('app' => $app, 'sprache' => $sprache); + + $query = 'SELECT phrase, + sprache, + orgeinheit_kurzbz, + orgform_kurzbz, + text + FROM public.tbl_phrase JOIN public.tbl_phrase_inhalt USING (phrase_id) + WHERE app = ? AND sprache = ?'; + + if (isset($phrase)) + { + $parametersArray['phrase'] = $phrase; + + if (is_array($phrase)) + { + $query .= ' AND phrase IN ?'; + } + else + { + $query .= ' AND phrase = ?'; + } + } + + if (isset($orgeinheit_kurzbz)) + { + $parametersArray['orgeinheit_kurzbz'] = $orgeinheit_kurzbz; + $query .= ' AND orgeinheit_kurzbz = ?'; + } + if (isset($orgform_kurzbz)) + { + $parametersArray['orgform_kurzbz'] = $orgform_kurzbz; + $query .= ' AND orgform_kurzbz = ?'; + } + + $result = $this->db->query($query, $parametersArray); + + if (is_object($result)) + return $this->_success($result->result()); + else + return $this->_error($this->db->error(), FHC_DB_ERROR); + } +} \ No newline at end of file