示例#1
0
 /**
  * Answer a step for all of the the files of the asset
  * 
  * @return object WizardStep
  * @access public
  * @since 10/31/05
  */
 function getRemoteFileRecordsStep()
 {
     $idManager = Services::getService("Id");
     $repository = $this->getRepository();
     $recStructId = $idManager->getId("REMOTE_FILE");
     $recStruct = $repository->getRecordStructure($recStructId);
     $step = new WizardStep();
     $step->setDisplayName($recStruct->getDisplayName());
     ob_start();
     print "\n<h2>" . _("Remote Files") . "</h2>";
     print "\n[[files]]";
     $step->setContent(ob_get_clean());
     $repeatableComponent = $step->addComponent("files", new WRepeatableComponentCollection());
     $repeatableComponent->setStartingNumber(0);
     $repeatableComponent->setAddLabel(_("Add New File"));
     $repeatableComponent->setRemoveLabel(_("Remove File"));
     ob_start();
     $component = $repeatableComponent->addComponent("record_id", new WHiddenField());
     $component = $repeatableComponent->addComponent("file_url", new WTextField());
     $component->setSize(50);
     $vComponent = $repeatableComponent->addComponent("file_name", new WVerifiedChangeInput());
     $vComponent->setChecked(FALSE);
     $component = $vComponent->setInputComponent(new WTextField());
     $vComponent = $repeatableComponent->addComponent("file_size", new WVerifiedChangeInput());
     $vComponent->setChecked(FALSE);
     $component = $vComponent->setInputComponent(new WTextField());
     $vComponent = $repeatableComponent->addComponent("mime_type", new WVerifiedChangeInput());
     $vComponent->setChecked(FALSE);
     $component = $vComponent->setInputComponent(new WTextField());
     // Dimensions
     $dimensionComponent = new WTextField();
     $dimensionComponent->setSize(8);
     $dimensionComponent->setStyle("text-align: right");
     $dimensionComponent->setErrorRule(new WECOptionalRegex("^([0-9]+px)?\$"));
     $dimensionComponent->setErrorText(_("Must be a positive integer followed by 'px'."));
     $dimensionComponent->addOnChange("validateWizard(this.form);");
     $vComponent = $repeatableComponent->addComponent("height", new WVerifiedChangeInput());
     $vComponent->setChecked(FALSE);
     $component = $vComponent->setInputComponent($dimensionComponent->shallowCopy());
     $vComponent = $repeatableComponent->addComponent("width", new WVerifiedChangeInput());
     $vComponent->setChecked(FALSE);
     $component = $vComponent->setInputComponent($dimensionComponent->shallowCopy());
     // Thumnail Upload
     $component = $repeatableComponent->addComponent("thumbnail_upload", new WFileUploadField());
     $vComponent = $repeatableComponent->addComponent("thumbnail_mime_type", new WVerifiedChangeInput());
     $vComponent->setChecked(FALSE);
     $component = $vComponent->setInputComponent(new WTextField());
     // Thumbnail dimensions
     $vComponent = $repeatableComponent->addComponent("thumbnail_height", new WVerifiedChangeInput());
     $vComponent->setChecked(FALSE);
     $component = $vComponent->setInputComponent($dimensionComponent->shallowCopy());
     $vComponent = $repeatableComponent->addComponent("thumbnail_width", new WVerifiedChangeInput());
     $vComponent->setChecked(FALSE);
     $component = $vComponent->setInputComponent($dimensionComponent->shallowCopy());
     print "\n<p>" . _("Url:") . " ";
     print "\n[[file_url]]</p>";
     print "\n<p>";
     print _("By default, the values below will be automatically populated from your uploaded file.");
     print " " . _("If needed, change the properties below to custom values: ");
     print "\n<table border='1'>";
     print "\n<tr>";
     print "\n\t<th>";
     print "\n\t\t" . _("Property") . "";
     print "\n\t</th>";
     print "\n\t<th>";
     print "\n\t\t" . _("Custom Value") . "";
     print "\n\t</th>";
     print "\n</tr>";
     print "\n<tr>";
     print "\n\t<td>";
     print "\n\t\t" . _("File Name") . "";
     print "\n\t</td>";
     print "\n\t<td>";
     print "\n\t\t[[file_name]]";
     print "\n\t</td>";
     print "\n</tr>";
     print "\n<tr>";
     print "\n\t<td>";
     print "\n\t\t" . _("File Size") . "";
     print "\n\t</td>";
     print "\n\t<td>";
     print "\n\t\t[[file_size]]";
     print "\n\t</td>";
     print "\n</tr>";
     print "\n<tr>";
     print "\n\t<td>";
     print "\n\t\t" . _("Mime Type") . "";
     print "\n\t</td>";
     print "\n\t<td>";
     print "\n\t\t[[mime_type]]";
     print "\n\t</td>";
     print "\n</tr>";
     print "\n<tr>";
     print "\n\t<td>";
     print "\n\t\t" . _("Width") . "";
     print "\n\t</td>";
     print "\n\t<td>";
     print "\n\t\t[[width]]";
     print "\n\t</td>";
     print "\n</tr>";
     print "\n<tr>";
     print "\n\t<td>";
     print "\n\t\t" . _("Height") . "";
     print "\n\t</td>";
     print "\n\t<td>";
     print "\n\t\t[[height]]";
     print "\n\t</td>";
     print "\n</tr>";
     print "\n<tr>";
     print "\n\t<td>";
     print "\n\t\t" . _("Thumbnail") . "";
     print "\n\t</td>";
     print "\n\t<td>";
     print "\n[[thumbnail_upload]]";
     print "\n\t</td>";
     print "\n</tr>";
     print "\n<tr>";
     print "\n\t<td>";
     print "\n\t\t" . _("Thumbnail Mime Type") . "";
     print "\n\t</td>";
     print "\n\t<td>";
     print "\n\t\t[[thumbnail_mime_type]]";
     print "\n\t</td>";
     print "\n</tr>";
     print "\n<tr>";
     print "\n\t<td>";
     print "\n\t\t" . _("Thumbnail Width") . "";
     print "\n\t</td>";
     print "\n\t<td>";
     print "\n\t\t[[thumbnail_width]]";
     print "\n\t</td>";
     print "\n</tr>";
     print "\n<tr>";
     print "\n\t<td>";
     print "\n\t\t" . _("Thumbnail Height") . "";
     print "\n\t</td>";
     print "\n\t<td>";
     print "\n\t\t[[thumbnail_height]]";
     print "\n\t</td>";
     print "\n</tr>";
     print "\n</table>";
     print "\n</p>";
     $repeatableComponent->setContent(ob_get_contents());
     ob_end_clean();
     $records = $this->_assets[0]->getRecordsByRecordStructure($recStructId);
     while ($records->hasNext()) {
         $record = $records->next();
         $partIterator = $record->getParts();
         $parts = array();
         while ($partIterator->hasNext()) {
             $part = $partIterator->next();
             $partStructure = $part->getPartStructure();
             $partStructureId = $partStructure->getId();
             $parts[$partStructureId->getIdString()] = $part;
         }
         $collection = array();
         $recordId = $record->getId();
         $collection['record_id'] = $recordId->getIdString();
         $collection['file_url'] = $parts['FILE_URL']->getValue();
         $collection['file_name'] = $parts['FILE_NAME']->getValue();
         $size = ByteSize::withValue($parts['FILE_SIZE']->getValue());
         $collection['file_size'] = $size->asString();
         $collection['mime_type'] = $parts['MIME_TYPE']->getValue();
         $dim = $parts['DIMENSIONS']->getValue();
         if ($dim[1]) {
             $collection['height'] = $dim[1] . 'px';
         }
         if ($dim[0]) {
             $collection['width'] = $dim[0] . 'px';
         }
         $collection['thumbnail_upload'] = array("starting_name" => "thumb.jpg", "starting_size" => strlen($parts['THUMBNAIL_DATA']->getValue()));
         $collection['thumbnail_mime_type'] = $parts['THUMBNAIL_MIME_TYPE']->getValue();
         $thumDim = $parts['THUMBNAIL_DIMENSIONS']->getValue();
         if ($thumDim[1]) {
             $collection['thumbnail_height'] = $thumDim[1] . 'px';
         }
         if ($thumDim[0]) {
             $collection['thumbnail_width'] = $thumDim[0] . 'px';
         }
         $repeatableComponent->addValueCollection($collection);
     }
     return $step;
 }
 /**
  * Sets the value of this Component to the {@link SObject} passed.
  * @param ref object $value The {@link SObject} value to use.
  *
  * @return void
  **/
 function setValue($value)
 {
     ArgumentValidator::validate($value, HasMethodsValidatorRule::getRule("asString"));
     parent::setValue($value->asString());
 }
 /**
  * Sets the value of this Component to the {@link SObject} passed.
  * @param ref object $value The {@link SObject} value to use.
  *
  * @return void
  **/
 function setValue($value)
 {
     parent::setValue($value->asString());
 }
 function WStyleComponent($callBack, $component, $property, $collection)
 {
     $this->_getThemeCallBack = $callBack;
     $this->_collection = $collection;
     $this->_property = $property;
     $this->_component = $component;
     $styleComponent = $this->getStyleComponent();
     $rule = $styleComponent->getRule();
     $regex = $rule->getRegularExpression();
     //$this->setErrorText($styleComponent->getErrorDescription());
     //$this->setErrorRule($styleComponent->getRule());
     //$this->_showError=false;
     if (is_null($styleComponent)) {
         throwError(new Error("The Component this references is based on cannot be null", "WStyleComponent", true));
     }
     if (get_class($styleComponent) == 'colorsc') {
         $input = new WSelectOrNew();
         $input->addOption('', "(not set)");
         $digits = array("0", "4", "8", "C", "F");
         for ($r = 0; $r < count($digits); $r++) {
             for ($g = 0; $g < count($digits); $g++) {
                 for ($b = 0; $b < count($digits); $b++) {
                     $val = '#' . $digits[$r] . $digits[$g] . $digits[$b];
                     $arr = $styleComponent->getRGBArray($val);
                     //num measures the "brightness" of the color.
                     //I think green is "brighter" than red and red "brighter" than blue.
                     $num = $arr[0] * 3 + $arr[1] * 2 + $arr[2];
                     //Our threshold is 750.
                     if ($num > 750) {
                         $col = "000";
                     } else {
                         $col = "#FFF";
                     }
                     $input->addOption($val, $val, "color: " . $col . "; background-color:" . $val . ";");
                 }
             }
         }
         // make sure the current color is a possibility.
         if (!is_null($styleComponent->getValue())) {
             //$input->addOption($styleComponent->getValue(), $styleComponent->getValue(), "color: ".$col."; background-color:".$styleComponent->getValue().";");
             $input->setValue($styleComponent->getValue());
         }
         // 			if ([[colorwheel colors]])
         // generate options for colors
     } else {
         if ($styleComponent->isLimitedToOptions()) {
             $input = new WSelectList();
             $input->addOption('', "(not set)");
             $options = $styleComponent->getOptions();
             foreach ($options as $opt) {
                 $input->addOption($opt, $opt, strtolower(preg_replace("/[^a-zA-Z0-9:_-]/", "-", $styleComponent->getDisplayName())) . ": {$opt};");
             }
             $input->setValue($styleComponent->getValue());
         } else {
             if ($styleComponent->hasOptions()) {
                 $input = new WSelectOrNew();
                 $input->addOption('', "(not set)");
                 $options = $styleComponent->getOptions();
                 foreach ($options as $opt) {
                     $input->addOption($opt, $opt, strtolower(preg_replace("/[^a-zA-Z0-9:_-]/", "-", $styleComponent->getDisplayName())) . ": {$opt};");
                 }
                 $input->setValue($styleComponent->getValue());
             } else {
                 $input = new WTextField();
                 $input->setValue($styleComponent->getValue());
             }
         }
     }
     if (!$styleComponent->isLimitedToOptions()) {
         $input->setErrorRule(new WECRegex($regex));
         $input->setErrorText($styleComponent->getErrorDescription());
     }
     $this->_wizardComponent = $input;
 }
 /**
  * Create wizard steps for editing the values of the specified Record and
  * add them to the wizard.
  * 
  * @param object $record
  * @param object $wizard The wizard to add the steps to.
  * @return void
  * @access public
  * @since 10/19/04
  */
 function createWizardSteps(Record $record, Wizard $wizard)
 {
     $recordStructure = $record->getRecordStructure();
     // Get all the parts
     $partIterator = $record->getParts();
     $parts = array();
     while ($partIterator->hasNext()) {
         $part = $partIterator->next();
         $partStructure = $part->getPartStructure();
         $partStructureId = $partStructure->getId();
         $parts[$partStructureId->getIdString()] = $part;
     }
     $step = $wizard->addStep("record", new WizardStep());
     $step->setDisplayName($recordStructure->getDisplayName());
     ob_start();
     $component = $step->addComponent("file_upload", new WFileUploadField());
     print "\n<em>" . _("Upload a new file or change file properties.") . "</em>\n<hr />";
     print "\n<br /><strong>";
     if ($parts['FILE_NAME']->getValue()) {
         print _("New file (optional)");
     } else {
         print _("File");
     }
     print ":</strong>";
     print "\n[[file_upload]]";
     $component = $step->addComponent("file_name", new WTextField());
     $component->setValue($parts['FILE_NAME']->getValue());
     $component = $step->addComponent("use_custom_filename", new WCheckBox());
     $component->setValue(false);
     $component = $step->addComponent("file_size", new WTextField());
     $size = ByteSize::withValue($parts['FILE_SIZE']->getValue());
     $component->setValue($size->asString());
     $component->setEnabled(FALSE, TRUE);
     //
     // 		$component =$step->addComponent("size_from_file", new WCheckBox());
     // 		$component->setValue(false);
     $component = $step->addComponent("mime_type", new WTextField());
     $component->setValue($parts['MIME_TYPE']->getValue());
     $component = $step->addComponent("use_custom_type", new WCheckBox());
     $component->setValue(false);
     // Dimensions
     $dimensionComponent = new WTextField();
     $dimensionComponent->setSize(8);
     $dimensionComponent->setStyle("text-align: right");
     $dimensionComponent->setErrorRule(new WECRegex("^([0-9]+px)?\$"));
     $dimensionComponent->setErrorText(_("Must be a positive integer followed by 'px'."));
     $dimensionComponent->addOnChange("validateWizard(this.form);");
     $dim = $parts['DIMENSIONS']->getValue();
     $component = $step->addComponent("height", $dimensionComponent->shallowCopy());
     if ($dim[1]) {
         $component->setValue($dim[1] . 'px');
     }
     $component = $step->addComponent("use_custom_height", new WCheckBox());
     $component->setValue(false);
     $component = $step->addComponent("width", $dimensionComponent->shallowCopy());
     if ($dim[0]) {
         $component->setValue($dim[0] . 'px');
     }
     $component = $step->addComponent("use_custom_width", new WCheckBox());
     $component->setValue(false);
     // Thumnail Upload
     $component = $step->addComponent("thumbnail_upload", new WFileUploadField());
     $component = $step->addComponent("thumbnail_mime_type", new WTextField());
     $component->setValue($parts['THUMBNAIL_MIME_TYPE']->getValue());
     $component = $step->addComponent("use_custom_thumbnail_type", new WCheckBox());
     $component->setValue(false);
     // Thumbnail dimensions
     $thumDim = $parts['THUMBNAIL_DIMENSIONS']->getValue();
     $component = $step->addComponent("thumbnail_height", $dimensionComponent->shallowCopy());
     if ($thumDim[1]) {
         $component->setValue($thumDim[1] . 'px');
     }
     $component = $step->addComponent("use_custom_thumbnail_height", new WCheckBox());
     $component->setValue(false);
     $component = $step->addComponent("thumbnail_width", $dimensionComponent->shallowCopy());
     if ($thumDim[0]) {
         $component->setValue($thumDim[0] . 'px');
     }
     $component = $step->addComponent("use_custom_thumbnail_width", new WCheckBox());
     $component->setValue(false);
     print "\n<p>" . _("Change properties of the uploaded file to custom values:");
     print "\n<table border='1'>";
     print "\n<tr>";
     print "\n\t<th>";
     print "\n\t\t" . _("Property") . "";
     print "\n\t</th>";
     print "\n\t<th>";
     print "\n\t\t" . _("Use Custom Value") . "";
     print "\n\t</th>";
     print "\n\t<th>";
     print "\n\t\t" . _("Custom Value") . "";
     print "\n\t</th>";
     print "\n</tr>";
     print "\n<tr>";
     print "\n\t<td>";
     print "\n\t\t" . _("File Name") . "";
     print "\n\t</td>";
     print "\n\t<td align='center'>";
     print "\n\t\t[[use_custom_filename]]";
     print "\n\t</td>";
     print "\n\t<td>";
     print "\n\t\t[[file_name]]";
     print "\n\t</td>";
     print "\n</tr>";
     print "\n<tr>";
     print "\n\t<td>";
     print "\n\t\t" . _("File Size") . "";
     print "\n\t</td>";
     print "\n\t<td align='center'>";
     // 		print "\n\t\t[[size_from_file]]";
     print "\n\t</td>";
     print "\n\t<td>";
     print "\n\t\t[[file_size]]";
     print "\n\t</td>";
     print "\n</tr>";
     print "\n<tr>";
     print "\n\t<td>";
     print "\n\t\t" . _("Mime Type") . "";
     print "\n\t</td>";
     print "\n\t<td align='center'>";
     print "\n\t\t[[use_custom_type]]";
     print "\n\t</td>";
     print "\n\t<td>";
     print "\n\t\t[[mime_type]]";
     print "\n\t</td>";
     print "\n</tr>";
     print "\n<tr>";
     print "\n\t<td>";
     print "\n\t\t" . _("Width") . "";
     print "\n\t</td>";
     print "\n\t<td align='center'>";
     print "\n\t\t[[use_custom_width]]";
     print "\n\t</td>";
     print "\n\t<td>";
     print "\n\t\t[[width]]";
     print "\n\t</td>";
     print "\n</tr>";
     print "\n<tr>";
     print "\n\t<td>";
     print "\n\t\t" . _("Height") . "";
     print "\n\t</td>";
     print "\n\t<td align='center'>";
     print "\n\t\t[[use_custom_height]]";
     print "\n\t</td>";
     print "\n\t<td>";
     print "\n\t\t[[height]]";
     print "\n\t</td>";
     print "\n</tr>";
     print "\n<tr>";
     print "\n\t<td>";
     print "\n\t\t" . _("Thumbnail") . "";
     print "\n\t</td>";
     print "\n\t<td align='center'>";
     print "\n\t\t &nbsp; ";
     print "\n\t</td>";
     print "\n\t<td>";
     print "\n[[thumbnail_upload]]";
     print "\n\t</td>";
     print "\n</tr>";
     print "\n<tr>";
     print "\n\t<td>";
     print "\n\t\t" . _("Thumbnail Mime Type") . "";
     print "\n\t</td>";
     print "\n\t<td align='center'>";
     print "\n\t\t[[use_custom_thumbnail_type]]";
     print "\n\t</td>";
     print "\n\t<td>";
     print "\n\t\t[[thumbnail_mime_type]]";
     print "\n\t</td>";
     print "\n</tr>";
     print "\n<tr>";
     print "\n\t<td>";
     print "\n\t\t" . _("Thumbnail Width") . "";
     print "\n\t</td>";
     print "\n\t<td align='center'>";
     print "\n\t\t[[use_custom_thumbnail_width]]";
     print "\n\t</td>";
     print "\n\t<td>";
     print "\n\t\t[[thumbnail_width]]";
     print "\n\t</td>";
     print "\n</tr>";
     print "\n<tr>";
     print "\n\t<td>";
     print "\n\t\t" . _("Thumbnail Height") . "";
     print "\n\t</td>";
     print "\n\t<td align='center'>";
     print "\n\t\t[[use_custom_thumbnail_height]]";
     print "\n\t</td>";
     print "\n\t<td>";
     print "\n\t\t[[thumbnail_height]]";
     print "\n\t</td>";
     print "\n</tr>";
     print "\n</table>";
     print "\n</p>";
     $step->setContent(ob_get_contents());
     ob_end_clean();
 }