/** * Attach object to specific page and redirects to specified page * * @access public * @param void * @return null */ function add_attachment() { $project = active_project(); if (!$project instanceof Project) { flash_error(lang('project dnx')); $this->redirectToReferer(get_url('dashboard')); } // if if (!$project->canEdit(logged_user())) { flash_error(lang('no access permissions')); $this->redirectToReferer(get_url('dashboard')); } // if $page_attachment = new PageAttachment(); $page_attachment->setText(lang('description')); $page_attachment->setRelObjectId('0'); $page_attachment->setRelObjectManager(array_var($_GET, 'rel_object_manager')); $page_attachment->setProjectId($project->getId()); $page_attachment->setPageName(array_var($_GET, 'page_name')); $page_attachment->setOrder(array_var($_GET, 'order')); $page_attachment->save(); PageAttachments::reorder(array_var($_GET, 'page_name'), $project); $this->redirectToReferer(get_url('dashboard')); }
/** * Delete specific object and associated objects * * @param void * @return boolean */ function delete() { PageAttachments::clearAttachmentsByObject($this); return parent::delete(); }
/** * Return manager instance * * @access protected * @param void * @return PageAttachments */ function manager() { if (!$this->manager instanceof PageAttachments) { $this->manager = PageAttachments::instance(); } return $this->manager; }
/** * Renumbers the order of the attachments * * @param string $page_name * @param Project $project * @return void */ function reorder($page_name, Project $project) { $page_attachments = PageAttachments::getAttachmentsByPageNameAndProject($page_name, $project); $order = 0; if (is_array($page_attachments) && count($page_attachments)) { foreach ($page_attachments as $page_attachment) { $order++; $page_attachment->setOrder($order); $page_attachment->save(); } // foreach } // if }
/** * This function will return all page attachments in project * * @param void * @return array */ function getAllPageAttachments() { if (is_null($this->all_page_attachments)) { $this->all_page_attachments = PageAttachments::getAllByProject($this); } return $this->all_page_attachments; }
/** * Remove contact from project * * @param void * @return null */ function remove_contact() { if (!active_project()->canChangePermissions(logged_user())) { flash_error(lang('no access permissions')); $this->redirectToReferer(active_project()->getOverviewUrl()); } // if $rel_object_manager = array_var($_GET, 'rel_object_manager', 'Contacts'); $rel_object_id = array_var($_GET, 'rel_object_id'); $contact = Contacts::findById($rel_object_id); if (!$contact instanceof Contact) { flash_error(lang('contact dnx')); $this->redirectTo('project', 'people'); } // if $project_id = array_var($_GET, 'project_id', active_project()); $project = Projects::findById(get_id('project_id')); if (!$project instanceof Project) { flash_error(lang('project dnx')); $this->redirectTo('project', 'people'); } // if $page_attachments = PageAttachments::getAttachmentsByManagerIdAndProject($rel_object_manager, $rel_object_id, $project_id); foreach ($page_attachments as $page_attachment) { try { $page_attachment->delete(); flash_success(lang('success remove contact from project')); } catch (Exception $e) { flash_error(lang('error remove contact from project')); } // try } // foreach $this->redirectTo('project', 'people'); }
/** * 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 arguments (@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, 'PageAttachments')) { return parent::paginate($arguments, $items_per_page, $current_page); } else { return PageAttachments::instance()->paginate($arguments, $items_per_page, $current_page); //$instance =& PageAttachments::instance(); //return $instance->paginate($arguments, $items_per_page, $current_page); } // if }