/** * Add record many to many (M-M) * * @param BizDataObj $dataObj * @param array $recArr * @return boolean */ private static function _addRecordMtoM($dataObj, $recArr) { // query on this object to get the corresponding record of this object. $searchRule = "[Id] = '" . $recArr["Id"] . "'"; $recordList = $dataObj->directFetch($searchRule, 1); if (count($recordList) == 1) { return true; } // insert a record on XTable $db = $dataObj->getDBConnection(); $xDataObj = isset($dataObj->association["XDataObj"]) ? $dataObj->association["XDataObj"] : null; $val1 = $dataObj->association["FieldRefVal"]; $val2 = $recArr["Id"]; if ($xDataObj) { // get new record from XDataObj $xObj = Openbizx::getObject($xDataObj); $newRecArr = $xObj->newRecord(); // verify the main table of XDataobj is same as the XTable if ($xObj->mainTableName != $dataObj->association["XTable"]) { throw new Openbizx\Data\Exception("Unable to create a record in intersection table: XDataObj's main table is not same as XTable."); //return false; } $fld1 = $xObj->getFieldNameByColumn($dataObj->association["XColumn1"]); $newRecArr[$fld1] = $val1; $fld2 = $xObj->getFieldNameByColumn($dataObj->association["XColumn2"]); $newRecArr[$fld2] = $val2; $ok = $xObj->insertRecord($newRecArr); if ($ok === false) { throw new Openbizx\Data\Exception($xObj->getErrorMessage()); //return false; } } else { $sql_col = "(" . $dataObj->association["XColumn1"] . "," . $dataObj->association["XColumn2"] . ")"; $sql_val = "('" . $val1 . "','" . $val2 . "')"; $sql = "INSERT INTO " . $dataObj->association["XTable"] . " " . $sql_col . " VALUES " . $sql_val; try { Openbizx::$app->getLog()->log(LOG_DEBUG, "DATAOBJ", "Associate Insert Sql = {$sql}"); $db->query($sql); } catch (Exception $e) { Openbizx::$app->getLog()->log(LOG_ERR, "DATAOBJ", "Query Error: " . $e->getMessage()); throw new Openbizx\Data\Exception("Query Error: " . $e->getMessage()); return false; } } // add the record to object cache. requery on this object to get the corresponding record of this object. $searchRule = "[Id] = '" . $recArr["Id"] . "'"; $recordList = $dataObj->directFetch($searchRule, 1); if (count($recordList) == 0) { return false; } return true; }
protected function loadFullMenuTree() { if (self::$fullMenuTree != null) { return; } $cache_id = 'FULL_MENU_LIST'; $cacheSvc = BizSystem::getService(CACHE_SERVICE, 1); $cacheSvc->init($this->m_Name, 600); // cache for 10 mins if ($cacheSvc->test($cache_id)) { self::$fullMenuTree = $cacheSvc->load($cache_id); return; } $rs = parent::directFetch(); foreach ($rs as $record) { if (empty($record['PId'])) { $record['PId'] = "__root__"; } unset($record['create_by']); unset($record['create_time']); unset($record['update_by']); unset($record['update_time']); unset($record['name']); unset($record['parent']); self::$fullMenuTree[$record['Id']] = $record; } foreach (self::$fullMenuTree as $mId => $record) { self::$fullMenuTree[$record['PId']]['children'][] = $mId; } //print_r(self::$fullMenuTree); $cacheSvc->save(self::$fullMenuTree, $cache_id); // put it in apc or file cache }