/**
  * Returns the categories for my_links for a given blog
  *
  * @param blogId Identifier of the blog.
  * @param order
  * @param page
  * @param itemsPerPage
  */
 function getMyLinksCategories($blogId, $order = MYLINKS_CATEGORIES_NO_ORDER, $page = -1, $itemsPerPage = DEFAULT_ITEMS_PER_PAGE)
 {
     $prefix = $this->getPrefix();
     // basic query
     $query = "SELECT c.id AS id, c.name AS name, c.blog_id AS blog_id, \n\t\t\t\t\t\t\tc.last_modification AS last_modification, c.properties AS properties, \n\t\t\t\t\t\t\tIF(l.id IS NULL, 0, COUNT(*)) AS num_links\n\t\t\t\t\t\tFROM {$prefix}mylinks_categories c LEFT JOIN {$prefix}mylinks l\n\t\t\t\t\t\tON l.blog_id = c.blog_id AND l.category_id = c.id \n\t\t\t\t\t\tWHERE c.blog_id= {$blogId}\n\t\t\t\t\t\tGROUP BY c.id";
     if ($order == MYLINKS_CATEGORIES_ALPHABETICAL_ORDER) {
         $query .= " ORDER BY c.name ASC";
     } elseif ($order == MYLINKS_CATEGORIES_REVERSE_ALPHABETICAL_ORDER) {
         $query .= " ORDER BY c.name DESC";
     } elseif ($order == MYLINKS_CATEGORIES_MOST_LINKS_FIRST) {
         $query .= " ORDER BY num_links DESC";
     } elseif ($order == MYLINKS_CATEGORIES_LESS_LINKS_FIRST) {
         $query .= " ORDER BY num_links ASC";
     } elseif ($order == MYLINKS_CATEGORIES_LAST_UPDATED_FIRST) {
         $query .= " ORDER BY c.last_modification ASC";
     } elseif ($order == MYLINKS_CATEGORIES_LAST_UPDATED_LAST) {
         $query .= " ORDER BY c.last_modification ASC";
     }
     // execute the query
     $result = $this->Execute($query, $page, $itemsPerPage);
     if (!$result) {
         return array();
     }
     if ($result->RowCount() == 0) {
         return array();
     }
     $myLinks = new MyLinks();
     $blogLinks = $myLinks->getLinks($blogId);
     $myLinksCategories = array();
     while ($row = $result->fetchRow($result)) {
         // configure the data for the category
         $myLinksCategory = new MyLinksCategory($row["name"], $row["blog_id"], $row["num_links"], unserialize($row["properties"]), $row["id"]);
         $myLinksCategories[$myLinksCategory->getId()] = $myLinksCategory;
     }
     // now assign the links to the correct category
     foreach ($blogLinks as $blogLink) {
         if ($myLinksCategories[$blogLink->getCategoryId()]) {
             $myLinksCategories[$blogLink->getCategoryId()]->addLink($blogLink);
         }
     }
     return $myLinksCategories;
 }
 /**
  * Carries out the specified action
  */
 function render()
 {
     // get the parameters
     $order = $this->getValue("showOrder");
     $categoryId = $this->getValue("showCategory");
     // get all the links and throw the event
     $links = new MyLinks();
     $blogLinks = $links->getLinks($this->_blogInfo->getId(), $categoryId, $this->_page, DEFAULT_ITEMS_PER_PAGE);
     $this->notifyEvent(EVENT_LINKS_LOADED, array("links" => &$blogLinks));
     // get the number of links
     $numLinks = $links->getNumLinks($this->_blogInfo->getId(), $categoryId);
     // get all the link categories but we have to respect the order that the user asked
     $linkCategories = new MyLinksCategories();
     $blogLinkCategories = $linkCategories->getMyLinksCategories($this->_blogInfo->getId(), $order);
     $this->notifyEvent(EVENT_LINK_CATEGORIES_LOADED, array("linkcategories" => &$blogLinkCategories));
     // prepare the pager
     $pager = new Pager("?op=editLinks&showCategory={$categoryId}&page=", $this->_page, $numLinks, DEFAULT_ITEMS_PER_PAGE);
     // put the data in the view
     $this->setValue("links", $blogLinks);
     $this->setValue("linkscategories", $blogLinkCategories);
     $this->setValue("currentcategory", $categoryId);
     $this->setValue("pager", $pager);
     parent::render();
 }
 /**
  * Returns an array of MyLink objects
  *
  * @return Array of MyLink object
  */
 function getLinks()
 {
     if ($this->_links == null) {
         $myLinks = new MyLinks();
         $categoryLinks = $myLinks->getLinks($this->getBlogId(), $this->getId());
         $this->setLinks($categoryLinks);
     }
     return $this->_links;
 }