Exemplo n.º 1
0
 function getWorkspaces()
 {
     if ($this->isNew()) {
         return array();
     }
     return WorkspaceTemplates::getWorkspacesByTemplate($this->getId());
 }
 function assign_to_ws()
 {
     if (!can_manage_templates(logged_user())) {
         flash_error(lang("no access permissions"));
         ajx_current("empty");
         return;
     }
     $template_id = get_id();
     $cotemplate = COTemplates::findById($template_id);
     if (!$cotemplate instanceof COTemplate) {
         flash_error(lang("template dnx"));
         ajx_current("empty");
         return;
     }
     $selected = WorkspaceTemplates::getWorkspacesByTemplate($template_id);
     tpl_assign('workspaces', logged_user()->getWorkspaces());
     tpl_assign('selected', $selected);
     tpl_assign('cotemplate', $cotemplate);
     $checked = array_var($_POST, 'ws_ids');
     if ($checked != null) {
         try {
             DB::beginWork();
             WorkspaceTemplates::deleteByTemplate($template_id);
             $wss = Projects::findByCSVIds($checked);
             foreach ($wss as $ws) {
                 $obj = new WorkspaceTemplate();
                 $obj->setWorkspaceId($ws->getId());
                 $obj->setTemplateId($template_id);
                 $obj->setInludeSubWs(false);
                 $obj->save();
             }
             DB::commit();
             flash_success(lang('success assign workspaces'));
             ajx_current("back");
         } catch (Exception $exc) {
             DB::rollback();
             flash_error(lang('error assign workspace') . $exc->getMessage());
             ajx_current("empty");
         }
     }
 }