public static function load($parent, $childs, $keyField, array $ids, $foreignKey = null)
 {
     self::parseItemStatement($parent, $parentItemName, $parentFields);
     Lms_Item::initStructure(Lms_Item::getClassName($parentItemName));
     $struct = Lms_Item::getStruct($parentItemName);
     if (count($parentFields)) {
         if ($foreignKey && !in_array($foreignKey, $parentFields)) {
             array_unshift($parentFields, $foreignKey);
         }
         foreach ($struct->getPk() as $fieldName) {
             if (!in_array($fieldName, $parentFields)) {
                 array_unshift($parentFields, $fieldName);
             }
         }
     }
     if (!$foreignKey && $struct->hasIndex($keyField)) {
         $foreignKey = $keyField;
     }
     $newScalarPKs = self::_exec($parentItemName, $parentFields, $keyField, $ids, $foreignKey);
     foreach ($childs as $child) {
         self::parseItemStatement($child, $childItemName, $childFields);
         Lms_Item::initStructure(Lms_Item::getClassName($childItemName));
         $relation = Lms_Item_Relations::get($parentItemName, $childItemName);
         if (!$relation) {
             $linkatorItemName = Lms_Item::getLinkator($parentItemName, $childItemName);
             $subRelation = Lms_Item_Relations::get($parentItemName, $linkatorItemName);
             $newKeys = array_unique(Lms_Item_Store::getAllFieldValues($newScalarPKs, Lms_Item::getTableName($parentItemName), $subRelation['parent_key']));
             self::load($linkatorItemName, array($child), $subRelation['foreign_key'], $newKeys, $subRelation['foreign_key']);
         } else {
             if (count($childFields)) {
                 if ($relation && !in_array($relation['foreign_key'], $childFields)) {
                     array_unshift($childFields, $relation['foreign_key']);
                 }
                 $struct = Lms_Item::getStruct($childItemName);
                 foreach ($struct->getPk() as $fieldName) {
                     if (!in_array($fieldName, $childFields)) {
                         array_unshift($childFields, $fieldName);
                     }
                 }
             }
             $newKeys = array_unique(Lms_Item_Store::getAllFieldValues($newScalarPKs, Lms_Item::getTableName($parentItemName), $relation['parent_key']));
             self::_exec($childItemName, $childFields, $relation['foreign_key'], $newKeys, $relation['foreign_key']);
         }
     }
 }
 public static function rowToItem($row, $itemName = null)
 {
     if (!$row) {
         return null;
     }
     if (!$itemName) {
         $itemName = Lms_Item::getCallingItemName();
     }
     Lms_Item::initStructure(Lms_Item::getClassName($itemName));
     $simplePk = Lms_Item::getSimplePk($itemName);
     $tableName = Lms_Item::getTableName($itemName);
     Lms_Item_Store::setValues($tableName, $row[$simplePk], $row, true);
     return Lms_Item::create($itemName, $row[$simplePk]);
 }
 public static function getTableName($itemName)
 {
     $className = Lms_Item::getClassName($itemName);
     return call_user_func(array($className, 'getTableName'));
 }