PageRenderTime 43ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/php/lib/platform/dokeos185/data_class/dokeos185_data_manager.class.php

https://bitbucket.org/chamilo/chamilo-migration-dev/
PHP | 511 lines | 2 code | 0 blank | 509 comment | 0 complexity | 765ae2b84ec5445062225308e6c1bc56 MD5 | raw file
  1. <?php
  2. //namespace migration;
  3. //
  4. ///**
  5. // * $Id: dokeos185_data_manager.class.php 221 2009-11-13 14:36:41Z vanpouckesven $
  6. // * @package migration.platform.dokeos185
  7. // */
  8. //require_once (dirname(__FILE__) . '/../../lib/old_migration_data_manager.class.php');
  9. //
  10. ///**
  11. // * Class that connects to the old dokeos185 system
  12. // *
  13. // * @author Sven Vanpoucke
  14. // * @author David Van Wayenbergh
  15. // */
  16. //class Dokeos185DataManager extends OldMigrationDataManager
  17. //{
  18. // /**
  19. // * MDB2 instance
  20. // * @var MDB2Connection
  21. // */
  22. // private $db;
  23. // private $_configuration;
  24. // private static $move_file;
  25. //
  26. // function __construct($old_directory)
  27. // {
  28. // $this->get_configuration($old_directory);
  29. // $this->initialize();
  30. // }
  31. //
  32. // /**
  33. // * Gets the configuration file of the old Dokeos 1.8.5
  34. // * @param String $old_directory
  35. // */
  36. // function get_configuration($old_directory)
  37. // {
  38. // $old_directory = 'file://' . $old_directory;
  39. //
  40. // if (file_exists($old_directory) && is_dir($old_directory))
  41. // {
  42. // $config_file = $old_directory . '/main/inc/conf/configuration.php';
  43. // if (file_exists($config_file) && is_file($config_file))
  44. // {
  45. // require_once ($config_file);
  46. // $this->_configuration = $_configuration;
  47. // }
  48. // }
  49. // }
  50. //
  51. // /**
  52. // * Function to validate the dokeos 185 settings given in the wizard
  53. // * @return true if settings are valid, otherwise false
  54. // */
  55. // function validate_settings()
  56. // {
  57. // if (mysql_connect($this->_configuration['db_host'], $this->_configuration['db_user'], $this->_configuration['db_password']))
  58. // {
  59. //
  60. // if (mysql_select_db($this->_configuration['main_database']) && mysql_select_db($this->_configuration['statistics_database']) && mysql_select_db($this->_configuration['user_personal_database']))
  61. // return true;
  62. // }
  63. //
  64. // return false;
  65. // }
  66. //
  67. // /**
  68. // * Connect to the dokeos185 database with login data from the $$this->_configuration
  69. // * @param String $dbname with databasename
  70. // */
  71. // function initialize()
  72. // {
  73. // PEAR :: setErrorHandling(PEAR_ERROR_CALLBACK, array(get_class(), 'handle_error'));
  74. // $dbname = 'dokeos_main';
  75. // $param = isset($this->_configuration[$dbname]) ? $this->_configuration[$dbname] : $dbname;
  76. // $host = $this->_configuration['db_host'];
  77. // $pos = strpos($host, ':');
  78. //
  79. // if ($pos == ! false)
  80. // {
  81. // $array = split(':', $host);
  82. // $socket = $array[count($array) - 1];
  83. // $host = 'unix(' . $socket . ')';
  84. // }
  85. //
  86. // $dsn = 'mysql://' . $this->_configuration['db_user'] . ':' . $this->_configuration['db_password'] . '@' . $host . '/' . $param;
  87. // $this->db = MDB2 :: connect($dsn, array('debug' => 3, 'debug_handler' => array('Dokeos185DataManager', 'debug')));
  88. //
  89. // if (PEAR :: isError($this->db))
  90. // {
  91. // die($this->db->getMessage());
  92. // }
  93. // $this->db->setCharset('utf8');
  94. // }
  95. //
  96. // function set_database($dbname)
  97. // {
  98. // $param = isset($this->_configuration[$dbname]) ? $this->_configuration[$dbname] : $dbname;
  99. // $this->db->setDatabase($param);
  100. // }
  101. //
  102. // /**
  103. // * This function can be used to handle some debug info from MDB2
  104. // */
  105. // function debug()
  106. // {
  107. // $args = func_get_args();
  108. // // Do something with the arguments
  109. // if ($args[1] == 'query')
  110. // {
  111. // //echo '<pre>';
  112. // //echo($args[2]);
  113. // //echo '</pre>';
  114. // }
  115. // }
  116. //
  117. // /**
  118. // * Handles pear errors
  119. // */
  120. // static function handle_error($error)
  121. // {
  122. // die(__FILE__ . ':' . __LINE__ . ': ' . $error->getMessage() . // For debugging only. May create a security hazard.
  123. //' (' . $error->getDebugInfo() . ')');
  124. // }
  125. //
  126. // /**
  127. // * Get all the users from the dokeos185 database
  128. // * @return array of Dokeos185User
  129. // */
  130. // function get_all_users($offset = null, $limit = null)
  131. // {
  132. // $this->set_database('main_database');
  133. // $query = 'SELECT * FROM ' . $this->get_table_name('user');
  134. // if ($limit != null)
  135. // $this->db->setLimit($limit, $offset);
  136. // $result = $this->db->query($query);
  137. // $users = array();
  138. // while ($record = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
  139. // {
  140. // $users[] = $this->record_to_user($record);
  141. //
  142. // }
  143. // $result->free();
  144. //
  145. // foreach ($users as $user)
  146. // {
  147. // $query_admin = 'SELECT * FROM ' . $this->get_table_name('admin') . ' WHERE user_id=' . $user->get_user_id();
  148. // $result_admin = $this->db->query($query_admin);
  149. //
  150. // if ($result_admin->numRows() == 1)
  151. // {
  152. // $user->set_platformadmin(1);
  153. // }
  154. //
  155. // $result_admin->free();
  156. // }
  157. //
  158. // return $users;
  159. // }
  160. //
  161. // /**
  162. // * Map a resultset record to a Dokeos185User Object
  163. // * @param ResultSetRecord $record from database
  164. // * @return Dokeos185User object with mapped data
  165. // */
  166. // function record_to_user($record)
  167. // {
  168. // if (! is_array($record) || ! count($record))
  169. // {
  170. // throw new Exception(get_lang('InvalidDataRetrievedFromDatabase'));
  171. // }
  172. // $defaultProp = array();
  173. // foreach (Dokeos185User :: get_default_user_property_names() as $prop)
  174. // {
  175. // $defaultProp[$prop] = utf8_encode($record[$prop]);
  176. // }
  177. // return new Dokeos185User($defaultProp);
  178. // }
  179. //
  180. // /**
  181. // * Generic method to create a classobject from a record
  182. // */
  183. // function record_to_classobject($record, $classname)
  184. // {
  185. // if (! is_array($record) || ! count($record))
  186. // {
  187. // throw new Exception(get_lang('InvalidDataRetrievedFromDatabase'));
  188. // }
  189. // $defaultProp = array();
  190. //
  191. // $class = new $classname($defaultProp);
  192. //
  193. // foreach ($class->get_default_property_names() as $prop)
  194. // {
  195. // $defaultProp[$prop] = utf8_encode($record[$prop]);
  196. // }
  197. //
  198. // $class->set_default_properties($defaultProp);
  199. //
  200. // return $class;
  201. // }
  202. //
  203. // /**
  204. // * Move a file to a new place, makes use of Filesystem class
  205. // * Built in checks for same filename
  206. // * @param String $old_rel_path Relative path on the old system
  207. // * @param String $new_rel_path Relative path on the LCMS system
  208. // * @return String $new_filename
  209. // */
  210. // function move_file($old_rel_path, $new_rel_path, $filename, $new_filename = null)
  211. // {
  212. // $old_path = $this->append_full_path(false, $old_rel_path);
  213. // $new_path = $this->append_full_path(true, $new_rel_path);
  214. //
  215. // if (! $new_filename)
  216. // $new_filename = $filename;
  217. //
  218. // $old_file = $old_path . $filename;
  219. // $new_file = $new_path . $new_filename;
  220. //
  221. // if (! file_exists($old_file) || ! is_file($old_file))
  222. // return null;
  223. //
  224. // $secure_file = Filesystem :: copy_file_with_double_files_protection($old_path, $filename, $new_path, $new_filename, self :: $move_file);
  225. // $mgdm = MigrationDataManager :: get_instance();
  226. // $mgdm->add_recovery_element($old_file, $new_file);
  227. //
  228. // return ($secure_file);
  229. //
  230. // // Filesystem :: remove($old_file);
  231. // }
  232. //
  233. // /**
  234. // * Create a directory
  235. // * @param boolean $is_new_system Which system the directory has to be created on (true = LCMS)
  236. // * @param String $rel_path Relative path on the chosen system
  237. // */
  238. // function create_directory($is_new_system, $rel_path)
  239. // {
  240. // Filesystem :: create_dir($this->append_full_path($is_new_system, $rel_path));
  241. // }
  242. //
  243. // /**
  244. // * Function to return the full path
  245. // * @param boolean $is_new_system Which system the directory has to be created on (true = LCMS)
  246. // * @param String $rel_path Relative path on the chosen system
  247. // * @return String $path
  248. // */
  249. // function append_full_path($is_new_system, $rel_path)
  250. // {
  251. // if ($is_new_system)
  252. // $path = Path :: get(SYS_PATH) . $rel_path;
  253. // else
  254. // $path = $this->_configuration['root_sys'] . $rel_path;
  255. //
  256. // return $path;
  257. // }
  258. //
  259. // /**
  260. // * Get all the current settings from the dokeos185 database
  261. // * @return array of Dokeos185SettingCurrent
  262. // */
  263. // function get_all_current_settings($offset = null, $limit = null)
  264. // {
  265. // $this->set_database('main_database');
  266. // $query = 'SELECT * FROM ' . $this->get_table_name('settings_current') . ' WHERE category = \'Platform\'';
  267. //
  268. // if ($limit != null)
  269. // $this->db->setLimit($limit, $offset);
  270. //
  271. // $result = $this->db->query($query);
  272. // $settings_current = array();
  273. // while ($record = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
  274. // {
  275. // $settings_current[] = $this->record_to_classobject($record, 'Dokeos185SettingCurrent');
  276. //
  277. // }
  278. // $result->free();
  279. //
  280. // return $settings_current;
  281. // }
  282. //
  283. // /**
  284. // * Get the first admin id
  285. // * @return admin_id
  286. // */
  287. // function get_old_admin_id()
  288. // {
  289. // $this->set_database('main_database');
  290. // $query = 'SELECT * FROM ' . $this->get_table_name('user') . ' WHERE EXISTS
  291. // (SELECT user_id FROM ' . $this->get_table_name('admin') . ' WHERE user.user_id = admin.user_id)';
  292. // $result = $this->db->query($query);
  293. //
  294. // $record = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
  295. // $id = $record['user_id'];
  296. // $result->free();
  297. //
  298. // return $id;
  299. // }
  300. //
  301. // /**
  302. // * Function that gets the item property of a record
  303. // * @param String $db
  304. // * @param String $tool
  305. // * @param int $id
  306. // * @return item_property item property of a record
  307. // */
  308. // function get_item_property($db, $tool, $id)
  309. // {
  310. // $this->set_database($db);
  311. //
  312. // $query = 'SELECT * FROM ' . $this->get_table_name('item_property') . ' WHERE tool = \'' . $tool . '\' AND ref = ' . $id;
  313. //
  314. // $result = $this->db->query($query);
  315. // $itemprops = $this->mapper($result, 'Dokeos185ItemProperty');
  316. // $result->free();
  317. // return $itemprops[0];
  318. // }
  319. //
  320. // /** Get all the documents from a course
  321. // * @param String $course
  322. // * @param int $include_deleted_files
  323. // * @return array of Dokeos185Documents
  324. // */
  325. // function get_all_documents($course, $include_deleted_files, $offset = null, $limit = null)
  326. // {
  327. // $this->set_database($course->get_db_name());
  328. // $query = 'SELECT * FROM ' . $this->get_table_name('document') . ' WHERE filetype <> \'folder\'';
  329. //
  330. // if ($include_deleted_files != 1)
  331. // $query = $query . ' AND id IN (SELECT ref FROM ' . $this->get_table_name('item_property') . ' WHERE tool=\'document\'' . ' AND visibility <> 2);';
  332. // if ($limit != null)
  333. // $this->db->setLimit($limit, $offset);
  334. // $result = $this->db->query($query);
  335. // $documents = $this->mapper($result, 'Dokeos185Document');
  336. //
  337. // return $documents;
  338. // }
  339. //
  340. // /**
  341. // * Generic method for getting all the records of a table
  342. // * @param String $database
  343. // * @param String $tablename
  344. // * @param String $classname
  345. // * @param String $tool_name
  346. // * @return dokeos185 datatype Array of dokeos 185 datatype
  347. // */
  348. // function get_all($database, $tablename, $classname, $tool_name = null, $offset = null, $limit = null)
  349. // {
  350. // $this->set_database($database);
  351. // /*$querycheck = 'SHOW table status like \'' . $tablename . '\'';
  352. // $result = $this->db->query($querycheck);
  353. // if (MDB2 :: isError($result) || $result->numRows() == 0)
  354. // {
  355. // $result->free();
  356. // return false;
  357. // }
  358. // $result->free();*/
  359. // $query = 'SELECT * FROM ' . $this->get_table_name($tablename);
  360. // if ($limit != null)
  361. // $this->db->setLimit($limit, $offset);
  362. //
  363. // if ($tool_name)
  364. // $query = $query . ' WHERE id IN (SELECT ref FROM ' . $this->get_table_name('item_property') . ' WHERE ' . 'tool=\'' . $tool_name . '\' AND visibility <> 2);';
  365. //
  366. // $result = $this->db->query($query);
  367. // if (MDB2 :: isError($result))
  368. // return false;
  369. //
  370. // $list = $this->mapper($result, $classname);
  371. // $result->free();
  372. // return $list;
  373. // }
  374. //
  375. // /**
  376. // * sets a boolean for move or copy files
  377. // * @param bool $move_file
  378. // */
  379. // static function set_move_file($move_file)
  380. // {
  381. // self :: $move_file = $move_file;
  382. // }
  383. //
  384. // /**
  385. // * Returns the first available course category
  386. // * @return int code of the first course category
  387. // */
  388. // function get_first_course_category()
  389. // {
  390. // $this->db_lcms_connect();
  391. // $query = 'SELECT code FROM ' . $this->get_table_name('weblcms_course_category');
  392. // $result = $this->db->query($query);
  393. // $record = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
  394. // $result->free();
  395. // if ($record)
  396. // return $record['code'];
  397. //
  398. // return null;
  399. // }
  400. //
  401. // /**
  402. // * Maps the result of the generic get_all method
  403. // * @param resultSet $result
  404. // * @param String $class
  405. // * @return Array with dokeos185 datatypes
  406. // */
  407. // function mapper($result, $class)
  408. // {
  409. // $list = array();
  410. // while ($record = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
  411. // {
  412. // $list[] = $this->record_to_classobject($record, $class);
  413. // }
  414. // $result->free();
  415. //
  416. // return $list;
  417. // }
  418. //
  419. // /**
  420. // * Gets all the answer of a question
  421. // * @param String $database
  422. // * @param int $id
  423. // * @return Array of Dokeos185QuizAnswers
  424. // */
  425. // function get_all_question_answer($database, $id)
  426. // {
  427. // $this->set_database($database);
  428. //
  429. // $query = 'SELECT * FROM ' . $this->get_table_name('quiz_answer') . ' WHERE question_id = ' . $id;
  430. // $result = $this->db->query($query);
  431. //
  432. // return $this->mapper($result, 'Dokeos185QuizAnswer');
  433. //
  434. // }
  435. //
  436. // function count_records($database, $table, $condition = null)
  437. // {
  438. // $this->set_database($database);
  439. // /*$querycheck = 'SHOW table status like \'' . $table . '\''; dump($querycheck);
  440. // $result = $this->db->query($querycheck);
  441. // if (MDB2 :: isError($result) || $result->numRows() == 0)
  442. // {
  443. // $result->free();
  444. // return 0;
  445. // }
  446. // $result->free();*/
  447. //
  448. // $query = 'SELECT COUNT(*) as number FROM ' . $this->get_table_name($table);
  449. //
  450. // if (isset($condition))
  451. // {
  452. // $translator = new ConditionTranslator($this);
  453. // $query .= $translator->render_query($condition);
  454. // }
  455. //
  456. // $result = $this->db->query($query);
  457. // unset($query);
  458. // $record = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
  459. // $result->free();
  460. // return $record['number'];
  461. // }
  462. //
  463. // function quote($value)
  464. // {
  465. // return $this->db->quote($value);
  466. // }
  467. //
  468. // static function is_date_column($name)
  469. // {
  470. // return false;
  471. // }
  472. //
  473. // function escape_column_name($name, $prefix_content_object_properties = false)
  474. // {
  475. // // Check whether the name contains a seperator, avoids notices.
  476. // $contains_table_name = strpos($name, '.');
  477. // if ($contains_table_name === false)
  478. // {
  479. // $table = $name;
  480. // $column = null;
  481. // }
  482. // else
  483. // {
  484. // list($table, $column) = explode('.', $name, 2);
  485. // }
  486. //
  487. // $prefix = '';
  488. //
  489. // if (isset($column))
  490. // {
  491. // $prefix = $table . '.';
  492. // $name = $column;
  493. // }
  494. // return $prefix . $this->db->quoteIdentifier($name);
  495. // }
  496. //
  497. // /**
  498. // * Expands a table identifier to the real table name. Currently, this
  499. // * method prefixes the given table name.
  500. // * @param string $name The table identifier.
  501. // * @return string The actual table name.
  502. // */
  503. // function get_table_name($name)
  504. // {
  505. // $dsn = $this->db->getDSN('array');
  506. // return $dsn['database'] . '.' . $name;
  507. // }
  508. //}
  509. //
  510. //
  511. ?>