public static function SaveWidgetHandler(Form $form)
 {
     $id = $form->getElement('id')->get('value');
     // ID can be null, that just means it's a new widget!
     if (!$id) {
         // Generate an id!
         $id = Core::GenerateUUID();
     }
     $model = new WidgetModel('/gallery/view/' . $id);
     $model->set('editurl', '/gallerywidget/update/' . $id);
     $model->set('deleteurl', '/gallerywidget/delete/' . $id);
     $model->set('title', $form->getElement('title')->get('value'));
     $model->setSetting('album', $form->getElement('album')->get('value'));
     $model->setSetting('count', $form->getElement('count')->get('value'));
     $model->setSetting('order', $form->getElement('order')->get('value'));
     $model->setSetting('dimensions', $form->getElement('dimensions')->get('value'));
     $model->setSetting('uselightbox', $form->getElement('uselightbox')->get('value'));
     $model->save();
     return 'back';
 }
예제 #2
0
	public static function _WidgetCreateUpdateHandler(Form $form){
		$baseurl = $form->getElement('baseurl')->get('value');

		$model = new WidgetModel($baseurl);
		$model->set('editurl', '/admin/widget/update?baseurl=' . $baseurl);
		$model->set('deleteurl', '/admin/widget/delete?baseurl=' . $baseurl);
		$model->set('title', $form->getElement('title')->get('value'));
		if($form->getElement('template')){
			$model->set('template', $form->getElementValue('template'));
		}

		$elements = $form->getElements();
		foreach($elements as $el){
			/** @var FormElement $el */
			if(strpos($el->get('name'), 'setting[') === 0){
				$name = substr($el->get('name'), 8, -1);
				$model->setSetting($name, $el->get('value'));
			}
		}
		$model->save();

		return 'back';
	}
예제 #3
0
	/**
	 * Internal function to parse and handle the configs in the component.xml file.
	 * This is used for installations and upgrades.
	 *
	 * @param boolean $install   Set to false to force uninstall/disable mode.
	 * @param int     $verbosity (default 0) 0: standard output, 1: real-time, 2: real-time verbose output.
	 *
	 * @return boolean | int
	 * @throws InstallerException
	 */
	public function _parseWidgets($install = true, $verbosity = 0) {
		$overallChanges  = [];
		$overallAction   = $install ? 'Installing' : 'Uninstalling';
		$overallActioned = $install ? 'Installed' : 'Uninstalled';
		$overallSet      = $install ? 'Set' : 'Remove';

		Core\Utilities\Logger\write_debug($overallAction . ' Widgets for ' . $this->getName());

		if(!$install){
			die('@todo Support uninstalling widgets via _parseWidgets!');
		}

		// I need to get the schema definitions first.
		$node = $this->_xmlloader->getElement('widgets');
		//$prefix = $node->getAttribute('prefix');

		// Now, get every table under this node.
		foreach ($node->getElementsByTagName('widget') as $subnode) {
			$baseurl     = $subnode->getAttribute('baseurl');
			$installable = $subnode->getAttribute('installable');
			$title       = $subnode->getAttribute('title');

			if($verbosity == 2){
				CLI::PrintActionStart($overallAction . ' widget ' . $baseurl . ' ("' . $title . '")');
			}

			// Insert/Update the defaults for an entry in the database.
			$m = new WidgetModel($baseurl);
			$action = ($m->exists()) ? 'Updated' : 'Added';

			if (!$m->get('title')){
				// Only set the title if it was previously unset
				$m->set('title', $title);
			}

			$m->set('installable', $installable);
			$saved = $m->save();

			if ($saved){
				if($verbosity == 2){
					CLI::PrintActionStatus(true);
				}
				$changes[] = $action . ' widget [' . $m->get('baseurl') . ']';

				// Is this a new widget and it's an admin installable one?
				// If so install it to the admin widgetarea!
				if($action == 'Added' && $installable == '/admin'){
					$weight = WidgetInstanceModel::Count(
						[
							'widgetarea' => 'Admin Dashboard',
							'page_baseurl' => '/admin',
						]
					) + 1;

					$wi = new WidgetInstanceModel();
					$wi->setFromArray(
						[
							'baseurl' => $m->get('baseurl'),
							'page_baseurl' => '/admin',
							'widgetarea' => 'Admin Dashboard',
							'weight' => $weight
						]
					);
					$wi->save();

					$overallChanges[] = $overallActioned . ' widget ' . $m->get('baseurl') . ' into the admin dashboard!';
				}
			}
			else{
				if($verbosity == 2){
					CLI::PrintActionStatus('skip');
				}
			}
		}

		return (sizeof($overallChanges) > 0) ? $overallChanges : false;
	}