Example #1
0
 function load(Zikula_Form_View $view, &$params)
 {
     if (!$view->isPostBack()) {
         $classes = ModUtil::apiFunc('Content', 'Admin', 'getStyleClasses');
         $empty = array(array('text' => '', 'value' => ''));
         $classes = array_merge($empty, $classes);
         $this->setItems($classes);
     }
     parent::load($view, $params);
 }
Example #2
0
 function load(Zikula_Form_View $view, &$params)
 {
     $this->addItem('auto', 'wauto');
     $this->addItem('1/1', 'w100');
     $this->addItem('3/4', 'w75');
     $this->addItem('2/3', 'w66');
     $this->addItem('1/2', 'w50');
     $this->addItem('1/3', 'w33');
     $this->addItem('1/4', 'w25');
     parent::load($view, $params);
 }
Example #3
0
 function load(Zikula_Form_View $view, &$params)
 {
     // get all layouts if needed
     if (array_key_exists('layouts', $params)) {
         $layouts = $params['layouts'];
     } else {
         $layouts = ModUtil::apiFunc('Content', 'Layout', 'getLayouts');
         if ($layouts === false) {
             return false;
         }
     }
     foreach ($layouts as $layout) {
         $this->_addItem($layout['title'], $layout['name'], $layout['image']);
     }
     parent::load($view, $params);
 }
Example #4
0
 function load(Zikula_Form_View $view, &$params)
 {
     if (!$view->isPostBack()) {
         // Find the active modules
         $moduleList = ModUtil::apiFunc('Extensions', 'admin', 'listmodules', array('state' => ModUtil::STATE_ACTIVE));
         $modules = array();
         // Only list modules that have a User view
         foreach ($moduleList as $module) {
             if (isset($module['capabilities']['user'])) {
                 $modules[] = array('text' => $module['displayname'], 'value' => $module['name']);
             }
         }
         $empty = array(array('text' => '', 'value' => ''));
         $modules = array_merge($empty, $modules);
         $this->setItems($modules);
     }
     parent::load($view, $params);
 }
Example #5
0
 function render(Zikula_Form_View $view)
 {
     $scripts = array('javascript/ajax/prototype.js', 'modules/Content/javascript/ajax.js');
     PageUtil::addVar('javascript', $scripts);
     $output = "<div class=\"z-formrow\">";
     $output .= parent::render($view);
     $output .= "</div>";
     $descr = array();
     $contentTypes = ModUtil::apiFunc('Content', 'Content', 'getContentTypes');
     foreach ($contentTypes as $type) {
         $descr[] = "\"{$type['module']}:{$type['name']}\" : \"" . htmlspecialchars($type['description']) . '"';
     }
     $descr = '<script type="text/javascript">/* <![CDATA[ */ var contentDescriptions = {' . implode(', ', $descr) . '} /* ]]> */</script>';
     $descr0 = count($contentTypes) > 0 ? $contentTypes[0]['description'] : '';
     $descr0 = htmlspecialchars($descr0);
     $output .= "<div class=\"z-formrow\" id=\"{$this->id}_descr\">{$descr0}</div>";
     $output .= $descr;
     return $output;
 }
Example #6
0
 /**
  * Load event handler.
  *
  * @param Zikula_Form_View $view Reference to Zikula_Form_View object.
  * @param array            &$params Parameters passed from the Smarty plugin function.
  *
  * @return void
  */
 public function load(Zikula_Form_View $view, &$params)
 {
     if ($this->mandatory) {
         $this->addItem('---', null);
     }
     if ($this->addAllOption) {
         $this->addItem(DataUtil::formatForDisplay(__('All')), '');
     }
     if ($this->onlyInstalledLanguages) {
         $langList = ZLanguage::getInstalledLanguageNames();
         foreach ($langList as $code => $name) {
             $this->addItem($name, $code);
         }
     } else {
         $langList = ZLanguage::languageMap();
         foreach ($langList as $code => $name) {
             $this->addItem($name, $code);
         }
     }
     parent::load($view, $params);
 }
Example #7
0
 function load(Zikula_Form_View $view, &$params)
 {
     // get all layouts if needed
     if (array_key_exists('layouts', $params)) {
         $layouts = $params['layouts'];
     } else {
         $layouts = ModUtil::apiFunc('Content', 'Layout', 'getLayouts');
         if ($layouts === false) {
             return false;
         }
     }
     // get module var for display layout options
     $layoutDisplay = ModUtil::getVar('Content', 'layoutDisplay');
     foreach ($layouts as $layout) {
         if (is_array($layoutDisplay) && $layoutDisplay[$layout['templateType']]) {
             // only show the layout option when the templateType is enabled
             $this->_addItem($layout['title'], $layout['name'], $layout['image']);
         }
     }
     parent::load($view, $params);
 }
