public function saveEvent($runData) { $site = $runData->getTemp("site"); $pl = $runData->getParameterList(); $pageId = $pl->getParameterValue("pageId"); if (!is_numeric($pageId)) { throw new ProcessException(_("Page does not exist.")); } $page = DB_PagePeer::instance()->selectByPrimaryKey($pageId); if (!$page) { throw new ProcessException(_("Page does not exist.")); } // check permissions $category = $page->getCategory(); WDPermissionManager::instance()->hasPagePermission('edit', $runData->getUser(), $category, $page); $data = $pl->getParameterValue("data"); $json = new JSONService(); $listData = $json->decode($data); //it's time to do some checking $listData->label = trim($listData->label); if (!$listData->label) { throw new ProcessException(_('The SimpleTodo module must have an id (e.g. id="list1").')); } $dataArray['label'] = $listData->label; $listData->title = trim($listData->title); if (!$listData->title) { throw new ProcessException(_('Your title field is empty, please correct that.')); } $dataArray['title'] = $listData->title; for ($i = 0; $i < count($listData->data); $i++) { $listData->data[$i]->text = trim($listData->data[$i]->text); $listData->data[$i]->link = trim($listData->data[$i]->link); if (!is_bool($listData->data[$i]->checked)) { throw new ProcessException(_('Something is wrong witch checkbox (it is not a boolean value).')); } if (empty($listData->data[$i]->text)) { throw new ProcessException(_('One of your text fields is empty, please correct that.')); } $dataArray['data'][$i]['text'] = $listData->data[$i]->text; $dataArray['data'][$i]['link'] = $listData->data[$i]->link; $dataArray['data'][$i]['checked'] = $listData->data[$i]->checked; } $c = new Criteria(); $c->add('label', $listData->label); $c->add('site_id', $site->getSiteId()); $list = DB_SimpletodoListPeer::instance()->selectOne($c); if (!$list) { $list = new DB_SimpletodoList(); $list->setSiteId($site->getSiteId()); $list->setLabel($dataArray['label']); } $list->setTitle($dataArray['title']); $itemData = $json->encode($dataArray['data']); $list->setData($itemData); $list->save(); }
public function build($runData) { $user = $runData->getUser(); if (self::$_counter == 0) { // check permissions $page = $runData->getTemp("page"); if ($page) { $category = $page->getCategory(); //s$runData->getTemp("category"); try { WDPermissionManager::instance()->hasPagePermission('create', $user, $category); self::$_canEdit = true; } catch (Exception $e) { } } } $runData->contextAdd('canEdit', self::$_canEdit); $runData->contextAdd('listCounter', self::$_counter); self::$_counter++; $pl = $runData->getParameterList(); $label = $pl->getParameterValue("id"); $label = trim($label); if (!$label) { throw new ProcessException(_('The SimpleTodo module must have an id.')); } if (!in_array($label, self::$_labelArray)) { array_push(self::$_labelArray, $label); } else { throw new ProcessException(_('The id attribute sholud be unique.')); } $runData->contextAdd("label", $label); $site = $runData->getTemp("site"); $c = new Criteria(); $c->add('label', $label); $c->add('site_id', $site->getSiteId()); $list = DB_SimpletodoListPeer::instance()->selectOne($c); if ($list) { $json = new JSONService(); $listData = $json->decode($list->getData()); $runData->contextAdd("title", $list->getTitle()); $runData->contextAdd("data", $listData); } }