예제 #1
0
 public function manage($path)
 {
     // Checks if...
     if (!$path['id'] && is_scalar($path['parameter'])) {
         // Creates new asset with default parameters
         $asset = DataCenterDBAsset::newFromType($path['type'], array('model' => $path['parameter'], 'tense' => 'present'));
         // Sets action specific parameters
         $formParameters = array('label' => 'deploy', 'hidden' => array('model'), 'success' => array('page' => 'assets', 'type' => $path['type']), 'type' => 'deploy');
         $headingParameters = array('message' => 'deploying-asset-type', 'subject' => DataCenterUI::message('type', $path['type']));
     } else {
         // Gets asset from database
         $asset = DataCenterDB::getAsset($path['type'], $path['id']);
         // Sets 'do' specific parameters
         $formParameters = array('label' => 'save', 'hidden' => array('id'), 'success' => array('page' => 'assets', 'type' => $path['type'], 'action' => 'view', 'id' => $path['id']), 'type' => 'manage');
         $headingParameters = array('message' => 'managing-asset-type', 'subject' => DataCenterUI::message('type', $path['type']));
     }
     // Gets model from database
     $model = $asset->getModel();
     // Gets list of locations
     $locations = DataCenterDB::getLocations();
     // Completes form parameters
     $formParameters = array_merge($formParameters, array('do' => 'save', 'failure' => $path, 'action' => array('page' => 'assets', 'type' => $path['type']), 'row' => $asset, 'fields' => array('tense' => array('type' => 'tense', 'disable' => !$path['id'] ? array('past') : array()), 'location' => array('type' => 'list', 'rows' => $locations, 'labels' => array('name', 'region'), 'glue' => ' / '), 'serial' => array('type' => 'string'), 'asset' => array('type' => 'string'))));
     // Returns 2 columm layout with a form and a scene
     return DataCenterUI::renderLayout('columns', array(DataCenterUI::renderLayout('rows', array(DataCenterUI::renderWidget('heading', $headingParameters), DataCenterUI::renderWidget('form', $formParameters))), DataCenterUI::renderLayout('rows', array(DataCenterUI::renderWidget('heading', array('message' => 'model-type', 'type' => $path['type'])), DataCenterUI::renderWidget('details', array_merge(self::$options[$path['type']]['details'], array('row' => $model)))))));
 }
예제 #2
0
 public function save(array $data, $type)
 {
     if (!DataCenterPage::userCan('change')) {
         return false;
     }
     $asset = DataCenterDBAsset::newFromType($type, $data['row']);
     $asset->save();
     $asset->saveMetaValues($data['meta']);
     $asset->insertChange($data['change']);
     return true;
 }