Exemplo n.º 1
0
 /**
  *
  */
 private function _formatParams(Model_Tudu_Tudu &$tudu, array $params, $suffix = '')
 {
     $keys = array('tid' => array('type' => 'string', 'column' => 'tuduid'), 'ftid' => array('type' => 'string', 'column' => 'tuduid'), 'tuduid' => array('type' => 'string'), 'starttime' => array('type' => 'date'), 'endtime' => array('type' => 'date'), 'priority' => array('type' => 'boolean', 'default' => 0), 'privacy' => array('type' => 'boolean', 'default' => 0), 'notifyall' => array('type' => 'boolean', 'default' => 0), 'cycle' => array('type' => 'boolean', 'default' => 0), 'isauth' => array('type' => 'boolean', 'default' => 0), 'istop' => array('type' => 'boolean', 'default' => 0), 'needconfirm' => array('type' => 'boolean', 'default' => 0), 'appid' => array('type' => 'string'), 'acceptmode' => array('type' => 'boolean'), 'subject' => array('type' => 'string'), 'classid' => array('type' => 'string'), 'flowid' => array('type' => 'string'), 'type' => array('type' => 'string'), 'classid' => array('type' => 'string', 'column' => 'classid'), 'boardid' => array('type' => 'string'), 'bid' => array('type' => 'string', 'column' => 'boardid'), 'content' => array('type' => 'html'), 'password' => array('type' => 'string', 'depend' => 'privacy'), 'to' => array('type' => 'receiver'), 'cc' => array('type' => 'receiver'), 'bcc' => array('type' => 'receiver'), 'reviewer' => array('type' => 'receiver'), 'agree' => array('type' => 'boolean'), 'ismodified' => array('type' => 'boolean'));
     $attributes = array();
     $type = !empty($params['type']) ? $params['type'] : 'task';
     foreach ($keys as $k => $item) {
         if ($k == 'to' && !empty($suffix)) {
             $val = $params['ch-' . $k . $suffix];
         } else {
             if (!isset($params[$k . $suffix]) && !isset($item['default'])) {
                 if ($item['type'] == 'boolean') {
                     $col = isset($item['column']) ? $item['column'] : $k;
                     $attributes[$col] = !empty($params[$k . $suffix]);
                 }
                 continue;
             }
             $val = isset($params[$k . $suffix]) ? $params[$k . $suffix] : $item['default'];
         }
         if ($k == 'cycle' && !$val) {
             $attributes['cycleid'] = null;
         }
         // 有依赖关系字段
         if (isset($item['depend']) && empty($params[$item['depend'] . $suffix])) {
             continue;
         }
         $col = isset($item['column']) ? $item['column'] : $k;
         switch ($item['type']) {
             case 'date':
                 $attributes[$col] = is_numeric($val) ? (int) $val : strtotime($val);
                 break;
             case 'boolean':
                 if ($col == 'notifyall' && $type == 'task') {
                     $attributes[$col] = (bool) (!empty($params['remind' . $suffix])) && !empty($params['notifyall' . $suffix]);
                 } else {
                     $attributes[$col] = (bool) $val;
                 }
                 break;
             case 'html':
                 $t = strip_tags($val, 'img');
                 $attributes[$col] = empty($t) ? '' : $val;
                 break;
             case 'receiver':
                 if (!empty($val)) {
                     $isFlow = $type != 'meeting' ? in_array($col, array('to', 'reviewer')) : false;
                     $attributes[$col] = $this->_formatReceiver($val, $isFlow, $col == 'to');
                     // 填充执行人进度
                     if ($col == 'to' && !empty($params['toidx' . $suffix]) && !empty($attributes['to'])) {
                         $idx = $params['toidx' . $suffix];
                         foreach ($idx as $i) {
                             $csfx = $suffix . '-' . $i;
                             if (isset($params['to' . $csfx]) && isset($params['to-percent' . $csfx])) {
                                 foreach ($attributes[$col][0] as $k => $item) {
                                     if ($item['username'] . ' ' . $item['truename'] == trim($params['to' . $csfx])) {
                                         $attributes[$col][0][$k]['percent'] = (int) $params['to-percent' . $csfx];
                                         break;
                                     }
                                 }
                             }
                         }
                     }
                 }
                 break;
             case 'string':
             default:
                 $attributes[$col] = trim($val);
                 break;
         }
     }
     if (isset($params['isclose' . $suffix])) {
         $attributes['isdone'] = (int) $params['isclose' . $suffix];
     }
     if (isset($attributes['type']) && $attributes['type'] == 'notice') {
         $attributes['istop'] = 0;
         if (!empty($attributes['endtime']) && $attributes['endtime'] >= strtotime('today')) {
             $attributes['istop'] = 1;
         }
     }
     $attachments = array();
     if (isset($params['attach' . $suffix]) && is_array($params['attach' . $suffix])) {
         foreach ($params['attach' . $suffix] as $item) {
             $attachments[] = array('fileid' => $item, 'isattachment' => true, 'isnetdisk' => false);
         }
     }
     if (isset($params['file' . $suffix]) && is_array($params['file' . $suffix])) {
         foreach ($params['file' . $suffix] as $item) {
             $attachments[] = array('fileid' => $item, 'isattachment' => false, 'isnetdisk' => false);
         }
     }
     if (!empty($params['nd-attach' . $suffix])) {
         $attachments = array_diff($attachments, $params['nd-attach' . $suffix]);
         $daoNdFile = Tudu_Dao_Manager::getDao('Dao_Td_Netdisk_File', Tudu_Dao_Manager::DB_TS);
         $daoAttachment = Tudu_Dao_Manager::getDao('Dao_Td_Attachment_File', Tudu_Dao_Manager::DB_TS);
         foreach ($params['nd-attach' . $suffix] as $ndfileId) {
             $fileId = $ndfileId;
             $attach = $daoAttachment->getFile(array('fileid' => $fileId));
             if (null !== $attach) {
                 $attachments[] = array('fileid' => $fileId, 'isattachment' => true, 'isnetdisk' => true);
                 continue;
             }
             $file = $daoNdFile->getFile(array('uniqueid' => $this->_user->uniqueId, 'fileid' => $ndfileId));
             if ($file->fromFileId) {
                 $fileId = $file->fromFileId;
             }
             if ($file->attachFileId) {
                 $fileId = $file->attachFileId;
             }
             $fid = $daoAttachment->createFile(array('uniqueid' => $this->_user->uniqueId, 'fileid' => $fileId, 'orgid' => $this->_user->orgId, 'filename' => $file->fileName, 'path' => $file->path, 'type' => $file->type, 'size' => $file->size, 'createtime' => time()));
             if ($fid) {
                 $attachments[] = array('fileid' => $fileId, 'isattachment' => true, 'isnetdisk' => true);
             }
         }
     }
     $tudu->setAttributes($attributes);
     if (!empty($attachments)) {
         foreach ($attachments as $item) {
             $tudu->addAttachment($item['fileid'], $item['isattachment'], $item['isnetdisk']);
         }
     }
 }
