/**
  * @return Entry|null the parent entry of null if none
  */
 public function getParent()
 {
     if ($this->parent == null && $this->parent_id) {
         $this->parent = Entry::find_one($this->parent_id);
     }
     return $this->parent;
 }
 /**
  * override this to setup anything that needs to be done before
  * @param $action string the action the user is trying to complete
  */
 public function processRequest($action = null)
 {
     $id = isset($_GET["id"]) ? $_GET["id"] : false;
     if (!$id) {
         header("Location: admin.php?page=collapsing_content&task=view_entries");
     }
     $entry = Entry::find_one($id);
     $entry->delete();
     if ($entry->getParent()) {
         header("Location: admin.php?page=collapsing_content&task=edit_entry&id=" . $entry->getParent()->id);
     } else {
         header("Location: admin.php?page=collapsing_content&task=view_entries");
     }
 }
 /**
  * @param  $atts array inputs
  * @return string shortcode content
  */
 public function handleShortcode($atts)
 {
     if (!isset($atts["id"])) {
         $entries = Entry::fetchAll();
     } else {
         $entries = [Entry::find_one($atts["id"])];
     }
     $collections = $this->buildCollections($entries);
     $exportedHTML = '';
     foreach ($collections as $collection) {
         $exportedHTML .= $collection->export();
     }
     return $exportedHTML;
 }
 /**
  * By default this will attempt to edit this post
  */
 protected function handlePost()
 {
     if (!$this->entry) {
         $this->entry = Entry::create([]);
     }
     if (isset($_POST["title"])) {
         $this->entry->title = $_POST["title"];
     }
     if (isset($_POST["subtitle"])) {
         $this->entry->subtitle = $_POST["subtitle"];
     }
     if (isset($_POST["above_entries"])) {
         $this->entry->top_content = $_POST["above_entries"];
     }
     if (isset($_POST["below_entries"])) {
         $this->entry->bottom_content = $_POST["below_entries"];
     }
     if (isset($_POST["template"])) {
         $this->entry->setTemplate($_POST["template"]);
     }
     if (isset($_POST["parent"]) && $_POST["parent"] != "") {
         $this->entry->parent_id = $_POST["parent"];
     }
     if (isset($_POST["using_post"])) {
         $this->entry->using_post = $_POST["using_post"] == "on";
     } else {
         $this->entry->using_post = false;
     }
     if (isset($_POST["post_id"])) {
         $this->entry->post_id = $_POST["post_id"];
     }
     $this->entry->save();
     if ($this->entry->getParent()) {
         header("Location: admin.php?page=collapsing_content&task=edit_entry&id=" . $this->entry->getParent()->id);
     } else {
         header("Location: admin.php?page=collapsing_content&task=view_entries");
     }
 }
 /**
  * override this to setup anything that needs to be done before
  * @param $action null|string the action that is being processed
  */
 public function processRequest($action = null)
 {
     $this->topLevelEntries = Entry::fetchAllParents();
 }
 /**
  * See: http://plugin.michael-simpson.com/?page_id=101
  * Called by install() to create any database tables if needed.
  * Best Practice:
  * (1) Prefix all table names with $wpdb->prefix
  * (2) make table names lower case only
  * @return void
  */
 protected function installDatabaseTables()
 {
     Entry::install_table();
 }