extra_field_value.lib.php 28 KB

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