Example #1
0
 /**
  * edit template
  *
  * @author                                  youzhao.zxw<*****@*****.**>
  * @param   array       $templateInfo       template information
  * @return  array                           edit result information
  */
 public static function editTemplate($templateInfo)
 {
     $resultInfo = array();
     $updateFlag = false;
     $title = trim($templateInfo['title']);
     $userTemplate = UserTemplate::model()->findByAttributes(array('type' => $templateInfo['type'], 'product_id' => $templateInfo['product_id'], 'created_by' => Yii::app()->user->id, 'title' => $title));
     if (false != $userTemplate) {
         $updateFlag = true;
         $userTemplate->updated_at = date(CommonService::DATE_FORMAT);
     } else {
         $userTemplate = new UserTemplate();
         $userTemplate->created_by = Yii::app()->user->id;
         $userTemplate->created_at = date(CommonService::DATE_FORMAT);
         $userTemplate->updated_at = $userTemplate->created_at;
         $userTemplate->product_id = $templateInfo['product_id'];
         $userTemplate->type = $templateInfo['type'];
         $userTemplate->title = $title;
     }
     $userTemplate->template_content = serialize($templateInfo['template_content']);
     if ($userTemplate->save()) {
         $resultInfo['status'] = CommonService::$ApiResult['SUCCESS'];
         if ($updateFlag) {
             $resultInfo['detail'] = array('id' => Yii::t('Common', self::TIP_UPDATE_SUCCESS));
         } else {
             $resultInfo['detail'] = array('id' => Yii::t('Common', self::TIP_CREATE_SUCCESS));
         }
     } else {
         $resultInfo['status'] = CommonService::$ApiResult['FAIL'];
         $resultInfo['detail'] = $userTemplate->getErrors();
     }
     return $resultInfo;
 }
 public function testRegenerateOnDelete()
 {
     $this->logInWithPermission();
     $ut = new UserTemplate();
     $ut->Title = 'Template 1';
     $ut->Use = 'Layout';
     $ut->Content = 'UserTemplate 1 $Content';
     $ut->write();
     $file = $ut->getTemplateFile();
     clearstatcache();
     $size = filesize($file);
     $this->assertTrue($size > 0);
     unlink($file);
     $file = $ut->getTemplateFile();
     clearstatcache();
     $size = filesize($file);
     $this->assertTrue($size > 0);
 }
 public function getCMSFields()
 {
     $fields = parent::getCMSFields();
     $field = DropdownField::create('ItemListID', 'Item list to display', ItemList::get()->map()->toArray())->setEmptyString('--choose list--');
     $fields->addFieldToTab('Root.Main', $field, 'Content');
     if ($this->hasField('TemplateID')) {
         $fields->addFieldToTab('Root.Main', $df = DropdownField::create('TemplateID', 'Template for rendering items', UserTemplate::get()->map()->toArray()), 'Content');
         $df->setEmptyString('--template--');
     }
     return $fields;
 }
