/**
  * Return manager instance
  *
  * @access protected
  * @param void
  * @return AttachedFiles 
  */
 function manager()
 {
     if (!$this->manager instanceof AttachedFiles) {
         $this->manager = AttachedFiles::instance();
     }
     return $this->manager;
 }
 /**
  * Detach file from related object
  *
  * @param void
  * @return null
  */
 function detach_from_object()
 {
     $manager_class = array_var($_GET, 'manager');
     $object_id = get_id('object_id');
     $file_id = get_id('file_id');
     $object = get_object_by_manager_and_id($object_id, $manager_class);
     if (!$object instanceof ProjectDataObject) {
         flash_error(lang('no access permissions'));
         $this->redirectToReferer(get_url('dashboard'));
     }
     // if
     $file = ProjectFiles::findById($file_id);
     if (!$file instanceof ProjectFile) {
         flash_error(lang('file dnx'));
         $this->redirectToReferer(get_url('dashboard'));
     }
     // if
     $attached_file = AttachedFiles::findById(array('rel_object_manager' => $manager_class, 'rel_object_id' => $object_id, 'file_id' => $file_id));
     // findById
     if (!$attached_file instanceof AttachedFile) {
         flash_error(lang('file not attached to object'));
         $this->redirectToReferer(get_url('dashboard'));
     }
     // if
     try {
         DB::beginWork();
         $attached_file->delete();
         DB::commit();
         flash_success(lang('success detach file'));
     } catch (Exception $e) {
         flash_error(lang('error detach file'));
         DB::rollback();
     }
     // try
     $this->redirectToReferer($object->getObjectUrl());
 }
 /**
  * Drop all relations with files for this object
  *
  * @param void
  * @return null
  */
 function clearAttachedFiles()
 {
     return AttachedFiles::clearRelationsByObject($this);
 }
示例#4
0
 /**
  * Remove all object relations from the database
  *
  * @param void
  * @return boolean
  */
 function clearObjectRelations()
 {
     return AttachedFiles::clearRelationsByFile($this);
 }
 /**
  * This function will return paginated result. Result is an array where first element is 
  * array of returned object and second populated pagination object that can be used for 
  * obtaining and rendering pagination data using various helpers.
  * 
  * Items and pagination array vars are indexed with 0 for items and 1 for pagination
  * because you can't use associative indexing with list() construct
  *
  * @access public
  * @param array $arguments Query argumens (@see find()) Limit and offset are ignored!
  * @param integer $items_per_page Number of items per page
  * @param integer $current_page Current page number
  * @return array
  */
 function paginate($arguments = null, $items_per_page = 10, $current_page = 1)
 {
     if (isset($this) && instance_of($this, 'AttachedFiles')) {
         return parent::paginate($arguments, $items_per_page, $current_page);
     } else {
         return AttachedFiles::instance()->paginate($arguments, $items_per_page, $current_page);
         //$instance =& AttachedFiles::instance();
         //return $instance->paginate($arguments, $items_per_page, $current_page);
     }
     // if
 }