]> git.andy128k.dev Git - ipf.git/commitdiff
misc
authoravl <alex.litovchenko@gmail.com>
Tue, 8 Sep 2009 18:06:07 +0000 (21:06 +0300)
committeravl <alex.litovchenko@gmail.com>
Tue, 8 Sep 2009 18:06:07 +0000 (21:06 +0300)
ipf/orm/utils.php
ipf/utils.php

index 371f5bea67beb4195a6053a57a629f37864c5ea6..72c2a1a9af546d2a7a613df125526618d7923aaa 100644 (file)
@@ -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;
+    }
 }
 
index f114f19f70d3a8ad7cc56c4de0ed3df74c924fad..c56cd9f9370ca5125a20e1d76ead85accf419ffa 100644 (file)
@@ -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;
+    }
+    
 
 }