/** Add the sql to perform a search. * * @param Gdn_SQLDriver $Sql * @param string $Columns a comma seperated list of columns to search on. */ public function addMatchSql($Sql, $Columns, $LikeRelavenceColumn = '') { if ($this->_SearchMode == 'like') { if ($LikeRelavenceColumn) { $Sql->select($LikeRelavenceColumn, '', 'Relavence'); } else { $Sql->select(1, '', 'Relavence'); } $Sql->beginWhereGroup(); $ColumnsArray = explode(',', $Columns); $First = true; foreach ($ColumnsArray as $Column) { $Column = trim($Column); $Param = $this->Parameter(); if ($First) { $Sql->where("{$Column} like {$Param}", null, false, false); $First = false; } else { $Sql->orWhere("{$Column} like {$Param}", null, false, false); } } $Sql->endWhereGroup(); } else { $Boolean = $this->_SearchMode == 'boolean' ? ' in boolean mode' : ''; $Param = $this->Parameter(); $Sql->select($Columns, "match(%s) against({$Param}{$Boolean})", 'Relavence'); $Param = $this->Parameter(); $Sql->where("match({$Columns}) against ({$Param}{$Boolean})", null, false, false); } }
/** * Joins the query to a permission junction table and limits the results accordingly. * * @param Gdn_SQLDriver $SQL The SQL driver to add the permission to. * @param mixed $Permissions The permission name (or array of names) to use when limiting the query. * @param string $ForeignAlias The alias of the table to join to (ie. Category). * @param string $ForeignColumn The primary key column name of $JunctionTable (ie. CategoryID). * @param string $JunctionTable * @param string $JunctionColumn */ public function sQLPermission($SQL, $Permissions, $ForeignAlias, $ForeignColumn, $JunctionTable = '', $JunctionColumn = '') { $Session = Gdn::session(); // Figure out the junction table if necessary. if (!$JunctionTable && StringEndsWith($ForeignColumn, 'ID')) { $JunctionTable = substr($ForeignColumn, 0, -2); } // Check to see if the permission is disabled. if (c('Garden.Permission.Disabled.' . $JunctionTable)) { if (!$Session->checkPermission($Permissions)) { $SQL->where('1', '0', false, false); } } elseif ($Session->UserID <= 0 || is_object($Session->User) && $Session->User->Admin != '1') { $SQL->Distinct()->join('Permission _p', '_p.JunctionID = ' . $ForeignAlias . '.' . $ForeignColumn, 'inner')->join('UserRole _ur', '_p.RoleID = _ur.RoleID', 'inner')->beginWhereGroup()->where('_ur.UserID', $Session->UserID); if (!is_array($Permissions)) { $Permissions = array($Permissions); } $SQL->beginWhereGroup(); foreach ($Permissions as $Permission) { $SQL->where('_p.`' . $Permission . '`', 1); } $SQL->endWhereGroup(); } else { // Force this method to play nice in case it is used in an or clause // (ie. it returns true in a sql sense by doing 1 = 1) $SQL->where('1', '1', false, false); } return $SQL; }