Exemplo n.º 1
0
 protected function setValue(IDataSettableStatement $aStatement, $keys, $names = null, Model $aDataSource, $sTableName = null)
 {
     $keys = array_values((array) $keys);
     if ($names) {
         $names = array_values((array) $names);
     } else {
         $names = $keys;
     }
     if ($sTableName) {
         $sTableName = "`{$sTableName}`.";
     }
     foreach ($keys as $idx => $sKey) {
         $aStatement->setData("{$sTableName}`{$sKey}`", $aDataSource->data($names[$idx]));
     }
 }
Exemplo n.º 2
0
 /**
  * @return ModelList
  */
 public static function belongsModelList(Model $aModel)
 {
     return $aModel->data('__belongsModelList');
 }
Exemplo n.º 3
0
 /**
  *
  * @param Model $aModel 子分类的model
  * @return ModelList 所有子分类的model,排序高级分类在前,子分类在后
  */
 public static function getChildren(Model $aModel)
 {
     if (!$aModel) {
         return;
     }
     $aPrototype = clone $aModel->prototype();
     $aPrototype->addOrderBy('lft');
     $aParentsModelList = $aPrototype->createModel(true);
     $aParentsModelList->loadSql("lft < @1 and rgt > @2", $aModel->lft, $aModel->rgt);
     return $aParentsModelList;
 }
Exemplo n.º 4
0
 private function setAssociatedModelData(Model $aModel, Model $aChildModel, array $arrFromKeys, array $arrToKeys)
 {
     foreach ($arrToKeys as $nIdx => $sKey) {
         if ($aChildModel->isList()) {
             $value = $aModel->data($arrFromKeys[$nIdx]);
             foreach ($aChildModel->childIterator() as $aChildChildModel) {
                 $aChildChildModel->setData($sKey, $value, false);
             }
         } else {
             $aChildModel->setData($sKey, $aModel->data($arrFromKeys[$nIdx]), false);
         }
     }
 }
Exemplo n.º 5
0
 private function queryForMultitermAssoc(DB $aDB, Association $aMultitermAssoc, array &$arrDataSheet, $nRowIdx)
 {
     $aToPrototype = $aMultitermAssoc->toPrototype();
     $aFromPrototype = $aMultitermAssoc->fromPrototype();
     // 根据上一轮查询设置条件
     if ($aMultitermAssoc->isType(Association::hasMany)) {
         $aRestraction = $this->makeResrictionForAsscotion($arrDataSheet[$nRowIdx], $aFromPrototype->path(), $aMultitermAssoc->fromKeys(), $aToPrototype->sqlTableAlias(), $aMultitermAssoc->toKeys());
     } else {
         if ($aMultitermAssoc->isType(Association::hasAndBelongsToMany)) {
             $aRestraction = $this->makeResrictionForAsscotion($arrDataSheet[$nRowIdx], $aFromPrototype->path(), $aMultitermAssoc->fromKeys(), $aMultitermAssoc->bridgeSqlTableAlias(), $aMultitermAssoc->toBridgeKeys());
         } else {
             throw new ORMException("what's this?");
         }
     }
     // 新建的一个记录表
     $sheet =& Model::dataSheet($arrDataSheet, $nRowIdx, $aToPrototype->name(), true);
     $this->execute($aToPrototype, $sheet, $aRestraction, array($aToPrototype->limitLength(), $aToPrototype->limitFrom()), $aDB);
 }