/**
  * 
  * 
  * @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 = $this->get_table();
     $tool = $this->get_tool();
     $sql = "SELECT n.*,         \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 n, \n                    {$table_item_property} AS prop\n                WHERE \n                    (n.notebook_id = prop.ref AND\n                     n.c_id = prop.c_id AND\n                     prop.tool = '{$tool}')";
     $sql .= $where ? "AND ({$where})" : '';
     $sql .= ' ORDER BY ';
     $sql .= $orderby ? $orderby : 'creation_date ASC';
     if ($limit) {
         $from = (int) $limit->from;
         $count = (int) $limit->count;
         $sql .= " LIMIT {$from}, {$count}";
     }
     $rs = Database::query($sql);
     while ($data = Database::fetch_object($rs)) {
         $result[] = Notebook::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 = Notebook::create();
     $item->c_id = $c_id;
     $item->session_id = $session_id;
     $action = $this->url(self::ACTION_ADD);
     $form = NotebookForm::create($action, $item);
     if ($form->validate()) {
         $repo = Notebook::repository();
         $success = $repo->save($item);
         $message = $success ? get_lang('NotebookAdded') : get_lang('Error');
         $home = $this->url();
         Redirect::go($home);
     }
     $data = (object) array();
     $data->type = $type;
     $data->form = $form;
     $this->render('edit', $data);
 }