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

Ticket #344 (closed defect: fixed)

Opened 21 months ago

Last modified 21 months ago

aBlogSlot - Slots handling of Deleted Posts

Reported by: johnnyoffline Owned by: boutell
Priority: critical Milestone: 1.4
Component: apostropheBlogPlugin Version: trunk
Keywords: Cc: boutell, jake, dordille, rickybanister, geoffd, agilbert, dordille, johnnyoffline
Symfony version: 1.4

Description

I tried to do this but I couldn't figure it out.

Just make it fail silently then assign this ticket back to me so's I can spruce it up and propagate this across all slots.


<?php
class aBlogSingleSlotComponents extends BaseaSlotComponents
{
  protected $modelClass = 'aBlogPost';
  protected $formClass = 'aBlogSingleSlotForm';
  
  public function executeEditView()
  {
    // Must be at the start of both view components
    $this->setup();
    
    // Careful, don't clobber a form object provided to us with validation errors
    // from an earlier pass
    if (!isset($this->form))
    {
      $this->form = new $this->formClass($this->id, $this->slot->getArrayValue());
    }
  }
  public function executeNormalView()
  {
    $this->setup();
    $this->values = $this->slot->getArrayValue();
    if(isset($this->values['blog_item']))
    {
      $this->aBlogItem = Doctrine::getTable($this->modelClass)->findOneBy('id', $this->values['blog_item']);
      aBlogItemTable::populatePages(array($this->aBlogItem));
    }
    $this->options['word_count'] = $this->getOption('word_count', 100);

    if(!isset($this->options['slideshowOptions']))
		{ // If no slideshow options are set, use the defaults
	    $this->options['slideshowOptions'] = array('width' => 100, 'height' => 100, 'resizeType' => 'c');
		}
		else
		{ // If -some- slideshow options are set, make sure to include defaults where not specified
	    $this->options['slideshowOptions'] = array(
				'width' => ((isset($this->options['slideshowOptions']['width']))? $this->options['slideshowOptions']['width']:100), 
				'height' => ((isset($this->options['slideshowOptions']['height']))? $this->options['slideshowOptions']['height']:100), 
				'resizeType' => ((isset($this->options['slideshowOptions']['resizeType']))? $this->options['slideshowOptions']['resizeType']:'c'), 
			);
		}

    $this->options['excerptLength'] = $this->getOption('excerptLength', 200);
    $this->options['maxImages'] = $this->getOption('maxImages', 1);

		// TODO: Make this work right
		if (!$this->aBlogItem)
		{ // The Blog Post was deleted perhaps ? :D

			// This doesnt work 
			//if ($sf_user->isAuthenticated() && $sf_user->isAdmin()) {
			//	echo "This blog post has been deleted";
			//}

			// This stops the error but isn't what we want
			$this->aBlogItem = new aBlogItem();
		}
		
  }
}

Attachments

Screen shot 2010-05-07 at May 7 - 3.51.21 PM.png Download (71.5 KB) - added by anonymous 21 months ago.

Change History

Changed 21 months ago by anonymous

Changed 21 months ago by boutell

John you are close but the controller layer is not the view layer. Rather than having variables provided to you ($sf_user) you get things from the current object ($this):

$this->getUser()

I think it's fine that you reassigned this to Dan but wanted to nudge you toward being able to do it next time round.

Also, guys, you want to check whether there is a blog post returned before doing this line as well:

aBlogItemTable::populatePages(array($this->aBlogItem));

Changed 21 months ago by dordille

  • owner changed from dordille to boutell
  • status changed from new to assigned

Tom and John, you guys seem to be banging away and the slots today, I am going to add to your fun a bit by reassigning.

Changed 21 months ago by boutell

  • status changed from assigned to closed
  • resolution set to fixed

This was done on Friday. When the blog post has been deleted it renders exactly like a brand new as-yet-unsaved blog post slot does, which is correct. When empty it doesn't impact the logged out view.

Note: See TracTickets for help on using tickets.