Exemplo n.º 1
0
 private function section_func($slug)
 {
     $section = Section::find($slug, 'slug');
     $this->sql = "SELECT r.id";
     foreach ($section->fields() as $field) {
         $type = $field->type();
         $this->sql .= ",\r\n GROUP_CONCAT(IF(d.field = " . intval($field->id) . ", " . $type->datafield . ", NULL)) AS `" . $field->name . "`";
     }
     $this->sql .= "\r\nFROM clout_record r \r\n";
     $this->sql .= "LEFT JOIN clout_data d ON d.record = r.id\r\n";
     $this->sql .= "WHERE r.section = " . intval($section->id);
     return $this;
 }
Exemplo n.º 2
0
 public function __construct()
 {
     if (GRAFT_CONFIG['DBHost'] == '' || GRAFT_CONFIG['DBName'] == '' || GRAFT_CONFIG['DBUser'] == '') {
         die('A database connection is required to run clout.');
     }
     // instance everything so the db gets setup
     // probably need a better way to do this
     // in the future #TODO
     \GraftPHP\Clout\Data::build();
     \GraftPHP\Clout\Field::build();
     \GraftPHP\Clout\FieldType::build();
     \GraftPHP\Clout\Record::build();
     \GraftPHP\Clout\Section::build();
     \GraftPHP\Clout\User::build();
     $this->data['sections'] = Section::all();
 }
Exemplo n.º 3
0
 public function store($section)
 {
     $section = Section::find($section, 'slug');
     $slug = Functions::urlSafe($_POST['f' . $section->slugfield()->id]);
     $unique_slug = false;
     while (!$unique_slug) {
         if ($section->checkslug($slug)) {
             $unique_slug = true;
         } else {
             $slug .= '-';
         }
     }
     $record = new Record();
     $record->section = $section->id;
     $record->slug = $slug;
     $record->save();
     $this->store_data($section, $record);
     Functions::redirect(Settings::cloutURL() . '/sections/' . $section->slug);
 }
Exemplo n.º 4
0
 public function update($section_id)
 {
     $section = Section::find($section_id, 'id');
     $section->name = $_POST['name'];
     $section->slug = Functions::URLSafe($_POST['name']);
     $section->save();
     // delete fields not in the POST data
     foreach ($section->fields() as $field) {
         $del = true;
         if (isset($_POST['field-id'])) {
             for ($f = 1; $f < count($_POST['field-id']); $f++) {
                 if (intval($field->id) == intval($_POST['field-id'][$f])) {
                     $del = false;
                 }
             }
         }
         if ($del) {
             $field->delete();
         }
     }
     // add/update fields in the POST data
     if (count($_POST['field-name']) > 1) {
         for ($f = 0; $f < count($_POST['field-id']); $f++) {
             $field = new Field();
             $field->id = $_POST['field-id'][$f] != '' ? $_POST['field-id'][$f] : null;
             $field->section = $section->id;
             $field->name = $_POST['field-name'][$f];
             $field->type = $_POST['field-type'][$f];
             $field->order = $_POST['field-order'][$f];
             $field->list = $_POST['field-list'][$f];
             $field->slug = $_POST['field-slug'][$f];
             $field->save();
         }
     }
     Functions::redirect(Settings::cloutURL() . '/settings/sections/' . $section->id);
 }