From: avl Date: Tue, 8 Sep 2009 18:06:07 +0000 (+0300) Subject: misc X-Git-Tag: 0.6~150 X-Git-Url: https://git.andy128k.dev/?a=commitdiff_plain;h=8bdef03667bb52f16d9fa1fba3efd3f82cf4a576;p=ipf-legacy-orm.git misc --- diff --git a/ipf/orm/utils.php b/ipf/orm/utils.php index 371f5be..72c2a1a 100644 --- a/ipf/orm/utils.php +++ b/ipf/orm/utils.php @@ -124,6 +124,25 @@ class IPF_ORM_Utils { return implode("\n",$r); } - + static function setOrd($obj, $field_name='ord', $where=null, $params=null){ + $res = null; + if ($where){ + $res = IPF_ORM_Query::create() + ->select("max($field_name) as max_ord") + ->from($obj->getTable()->getClassnameToReturn()) + ->where($where, $params) + ->execute(); + } + else{ + $res = IPF_ORM_Query::create() + ->select("max($field_name) as max_ord") + ->from($obj->getTable()->getClassnameToReturn()) + ->execute(); + } + if (isset($res[0]['max_ord'])) + $obj->$field_name = (int)$res[0]->max_ord + 1; + else + $obj->$field_name = 1; + } }