/**
  * 
  * 
  * @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;
 }
Пример #2
0
 public function find_by_id()
 {
     $c_id = Request::get_c_id();
     $id = Request::get_id();
     $item = Glossary::repository()->find_one_by_id($c_id, $id);
     $data = (object) array();
     if ($item) {
         $data->name = $item->name;
         $data->description = $item->description;
     }
     $this->response($success, '', $data);
 }
 public function import_csv()
 {
     if (!$this->is_allowed_to_edit()) {
         $this->forbidden();
         return;
     }
     $action = $this->url(self::ACTION_IMPORT_CSV);
     $form = UploadFileForm::create($action);
     $form->init();
     if ($form->validate()) {
         $delete_all = $form->get_delete_all();
         if ($delete_all) {
             $course = Request::get_course_key();
             $repo = Glossary::repository();
             $repo->remove_by_course($course);
         }
         $file = $form->get_file();
         $path = $file->tmp_name;
         $reader = new CsvReader($path);
         $items = $reader->get_items();
         $course = Request::get_course_key();
         $import = new CourseImport($course);
         $import->add($items);
         $home = $this->url(self::ACTION_DEFAULT);
         Redirect::go($home);
     }
     $data = (object) array();
     $data->form = $form;
     $this->render('upload', $data);
 }