Entry.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace app\models;
  3. use app\models\Users;
  4. Class entry extends \lithium\data\Model {
  5. public static function __init() {
  6. parent::__init();
  7. //Validators go here
  8. }
  9. public $validates = array(
  10. 'my_watched_episodes' => array('numeric', 'message' => 'please enter a number'),
  11. 'my_start_date' => array('date', 'message' => 'Please enter a valid date'),
  12. 'my_finish_date' => array('date', 'message' => 'Please enter a valid date'),
  13. 'my_score' => array(array('inRange' => array('min' => 0, 'max' => '10'), 'message' => 'Enter a valid score'),
  14. array('numeric', 'message' => 'Please enter a number')),
  15. //'my_status' => array('isValidStatus', 'message' => 'please enter valid status'),
  16. 'my_times_watched' => array('numeric', 'message' => 'This must be a number')
  17. );
  18. /* Things to validate:
  19. ["my_watched_episodes"]=>
  20. string(2) "12" is equal to or less than anime->episode_count
  21. ["my_start_date"]=>
  22. string(5) "today" is a date
  23. ["my_finish_date"]=>
  24. string(5) "today" is a date later than start date
  25. ["my_score"]=>
  26. string(3) "15 " is between 0 and 10
  27. ["my_status"]=>
  28. string(1) "3"
  29. ["my_comments"]=>
  30. string(18) "This anime is tits"
  31. ["my_times_watched"]=>
  32. string(1) "2" is int
  33. ["rewatch_value"]=>
  34. string(1) "2"
  35. ["tags"]=>
  36. string(46) "winning tigerblood childrens_show your_grandma"
  37. ["rewatching"]=>
  38. string(0) ""
  39. **/
  40. /*
  41. public function add($entity, $username)
  42. {
  43. var_dump($entity->_data);
  44. exit();
  45. $updateData = array('$push' => array('animelist' => $entity));
  46. $conditions = array('username' => $username);
  47. $result = Entry::update($updateData, $conditions, array('atomic' => false));
  48. return $result;
  49. }
  50. */
  51. public function add($entity, $username)
  52. {
  53. $user = User::find('first', array('conditions' => compact('username')));
  54. $user->animelist[] = $entity;
  55. return $user->save(null, array('validate' => false));
  56. }
  57. }