public function __construct(Database $database, Collection $collection, Container $container, User $user) { parent::__construct($database, $container); $this->collection = $collection; $this->input = $container->input; $this->user = $user->getCurrentUser(); //"label"=>"","datatype"=>"","charsize"=>"" , "default"=>"", "index"=>TRUE, "allowempty"=>FALSE $this->definePropertyModel(array("media_published" => array("Published", "datetime", 50), "media_content" => array("Content", "varchar", 1000), "media_title" => array("Title", "mediumtext", 50, NULL), "media_summary" => array("Summary", "mediumtext", 50, NULL), "media_comment_status" => array("Allow Comments", "tinyint", 1, 0), "media_parent" => array("Parent", "smallint", 10, 0), "media_generator" => array("Generator", "mediumtext", 100), "media_template" => array("Template", "mediumtext", 100), "media_provider" => array("Provider", "mediumtext", 100, "budkit"), "media_mentions" => array("Mentions", "varchar", 1000), "media_owner" => array("Owner", "varchar", 1000), "media_verb" => array("Verb", "mediumtext", 20, "post"), "media_geotags" => array("Geotags", "varchar", 1000), "media_object" => array("Object", "varchar", 1000), "media_target" => array("Target", "varchar", 1000), "media_permissions" => array("Permissions", "mediumtext", 50)), "media"); $this->defineValueGroup("media"); $this->setListOrderBy(array("o.object_updated_on"), "DESC"); }
public function update($uri, $format = 'html') { //1. check this uer has permission to execute /page/create $this->checkPermission("execute"); //2. are we patching or updating an existing? $input = $this->application->input; $user = new User($this->application, $this->application->database, $this->application->session); if ($input->methodIs("PATCH")) { //because we are updating; //3. load the page; $page = $this->application->createInstance(Model\Page::class); // $page = $page->defineValueGroup("page"); $page = $page->loadObjectByURI($uri); //4. Is this a valid page? if ($page->getObjectId()) { //if we have a page; //Checks if the current user is the owner of this page or has special permissions to edit pages if ($page->getPropertyValue("media_owner") == $user->getCurrentUser()->getPropertyValue("user_name_id") || $this->checkPermission("special", "/page/edit")) { //we will save the content as HTML $page = $this->bindData($page); //binds input data; $page->setPropertyValue("media_published", Time::stamp()); $page->defineValueGroup("page"); if ($page->saveObject($page->getObjectURI(), $page->getObjectType())) { $this->response->addAlert(t("Your page content has been updated successfully"), "success"); //Redirect to dashboard or to last url? return $this->application->dispatcher->redirect("/page/{$page->getObjectURI()}/edit", HTTP_FOUND, null, $this->response->getAlerts()); } } } } $this->response->addAlert(t("The page content was not updated"), "warning"); //Redirect to dashboard or to last url? return $this->application->dispatcher->redirect("/page/{$page->getObjectURI()}/edit", HTTP_FOUND, null, $this->response->getAlerts()); }