/**
  * 
  * 
  * @param string $where Where filter to apply
  * @return array 
  */
 public function find($where, $orderby = '', $limit = null)
 {
     $table_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
     $table = Database::get_course_table(TABLE_GLOSSARY);
     $tool = TOOL_GLOSSARY;
     $sql = "SELECT g.*,         \n                       prop.id AS property_id, \n                       prop.tool, \n                       prop.insert_user_id,\n                       prop.insert_date,\n                       prop.lastedit_date,\n                       prop.ref,\n                       prop.lastedit_type,\n                       prop.lastedit_user_id,\n                       prop.to_group_id, \n                       prop.to_user_id, \n                       prop.visibility, \n                       prop.start_visible, \n                       prop.end_visible, \n                       prop.id_session\n                FROM \n                    {$table} AS g, \n                    {$table_item_property} AS prop\n                WHERE \n                    (g.glossary_id = prop.ref AND\n                     g.c_id = prop.c_id AND\n                     prop.tool = '{$tool}')";
     $sql .= $where ? "AND ({$where})" : '';
     $sql .= ' ORDER BY ';
     $sql .= $orderby ? $orderby : 'name ASC';
     if ($count) {
         $from = (int) $limit->from;
         $count = (int) $limit->count;
         $sql .= " LIMIT {$from}, {$count}";
     }
     $rs = Database::query($sql);
     while ($data = Database::fetch_object($rs)) {
         $result[] = Glossary::create($data);
     }
     return $result;
 }
 /**
  * Perform the add action
  */
 public function add()
 {
     if (!$this->is_allowed_to_edit()) {
         $this->forbidden();
         return;
     }
     $c_id = Request::get_c_id();
     $session_id = Request::get_session_id();
     $item = Glossary::create();
     $item->c_id = $c_id;
     $item->session_id = $session_id;
     $action = $this->url(self::ACTION_ADD);
     $form = GlossaryForm::create($action, $item);
     if ($form->validate()) {
         $repo = Glossary::repository();
         $success = $repo->save($item);
         $message = $success ? get_lang('GlossaryAdded') : get_lang('Error');
         $home = $this->url();
         Redirect::go($home);
     }
     $data = (object) array();
     $data->type = $type;
     $data->form = $form;
     $this->render('edit', $data);
 }