/** * Applies WHERE conditions to a DbCommand query for folders. * * @access private * @param DbCommand $query * @param FolderCriteriaModel $criteria */ private function _applyFolderConditions($query, FolderCriteriaModel $criteria) { $whereConditions = array(); $whereParams = array(); if ($criteria->id) { $whereConditions[] = DbHelper::parseParam('f.id', $criteria->id, $whereParams); } if ($criteria->sourceId) { $whereConditions[] = DbHelper::parseParam('f.sourceId', $criteria->sourceId, $whereParams); } if ($criteria->parentId) { // Set parentId to null if we're looking for folders with no parents. if ($criteria->parentId == FolderCriteriaModel::AssetsNoParent) { $criteria->parentId = null; } $whereConditions[] = DbHelper::parseParam('f.parentId', array($criteria->parentId), $whereParams); } if ($criteria->name) { $whereConditions[] = DbHelper::parseParam('f.name', $criteria->name, $whereParams); } if (!is_null($criteria->fullPath)) { $whereConditions[] = DbHelper::parseParam('f.fullPath', $criteria->fullPath, $whereParams); } if (count($whereConditions) == 1) { $query->where($whereConditions[0], $whereParams); } else { array_unshift($whereConditions, 'and'); $query->where($whereConditions, $whereParams); } }
/** * Applies WHERE conditions to a DbCommand query for folders. * * @param DbCommand $query * @param FolderCriteriaModel $criteria * * @return null */ private function _applyFolderConditions($query, FolderCriteriaModel $criteria) { $whereConditions = array(); $whereParams = array(); if ($criteria->id) { $whereConditions[] = DbHelper::parseParam('f.id', $criteria->id, $whereParams); } if ($criteria->sourceId) { $whereConditions[] = DbHelper::parseParam('f.sourceId', $criteria->sourceId, $whereParams); } if ($criteria->parentId) { $whereConditions[] = DbHelper::parseParam('f.parentId', $criteria->parentId, $whereParams); } if ($criteria->name) { $whereConditions[] = DbHelper::parseParam('f.name', $criteria->name, $whereParams); } if (!is_null($criteria->path)) { // This folder has a comma in it. if (strpos($criteria->path, ',') !== false) { // Escape the comma. $condition = DbHelper::parseParam('f.path', str_replace(',', '\\,', $criteria->path), $whereParams); $lastKey = key(array_slice($whereParams, -1, 1, true)); // Now un-escape it. $whereParams[$lastKey] = str_replace('\\,', ',', $whereParams[$lastKey]); } else { $condition = DbHelper::parseParam('f.path', $criteria->path, $whereParams); } $whereConditions[] = $condition; } if (count($whereConditions) == 1) { $query->where($whereConditions[0], $whereParams); } else { array_unshift($whereConditions, 'and'); $query->where($whereConditions, $whereParams); } }
/** * Applies WHERE conditions to a DbCommand query for users. * * @access private * @param DbCommand $query * @param $criteria * @return void */ private function _applyUserConditions($query, $criteria) { $whereConditions = array(); $whereParams = array(); if ($criteria->id) { $whereConditions[] = DbHelper::parseParam('u.id', $criteria->id, $whereParams); } if ($criteria->groupId || $criteria->group) { $query->join('usergroups_users gu', 'gu.userId = u.id'); if ($criteria->groupId) { $whereConditions[] = DbHelper::parseParam('gu.groupId', $criteria->groupId, $whereParams); } if ($criteria->group) { $query->join('usergroups g', 'g.id = gu.groupId'); $whereConditions[] = DbHelper::parseParam('g.handle', $criteria->group, $whereParams); } } if ($criteria->username) { $whereConditions[] = DbHelper::parseParam('u.username', $criteria->username, $whereParams); } if ($criteria->firstName) { $whereConditions[] = DbHelper::parseParam('u.firstName', $criteria->firstName, $whereParams); } if ($criteria->lastName) { $whereConditions[] = DbHelper::parseParam('u.lastName', $criteria->lastName, $whereParams); } if ($criteria->email) { $whereConditions[] = DbHelper::parseParam('u.email', $criteria->email, $whereParams); } if ($criteria->admin) { $whereConditions[] = DbHelper::parseParam('u.admin', 1, $whereParams); } if ($criteria->status) { $whereConditions[] = DbHelper::parseParam('u.status', $criteria->status, $whereParams); } if ($criteria->lastLoginDate) { $whereConditions[] = DbHelper::parseParam('u.lastLoginDate', $criteria->lastLoginDate, $whereParams); } if ($whereConditions) { array_unshift($whereConditions, 'and'); $query->where($whereConditions, $whereParams); } }