Exemplo n.º 2
0
 /**
  *
  */
 private function _formatParams(Model_Tudu_Tudu &$tudu, array $params, $suffix = '')
 {
     $keys = array('tid' => array('type' => 'string', 'column' => 'tuduid'), 'ftid' => array('type' => 'string', 'column' => 'tuduid'), 'tuduid' => array('type' => 'string'), 'acceptmode' => array('type' => 'boolean'), 'subject' => array('type' => 'string'), 'content' => array('type' => 'html'), 'cc' => array('type' => 'receiver'), 'bcc' => array('type' => 'receiver'));
     $time = time();
     $attributes = array('orgid' => $this->_user->orgId, 'type' => 'task', 'boardid' => '^app-attend', 'appid' => 'attend', 'classid' => '^attend');
     foreach ($keys as $k => $item) {
         if ($k == 'to' && !empty($suffix)) {
             $val = $params['ch-' . $k . $suffix];
         } else {
             if (!isset($params[$k . $suffix])) {
                 continue;
             }
             $val = $params[$k . $suffix];
         }
         // 有依赖关系字段
         if (isset($item['depend']) && empty($params[$item['depend'] . $suffix])) {
             continue;
         }
         $col = isset($item['column']) ? $item['column'] : $k;
         switch ($item['type']) {
             case 'date':
                 $attributes[$col] = is_numeric($val) ? (int) $val : strtotime($val);
                 break;
             case 'boolean':
                 $attributes[$col] = (bool) $val;
                 break;
             case 'html':
                 $t = strip_tags($val, 'img');
                 $attributes[$col] = empty($t) ? '' : $val;
                 break;
             case 'receiver':
                 if (!empty($val)) {
                     $attributes[$col] = $this->_formatReceiver($val, in_array($col, array('to', 'reviewer')));
                 }
                 break;
             case 'string':
             default:
                 $attributes[$col] = trim($val);
                 break;
         }
     }
     if (isset($attributes['type']) && $attributes['type'] == 'notice') {
         $attributes['istop'] = 0;
         if (!empty($attributes['endtime']) && $attributes['endtime'] >= strtotime('today')) {
             $attributes['istop'] = 1;
         }
     }
     $attachments = array();
     if (!empty($params['nd-attach' . $suffix])) {
         $ret['attachment'] = array_diff($ret['attachment'], $params['nd-attach' . $suffix]);
         $daoNdFile = Tudu_Dao_Manager::getDao('Dao_Td_Netdisk_File', Tudu_Dao_Manager::DB_TS);
         $daoAttachment = Tudu_Dao_Manager::getDao('Dao_Td_Attachment_File', Tudu_Dao_Manager::DB_TS);
         foreach ($params['nd-attach' . $suffix] as $ndfileId) {
             $fileId = $ndfileId;
             $attach = $daoAttachment->getFile(array('fileid' => $fileId));
             if (null !== $attach) {
                 $ret['attachment'][] = $fileId;
                 continue;
             }
             $file = $daoNdFile->getFile(array('uniqueid' => $this->_user->uniqueId, 'fileid' => $ndfileId));
             if ($file->fromFileId) {
                 $fileId = $file->fromFileId;
             }
             if ($file->attachFileId) {
                 $fileId = $file->attachFileId;
             }
             $fid = $daoAttachment->createFile(array('uniqueid' => $this->_user->uniqueId, 'fileid' => $fileId, 'orgid' => $this->_user->orgId, 'filename' => $file->fileName, 'path' => $file->path, 'type' => $file->type, 'size' => $file->size, 'createtime' => time()));
             if ($fid) {
                 $attachments[] = array('fileid' => $fileId, 'isattachment' => true, 'isnetdisk' => true);
             }
         }
     }
     if (isset($params['attach' . $suffix]) && is_array($params['attach' . $suffix])) {
         foreach ($params['attach' . $suffix] as $item) {
             $attachments[] = array('fileid' => $item, 'isattachment' => true, 'isnetdisk' => false);
         }
     }
     if (isset($params['file' . $suffix]) && is_array($params['file' . $suffix])) {
         foreach ($params['file' . $suffix] as $item) {
             $attachments[] = array('fileid' => $item, 'isattachment' => false, 'isnetdisk' => false);
         }
     }
     $tudu->setAttributes($attributes);
     if (!empty($attachments)) {
         foreach ($attachments as $item) {
             $tudu->addAttachment($item['fileid'], $item['isattachment'], $item['isnetdisk']);
         }
     }
 }
