/** * Test to make sure we can build a query with a raw JOIN statement * * @return void **/ public function testBuildQueryWithRawJoinClause() { // Here's the query we're try to write... $expected = "SELECT * FROM `users` INNER JOIN posts ON `users`.id = `posts`.user_id AND `users`.id > 1"; $dbo = $this->getMockDriver(); $query = new Query($dbo); $query->select('*')->from('users')->joinRaw('posts', '`users`.id = `posts`.user_id AND `users`.id > 1'); $this->assertEquals($expected, str_replace("\n", ' ', $query->toString()), 'Query did not build the expected result'); }
/** * Test to make sure we can build a query with complex nested where statements * * @return void **/ public function testBuildQueryWithNestedWheres() { // Here's the query we're try to write... $expected = "SELECT * FROM `users` WHERE (`name` = 'a' OR `name` = 'b' ) AND (`email` = 'c' OR `email` = 'd' )"; $dbo = $this->getMockDriver(); $query = new Query($dbo); $query->select('*')->from('users')->whereEquals('name', 'a', 1)->orWhereEquals('name', 'b', 1)->resetDepth(0)->whereEquals('email', 'c', 1)->orWhereEquals('email', 'd', 1); $this->assertEquals($expected, str_replace("\n", ' ', $query->toString()), 'Query did not build the expected result'); }
/** * Get a list of templates for the specified client * * @param integer $client_id * @param integer $id * @return object */ public function getTemplate($client_id = 0, $id = 0) { if (!$this->app->has('cache.store') || !($cache = $this->app['cache.store'])) { $cache = new \Hubzero\Cache\Storage\None(); } $templates = $cache->get('com_templates.templates' . $client_id . $this->lang); if (!$templates || empty($templates)) { try { $db = $this->app['db']; $s = '#__template_styles'; $e = '#__extensions'; $query = new Query($db); $query->select($s . '.id')->select($s . '.home')->select($s . '.template')->select($s . '.params')->select($e . '.protected')->from($s)->join($e, $e . '.element', $s . '.template')->whereEquals($s . '.client_id', (int) $client_id)->whereEquals($e . '.enabled', 1)->whereEquals($e . '.type', 'template')->whereRaw($e . '.`client_id` = `' . $s . '`.`client_id`'); if ($id) { $query->whereEquals($s . '.id', $id); } $query->order('home', 'desc'); $db->setQuery($query->toString()); $templates = $db->loadObjectList('id'); foreach ($templates as $i => $template) { $template->params = new Registry($template->params); $template->path = $this->determinePath($template->protected) . DIRECTORY_SEPARATOR . $template->template; $templates[$i] = $template; // Create home element if ($template->home && !isset($templates[0])) { $templates[0] = clone $template; } } $cache->put('com_templates.templates' . $client_id . $this->lang, $templates, $this->app['config']->get('cachetime', 15)); } catch (Exception $e) { $templates = array(); } } $tmpl = null; if (isset($templates[$id])) { $tmpl = $templates[$id]; } else { if (isset($templates[0])) { $tmpl = $templates[0]; } } if ($tmpl && file_exists($tmpl->path . DIRECTORY_SEPARATOR . 'index.php')) { return $tmpl; } return $this->getSystemTemplate(); }