Ejemplo n.º 1
0
 /**
  *
  * @param \Link\LinkCategory $link
  */
 function init($link = null)
 {
     $this->set_link($link);
     $defaults = array();
     $defaults['url'] = $link->url ? $link->url : 'http://';
     $defaults['title'] = $link->title;
     $defaults['description'] = $link->description;
     $defaults['category_id'] = $link->category_id;
     $defaults['display_order'] = $link->display_order;
     $defaults['on_homepage'] = $link->on_homepage;
     $defaults['target'] = $link->target;
     $this->add_hidden('c_id', $link->c_id);
     $this->add_hidden('id', $link->id);
     $this->add_hidden('session_id', $link->session_id);
     $form_name = $category->id ? get_lang('LinkMod') : get_lang('LinkAdd');
     $this->add_header($form_name);
     $this->add_textfield('url', get_lang('Url'), $required = true, array('class' => 'span6'));
     $this->addRule('url', get_lang('MalformedUrl'), 'regex', '|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i');
     $this->add_textfield('title', get_lang('Title'), $required = false, array('class' => 'span6'));
     $this->add_textarea('description', get_lang('Description'), array('class' => 'span3'));
     $this->add_checkbox('on_homepage', '', get_lang('OnHomepage'));
     $id = $link->id;
     if ($id) {
         $url = Chamilo::url('/main/metadata/index.php', array('eid' => "Link.{$id}"));
         $metadata = '<a class="control-text" href="' . $url . '">' . get_lang('AddMetadata') . '</a>';
         $this->add_label(get_lang('Metadata'), $metadata);
     }
     $options = array();
     $options[0] = '--';
     $categories = LinkCategoryRepository::instance()->find_by_course($link->c_id, $link->session_id);
     foreach ($categories as $category) {
         $options[$category->id] = $category->category_title;
     }
     $this->add_select('category_id', get_lang('Category'), $options);
     $targets = array('_self' => get_lang('LinkOpenSelf'), '_blank' => get_lang('LinkOpenBlank'), '_parent' => get_lang('LinkOpenParent'), '_top' => get_lang('LinkOpenTop'));
     $this->add_select('target', get_lang('LinkTarget'), $targets);
     //$help = '<span class="help-block">' . get_lang('AddTargetOfLinkOnHomepage') . '</span>';
     //$this->add_label('', $help);
     $this->add_button('save', get_lang('Save'), array('class' => 'btn save'));
     $this->setDefaults($defaults);
 }
Ejemplo n.º 2
0
 public function edit_category()
 {
     if (!$this->is_allowed_to_edit()) {
         $this->forbidden();
         return;
     }
     $c_id = Request::get_c_id();
     $id = Request::get_id();
     $repo = LinkCategoryRepository::instance();
     $category = $repo->find_one_by_id($c_id, $id);
     $action = $this->url(self::ACTION_EDIT_CATEGORY);
     $form = new CategoryForm('category', 'post', $action);
     $form->init($category);
     if ($form->validate()) {
         $form->update_model();
         $repo = LinkCategoryRepository::instance();
         $success = $repo->save($category);
         $message = $success ? get_lang('CategorySaved') : get_lang('Error');
         $home = $this->url(self::ACTION_DEFAULT);
         Redirect::go($home);
     }
     global $interbreadcrumb;
     $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('EditCategory'));
     $data = (object) array();
     $data->form = $form;
     $this->render('edit_category', $data);
 }
 public function sort_categories()
 {
     if (!$this->is_allowed_to_edit()) {
         $this->forbidden();
         return;
     }
     $c_id = Request::get_c_id();
     $ids = Request::get_ids();
     if (empty($ids)) {
         return;
     }
     $repo = LinkCategoryRepository::instance();
     $success = $repo->order($c_id, $ids);
     $this->response($success);
 }