/** * Get the current max objects Order (search order field then return value) * @param array() $searchConditions to construct the where clause (default none) * format array("database column name" => "database value", ... => ..., ...) * @param boolean $public the data location wich needed (defaul false : edited) * @return integer the max order * @access public */ function getOrderMax($whereConditions = array(), $public = false) { //search order field if ($this->_tableData['order'][0] == 'order') { $currentOrder = $this->_tableData['order'][1]; $orderFieldName = 'order' . $this->_tableSufix; } else { foreach ($this->_tableData as $label => $aData) { if ($aData[0] == 'order') { $currentOrder = $this->_tableData[$label][1]; $orderFieldName = $label . $this->_tableSufix; } } $this->raiseError("Can not found order field in database"); return false; } //from if ($this->_hasResource()) { $from = $public ? $this->_tableName . '_public' : $this->_tableName . '_edited'; } else { $from = $this->_tableName; } //where clause if (count($whereConditions)) { $where = "where "; $count = 0; foreach ($whereConditions as $label => $condition) { $where .= $count ? " and " : ''; $count++; $where .= " " . $label . $this->_tableSufix . "='" . SensitiveIO::sanitizeSQLString($condition) . "' "; } } $sql = "\n\t\t\tselect\n\t\t\t\tcount(*),\n\t\t\t\tmax(" . $orderFieldName . ")\n\t\t\tfrom\n\t\t\t\t" . $from . "\n\t\t\t" . $where . "\n\t\t"; $q = new CMS_query($sql); if ($q->hasError()) { $this->raiseError("Database query error"); return false; } else { $max = $q->getarray(); return $max["max(" . $orderFieldName . ")"]; } }