Exemplo n.º 3
0
 /**
  *
  * @param Model_Tudu_Tudu $tudu
  * @param array $params
  */
 protected function _formatParams(Model_Tudu_Tudu &$tudu, array $params)
 {
     $attributes = array();
     //$attachment = array();
     foreach ($params as $key => $value) {
         switch ($key) {
             case 'starttime':
             case 'endtime':
                 $attributes[$key] = is_numeric($value) ? (int) $value : strtotime($value);
                 break;
             case 'priority':
             case 'privacy':
             case 'notifyall':
             case 'cycle':
             case 'isauth':
             case 'needconfirm':
             case 'istop':
             case 'acceptmode':
                 $attributes[$key] = (bool) $value;
                 break;
             case 'to':
             case 'cc':
             case 'bcc':
                 if (!empty($value)) {
                     $attributes[$key] = $this->_formatReceiver($value, $key == 'to');
                 }
                 break;
             case 'reviewer':
                 break;
             case 'image':
                 break;
             case 'subject':
             case 'classid':
             case 'tuduid':
             case 'location':
             default:
                 $attributes[$key] = $value;
         }
     }
     // 处理附件图片
     $attributes['content'] = !empty($attributes['content']) ? nl2br($attributes['content']) : '';
     $attachments = array();
     if (isset($params['image'])) {
         $images = $params['image'];
         if (!is_array($params['image'])) {
             $images = explode(',', $images);
         }
         foreach ($images as $fileId) {
             if (!$fileId) {
                 continue;
             }
             if (false !== strpos($fileId, ',')) {
                 $arr = explode(',', $fileId);
                 foreach ($arr as $fid) {
                     $attachments[] = array('fileid' => $fid, 'isattachment' => false, 'isnetdisk' => false);
                     $fid = str_replace('AID:', '', $fid);
                     $attributes['content'] .= '<br /><img src="AID:' . $fid . '" _aid="' . $fid . '" />';
                 }
                 continue;
             }
             $attachments[] = array('fileid' => $fileId, 'isattachment' => false, 'isnetdisk' => false);
             $fileId = str_replace('AID:', '', $fileId);
             $attributes['content'] .= '<br /><img src="AID:' . $fileId . '" _aid="' . $fileId . '" />';
         }
     }
     $tudu->setAttributes($attributes);
     if (!empty($attachments)) {
         foreach ($attachments as $item) {
             $tudu->addAttachment($item['fileid'], $item['isattachment'], $item['isnetdisk']);
         }
     }
 }