]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - classes/Profile_tag.php
fix require in Profile_tag.php
[quix0rs-gnu-social.git] / classes / Profile_tag.php
1 <?php
2 /**
3  * Table Definition for profile_tag
4  */
5 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
6
7 class Profile_tag extends Memcached_DataObject 
8 {
9     ###START_AUTOCODE
10     /* the code below is auto generated do not remove the above tag */
11
12     public $__table = 'profile_tag';                     // table name
13     public $tagger;                          // int(4)  primary_key not_null
14     public $tagged;                          // int(4)  primary_key not_null
15     public $tag;                             // varchar(64)  primary_key not_null
16     public $modified;                        // timestamp()   not_null default_CURRENT_TIMESTAMP
17
18     /* Static get */
19     function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Profile_tag',$k,$v); }
20
21     /* the code above is auto generated do not remove the tag below */
22     ###END_AUTOCODE
23
24         static function getTags($tagger, $tagged) {
25                 
26                 $tags = array();
27
28                 # XXX: store this in memcached
29                 
30                 $profile_tag = new Profile_tag();
31                 $profile_tag->tagger = $tagger;
32                 $profile_tag->tagged = $tagged;
33                 
34                 $profile_tag->find();
35                 
36                 while ($profile_tag->fetch()) {
37                         $tags[] = $profile_tag->tag;
38                 }
39                 
40                 $profile_tag->free();
41                 
42                 return $tags;
43         }
44         
45         static function setTags($tagger, $tagged, $tags) {
46                 
47                 $oldtags = Profile_tag::getTags($tagger, $tagged);
48                 
49                 # Delete stuff that's old that not in new
50                 
51                 $to_delete = array_diff($oldtags, $newtags);
52                 
53                 # Insert stuff that's in new and not in old
54                 
55                 $to_insert = array_diff($newtags, $oldtags);
56                 
57                 $profile_tag = new Profile_tag();
58                 
59                 $profile_tag->tagger = $tagger;
60                 $profile_tag->tagged = $tagged;
61                 
62                 $profile_tag->query('BEGIN');
63                 
64                 foreach ($to_delete as $deltag) {
65                         $profile_tag->tag = $deltag;
66                         $result = $profile_tag->delete();
67                         if (!$result) {
68                                 common_log_db_error($profile_tag, 'DELETE', __FILE__);
69                                 return false;
70                         }
71                 }
72                 
73                 foreach ($to_insert as $instag) {
74                         $profile_tag->tag = $instag;
75                         $result = $profile_tag->insert();
76                         if (!$result) {
77                                 common_log_db_error($profile_tag, 'INSERT', __FILE__);
78                                 return false;
79                         }
80                 }
81                 
82                 $profile_tag->query('COMMIT');
83                 
84                 return true;
85         }
86 }