예제 #1
0
파일: Copy.php 프로젝트: bharatm/NDL-VuFind
 /**
  * Perform a bulk operation.
  *
  * @param array $ids    IDs to process
  * @param int   $listID Target list
  * limit).
  *
  * @return boolean Success
  */
 protected function processRecords($ids, $listID)
 {
     global $user;
     if (empty($ids)) {
         $this->errorMsg = 'bulk_noitems_advice';
         return false;
     }
     if (!$user) {
         $this->errorMsg = 'You must be logged in first';
         return false;
     }
     $list = User_list::staticGet($listID);
     if ($user->id != $list->user_id) {
         $this->errorMsg = 'list_access_denied';
         return false;
     }
     $resources = $user->getResources();
     foreach ($resources as $resource) {
         if (in_array($resource->record_id, $ids)) {
             $notes = '';
             $userResource = new User_resource();
             $userResource->user_id = $user->id;
             $userResource->list_id = $_REQUEST['listID'];
             $userResource->resource_id = $resource->id;
             if ($userResource->find(true)) {
                 $notes = $userResource->notes;
             }
             $tags = array();
             foreach ($user->getTags($resource->record_id) as $tag) {
                 $tags[] = $tag->tag;
             }
             $user->addResource($resource, $list, $tags, $notes);
         }
     }
     $this->infoMsg = 'records_copied';
     return true;
 }
예제 #2
0
파일: User.php 프로젝트: bharatm/NDL-VuFind
 /**
  * Add a resource to the user's account.
  *
  * @param object $resource        The resource to add.
  * @param object $list            The list to store the resource in.
  * @param array  $tagArray        An array of tags to associate with the
  * resource.
  * @param string $notes           User notes about the resource.
  * @param bool   $replaceExisting Whether to replace all existing tags (true)
  * or append to the existing list (false).
  *
  * @return bool
  * @access public
  */
 public function addResource($resource, $list, $tagArray, $notes, $replaceExisting = true)
 {
     $join = new User_resource();
     $join->user_id = $this->id;
     $join->resource_id = $resource->id;
     $join->list_id = $list->id;
     if ($join->find(true)) {
         $join->notes = $notes;
         $join->update();
         // update() will return false if we save without making any changes,
         // but we always want to report success after this point.
         $result = true;
     } else {
         if ($notes) {
             $join->notes = $notes;
         }
         $result = $join->insert();
     }
     if ($result) {
         $join = new Resource_tags();
         $join->resource_id = $resource->id;
         $join->user_id = $this->id;
         $join->list_id = $list->id;
         if ($replaceExisting) {
             // Delete old tags -- note that we need to clone $join for this
             // operation or else it will be broken when we use it for searching
             // below.
             $killer = clone $join;
             $killer->delete();
         }
         // Add new tags, if any:
         if (is_array($tagArray) && count($tagArray)) {
             foreach ($tagArray as $value) {
                 $value = str_replace('"', '', $value);
                 $tag = new Tags();
                 $tag->tag = $value;
                 if (!$tag->find(true)) {
                     $tag->insert();
                 }
                 $join->tag_id = $tag->id;
                 // Don't save duplicate tags!
                 if (!$join->find(false)) {
                     $join->insert();
                 }
             }
         }
         // Update list modification date
         $list->updateModifiedDate();
         return true;
     } else {
         return false;
     }
 }
예제 #3
0
 /**
  * @param Resource $resource
  * @param User_list $list
  * @param string[] $tagArray
  * @param string $notes
  * @param bool $updateSolr
  * @return bool
  */
 function addResource($resource, $list, $tagArray, $notes, $updateSolr = true)
 {
     require_once 'User_resource.php';
     require_once 'Tags.php';
     $join = new User_resource();
     $join->user_id = $this->id;
     $join->resource_id = $resource->id;
     $join->list_id = $list->id;
     if ($join->find(true)) {
         if ($notes) {
             $join->notes = $notes;
             $join->update();
         }
         $result = true;
     } else {
         if ($notes) {
             $join->notes = $notes;
         }
         $result = $join->insert();
     }
     if ($result) {
         if (is_array($tagArray) && count($tagArray)) {
             require_once 'Resource_tags.php';
             $join = new Resource_tags();
             $join->resource_id = $resource->id;
             $join->user_id = $this->id;
             $join->list_id = $list->id;
             $join->delete();
             foreach ($tagArray as $value) {
                 $value = trim(strtolower(str_replace('"', '', $value)));
                 $tag = new Tags();
                 $tag->tag = $value;
                 if (!$tag->find(true)) {
                     $tag->insert();
                 }
                 $join->tag_id = $tag->id;
                 $join->insert();
             }
         }
         if ($updateSolr) {
             $list->updateDetailed(true);
         }
         //Make a call to strands to update that the item was added to the list
         global $configArray;
         if (isset($configArray['Strands']['APID'])) {
             if ($resource->source == 'eContent') {
                 $strandsUrl = "http://bizsolutions.strands.com/api2/event/addtofavorites.sbs?apid={$configArray['Strands']['APID']}&item={$resource->record_id}&user={$this->id}";
             } else {
                 $strandsUrl = "http://bizsolutions.strands.com/api2/event/addtofavorites.sbs?apid={$configArray['Strands']['APID']}&item=econtentRecord{$resource->record_id}&user={$this->id}";
             }
             file_get_contents($strandsUrl);
         }
         return true;
     } else {
         return false;
     }
 }