Beispiel #1
0
 /**
  * Set data from a method call.
  *
  * If $key is an array, the behaviour will be the same as calling the method
  * multiple times for each (key, value) pair in the $key array.
  * Note that the parameter $value will not be used if $key is an array.
  *
  * The $key can also use dot notation in order to set a value deeper inside the Data array.
  * Works the same way if $addProperty is true, but uses objects instead of arrays.
  *
  * @see setvalr
  *
  * @param string|array $key The key that identifies the data.
  * @param mixed $value The data.  Will not be used if $key is an array
  * @param mixed $addProperty Whether or not to also set the data as a property of this object.
  * @return mixed The $Value that was set.
  */
 public function setData($key, $value = null, $addProperty = false)
 {
     // In the case of $key being an array of (key => value),
     // it calls itself with each (key => value)
     if (is_array($key)) {
         foreach ($key as $k => $v) {
             $this->setData($k, $v, $addProperty);
         }
         return;
     }
     setvalr($key, $this->Data, $value);
     if ($addProperty === true) {
         setvalr($key, $this, $value);
     }
     return $value;
 }
 /**
  * Set a key to a value in a collection.
  *
  * Works with single keys or "dot" notation. If $key is an array, a simple
  * shallow array_merge is performed.
  *
  * @param string $key The key or property name of the value.
  * @param array &$collection The array or object to search.
  * @param mixed $value The value to set.
  * @return mixed Newly set value or if array merge
  * @deprecated Use {@link setvalr()}.
  */
 function svalr($key, &$collection, $value = null)
 {
     setvalr($key, $collection, $value);
 }
 /**
  * Enabling and disabling categories from list.
  *
  * @since 2.0.0
  * @access public
  */
 public function manageCategories()
 {
     // Check permission
     $this->permission('Garden.Community.Manage');
     $this->addSideMenu('vanilla/settings/managecategories');
     $this->addJsFile('categories.js');
     $this->addJsFile('jquery.alphanumeric.js');
     // This now works on latest jQuery version 1.10.2
     //
     // Jan29, 2014, upgraded jQuery UI to 1.10.3 from 1.8.11
     $this->addJsFile('nestedSortable/jquery-ui.min.js');
     // Newer nestedSortable, but does not work.
     //$this->addJsFile('js/library/nestedSortable/jquery.mjs.nestedSortable.js');
     // old jquery-ui
     //$this->addJsFile('js/library/nestedSortable.1.3.4/jquery-ui-1.8.11.custom.min.js');
     $this->addJsFile('nestedSortable.1.3.4/jquery.ui.nestedSortable.js');
     $this->title(t('Categories'));
     // Get category data
     $CategoryData = $this->CategoryModel->getAll('TreeLeft');
     // Set CanDelete per-category so we can override later if we want.
     $canDelete = checkPermission('Garden.Settings.Manage');
     array_walk($CategoryData->result(), function (&$value) use($canDelete) {
         setvalr('CanDelete', $value, $canDelete);
     });
     $this->setData('CategoryData', $CategoryData, true);
     // Setup & save forms
     $Validation = new Gdn_Validation();
     $ConfigurationModel = new Gdn_ConfigurationModel($Validation);
     $ConfigurationModel->setField(array('Vanilla.Categories.MaxDisplayDepth', 'Vanilla.Categories.DoHeadings', 'Vanilla.Categories.HideModule'));
     // Set the model on the form.
     $this->Form->setModel($ConfigurationModel);
     // Define MaxDepthOptions
     $DepthData = array();
     $DepthData['2'] = sprintf(t('more than %s deep'), plural(1, '%s level', '%s levels'));
     $DepthData['3'] = sprintf(t('more than %s deep'), plural(2, '%s level', '%s levels'));
     $DepthData['4'] = sprintf(t('more than %s deep'), plural(3, '%s level', '%s levels'));
     $DepthData['0'] = t('never');
     $this->setData('MaxDepthData', $DepthData);
     // If seeing the form for the first time...
     if ($this->Form->authenticatedPostBack() === false) {
         // Apply the config settings to the form.
         $this->Form->setData($ConfigurationModel->Data);
     } else {
         if ($this->Form->save() !== false) {
             $this->informMessage(t("Your settings have been saved."));
         }
     }
     // Render default view
     $this->render();
 }