Example #1
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function postCreate(ObjectTypeRequest $request)
 {
     $objecttype = new Object();
     $objecttype->author_id = Auth::user()->id;
     $objecttype->type = 'object_type';
     $objecttype->name = "_object_type_" . str_replace(' ', '-', $request->title);
     $objecttype->title = "Object Type: {$request->title}";
     $objecttype->status = 'published';
     $objecttype->guid = Hash::getUniqueId();
     $objecttype->save();
     return redirect('admin/object-types')->with('message', 'Type saved successfully');
 }
Example #2
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function getEdit($id)
 {
     $data = Object::get();
     $object = Object::find($id);
     if ($typeName = $object->type) {
         if ($type = Object::getType($typeName)->first()) {
             $fieldsRows = Object::getFields($type->id)->get();
             $fields = array();
             $fieldControls = array();
             // Promoted
             $field = array();
             $field['id'] = '_field_promoted';
             $field['name'] = 'promoted';
             $field['label'] = 'Promoted';
             $field['type'] = 'boolean';
             $field['instructions'] = '';
             $field['required'] = 0;
             $values = $this->getFieldValues($id, $field);
             foreach ($values as $key => $value) {
                 if ($values[$key] == '1') {
                     $values[$key] = 'on';
                 }
             }
             $fieldControls[] = view('admin.partials.form.boolean', compact('field', 'values'));
             // Occupation
             $field = array();
             $field['id'] = '_field_occupation';
             $field['name'] = 'occupation';
             $field['label'] = 'Occupation';
             $field['type'] = 'text';
             $field['instructions'] = '';
             $field['required'] = 0;
             $values = $this->getFieldValues($id, $field);
             $fieldControls[] = view('admin.partials.form.text', compact('field', 'values'));
             // Address
             $uniqueId = Hash::getUniqueId();
             $field = array();
             $field['id'] = '_field_address';
             $field['name'] = 'address';
             $field['label'] = 'Address';
             $field['type'] = 'map';
             $field['instructions'] = '';
             $field['required'] = 0;
             $values = $this->getFieldValues($id, $field);
             $fieldControls[] = view('admin.partials.form.map', compact('field', 'values', 'uniqueId'));
             // French
             $field = array();
             $field['id'] = '_field_french_speakers';
             $field['name'] = 'french_speakers';
             $field['label'] = 'French Speakers';
             $field['type'] = 'boolean';
             $field['instructions'] = '';
             $field['required'] = 0;
             $values = $this->getFieldValues($id, $field);
             $fieldControls[] = view('admin.partials.form.boolean', compact('field', 'values'));
             // Address
             $field = array();
             $field['id'] = '_field_phone';
             $field['name'] = 'phone';
             $field['label'] = 'Phone';
             $field['type'] = 'tel';
             $field['instructions'] = '';
             $field['required'] = 0;
             $values = $this->getFieldValues($id, $field);
             $fieldControls[] = view('admin.partials.form.tel', compact('field', 'values'));
             // Email
             $field = array();
             $field['id'] = '_field_email';
             $field['name'] = 'email';
             $field['label'] = 'Email';
             $field['type'] = 'email';
             $field['instructions'] = '';
             $field['required'] = 0;
             $values = $this->getFieldValues($id, $field);
             $fieldControls[] = view('admin.partials.form.email', compact('field', 'values'));
             foreach ($fieldsRows as $fieldRow) {
                 $field = unserialize($fieldRow['meta_value']);
                 $fields[] = $field;
                 //$field['value'] = $object->getValue($field['id']);
                 $values = array();
                 $valuesMeta = ObjectMeta::where('object_id', $id)->where('meta_key', 'LIKE', $field['id'] . '%')->get();
                 foreach ($valuesMeta as $valueMeta) {
                     $valueMetaKey = str_replace($field['id'], '', $valueMeta['meta_key']);
                     if (substr($valueMetaKey, 0, 1) == '-') {
                         $valueMetaKey = substr($valueMetaKey, 1);
                     }
                     $value = $valueMeta['meta_value'];
                     if ($value == '1') {
                         $value = 'on';
                     }
                     if ($valueMetaKey) {
                         $values[$valueMetaKey] = $value;
                     } else {
                         $values[] = $value;
                     }
                 }
                 $uniqueId = Hash::getUniqueId();
                 switch ($field['type']) {
                     case 'text':
                         $fieldControls[] = view('admin.partials.form.text', compact('field', 'values', 'uniqueId'));
                         break;
                     case 'wysiwyg':
                         $fieldControls[] = view('admin.partials.form.wysiwyg', compact('field', 'values', 'uniqueId'));
                         break;
                     case 'map':
                         $fieldControls[] = view('admin.partials.form.map', compact('field', 'values', 'uniqueId'));
                         break;
                     case 'tel':
                         $fieldControls[] = view('admin.partials.form.tel', compact('field', 'values', 'uniqueId'));
                         break;
                     case 'boolean':
                         $fieldControls[] = view('admin.partials.form.boolean', compact('field', 'values', 'uniqueId'));
                         break;
                 }
             }
         }
     }
     if (isset($object)) {
         if ($imageObjectId = $object->getValue('_featured_image')) {
             $featuredImage = getImageSrc($imageObjectId, 'thumbnail');
         }
         if ($imageObjectId = $object->getValue('_content_image')) {
             $contentImage = getImageSrc($imageObjectId, 'thumbnail');
         }
         //d
     }
     return view('admin.object.create_edit', compact('object', 'fields', 'values', 'fieldControls', 'featuredImage', 'contentImage'));
 }