コード例 #1
0
ファイル: Project.php プロジェクト: baldasso/mapasculturais
 function register(Agent $agent, File $registrationForm = null)
 {
     $app = App::i();
     $app->applyHookBoundTo($this, 'project.register:before', array($agent, $registrationForm));
     if (!$this->isRegistrationOpen()) {
         throw new \MapasCulturais\Exceptions\PermissionDenied(App::i()->user, $this, 'register');
     }
     $group = $app->projectRegistrationAgentRelationGroupName;
     $relation_class = $this->getAgentRelationEntityClassName();
     if ($this->isRegistered($agent)) {
         return $app->txt("This agent is already registered in this project.");
     }
     $relation = new $relation_class();
     $relation->agent = $agent;
     $relation->owner = $this;
     $relation->group = $group;
     $relation->status = ProjectAgentRelation::STATUS_REGISTRATION;
     $relation->save();
     if ($registrationForm) {
         $registrationForm->owner = $relation;
         $registrationForm->save();
     }
     $app->em->flush();
     $this->clearAgentRelationCache();
     $app->applyHookBoundTo($this, 'project.register:after', array($relation));
     return $relation;
 }
コード例 #2
0
ファイル: File.php プロジェクト: baldasso/mapasculturais
 /**
  * Returns a transformed image.
  *
  * @param string $wideimage_operations
  *
  * @example $image->transform('resize(200, 100)->crop(50, 50, 30, 20)->rotate(20)')
  *
  * @return File
  */
 protected function _transform($transformation_name, $wideimage_operations)
 {
     if (!trim($wideimage_operations)) {
         return $this;
     }
     $wideimage_operations = strtolower(str_replace(' ', '', $wideimage_operations));
     $hash = md5($this->md5 . $this->name . $wideimage_operations);
     // modify the filename adding the hash before the file extension. ex: file.png => file-5762a89ee8e05021006d6c35095903b5.png
     $image_name = preg_replace("#(\\.[[:alnum:]]+)\$#i", '-' . $hash . '$1', $this->name);
     if (key_exists($transformation_name, $this->files)) {
         return $this->files[$transformation_name];
     }
     if (!file_exists($this->getPath())) {
         return $this;
     }
     $new_image = \WideImage\WideImage::load($this->getPath());
     eval('$new_image = $new_image->' . $wideimage_operations . ';');
     $tmp_filename = sys_get_temp_dir() . '/' . $image_name;
     $new_image->saveToFile($tmp_filename);
     $image = new File(array('error' => UPLOAD_ERR_OK, 'name' => $image_name, 'type' => $this->mimeType, 'tmp_name' => $tmp_filename, 'size' => filesize($tmp_filename)));
     $image->group = $transformation_name;
     $image->setOwner($this);
     $image->save(true);
     return $image;
 }