当前位置: 首页>>代码示例>>PHP>>正文


PHP DatabaseFactory::getParentIdColumnName方法代码示例

本文整理汇总了PHP中DatabaseFactory::getParentIdColumnName方法的典型用法代码示例。如果您正苦于以下问题:PHP DatabaseFactory::getParentIdColumnName方法的具体用法?PHP DatabaseFactory::getParentIdColumnName怎么用?PHP DatabaseFactory::getParentIdColumnName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DatabaseFactory的用法示例。


在下文中一共展示了DatabaseFactory::getParentIdColumnName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getJoin

 /**
  * Returns The SQL query join part (shared between getElementList and getElementCount)
  * @param string $mainTableName The main table name
  * @param string $join The join string to apply (ex : 'World IJ Region, Region LJ City, World IJ City')
  * @return array array($request, $joinTableNameList, $joinTableAttachements, $specificJoinConditions, $joinOrder)
  */
 public static function getJoin($mainTableName, $joinCondition)
 {
     $joinSelectRequest = '';
     // SELECT part of the request
     $joinFromRequest = '';
     // FROM part of the request
     // Parses join string (ex : 'World IJ Region, Region LJ User')
     $joinTableNameList = array();
     // Element types array (ex : [World, Region, City])
     $joinOperators = array();
     // Join operators array (ex : [IJ, LJ, RJ])
     $joinLeftTypes = array();
     // Join left types array (ex : [World, Region, World]])
     $joinRightTypes = array();
     // Join right types array (ex : [Region, City, City]])
     $joinConditions = array();
     $joinTableAttachements = array();
     // Join table attachements array (ex : [Region => World, City => [Region, World]])
     // Sets a join per table/condition match, separeted by comma (ie: 0 => Character IJ User, 1 => Character IJ Type)
     $joinList = StringTool::split(DatabaseFactory::JOIN_TABLE_SEPARATOR, $joinCondition);
     $joinOrder = array();
     // join order array (ex: ['Region'=>0, 'User'=>-1, 'Zone'=>1])
     $joinOrder[$mainTableName] = 0;
     // join order init
     foreach ($joinList as &$join) {
         // Parse join conditions and joined tables
         $joinSplit = StringTool::split(DatabaseFactory::JOIN_CONDITIONS_SEPARATOR, $join);
         $joinTables = $joinSplit[0];
         $joinCondition = isset($joinSplit[1]) ? $joinSplit[1] : NULL;
         // Separates left and right parts from spaces (ie: Character IJ Type => array(Character, IJ, Type))
         list($leftSyntax, $joinOperator, $rightSyntax) = StringTool::split(DatabaseFactory::JOIN_SYNTAX_SEPARATOR, $joinTables);
         // Scans left/right part for aliases
         $leftType = $leftSyntax;
         $rightType = $rightSyntax;
         // Gets table names from types
         $leftTableName = DatabaseFactory::getElementTableName($leftType);
         $rightTableName = DatabaseFactory::getElementTableName($rightType);
         if (isset($joinOrder[$leftTableName])) {
             $joinOrder[$rightTableName] = $joinOrder[$leftTableName] + 1;
         } elseif (isset($joinOrder[$rightTableName])) {
             $joinOrder[$leftTableName] = $joinOrder[$rightTableName] - 1;
         } else {
             LogTool::getInstance()->logWarning('Join syntax is not in the right order');
         }
         if ($leftTableName != $mainTableName && !in_array($leftTableName, $joinTableNameList)) {
             $joinTableNameList[] = $leftTableName;
         }
         if ($rightTableName != $mainTableName && !in_array($rightTableName, $joinTableNameList)) {
             $joinTableNameList[] = $rightTableName;
         }
         $joinOperators[] = $joinOperator;
         $joinLeftTypes[] = $leftType;
         $joinRightTypes[] = $rightType;
         $joinConditions[] = $joinCondition;
         $joinTableAttachements[$rightTableName][] = $leftTableName;
     }
     // Builds request field list part
     $usedTableNameList = array($mainTableName);
     $joinSelectRequest .= $mainTableName . '.*';
     foreach ($joinTableNameList as &$joinTableName) {
         $joinSelectRequest .= ', NULL AS ' . $joinTableName . DatabaseFactory::JOIN_TABLE_FIELD_SEPARATOR . ', ' . $joinTableName . '.*';
     }
     // Builds request "FROM" part
     $joinFromRequest .= ' FROM ' . $mainTableName;
     // Builds request join list part
     $specificJoinConditions = FALSE;
     $joinOperatorsCount = count($joinOperators);
     for ($fieldIndex = 0; $fieldIndex < $joinOperatorsCount; $fieldIndex++) {
         $joinOperator = $joinOperators[$fieldIndex];
         $joinLeftType = $joinLeftTypes[$fieldIndex];
         $joinRightType = $joinRightTypes[$fieldIndex];
         $joinLeftTableName = DatabaseFactory::getElementTableName($joinLeftType);
         $joinRightTableName = DatabaseFactory::getElementTableName($joinRightType);
         $joinLeftField = $joinLeftTableName . '_id';
         $joinRightField = DatabaseFactory::getParentIdColumnName($joinLeftType);
         $joinCondition = $joinConditions[$fieldIndex];
         if ($joinCondition === NULL) {
             $joinCondition = $joinRightTableName . '.' . $joinRightField . '=' . $joinLeftTableName . '.' . $joinLeftField;
         } else {
             $specificJoinConditions = TRUE;
         }
         switch ($joinOperator) {
             // Inner join
             case 'IJ':
                 $joinOperatorSql = ' INNER JOIN ';
                 break;
                 // Left join
             // Left join
             case 'LJ':
                 $joinOperatorSql = ' LEFT JOIN ';
                 break;
             default:
                 // Unknown join
                 throw new DatabaseException('Invalid join operator specified : "' . $joinOperator . '"');
//.........这里部分代码省略.........
开发者ID:jonathan-vallet,项目名称:craftanat,代码行数:101,代码来源:DatabaseFactory.class.php

示例2: getParentElement

 /**
  * Gets parent element from an element
  * @param Element $element The child element
  * @param string $parentClass The parent element class
  * @param string $conditions The conditions string to apply
  * @param string $orderBy The order string to apply
  * @return Element The parent element
  */
 public static function getParentElement($element, $parentClass, $conditions = NULL, $orderBy = NULL)
 {
     $logInstance = LogTool::getInstance();
     $logInstance->logDebug('Gets ' . $element->getElementClass() . ' parent ' . $parentClass . ' element...');
     // Gets parent element by type and id
     $parentIdFieldName = DatabaseFactory::getParentIdColumnName($parentClass);
     // Split parent class name for search like people_mother, to get mother_people_id field from People table
     $parentClassNameList = StringTool::split(ElementFactory::TABLE_FIELD_SEPARATOR, $parentClass);
     $parentClass = end($parentClassNameList);
     $parentId = $element->{$parentIdFieldName};
     // Parent element id is null
     if ($parentId === NULL) {
         throw new ElementException('Cannot get ' . $parentClass . ' parent for ' . $element->getElementClass() . ' with id #' . $element->id . ': ' . $parentIdFieldName . ' is NULL');
     }
     return ElementFactory::getElement($parentClass, $parentId, $conditions, $orderBy);
 }
开发者ID:jonathan-vallet,项目名称:craftanat,代码行数:24,代码来源:ElementFactory.class.php


注:本文中的DatabaseFactory::getParentIdColumnName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。