To participate you must create an account on apostrophenow.org. If you have already done so, click Login.

Changeset 4484

Show
Ignore:
Timestamp:
01/20/12 10:41:35 (4 months ago)
Author:
tboutell
Message:

* BaseaSlideshowSlotActions?: Factored out the slideshow slot code that relinks the related media items into a separate method so it can be easily called from overrides
* BaseaActions?: New 'quiet' option to editSave saves a new version of the slot but doesn't try to render anything
* BaseaActions?: New 'refresh' option to editSave (which defaults to true) can be explicitly shut off to avoid refreshing the whole page object if you don't need the overhead right now

Location:
plugins/apostrophePlugin/branches/1.5/lib/action
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • plugins/apostrophePlugin/branches/1.5/lib/action/BaseaSlideshowSlotActions.class.php

    r4399 r4484  
    2626    { 
    2727      $ids = preg_split('/,/', $request->getParameter('aMediaIds')); 
    28       $q = Doctrine::getTable('aMediaItem')->createQuery('m')->select('m.*')->whereIn('m.id', $ids)->andWhere('m.type = "image"'); 
    29       // Let the query preserve order for us 
    30       $items = aDoctrine::orderByList($q, $ids)->execute(); 
    31       $this->slot->unlink('MediaItems'); 
    32       $links = aArray::getIds($items); 
    33       $this->slot->link('MediaItems', $links); 
     28      $this->relinkMediaItems($ids); 
    3429 
    3530      // This isn't a normal form submission, but the act of selecting items for a 
     
    4742    } 
    4843  } 
     44 
     45  /** 
     46   * Drop any existing links to media items and re-link to any valid media item ids 
     47   * mentioned in $ids. Doctrine is not very good at this, but this solution is 
     48   * battle-tested 
     49   */ 
     50  protected function relinkMediaItems($ids) 
     51  { 
     52    $q = Doctrine::getTable('aMediaItem')->createQuery('m')->select('m.*')->whereIn('m.id', $ids)->andWhere('m.type = "image"'); 
     53    // Let the query preserve order for us 
     54    $items = aDoctrine::orderByList($q, $ids)->execute(); 
     55    $this->slot->unlink('MediaItems'); 
     56    $links = aArray::getIds($items); 
     57    $this->slot->link('MediaItems', $links); 
     58  } 
    4959   
    5060  protected function afterSetMediaIds() 
  • plugins/apostrophePlugin/branches/1.5/lib/action/BaseaSlotActions.class.php

    r4378 r4484  
    107107 
    108108  /** 
    109    * DOCUMENT ME 
    110    * @return mixed 
    111    */ 
    112   protected function editSave() 
    113   { 
     109   * Save a new version of the area with the updated or created slot in question, refreshing the page 
     110   * so that it will render properly. If the request parameter 'noajax' is present, redirect to the 
     111   * page, otherwise call editAjax to trigger an ajax refresh of the slot.  
     112   * 
     113   * If $options['quiet'] is specified and true, don't try to redirect or refresh the slot, just do the  
     114   * backend storage of the new version of the slot. If $options['refresh'] is specified and false, 
     115   * don't refresh the page and its slots 
     116   * 
     117   * @return mixed 
     118   */ 
     119  protected function editSave($options) 
     120  { 
     121    $quiet = isset($options['quiet']) && $options['quiet']; 
     122    $refresh = (!isset($options['refresh'])) || $options['refresh']; 
     123     
    114124    // A simple hook to let other code know when slot editing has taken place and  
    115125    // a new slot is about to be saved. Since objects are passed by reference it's 
     
    125135    // Refetch the page to reflect these changes before we 
    126136    // rerender the slot 
    127     aTools::setCurrentPage( 
    128       aPageTable::retrieveByIdWithSlots($this->page->id)); 
    129     if ($this->getRequestParameter('noajax')) 
    130     { 
    131       return $this->redirectToPage(); 
    132     } 
    133     else 
    134     { 
    135       return $this->editAjax(false); 
     137    if ($refresh) 
     138    { 
     139      aTools::setCurrentPage( 
     140        aPageTable::retrieveByIdWithSlots($this->page->id)); 
     141    } 
     142    if (!$quiet) 
     143    { 
     144      if ($this->getRequestParameter('noajax')) 
     145      { 
     146        return $this->redirectToPage(); 
     147      } 
     148      else 
     149      { 
     150        return $this->editAjax(false); 
     151      } 
    136152    } 
    137153  }