summaryrefslogtreecommitdiffstats
path: root/models/Entry.php
blob: d9d2a2deeed1f2458149ac88647949a6bfe09073 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php

namespace app\models;

use app\models\Users;

Class entry extends \lithium\data\Model {
	public static function __init() {
		parent::__init();

		//Validators go here
	}

	public $validates = array(
		    'my_watched_episodes' => array('numeric', 'message' => 'please enter a number'),
			'my_start_date' => array('date', 'message' => 'Please enter a valid date'),
			'my_finish_date' => array('date', 'message' => 'Please enter a valid date'),
			'my_score' => array(array('inRange' => array('min' => 0, 'max' => '10'), 'message' => 'Enter a valid score'),
								array('numeric', 'message' => 'Please enter a number')),
			//'my_status' => array('isValidStatus', 'message' => 'please enter valid status'),
			'my_times_watched' => array('numeric', 'message' => 'This must be a number')
		);

	/* Things to validate:
    ["my_watched_episodes"]=>
    string(2) "12" is equal to or less than  anime->episode_count
    ["my_start_date"]=>
    string(5) "today" is a date
    ["my_finish_date"]=>
    string(5) "today" is a date later than start date
    ["my_score"]=>
    string(3) "15 " is between 0 and 10
    ["my_status"]=>
    string(1) "3"
    ["my_comments"]=>
    string(18) "This anime is tits"
    ["my_times_watched"]=>
    string(1) "2" is int
    ["rewatch_value"]=>
    string(1) "2"
    ["tags"]=>
    string(46) "winning tigerblood childrens_show your_grandma"
    ["rewatching"]=>
    string(0) ""
	**/

	/*
	public function add($entity, $username)
	{
		var_dump($entity->_data);
		exit();
		$updateData = array('$push' => array('animelist' => $entity));
		$conditions = array('username' => $username);
		$result = Entry::update($updateData, $conditions, array('atomic' => false));
		return $result; 
	}
	*/

	public function add($entity, $username)
	{
		$user = User::find('first', array('conditions' => compact('username')));
		$user->animelist[] = $entity;
		return $user->save(null, array('validate' => false));

	}
}