Пример #1
0
 /**
  * Save the link list
  *
  * @param  array  $navigation The full navigation array
  * @param  array  $keys       The page keys
  * @param  string $language   The language to save the file for
  * @return string             The full content for the cache file
  */
 protected function dumpEditorLinkList($navigation, $keys, $language)
 {
     // get the order
     foreach (array_keys($navigation) as $type) {
         $order[$type] = $this->getOrder($navigation, $type, 0);
     }
     // start building the cache file
     $editorLinkListString = $this->getCacheHeader('the links that can be used by the editor');
     // init var
     $links = array();
     // init var
     $cachedTitles = (array) $this->database->getPairs('SELECT i.id, i.navigation_title
          FROM pages AS i
          WHERE i.id IN(' . implode(',', array_keys($keys)) . ')
          AND i.language = ? AND i.status = ?', array($language, 'active'));
     // loop the types in the order we want them to appear
     foreach (array('page', 'meta', 'footer', 'root') as $type) {
         // any pages?
         if (isset($order[$type])) {
             // loop pages
             foreach ($order[$type] as $pageId => $url) {
                 // skip if we don't have a title
                 if (!isset($cachedTitles[$pageId])) {
                     continue;
                 }
                 // get the title
                 $title = \SpoonFilter::htmlspecialcharsDecode($cachedTitles[$pageId]);
                 // split into chunks
                 $urlChunks = explode('/', $url);
                 // remove the language chunk
                 $hasMultiLanguages = BackendModel::getContainer()->getParameter('site.multilanguage');
                 $urlChunks = $hasMultiLanguages ? array_slice($urlChunks, 2) : array_slice($urlChunks, 1);
                 // subpage?
                 if (count($urlChunks) > 1) {
                     // loop while we have more then 1 chunk
                     while (count($urlChunks) > 1) {
                         // remove last chunk of the url
                         array_pop($urlChunks);
                         // build the temporary URL, so we can search for an id
                         $tempUrl = implode('/', $urlChunks);
                         // search the pageID
                         $tempPageId = array_search($tempUrl, $keys);
                         // prepend the title
                         if (!isset($cachedTitles[$tempPageId])) {
                             $title = ' > ' . $title;
                         } else {
                             $title = $cachedTitles[$tempPageId] . ' > ' . $title;
                         }
                     }
                 }
                 // add
                 $links[] = array($title, $url);
             }
         }
     }
     // add JSON-string
     $editorLinkListString .= 'var linkList = ' . json_encode($links) . ';';
     return $editorLinkListString;
 }
 /**
  * @depends testExecute
  */
 public function testGetPairs()
 {
     $this->assertEquals(10, count($this->db->getPairs('SELECT id, username FROM users LIMIT 10;')));
     $this->assertEquals(10, count($this->db->getPairs('SELECT id, username FROM users WHERE id != ? LIMIT 10', 1337)));
     $this->assertEquals(10, count($this->db->getPairs('SELECT id, username FROM users WHERE id != ? LIMIT ?', array(1337, 10))));
     $this->assertEquals(10, count($this->db->getPairs('SELECT id, username FROM users WHERE id != :id LIMIT 10', array(':id' => 1337))));
     $this->assertEquals(10, count($this->db->getPairs('SELECT id, username FROM users WHERE id != :id LIMIT :limit', array(':id' => 1337, ':limit' => 10))));
 }