* @package design * @version $Id: model.php 5079 2013-07-10 00:44:34Z chencongzhi520@gmail.com $ * @link http://www.zentao.net */ ?> stripTags('desc', $this->config->allowedTags) ->add('createdBy', $this->app->user->account) ->add('createdDate', helper::now()) ->add('program', $this->session->program) ->add('version', 1) ->remove('file,files,labels,children,toList') ->get(); $design = $this->loadModel('file')->processImgURL($design, 'desc', $this->post->uid); $this->dao->insert(TABLE_DESIGN)->data($design)->autoCheck()->batchCheck('name,type', 'notempty')->exec(); if(!dao::isError()) { $designID = $this->dao->lastInsertID(); $this->file->updateObjectID($this->post->uid, $designID, 'design'); $files = $this->file->saveUpload('design', $designID); $spec = new stdclass(); $spec->design = $designID; $spec->version = 1; $spec->name = $design->name; $spec->desc = $design->desc; $spec->files = empty($files) ? '' : implode(',', array_keys($files)); $this->dao->insert(TABLE_DESIGNSPEC)->data($spec)->exec(); return $designID; } return false; } /** * Update a design. * * @param int $designID * @access public * @return bool */ public function update($designID) { $oldDesign = $this->getByID($designID); $design = fixer::input('post') ->add('editedBy', $this->app->user->account) ->add('editedDate', helper::now()) ->stripTags($this->config->design->editor->edit['id'], $this->config->allowedTags) ->remove('file,files,labels,children,toList') ->get(); $design = $this->loadModel('file')->processImgURL($design, 'desc', $this->post->uid); $this->dao->update(TABLE_DESIGN)->data($design)->autoCheck()->batchCheck('name,type', 'notempty')->where('id')->eq($designID)->exec(); if(!dao::isError()) { $this->file->updateObjectID($this->post->uid, $designID, 'design'); $files = $this->file->saveUpload('design', $designID); $designChanged = ($oldDesign->name != $design->name || $oldDesign->desc != $design->desc || !empty($files)); if($designChanged) { $design = $this->getByID($designID); $version = $design->version + 1; $spec = new stdclass(); $spec->design = $designID; $spec->version = $version; $spec->name = $design->name; $spec->desc = $design->desc; $spec->files = empty($files) ? '' : implode(',', array_keys($files)); $this->dao->insert(TABLE_DESIGNSPEC)->data($spec)->exec(); $this->dao->update(TABLE_DESIGN)->set('version')->eq($version)->where('id')->eq($designID)->exec(); } return common::createChanges($oldDesign, $design); } return false; } /** * LinkCommit a design. * * @param int $designID * @access public * @return void */ public function linkCommit($designID) { $this->dao->delete()->from(TABLE_RELATION)->where('AType')->eq('design')->andWhere('AID')->eq($designID)->andWhere('BType')->eq('commit')->andWhere('relation')->eq('completedin')->exec(); $this->dao->delete()->from(TABLE_RELATION)->where('AType')->eq('commit')->andWhere('BID')->eq($designID)->andWhere('BType')->eq('design')->andWhere('relation')->eq('completedfrom')->exec(); $revisions = $_POST['revision']; foreach($revisions as $revision) { $data = new stdclass(); $data->program = $this->session->program; $data->product = $this->session->product; $data->AType = 'design'; $data->AID = $designID; $data->BType = 'commit'; $data->BID = $revision; $data->relation = 'completedin'; $data->extra = $this->session->repoID; $this->dao->replace(TABLE_RELATION)->data($data)->autoCheck()->exec(); $data->AType = 'commit'; $data->AID = $revision; $data->BType = 'design'; $data->BID = $designID; $data->relation = 'completedfrom'; $this->dao->replace(TABLE_RELATION)->data($data)->autoCheck()->exec(); } } /** * SetProductMenu * * @param int $productID * @access public * @return void */ public function setProductMenu($productID = 0) { $programID = $this->session->program; $program = $this->loadModel('project')->getByID($programID); $products = $this->loadModel('product')->getPairs($programID); $productID = in_array($productID, array_keys($products)) ? $productID : key($products); $productID = $this->loadModel('product')->saveState($productID, $products); if($program->category == 'multiple') $this->loadModel('product')->setMenu($products, $productID); } /** * GetByID * * @param int $designID * @access public * @return object */ public function getByID($designID) { $design = $this->dao->select('*')->from(TABLE_DESIGN)->where('id')->eq($designID)->fetch(); $design->files = $this->loadModel('file')->getByObject('design', $designID); $design->productName = $this->dao->findByID($design->product)->from(TABLE_PRODUCT)->fetch('name'); $design->commit = ''; $relations = $this->loadModel('common')->getRelations('design', $designID, 'commit'); foreach($relations as $relation) $design->commit .= html::a(helper::createLink('design', 'revision', "repoID=$relation->BID"), "#$relation->BID", '_blank'); return $this->loadModel('file')->replaceImgURL($design, 'desc'); } /** * GetDesignPairs * * @param int $productID * @param string $type * @access public * @return object */ public function getDesignPairs($productID = 0, $type = 'detailed') { $designs = $this->dao->select('id, name')->from(TABLE_DESIGN) ->where('product')->eq($productID) ->andWhere('deleted')->eq(0) ->andWhere('type')->eq($type) ->fetchPairs(); foreach($designs as $id => $name) $designs[$id] = $id . ':' . $name; return $designs; } /** * GetAffectedScope * * @param int $design * @access public * @return object */ public function getAffectedScope($design) { /* Get affected tasks. */ $design->tasks = $this->dao->select('*')->from(TABLE_TASK) ->where('deleted')->eq(0) ->andWhere('status')->ne('closed') ->andWhere('design')->eq($design->id) ->orderBy('id desc')->fetchAll(); return $design; } /** * GetList * * @param int $productID * @param int $type * @param int $orderBy * @param int $pager * @access public * @return array */ public function getList($productID, $type = 'all', $orderBy = 'id_desc', $pager = null) { $designs = $this->dao->select('*')->from(TABLE_DESIGN) ->where('deleted')->eq(0) ->beginIF($this->session->program)->andWhere('program')->eq($this->session->program)->fi() ->beginIF($type != 'all')->andWhere('type')->in($type)->fi() ->andWhere('product')->eq($productID) ->orderBy($orderBy) ->page($pager) ->fetchAll('id'); foreach($designs as $id => $design) { $design->commit = ''; $relations = $this->loadModel('common')->getRelations('design', $id, 'commit'); foreach($relations as $relation) $design->commit .= html::a(helper::createLink('design', 'revision', "repoID=$relation->BID", '', true), "#$relation->BID", '_blank'); } return $designs; } }