Ejemplo n.º 1
0
 /**
  * Возвращает скаляризованный ключ индекса $indexName таблицы $tableName
  * для поля $scalarPK
  * Например, 
  * INSERT INTO files(file_id, movie_id, path) (1, 1000, '/file');
  * $struct->addIndex('movie_id', array('movie_id'));
  * echo Lms_Item_Store::getScalarIndexKey('files', 'movie_id', 1); //1000
  * @param string $indexName
  * @param string $scalarPK
  * @return int/string
  */
 private static function getScalarIndexKey($tableName, $indexName, $scalarPK)
 {
     $struct = self::getStruct($tableName);
     $index = $struct->getIndex($indexName);
     $indexKey = array();
     try {
         foreach ($index['fields'] as $fieldName) {
             $indexKey[$fieldName] = self::getValue($tableName, $scalarPK, $fieldName);
         }
     } catch (Lms_Item_Store_FieldValueNotExistsException $e) {
         return null;
     }
     return Lms_Item_Scalar::scalarize($indexKey);
 }
 public function storeData($data)
 {
     $this->_buffer = $data;
     $this->_scalarPkValue = Lms_Item_Scalar::scalarize($this->_getAssocPkValue(self::FROM_BUFFER));
     Lms_Item_Store::setValues($this->getTableName(), $this->_scalarPkValue, $data);
 }
 private static function _fillData($tableName, $rows, $foreignKey)
 {
     $newScalarPKs = array();
     if (!count($rows)) {
         return $newScalarPKs;
     }
     $struct = Lms_Item_Store::getStruct($tableName);
     $pk = $struct->getPk();
     for ($i = count($rows) - 1; $i >= 0; $i--) {
         if (is_array($pk)) {
             $assocPK = array();
             foreach ($pk as $pkFieldName) {
                 $assocPK[$pkFieldName] = $rows[$i][$pkFieldName];
             }
             $scalarPk = Lms_Item_Scalar::scalarize($assocPK);
         } else {
             $scalarPk = $rows[$i][$pk];
         }
         $newScalarPKs[] = $scalarPk;
         Lms_Item_Store::setValues($tableName, $scalarPk, $rows[$i], true);
         if ($foreignKey && isset($rows[$i][$foreignKey])) {
             $indexKey = $rows[$i][$foreignKey];
             Lms_Item_Store::setIndexStatus($tableName, $foreignKey, $indexKey, Lms_Item_Struct::FULL_INDEX);
         }
     }
     Lms_Item_Store::rebuildIndex($tableName);
     return $newScalarPKs;
 }