예제 #1
0
 /**
  * Returns elements based on a given query.
  *
  * @access private
  * @param BaseElementType $elementType
  * @param DbCommand       $subquery
  * @param bool            $ordered
  * @return array
  */
 private function _getElementsFromQuery(BaseElementType $elementType, DbCommand $subquery, $ordered = false)
 {
     if ($ordered) {
         $subquery->addSelect('relations.sortOrder');
     }
     // Only get the unique elements (no locale duplicates)
     $query = craft()->db->createCommand()->select('*')->from('(' . $subquery->getText() . ') AS ' . craft()->db->quoteTableName('r'))->group('r.id');
     $query->params = $subquery->params;
     if ($ordered) {
         $query->order('sortOrder');
     }
     $result = $query->queryAll();
     $elements = array();
     foreach ($result as $row) {
         // The locale column might be null since the element_i18n table was left-joined into the query,
         // In that case it should be removed from the $row array so that the default value can be used.
         if (!$row['locale']) {
             unset($row['locale']);
         }
         $elements[] = $elementType->populateElementModel($row);
     }
     return $elements;
 }