コード例 #1
0
ファイル: Fieldgroups.php プロジェクト: nightsh/ProcessWire
 /**
  * Save the Fieldgroup to DB
  *
  * If fields were removed from the Fieldgroup, then track them down and remove them from the associated field_* tables
  *
  * @param Saveable $item Fieldgroup to save
  * @return bool True on success, false on failure
  *
  */
 public function ___save(Saveable $item)
 {
     if ($item->id && $item->removedFields) {
         foreach ($this->fuel('templates') as $template) {
             if ($template->fieldgroup->id !== $item->id) {
                 continue;
             }
             foreach ($item->removedFields as $field) {
                 if ($field->flags & Field::flagGlobal && !$template->noGlobal) {
                     throw new WireException("Field '{$field}' may not be removed from fieldgroup '{$item->name}' because it is globally required (Field::flagGlobal)");
                 }
                 if ($field->flags & Field::flagPermanent) {
                     throw new WireException("Field '{$field}' may not be removed from fieldgroup '{$item->name}' because it is permanent.");
                 }
                 $pages = $this->fuel('pages')->find("templates_id={$template->id}, check_access=0, status<" . Page::statusMax);
                 foreach ($pages as $page) {
                     try {
                         $field->type->deletePageField($page, $field);
                         $page->save($field->name);
                         if ($this->fuel('config')->debug) {
                             $this->message("Deleted '{$field->name}' from '{$page->path}'");
                         }
                     } catch (Exception $e) {
                         $this->error($e->getMessage());
                     }
                 }
                 $item->finishRemove($field);
             }
         }
     }
     $contextData = array();
     if ($item->id) {
         // save context data
         $result = wire('db')->query("SELECT fields_id, data FROM fieldgroups_fields WHERE fieldgroups_id=" . (int) $item->id);
         while ($row = $result->fetch_assoc()) {
             $contextData[$row['fields_id']] = $row['data'];
         }
     }
     $result = parent::___save($item);
     if (count($contextData)) {
         // restore context data
         foreach ($contextData as $fields_id => $data) {
             $data = wire('db')->escape_string($data);
             wire('db')->query("UPDATE fieldgroups_fields SET data='{$data}' WHERE fieldgroups_id={$item->id} AND fields_id={$fields_id}");
         }
     }
     return $result;
 }
コード例 #2
0
ファイル: Fieldgroups.php プロジェクト: avatar382/fablab_site
 /**
  * Save the Fieldgroup to DB
  *
  * If fields were removed from the Fieldgroup, then track them down and remove them from the associated field_* tables
  *
  * @param Saveable $item Fieldgroup to save
  * @return bool True on success, false on failure
  * @throws WireException
  *
  */
 public function ___save(Saveable $item)
 {
     $database = $this->wire('database');
     if ($item->id && $item->removedFields) {
         foreach ($this->wire('templates') as $template) {
             if ($template->fieldgroup->id !== $item->id) {
                 continue;
             }
             foreach ($item->removedFields as $field) {
                 // make sure the field is valid to delete from this template
                 if ($field->flags & Field::flagGlobal && !$template->noGlobal) {
                     throw new WireException("Field '{$field}' may not be removed from fieldgroup '{$item->name}' because it is globally required (Field::flagGlobal)");
                 }
                 if ($field->flags & Field::flagPermanent) {
                     throw new WireException("Field '{$field}' may not be removed from fieldgroup '{$item->name}' because it is permanent.");
                 }
                 $field->type->deleteTemplateField($template, $field);
                 $item->finishRemove($field);
             }
         }
         $item->resetRemovedFields();
     }
     $contextData = array();
     if ($item->id) {
         // save context data
         $query = $database->prepare("SELECT fields_id, data FROM fieldgroups_fields WHERE fieldgroups_id=:item_id");
         $query->bindValue(":item_id", (int) $item->id, PDO::PARAM_INT);
         $query->execute();
         while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
             $contextData[$row['fields_id']] = $row['data'];
         }
         $query->closeCursor();
     }
     $result = parent::___save($item);
     if (count($contextData)) {
         // restore context data
         foreach ($contextData as $fields_id => $data) {
             $fieldgroups_id = (int) $item->id;
             $fields_id = (int) $fields_id;
             $query = $database->prepare("UPDATE fieldgroups_fields SET data=:data WHERE fieldgroups_id=:fieldgroups_id AND fields_id=:fields_id");
             // QA
             $query->bindValue(":data", $data, PDO::PARAM_STR);
             $query->bindValue(":fieldgroups_id", $fieldgroups_id, PDO::PARAM_INT);
             $query->bindValue(":fields_id", $fields_id, PDO::PARAM_INT);
             $query->execute();
         }
     }
     return $result;
 }
