* @license PHP License * @package WB * @subpackage content */ /** * Load required class */ WBClass::load('WBContent'); /** * Content component: Login * * @version 0.3.0 * @package WB * @subpackage content */ class WBContent_BlogEditor extends WBContent { /** * my parameter list * @var array */ protected $config = array( 'process' => 'list', 'requiredgroup' => 'blogeditor' ); /** * table * @var WBDatasource_Table */ protected $table; /** * id of current news article * @var string */ protected $id = '__new'; /** * run * * run component * * @return array parameter list */ public function run() { if (!$this->isUserInGroup($this->config['requiredgroup'])) { $this->loadTemplates('anon'); return $this->config; } $this->table = WBClass::create( 'WBDatasource_Table' ); $p = null; $this->config['process'] = strtolower($this->config['process']); // administrators may delete other's blog entries but not edit them $foreign = $this->user->getId(); if ($this->config['process'] == 'rm' && $this->isUserInGroup('admin')) { $foreign = null; } // load article $p = array(array()); $this->id = $this->req->get('id', '__new'); if($this->id != '__new') { $p = $this->table->get('blog', $this->id, $foreign); } if (count($p) != 1) { $p = array(array()); $this->id = '__new'; } $p = $p[0]; $this->tmpl->addGlobalVar('id', $this->id); switch ($this->config['process']) { case 'add': $this->id = '__new'; break; case 'rm': case 'edit': default: $this->tmpl->addGlobalVars($p); // delete? if ($this->config['process'] == 'rm' && $this->id != '__new') { if ($this->req->get('force', 'no') != 'yes') { $this->loadTemplates('rm'); return $this->config; break; } $this->table->delete('blog', $this->id, $foreign); $this->loadTemplates('rmDeleted'); return $this->config; } break; } $this->processForm('edit', $p); return $this->config; } /** * receive output * * fetch output of this content component * * @return string */ public function getString() { return $this->tmpl->getParsedTemplate( 'snippet' ); } /** * Save user's primary data * * Update user's forename and surname * * @param patForms $form * @param array $values */ public function onEditValid( $form, $values ) { $values['uid'] = $this->user->getId(); $this->table->save( 'blog', $this->id, $values ); return true; } /** * location of form config * * Return sub directory where form element definitions are located * * @return string folder */ protected function getFormConfigDir() { return 'blog'; } /** * Add form rules to just created form * * * * @param patForms $form object * @param string name of the xml- and template-filename * @param array $elements list of elements current form * @return bool true on success */ protected function insertFormRules( &$form, $name, $elements ) { return true; } } ?>