Example #8
0
 /**
  * Load event handler.
  *
  * @param Zikula_Form_View $view Reference to Zikula_Form_View object.
  * @param array            &$params Parameters passed from the Smarty plugin function.
  *
  * @return void
  */
 public function load(Zikula_Form_View $view, &$params)
 {
     if ($this->showEmptyValue != 0) {
         $this->addItem('- - -', 0);
     }
     // switch between doctrine and dbobject mode
     if ($this->recordClass) {
         $q = Doctrine::getTable($this->recordClass)->createQuery();
         if ($this->where) {
             if (is_array($this->where)) {
                 $q->where($this->where[0], $this->where[1]);
             } else {
                 $q->where($this->where);
             }
         }
         if ($this->orderby) {
             $q->orderBy($this->orderby);
         }
         if ($this->pos >= 0) {
             $q->offset($this->pos);
         }
         if ($this->num > 0) {
             $q->limit($this->num);
         }
         $rows = $q->execute();
         foreach ($rows as $row) {
             $itemLabel = $row[$this->displayField];
             if (!empty($this->displayFieldTwo)) {
                 $itemLabel .= ' (' . $row[$this->displayFieldTwo] . ')';
             }
             $this->addItem($itemLabel, $row[$this->idField]);
         }
     } else {
         ModUtil::dbInfoLoad($this->module);
         // load the object class corresponding to $this->objecttype
         $class = "{$this->module}_DBObject_" . StringUtil::camelize($this->objecttype) . 'Array';
         // instantiate the object-array
         $objectArray = new $class();
         // get() returns the cached object fetched from the DB during object instantiation
         // get() with parameters always performs a new select
         // while the result will be saved in the object, we assign in to a local variable for convenience.
         $objectData = $objectArray->get($this->where, $this->orderby, $this->pos, $this->num);
         foreach ($objectData as $obj) {
             $itemLabel = $obj[$this->displayField];
             if (!empty($this->displayFieldTwo)) {
                 $itemLabel .= ' (' . $obj[$this->displayFieldTwo] . ')';
             }
             $this->addItem($itemLabel, $obj[$this->idField]);
         }
     }
     parent::load($view, $params);
 }
Example #9
0
 /**
  * Load values.
  *
  * Called internally by the plugin itself to load values from the render.
  * Can also by called when some one is calling the render object's Zikula_Form_View::setValues.
  *
  * @param Zikula_Form_View $view    Reference to Zikula_Form_View render object.
  * @param array            &$values Values to load.
  *
  * @return void
  */
 function loadValue(Zikula_Form_View $view, &$values)
 {
     if ($this->enableDBUtil && $this->dataBased) {
         $items = null;
         $value = null;
         if ($this->group == null) {
             if ($this->dataField != null && isset($values['__CATEGORIES__'][$this->dataField])) {
                 $value = $values['__CATEGORIES__'][$this->dataField];
             }
             if ($this->itemsDataField != null && isset($values[$this->itemsDataField])) {
                 $items = $values[$this->itemsDataField];
             }
         } else {
             if (isset($values[$this->group])) {
                 $data = $values[$this->group];
                 if (isset($data['__CATEGORIES__'][$this->dataField])) {
                     $value = $data['__CATEGORIES__'][$this->dataField];
                     if ($this->itemsDataField != null && isset($data[$this->itemsDataField])) {
                         $items = $data[$this->itemsDataField];
                     }
                 }
             }
         }
         if ($items != null) {
             $this->setItems($items);
         }
         $this->setSelectedValue($value);
     } else {
         if ($this->enableDoctrine && $this->dataBased) {
             $items = null;
             $value = null;
             if ($this->group == null) {
                 if ($this->dataField != null && isset($values['Categories'][$this->dataField])) {
                     $value = $values['Categories'][$this->dataField]['category_id'];
                 }
                 if ($this->itemsDataField != null && isset($values[$this->itemsDataField])) {
                     $items = $values[$this->itemsDataField];
                 }
             } else {
                 if (isset($values[$this->group])) {
                     $data = $values[$this->group];
                     if (isset($data['Categories'][$this->dataField])) {
                         $value = $data['Categories'][$this->dataField]['category_id'];
                         if ($this->itemsDataField != null && isset($data[$this->itemsDataField])) {
                             $items = $data[$this->itemsDataField];
                         }
                     }
                 }
             }
             if ($items != null) {
                 $this->setItems($items);
             }
             $this->setSelectedValue($value);
         } else {
             if ($this->doctrine2) {
                 if (isset($values[$this->group])) {
                     $entity = $values[$this->group];
                     if (isset($entity[$this->dataField])) {
                         $collection = $entity[$this->dataField];
                         if (isset($collection[$this->registryId])) {
                             $value = $collection[$this->registryId]->getCategory()->getId();
                             $this->setSelectedValue($value);
                         }
                     }
                 }
             } else {
                 parent::loadValue($view, $values);
             }
         }
     }
 }
