[pLog-svn] r3953 - in plog/trunk: class/action/admin class/dao/customfields locale templates/admin

oscar at devel.lifetype.net oscar at devel.lifetype.net
Sun Sep 10 18:09:52 GMT 2006


Author: oscar
Date: 2006-09-10 18:09:52 +0000 (Sun, 10 Sep 2006)
New Revision: 3953

Added:
   plog/trunk/class/dao/customfields/customfieldlistvalue.class.php
Modified:
   plog/trunk/class/action/admin/adminaddcustomfieldaction.class.php
   plog/trunk/class/action/admin/admineditcustomfieldaction.class.php
   plog/trunk/class/action/admin/adminpostmanagementcommonaction.class.php
   plog/trunk/class/action/admin/adminupdatecustomfieldaction.class.php
   plog/trunk/class/dao/customfields/customfield.class.php
   plog/trunk/class/dao/customfields/customfields.class.php
   plog/trunk/class/dao/customfields/customfieldvaluefactory.class.php
   plog/trunk/locale/locale_en_UK.php
   plog/trunk/templates/admin/customfields.template
   plog/trunk/templates/admin/editcustomfield.template
   plog/trunk/templates/admin/editpost.template
   plog/trunk/templates/admin/header.template
   plog/trunk/templates/admin/newcustomfield.template
   plog/trunk/templates/admin/newpost.template
   plog/trunk/templates/admin/newpost_customfields.template
Log:
added support for drop-down lists as a type of custom field in LT 1.2


Modified: plog/trunk/class/action/admin/adminaddcustomfieldaction.class.php
===================================================================
--- plog/trunk/class/action/admin/adminaddcustomfieldaction.class.php	2006-09-10 13:13:56 UTC (rev 3952)
+++ plog/trunk/class/action/admin/adminaddcustomfieldaction.class.php	2006-09-10 18:09:52 UTC (rev 3953)
@@ -34,6 +34,7 @@
 			$this->_form->registerField( "fieldSearchable" );
 			$this->_form->registerField( "fieldHidden" );
 			$this->_form->registerField( "fieldId" );
+			$this->_form->registerField( "fieldValues" );
 			$this->setValidationErrorView( new AdminTemplatedView( $this->_blogInfo, "newcustomfield" ));
         }
 		
@@ -48,16 +49,29 @@
 			$this->_fieldType = $this->_request->getValue( "fieldType" );
 			$this->_fieldSearchable = (int)($this->_request->getValue( "fieldSearchable" ) != "" );
 			$this->_fieldHidden = (int)($this->_request->getValue( "fieldHidden" ) != "" );
+						
+			// get and pre-process the field values
+			if( $this->_fieldType == CUSTOM_FIELD_LIST ) {
+				$values = $this->_request->getValue( "fieldValues" );
+				$this->_fieldValues = Array();				
+				foreach( $values as $value ) {
+					$this->_fieldValues[] = Textfilter::filterAllHTML( $value );
+				}
+			}
 		
 			$fields = new CustomFields();
 			
 			// build the new custom field
 			$customField = new CustomField( $this->_fieldName, 
-			                                $this->_fieldDescription, $this->_fieldType,
+			                                $this->_fieldDescription, 
+			                                $this->_fieldType,
 			                                $this->_blogInfo->getId(), 
 											$this->_fieldHidden, 
-											$this->_fieldSearchable );
-											
+											$this->_fieldSearchable );			
+			// save the values if this field is a list
+			if( $this->_fieldType == CUSTOM_FIELD_LIST )
+				$customField->setFieldValues( $this->_fieldValues );
+				
 			// throw the pre-event
 			$this->notifyEvent( EVENT_PRE_CUSTOM_FIELD_ADD, Array( "field" => &$customField ));
 			

Modified: plog/trunk/class/action/admin/admineditcustomfieldaction.class.php
===================================================================
--- plog/trunk/class/action/admin/admineditcustomfieldaction.class.php	2006-09-10 13:13:56 UTC (rev 3952)
+++ plog/trunk/class/action/admin/admineditcustomfieldaction.class.php	2006-09-10 18:09:52 UTC (rev 3953)
@@ -31,7 +31,8 @@
 			$this->_form->registerField( "fieldDescription" );
 			$this->_form->registerField( "fieldType" );
 			$this->_form->registerField( "fieldSearchable" );
