extra_field_value.lib.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Declaration for the ExtraFieldValue class, managing the values in extra
  5. * fields for any datatype
  6. * @package chamilo.library
  7. */
  8. /**
  9. * Class managing the values in extra fields for any datatype
  10. * @package chamilo.library.extrafields
  11. */
  12. class ExtraFieldValue extends Model
  13. {
  14. public $type = null;
  15. public $columns = array('id', 'field_id', 'field_value', 'tms', 'comment');
  16. /** @var string session_id, course_code, user_id, question id */
  17. public $handler_id = null;
  18. public $entityName;
  19. /**
  20. * Formats the necessary elements for the given datatype
  21. * @param string The type of data to which this extra field applies (user, course, session, ...)
  22. * @return void (or false if unmanaged datatype)
  23. * @assert (-1) === false
  24. */
  25. public function __construct($type)
  26. {
  27. $this->type = $type;
  28. $extra_field = new ExtraField($this->type);
  29. $this->handler_id = $extra_field->handler_id;
  30. switch ($this->type) {
  31. case 'course':
  32. $this->table = Database::get_main_table(TABLE_MAIN_COURSE_FIELD_VALUES);
  33. $this->table_handler_field = Database::get_main_table(TABLE_MAIN_COURSE_FIELD);
  34. $this->author_id = 'user_id';
  35. $this->entityName = 'ChamiloLMS\Entity\CourseFieldValues';
  36. break;
  37. case 'user':
  38. $this->table = Database::get_main_table(TABLE_MAIN_USER_FIELD_VALUES);
  39. $this->table_handler_field = Database::get_main_table(TABLE_MAIN_USER_FIELD);
  40. $this->author_id = 'author_id';
  41. $this->entityName = 'ChamiloLMS\Entity\UserFieldValues';
  42. break;
  43. case 'session':
  44. $this->table = Database::get_main_table(TABLE_MAIN_SESSION_FIELD_VALUES);
  45. $this->table_handler_field = Database::get_main_table(TABLE_MAIN_SESSION_FIELD);
  46. $this->author_id = 'user_id';
  47. $this->entityName = 'ChamiloLMS\Entity\SessionFieldValues';
  48. break;
  49. case 'question':
  50. $this->table = Database::get_main_table(TABLE_MAIN_QUESTION_FIELD_VALUES);
  51. $this->table_handler_field = Database::get_main_table(TABLE_MAIN_QUESTION_FIELD);
  52. $this->author_id = 'user_id';
  53. $this->entityName = 'ChamiloLMS\Entity\QuestionFieldValues';
  54. break;
  55. case 'lp':
  56. $this->table = Database::get_main_table(TABLE_MAIN_LP_FIELD_VALUES);
  57. $this->table_handler_field = Database::get_main_table(TABLE_MAIN_LP_FIELD);
  58. $this->author_id = 'lp_id';
  59. //$this->entityName = 'ChamiloLMS\Entity\QuestionFieldValues';
  60. break;
  61. default:
  62. //unmanaged datatype, return false to let the caller know it
  63. // didn't work
  64. return false;
  65. }
  66. $this->columns[] = $this->handler_id;
  67. $this->columns[] = $this->author_id;
  68. }
  69. /**
  70. * Gets the number of values stored in the table (all fields together)
  71. * for this type of resource
  72. * @return integer Number of rows in the table
  73. * @assert () !== false
  74. */
  75. public function get_count()
  76. {
  77. $row = Database::select('count(*) as count', $this->table, array(), 'first');
  78. return $row['count'];
  79. }
  80. /**
  81. * Saves a series of records given as parameter into the coresponding table
  82. * @param array Structured parameter for the insertion into the *_field_values table
  83. * @return mixed false on empty params, void otherwise
  84. * @assert (array()) === false
  85. */
  86. public function save_field_values($params)
  87. {
  88. $extra_field = new ExtraField($this->type);
  89. if (empty($params[$this->handler_id])) {
  90. return false;
  91. }
  92. foreach ($params as $key => $value) {
  93. $found = strpos($key, '__persist__');
  94. if ($found) {
  95. $tempKey = str_replace('__persist__', '', $key);
  96. if (!isset($params[$tempKey])) {
  97. $params[$tempKey] = array();
  98. }
  99. break;
  100. }
  101. }
  102. // Parse params.
  103. foreach ($params as $key => $value) {
  104. if (substr($key, 0, 6) == 'extra_') {
  105. // An extra field.
  106. $field_variable = substr($key, 6);
  107. $extra_field_info = $extra_field->get_handler_field_info_by_field_variable($field_variable);
  108. if ($extra_field_info) {
  109. $commentVariable = 'extra_'.$field_variable.'_comment';
  110. $comment = isset($params[$commentVariable]) ? $params[$commentVariable] : null;
  111. switch ($extra_field_info['field_type']) {
  112. case ExtraField::FIELD_TYPE_TAG :
  113. $old = self::getAllValuesByItemAndField(
  114. $extra_field_info['id'],
  115. $params[$this->handler_id]
  116. );
  117. $deleteItems = array();
  118. if (!empty($old)) {
  119. $oldIds = array();
  120. foreach ($old as $oldItem) {
  121. $oldIds[] = $oldItem['field_value'];
  122. }
  123. $deleteItems = array_diff($oldIds, $value);
  124. }
  125. foreach ($value as $optionId) {
  126. $new_params = array(
  127. $this->handler_id => $params[$this->handler_id],
  128. 'field_id' => $extra_field_info['id'],
  129. 'field_value' => $optionId,
  130. 'comment' => $comment
  131. );
  132. self::save($new_params);
  133. }
  134. if (!empty($deleteItems)) {
  135. foreach ($deleteItems as $deleteFieldValue) {
  136. self::deleteValuesByHandlerAndFieldAndValue(
  137. $extra_field_info['id'],
  138. $params[$this->handler_id],
  139. $deleteFieldValue
  140. );
  141. }
  142. }
  143. break;
  144. default;
  145. $new_params = array(
  146. $this->handler_id => $params[$this->handler_id],
  147. 'field_id' => $extra_field_info['id'],
  148. 'field_value' => $value,
  149. 'comment' => $comment
  150. );
  151. self::save($new_params);
  152. }
  153. }
  154. }
  155. }
  156. }
  157. /**
  158. * Save values in the *_field_values table
  159. * @param array Structured array with the values to save
  160. * @param boolean Whether to show the insert query (passed to the parent save() method)
  161. * @result mixed The result sent from the parent method
  162. * @assert (array()) === false
  163. */
  164. public function save($params, $show_query = false)
  165. {
  166. $extra_field = new ExtraField($this->type);
  167. // Setting value to insert.
  168. $value = $params['field_value'];
  169. $value_to_insert = null;
  170. if (is_array($value)) {
  171. $value_to_insert = implode(';', $value);
  172. } else {
  173. $value_to_insert = Database::escape_string($value);
  174. }
  175. $params['field_value'] = $value_to_insert;
  176. //If field id exists
  177. $extra_field_info = $extra_field->get($params['field_id']);
  178. if ($extra_field_info) {
  179. switch ($extra_field_info['field_type']) {
  180. case ExtraField::FIELD_TYPE_RADIO:
  181. case ExtraField::FIELD_TYPE_SELECT:
  182. case ExtraField::FIELD_TYPE_SELECT_MULTIPLE:
  183. //$field_options = $session_field_option->get_field_options_by_field($params['field_id']);
  184. //$params['field_value'] = split(';', $value_to_insert);
  185. /*
  186. if ($field_options) {
  187. $check = false;
  188. foreach ($field_options as $option) {
  189. if (in_array($option['option_value'], $values)) {
  190. $check = true;
  191. break;
  192. }
  193. }
  194. if (!$check) {
  195. return false; //option value not found
  196. }
  197. } else {
  198. return false; //enumerated type but no option found
  199. }*/
  200. break;
  201. case ExtraField::FIELD_TYPE_TEXT:
  202. case ExtraField::FIELD_TYPE_TEXTAREA:
  203. break;
  204. case ExtraField::FIELD_TYPE_DOUBLE_SELECT:
  205. if (is_array($value)) {
  206. if (isset($value['extra_'.$extra_field_info['field_variable']]) &&
  207. isset($value['extra_'.$extra_field_info['field_variable'].'_second'])
  208. ) {
  209. $value_to_insert = $value['extra_'.$extra_field_info['field_variable']].'::'.$value['extra_'.$extra_field_info['field_variable'].'_second'];
  210. } else {
  211. $value_to_insert = null;
  212. }
  213. }
  214. break;
  215. default:
  216. break;
  217. }
  218. if ($extra_field_info['field_type'] == ExtraField::FIELD_TYPE_TAG) {
  219. $field_values = self::getAllValuesByItemAndFieldAndValue(
  220. $params[$this->handler_id],
  221. $params['field_id'],
  222. $value
  223. );
  224. } else {
  225. $field_values = self::get_values_by_handler_and_field_id(
  226. $params[$this->handler_id],
  227. $params['field_id']
  228. );
  229. }
  230. $params['field_value'] = $value_to_insert;
  231. $params['tms'] = api_get_utc_datetime();
  232. $params[$this->author_id] = api_get_user_id();
  233. // Insert
  234. if (empty($field_values)) {
  235. if ($extra_field_info['field_loggeable'] == 1) {
  236. global $app;
  237. switch($this->type) {
  238. case 'question':
  239. $extraFieldValue = new ChamiloLMS\Entity\QuestionFieldValues();
  240. $extraFieldValue->setUserId(api_get_user_id());
  241. $extraFieldValue->setQuestionId($params[$this->handler_id]);
  242. break;
  243. case 'course':
  244. $extraFieldValue = new ChamiloLMS\Entity\CourseFieldValues();
  245. $extraFieldValue->setUserId(api_get_user_id());
  246. $extraFieldValue->setQuestionId($params[$this->handler_id]);
  247. break;
  248. case 'user':
  249. $extraFieldValue = new ChamiloLMS\Entity\UserFieldValues();
  250. $extraFieldValue->setUserId($params[$this->handler_id]);
  251. $extraFieldValue->setAuthorId(api_get_user_id());
  252. break;
  253. case 'session':
  254. $extraFieldValue = new ChamiloLMS\Entity\SessionFieldValues();
  255. $extraFieldValue->setUserId(api_get_user_id());
  256. $extraFieldValue->setSessionId($params[$this->handler_id]);
  257. break;
  258. }
  259. if (isset($extraFieldValue)) {
  260. if (!empty($params['field_value'])) {
  261. $extraFieldValue->setComment($params['comment']);
  262. $extraFieldValue->setFieldValue($params['field_value']);
  263. $extraFieldValue->setFieldId($params['field_id']);
  264. $extraFieldValue->setTms(api_get_utc_datetime(null, false, true));
  265. $app['orm.ems']['db_write']->persist($extraFieldValue);
  266. $app['orm.ems']['db_write']->flush();
  267. }
  268. }
  269. } else {
  270. if ($extra_field_info['field_type'] == ExtraField::FIELD_TYPE_TAG) {
  271. $option = new ExtraFieldOption($this->type);
  272. $optionExists = $option->get($params['field_value']);
  273. if (empty($optionExists)) {
  274. $optionParams = array(
  275. 'field_id' => $params['field_id'],
  276. 'option_value' => $params['field_value']
  277. );
  278. $optionId = $option->saveOptions($optionParams);
  279. } else {
  280. $optionId = $optionExists['id'];
  281. }
  282. $params['field_value'] = $optionId;
  283. if ($optionId) {
  284. return parent::save($params, $show_query);
  285. }
  286. } else {
  287. return parent::save($params, $show_query);
  288. }
  289. }
  290. } else {
  291. // Update
  292. if ($extra_field_info['field_loggeable'] == 1) {
  293. global $app;
  294. switch($this->type) {
  295. case 'question':
  296. $extraFieldValue = $app['orm.ems']['db_write']->getRepository('ChamiloLMS\Entity\QuestionFieldValues')->find($field_values['id']);
  297. $extraFieldValue->setUserId(api_get_user_id());
  298. $extraFieldValue->setQuestionId($params[$this->handler_id]);
  299. break;
  300. case 'course':
  301. $extraFieldValue = $app['orm.ems']['db_write']->getRepository('ChamiloLMS\Entity\CourseFieldValues')->find($field_values['id']);
  302. $extraFieldValue->setUserId(api_get_user_id());
  303. $extraFieldValue->setCourseCode($params[$this->handler_id]);
  304. break;
  305. case 'user':
  306. $extraFieldValue = $app['orm.ems']['db_write']->getRepository('ChamiloLMS\Entity\UserFieldValues')->find($field_values['id']);
  307. $extraFieldValue->setUserId(api_get_user_id());
  308. $extraFieldValue->setAuthorId(api_get_user_id());
  309. break;
  310. case 'session':
  311. $extraFieldValue = $app['orm.ems']['db_write']->getRepository('ChamiloLMS\Entity\SessionFieldValues')->find($field_values['id']);
  312. $extraFieldValue->setUserId(api_get_user_id());
  313. $extraFieldValue->setSessionId($params[$this->handler_id]);
  314. break;
  315. }
  316. if (isset($extraFieldValue)) {
  317. if (!empty($params['field_value'])) {
  318. /*
  319. * If the field value is similar to the previous value then the comment will be the same
  320. in order to no save in the log an empty record
  321. */
  322. if ($extraFieldValue->getFieldValue() == $params['field_value']) {
  323. if (empty($params['comment'])) {
  324. $params['comment'] = $extraFieldValue->getComment();
  325. }
  326. }
  327. $extraFieldValue->setComment($params['comment']);
  328. $extraFieldValue->setFieldValue($params['field_value']);
  329. $extraFieldValue->setFieldId($params['field_id']);
  330. $extraFieldValue->setTms(api_get_utc_datetime(null, false, true));
  331. $app['orm.ems']['db_write']->persist($extraFieldValue);
  332. $app['orm.ems']['db_write']->flush();
  333. }
  334. }
  335. } else {
  336. $params['id'] = $field_values['id'];
  337. return parent::update($params, $show_query);
  338. }
  339. }
  340. }
  341. }
  342. /**
  343. * Returns the value of the given extra field on the given resource
  344. * @param int Item ID (It could be a session_id, course_id or user_id)
  345. * @param int Field ID (the ID from the *_field table)
  346. * @param bool Whether to transform the result to a human readable strings
  347. * @return mixed A structured array with the field_id and field_value, or false on error
  348. * @assert (-1,-1) === false
  349. */
  350. public function get_values_by_handler_and_field_id($item_id, $field_id, $transform = false)
  351. {
  352. $field_id = intval($field_id);
  353. $item_id = Database::escape_string($item_id);
  354. $sql = "SELECT s.*, field_type FROM {$this->table} s
  355. INNER JOIN {$this->table_handler_field} sf ON (s.field_id = sf.id)
  356. WHERE {$this->handler_id} = '$item_id' AND
  357. field_id = '".$field_id."'
  358. ORDER BY id";
  359. $result = Database::query($sql);
  360. if (Database::num_rows($result)) {
  361. $result = Database::fetch_array($result, 'ASSOC');
  362. if ($transform) {
  363. if (!empty($result['field_value'])) {
  364. switch ($result['field_type']) {
  365. case ExtraField::FIELD_TYPE_DOUBLE_SELECT:
  366. $field_option = new ExtraFieldOption($this->type);
  367. $options = explode('::', $result['field_value']);
  368. // only available for PHP 5.4 :( $result['field_value'] = $field_option->get($options[0])['id'].' -> ';
  369. $result = $field_option->get($options[0]);
  370. $result_second = $field_option->get($options[1]);
  371. if (!empty($result)) {
  372. $result['field_value'] = $result['option_display_text'].' -> ';
  373. $result['field_value'] .= $result_second['option_display_text'];
  374. }
  375. break;
  376. case ExtraField::FIELD_TYPE_SELECT:
  377. $field_option = new ExtraFieldOption($this->type);
  378. $extra_field_option_result = $field_option->get_field_option_by_field_and_option(
  379. $result['field_id'],
  380. $result['field_value']
  381. );
  382. if (isset($extra_field_option_result[0])) {
  383. $result['field_value'] = $extra_field_option_result[0]['option_display_text'];
  384. }
  385. break;
  386. }
  387. }
  388. }
  389. return $result;
  390. } else {
  391. return false;
  392. }
  393. }
  394. /**
  395. * @param string $tag
  396. * @param int $field_id
  397. * @param int $limit
  398. * @return array
  399. */
  400. public function searchValuesByField($tag, $field_id, $limit = 10)
  401. {
  402. $field_id = intval($field_id);
  403. $limit = intval($limit);
  404. $tag = Database::escape_string($tag);
  405. $sql = "SELECT DISTINCT s.field_value, s.field_id
  406. FROM {$this->table} s
  407. INNER JOIN {$this->table_handler_field} sf ON (s.field_id = sf.id)
  408. WHERE
  409. field_id = '".$field_id."' AND
  410. field_value LIKE '%$tag%'
  411. ORDER BY field_value
  412. LIMIT 0, $limit
  413. ";
  414. $result = Database::query($sql);
  415. $values = array();
  416. if (Database::num_rows($result)) {
  417. $values = Database::store_result($result, 'ASSOC');
  418. }
  419. return $values;
  420. }
  421. /**
  422. * Gets a structured array of the original item and its extra values, using
  423. * a specific original item and a field name (like "branch", or "birthdate")
  424. * @param int Item ID from the original table
  425. * @param string The name of the field we are looking for
  426. * @return mixed Array of results, or false on error or not found
  427. * @assert (-1,'') === false
  428. */
  429. public function get_values_by_handler_and_field_variable($item_id, $field_variable, $transform = false)
  430. {
  431. $item_id = Database::escape_string($item_id);
  432. $field_variable = Database::escape_string($field_variable);
  433. $sql = "SELECT s.*, field_type FROM {$this->table} s
  434. INNER JOIN {$this->table_handler_field} sf
  435. ON (s.field_id = sf.id)
  436. WHERE
  437. {$this->handler_id} = '$item_id' AND
  438. field_variable = '".$field_variable."'
  439. ORDER BY id";
  440. $result = Database::query($sql);
  441. if (Database::num_rows($result)) {
  442. $result = Database::fetch_array($result, 'ASSOC');
  443. if ($transform) {
  444. if ($result['field_type'] == ExtraField::FIELD_TYPE_DOUBLE_SELECT) {
  445. if (!empty($result['field_value'])) {
  446. $field_option = new ExtraFieldOption($this->type);
  447. $options = explode('::', $result['field_value']);
  448. // only available for PHP 5.4 :( $result['field_value'] = $field_option->get($options[0])['id'].' -> ';
  449. $result = $field_option->get($options[0]);
  450. $result_second = $field_option->get($options[1]);
  451. if (!empty($result)) {
  452. $result['field_value'] = $result['option_display_text'].' -> ';
  453. $result['field_value'] .= $result_second['option_display_text'];
  454. }
  455. }
  456. }
  457. }
  458. return $result;
  459. } else {
  460. return false;
  461. }
  462. }
  463. /**
  464. * Gets the ID from the item (course, session, etc) for which
  465. * the given field is defined with the given value
  466. * @param string Field (type of data) we want to check
  467. * @param string Data we are looking for in the given field
  468. * @return mixed Give the ID if found, or false on failure or not found
  469. * @assert (-1,-1) === false
  470. */
  471. public function get_item_id_from_field_variable_and_field_value($field_variable, $field_value, $transform = false)
  472. {
  473. $field_value = Database::escape_string($field_value);
  474. $field_variable = Database::escape_string($field_variable);
  475. $sql = "SELECT {$this->handler_id} FROM {$this->table} s
  476. INNER JOIN {$this->table_handler_field} sf
  477. ON (s.field_id = sf.id)
  478. WHERE
  479. field_value = '$field_value' AND
  480. field_variable = '".$field_variable."'
  481. ";
  482. $result = Database::query($sql);
  483. if ($result !== false && Database::num_rows($result)) {
  484. $result = Database::fetch_array($result, 'ASSOC');
  485. return $result;
  486. } else {
  487. return false;
  488. }
  489. }
  490. /**
  491. * Get all values for a specific field id
  492. * @param int Field ID
  493. * @return mixed Array of values on success, false on failure or not found
  494. * @assert (-1) === false
  495. */
  496. public function get_values_by_field_id($field_id)
  497. {
  498. $field_id = intval($field_id);
  499. $sql = "SELECT s.*, field_type FROM {$this->table} s
  500. INNER JOIN {$this->table_handler_field} sf
  501. ON (s.field_id = sf.id)
  502. WHERE field_id = '".$field_id."' ORDER BY id";
  503. $result = Database::query($sql);
  504. if (Database::num_rows($result)) {
  505. return Database::store_result($result, 'ASSOC');
  506. }
  507. return false;
  508. }
  509. /**
  510. * @param int $itemId
  511. * @param int $fieldId
  512. * @return array
  513. */
  514. public function getAllValuesByItemAndField($itemId, $fieldId)
  515. {
  516. $fieldId = intval($fieldId);
  517. $itemId = intval($itemId);
  518. $sql = "SELECT s.* FROM {$this->table} s
  519. INNER JOIN {$this->table_handler_field} sf
  520. ON (s.field_id = sf.id)
  521. WHERE
  522. field_id = '".$fieldId."' AND
  523. {$this->handler_id} = '$itemId'
  524. ORDER BY field_value";
  525. $result = Database::query($sql);
  526. if (Database::num_rows($result)) {
  527. return Database::store_result($result, 'ASSOC');
  528. }
  529. return false;
  530. }
  531. /**
  532. * @param int $itemId
  533. * @param int $fieldId
  534. * @param string $fieldValue
  535. * @return array|bool
  536. */
  537. public function getAllValuesByItemAndFieldAndValue($itemId, $fieldId, $fieldValue)
  538. {
  539. $fieldId = intval($fieldId);
  540. $itemId = intval($itemId);
  541. $fieldValue = Database::escape_string($fieldValue);
  542. $sql = "SELECT s.* FROM {$this->table} s
  543. INNER JOIN {$this->table_handler_field} sf
  544. ON (s.field_id = sf.id)
  545. WHERE
  546. field_id = '".$fieldId."' AND
  547. {$this->handler_id} = '$itemId' AND
  548. field_value = $fieldValue
  549. ORDER BY field_value";
  550. $result = Database::query($sql);
  551. if (Database::num_rows($result)) {
  552. return Database::store_result($result, 'ASSOC');
  553. }
  554. return false;
  555. }
  556. /**
  557. * Deletes all the values related to a specific field ID
  558. * @param int Field ID
  559. * @return void
  560. * @assert ('a') == null
  561. */
  562. public function delete_all_values_by_field_id($field_id)
  563. {
  564. $field_id = intval($field_id);
  565. $sql = "DELETE FROM {$this->table} WHERE field_id = $field_id";
  566. Database::query($sql);
  567. }
  568. /**
  569. * Deletes values of a specific field for a specific item
  570. * @param int Item ID (session id, course id, etc)
  571. * @param int Field ID
  572. * @return void
  573. * @assert (-1,-1) == null
  574. */
  575. public function delete_values_by_handler_and_field_id($item_id, $field_id)
  576. {
  577. $field_id = intval($field_id);
  578. $item_id = Database::escape_string($item_id);
  579. $sql = "DELETE FROM {$this->table} WHERE {$this->handler_id} = '$item_id' AND field_id = '".$field_id."' ";
  580. Database::query($sql);
  581. }
  582. /**
  583. * @param int $itemId
  584. * @param int $fieldId
  585. * @param int $fieldValue
  586. */
  587. public function deleteValuesByHandlerAndFieldAndValue($itemId, $fieldId, $fieldValue)
  588. {
  589. $itemId = intval($itemId);
  590. $fieldId = intval($fieldId);
  591. $fieldValue = Database::escape_string($fieldValue);
  592. $sql = "DELETE FROM {$this->table}
  593. WHERE
  594. {$this->handler_id} = '$itemId' AND
  595. field_id = '".$fieldId."' AND
  596. field_value = '$fieldValue'";
  597. Database::query($sql);
  598. }
  599. /**
  600. * Not yet implemented - Compares the field values of two items
  601. * @param int Item 1
  602. * @param int Item 2
  603. * @return mixed Differential array generated from the comparison
  604. */
  605. public function compare_item_values($item_id, $item_to_compare)
  606. {
  607. }
  608. }