mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-19 16:02:15 +00:00
- Added Phrase controller
- Phrase controller has the method getPhrases() to get sentences translated into several languages - Added method getPhrases to PhrasesLib - Modified the PhrasesLib constructor to pass the uid to the models - Added method getPhrases to Phrase_model
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
/**
|
||||
* FH-Complete
|
||||
*
|
||||
* @package FHC-API
|
||||
* @author FHC-Team
|
||||
* @copyright Copyright (c) 2016, fhcomplete.org
|
||||
* @license GPLv3
|
||||
* @link http://fhcomplete.org
|
||||
* @since Version 1.0
|
||||
* @filesource
|
||||
*/
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if (!defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
class Phrase extends APIv1_Controller
|
||||
{
|
||||
/**
|
||||
* Phrase API constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->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;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
class Phrase_model extends DB_Model
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
@@ -12,4 +12,57 @@ class Phrase_model extends DB_Model
|
||||
$this->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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user