Airship\Cabin\Bridge\Blueprint\CustomPages::createDir PHP Méthode

createDir() public méthode

Create a new page (and initial page version)
public createDir ( string $cabin, string $path, array $post = [] ) : boolean
$cabin string
$path string
$post array
Résultat boolean
    public function createDir(string $cabin, string $path, array $post = []) : bool
    {
        if (empty($post['url'])) {
            return false;
        }
        $this->db->beginTransaction();
        // Get the ID for the parent directory
        if (!empty($path)) {
            $directory_id = $this->getParentDirFromStr($path, $cabin);
            $count = $this->db->cell('SELECT count(*) FROM airship_custom_dir WHERE cabin = ? AND parent = ? AND url = ?', $cabin, $directory_id, $post['url']);
        } else {
            $directory_id = null;
            $count = $this->db->cell('SELECT count(*) FROM airship_custom_dir WHERE cabin = ? AND parent IS NULL AND url = ?', $cabin, $post['url']);
        }
        if ($count > 0) {
            // already exists
            return false;
        }
        $this->db->insert('airship_custom_dir', ['cabin' => $cabin, 'parent' => $directory_id, 'url' => $post['url'], 'active' => true]);
        return $this->db->commit();
    }

Usage Example

Exemple #1
0
 /**
  * @param string $cabin
  * @param string $parent
  * @param array $post
  * @return bool
  */
 protected function processNewDir(string $cabin, string $parent, array $post = []) : bool
 {
     if (!\Airship\all_keys_exist(['url', 'save_btn'], $post)) {
         return false;
     }
     if ($this->pg->createDir($cabin, $parent, $post)) {
         \Airship\redirect($this->airship_cabin_prefix . '/pages/' . $cabin, ['dir' => $parent]);
     }
     return true;
 }