From 12691e6f8a4ccc9f02dfaef4f9af87ae430d3391 Mon Sep 17 00:00:00 2001 From: avl Date: Tue, 8 Sep 2009 21:06:07 +0300 Subject: [PATCH] misc --- ipf/orm/utils.php | 21 ++++++++++++++++++++- ipf/utils.php | 8 ++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) 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; + } } diff --git a/ipf/utils.php b/ipf/utils.php index f114f19..c56cd9f 100644 --- a/ipf/utils.php +++ b/ipf/utils.php @@ -247,6 +247,14 @@ class IPF_Utils { static function moneyFormat($val){ return number_format((float)$val,2); } + + static function toSlug($slug){ + if ($slug){ + return strtolower(preg_replace('/[^A-Z^a-z^0-9^\/]+/', '-', $slug)); + } + return $slug; + } + } -- 2.49.0