public function execute($request) { $this->form = new sfForm(); $this->resource = $this->getRoute()->resource; // Check that object exists and that it is not the root if (!isset($this->resource) || !isset($this->resource->parent)) { $this->forward404(); } // Check user authorization if (!QubitAcl::check($this->resource, 'update')) { QubitAcl::forwardUnauthorized(); } // Add javascript libraries $this->response->addJavaScript('/vendor/yui/logger/logger', 'last'); $this->response->addJavaScript('/vendor/yui/uploader/uploader-min', 'last'); $this->response->addJavaScript('multiFileUpload', 'last'); // Get max upload size limits $this->maxUploadSize = QubitDigitalObject::getMaxUploadSize(); // Paths for uploader javascript $this->uploadSwfPath = "{$this->request->getRelativeUrlRoot()}/vendor/yui/uploader/assets/uploader.swf"; $this->uploadResponsePath = "{$this->context->routing->generate(null, array('module' => 'digitalobject', 'action' => 'upload'))}?" . http_build_query(array(session_name() => session_id())); $this->uploadTmpDir = "{$this->request->getRelativeUrlRoot()}/uploads/tmp"; // Build form $this->form->setValidator('files', new QubitValidatorCountable(array('required' => true))); $this->form->setValidator('title', new sfValidatorString()); $this->form->setWidget('title', new sfWidgetFormInput()); $this->form->setDefault('title', 'image %dd%'); $this->form->setValidator('levelOfDescription', new sfValidatorString()); $choices = array(); $choices[null] = null; foreach (QubitTaxonomy::getTermsById(QubitTaxonomy::LEVEL_OF_DESCRIPTION_ID) as $item) { $choices[$this->context->routing->generate(null, array($item, 'module' => 'term'))] = $item; } $this->form->setWidget('levelOfDescription', new sfWidgetFormSelect(array('choices' => $choices))); if ($request->isMethod('post')) { $this->form->bind($request->getPostParameters(), $request->getFiles()); if ($this->form->isValid()) { $this->processForm(); } } }
public function execute($request) { $this->version = '1.3'; $this->verbose = 'false'; $this->noOp = 'false'; $this->maxUploadSize = QubitDigitalObject::getMaxUploadSize() / 1024; // From bytes to kilobytes $this->mediation = 'false'; // Should be based in auth + X-On-Behalf-Of if (isset($request->getAttribute('sf_route')->resource)) { $this->resource = $this->getRoute()->resource; $this->title = $this->resource->__toString(); $this->workspaces = $this->resource->getChildren(); } else { $this->title = sfConfig::get('app_siteTitle'); $criteria = new Criteria(); $criteria->add(QubitInformationObject::PARENT_ID, QubitInformationObject::ROOT_ID, Criteria::IN); $criteria = QubitAcl::addFilterDraftsCriteria($criteria); $this->workspaces = QubitInformationObject::get($criteria); } $this->response->setHttpHeader('Content-Type', 'application/atom+xml; charset="utf-8"'); $request->setRequestFormat('xml'); }
protected function addFormFields() { // Media type field $choices = array(); $criteria = new Criteria(); $criteria->add(QubitTerm::TAXONOMY_ID, QubitTaxonomy::MEDIA_TYPE_ID); foreach (QubitTerm::get($criteria) as $item) { $choices[$item->id] = $item->getName(array('cultureFallback' => true)); } asort($choices); // Sort media types by name $this->form->setValidator('mediaType', new sfValidatorChoice(array('choices' => array_keys($choices)))); $this->form->setWidget('mediaType', new sfWidgetFormSelect(array('choices' => $choices))); $this->form->setDefault('mediaType', $this->resource->mediaTypeId); // Only display "compound digital object" toggle if we have a child with a // digital object $this->showCompoundObjectToggle = false; foreach ($this->informationObject->getChildren() as $item) { if (null !== $item->getDigitalObject()) { $this->showCompoundObjectToggle = true; break; } } if ($this->showCompoundObjectToggle) { $this->form->setValidator('displayAsCompound', new sfValidatorBoolean()); $this->form->setWidget('displayAsCompound', new sfWidgetFormSelectRadio(array('choices' => array('1' => $this->context->i18n->__('Yes'), '0' => $this->context->i18n->__('No'))))); // Set "displayAsCompound" value from QubitProperty $criteria = new Criteria(); $criteria->add(QubitProperty::OBJECT_ID, $this->resource->id); $criteria->add(QubitProperty::NAME, 'displayAsCompound'); if (null != ($compoundProperty = QubitProperty::getOne($criteria))) { $this->form->setDefault('displayAsCompound', $compoundProperty->getValue(array('sourceCulture' => true))); } } // Add rights component $this->rightEditComponent = new RightEditComponent($this->context, 'right', 'edit'); $this->rightEditComponent->resource = $this->resource; $this->rightEditComponent->execute($this->request); $maxUploadSize = QubitDigitalObject::getMaxUploadSize(); ProjectConfiguration::getActive()->loadHelpers('Qubit'); // If reference representation doesn't exist, include upload widget foreach ($this->representations as $usageId => $representation) { if (null === $representation) { $repName = "repFile_{$usageId}"; $derName = "generateDerivative_{$usageId}"; $this->form->setValidator($repName, new sfValidatorFile()); $this->form->setWidget($repName, new sfWidgetFormInputFile()); if (-1 < $maxUploadSize) { $this->form->getWidgetSchema()->{$repName}->setHelp($this->context->i18n->__('Max. size ~%1%', array('%1%' => hr_filesize($maxUploadSize)))); } else { $this->form->getWidgetSchema()->{$repName}->setHelp(''); } // Add "auto-generate" checkbox $this->form->setValidator($derName, new sfValidatorBoolean()); $this->form->setWidget($derName, new sfWidgetFormInputCheckbox(array(), array('value' => 1))); } else { $this["rightEditComponent_{$usageId}"] = new RightEditComponent($this->context, 'right', 'edit'); $this["rightEditComponent_{$usageId}"]->resource = $representation; $this["rightEditComponent_{$usageId}"]->nameFormat = 'editRight' . $usageId . '[%s]'; $this["rightEditComponent_{$usageId}"]->execute($this->request); } } }