/**
  * Export all setting categories and settings into a xml file
  */
 public function actionExport($filename = 'settings.xml')
 {
     $fileLocation = Yii::getPathOfAlias('console.data') . '/' . $filename;
     // Export setting categories first
     $xml = new ClassXML();
     $xml->newXMLDocument();
     // Grab categories
     $categories = Yii::app()->db->createCommand('SELECT * FROM `settingcat`')->queryAll();
     $categoriesKeys = array();
     $xml->addElement('settings_export');
     $xml->addElement('setting_categories', 'settings_export');
     foreach ($categories as $category) {
         $categoriesKeys[$category['id']] = $category['groupkey'];
         unset($category['id']);
         $xml->addElementAsRecord('setting_categories', 'setting_category', $category);
     }
     // Grab Settings
     $settings = Yii::app()->db->createCommand('SELECT * FROM `setting`')->queryAll();
     $xml->addElement('settings', 'settings_export');
     foreach ($settings as $setting) {
         unset($setting['id']);
         // Switch category
         $setting['category'] = $categoriesKeys[$setting['category']];
         $xml->addElementAsRecord('settings', 'setting_row', $setting);
     }
     $contents = $xml->fetchDocument();
     file_put_contents($fileLocation, $contents);
     echoCli('Export Done');
 }
 /**
  * Export all source messages into a xml file
  */
 public function actionExport($filename = 'language_messages.xml')
 {
     $fileLocation = Yii::getPathOfAlias('console.data') . '/' . $filename;
     // Export setting categories first
     $xml = new ClassXML();
     $xml->newXMLDocument();
     // Grab categories
     $messages = Yii::app()->db->createCommand('SELECT * FROM `source_message`')->queryAll();
     $messageKeys = array();
     $xml->addElement('messages_export');
     foreach ($messages as $message) {
         unset($message['id']);
         $xml->addElementAsRecord('messages_export', 'message_row', $message);
     }
     $contents = $xml->fetchDocument();
     file_put_contents($fileLocation, $contents);
     echoCli('Export Done');
 }
 /**
  * Export all permissions into the xml file
  */
 public function actionExport($filename = 'permissions.xml')
 {
     $fileLocation = Yii::getPathOfAlias('console.data') . '/' . $filename;
     // Export setting categories first
     $xml = new ClassXML();
     $xml->newXMLDocument();
     // Grab auth items
     $authItems = Yii::app()->db->createCommand('SELECT * FROM `auth_item`')->queryAll();
     $xml->addElement('permissions_export');
     $xml->addElement('permissions_auth_items', 'permissions_export');
     foreach ($authItems as $authItem) {
         unset($authItem['id']);
         $xml->addElementAsRecord('permissions_auth_items', 'auth_item', $authItem);
     }
     // Grab auth item child
     $authItemChilds = Yii::app()->db->createCommand('SELECT * FROM `auth_item_child`')->queryAll();
     $xml->addElement('auth_item_childs', 'permissions_export');
     foreach ($authItemChilds as $authItemChild) {
         $xml->addElementAsRecord('auth_item_childs', 'auth_item_child_row', $authItemChild);
     }
     $contents = $xml->fetchDocument();
     file_put_contents($fileLocation, $contents);
     echoCli('Export Done');
 }
 /**
  * Export language
  */
 public function actionExport($id)
 {
     // Check access
     checkAccessThrowException('op_language_export_language');
     // Check if it exists
     $model = Language::model()->findByPk($id);
     if (!$model) {
         ferror(at('That language was not found.'));
         $this->redirect(array('index'));
     }
     // Export setting categories first
     $xml = new ClassXML();
     $xml->newXMLDocument();
     $xml->addElement('language_export');
     // Grab categories
     $xml->addElementAsRecord('language_export', 'language_row', array('name' => $model->name, 'abbr' => $model->abbr));
     // Grab Messages
     $messages = Yii::app()->db->createCommand()->select('m.*, s.message, s.category')->from('message m')->join('source_message s', 's.id=m.id')->where('language_id=:id', array(':id' => $id))->queryAll();
     $xml->addElement('messages_export', 'language_export');
     foreach ($messages as $message) {
         $data = array('category' => $message['category'], 'orig' => $message['message'], 'translation' => $message['translation']);
         $xml->addElementAsRecord('messages_export', 'message_row', $data);
     }
     $contents = $xml->fetchDocument();
     $name = sprintf('language_export_%s_%s', $model->abbr, date('y_m_d'));
     // Download
     downloadAs($name, trim($contents), 'xml');
 }