コード例 #1
0
 /**
  * Process a form submission
  *
  * @param  array $fields
  * @return void
  */
 public function process(array $fields)
 {
     if (isset($fields['rm_submissions'])) {
         foreach ($fields['rm_submissions'] as $id) {
             $fv = \Phire\Fields\Table\FieldValues::findBy(['model_id' => $id]);
             foreach ($fv->rows() as $value) {
                 $field = \Phire\Fields\Table\Fields::findById($value->field_id);
                 if (isset($field->id) && $field->type == 'file') {
                     $file = json_decode($value->value);
                     if (file_exists($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/files/' . $file)) {
                         unlink($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/files/' . $file);
                     }
                 }
             }
             $fv = new \Phire\Fields\Table\FieldValues();
             $fv->delete(['model_id' => $id]);
             $form = Table\FormSubmissions::findById((int) $id);
             if (isset($form->id)) {
                 $form->delete();
             }
         }
     }
 }
コード例 #2
0
ファイル: Template.php プロジェクト: phirecms/phire-templates
 /**
  * Copy template
  *
  * @param  \Pop\Module\Manager $modules
  * @return void
  */
 public function copy(\Pop\Module\Manager $modules)
 {
     $oldId = (int) $this->data['id'];
     $template = Table\Templates::findById($oldId);
     if (isset($template->id)) {
         $i = 1;
         $name = $template->name . ' (Copy ' . $i . ')';
         $dupeTemplate = Table\Templates::findBy(['name' => $name]);
         while (isset($dupeTemplate->id)) {
             $i++;
             $name = $template->name . ' (Copy ' . $i . ')';
             $dupeTemplate = Table\Templates::findBy(['name' => $name]);
         }
         $newTemplate = new Table\Templates(['parent_id' => $template->parent_id, 'name' => $name, 'device' => null !== $template->parent_id ? null : 'desktop', 'template' => $template->template, 'history' => $template->history]);
         $newTemplate->save();
         if ($modules->isRegistered('phire-fields')) {
             $fv = \Phire\Fields\Table\FieldValues::findBy(['model_id' => $oldId]);
             if ($fv->count() > 0) {
                 foreach ($fv->rows() as $value) {
                     $v = new \Phire\Fields\Table\FieldValues(['field_id' => $value->field_id, 'model_id' => $newTemplate->id, 'model' => 'Phire\\Templates\\Model\\Template', 'value' => $value->value, 'timestamp' => time(), 'history' => $value->history]);
                     $v->save();
                 }
             }
         }
         $this->data = array_replace($this->data, $newTemplate->getColumns());
     }
 }
コード例 #3
0
ファイル: Content.php プロジェクト: phirecms/phire-content
 /**
  * Copy content
  *
  * @param  int $userId
  * @return void
  */
 public function copy($userId)
 {
     $oldId = (int) $this->data['id'];
     $content = Table\Content::findById($oldId);
     if (isset($content->id)) {
         $i = 1;
         $title = $content->title . ' (Copy ' . $i . ')';
         $uri = $content->uri . '-' . $i;
         $slug = $content->slug . '-' . $i;
         $dupeContent = Table\Content::findBy(['uri' => $uri]);
         while (isset($dupeContent->id)) {
             $i++;
             $title = $content->title . ' (Copy ' . $i . ')';
             $uri = $content->uri . '-' . $i;
             $slug = $content->slug . '-' . $i;
             $dupeContent = Table\Content::findBy(['uri' => $uri]);
         }
         $newContent = new Table\Content(['type_id' => $content->type_id, 'parent_id' => $content->parent_id, 'title' => $title, 'uri' => $uri, 'slug' => $slug, 'publish' => date('Y-m-d H:i:s'), 'expire' => null, 'status' => -1, 'template' => $content->template, 'roles' => $content->roles, 'order' => $content->order, 'force_ssl' => $content->force_ssl, 'created' => date('Y-m-d H:i:s'), 'created_by' => $userId]);
         $newContent->save();
         if (class_exists('Phire\\Fields\\Table\\FieldValues')) {
             $fv = \Phire\Fields\Table\FieldValues::findBy(['model_id' => $oldId]);
             if ($fv->count() > 0) {
                 foreach ($fv->rows() as $value) {
                     $v = new \Phire\Fields\Table\FieldValues(['field_id' => $value->field_id, 'model_id' => $newContent->id, 'model' => 'Phire\\Content\\Model\\Content', 'value' => $value->value, 'timestamp' => time(), 'history' => $value->history]);
                     $v->save();
                 }
             }
         }
         $this->data = array_replace($this->data, $newContent->getColumns());
     }
 }