Exemple #1
0
 /**
  * Add new friend.
  *
  * @static
  * @param   integer  $user_id
  * @param   integer  $friend_id
  * @return  boolean
  */
 public static function add($user_id, $friend_id)
 {
     try {
         $friend = new Model_Friend();
         $friend->set_fields(array('user_id' => $user_id, 'friend_id' => $friend_id, 'created' => time()));
         $friend->save();
         Anqh::cache_delete('friends_' . $user_id);
         Anqh::cache_delete('friends_of_' . $friend_id);
         return true;
     } catch (Exception $e) {
         return false;
     }
 }
Exemple #2
0
 public function action_request_accept()
 {
     // no confirmation
     $friend = new Model_Owner($this->request->param('id'));
     if (!$friend->is_on_my_friends_list($this->me())) {
         Message::add('error', 'This person does not want to be your friend.');
         Request::current()->redirect('');
     }
     if ($friend->is_on_friends_friends_list($this->me())) {
         Message::add('error', 'You are already friends with this person.');
         Request::current()->redirect('');
     }
     $new_friend = new Model_Friend();
     $new_friend->creator_id = $this->me()->id;
     $new_friend->firstname = $friend->firstname;
     $new_friend->surname = $friend->surname;
     $new_friend->email = $friend->email;
     $new_friend->save();
     Message::add('success', 'Successfully confirmed friendship');
     Request::current()->redirect('');
 }
Exemple #3
0
 private function add_new_friends_from_post(&$view, $list)
 {
     $added = 0;
     $view->new_friends = array();
     $i = 0;
     $firstnames = arr::get($_POST, 'firstname', array());
     $surnames = arr::get($_POST, 'surname', array());
     $emails = arr::get($_POST, 'email', array());
     foreach ($firstnames as $firstname) {
         // would be nice if PHP could traverse multiple arrays in one foreach
         $surname = $surnames[$i];
         $email = $emails[$i];
         $i++;
         if (!strlen($firstname . $surname . $email)) {
             continue;
         }
         if (empty($firstname) || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
             $view->new_friends[] = array($firstname, $surname, $email);
             $view->errors['new'] = 'Please enter a first name and a valid email address.';
             continue;
         }
         // already got a friend with this email
         if ($this->me('owner')->has_friend_with_email($email)) {
             $friend = new Model_Friend(array('email' => $email, 'creator_id' => $this->me()->id));
             if ($friend->is_on_list($list)) {
                 Message::add('warning', $friend->firstname . ' ' . $friend->surname . ' is already on this list.');
                 continue;
             }
         } else {
             $friend = new Model_Friend();
             $friend->creator = $this->me();
             $friend->firstname = $firstname;
             $friend->surname = $surname;
             $friend->email = $email;
             $friend->save();
         }
         $friend->add('lists', $list);
         $added++;
     }
     return $added;
 }