/**
* render plugin for fetching a particular module object
*
* Examples
* {selectmodobject module="AutoCustomer" objecttype="customer" id=4 assign="myCustomer"}
* {selectmodobject module="AutoCocktails" objecttype="recipe" id=12 assign="myRecipe"}
* {selectmodobject recordClass="AutoCocktails_Model_Recipe" id=12 assign="myRecipe"}
*
* Parameters:
* module Name of the module storing the desired object (in DBObject mode)
* objecttype Name of object type (in DBObject mode)
* recordClass Class name of an doctrine record. (in Doctrine mode)
* id Identifier of desired object
* prefix Optional prefix for class names (defaults to PN) (in DBObject mode)
* assign Name of the returned object
*
* @param array $params All attributes passed to this function from the template.
* @param Zikula_View $view Reference to the Zikula_View object.
*
* @return void
*/
function smarty_function_selectmodobject($params, Zikula_View $view)
{
if (isset($params['recordClass']) && !empty($params['recordClass'])) {
$doctrineMode = true;
} else {
// DBObject checks
if (!isset($params['module']) || empty($params['module'])) {
$view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('selectmodobject', 'module')));
}
if (!isset($params['objecttype']) || empty($params['objecttype'])) {
$view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('selectmodobject', 'objecttype')));
}
if (!isset($params['prefix'])) {
$params['prefix'] = 'PN';
}
$doctrineMode = false;
}
if (!isset($params['id']) || empty($params['id']) || !is_numeric($params['id'])) {
$view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('selectmodobject', 'id')));
}
if (!isset($params['assign']) || empty($params['assign'])) {
$view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('selectmodobject', 'assign')));
}
// load object depending on mode: doctrine or dbobject
if (!$doctrineMode) {
if (!ModUtil::available($params['module'])) {
$view->trigger_error(__f('Invalid %1$s passed to %2$s.', array('module', 'selectmodobject')));
}
ModUtil::dbInfoLoad($params['module']);
$classname = "{$params['module']}_DBObject_" . StringUtil::camelize($params['objecttype']);
if (!class_exists($classname) && System::isLegacyMode()) {
// BC check for PNObject old style.
// load the object class corresponding to $params['objecttype']
if (!($class = Loader::loadClassFromModule($params['module'], $params['objecttype'], false, false, $params['prefix']))) {
z_exit(__f('Unable to load class [%s] for module [%s]', array(DataUtil::formatForDisplay($params['objecttype']), DataUtil::formatForDisplay($params['module']))));
}
}
// intantiate object model
$object = new $class();
$idField = $object->getIDField();
// assign object data
// this performs a new database select operation
// while the result will be saved within the object, we assign it to a local variable for convenience
$objectData = $object->get(intval($params['id']), $idField);
if (!is_array($objectData) || !isset($objectData[$idField]) || !is_numeric($objectData[$idField])) {
$view->trigger_error(__('Sorry! No such item found.'));
}
} else {
$objectData = Doctrine_Core::getTable($params['recordClass'])->find($params['id']);
if ($objectData === false) {
$view->trigger_error(__('Sorry! No such item found.'));
}
}
$view->assign($params['assign'], $objectData);
}
/**
* Set a cookie value.
*
* @param string $name Name of cookie.
* @param string $value Value.
* @param integer $expires Unix epoch date for expiry.
* @param string $path Cookie path.
* @param string $domain Domain must be at least .domain.tld.
* @param boolean $secure To set if cookie must only be set over existing https connection.
* @param boolean $signed Override system setting to use signatures.
*
* @return boolean
*/
public static function setCookie($name, $value = '', $expires = null, $path = null, $domain = null, $secure = null, $signed = true)
{
if (!$name) {
return z_exit(__f("Error! In 'setCookie', you must specify at least the cookie name '%s'.", DataUtil::formatForDisplay($name)));
}
if (!is_string($value)) {
return z_exit('setCookie: ' . DataUtil::formatForDisplay($value) . ' must be a string');
}
if (System::getVar('signcookies') && !$signed == false) {
// sign the cookie
$value = SecurityUtil::signData($value);
}
return setcookie($name, $value, $expires, $path, $domain, $secure);
}
/**
* Check permission of action
*
* @param string $module Module name.
* @param string $schema Schema name.
* @param array $obj Array object.
* @param string $permLevel Permission level.
* @param integer $actionId Action Id.
*
* @return boolean
*/
public static function permissionCheck($module, $schema, $obj = array(), $permLevel = 'overview', $actionId = null)
{
// translate permission to something meaningful
$permLevel = self::translatePermission($permLevel);
// test conversion worked
if (!$permLevel) {
return false;
}
// get current user
$currentUser = UserUtil::getVar('uid');
// no user then assume anon
if (empty($currentUser)) {
$currentUser = -1;
}
$function = "{$module}_workflow_{$schema}_permissioncheck";
if (function_exists($function)) {
// function already exists
return $function($obj, $permLevel, $currentUser, $actionId);
}
// test operation file exists
$path = self::_findpath("function.{$schema}_permissioncheck.php", $module);
if (!$path) {
return z_exit(__f("Permission check file [%s] does not exist.", "function.{$schema}_permissioncheck.php"));
}
// load file and test if function exists
include_once $path;
if (!function_exists($function)) {
return z_exit(__f("Permission check function [%s] not defined.", $function));
}
// function must be loaded so now we can execute the function
return $function($obj, $permLevel, $currentUser, $actionId);
}
/**
* Return a nParas paragraphs of random text based on the dictionary.
*
* @param intiger $nParas The number of paragraphs to return to put in the sentence.
* @param string $dict The dictionary to use (a space separated list of words).
* @param intiger $irndS The number of sentences in a paragraph (optional) (default=0=randomlyGenerated).
* @param intiger $irndW The number of words in a sentence (optional) (default=0=randomlyGenerated).
* @param boolean $startCustomary Whether or not to start with the customary phrase (optional) (default=false).
*
* @return The resulting random date string.
*/
public static function getParagraphs($nParas, $dict = '', $irndS = 0, $irndW = 0, $startCustomary = false)
{
if (!$nParas) {
return z_exit(__f('Invalid %1$s passed to %2$s.', array('nParas', 'RandomUtil::getParagraphs')));
}
if (!$dict) {
return z_exit(__f('Invalid %1$s passed to %2$s.', array('dictionary', 'RandomUtil::getParagraphs')));
}
$dictArray = explode(' ', $dict);
$txt = '';
for ($i = 0; $i < $nParas; $i++) {
if (!$irndS) {
$rndS = self::getInteger(3, 7);
} else {
$rndS = $irndS;
}
for ($j = 0; $j < $rndS; $j++) {
if (!$irndW) {
$rndW = self::getInteger(8, 25);
} else {
$rndW = $irndW;
}
$txt .= self::getSentence($rndW, $dictArray);
}
$txt .= "\n";
}
// start with first 5 words
if ($startCustomary) {
$pre = '';
for ($i = 0; $i < 5; $i++) {
$pre .= $dictArray[$i] . ' ';
}
$startLetter = substr($txt, 0, 1);
$txt = $pre . strtolower($startLetter) . substr($txt, 1);
}
return $txt;
}
/**
* Post-process an object's expanded category data to generate relative paths.
*
* @param array &$obj The object we wish to post-process.
* @param array $rootCatsIDs The root category ID for the relative path creation.
* @param boolean $includeRoot Whether or not to include the root folder in the relative path (optional) (default=false).
*
* @return The object with the additionally expanded category data is altered in place and returned
*/
public static function postProcessExpandedObjectCategories(&$obj, $rootCatsIDs, $includeRoot = false)
{
if (!$obj) {
return z_exit(__f('Invalid object in %s', 'postProcessExpandedObjectCategories'));
}
$rootCats = CategoryUtil::getCategoriesByRegistry($rootCatsIDs);
if (empty($rootCats)) {
return false;
}
// if the function was called to process the object categories
if (isset($obj['__CATEGORIES__'])) {
$ak = array_keys($obj['__CATEGORIES__']);
foreach ($ak as $prop) {
CategoryUtil::buildRelativePathsForCategory($rootCats[$prop], $obj['__CATEGORIES__'][$prop], $includeRoot);
}
// else, if the function was called to process the categories array directly
} else {
$ak = array_keys($obj);
foreach ($ak as $prop) {
CategoryUtil::buildRelativePathsForCategory($rootCats[$prop], $obj[$prop], $includeRoot);
}
}
return;
}
/**
* Limit the table name if necessary and prepend the prefix.
*
* When using Oracle the object name may not be longer than 30 chars. Now ADODB uses TRIGGERS and SEQUENCEs to emulate the AUTOINCREMENT
* which eats up to 9 chars (TRIG_SEQ_<prefix>_<tablename>) so we have to limit the length of the table name to
* 30 - 9 - length(prefix) - separator.
* We use this function as a central point to shorten table name (there might be restrictions in ' other RDBMS too). If the resulting tablename is
* empty we will show an error. In this case the prefix is too long.
*
* @param string $table The treated table reference.
* @param string $dbDriverName The driver used for this DB (optional).
*
* @deprecated
* @see Doctrines DBAL layer.
*
* @return boolean
*/
public static function getLimitedTablename($table, $dbDriverName = '')
{
if (!$dbDriverName) {
$dbDriverName = strtolower(Doctrine_Manager::getInstance()->getCurrentConnection()->getDriverName());
}
$prefix = self::getTablePrefix($table);
switch ($dbDriverName) {
case 'oracle':
// Oracle
$maxlen = 30;
// max length for a tablename
$_tablename = $table;
// save for later if we need to show an error
$lenTable = strlen($table);
$lenPrefix = strlen($prefix);
// 10 for length of TRIG_SEQ_ + _
if ($lenTable + $lenPrefix + 10 > $maxlen) {
$table = substr($table, 0, $maxlen - 10 - $lenPrefix);
// same as 20-strlen(), but easier to understand :-)
}
if (empty($table)) {
return z_exit(__f('%1$s: unable to limit tablename [%2$s] because database prefix is too long for Oracle, please shorten it (recommended length is 4 chars)', array(__CLASS__ . '::' . __FUNCTION__, DataUtil::formatForDisplay($_tablename))));
}
break;
default:
// no action necessary, use tablename as is
break;
}
// finally build the tablename
$tablename = $prefix ? $prefix . '_' . $table : $table;
return $tablename;
}
/**
* Load event handler.
*
* @param Zikula_Form_View $view Reference to Zikula_Form_View object.
* @param array &$params Parameters passed from the Smarty plugin function.
*
* @return void
*/
public function load(Zikula_Form_View $view, &$params)
{
if ($this->showEmptyValue != 0) {
$this->addItem('- - -', 0);
}
// switch between doctrine and dbobject mode
if ($this->recordClass) {
$q = Doctrine::getTable($this->recordClass)->createQuery();
if ($this->where) {
if (is_array($this->where)) {
$q->where($this->where[0], $this->where[1]);
} else {
$q->where($this->where);
}
}
if ($this->orderby) {
$q->orderBy($this->orderby);
}
if ($this->pos >= 0) {
$q->offset($this->pos);
}
if ($this->num > 0) {
$q->limit($this->num);
}
$rows = $q->execute();
foreach ($rows as $row) {
$itemLabel = $row[$this->displayField];
if (!empty($this->displayFieldTwo)) {
$itemLabel .= ' (' . $row[$this->displayFieldTwo] . ')';
}
$this->addItem($itemLabel, $row[$this->idField]);
}
} else {
ModUtil::dbInfoLoad($this->module);
// load the object class corresponding to $this->objecttype
$class = "{$this->module}_DBObject_" . StringUtil::camelize($this->objecttype) . 'Array';
if (!class_exists($class) && System::isLegacyMode()) {
if (!($class = Loader::loadArrayClassFromModule($this->module, $this->objecttype, false, $this->prefix))) {
z_exit(__f('Unable to load class [%s] for module [%s]', array(DataUtil::formatForDisplay($this->objecttype, $this->module))));
}
}
// instantiate the object-array
$objectArray = new $class();
// get() returns the cached object fetched from the DB during object instantiation
// get() with parameters always performs a new select
// while the result will be saved in the object, we assign in to a local variable for convenience.
$objectData = $objectArray->get($this->where, $this->orderby, $this->pos, $this->num);
foreach ($objectData as $obj) {
$itemLabel = $obj[$this->displayField];
if (!empty($this->displayFieldTwo)) {
$itemLabel .= ' (' . $obj[$this->displayFieldTwo] . ')';
}
$this->addItem($itemLabel, $obj[$this->idField]);
}
}
parent::load($view, $params);
}
/**
* render plugin for fetching a list of module objects
*
* Examples
* {selectmodobjectarray module="AutoCustomer" objecttype="customer" assign="myCustomers"}
* {selectmodobjectarray module="AutoCocktails" objecttype="recipe" orderby="name desc" assign="myRecipes"}
* {selectmodobjectarray recordClass="AutoCocktails_Model_Recipe" orderby="name desc" assign="myRecipes"}
*
* Parameters:
* module Name of the module storing the desired object (in DBObject mode)
* objecttype Name of object type (in DBObject mode)
* recordClass Class name of an doctrine record. (in Doctrine mode)
* useArrays true to fetch arrays and false to fetch objects (default is true) (in Doctrine mode)
* where Filter value
* orderby Sorting field and direction
* pos Start offset
* num Amount of selected objects
* prefix Optional prefix for class names (defaults to PN) (in DBObject mode)
* assign Name of the returned object
*
* @param array $params All attributes passed to this function from the template.
* @param Zikula_View $view Reference to the Zikula_View object.
*
* @return void
*/
function smarty_function_selectmodobjectarray($params, Zikula_View $view)
{
if (isset($params['recordClass']) && !empty($params['recordClass'])) {
$doctrineMode = true;
} else {
// DBObject checks
if (!isset($params['module']) || empty($params['module'])) {
$view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('selectmodobjectarray', 'module')));
}
if (!isset($params['objecttype']) || empty($params['objecttype'])) {
$view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('selectmodobjectarray', 'objecttype')));
}
if (!isset($params['prefix'])) {
$params['prefix'] = 'PN';
}
$doctrineMode = false;
}
if (!isset($params['assign'])) {
$view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('selectmodobjectarray', 'assign')));
}
// load object depending on mode: doctrine or dbobject
if (!$doctrineMode) {
if (!ModUtil::available($params['module'])) {
$view->trigger_error(__f('Invalid %1$s passed to %2$s.', array('module', 'selectmodobjectarray')));
}
ModUtil::dbInfoLoad($params['module']);
$classname = "{$params['module']}_DBObject_" . StringUtil::camelize($params['objecttype']) . 'Array';
if (!class_exists($classname) && System::isLegacyMode()) {
// BC check for PNObjectArray old style.
// load the object class corresponding to $params['objecttype']
if (!($class = Loader::loadArrayClassFromModule($params['module'], $params['objecttype'], false, $params['prefix']))) {
z_exit(__f('Error! Cannot load module array class %1$s for module %2$s.', array(DataUtil::formatForDisplay($params['module']), DataUtil::formatForDisplay($params['objecttype']))));
}
}
// instantiate the object-array
$objectArray = new $class();
// convenience vars to make code clearer
$where = $sort = '';
if (isset($params['where']) && !empty($params['where'])) {
$where = $params['where'];
}
// TODO: add FilterUtil support here in 2.0
if (isset($params['orderby']) && !empty($params['orderby'])) {
$sort = $params['orderby'];
}
$pos = 1;
if (isset($params['pos']) && !empty($params['pos']) && is_numeric($params['pos'])) {
$pos = $params['pos'];
}
$num = 10;
if (isset($params['num']) && !empty($params['num']) && is_numeric($params['num'])) {
$num = $params['num'];
}
// get() returns the cached object fetched from the DB during object instantiation
// get() with parameters always performs a new select
// while the result will be saved in the object, we assign in to a local variable for convenience.
$objectData = $objectArray->get($where, $sort, $pos - 1, $num);
} else {
$query = Doctrine_Core::getTable($params['recordClass'])->createQuery();
if (isset($params['where']) && !empty($params['where'])) {
if (is_array($params['where'])) {
$query->where($params['where'][0], $params['where'][1]);
} else {
$query->where($params['where']);
}
}
if (isset($params['orderby']) && !empty($params['orderby'])) {
$query->orderBy($params['orderby']);
}
$pos = 0;
if (isset($params['pos']) && !empty($params['pos']) && is_numeric($params['pos'])) {
$pos = $params['pos'];
}
$num = 10;
if (isset($params['num']) && !empty($params['num']) && is_numeric($params['num'])) {
//.........这里部分代码省略.........
/**
* Internal intialization routine.
*
* If $_init is an arrary it is set(), otherwise it is interpreted as a string specifying
* the source from where the data should be retrieved from.
*
* @param mixed $init Initialization value (can be an object or a string directive).
* @param string $key The DB key to use to retrieve the object (optional) (default=null).
* @param strubg $field The field containing the key value (optional) (default=null).
*
* @return void
*/
public function _init($init = null, $key = null, $field = null)
{
if ($this->_objType != 'DBOBJECT') {
$dbtables = DBUtil::getTables();
$tkey = $this->_objType;
$ckey = $this->_objType . "_column";
$this->_table = isset($dbtables[$tkey]) ? $dbtables[$tkey] : null;
$this->_columns = isset($dbtables[$ckey]) ? $dbtables[$ckey] : null;
if ($field) {
$this->_objField = $field;
} else {
$this->_objField = 'id';
}
}
if (!$init) {
return;
}
if (is_array($init)) {
$this->setData($init);
} elseif (is_string($init)) {
switch ($init) {
case self::GET_FROM_DB:
if (!$key) {
return z_exit("Invalid DB-key in DBObject::_init() ...");
}
$this->get($key, $field);
break;
case self::GET_FROM_GET:
case self::GET_FROM_POST:
case self::GET_FROM_REQUEST:
$this->setData($this->getDataFromInput($this->_objPath, null, $init));
break;
case self::GET_FROM_SESSION:
$this->getDataFromSource($_SESSION, $this->_objPath);
break;
case self::GET_FROM_VALIDATION_FAILED:
$this->getDataFromSource($_SESSION['validationFailedObjects'], $this->_objPath);
break;
default:
return z_exit(__f("Error! An invalid initialization directive '%s' found in 'DBObject::_init()'.", $init));
}
} else {
return z_exit(__f("Error! An unexpected parameter type initialization '%s' was encountered in 'DBObject::_init()'.", $init));
}
}
/**
* Return a boolean indicating whether or not the specified field failed validation.
*
* @param string $objectType The (string) object type.
* @param string $field The fieldname.
*
* @return boolean A boolean indicating whether or not the specified field failed validation.
*/
public static function hasValidationErrors($objectType, $field = null)
{
if (!$objectType) {
return z_exit(__f('Empty %1$s passed to %2$s.', array('objectType', 'FormUtil::hasValidationErrors')));
}
if (!$field) {
return z_exit(__f('Empty %1$s passed to %2$s.', array('field', 'FormUtil::hasValidationErrors')));
}
$ve = self::getValidationErrors();
if (isset($ve[$objectType][$field])) {
return (bool) $ve[$objectType][$field];
} else {
return false;
}
}
/**
* Internal intialization routine.
*
* If $init is an arrary it is set(), otherwise it is interpreted as a string specifying
* the source from where the data should be retrieved from.
*
* @param string|array $init Initialization value (can be an object or a string directive) (optional) (default=null).
* @param string $where The where clause to use when retrieving the object array (optional) (default='').
* @param string $orderBy The order-by clause to use when retrieving the object array (optional) (default='').
* @param integer $limitOffset The limiting offset.
* @param integer $limitNumRows The limiting number of rows.
* @param string $assocKey Key field to use for building an associative array (optional) (default=null).
*
* @return void
*/
public function _init($init = null, $where = null, $orderBy = null, $limitOffset = -1, $limitNumRows = -1, $assocKey = null)
{
if ($this->_objType != 'DBOBJECTARRAY') {
$dbtables = DBUtil::getTables();
$tkey = $this->_objType;
$ckey = $tkey . "_column";
$this->_table = isset($dbtables[$tkey]) ? $dbtables[$tkey] : '';
$this->_columns = isset($dbtables[$ckey]) ? $dbtables[$ckey] : '';
}
if (!$init) {
return;
}
if (is_array($init)) {
$this->setData($init);
} elseif (is_string($init)) {
switch ($init) {
case DBObject::GET_FROM_DB:
$this->get($where, $orderBy, $limitOffset, $limitNumRows, $assocKey, true);
break;
case DBObject::GET_FROM_GET:
case DBObject::GET_FROM_POST:
case DBObject::GET_FROM_REQUEST:
$this->setData($this->getDataFromInput($this->_objPath, null, $init));
break;
case DBObject::GET_FROM_SESSION:
$this->getDataFromSource($_SESSION, $this->_objPath);
break;
case DBObject::GET_FROM_VALIDATION_FAILED:
$this->getDataFromSource($_SESSION['validationFailedObjects'], $this->_objPath);
break;
default:
return z_exit(__f("Error! An invalid initialization directive '%s' found in 'DBObjectArray::init()'.", $init));
}
} else {
return z_exit(__f("Error! An unexpected parameter type initialization '%s' was encountered in 'PNObject::init()'.", $init));
}
}
/**
* Load a DBObject extended class from the given module. The given class name is
* prefixed with 'PN' and underscores are removed to produce a proper class name.
*
* @param module The module to load from
* @param base_obj_type The base object type for which to load the class
* @param array If true, load the array class instead of the single-object class.
* @param exitOnError whether or not exit upon error (optional) (default=true)
* @param prefix Override parameter for the default PN prefix (default=PN)
*
* @deprecated since 1.3.0
*
* @return string The ClassName which was loaded from the file
*/
public static function loadClassFromModule($module, $base_obj_type, $array = false, $exitOnError = false, $prefix = 'PN')
{
LogUtil::log(__f('Warning! Function %1$s is deprecated. Please use %2$s instead.', array(__CLASS__ . '#' . __FUNCTION__, 'autoloading'), E_USER_DEPRECATED));
if (!$module) {
return z_exit(__f("Error! Invalid module specification '%s'.", $module));
}
if (!$base_obj_type) {
return z_exit(__f("Error! Invalid 'base_obj_type' specification '%s'.", $base_obj_type));
}
$prefix = (string) $prefix;
if (strpos($base_obj_type, '_') !== false) {
$c = $base_obj_type;
$class = '';
while (($p = strpos($c, '_')) !== false) {
$class .= ucwords(substr($c, 0, $p));
$c = substr($c, $p + 1);
}
$class .= ucwords($c);
} else {
$class = ucwords($base_obj_type);
}
$class = $prefix . $class;
if ($array) {
$class .= 'Array';
}
// prevent unncessary reloading
if (class_exists($class)) {
return $class;
}
$classFiles = array();
$classFiles[] = "config/classes/{$module}/{$class}.class.php";
$classFiles[] = "system/{$module}/classes/{$class}.class.php";
$classFiles[] = "modules/{$module}/classes/{$class}.class.php";
foreach ($classFiles as $classFile) {
$classFile = DataUtil::formatForOS($classFile);
if (is_readable($classFile)) {
if (self::includeOnce($classFile)) {
return $class;
}
if ($exitOnError) {
return z_exit(__f('Error! Unable to load class [%s]', $classFile));
}
return false;
}
}
return false;
}
/**
* Get the IDs of the property registers.
*
* @param string $modname The module name.
* @param string $entityname The entity name for which we wish to get the property for.
*
* @return array The associative field array of register ids for the specified module.
*/
public static function getRegisteredModuleCategoriesIds($modname, $entityname)
{
if (!$modname || !$entityname) {
return z_exit(__f("Error! Received invalid specifications %1{$s}, %2{$s}.", array($modname, $entityname)));
}
$em = \ServiceUtil::get('doctrine')->getManager();
$rCategories = $em->getRepository('Zikula\\Core\\Doctrine\\Entity\\CategoryRegistry')->findBy(array('modname' => $modname, 'entityname' => $entityname));
$fArr = array();
foreach ($rCategories as $rCategory) {
$fArr[$rCategory['property']] = $rCategory['id'];
}
return $fArr;
}
/**
* Adds Join to columns.
*
* Edits the column array for use with a join array.
* We must call it whenever we edited the join information!
*
* @return void
*/
public function addJoinToColumn()
{
if (count($this->_join) <= 0) {
return;
}
// reset columns
$this->resetColumns();
// now add the alias to all fields
foreach ($this->_column as &$a) {
$a = $this->_alias . '.' . $a;
}
$tables = DBUtil::getTables();
// store the fixed aliases
$aliases = array();
foreach ($this->_join as $join) {
if (isset($join['join_alias'])) {
$aliases[] = $join['join_alias'];
}
}
// add fields of all joins
$alias = 'a';
foreach ($this->_join as $join) {
// check if the alias is ok
if (!isset($join['join_alias'])) {
if (in_array($alias, $aliases)) {
do {
$alias++;
} while (in_array($alias, $aliases));
}
$join['join_alias'] = $alias;
}
// process the fields
$jc = isset($tables[$join['join_table'] . '_column']) ? $tables[$join['join_table'] . '_column'] : false;
foreach ($join['join_field'] as $k => $f) {
$a = $join['object_field_name'][$k];
if (isset($this->_column[$a])) {
// Oh, that won't work! Two fields with the same alias!
return z_exit(__f('%s: Invalid join information!', 'FilterUtil'));
}
// so, let's add the field to the column array
$this->_column[$a] = $join['join_alias'] . '.' . ($jc ? $jc[$f] : $f);
}
// now increase the alias ('a'++ = 'b')
$alias++;
}
}
请发表评论