Пример #1
0
 /**
  * @param array $record
  */
 public function prepareRecord(array &$record)
 {
     $permissions = ['___delete_allowed' => $this->isDeleteAllowed() && $this->scaffoldSection->isRecordDeleteAllowed($record), '___edit_allowed' => $this->isEditAllowed() && $this->scaffoldSection->isRecordEditAllowed($record), '___details_allowed' => $this->isDetailsViewerAllowed() && $this->scaffoldSection->isRecordDetailsAllowed($record)];
     $customData = $this->getCustomDataForRecord($record);
     $fields = $this->getFields();
     $pkKey = $this->getModel()->getPkColumnName();
     foreach ($record as $key => $value) {
         if ($this->getModel()->hasTableRelation($key)) {
             continue;
         }
         if (empty($fields[$key])) {
             if ($key !== $pkKey) {
                 unset($record[$key]);
             }
             continue;
         }
         if (is_object($fields[$key]) && method_exists($fields[$key], 'convertValue')) {
             $record['__' . $key] = $record[$key];
             $record[$key] = $fields[$key]->convertValue($record[$key], $this->getModel()->getTableColumn($key), $record);
         }
     }
     $record += $permissions;
     if (!empty($customData) && is_array($customData)) {
         $record += $customData;
     }
 }
Пример #2
0
 /**
  * @param array $record
  * @return array
  * @throws \PeskyCMF\Scaffold\ScaffoldFieldException
  * @throws \PeskyORM\Exception\DbColumnConfigException
  * @throws \PeskyORM\Exception\DbModelException
  * @throws \PeskyORM\Exception\DbTableConfigException
  */
 public function prepareRecord(array $record)
 {
     $permissions = ['___delete_allowed' => $this->isDeleteAllowed() && $this->scaffoldSection->isRecordDeleteAllowed($record), '___edit_allowed' => $this->isEditAllowed() && $this->scaffoldSection->isRecordEditAllowed($record), '___details_allowed' => $this->isDetailsViewerAllowed() && $this->scaffoldSection->isRecordDetailsAllowed($record)];
     $customData = $this->getCustomDataForRecord($record);
     $dbFields = $this->getDbFields();
     $pkKey = $this->getModel()->getPkColumnName();
     // backup values
     $recordWithBackup = [];
     foreach ($record as $key => $value) {
         $recordWithBackup[$key] = $recordWithBackup['__' . $key] = $value;
     }
     foreach ($record as $key => $notUsed) {
         if ($this->getModel()->hasTableRelation($key)) {
             continue;
         }
         if (empty($dbFields[$key])) {
             if ($key !== $pkKey) {
                 unset($recordWithBackup[$key]);
             }
             continue;
         }
         $fieldConfig = $dbFields[$key];
         if (is_object($fieldConfig) && method_exists($fieldConfig, 'convertValue') && (!method_exists($fieldConfig, 'isVisible') || $fieldConfig->isVisible())) {
             $recordWithBackup[$key] = $fieldConfig->convertValue($recordWithBackup[$key], $recordWithBackup);
         }
     }
     if (!empty($customData) && is_array($customData)) {
         $recordWithBackup = array_merge($recordWithBackup, $customData);
     }
     $recordWithBackup = array_merge($recordWithBackup, $permissions);
     foreach ($this->getNonDbFields() as $key => $fieldConfig) {
         $valueConverter = $fieldConfig->getValueConverter();
         if ($valueConverter instanceof \Closure) {
             $recordWithBackup[$key] = call_user_func($valueConverter, $recordWithBackup, $fieldConfig, $this);
         } else {
             if (!array_has($recordWithBackup, $key)) {
                 $recordWithBackup[$key] = '';
             }
         }
     }
     return $recordWithBackup;
 }