/**
  * Associate the list of provided media with this display group
  * @param user $user           The logged in user
  * @param int $displayGroupId The Display Group to Assign to
  * @param array $mediaList      The Media to Assign
  */
 public function AssociateFiles($user, $displayGroupId, $mediaList)
 {
     Debug::LogEntry('audit', 'IN', get_class(), __FUNCTION__);
     Kit::ClassLoader('lkmediadisplaygroup');
     $link = new LkMediaDisplayGroup($this->db);
     try {
         $dbh = PDOConnect::init();
         // Check that some media assignments have been made
         if (count($mediaList) == 0) {
             $this->ThrowError(25006, __('No media to assign'));
         }
         // Drop all current assignments
         if (!$link->UnlinkAllFromDisplayGroup($displayGroupId)) {
             $this->ThrowError(__('Unable to make this assignment during preparation.'));
         }
         // Loop through all the media
         foreach ($mediaList as $mediaId) {
             $mediaId = Kit::ValidateParam($mediaId, _INT);
             // Check we have permissions to use this media (we will use this to copy the media later)
             $mediaAuth = $user->MediaAuth($mediaId, true);
             if (!$mediaAuth->view) {
                 $this->ThrowError(__('You have selected media that you no longer have permission to use. Please reload the form.'));
             }
             // Create the link
             if (!$link->Link($displayGroupId, $mediaId)) {
                 $this->ThrowError(__('Unable to make this assignment'));
             }
         }
         // Flag this display group as incomplete
         $this->FlagIncomplete($displayGroupId);
         return true;
     } catch (Exception $e) {
         Debug::LogEntry('error', $e->getMessage(), get_class(), __FUNCTION__);
         if (!$this->IsError()) {
             $this->SetError(1, __('Unknown Error'));
         }
         return false;
     }
 }
示例#2
0
 public function Delete($mediaId, $newRevisionMediaId = NULL)
 {
     Debug::LogEntry('audit', 'IN', 'Media', 'Delete');
     try {
         $dbh = PDOConnect::init();
         // Check for links
         $sth = $dbh->prepare('SELECT * FROM lklayoutmedia WHERE MediaID = :mediaid');
         $sth->execute(array('mediaid' => $mediaId));
         if ($sth->fetch()) {
             $this->ThrowError(21, __('This media is in use, please retire it instead.'));
         }
         // Get the file name
         $sth = $dbh->prepare('SELECT StoredAs FROM media WHERE mediaID = :mediaid');
         $sth->execute(array('mediaid' => $mediaId));
         if (!($row = $sth->fetch())) {
             $this->ThrowError(22, __('Cannot locate the files for this media. Unable to delete.'));
         }
         // This will be used to delete the actual file (stored on disk)
         $fileName = Kit::ValidateParam($row['StoredAs'], _STRING);
         // Remove permission assignments
         $security = new MediaGroupSecurity($this->db);
         if (!$security->UnlinkAll($mediaId)) {
             throw new Exception("Error Processing Request", 1);
         }
         // Delete any assignments
         $link = new LkMediaDisplayGroup($this->db);
         if (!$link->UnlinkAllFromDisplayGroup($mediaId)) {
             $this->ThrowError(__('Unable to drop file assignments during display delete.'));
         }
         // Delete the media
         $sth = $dbh->prepare('DELETE FROM media WHERE MediaID = :mediaid');
         $sth->execute(array('mediaid' => $mediaId));
         // Delete the file itself (and any thumbs, etc)
         if (!$this->DeleteMediaFile($fileName)) {
             throw new Exception("Error Processing Request", 1);
         }
         // Bring back the previous revision of this media (if there is one)
         $sth = $dbh->prepare('SELECT IFNULL(MediaID, 0) AS MediaID FROM media WHERE EditedMediaID = :mediaid');
         $sth->execute(array('mediaid' => $mediaId));
         if ($editedMediaRow = $sth->fetch()) {
             // Unretire this edited record
             $editedMediaId = Kit::ValidateParam($editedMediaRow['MediaID'], _INT);
             if ($newRevisionMediaId == null) {
                 // Bring back the old one
                 $sth = $dbh->prepare('UPDATE media SET IsEdited = 0, EditedMediaID = NULL WHERE mediaid = :mediaid');
                 $sth->execute(array('mediaid' => $editedMediaId));
             } else {
                 // Link up the old one
                 $sth = $dbh->prepare('UPDATE media SET EditedMediaID = :newRevisionMediaId WHERE mediaid = :mediaid');
                 $sth->execute(array('mediaid' => $editedMediaId, 'newRevisionMediaId' => $newRevisionMediaId));
             }
         }
         return true;
     } catch (Exception $e) {
         Debug::LogEntry('error', $e->getMessage());
         if (!$this->IsError()) {
             $this->SetError(23, __('Error deleting media.'));
         }
         return false;
     }
 }
示例#3
0
 public function VersionInstructions()
 {
     $response = new ResponseManager();
     Kit::ClassLoader('media');
     Kit::ClassLoader('display');
     Kit::ClassLoader('lkmediadisplaygroup');
     $displayGroupId = Kit::GetParam('displaygroupid', _POST, _INT);
     $mediaId = Kit::GetParam('mediaid', _POST, _INT);
     // Make sure we have permission to do this to this display
     $auth = $this->user->DisplayGroupAuth($displayGroupId, true);
     if (!$auth->edit) {
         trigger_error(__('You do not have permission to edit this display group'), E_USER_ERROR);
     }
     // Make sure we have permission to use this file
     $mediaAuth = $this->user->MediaAuth($mediaId, true);
     if (!$mediaAuth->view) {
         trigger_error(__('You have selected media that you no longer have permission to use. Please reload the form.'), E_USER_ERROR);
     }
     // Make sure this file is assigned to this display group
     $link = new LkMediaDisplayGroup($this->db);
     if (!$link->Link($displayGroupId, $mediaId)) {
         trigger_error($display->GetErrorMessage(), E_USER_ERROR);
     }
     // Get the "StoredAs" for this media item
     $media = new Media($this->db);
     $storedAs = $media->GetStoredAs($mediaId);
     // Get a list of displays for this group
     $displays = $this->user->DisplayList(array('displayid'), array('displaygroupid' => $displayGroupId));
     foreach ($displays as $display) {
         // Update the Display with the new instructions
         $displayObject = new Display($this->db);
         if (!$displayObject->SetVersionInstructions($display['displayid'], $mediaId, $storedAs)) {
             trigger_error($displayObject->GetErrorMessage(), E_USER_ERROR);
         }
     }
     $response->SetFormSubmitResponse(__('Version Instructions Set'));
     $response->Respond();
 }