コード例 #3
0
ファイル: Fieldgroups.php プロジェクト: nicolasleon/P21
 /**
  * Save the Fieldgroup to DB
  *
  * If fields were removed from the Fieldgroup, then track them down and remove them from the associated field_* tables
  *
  */
 public function ___save(Saveable $item)
 {
     if ($item->removedFields) {
         foreach ($this->fuel('templates') as $template) {
             if ($template->fieldgroup->id !== $item->id) {
                 continue;
             }
             foreach ($item->removedFields as $field) {
                 if ($field->flags & Field::flagGlobal && !$template->noGlobal) {
                     throw new WireException("Field '{$field}' may not be removed from fieldgroup '{$this}' because it is globally required (Field::flagGlobal)");
                 }
                 if ($field->flags & Field::flagPermanent) {
                     throw new WireException("Field '{$field}' may not be removed from fieldgroup '{$this}' because it is permanent.");
                 }
                 $pages = $this->fuel('pages')->find("templates_id={$template->id}, check_access=0, status<" . Page::statusMax);
                 foreach ($pages as $page) {
                     try {
                         $field->type->deletePageField($page, $field);
                         $page->save($field->name);
                         if ($this->fuel('config')->debug) {
                             $this->message("Deleted '{$field->name}' from '{$page->path}'");
                         }
                     } catch (Exception $e) {
                         $this->error($e->getMessage());
                     }
                 }
                 $item->finishRemove($field);
             }
         }
     }
     return parent::___save($item);
 }
コード例 #4
0
ファイル: Fieldgroups.php プロジェクト: gusdecool/bunga-wire
 /**
  * Save the Fieldgroup to DB
  *
  * If fields were removed from the Fieldgroup, then track them down and remove them from the associated field_* tables
  *
  * @param Saveable $item Fieldgroup to save
  * @return bool True on success, false on failure
  * @throws WireException
  *
  */
 public function ___save(Saveable $item)
 {
     $database = $this->wire('database');
     if ($item->id && $item->removedFields) {
         foreach ($this->fuel('templates') as $template) {
             if ($template->fieldgroup->id !== $item->id) {
                 continue;
             }
             foreach ($item->removedFields as $field) {
                 if ($field->flags & Field::flagGlobal && !$template->noGlobal) {
                     throw new WireException("Field '{$field}' may not be removed from fieldgroup '{$item->name}' because it is globally required (Field::flagGlobal)");
                 }
                 if ($field->flags & Field::flagPermanent) {
                     throw new WireException("Field '{$field}' may not be removed from fieldgroup '{$item->name}' because it is permanent.");
                 }
                 $pages = $this->fuel('pages')->find("templates_id={$template->id}, check_access=0, status<" . Page::statusMax);
                 foreach ($pages as $page) {
                     try {
                         $field->type->deletePageField($page, $field);
                         // $page->save($field->name);
                         if ($this->fuel('config')->debug) {
                             $this->message("Deleted '{$field->name}' from '{$page->path}'");
                         }
                     } catch (Exception $e) {
                         $this->error($e->getMessage());
                     }
                 }
                 $item->finishRemove($field);
             }
         }
         $item->resetRemovedFields();
     }
     $contextData = array();
     if ($item->id) {
         // save context data
         $query = $database->prepare("SELECT fields_id, data FROM fieldgroups_fields WHERE fieldgroups_id=:item_id");
         $query->bindValue(":item_id", (int) $item->id, PDO::PARAM_INT);
         $query->execute();
         while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
             $contextData[$row['fields_id']] = $row['data'];
         }
         $query->closeCursor();
     }
     $result = parent::___save($item);
     if (count($contextData)) {
         // restore context data
         foreach ($contextData as $fields_id => $data) {
             $fieldgroups_id = (int) $item->id;
             $fields_id = (int) $fields_id;
             $query = $database->prepare("UPDATE fieldgroups_fields SET data=:data WHERE fieldgroups_id=:fieldgroups_id AND fields_id=:fields_id");
             // QA
             $query->bindValue(":data", $data, PDO::PARAM_STR);
             $query->bindValue(":fieldgroups_id", $fieldgroups_id, PDO::PARAM_INT);
             $query->bindValue(":fields_id", $fields_id, PDO::PARAM_INT);
             $query->execute();
         }
     }
     return $result;
 }