/** * Parse csv file for getting its metadata * @param \SimpleXMLIterator $data data * @return multitype:Ambigous <> */ public function parseFile($data) { try { $temp = (array) $data; $fileName = $temp['fileName']; $dataType = $temp['dataType']; $duplicateHandle = $data['duplicateHandle']; $fileStorageId = (string) $temp['fileStorageId']; $fullPath = (string) $temp['fullPath']; // count file $fp = file($fullPath); $count = count($fp) - 1; // Get headers $header = array(); if (($handle = fopen($fullPath, "r")) !== false) { // no row length limit plus csv escape with ' while (($csvRow = fgetcsv($handle, 0, ",", "'")) !== false) { for ($columnNo = 0, $columnCount = count($csvRow); $columnNo < $columnCount; $columnNo++) { $header[] = $csvRow[$columnNo]; $data->headers->addChild($columnNo, (string) $csvRow[$columnNo]); } break; } fclose($handle); } $data->records = $count; $file = $data->addChild('file'); $file->addChild('fileName', (string) $temp['fileName']); $file->addChild('fileStorageId', $fileStorageId); unset($data->fileStorageId); unset($data->fileName); unset($data->fullPath); $response = $this->edit($data); // Make response $response['fileName'] = $fileName; $response['headers'] = $header; return $response; } catch (\Exception $e) { echo $e->getMessage(); } }
/** * save and edit system template document * @param unknown $data data * @return Ambigous <multitype:, multitype:Ambigous <boolean, \Base\Model\Service\Ambigous, multitype:, string, unknown, object> NULL > */ public function edit($data) { if (isset($data->id) && !empty($data->id) && isset($data->generatedOn)) { unset($data->recipient); } $result = parent::edit($data); $response = new \SimpleXMLIterator('<?xml version="1.0" encoding="UTF-8"?><template/>'); $response->addChild('id', (string) $result['id']); $response->addChild('fields', 'recipient'); $recipients = $this->getOne($response); $result['recipients'] = $recipients['fields']; return $result; }
protected function updateAPP() { if (is_file($this->applist) && is_writable($this->applist)) { try { $doc = new SimpleXMLIterator($this->applist, null, true); } catch (Exception $e) { $this->error[] = "发生异常:" . $e->getMessage() . " 文件:" . $e->getFile() . " 行号:" . $e->getLine(); return false; } if ($doc->getName() != "apps") { $this->error[] = "applist.xml的根元素必须是apps"; return false; } $i = $doc->count(); if ($i !== 0) { $apps = $doc->app; foreach ($apps as $app) { if ($app['name'] == $this->app_name) { $this->error[] = "项目列表存在重名项目,请修改项目名称"; return false; } } } $doc->addChild("app"); $doc->app[$i]->addAttribute("name", $this->app_name); $doc->app[$i]->addAttribute("path", $this->app_path); $doc->app[$i]->addAttribute("index", $this->app_index); if ($doc->asXML($this->applist)) { return true; } else { $this->error[] = "TinkPHP助手/data/applist.xml 写入失败"; return false; } } else { $this->error[] = "TinkPHP助手/data/applist.xml不存在"; return false; } }
/** * edit function * @param SimpleXMLIterator $data array * @return array */ public function edit($data) { // get the users instance referece $query = $this->_dm->createQueryBuilder('MoveIn4Instance\\Document\\InstanceDocument'); $inst = $query->field('shortName')->equals((string) $data->auth->inst)->getQuery()->getSingleResult(); if ($inst) { $data->addChild('instance', $inst->getId()); } return parent::edit($data); }
/** * replace _id with id in message for saving form data * @param \SimpleXMLIterator $data - passed from message queue * @return void */ private function _setQuickEditData($data) { if (isset($data->_id)) { $data->addChild('id', $data->_id); unset($data->_id); } elseif (isset($data['_id'])) { $data['id'] = $data['_id']; unset($data['_id']); } foreach ($data as $key => $value) { if (is_object($value) || is_array($value)) { $this->_setQuickEditData($value); } } }