Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
generic_usort.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * Apply sort by family
8  *
9  * @author Anakeen
10  * @version $Id: generic_usort.php,v 1.6 2006/04/28 14:34:02 eric Exp $
11  * @package FDL
12  * @subpackage
13  */
14 /**
15  */
16 
17 include_once ("FDL/Class.Doc.php");
18 include_once ("GENERIC/generic_util.php");
19 // -----------------------------------
21 {
22  // -----------------------------------
23  // get all parameters
24  $aorder = $action->getArgument("aorder"); // id for controlled object
25  $catg = $action->getArgument("catg"); // id for controlled object
26  $onefamOrigin = $action->getArgument("onefam"); // onefam origin
27  $tab = $action->getArgument("tab", 0); // tab index
28  $dirid = $action->getArgument("dirid", 0); // collection id
29  $sfamid = '';
30  if ($catg) {
31  $dir = new_doc($action->dbaccess, $catg);
32  if ($dir->isAlive()) {
33  $sfamid = $dir->getRawValue("se_famid");
34  }
35  }
36 
37  $action->parent->param->Set("GENERIC_USORT", setUsort($action, $aorder, $sfamid) , Param::PARAM_USER . $action->user->id, $action->parent->id);
38 
39  $famid = getDefFam($action);
40  if ($tab) {
41  redirect($action, $action->GetParam("APPNAME", "GENERIC") , "GENERIC_TAB&onefam=$onefamOrigin&catg=$catg&famid=$famid&tab=$tab", $action->GetParam("CORE_STANDURL"));
42  } else {
43  redirect($action, $action->GetParam("APPNAME", "GENERIC") , "GENERIC_LIST&onefam=$onefamOrigin&dirid=$dirid&tab=0&famid=$famid&tab=$tab", $action->GetParam("CORE_STANDURL"));
44  }
45 }
46 
47 function setUsort(Action & $action, $aorder, $famid = "")
48 {
49  if (!$famid) $famid = getDefFam($action);
50  $dbaccess = $action->dbaccess;
51 
52  $fdoc = new_Doc($dbaccess, $famid);
53 
54  $pu = $action->GetParam("GENERIC_USORT");
55  $tr = array();
56  if ($pu) {
57  // disambled parameter
58  $tu = explode("|", $pu);
59 
60  foreach ($tu as $v) {
61  list($afamid, $uorder, $sqlorder) = explode(":", $v);
62  $tr[$afamid] = $uorder . ":" . $sqlorder;
63  }
64  }
65 
66  if (!isset($tr[$famid])) {
67  /*
68  * Handle the case when no order is memorized and "revdate"
69  * is clicked: invert revdate sort order
70  */
71  /* This should be in sync with the default value $def from getDefUSort() */
72  if ($aorder == 'revdate') {
73  $aorder = '-revdate';
74  } elseif ($aorder == '-revdate') {
75  $aorder = 'revdate';
76  }
77  }
78 
79  $sqlorder = $aorder;
80  if (isset($aorder[0]) && $aorder[0] == "-") $sqlorder = substr($aorder, 1);
81  $a = $fdoc->getAttribute($sqlorder);
82  if ($a === false) {
83  $a = $fdoc->getPropertyValue($sqlorder);
84  }
85  if ($a && isset($a->type) && $a->type == "text") $sqlorder = "lower($sqlorder)";
86  if (isset($aorder[0]) && $aorder[0] == "-") $sqlorder.= " desc";
87 
88  $tr[$famid] = $aorder . ":" . $sqlorder;
89  // rebuild parameter
90  $tu = array();
91  reset($tr);
92  foreach ($tr as $k => $v) {
93  $tu[] = "$k:$v";
94  }
95  return implode("|", $tu);
96 }
global $action
print< H1 > Check Database< i > $dbaccess</i ></H1 > $a
Definition: checklist.php:45
setUsort(Action &$action, $aorder, $famid="")
getDefFam(Action &$action)
Set($name, &$parent)
generic_usort(Action &$action)
const PARAM_USER
Definition: Class.Param.php:34
new_Doc($dbaccess, $id= '', $latest=false)
$dir
Definition: resizeimg.php:144
static getArgument($k, $def= '')
$dbaccess
Definition: checkVault.php:17
← centre documentaire © anakeen