当前位置: 首页>>代码示例>>PHP>>正文


PHP plgFabrik_Element::onSave方法代码示例

本文整理汇总了PHP中plgFabrik_Element::onSave方法的典型用法代码示例。如果您正苦于以下问题:PHP plgFabrik_Element::onSave方法的具体用法?PHP plgFabrik_Element::onSave怎么用?PHP plgFabrik_Element::onSave使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在plgFabrik_Element的用法示例。


在下文中一共展示了plgFabrik_Element::onSave方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: makeElementsFromFields

 /**
  * take a table name and make elements for all of its fields
  * @param int group id
  * @param string $tableName
  */
 function makeElementsFromFields($groupId, $tableName)
 {
     $fabrikDb =& $this->getFEModel()->getDb();
     $dispatcher = JDispatcher::getInstance();
     $elementModel = new plgFabrik_Element($dispatcher);
     $pluginManager = $this->getFormModel()->getPluginManager();
     $user = JFactory::getUser();
     $elementTypes = JRequest::getVar('elementtype', array(), 'default', 'array');
     $fields = $fabrikDb->getTableFields(array($tableName));
     $fields = $fields[$tableName];
     $createdate = JFactory::getDate()->toMySQL();
     $key = $this->getFEModel()->getPrimaryKeyAndExtra($tableName);
     $ordering = 0;
     // no existing fabrik table so we take a guess at the most
     //relavent element types to  create
     $elementLabels = JRequest::getVar('elementlabels', array(), 'default', 'array');
     foreach ($fields as $label => $type) {
         $element = FabTable::getInstance('Element', 'FabrikTable');
         if (array_key_exists($ordering, $elementTypes)) {
             //if importing from a CSV file then we have userselect field definitions
             $plugin = $elementTypes[$ordering];
         } else {
             //if the field is the primary key and it's an INT type set the plugin to be the fabrik internal id
             if ($key[0]['colname'] == $label && strtolower(substr($key[0]['type'], 0, 3)) === 'int') {
                 $plugin = 'internalid';
             } else {
                 //otherwise guestimate!
                 switch ($type) {
                     case "int":
                     case "tinyint":
                     case "varchar":
                         $plugin = 'field';
                         break;
                     case "text":
                     case "tinytext":
                     case "mediumtext":
                     case "longtext":
                         $plugin = 'textarea';
                         break;
                     case "datetime":
                     case "date":
                     case "time":
                     case "timestamp":
                         $plugin = 'date';
                         break;
                     default:
                         $plugin = 'field';
                         break;
                 }
             }
         }
         $element->plugin = $plugin;
         $element->hidden = $element->label == 'id' ? '1' : '0';
         $element->group_id = $groupId;
         $element->name = $label;
         $element->created = $createdate;
         $element->created_by = $user->get('id');
         $element->created_by_alias = $user->get('username');
         $element->published = '1';
         $element->show_in_list_summary = '1';
         switch ($plugin) {
             case 'textarea':
                 $element->width = '40';
                 break;
             case 'date':
                 $element->width = '10';
                 break;
             default:
                 $element->width = '30';
                 break;
         }
         $element->height = '6';
         $element->ordering = $ordering;
         $element->params = $elementModel->getDefaultAttribs();
         $element->label = JArrayHelper::getValue($elementLabels, $ordering, str_replace("_", " ", $label));
         if (!$element->store()) {
             return JError::raiseError(500, $element->getError());
         }
         $elementModel =& $pluginManager->getPlugIn($element->plugin, 'element');
         $elementModel->setId($element->id);
         $elementModel->_element = $element;
         // hack for user element
         $details = array('group_id' => $element->group_id);
         JRequest::setVar('details', $details);
         $elementModel->onSave();
         $ordering++;
     }
 }
开发者ID:juliano-hallac,项目名称:fabrik,代码行数:93,代码来源:list.php


注:本文中的plgFabrik_Element::onSave方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。