-			$this->_form->registerField( "fieldHidden" );			
+			$this->_form->registerField( "fieldHidden" );
+			$this->_form->registerField( "fieldValues" );
         }
 
 
@@ -61,6 +62,7 @@
 				$this->_view->setValue( "fieldType", $field->getType());
 				$this->_view->setValue( "fieldSearchable", true );
 				$this->_view->setValue( "fieldHidden", $field->isHidden());
+				$this->_view->setValue( "fieldValues", $field->getFieldValues());
 			}
 			
 			$this->setCommonData();

Modified: plog/trunk/class/action/admin/adminpostmanagementcommonaction.class.php
===================================================================
--- plog/trunk/class/action/admin/adminpostmanagementcommonaction.class.php	2006-09-10 13:13:56 UTC (rev 3952)
+++ plog/trunk/class/action/admin/adminpostmanagementcommonaction.class.php	2006-09-10 18:09:52 UTC (rev 3953)
@@ -149,7 +149,7 @@
 		 */
 		function _getArticleCustomFields()
 		{
-			// prepare the custom fields
+			// prepare the custom fields			
 			$fields = Array();
 			if( is_array($this->_customFields)) {
 				foreach( $this->_customFields as $fieldId => $fieldValue ) {

Modified: plog/trunk/class/action/admin/adminupdatecustomfieldaction.class.php
===================================================================
--- plog/trunk/class/action/admin/adminupdatecustomfieldaction.class.php	2006-09-10 13:13:56 UTC (rev 3952)
+++ plog/trunk/class/action/admin/adminupdatecustomfieldaction.class.php	2006-09-10 18:09:52 UTC (rev 3953)
@@ -21,6 +21,7 @@
 		var $_fieldSearchable;
 		var $_fieldId;
 		var $_fieldHidden;
+		var $_fieldValues;
 
         function AdminUpdateCustomFieldAction( $actionInfo, $request )
         {
@@ -33,6 +34,7 @@
 			$this->registerFieldValidator( "fieldId", new IntegerValidator());
 			$this->_form->registerField( "fieldSearchable" );
 			$this->_form->registerField( "fieldHidden" );
+			$this->_form->registerField( "fieldValues" );
 			$this->setValidationErrorView( new AdminTemplatedView( $this->_blogInfo, "editcustomfield" ));			
         }
 
@@ -47,7 +49,16 @@
 			$this->_fieldDescription = Textfilter::filterAllHTML($this->_request->getValue( "fieldDescription" )); 
 			$this->_fieldType = $this->_request->getValue( "fieldType" );
 			$this->_fieldSearchable = $this->_request->getValue( "fieldSearchable" );
-			$this->_fieldHidden = $this->_request->getValue( "fieldHidden" );			
+			$this->_fieldHidden = $this->_request->getValue( "fieldHidden" );
+			
+			// get and pre-process the field values
+			if( $this->_fieldType == CUSTOM_FIELD_LIST ) {
+				$values = $this->_request->getValue( "fieldValues" );
+				$this->_fieldValues = Array();				
+				foreach( $values as $value ) {
+					$this->_fieldValues[] = Textfilter::filterAllHTML( $value );
+				}
+			}			
 					
 			// and start to update the field
 			$fields = new CustomFields();
@@ -68,6 +79,10 @@
 			$field->setType( $this->_fieldType );
 			$field->setHidden( $this->_fieldHidden );
 			
+			// save the values if this field is a list
+			if( $this->_fieldType == CUSTOM_FIELD_LIST )
+				$field->setFieldValues( $this->_fieldValues );			
+			
 			// fire the pre-event
 			$this->notifyEvent( EVENT_PRE_CUSTOM_FIELD_UPDATE, Array( "field" => &$field ));
 			

Modified: plog/trunk/class/dao/customfields/customfield.class.php
===================================================================
--- plog/trunk/class/dao/customfields/customfield.class.php	2006-09-10 13:13:56 UTC (rev 3952)
+++ plog/trunk/class/dao/customfields/customfield.class.php	2006-09-10 18:09:52 UTC (rev 3953)
@@ -17,6 +17,7 @@
 		var $_searchable;
 		var $_hidden;
 		var $_defaultValue;
+		var $_fieldValues;
 	
 		function CustomField( $name, $description, $type, $blogId, $hidden = false, $searchable = true, $id = -1 )
 		{
@@ -29,6 +30,7 @@
 			$this->_searchable = $searchable;
 			$this->_hidden = $hidden;
 			$this->_defaultValue = "";
+			$this->_fieldValues = Array();
 			
 			$this->_fields = Array(
 				"field_name" => "getName",
@@ -36,7 +38,8 @@
 				"field_description" => "getDescription",
 				"field_type" => "getType",
 				"hidden" => "getHidden",
-				"searchable" => "getSearchable"
+				"searchable" => "getSearchable",
+				"field_values" => "getFieldValues"
 			);
 		}
 		
@@ -131,6 +134,16 @@
 		function getDefaultValue()
 		{
 			return $this->_defaultValue;	
-		}		
+		}
+		
+		function getFieldValues()
+		{
+			return( $this->_fieldValues );
+		}
+		
+		function setFieldValues( $values )
+		{
+			$this->_fieldValues = $values;
+		}
 	}
 ?>

Added: plog/trunk/class/dao/customfields/customfieldlistvalue.class.php
===================================================================
--- plog/trunk/class/dao/customfields/customfieldlistvalue.class.php	2006-09-10 13:13:56 UTC (rev 3952)
+++ plog/trunk/class/dao/customfields/customfieldlistvalue.class.php	2006-09-10 18:09:52 UTC (rev 3953)
@@ -0,0 +1,31 @@
+<?php
+
+	include_once( PLOG_CLASS_PATH."class/dao/customfields/customfieldvalue.class.php" );
+	
+	/**
+	 * offers methods for dealing with custom fields that use drop-down lists that
+	 * allows to select one of the values
+	 *
+	 * \ingroup DAO
+	 */
+	class CustomFieldListValue extends CustomFieldValue
+	{		
+		/**
+		 * constructor
+		 *
+		 * @see CustomFieldValue
+		 */
+		function CustomFieldListValue( $fieldId, $fieldValue, $articleId, $blogId, $id = -1 )
+		{
+			$this->CustomFieldValue( $fieldId, $fieldValue, $articleId, $blogId, $id );
+			$this->setValue( $fieldValue );
+		}
+		
+		function getFieldValues()
+		{
+			$field = $this->getCustomField();
+			return( $this->getFieldValues());
+		}
+	}
+	
+?>

Modified: plog/trunk/class/dao/customfields/customfields.class.php
===================================================================
--- plog/trunk/class/dao/customfields/customfields.class.php	2006-09-10 13:13:56 UTC (rev 3952)
+++ plog/trunk/class/dao/customfields/customfields.class.php	2006-09-10 18:09:52 UTC (rev 3953)
@@ -196,6 +196,11 @@
 									  $row["hidden"],
 									  $row["searchable"],
 									  $row["id"] );
