Index: trunk/extensions/SemanticForms/includes/SF_Utils.php |
— | — | @@ -149,7 +149,123 @@ |
150 | 150 | SMWPropertyValue::registerProperty( $id, $typeid, $label, true ); |
151 | 151 | } |
152 | 152 | } |
| 153 | + /** |
| 154 | + * Function to return the Property based on the xml passed from the PageSchema extension |
| 155 | + */ |
| 156 | + public static function sfCreatePageSchemasObject( $objectName, $xmlForField, &$object ) { |
| 157 | + $sfarray = array(); |
| 158 | + if ( $objectName == "FormInput" ) { |
| 159 | + foreach ( $xmlForField->children() as $tag => $child ) { |
| 160 | + if ( $tag == $objectName ) { |
| 161 | + foreach ( $child->children() as $prop ) { |
| 162 | + if($prop->getName() == 'InputType'){ |
| 163 | + $sfarray[$prop->getName()] = (string)$prop; |
| 164 | + }else{ |
| 165 | + //Remember these values can be null also. While polulating in the page text, take care of that. |
| 166 | + $sfarray[(string)$prop->attributes()->name] = (string)$prop; |
| 167 | + } |
| 168 | + } |
| 169 | + } |
| 170 | + } |
| 171 | + //Setting value specific to SF in 'sf' index. |
| 172 | + $object['sf'] = $sfarray; |
| 173 | + } |
| 174 | + return true; |
| 175 | + } |
153 | 176 | |
| 177 | + /** |
| 178 | + */ |
| 179 | + public static function sfGetPageList( $psSchemaObj, &$genPageList ) { |
| 180 | + global $wgOut, $wgUser; |
| 181 | + $template_all = $psSchemaObj->getTemplates(); |
| 182 | + $form_templates = array(); |
| 183 | + foreach ( $template_all as $template ) { |
| 184 | + $title = Title::makeTitleSafe( NS_TEMPLATE, $template->getName() ); |
| 185 | + $genPageList[] = 'Template:'.$title->getText(); |
| 186 | + //Creating Form Templates at this time |
| 187 | + $form_template = SFTemplateInForm::create( $template->getName(), |
| 188 | + $template->getLabel(), |
| 189 | + $template->isMultiple() ); |
| 190 | + $form_templates[] = $form_template; |
| 191 | + } |
| 192 | + $form_name = $psSchemaObj->getFormName(); |
| 193 | + $form = SFForm::create( $form_name, $form_templates ); |
| 194 | + $title = Title::makeTitleSafe( SF_NS_FORM, $form->form_name ); |
| 195 | + $genPageList[] = 'Form:'.$title->getText(); |
| 196 | + return true; |
| 197 | + } |
| 198 | + /** |
| 199 | + */ |
| 200 | + public static function sfGeneratePages( $psSchemaObj, $toGenPageList ) { |
| 201 | + global $wgOut, $wgUser; |
| 202 | + $template_all = $psSchemaObj->getTemplates(); |
| 203 | + $form_templates = array(); |
| 204 | + $jobs = array(); |
| 205 | + foreach ( $template_all as $template ) { |
| 206 | + $template_array = array(); |
| 207 | + $template_array['name'] = $template->getName(); |
| 208 | + $template_array['category_name'] = $psSchemaObj->categoryName; |
| 209 | + $field_all = $template->getFields(); |
| 210 | + $field_count = 0; //counts the number of fields |
| 211 | + $template_fields = array(); |
| 212 | + foreach( $field_all as $fieldObj ) { //for each Field, retrieve smw properties and fill $prop_name , $prop_type |
| 213 | + $field_count++; |
| 214 | + $sf_array = $fieldObj->getObject('FormInput');//this returns an array with property values filled |
| 215 | + $form_input_array = $sf_array['sf']; |
| 216 | + $field_t = SFTemplateField::create( $fieldObj->getName(), $fieldObj->getLabel() ); |
| 217 | + $smw_array = $fieldObj->getObject('Property'); //this returns an array with property values filled |
| 218 | + $prop_array = $smw_array['smw']; |
| 219 | + $field_t->semantic_property = $prop_array['name']; |
| 220 | + $field_t->is_list = $fieldObj->isList(); |
| 221 | + $template_fields[] = $field_t; |
| 222 | + } |
| 223 | + $template_text = SFTemplateField::createTemplateText( $template->getName(), $template_fields, null, $psSchemaObj->categoryName, null, null, null ); |
| 224 | + $title = Title::makeTitleSafe( NS_TEMPLATE, $template->getName() ); |
| 225 | + if( in_array('Template:'.$title->getText(), $toGenPageList )){ |
| 226 | + $params = array(); |
| 227 | + $params['user_id'] = $wgUser->getId(); |
| 228 | + $params['page_text'] = $template_text; |
| 229 | + $jobs[] = new PSCreatePageJob( $title, $params ); |
| 230 | + Job::batchInsert( $jobs ); |
| 231 | + } |
| 232 | + //Creating Form Templates at this time |
| 233 | + $form_template = SFTemplateInForm::create( $template->getName(), $template->getLabel(), $template->isMultiple() ); |
| 234 | + $form_templates[] = $form_template; |
| 235 | + } |
| 236 | + $form_name = $psSchemaObj->getFormName(); |
| 237 | + $form = SFForm::create( $form_name, $form_templates ); |
| 238 | + $title = Title::makeTitleSafe( SF_NS_FORM, $form->form_name ); |
| 239 | + if( in_array('Form:'.$title->getText(), $toGenPageList )){ |
| 240 | + $full_text = $form->createMarkup(); |
| 241 | + $params = array(); |
| 242 | + $params['user_id'] = $wgUser->getId(); |
| 243 | + $params['page_text'] = $full_text; |
| 244 | + $jobs[] = new PSCreatePageJob( $title, $params ); |
| 245 | + Job::batchInsert( $jobs ); |
| 246 | + } |
| 247 | + return true; |
| 248 | + } |
| 249 | + /** |
| 250 | + *Thi Function parses the Field elements in the xml of the pages. Hooks for PageSchemas extension |
| 251 | + */ |
| 252 | + public static function sfParseFieldElements( $field_xml, &$text_object ) { |
| 253 | + foreach ( $field_xml->children() as $tag => $child ) { |
| 254 | + if ( $tag == "FormInput" ) { |
| 255 | + $text = ""; |
| 256 | + $text = PageSchemas::tableMessageRowHTML( "paramAttr", "SemanticForms", (string)$tag ); |
| 257 | + foreach ( $child->children() as $prop ) { |
| 258 | + if( $prop->getName() == 'InputType' ){ |
| 259 | + $text .= PageSchemas::tableMessageRowHTML("paramAttrMsg", $prop->getName(), $prop ); |
| 260 | + }else { |
| 261 | + $prop_name = (string)$prop->attributes()->name; |
| 262 | + $text .= PageSchemas::tableMessageRowHTML("paramAttrMsg", $prop_name, (string)$prop ); |
| 263 | + } |
| 264 | + } |
| 265 | + $text_object['sf']=$text; |
| 266 | + } |
| 267 | + } |
| 268 | + return true; |
| 269 | + } |
154 | 270 | public static function initProperties() { |
155 | 271 | global $sfgContLang; |
156 | 272 | |