Example #4
0
 /**
  * Prepare info page
  *
  * @author                                    youzhao.zxw<*****@*****.**>
  * @param   String          $infoType         bug,case or result
  * @param   CController     $controller       page controller
  * @param   String          $actionType       edit action
  * @param   array           $request          page request info
  * @return  array                             page information
  */
 public static function initInfoPage($infoType, $controller, $actionType, $request)
 {
     $basicModelName = ucfirst(strtolower($infoType)) . 'InfoView';
     $infoId = $request->getParam('id');
     $fileDeleteable = true;
     if ('view' == $actionType) {
         $fileDeleteable = false;
     }
     if (isset($infoId)) {
         $mixedInfo = InfoService::loadModel($infoType, $infoId, $fileDeleteable);
         $model = $mixedInfo->getBasicInfo();
         $customInfo = $mixedInfo->getCustomInfo();
         if (Info::TYPE_BUG == $infoType) {
             if (!in_array($actionType, BugInfo::model()->getLegalActionByState($model->getAttribute($infoType . '_status')))) {
                 throw new CHttpException(400, Yii::t('Common', 'Required URL not found or permission denied.'));
             }
             if ('view' != $actionType) {
                 $model->setAttribute('bug_status', self::getBugStatusByAction($actionType));
             }
             if (BugInfo::ACTION_OPEN == $actionType) {
             } elseif (BugInfo::ACTION_RESOLVE == $actionType) {
                 $model->resolved_at = date(CommonService::DATE_FORMAT);
                 $model->resolved_by = Yii::app()->user->id;
                 $model->assign_to = $model->created_by;
                 $model->assign_to_name = CommonService::getUserRealName($model->created_by);
             } elseif (BugInfo::ACTION_CLOSE == $actionType) {
                 $model->closed_at = date(CommonService::DATE_FORMAT);
                 $model->closed_by = Yii::app()->user->id;
                 $model->assign_to = TestUser::CLOSE_USER_ID;
                 $model->assign_to_name = TestUser::CLOSE_USER_NAME;
             } elseif (BugInfo::ACTION_ACTIVATE == $actionType) {
                 $customInfo = self::filterCustomInfoInReactive($customInfo, $model->product_id);
                 $model->reopen_count += 1;
                 $model->assign_to = $model->resolved_by;
                 $model->assign_to_name = CommonService::getUserRealName($model->resolved_by);
                 $model = self::setBugActiveModel($model);
             }
             $model->scenario = $actionType;
         }
         $productId = $model->product_id;
         $customFieldArr = FieldConfigService::getCustomFieldConfig($productId, $infoType, $controller, $actionType, array(), $customInfo);
     } else {
         $model = new $basicModelName();
         $customInfo = array();
         $sourceId = $request->getParam('source_id');
         $templateId = $request->getParam('template_id');
         $caseId = $request->getParam('case_id');
         $resultId = $request->getParam('result_id');
         $bugId = $request->getParam('bug_id');
         $bactchRunProductId = $request->getParam('batch_product_id');
         if (isset($sourceId)) {
             $mixedInfo = InfoService::loadModel($infoType, $sourceId, $fileDeleteable);
             $model = $mixedInfo->getBasicInfo();
             unset($model->id);
             $model->setIsNewRecord(true);
             $productId = $model->product_id;
             if ('bug' == $infoType) {
                 $customInfo = FieldConfigService::getBugAvailableValueByAction($mixedInfo->getCustomInfo(), $actionType, $productId);
                 $model = self::setBugActiveModel($model);
             } else {
                 if ('case' == $infoType) {
                     $customInfo = $mixedInfo->getCustomInfo();
                     unset($customInfo['id']);
                     unset($customInfo['case_id']);
                 }
             }
             $customFieldArr = FieldConfigService::getCustomFieldConfig($productId, $infoType, $controller, $actionType, array(), $customInfo);
         } elseif (isset($templateId)) {
             $templateInfo = UserTemplate::model()->findByPk($templateId);
             if ($templateInfo === null) {
                 throw new CHttpException(404, 'The requested page does not exist.');
             }
             $mixedInfo = unserialize($templateInfo['template_content']);
             $model->attributes = $mixedInfo->getBasicInfo();
             $productId = $model->product_id;
             $productInfo = Product::model()->findByPk($productId);
             $model->product_name = $productInfo->name;
             $customInfo = $mixedInfo->getCustomInfo();
             //no need custom id and info_id from template
             if (Info::TYPE_BUG == $infoType) {
                 $customInfo = FieldConfigService::getBugAvailableValueByAction($customInfo, $actionType, $productId);
                 $model = self::setBugActiveModel($model);
             } else {
                 if (Info::TYPE_CASE == $infoType) {
                     unset($customInfo['id']);
                     unset($customInfo['case_id']);
                 }
             }
             //unset($model->id);
             $customFieldArr = FieldConfigService::getCustomFieldConfig($productId, $infoType, $controller, $actionType, array(), $customInfo);
         } elseif (isset($caseId)) {
             $caseMixedInfo = InfoService::loadModel('case', $caseId, $fileDeleteable);
             $caseModel = $caseMixedInfo->getBasicInfo();
             $model->related_case_id = $caseId;
             $model->title = $caseModel->title;
             $model->product_id = $caseModel->product_id;
             $model->product_name = $caseModel->product_name;
             $model->module_name = $caseModel->module_name;
             $model->productmodule_id = $caseModel->productmodule_id;
             $model->result_step = $caseModel->case_step;
             $model->assign_to = TestUser::CLOSE_USER_ID;
             $model->assign_to_name = TestUser::CLOSE_USER_NAME;
             $productId = $caseModel->product_id;
             $customFieldArr = FieldConfigService::getCustomFieldConfig($productId, $infoType, $controller, $actionType, array(), $customInfo);
         } elseif (isset($bugId)) {
             $bugMixedInfo = InfoService::loadModel(Info::TYPE_BUG, $bugId, $fileDeleteable);
             $bugModel = $bugMixedInfo->getBasicInfo();
             $model->related_bug = $bugId;
             $model->title = $bugModel->title;
             $model->product_id = $bugModel->product_id;
             $model->product_name = $bugModel->product_name;
             $model->priority = $bugModel->priority;
             $model->module_name = $bugModel->module_name;
             $model->productmodule_id = $bugModel->productmodule_id;
             $model->case_step = $bugModel->repeat_step;
             $model->assign_to = $bugModel->assign_to;
             $model->assign_to_name = $bugModel->assign_to_name;
             $model->mail_to = $bugModel->mail_to;
             $productId = $bugModel->product_id;
             $customFieldArr = FieldConfigService::getCustomFieldConfig($productId, $infoType, $controller, $actionType, array(), $customInfo);
         } elseif (isset($bactchRunProductId)) {
             $model->title = Yii::t('Common', 'Mutiple items');
             $model->product_id = $bactchRunProductId;
             $model->product_name = Yii::t('Common', 'Mutiple items');
             $model->module_name = Yii::t('Common', 'Mutiple items');
             $model->assign_to = TestUser::CLOSE_USER_ID;
             $model->assign_to_name = TestUser::CLOSE_USER_NAME;
             $productId = $bactchRunProductId;
             $customFieldArr = FieldConfigService::getCustomFieldConfig($productId, $infoType, $controller, $actionType, array(), $customInfo);
         } elseif (isset($resultId)) {
             $resultMixedInfo = InfoService::loadModel('result', $resultId, $fileDeleteable);
             $resultModel = $resultMixedInfo->getBasicInfo();
             $resultCustomInfo = $resultMixedInfo->getCustomInfo();
             $model->related_result = $resultId;
             $model->title = $resultModel->title;
             $model->module_name = $resultModel->module_name;
             $model->repeat_step = ResultStepService::removeStepResultForBug($resultModel->result_step);
             $model->product_id = $resultModel->product_id;
             $model->productmodule_id = $resultModel->productmodule_id;
             $model->assign_to = TestUser::ACTIVE_USER_ID;
             $model->assign_to_name = TestUser::ACTIVE_USER_NAME;
             $productId = $resultModel->product_id;
             $copyFieldArr = FieldConfigService::getBugCopyableFields($productId);
             foreach ($copyFieldArr as $resultField) {
                 $copyFieldName = $resultField['field_name'];
                 if (isset($resultCustomInfo[$copyFieldName])) {
                     $customInfo[$copyFieldName] = $resultCustomInfo[$copyFieldName];
                 }
             }
             $customFieldArr = FieldConfigService::getCustomFieldConfig($productId, $infoType, $controller, $actionType, array(), $customInfo);
         } else {
             $productId = $request->getParam('product_id');
             $productInfo = Product::model()->findByPk($productId);
             $model->product_name = $productInfo->name;
             $selectModuleId = Yii::app()->user->getState($productId . '_' . $infoType . '_selectedModule');
             if (!empty($selectModuleId)) {
                 $model->productmodule_id = $selectModuleId;
                 $selectedModuleInfo = ProductModule::model()->findByPk($selectModuleId);
                 if (!empty($selectedModuleInfo)) {
                     $model->assign_to = $selectedModuleInfo['owner'];
                     $model->assign_to_name = CommonService::getUserRealName($selectedModuleInfo['owner']);
                 }
             }
             if (Info::TYPE_BUG == $infoType) {
                 $model->repeat_step = $productInfo[$infoType . '_step_template'];
             } elseif (Info::TYPE_CASE == $infoType) {
                 $model->case_step = $productInfo[$infoType . '_step_template'];
             }
             $customFieldArr = FieldConfigService::getCustomFieldConfig($productId, $infoType, $controller, Info::ACTION_OPEN);
         }
         if (Info::TYPE_RESULT != $infoType) {
             $model->setAttribute($infoType . '_status', 'Active');
         } else {
             $model->setAttribute($infoType . '_status', ResultInfo::STATUS_COMPLETED);
         }
         if (Info::TYPE_BUG == $infoType) {
             $model->reopen_count = 0;
         }
         if (Info::TYPE_CASE == $infoType) {
             $model->delete_flag = CommonService::$TrueFalseStatus['FALSE'];
         }
         $model->attachment_file = '';
         $model->created_at = date(CommonService::DATE_FORMAT);
         $model->created_by = Yii::app()->user->id;
         $model->updated_at = '';
         $model->updated_by = '';
     }
     $model->product_id = $productId;
     $assignToName = self::parseAssignToName($model->assign_to);
     if ('' != $assignToName) {
         $model->assign_to_name = $assignToName;
     }
     return array($productId, $model, $customInfo, $customFieldArr);
 }
Example #5
0
 public function actionDeleteTemplateOrQuery()
 {
     $id = $_GET['id'];
     $type = $_GET['type'];
     if ('template' == $type) {
         $tmpInfo = UserTemplate::model()->findByAttributes(array('id' => $id, 'created_by' => Yii::app()->user->id));
     } elseif ('query' == $type) {
         $tmpInfo = UserQuery::model()->findByAttributes(array('id' => $id, 'created_by' => Yii::app()->user->id));
     }
     if ($tmpInfo !== null) {
         $tmpInfo->delete();
     }
     echo CommonService::$ApiResult['SUCCESS'];
 }
Example #6
0
 public function __construct()
 {
     $this->tpl_name = "user/user_form";
     parent::__construct();
     $this->template->add_template($this->tpl_name);
 }