Ejemplo n.º 1
0
 /**
  * Save a group of records to the user's favorites.
  *
  * @param array               $params Array with some or all of these keys:
  *  <ul>
  *    <li>ids - Array of IDs in source|id format</li>
  *    <li>mytags - Unparsed tag string to associate with record (optional)</li>
  *    <li>list - ID of list to save record into (omit to create new list)</li>
  *  </ul>
  * @param \VuFind\Db\Row\User $user   The user saving the record
  *
  * @return void
  */
 public function saveBulk($params, $user)
 {
     // Validate incoming parameters:
     if (!$user) {
         throw new LoginRequiredException('You must be logged in first');
     }
     // Get or create a list object as needed:
     $listId = isset($params['list']) ? $params['list'] : '';
     $table = $this->getController()->getTable('UserList');
     if (empty($listId) || $listId == 'NEW') {
         $list = $table->getNew($user);
         $list->title = $this->getController()->translate('My Favorites');
         $list->save($user);
     } else {
         $list = $table->getExisting($listId);
         $list->rememberLastUsed();
         // handled by save() in other case
     }
     // Loop through all the IDs and save them:
     foreach ($params['ids'] as $current) {
         // Break apart components of ID:
         list($source, $id) = explode('|', $current, 2);
         // Get or create a resource object as needed:
         $resourceTable = $this->getController()->getTable('Resource');
         $resource = $resourceTable->findResource($id, $source);
         // Add the information to the user's account:
         $tags = isset($params['mytags']) ? Tags::parse(trim($params['mytags'])) : array();
         $user->saveResource($resource, $list, $tags, '', false);
     }
 }
Ejemplo n.º 2
0
 /**
  * Test deduplication
  *
  * @return void
  */
 public function testDeduplication()
 {
     $this->assertEquals(['test'], $this->parser->parse('test test test'));
 }
Ejemplo n.º 3
0
 /**
  * Save this record to the user's favorites.
  *
  * @param array               $params Array with some or all of these keys:
  *  <ul>
  *    <li>mytags - Unparsed tag string to associate with record (optional)</li>
  *    <li>notes - Notes to associate with record (optional)</li>
  *    <li>list - ID of list to save record into (omit to create new list)</li>
  *  </ul>
  * @param \VuFind\Db\Row\User $user   The user saving the record
  *
  * @return void
  */
 public function saveToFavorites($params, $user)
 {
     // Validate incoming parameters:
     if (!$user) {
         throw new LoginRequiredException('You must be logged in first');
     }
     // Get or create a list object as needed:
     $listId = isset($params['list']) ? $params['list'] : '';
     $table = $this->getDbTable('UserList');
     if (empty($listId) || $listId == 'NEW') {
         $list = $table->getNew($user);
         $list->title = $this->translate('My Favorites');
         $list->save($user);
     } else {
         $list = $table->getExisting($listId);
         $list->rememberLastUsed();
         // handled by save() in other case
     }
     // Get or create a resource object as needed:
     $resourceTable = $this->getDbTable('Resource');
     $resource = $resourceTable->findResource($this->getUniqueId(), $this->resourceSource, true, $this);
     // Add the information to the user's account:
     $user->saveResource($resource, $list, isset($params['mytags']) ? Tags::parse(trim($params['mytags'])) : array(), isset($params['notes']) ? $params['notes'] : '');
 }