Ver código fonte

added order to AccessGroup; added cese insensitive V::geti

Piotr Labudda 9 anos atrás
pai
commit
3be8cc6340

+ 13 - 0
SE/se-lib/Schema/AccessGroupStorageAcl.php

@@ -116,6 +116,19 @@ class Schema_AccessGroupStorageAcl extends Core_AclBase {// Read only class
       }
     }
 
+    $orderBy = strtolower(V::get('order_by', 'id', $params));
+    $orderDir = strtolower(V::get('order_dir', 'desc', $params));
+    if (!in_array($orderBy, ['id', 'name', 'uid'])) throw new HttpException("Bad Request - wrong or missing order by", 400);
+    if (!in_array($orderDir, ['desc', 'asc'])) throw new HttpException("Bad Request - wrong or missing order dir", 400);
+    usort($items, function ($a, $b) use ($orderBy, $orderDir) {
+      if ('desc' == $orderDir) {
+        return (V::geti($orderBy, '', $a) > V::geti($orderBy, '', $b)) ? -1 : 1;
+      } else if ('asc' == $orderDir) {
+        return (V::geti($orderBy, '', $a) > V::geti($orderBy, '', $b)) ? 1 : -1;
+      }
+      return 0;
+    });
+
     if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems \$items:";print_r($items);echo "\n";}
     return $items;
   }

+ 3 - 2
SE/se-lib/TableAjax.php

@@ -3613,14 +3613,15 @@ jQuery(document).ready(function(){
 					}
 
 					jQuery.ajax({
-						url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>&_task=CREATE',
+						url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>&_task=CREATE',// TODO: mv to ViewTableAjax route
+						// TODO: url: 'index.php?_route=ViewTableAjax&_task=createForm&namespace=<?= $acl->getNamespace(); ?>&_hash=<?php echo $this->_htmlID; ?>',
 						type: 'GET',
 						dataType: 'text',
 						data: reqData,
 						async: true,
 						success: function(data) {
 							taskCnt.removeClass('AjaxTable-loading');
-							//console.log('request finished L.<?php echo __LINE__; ?>');
+							// console.log('request finished L.<?php echo __LINE__; ?>', data);
 							jQuery(data).appendTo(taskCnt);
 
 							initDateTimePicker(taskCnt);

+ 12 - 0
SE/se-lib/V.php

@@ -7,6 +7,18 @@
  */
 class V {
 
+	/**
+	 * Get variable from array or object - case insensitive
+	 */
+	public static function geti($name, $default, $from, $type = '', $filterCallback = null) {
+		$lowerFrom = array();
+		if (!is_object($from) && !is_array($from)) throw new Exception("Bad param - from must be array or object");
+		foreach ((array)$from as $fieldName => $value) {
+			$lowerFrom[ strtolower($fieldName) ] = $value;
+		}
+		return V::get($name, $default, $lowerFrom, $type, $filterCallback);
+	}
+
 	/**
 	 * Get variable from array or object.
 	 */