+			// set the field with the possible values, but check first if it can be unserialized before we get an error
+			!isset( $row["field_values"] ) ? $values = Array() : $values = unserialize( $row["field_values"] );
+			
+			
+			$field->setFieldValues( $values );
 									  
 			return $field;
 		}

Modified: plog/trunk/class/dao/customfields/customfieldvaluefactory.class.php
===================================================================
--- plog/trunk/class/dao/customfields/customfieldvaluefactory.class.php	2006-09-10 13:13:56 UTC (rev 3952)
+++ plog/trunk/class/dao/customfields/customfieldvaluefactory.class.php	2006-09-10 18:09:52 UTC (rev 3953)
@@ -4,6 +4,7 @@
 	include_once( PLOG_CLASS_PATH."class/dao/customfields/customfieldvalue.class.php" );
 	include_once( PLOG_CLASS_PATH."class/dao/customfields/customfielddatevalue.class.php" );
 	include_once( PLOG_CLASS_PATH."class/dao/customfields/customfieldcheckboxvalue.class.php" );	
+	include_once( PLOG_CLASS_PATH."class/dao/customfields/customfieldlistvalue.class.php" );	
 		
 	/**
 	 * Generates the right CustomFieldValue (or subclass of it)
@@ -28,7 +29,7 @@
 	        		                           CUSTOM_FIELD_TEXTAREA => "CustomFieldValue",
 											   CUSTOM_FIELD_CHECKBOX => "CustomFieldCheckboxValue",
 											   CUSTOM_FIELD_DATE => "CustomFieldDateValue",
-											   CUSTOM_FIELD_LIST => "CustomFieldValue",
+											   CUSTOM_FIELD_LIST => "CustomFieldListValue",
 											   CUSTOM_FIELD_MULTILIST => "CustomFieldValue",
 											   "default" => "CustomFieldValue" );
 	       
@@ -53,6 +54,7 @@
 			// make things easier for clients of the class! But we can use the array with the
 			// mappins to easily figure out the right$ class for the job
 			$constructor = CustomFieldValueFactory::_findConstructorClass( (int)$row["field_type"] );
+
 			$value = new $constructor( $row["field_id"],
 			                           $row["field_value"],
 									   $row["article_id"],

Modified: plog/trunk/locale/locale_en_UK.php
===================================================================
--- plog/trunk/locale/locale_en_UK.php	2006-09-10 13:13:56 UTC (rev 3952)
+++ plog/trunk/locale/locale_en_UK.php	2006-09-10 18:09:52 UTC (rev 3953)
@@ -1083,4 +1083,7 @@
 //
 $messages['auth'] = 'Auth';
 $messages['authenticated'] = 'Authenticated';
+$messages['dropdown_list_field'] = 'Drop-down list';
+$messages['values'] = 'Field values';
+$messages['field_values'] = 'Values that will be shown as options in this field. The first one will be used as the default option.';
 ?>
\ No newline at end of file

Modified: plog/trunk/templates/admin/customfields.template
===================================================================
--- plog/trunk/templates/admin/customfields.template	2006-09-10 13:13:56 UTC (rev 3952)
+++ plog/trunk/templates/admin/customfields.template	2006-09-10 18:09:52 UTC (rev 3953)
@@ -33,7 +33,8 @@
 				    {if $field->getType() == 1}{$locale->tr("text_field")}{/if}
 					{if $field->getType() == 2}{$locale->tr("text_area")}{/if}
 					{if $field->getType() == 3}{$locale->tr("checkbox")}{/if}
-					{if $field->getType() == 4}{$locale->tr("date_field")}{/if}					
+					{if $field->getType() == 4}{$locale->tr("date_field")}{/if}
+					{if $field->getType() == 5}{$locale->tr("dropdown_list_field")}{/if}					
 				 </td>	
 				 <td>
 				   {if $field->isHidden()}{$locale->tr("yes")}{else}{$locale->tr("No")}{/if}

Modified: plog/trunk/templates/admin/editcustomfield.template
===================================================================
--- plog/trunk/templates/admin/editcustomfield.template	2006-09-10 13:13:56 UTC (rev 3952)
+++ plog/trunk/templates/admin/editcustomfield.template	2006-09-10 18:09:52 UTC (rev 3953)
@@ -1,7 +1,7 @@
 {include file="$admintemplatepath/header.template"}
 {include file="$admintemplatepath/navigation.template" showOpt=blogCustomFields title=$locale->tr("editCustomField")}
 
- <form name="editCustomField" method="post" action="admin.php">
+ <form name="editCustomField" method="post" action="admin.php" onSubmit="listSelectAll('fieldValues');return true">
   <fieldset class="inputField">
    <legend>{$locale->tr("editCustomField")}</legend>
    {include file="$admintemplatepath/formvalidate.template" message=$locale->tr("error_updating_custom_field")} 
@@ -26,13 +26,28 @@
     <label for="fieldType">{$locale->tr("type")}</label>
     <span class="required">*</span>
     <div class="formHelp">{$locale->tr("field_type_help")}</div>
-    <select name="fieldType" id="fieldType">
+    <select name="fieldType" id="fieldType" {literal}onChange="elem=document.getElementById('fieldValuesBlock');if(this.selectedIndex==4){elem.style.display='block';}else{elem.style.display='none';}"{/literal}>
      <option value="1" {if $fieldType == 1}selected="selected"{/if}>{$locale->tr("text_field")}</option>
      <option value="2" {if $fieldType == 2}selected="selected"{/if}>{$locale->tr("text_area")}</option>
      <option value="3" {if $fieldType == 3}selected="selected"{/if}>{$locale->tr("checkbox")}</option>
      <option value="4" {if $fieldType == 4}selected="selected"{/if}>{$locale->tr("date_field")}</option>    
+     <option value="5" {if $fieldType == 5}selected="selected"{/if}>{$locale->tr("dropdown_list_field")}</option>
     </select>   
    </div>
+
+   <div class="field" id="fieldValuesBlock" {if $fieldType != 5}style="display:none"{/if}>
+	<label for="fieldValues">{$locale->tr("values")}</label>
+	<span class="required">*</span>
+	<div class="formHelp">{$locale->tr("field_values")}</div>
+		<select name="fieldValues[]" id="fieldValues" multiple="multiple" style="width:40%" size="5">
+		{foreach from=$fieldValues item=value}
+		  <option value="{$value}">{$value}</option>
+		{/foreach}
+		</select>
+		<br />
+		<input type="button" class="button" {literal}onClick="newValue=window.prompt('Enter new value for the custom field');if(newValue!=null){appendDocumentList(document,'fieldValues',newValue,newValue);}"{/literal} value="{$locale->tr("add")}" />
+		<input type="button" class="button" onClick="removeSelectedItemsFromList(document.getElementById('fieldValues'))" value="{$locale->tr("remove_selected")}" />
+   </div>
      
    <div class="field">
     <label for="fieldHidden">{$locale->tr("hidden")}</label>

Modified: plog/trunk/templates/admin/editpost.template
===================================================================
--- plog/trunk/templates/admin/editpost.template	2006-09-10 13:13:56 UTC (rev 3952)
+++ plog/trunk/templates/admin/editpost.template	2006-09-10 18:09:52 UTC (rev 3953)
@@ -130,6 +130,9 @@
          </select>
         {include file="$admintemplatepath/validate.template" field=globalArticleCategoryId message=$locale->tr("error_no_global_article_category_selected")}	   
        </div>   
+
+	   <!-- list custom fields -->
+	   {include file="$admintemplatepath/newpost_customfields.template" type=5 fields=$customfields}
 	      
        <div class="field_checkbox">
          <input class="checkbox" type="checkbox" id="commentsEnabled" name="commentsEnabled" value="1" {if $postCommentsEnabled} checked="checked" {/if}/>

Modified: plog/trunk/templates/admin/header.template
===================================================================
--- plog/trunk/templates/admin/header.template	2006-09-10 13:13:56 UTC (rev 3952)
+++ plog/trunk/templates/admin/header.template	2006-09-10 18:09:52 UTC (rev 3953)
@@ -27,6 +27,7 @@
 <script type="text/javascript" src="js/cookie/cookie.js"></script>
 <script type="text/javascript" src="js/prototype/prototype.js"></script>
 <script type="text/javascript" src="js/rico/rico.js"></script>
+<script type="text/javascript" src="js/ui/forms.js"></script>
 {if $blogEnablePullDownMenu}
   <script type="text/javascript" src="js/JSCookMenu/JSCookMenu.js"></script>
   <link rel="stylesheet" href="js/JSCookMenu/ThemeOffice/theme.css" type="text/css" />

Modified: plog/trunk/templates/admin/newcustomfield.template
===================================================================
--- plog/trunk/templates/admin/newcustomfield.template	2006-09-10 13:13:56 UTC (rev 3952)
+++ plog/trunk/templates/admin/newcustomfield.template	2006-09-10 18:09:52 UTC (rev 3953)
@@ -1,7 +1,7 @@
 {include file="$admintemplatepath/header.template"}
 {include file="$admintemplatepath/navigation.template" showOpt=newCustomField title=$locale->tr("newCustomField")}
 
- <form name="newCustomField" method="post" action="admin.php">
+ <form name="newCustomField" method="post" action="admin.php" onSubmit="listSelectAll('fieldValues');return true">
   <fieldset class="inputField">
    <legend>{$locale->tr("newCustomField")}</legend>
    {include file="$admintemplatepath/formvalidate.template" message=$locale->tr("error_adding_custom_field")}   
@@ -26,14 +26,29 @@
     <label for="fieldType">{$locale->tr("type")}</label>
     <span class="required">*</span>
     <div class="formHelp">{$locale->tr("field_type_help")}</div>
-    <select name="fieldType" id="fieldType">
+    <select name="fieldType" id="fieldType" {literal}onChange="elem=document.getElementById('fieldValuesBlock');if(this.selectedIndex==4){elem.style.display='block';}else{elem.style.display='none';}"{/literal}>
      <option value="1" {if $fieldType == 1}selected="selected"{/if}>{$locale->tr("text_field")}</option>
      <option value="2" {if $fieldType == 2}selected="selected"{/if}>{$locale->tr("text_area")}</option>
      <option value="3" {if $fieldType == 3}selected="selected"{/if}>{$locale->tr("checkbox")}</option>
      <option value="4" {if $fieldType == 4}selected="selected"{/if}>{$locale->tr("date_field")}</option>    
+	 <option value="5" {if $fieldType == 5}selected="selected"{/if}>{$locale->tr("dropdown_list_field")}</option>
     </select>   
    </div>
-   
+
+   <div class="field" id="fieldValuesBlock" {if $fieldType != 5}style="display:none"{/if}>
+	<label for="fieldValues">{$locale->tr("values")}</label>
+	<span class="required">*</span>
+	<div class="formHelp">{$locale->tr("field_values")}</div>
+		<select name="fieldValues[]" id="fieldValues" multiple="multiple" style="width:40%" size="5">
+		{foreach from=$fieldValues item=value}
+		   <option value="{$value}">{$value}</option>
+		{/foreach}
+		</select>
+		<br />
+		<input type="button" class="button" {literal}onClick="newValue=window.prompt('Enter new value for the custom field');if(newValue!=null){appendDocumentList(document,'fieldValues',newValue,newValue);}"{/literal} value="{$locale->tr("add")}" />
+		<input type="button" class="button" onClick="removeSelectedItemsFromList(document.getElementById('fieldValues'))" value="{$locale->tr("remove_selected")}" />
+   </div>
+
    <div class="field">
     <label for="fieldHidden">{$locale->tr("hidden")}</label>
     <span class="required">*</span>

Modified: plog/trunk/templates/admin/newpost.template
===================================================================
--- plog/trunk/templates/admin/newpost.template	2006-09-10 13:13:56 UTC (rev 3952)
+++ plog/trunk/templates/admin/newpost.template	2006-09-10 18:09:52 UTC (rev 3953)
@@ -153,7 +153,10 @@
 	       {/if}
          </select>
         {include file="$admintemplatepath/validate.template" field=globalArticleCategoryId message=$locale->tr("error_no_global_article_category_selected")}	   
-       </div>	   
+       </div>	  
+
+	   <!-- list custom fields -->
+	   {include file="$admintemplatepath/newpost_customfields.template" type=5 fields=$customfields}
    
        <div class="field_checkbox">
          <input class="checkbox" type="checkbox" id="commentsEnabled" name="commentsEnabled" value="1" {if $commentsEnabled} checked="checked" {/if}/>

Modified: plog/trunk/templates/admin/newpost_customfields.template
===================================================================
--- plog/trunk/templates/admin/newpost_customfields.template	2006-09-10 13:13:56 UTC (rev 3952)
+++ plog/trunk/templates/admin/newpost_customfields.template	2006-09-10 18:09:52 UTC (rev 3953)
@@ -26,5 +26,15 @@
 	      <img src="imgs/admin/cal.jpg" alt="{$locale->tr("pick_date")}" style="border:0px;width: 16px; height: 14px; padding: 0;" />
 	    </a>
 	</div>  
+	{elseif $field->getType() == 5 && ($type == 5 || $type == "")}
+    <div class="field">
+	  <label for="customField[{$fieldId}]">{$field->getName()}</label>
+	  <div class="formHelp">{$field->getDescription()}</div>
+	  <select name="customField[{$fieldId}]" id="customField[{$fieldId}]">
+		{foreach from=$field->getFieldValues() item=value}
+		  <option value="{$value}" {if $customField[$fieldId]==$value}selected="selected"{/if}>{$value}</option>
+		{/foreach}
+	  </select>
+	</div> 	
   {/if}
 {/foreach}
\ No newline at end of file



More information about the pLog-svn mailing list