Ejemplo n.º 1
0
 /**
  * The constructor.
  * @access public
  * @param string content This is an arbitrary string that will be printed,
  * whenever the user calls the <code>render()</code> method. If <code>null</code>,
  * then the component will have no content.
  * @param integer type The type of this component. One of BLANK, HEADING, HEADER, FOOTER,
  * BLOCK, MENU, MENU_ITEM_LINK_UNSELECTED, MENU_ITEM_LINK_SELECTED, MENU_ITEM_HEADING, OTHER.
  * @param integer index The index of this component. The index has no semantic meaning: 
  * you can think of the index as 'level' of the component. Alternatively, 
  * the index could serve as means of distinguishing between components with 
  * the same type. Most often one would use the index in conjunction with
  * the <code>getStylesForComponentType()</code> and 
  * <code>addStyleForComponentType()</code> methods.
  * @param optional object StyleCollections styles,... Zero, one, or more StyleCollection 
  * objects that will be added to the newly created Component. Warning, this will
  * result in copying the objects instead of referencing them as using
  * <code>addStyle()</code> would do.
  **/
 function Component($content, $type, $index)
 {
     // ** parameter validation
     $rule = OptionalRule::getRule(StringValidatorRule::getRule());
     ArgumentValidator::validate($content, $rule, true);
     $rule = ChoiceValidatorRule::getRule(BLANK, HEADING, HEADER, FOOTER, BLOCK, MENU, SUB_MENU, MENU_ITEM_LINK_UNSELECTED, MENU_ITEM_LINK_SELECTED, MENU_ITEM_HEADING, OTHER);
     ArgumentValidator::validate($type, $rule, true);
     ArgumentValidator::validate($index, IntegerValidatorRule::getRule(), true);
     // ** end of parameter validation
     $this->_content = $content;
     $this->_styleCollections = array();
     $this->_type = $type;
     $this->_index = $index;
     // if there are style collections to add
     if (func_num_args() > 3) {
         for ($i = 3; $i < func_num_args(); $i++) {
             $this->addStyle(func_get_arg($i));
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Set the direction of component rendering from the default of Left-Right/Top-Bottom.
  * Allowed values:
  *		Left-Right/Top-Bottom
  *		Top-Bottom/Left-Right
  * 		Right-Left/Top-Bottom
  *		Top-Bottom/Right-Left
  *		Left-Right/Bottom-Top
  *		Bottom-Top/Left-Right
  *		Right-Left/Bottom-Top
  *		Bottom-Top/Right-Left
  * 
  * @param string $direction
  * @return void
  * @access public
  * @since 8/18/06
  */
 function setRenderDirection($direction)
 {
     ArgumentValidator::validate($direction, ChoiceValidatorRule::getRule('Left-Right/Top-Bottom', 'Top-Bottom/Left-Right', 'Right-Left/Top-Bottom', 'Top-Bottom/Right-Left', 'Left-Right/Bottom-Top', 'Bottom-Top/Left-Right', 'Right-Left/Bottom-Top', 'Bottom-Top/Right-Left'));
     $this->_renderDirection = $direction;
 }
 /**
  * Add a new field to the matrix. Each field can be set to one of the options. 
  *
  * The final parameter allows you to set how the value of this field must
  * relate to the field prior to it. If null, then no relation is enforced. Valid options
  * for this parameter are:
  *		null
  *		'<'
  *		'<='
  *		'=='
  *		'>='
  *		'>'
  *
  * When an field is changed, all other fields will attempt to move and respect
  * the rules set. If the rules cannot be met, then the field change is reverted.
  * 
  * @param string $parentKey
  * @param string $key
  * @param string $displayText
  * @param optional mixed $initialValue null or an option value.
  * @param optional mixed $rule One of null, '<', '<=', '==', '>=', '>'.
  * @return object RadioMatrixField
  * @access public
  * @since 11/1/07
  */
 public function addChildField($parentKey, $key, $displayText, $initialValue = null, $rule = null)
 {
     ArgumentValidator::validate($parentKey, NonZeroLengthStringValidatorRule::getRule());
     ArgumentValidator::validate($key, NonZeroLengthStringValidatorRule::getRule());
     ArgumentValidator::validate($displayText, NonZeroLengthStringValidatorRule::getRule());
     if (!is_null($initialValue)) {
         ArgumentValidator::validate($initialValue, NonZeroLengthStringValidatorRule::getRule());
     }
     if (!is_null($rule)) {
         ArgumentValidator::validate($rule, ChoiceValidatorRule::getRule('<', '<=', '==', '>=', '>'));
     }
     parent::addField($key, $displayText, $initialValue, null);
     $field = $this->fields[count($this->fields) - 1];
     $field->rule = $rule;
     $this->fields[$this->getFieldIndex($parentKey)]->addChild($field);
     try {
         $this->validateState();
     } catch (RuleValidationFailedException $e) {
         throw new RuleValidationFailedException("Default state does not validate against the rules supplied. Please change either the default values of the fields or the rules in order to have a valid initial state.");
     }
     return $field;
 }
 /**
  * Log an event. Plugins should log events that involve data modification
  * with type 'Event_Notice' and events that involve errors with type 'Error'
  * 
  * @param string $category
  * @param string $description
  * @param optional string $type
  * @return void
  * @access public
  * @since 3/6/06
  */
 public final function logEvent($category, $description, $type = 'Event_Notice')
 {
     ArgumentValidator::validate($category, StringValidatorRule::getRule());
     ArgumentValidator::validate($description, StringValidatorRule::getRule());
     ArgumentValidator::validate($type, ChoiceValidatorRule::getRule('Event_Notice', 'Error'));
     if (Services::serviceRunning("Logging")) {
         $loggingManager = Services::getService("Logging");
         $log = $loggingManager->getLogForWriting("Segue");
         $formatType = new Type("logging", "edu.middlebury", "AgentsAndNodes", "A format in which the acting Agent[s] and the target nodes affected are specified.");
         $priorityType = new Type("logging", "edu.middlebury", $type, "Normal events.");
         $item = new AgentNodeEntryItem($category, $description);
         $item->addNodeId($this->_asset->getId());
         // Get the site Id (Note: this creates a circular dependancy between
         // the plugins package and the SiteDisplay Package.
         try {
             $idManager = Services::getService("Id");
             $director = SiteDispatcher::getSiteDirector();
             $relatedComponent = $this->getRelatedSiteComponent();
             $rootSiteComponent = $director->getRootSiteComponent($relatedComponent->getId());
             $item->addNodeId($idManager->getId($rootSiteComponent->getId()));
             $log->appendLogWithTypes($item, $formatType, $priorityType);
         } catch (OperationFailedException $e) {
         }
     }
 }
Ejemplo n.º 5
0
 /**
  * Returns the HTML string that needs to be printed after successful rendering
  * of components of the given type and index. Note: use of the PreHTML
  * and PostHTML get/set methods is discouraged - use styles instead: see 
  * <code>addStyleForComponentType()</code> and <code>getStylesForComponentType()</code>.
  * @access public
  * @param integer type The type of the component. One of BLANK, HEADING, HEADER, FOOTER,
  * BLOCK, MENU, MENU_ITEM_LINK_UNSELECTED, MENU_ITEM_LINK_SELECTED, MENU_ITEM_HEADING, OTHER.
  * @param integer index The index that will determine which HTML string to return
  * If the given index is greater than the maximal registered index
  * for the given component type, then the highest index availible will be used.
  * @return string The HTML string.
  **/
 function getPostHTMLForComponentType($type, $index)
 {
     // ** parameter validation
     $rule = ChoiceValidatorRule::getRule(BLANK, HEADING, HEADER, FOOTER, BLOCK, MENU, SUB_MENU, MENU_ITEM_LINK_UNSELECTED, MENU_ITEM_LINK_SELECTED, MENU_ITEM_HEADING, OTHER);
     ArgumentValidator::validate($type, $rule, true);
     ArgumentValidator::validate($index, IntegerValidatorRule::getRule(), true);
     // ** end of parameter validation
     // Frst of all, see if there are any registered HTML strings for this
     // component type at all.
     if (!isset($this->_componentPostHTML[$type])) {
         return "";
     }
     // Now, we know there is at least one HTML string for this
     // component type. See, if there are any for the given index.
     if (isset($this->_componentPostHTML[$type][$index])) {
         return $this->_componentPostHTML[$type][$index];
     }
     // If not, then see if there are any HTML strings for smaller indices.
     // To do so, sort the indices in a reversed order and find the first
     // index that is smaller than the given one.
     $keys = array_keys($this->_componentPostHTML[$type]);
     rsort($keys, SORT_NUMERIC);
     for ($i = 0; $i < count($keys); $i++) {
         if ($keys[$i] < $index) {
             return $this->_componentPostHTML[$type][$keys[$i]];
         }
     }
     // nothing has been found
     return "";
 }
Ejemplo n.º 6
0
 /**
  * Resolve a type and index into one of our component types
  * 
  * @param int $type
  * @param int $index
  * @return string
  * @access protected
  * @since 5/6/08
  */
 protected function resolveType($type, $index)
 {
     // ** parameter validation
     $rule = ChoiceValidatorRule::getRule(BLANK, HEADING, HEADER, FOOTER, BLOCK, MENU, SUB_MENU, MENU_ITEM_LINK_UNSELECTED, MENU_ITEM_LINK_SELECTED, MENU_ITEM_HEADING, OTHER);
     ArgumentValidator::validate($type, $rule, true);
     ArgumentValidator::validate($index, IntegerValidatorRule::getRule(), true);
     switch ($type) {
         case BLANK:
         case OTHER:
             return 'Blank';
         case BLOCK:
             switch ($index) {
                 case BACKGROUND_BLOCK:
                     return 'Block_Background';
                 case STANDARD_BLOCK:
                 case WIZARD_BLOCK:
                 case EMPHASIZED_BLOCK:
                     return 'Block_Standard';
                 case SIDEBAR_BLOCK:
                     return 'Block_Sidebar';
                 default:
                     return 'Block_Alert';
             }
         case MENU:
             switch ($index) {
                 case MENU_LEFT:
                     return 'Menu_Left';
                 case MENU_RIGHT:
                     return 'Menu_Right';
                 case MENU_TOP:
                     return 'Menu_Top';
                 default:
                     return 'Menu_Bottom';
             }
         case SUB_MENU:
             return 'Menu_Sub';
         case MENU_ITEM_LINK_UNSELECTED:
             return 'MenuItem_Link_Unselected';
         case MENU_ITEM_LINK_SELECTED:
             return 'MenuItem_Link_Selected';
         case MENU_ITEM_HEADING:
             return 'MenuItem_Heading';
         case HEADING:
             switch ($index) {
                 case 1:
                     return 'Heading_1';
                 case 2:
                     return 'Heading_2';
                 case 4:
                     return 'Heading_Sidebar';
                 default:
                     return 'Heading_3';
             }
         case HEADER:
             return 'Header';
         case FOOTER:
             return 'Footer';
         default:
             throw new InvalidArgumentException("Usuported type, {$type}.");
     }
 }
Ejemplo n.º 7
0
 /**
  * Add a new field to the matrix. Each field can be set to one of the options. 
  *
  * The final parameter allows you to set how the value of this field must
  * relate to the field prior to it. If null, then no relation is enforced. Valid options
  * for this parameter are:
  *		null
  *		'<'
  *		'<='
  *		'=='
  *		'>='
  *		'>'
  *
  * When an field is changed, all other fields will attempt to move and respect
  * the rules set. If the rules cannot be met, then the field change is reverted.
  * 
  * @param string $key
  * @param string $displayText
  * @param optional mixed $initialValue null or an option value.
  * @param optional mixed $rule One of null, '<', '<=', '==', '>=', '>'.
  * @return object RadioMatrixField
  * @access public
  * @since 11/1/07
  */
 public function addField($key, $displayText, $initialValue = null, $rule = null)
 {
     ArgumentValidator::validate($key, NonZeroLengthStringValidatorRule::getRule());
     ArgumentValidator::validate($displayText, NonZeroLengthStringValidatorRule::getRule());
     if (!is_null($initialValue)) {
         ArgumentValidator::validate($initialValue, NonZeroLengthStringValidatorRule::getRule());
     }
     if (!is_null($rule)) {
         ArgumentValidator::validate($rule, ChoiceValidatorRule::getRule('<', '<=', '==', '>=', '>'));
     }
     $field = $this->createField();
     $field->key = $key;
     $field->displayText = $displayText;
     if (is_null($initialValue)) {
         $field->value = 0;
     } else {
         $field->value = $this->getOptionNumber($initialValue);
     }
     $field->rule = $rule;
     $field->spacerBefore = false;
     $field->spacerAfter = false;
     $field->disabledOptions = array();
     $field->index = count($this->fields);
     $this->fields[] = $field;
     try {
         $this->validateState();
     } catch (RuleValidationFailedException $e) {
         throw new RuleValidationFailedException("Default state does not validate against the rules supplied. Please change either the default values of the fields or the rules in order to have a valid initial state.");
     }
     return $field;
 }