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

Source for file catform.class.php

Documentation is available at catform.class.php

  1. <?php
  2.  
  3. include_once (dirname(__FILE__).'/../../../inc/global.inc.php');
  4. include_once (dirname(__FILE__).'/../be.inc.php');
  5. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  6.  
  7. /**
  8.  * Extends formvalidator with add&edit forms
  9.  * @author Stijn Konings
  10.  * @package dokeos.gradebook
  11.  */
  12.  
  13. class CatForm extends FormValidator {
  14.     
  15.     const TYPE_ADD = 1;
  16.     const TYPE_EDIT = 2;
  17.     const TYPE_MOVE = 3;
  18.     const TYPE_SELECT_COURSE = 4;
  19.     private $category_object;
  20.     
  21.     /**
  22.      * Builds a form containing form items based on a given parameter
  23.      * @param int form_type 1=add, 2=edit,3=move,4=browse
  24.      * @param obj cat_obj the category object
  25.      * @param string form name
  26.      * @param method method
  27.      */
  28.     function CatForm($form_type$category_object,$form_name,$method 'post',$action=null)
  29.     {
  30.         parent :: __construct($form_name$method$action);
  31.         $this->form_type $form_type;
  32.         if (isset ($category_object))
  33.         {    
  34.             $this->category_object = $category_object;
  35.         }
  36.         if ($this->form_type == self :: TYPE_EDIT)
  37.         {
  38.             $this->build_editing_form();
  39.         }
  40.         elseif ($this->form_type == self :: TYPE_ADD)
  41.         {
  42.             $this->build_add_form();
  43.         }
  44.         elseif ($this->form_type == self :: TYPE_MOVE)
  45.         {
  46.             $this->build_move_form();
  47.         }
  48.         elseif ($this->form_type == self :: TYPE_SELECT_COURSE)
  49.         {
  50.             $this->build_select_course_form();
  51.         }
  52.         $this->setDefaults();
  53.     }
  54.  
  55.     /**
  56.      * This function will build a move form that will allow the user to move a category to
  57.      * a another
  58.      */
  59.        protected function build_move_form()
  60.        {
  61.         $renderer =$this->defaultRenderer();
  62.         $renderer->setElementTemplate('<span>{element}</span> ');
  63.         $this->addElement('static',null,null,'"'.$this->category_object->get_name().'" ');
  64.         $this->addElement('static',null,null,get_lang('MoveTo')' : ');
  65.         $select $this->addElement('select','move_cat',null,null);
  66.         foreach ($this->category_object->get_target_categories(as $cat)
  67.         {
  68.             for ($i=0;$i<$cat[2];$i++)
  69.             {
  70.                 $line .= '--';
  71.             }
  72.             if ($cat[0!= $this->category_object->get_parent_id())
  73.                 $select->addoption($line.' '.$cat[1],$cat[0]);
  74.             else
  75.                 $select->addoption($line.' '.$cat[1],$cat[0],'disabled');
  76.             $line '';
  77.         }
  78.            $this->addElement('submit'nullget_lang('Ok'));
  79.        }
  80.     /** 
  81.      * This function builds an 'add category form, if parent id is 0, it will only
  82.      * show courses
  83.      */
  84.        protected function build_add_form()
  85.        {
  86.         //check if we are a root category
  87.         //if so, you can only choose between courses
  88.         if ($this->category_object->get_parent_id(== '0')
  89.         {
  90.             $select $this->addElement('select','select_course',array(get_lang('PickACourse'),'test')null);
  91.             $coursecat Category :: get_not_created_course_categories(api_get_user_id());
  92.             if (count($coursecat)==0)
  93.                 $select->addoption(get_lang('CourseIndependent'),'COURSEINDEPENDENT','disabled');
  94.                 else
  95.                 $select->addoption(get_lang('CourseIndependent'),'COURSEINDEPENDENT');
  96.             //only return courses that are not yet created by the teacher
  97.  
  98.             foreach($coursecat as $row
  99.             {
  100.                 $select->addoption($row[1],$row[0]);
  101.             }
  102.                $this->setDefaults(array(
  103.                   'hid_user_id' => $this->category_object->get_user_id(),
  104.                   'hid_parent_id' => $this->category_object->get_parent_id()
  105.                ));        
  106.         }
  107.         else
  108.         {            
  109.                $this->setDefaults(array(
  110.                'hid_user_id' => $this->category_object->get_user_id(),
  111.                'hid_parent_id' => $this->category_object->get_parent_id()
  112.                ));
  113.                $this->addElement('hidden','course_code'$this->category_object->get_course_code());                     
  114.         }
  115.            $this->build_basic_form();
  116.        }
  117.        
  118.     /**
  119.      * Builds an form to edit a category
  120.      */
  121.        protected function build_editing_form()
  122.        {
  123.            $this->setDefaults(array(
  124.             'name' => $this->category_object->get_name(),
  125.             'description' => $this->category_object->get_description(),
  126.             'hid_user_id' => $this->category_object->get_user_id(),
  127.             'hid_parent_id' => $this->category_object->get_parent_id(),    
  128.                 'weight' => $this->category_object->get_weight(),    
  129.                 'visible' => $this->category_object->is_visible(),
  130.                 'certif_min_score' => $this->category_object->get_certificate_min_score(),
  131.             ));
  132.            $this->addElement('hidden','hid_id'$this->category_object->get_id());
  133.            $this->addElement('hidden','course_code'$this->category_object->get_course_code());
  134.         $this->build_basic_form();
  135.        }
  136.        
  137.        private function build_basic_form()
  138.        {
  139.         $this->addElement('hidden''zero'0);
  140.         $this->add_textfield('name'get_lang('CategoryName'),true,array('size'=>'54','maxlength'=>'50'));
  141.         $this->add_textfield('weight'get_lang('Weight'),true,array('size'=>'4','maxlength'=>'4'));            
  142.         $this->add_textfield('certif_min_score'get_lang('CertificateMinScore'),false,array('size'=>'4','maxlength'=>'4'));            
  143.            $this->addElement('hidden','hid_user_id');
  144.            $this->addElement('hidden','hid_parent_id');
  145.         $this->addElement('textarea''description'get_lang('Description'),array('rows'=>'3','cols' => '34'));
  146.         $this->addElement('checkbox''visible',get_lang('Visible'));
  147.         $this->addElement('submit'nullget_lang('Ok'));
  148.         $this->addRule('weight',get_lang('OnlyNumbers'),'numeric');
  149.         $this->addRule('weight',get_lang('NoDecimals'),'nopunctuation');
  150.         $this->addRule(array ('weight''zero')get_lang('NegativeValue')'compare''>=');
  151.         $this->addRule('certif_min_score',get_lang('OnlyNumbers'),'numeric');
  152.         $this->addRule('certif_min_score',get_lang('NoDecimals'),'nopunctuation');
  153.         $this->addRule(array ('certif_min_score''zero')get_lang('NegativeValue')'compare''>=');
  154.        }
  155.     /** 
  156.      * This function builds an 'select course' form in the add category process,
  157.      * if parent id is 0, it will only show courses
  158.      */
  159.        protected function build_select_course_form()
  160.        {
  161.         $select $this->addElement('select','select_course',array(get_lang('PickACourse'),'test')null);
  162.         $coursecat Category :: get_all_courses(api_get_user_id());
  163.         //only return courses that are not yet created by the teacher
  164.  
  165.         foreach($coursecat as $row
  166.         {
  167.             $select->addoption($row[1],$row[0]);
  168.         }
  169.         $this->setDefaults(array(
  170.            'hid_user_id' => $this->category_object->get_user_id(),
  171.            'hid_parent_id' => $this->category_object->get_parent_id()
  172.         ));        
  173.            $this->addElement('hidden','hid_user_id');
  174.            $this->addElement('hidden','hid_parent_id');
  175.         $this->addElement('submit'nullget_lang('Ok'));
  176.        }
  177.          
  178.        function display()
  179.        {
  180.            parent :: display();
  181.        }
  182.        
  183.        function setDefaults($defaults array ())
  184.       {
  185.            parent :: setDefaults($defaults);
  186.        }
  187. }
  188. ?>

Documentation generated on Thu, 12 Jun 2008 13:02:50 -0500 by phpDocumentor 1.4.1