/**
  * Test setting and retrieving data
  *
  * @return void
  */
 public function testCreateSaveAndRetrieve()
 {
     // Create a sample friend
     $f = new WpHerissonFriends();
     $datas = array('alias' => $this->sampleName, 'url' => $this->sampleUrl, 'name' => 'name', 'email' => 'email', 'public_key' => 'public_key', 'is_active' => 12, 'b_wantsyou' => 34, 'b_youwant' => 56);
     $sql = array();
     foreach ($datas as $key => $value) {
         $f->{$key} = $value;
         $sql[] = "{$key}=?";
     }
     $f->save();
     $id = $f->id;
     // Check it's saved in the DB, with all parameters
     $friends = WpHerissonFriendsTable::getWhere(implode(' AND ', $sql), array_values($datas));
     $this->assertEquals(1, sizeof($friends));
     // Retrieve the id
     $g = WpHerissonFriendsTable::get($id);
     foreach ($datas as $key => $value) {
         $this->assertEquals($value, $g->{$key});
     }
     // Cleanup
     $g->delete();
 }
Пример #2
0
 /**
  * Handle the importation of bookmarks from a friend
  *
  * @return a list of WpHerissonBookmarks
  */
 public function import()
 {
     $friendId = post('friendId');
     if (!$friendId) {
         throw new Exception("Missing friend Id");
     }
     $friend = WpHerissonFriendsTable::get(post('friendId'));
     if (!$friend->id) {
         throw new Exception("Unknown friend");
     }
     $bookmarks = $friend->retrieveBookmarks();
     return $bookmarks;
 }
Пример #3
0
 /**
  * Action to edit a friend
  *
  * If POST method used, update the given friend with the POST parameters,
  * otherwise just display the friend properties
  *
  * @return void
  */
 function editAction()
 {
     $id = intval(param('id'));
     if (!$id) {
         $id = 0;
     }
     if (sizeof($_POST)) {
         $url = post('url');
         $alias = post('alias');
         $new = $id == 0 ? true : false;
         if ($new) {
             $friend = new WpHerissonFriends();
             $friend->is_active = 0;
         } else {
             $friend = WpHerissonFriendsTable::get($id);
         }
         $friend->alias = $alias;
         $friend->url = $url;
         if ($new) {
             $friend->getInfo();
             $friend->askForFriend();
         }
         $friend->save();
         if ($new) {
             if ($new && $friend->is_active) {
                 Message::i()->addSucces(__("Friend has been added and automatically validated"));
             } else {
                 Message::i()->addSucces(__("Friend has been added, but needs to be validated by its owner"));
             }
             // Return to list after creating new friend.
             $this->indexAction();
             $this->setView('index');
             return;
         } else {
             Message::i()->addSucces(__("Friend saved"));
         }
     }
     if ($id == 0) {
         $this->view->existing = new WpHerissonFriends();
     } else {
         $this->view->existing = WpHerissonFriendsTable::get($id);
     }
     $this->view->id = $id;
 }
Пример #4
0
 /**
  * Download a backup from friend
  *
  * @return void
  */
 private function _retrieve()
 {
     $friend = WpHerissonFriendsTable::get(get('id'));
     if (!$friend->id) {
         Message::i()->addError(__("Friend could not be found", HERISSON_TD));
         $this->indexAction();
         $this->setView('index');
         return;
     }
     return $friend->downloadBackup();
 }