public function add() { if (Page::already($_POST['baseUrl'], $_POST['uri'], $_POST['language'])) { throw new Exception('PAGE ALREADY EXISTS', 409); } $page = new Page(); $page->setBaseUrl($_POST['baseUrl']); $page->setUri($_POST['uri']); $page->setLanguage($_POST['language']); if (array_key_exists('content', $_POST) && !empty($_POST['content'])) { $page->setContent($_POST['content']); } $page->setModele($_POST['modele']); $page->setTitle($_POST['title']); if (array_key_exists('languageParentId', $_POST)) { $page->setLanguageParentId($_POST['languageParentId']); } if (array_key_exists('ajax', $_POST)) { $page->setAjax($_POST['ajax']); } if (array_key_exists('published', $_POST)) { $page->setPublished($_POST['published']); } if (array_key_exists('metas', $_POST)) { $page->setMetas($_POST['metas']); } if (array_key_exists('css', $_POST)) { $page->setCss($_POST['css']); } if (array_key_exists('js', $_POST)) { $page->setJs($_POST['js']); } if (array_key_exists('action', $_POST)) { $page->setAction($_POST['action']); } if (array_key_exists('method', $_POST)) { $page->setMethod($_POST['method']); } if (array_key_exists('priority', $_POST)) { $page->setPriority($_POST['priority']); } if (array_key_exists('datas', $_POST)) { $page->setDatas($_POST['datas']); } if (!array_key_exists('blockIds', $_POST)) { $blkIds = array(); foreach ($_POST['blockIds'] as $blk) { if (array_key_exists('id', $blk) && MongoId::isValid($blk['id'])) { $blkIds[] = $blk['id']; } } $this->page->setBlockIds($blkIds); } $page->save(); return array('pageId' => $page->getId()); }
function convertToPage(&$logged_user, &$error) { db_begin_work(); $page = new Page(); $page->setProjectId($this->getProjectId()); $page->setName($this->getName()); $body = $this->getBody(); if (empty($body)) { $body = 'page Content missing'; } $page->setBody($body); $page->setState($this->getState()); $page->setVisibility($this->getVisibility()); $page->setPriority($this->getPriority()); $page->setCommentsCount($this->getCommentsCount()); $page->setIsLocked($this->getIsLocked()); $page->setCreatedById($logged_user->getId()); $page->setCreatedByName($logged_user->getName()); $page->setCreatedByEmail($logged_user->getEmail()); $save = $page->save(); if ($save && !is_error($save)) { db_commit(); $page->ready(); $link = mysql_connect(DB_HOST, DB_USER, DB_PASS); mysql_select_db(DB_NAME); $query = "update healingcrystals_project_objects set parent_id='" . $page->getId() . "', parent_type='Page' where parent_id='" . $this->getId() . "' and project_id='" . $this->getProjectId() . "' and type in ('Comment', 'Task')"; mysql_query($query); $query = "update healingcrystals_project_objects set parent_id=null, parent_type=null where parent_id='" . $this->getId() . "' and project_id='" . $this->getProjectId() . "' and type not in ('Comment', 'Task')"; mysql_query($query); $query = "select * from healingcrystals_assignments where object_id='" . $this->getId() . "'"; $result = mysql_query($query); while ($entry = mysql_fetch_assoc($result)) { $query = "insert into healingcrystals_assignments (user_id, object_id, is_owner) values ('" . $entry['user_id'] . "', '" . $page->getId() . "', '" . $entry['is_owner'] . "')"; mysql_query($query); } $query = "select * from healingcrystals_project_object_categories where object_id='" . $this->getId() . "'"; $result = mysql_query($query); while ($entry = mysql_fetch_assoc($result)) { $query = "insert ignore into healingcrystals_project_object_categories (object_id, category_id) values ('" . $page->getId() . "', '" . $entry['category_id'] . "')"; mysql_query($query); } mysql_close($link); $this->moveToTrash(); return $page->getId(); } else { db_rollback(); $error = $save; return ''; } }