/**
 * Render link to a specific category
 * 
 * Parameters:
 * 
 * - category_id - integer, return parent category ID. 
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 */
function smarty_function_in_category_link($params, &$smarty)
{
    $category_id = array_var($params, 'category_id');
    $user = array_var($params, 'user', null);
    $category = DocumentCategories::findById($category_id);
    if (instance_of($category, 'DocumentCategory')) {
        if ($category->canView($user)) {
            return '<a href="' . $category->getViewUrl() . '">' . clean($category->getName()) . '</a>';
        } else {
            return clean($category->getName());
        }
        // if
    }
    // if
    return '<span class="unknown_category_link unknown_object_link">' . lang('Unknown Category') . '</span>';
}
 /**
  * Constructor method
  *
  * @param string $request
  * @return DocumentsCategoriesController
  */
 function __construct($request)
 {
     parent::__construct($request);
     if (!$this->logged_user->isAdministrator() && !$this->logged_user->getSystemPermission('can_use_documents')) {
         $this->httpError(HTTP_ERR_FORBIDDEN);
     }
     // if
     $this->wireframe->addBreadCrumb(lang('Documents'), assemble_url('documents'));
     $category_id = $this->request->getId('category_id');
     if ($category_id) {
         $this->active_document_category = DocumentCategories::findById($category_id);
     }
     // if
     if (instance_of($this->active_document_category, 'DocumentCategory')) {
         $this->wireframe->addBreadCrumb($this->active_document_category->getName(), $this->active_document_category->getViewUrl());
         if (Document::canAdd($this->logged_user)) {
             $add_text_url = assemble_url('documents_add_text', array('category_id' => $this->active_document_category->getId()));
             $upload_file_url = assemble_url('documents_upload_file', array('category_id' => $this->active_document_category->getId()));
         }
         // if
     } else {
         $this->active_document_category = new DocumentCategory();
         if (Document::canAdd($this->logged_user)) {
             $add_text_url = assemble_url('documents_add_text');
             $upload_file_url = assemble_url('documents_upload_file');
         }
         // if
     }
     // if
     if (Document::canAdd($this->logged_user)) {
         $this->wireframe->addPageAction(lang('New Text Document'), $add_text_url);
         $this->wireframe->addPageAction(lang('Upload File'), $upload_file_url);
     } else {
         $add_text_url = null;
         $upload_file_url = null;
     }
     // if
     $this->smarty->assign(array('document_categories_url' => $this->logged_user->isAdministrator() ? assemble_url('document_categories') : null, 'add_category_url' => DocumentCategory::canAdd($this->logged_user) ? assemble_url('document_categories_add') : null, 'add_text_url' => $add_text_url, 'upload_file_url' => $upload_file_url, 'active_document_category' => $this->active_document_category, 'categories' => DocumentCategories::findAll($this->logged_user)));
 }