class Step extends MyObject
{
public $Widget = null;
public function __construct($data = null)
{
parent::__construct($data, 'steps');
$this->fullTextFields[] = 'title';
$this->fullTextFields[] = 'instructions';
}
public function getPagesXml()
{
$xml = parent::getPagesXml();
$xml .= <<
XML;
return $xml;
}
public function getEditPageParamXml()
{
$xml = parent::getEditPageParamXml();
$xml .= "";
return $xml;
}
public function initEditPage()
{
parent::initEditPage();
//no id? set our widget
if (!$this->id)
{
if ($this->params('widget_id'))
$this->Widget = new Widget($this->params('widget_id'));
else
throw new PageError('You must supply a widget id when adding a new step.');
}
if (!$this->Widget->canEdit())
throw new PageError('You cannot add/edit a step on a widget you don\'t control');
}
public function initEditImagesPage()
{
parent::initEditPage();
$this->pageTitle = "'" . $this->getName() . "' Images";
}
public function drawEditImagesPage()
{
$links[] = $this->Widget->getLink(".editsteps?id={$this->Widget->id}", "Back to Edit Steps");
$links[] = $this->getLink(".edit?id=$this->id", "Edit Step");
$links[] = $this->getLink(".view?id=$this->id", "View Step");
$this->drawPageNavigation($links);
?>
Interface Help
- Drag image from library to add it to the step.
- Click and drag small images to (re)order.
- The first image is the main image for the step.
- Click small image to view large detail.
- Click and drag on the large image to add annotations to the image.
$this->drawStepImages();
}
public function editFormAddFields($form)
{
$form->add('HiddenField', 'widget_id', array(
'value' => $this->Widget->id
));
$form->add('TextField', 'title', array(
'required' => true,
'width' => '95%'
));
$form->add('TextAreaField', 'instructions', array(
'required' => true,
'width' => '95%',
'height' => '400px'
));
$form->add('LabelField', 'images', array(
'title' => '',
'text' => 'You will be able to add images in the next step.'
));
if ($this->id)
$form->addSubmit('Save Step');
else
$form->addSubmit('Add Step');
}
public function save()
{
//no id? update our order
if (!$this->id)
{
$ar = dbFetchAssoc(dbQuery("
SELECT max(step_order) AS max_order
FROM steps
WHERE widget_id = '$this->widget_id'
"));
$this->step_order = (int)$ar['max_order'] + 1;
}
parent::save();
}
public function lookupData($deep = true)
{
parent::lookupData($deep);
if ($deep)
{
$this->Widget = new Widget();
$this->Widget->load($this->widget_id, false);
}
}
public function getName($link = false)
{
return parent::getName($link, $this->title);
}
public function editPagePostSuccess()
{
Util::redirect($this->getUrl("widget.editsteps?id=$this->widget_id"));
}
public function deletePost()
{
parent::deletePost($this->getUrl("widget.editsteps?id=$this->widget_id"));
}
public function drawRow()
{
echo "" . $this->getName(true) . "
";
}
public function drawViewPage()
{
if ($this->canEdit())
{
$links[] = $this->getLink(".edit?id=$this->id", "Edit Step");
$links[] = $this->getLink(".delete?id=$this->id", "Delete Step");
}
if (count($links))
$this->drawPageNavigation($links);
echo "Draw all our steps up here...
";
echo "" . Linkify::bbcode($this->instructions) . "
";
$this->drawStepImages();
}
public function getCreateFieldsArray()
{
$data = parent::getCreateFieldsArray();
$data['widget_id'] = 'widget_id int(11) default 0 not null';
$data['title'] = "title varchar(255) default '' not null";
$data['instructions'] = "instructions text default '' not null";
$data['step_order'] = 'step_order int(11) default 0 not null';
return $data;
}
public function getCreateIndexesArray()
{
$data = parent::getCreateIndexesArray();
$data['widget_id'] = 'key(widget_id)';
return $data;
}
public function drawStepImages()
{
$img = new Gallery();
$rs = $img->search(array(
'step_id' => $this->id
));
?>
foreach ($rs AS $ob)
echo "\t- id\">" . $ob->getImage('thumb', false, false) . "
\n";
?>
\n";
}
}
?>