コード例 #1
0
ファイル: NodePermission.php プロジェクト: autn/gcl-users
 /**
  * Add a node permission
  *
  * @param array $attributes
  * @return json
  */
 public function add(array $attributes = [])
 {
     if (isset($attributes['parent_id']) && !empty($attributes['parent_id'])) {
         $parent = parent::where('id', '=', $attributes['parent_id'])->first();
         if (!$parent) {
             return false;
         }
         $child = parent::create($attributes);
         $child->makeChildOf($parent);
     } else {
         $root = $this->getRootNode();
         $child = parent::create($attributes);
         $child->makeChildOf($root);
     }
     return $this->getRootChildren();
 }
コード例 #2
0
 /**
  * Processes POST requests (both insert and edit)
  *
  * @return object
  */
 public function postEntry()
 {
     // $imageFields will be used to skip image fields that were not used in POST
     $imageFields = array();
     // Handle file uploads, if image fields are present
     if (count($this->imageFields) > 0) {
         // If fieldId is not set get the next auto incremenet id (Needed for filename generation)
         $fieldId = is_numeric(\Input::get('id')) ? \Input::get('id') : AdminController::getNextAutoIncrement($this->data['module']->table_name);
         foreach ($this->imageFields as $imageField) {
             if (\Input::hasFile($imageField->column_name)) {
                 // Handle file upload
                 $fileName = $this->handleFileUpload($imageField->column_name, $imageField->id, $fieldId);
                 // Store a fileName in database
                 $fileName = is_null($fileName) ? '' : $fileName;
                 \Input::merge([$imageField->column_name => $fileName]);
             } else {
                 \Input::merge([$imageField->column_name => '']);
                 $imageFields[] = $imageField->column_name;
             }
         }
     }
     $manyToManyFields = array();
     // Handle many-to-many fields
     if (count($this->manyToManyFields) > 0) {
         foreach ($this->manyToManyFields as $manyToManyField) {
             $manyToManyFields[] = $manyToManyField->column_name;
         }
     }
     // If id is set then do entry editing
     if (is_numeric(\Input::get('id'))) {
         // Editing entry
         foreach (\Input::all() as $columnName => $value) {
             // Skip empty image upload fields
             if (!in_array($columnName, $imageFields)) {
                 $this->data['entry'][$columnName] = $value;
             }
         }
         // Handle many-to-many input differently
         foreach ($manyToManyFields as $field) {
             $tableName = $this->data['manyToMany'][$field]['tableName'];
             if (\Input::has($field)) {
                 $this->data['entry'][$field] = '';
                 if (is_array(\Input::get($field))) {
                     $this->data['entry']->{$tableName}()->sync(\Input::get($field));
                 }
             } else {
                 $this->data['entry']->{$tableName}()->detach();
             }
         }
         // Save the data
         $this->data['entry']->save();
         // Flash the success message to a user
         \Session::flash('success', 'Data has been saved.');
     } else {
         // Inserting new entry
         $newNode = $this->modelInstance->create(\Input::all());
         // If parent_id is provided move a newly created node under parent_id node
         if (is_numeric(\Input::get('parent_id'))) {
             $parentNode = $this->modelInstance->find(\Input::get('parent_id'));
             $newNode->makeChildOf($parentNode);
         }
     }
     // Render the view
     return \Redirect::to(\Request::path());
 }