问题描述
我正在与Drupal 6.x系统一起创建锻炼/个人培训计划,并且正在将CCK与锻炼和计划的内容类型一起使用,其中计划包含一些标题字段和对锻炼的节点引用列表它包括。这很好用,我可以手动创建效果很好的程序。现在,我希望创建一个模块,该模块可以根据我开发的多种算法自动生成这些程序,该过程将类似于:
I am working with a Drupal 6.x system to create exercise / personal training programmes, and am using the CCK with content types of Exercise and Programme, where Programme contains a few header fields and a list of node references to the exercises it consists of. This works great and I can manually create programmes which work fine. I now wish to create a module which can generate these programs automatically based on a number of algorithms I have developed, the process will look like:
- 将所有练习加载到数组中
- 加载用户的个人信息(先前输入)
- 建立最合适的练习
- 创建新的程序内容类型
- 保存程序
- Load all exercises into array
- Load users personal info (entered previously)
- Establish best suited exercises
- Create new programme content type
- Save programme
一个练习具有许多相关属性尽管我可以直接在表中使用SQL来完成上述所有操作,但这将非常复杂并且感觉不正确。我想在第1步中将练习作为练习对象的数组(node_load?)加载,然后创建一个程序对象并保存。这种OO类型方法是否可行?还是我不得不直接处理数据?
An Exercise has a number of related attributes and although I could do all of the above using SQL directly into the tables it would be quite complex and doesn't feel right. I would like in step 1 to load the exercises as an array of Exercise objects (node_load?), and then create a programme object and save. Is this OO type approach possible or do I have to resort to manipulating the data directly?
推荐答案
解决此问题的最佳方法
步骤1您可以对所有权限
执行node_load($ nid)步骤2您可以使用user_load ($ uid)
步骤3,您需要遍历用户对象并匹配适当的权限。
步骤4/5我将创建一个新的$ node = stdClass();对象并使用正确的数据填充属性,然后从node_save($ node)执行;
Step 1 you can do node_load($nid) on all the excerciesStep 2 you can use user_load($uid)Step 3 you'll need to iterate through the user object and match up to the appropriate excercies.Step 4/5 I'd create a new $node = stdClass(); object and populate the attributes with the correct data then perfrom a node_save($node); this will assign it a $node->id etc.
如果不确定训练程序节点中的属性是什么,则执行print_r($ node);在您已经创建的一个上。
If your unsure on what attributes are in your training program node, then do a print_r($node); on one you've created already.
菲尔
这篇关于以编程方式/通过API创建Drupal CCK内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!