public function render($content)
 {
     $element = $this->getElement();
     // apply this decorator to Managedfile elements only.
     if (!$element instanceof Project_Form_Element_Managedfile) {
         return $content;
     }
     $view = $element->getView();
     if (!$view instanceof Zend_View_Interface) {
         // do nothing if no view is present.
         return $content;
     }
     // element's FQN
     $name = $element->getFullyQualifiedName();
     $fid = $element->getValue();
     $filepath = null !== $fid && is_int($fid) ? Managedfile::getManagedFilepath($fid) : '';
     $attribs = $element->getAttribs();
     $markup = $view->formText($name, $filepath, $attribs);
     $separator = $this->getSeparator();
     switch ($this->getPlacement()) {
         case self::PREPEND:
             $ret = $markup . $separator . $content;
             break;
         case self::APPEND:
         default:
             $ret = $content . $separator . $markup;
             break;
     }
     return $ret;
 }
 public function setValue($value)
 {
     if (null === $value || '' === $value) {
         $this->_fid = null;
         $this->_filepath = '';
         $value = null;
     } elseif (is_numeric($value)) {
         $this->_fid = (int) $value;
         $this->_filepath = Managedfile::getManagedFilepath($this->_fid);
     } elseif (is_string($value)) {
         $this->_filepath = (string) $value;
         $this->_fid = Managedfile::getManagedFid($this->_filepath, true);
     }
 }
 /**
  * Create a new record in the Managedfile table or return an existing one.
  * If $verifypath == TRUE, a new record will be created only if the file exists.
  *
  * @param string $path      Relative path offset from the www/ folder
  * @param boolean $verifypath
  * @return NULL|Managedfile
  */
 public static function createManagedfileRow($path, $verifypath = false)
 {
     $create = true;
     if ($verifypath) {
         $fullpath = Curry_Core::$config->curry->wwwPath . DIRECTORY_SEPARATOR . $path;
         $create = file_exists($fullpath);
     }
     $managedfile = null;
     if ($create) {
         $entityType = self::getEntityType($path);
         if ($entityType === self::ENTITY_TYPE_DIR) {
             $path .= DIRECTORY_SEPARATOR;
         }
         // check whether the record exists in the Managedfile table.
         $managedfile = ManagedfileQuery::create()->findOneByFilepath($path);
         if ($managedfile) {
             return $managedfile;
         }
         $mime = self::getMimeType($path);
         $managedfile = new Managedfile();
         $managedfile->setFilepath($path)->setType($entityType)->setFilemime($mime)->setOwner(User::getUser())->save();
     }
     return $managedfile;
 }
Example #4
0
 protected function handleAdd(array $values)
 {
     $tableName = $values['table_name'];
     $colName = $values['column_name'];
     $tableMap = PropelQuery::from($tableName)->getTableMap();
     $colMap = $tableMap->getColumn($colName);
     $fidColMap = $tableMap->getColumn("{$colName}_fid");
     $rows = PropelQuery::from($tableName)->where("{$tableMap->getPhpName()}.{$colMap->getPhpName()} IS NOT NULL")->_or()->filterBy($colMap->getPhpName(), '', Criteria::NOT_EQUAL)->find();
     $nbCreated = 0;
     foreach ($rows as $row) {
         $filePath = $row->{'get' . $colMap->getPhpName()}();
         $managedfile = ManagedfileQuery::create()->filterByFilepath($filePath)->findOneOrCreate();
         if ($managedfile->isNew()) {
             $fullpath = Curry_Core::$config->curry->wwwPath . DIRECTORY_SEPARATOR . $filePath;
             $deleted = !file_exists($fullpath);
             $managedfile->setFilemime(Managedfile::getMimeType($filePath))->setDeleted($deleted)->save();
             ++$nbCreated;
         }
         // update fid column
         $currentFid = $row->{'get' . $fidColMap->getPhpName()}();
         $realFid = $managedfile->getFid();
         if ($currentFid != $realFid) {
             $row->{'set' . $fidColMap->getPhpName()}($realFid)->save();
         }
     }
     $this->addMessage("Created {$nbCreated} new records in the Managedfile table.");
 }