/** * @param SQLQuery $query */ public function augmentSQL(SQLQuery &$query) { $address = Controller::curr()->getRequest()->getVar('Address'); if ($this->owner->hasMethod('updateAddressValue')) { $address = $this->owner->updateAddressValue($address); } if ($address) { // on frontend $coords = GoogleGeocoding::address_to_point($address); $Lat = $coords['lat']; $Lng = $coords['lng']; $query->addSelect(array('( 3959 * acos( cos( radians(' . $Lat . ') ) * cos( radians( `Lat` ) ) * cos( radians( `Lng` ) - radians(' . $Lng . ') ) + sin( radians(' . $Lat . ') ) * sin( radians( `Lat` ) ) ) ) AS distance')); } }
function getAdminPermissionSet(array &$res) { $companyId = $_REQUEST["CompanyId"]; if (isset($companyId) && is_numeric($companyId) && $companyId > 0) { // user could be ccla admin of only one company and company must have at least one team set $ccla_group = Group::get()->filter('Code', ICLAMember::CCLAGroupSlug)->first(); if (!$ccla_group) { return; } $query_groups = new SQLQuery(); $query_groups->addSelect("GroupID"); $query_groups->addFrom("Company_Administrators"); $query_groups->addWhere("MemberID = {$this->owner->ID} AND CompanyID <> {$companyId} AND GroupID = {$ccla_group->ID} "); $groups = $query_groups->execute()->keyedColumn(); $company = Company::get()->byID($companyId); if (count($groups) === 0 && $company->isICLASigned()) { array_push($res, 'CCLA_ADMIN'); } } }
public function testSelect() { $query = new SQLQuery('"Title"', '"MyTable"'); $query->addSelect('"TestField"'); $this->assertEquals('SELECT "Title", "TestField" FROM "MyTable"', $query->sql()); // Test replacement of select $query->setSelect(array('Field' => '"Field"', 'AnotherAlias' => '"AnotherField"')); $this->assertEquals('SELECT "Field", "AnotherField" AS "AnotherAlias" FROM "MyTable"', $query->sql()); // Check that ' as ' selects don't get mistaken as aliases $query->addSelect(array('Relevance' => "MATCH (Title, MenuTitle) AGAINST ('Two as One')")); $this->assertEquals('SELECT "Field", "AnotherField" AS "AnotherAlias", MATCH (Title, MenuTitle) AGAINST (' . '\'Two as One\') AS "Relevance" FROM "MyTable"', $query->sql()); }
/** * @return SQLQuery */ protected function getRemoteObjectsQuery() { // Get all tables to query $tables = $this->getRemoteClassHierarchy(); $baseClass = array_shift($tables); // Generate sql query $query = new SQLQuery("\"{$baseClass}\".*", "\"{$baseClass}\"", $this->targetWhere); $query->setOrderBy("\"{$baseClass}\".\"ID\" ASC"); // Sort by ID for some performance reasons foreach ($tables as $class) { $query->addSelect("\"{$class}\".*"); $query->addLeftJoin($class, "\"{$baseClass}\".\"ID\" = \"{$class}\".\"ID\""); } return $query; }