dokeos-gradebook
[ class tree: dokeos-gradebook ] [ index: dokeos-gradebook ] [ all elements ]

Source for file linkform.class.php

Documentation is available at linkform.class.php

  1. <?php
  2. include_once (dirname(__FILE__).'/../../../inc/global.inc.php');
  3. include_once (dirname(__FILE__).'/../be.inc.php');
  4. include_once (dirname(__FILE__).'/../gradebook_functions.inc.php');
  5. include_once (api_get_path(LIBRARY_PATH'groupmanager.lib.php');
  6. require_once (api_get_path(LIBRARY_PATH'formvalidator/FormValidator.class.php');
  7.  
  8. /**
  9.  * Forms related to links
  10.  * @author Stijn Konings
  11.  * @author Bert Stepp� (made more generic)
  12.  * @package dokeos.gradebook
  13.  */
  14. class LinkForm extends FormValidator
  15. {
  16.  
  17.     const TYPE_CREATE = 1;
  18.     const TYPE_MOVE = 2;
  19.  
  20.     private $category_object;
  21.     private $link_object;
  22.     private $extra;
  23.  
  24.     /**
  25.      * Builds a form containing form items based on a given parameter
  26.      * @param int form_type 1=choose link
  27.      * @param obj cat_obj the category object
  28.      * @param string form name
  29.      * @param method 
  30.      * @param action 
  31.      */
  32.     function LinkForm($form_type$category_object,$link_object$form_name$method 'post'$action null$extra null)
  33.     {
  34.         parent :: __construct($form_name$method$action);
  35.  
  36.         if (isset ($category_object))
  37.             $this->category_object = $category_object;
  38.         if (isset ($link_object))
  39.             $this->link_object = $link_object;
  40.         if (isset ($extra))
  41.             $this->extra = $extra;
  42.  
  43.         if ($form_type == self :: TYPE_CREATE)
  44.             $this->build_create();
  45.         elseif ($form_type == self :: TYPE_MOVE)
  46.             $this->build_move();
  47.  
  48.         //$this->setDefaults();
  49.     }
  50.  
  51.     protected function build_move()
  52.     {
  53.         $renderer =$this->defaultRenderer();
  54.         $renderer->setElementTemplate('<span>{element}</span> ');
  55.         $this->addElement('static',null,null,'"'.$this->link_object->get_name().'" ');
  56.         $this->addElement('static',null,null,get_lang('MoveTo').' : ');
  57.         $select $this->addElement('select','move_cat',null,null);
  58.         foreach ($this->link_object->get_target_categories(as $cat)
  59.         {
  60.             for ($i=0;$i<$cat[2];$i++)
  61.             {
  62.                 $line .= '&mdash;';
  63.             }
  64.             $select->addoption($line.' '.$cat[1],$cat[0]);
  65.             $line '';
  66.         }
  67.            $this->addElement('submit'nullget_lang('Ok'));        
  68.     }
  69.  
  70.     protected function build_create()
  71.     {
  72.         
  73.         $select $this->addElement('select',
  74.                                     'select_link',
  75.                                     get_lang('ChooseLink'),
  76.                                     null,
  77.                                     array('onchange' => 'document.create_link.submit()'));
  78.  
  79.         $linktypes LinkFactory :: get_all_types();
  80.  
  81.         $select->addoption('['.get_lang('ChooseLink').']'0);
  82.  
  83.         $cc $this->category_object->get_course_code();
  84.         foreach ($linktypes as $linktype)
  85.         {
  86.             $link LinkFactory :: create ($linktype);
  87.             if(!empty($cc))
  88.             {
  89.                 $link->set_course_code($cc);
  90.             }
  91.             elseif(!empty($_GET['course_code']))
  92.             {
  93.                 $link->set_course_code(Database::escape_string($_GET['course_code']));
  94.             }
  95.             // disable this element if the link works with a dropdownlist
  96.             // and if there are no links left
  97.             if (!$link->needs_name_and_description()
  98.                 && count($link->get_all_links()) == '0')
  99.                 $select->addoption($link->get_type_name()$linktype'disabled');
  100.             else
  101.                 $select->addoption($link->get_type_name()$linktype);
  102.         }
  103.  
  104.         if (isset($this->extra))
  105.         {
  106.             $this->setDefaults(array('select_link' => $this->extra));
  107.         }
  108.  
  109.     }
  110.  
  111. }
  112. ?>

Documentation generated on Thu, 12 Jun 2008 13:59:52 -0500 by phpDocumentor 1.4.1