コード例 #1
0
 /**
  * Gets all elements by class
  * @param string $elementClass The element type searched
  * @param string $conditions The conditions string to apply (ex : Region.x < 10 AND World.size = 500)
  * @param string $orderBy The order string to apply (ex : 'Region.x, City.name DESC')
  * @return array The found element list array
  */
 public static function &getElementList($elementClass, $conditions = NULL, $orderBy = NULL, $join = NULL)
 {
     $logInstance = LogTool::getInstance();
     $logInstance->logDebug('Gets ' . $elementClass . ' list (conditions="' . $conditions . '", order="' . $orderBy . '")');
     // Tries to get element list from cache
     if ($join === NULL) {
         try {
             return CacheFactory::getElementList($elementClass, $conditions, $orderBy);
         } catch (ElementFactoryException $e) {
         }
     }
     // Gets element list from database
     list($elementList, $retrievedElementList) = DatabaseFactory::getElementList($elementClass, $conditions, $orderBy, $join);
     // Adds result to cache
     CacheFactory::addElementList($elementClass, $elementList, $conditions, $orderBy);
     if ($join !== NULL) {
         foreach ($retrievedElementList as $mainElementTableName => $mainElementElementList) {
             foreach ($mainElementElementList as $mainElementId => $attachedElementList) {
                 foreach ($attachedElementList as $childElementTableName => $childElementList) {
                     // Builds parent id conditions to cache list
                     $parentIdFieldName = DatabaseFactory::getParentIdColumnName(DatabaseFactory::getElementClassName($mainElementTableName));
                     $childRequestConditions = $childElementTableName . '.' . $parentIdFieldName . '=' . $mainElementId;
                     CacheFactory::addElementList(DatabaseFactory::getElementClassName($childElementTableName), $childElementList, $childRequestConditions, $orderBy);
                 }
             }
         }
     }
     return $elementList;
 }