Example #10
0
 /**
  * Load values.
  *
  * Called internally by the plugin itself to load values from the render.
  * Can also by called when some one is calling the render object's Zikula_Form_View::setValues.
  *
  * @param Zikula_Form_View $view    Reference to Zikula_Form_View render object.
  * @param array            &$values Values to load.
  *
  * @return void
  */
 public function loadValue(Zikula_Form_View $view, &$values)
 {
     if ($this->enableDBUtil && $this->dataBased) {
         $items = null;
         $value = null;
         if ($this->group == null) {
             if ($this->dataField != null && isset($values['__CATEGORIES__'][$this->dataField])) {
                 $value = $values['__CATEGORIES__'][$this->dataField];
             }
             if ($this->itemsDataField != null && isset($values[$this->itemsDataField])) {
                 $items = $values[$this->itemsDataField];
             }
         } else {
             if (isset($values[$this->group])) {
                 $data = $values[$this->group];
                 if (isset($data['__CATEGORIES__'][$this->dataField])) {
                     $value = $data['__CATEGORIES__'][$this->dataField];
                     if ($this->itemsDataField != null && isset($data[$this->itemsDataField])) {
                         $items = $data[$this->itemsDataField];
                     }
                 }
             }
         }
         if ($items != null) {
             $this->setItems($items);
         }
         $this->setSelectedValue($value);
     } else {
         if ($this->enableDoctrine && $this->dataBased) {
             $items = null;
             $value = null;
             if ($this->group == null) {
                 if ($this->dataField != null && isset($values['Categories'][$this->dataField])) {
                     $value = $values['Categories'][$this->dataField]['category_id'];
                 }
                 if ($this->itemsDataField != null && isset($values[$this->itemsDataField])) {
                     $items = $values[$this->itemsDataField];
                 }
             } else {
                 if (isset($values[$this->group])) {
                     $data = $values[$this->group];
                     if (isset($data['Categories'][$this->dataField])) {
                         $value = $data['Categories'][$this->dataField]['category_id'];
                         if ($this->itemsDataField != null && isset($data[$this->itemsDataField])) {
                             $items = $data[$this->itemsDataField];
                         }
                     }
                 }
             }
             if ($items != null) {
                 $this->setItems($items);
             }
             $this->setSelectedValue($value);
         } else {
             if ($this->doctrine2) {
                 if (isset($values[$this->group])) {
                     $entity = $values[$this->group];
                     if (isset($entity[$this->dataField])) {
                         $collection = $entity[$this->dataField];
                         $selectedValues = array();
                         foreach ($collection as $c) {
                             $categoryId = $c->getCategoryRegistryId();
                             if ($categoryId == $this->registryId) {
                                 $selectedValues[] = $c->getCategory()->getId();
                             }
                         }
                         if ($this->selectionMode == 'single' && isset($selectedValues[0])) {
                             $this->setSelectedValue($selectedValues[0]);
                         } else {
                             $this->setSelectedValue($selectedValues);
                         }
                     }
                 }
             } else {
                 parent::loadValue($view, $values);
             }
         }
     }
 }
 /**
  * Set the selected value.
  *
  * @param mixed $value Selected value.
  *
  * @return void
  */
 public function setSelectedValue($value)
 {
     $newValue = null;
     if ($this->selectionMode == 'single') {
         if ($value instanceof Zikula_EntityAccess && method_exists($value, 'createCompositeIdentifier')) {
             $newValue = $value->createCompositeIdentifier();
         } elseif (is_array($value)) {
             $idFields = ModUtil::apiFunc($this->name, 'selection', 'getIdFields', array('ot' => $value['_objectType']));
             $newValue = $value[$idFields[0]];
         } else {
             $newValue[] = $value;
         }
     } else {
         $newValue = array();
         if (is_array($value) || $value instanceof Collection) {
             foreach ($value as $entity) {
                 if ($entity instanceof Zikula_EntityAccess && method_exists($entity, 'createCompositeIdentifier')) {
                     $newValue[] = $entity->createCompositeIdentifier();
                 } elseif (is_array($entity)) {
                     $idFields = ModUtil::apiFunc($this->name, 'selection', 'getIdFields', array('ot' => $entity['_objectType']));
                     $newValue[] = $entity[$idFields[0]];
                 } else {
                     $newValue[] = $entity;
                 }
             }
         }
     }
     return parent::setSelectedValue($newValue);
 }
Example #12
0
 /**
  * Alias to Zikula_Form_Plugin_DropdownList constructor.
  *
  * @deprecated
  * @see Zikula_Form_Plugin_DropdownList::__construct()
  */
 public function __construct(&$render, &$params)
 {
     parent::__construct($render, $params);
     LogUtil::log(__f('Warning! Class %1$s is deprecated. Please use %2$s instead.', array(__CLASS__, 'Zikula_Form_Plugin_DropdownList')), E_USER_DEPRECATED);
 }