本文整理汇总了PHP中CFile::SaveForDB方法的典型用法代码示例。如果您正苦于以下问题:PHP CFile::SaveForDB方法的具体用法?PHP CFile::SaveForDB怎么用?PHP CFile::SaveForDB使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CFile
的用法示例。
在下文中一共展示了CFile::SaveForDB方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Add
function Add($arFields)
{
global $DB;
$arFields1 = array();
foreach ($arFields as $key => $value) {
if (substr($key, 0, 1) == "=") {
$arFields1[substr($key, 1)] = $value;
unset($arFields[$key]);
}
}
if (!CBlogImage::CheckFields("ADD", $arFields)) {
return false;
}
if (is_array($arFields['FILE_ID'])) {
if (array_key_exists("FILE_ID", $arFields) && is_array($arFields["FILE_ID"]) && (!array_key_exists("MODULE_ID", $arFields["FILE_ID"]) || strlen($arFields["FILE_ID"]["MODULE_ID"]) <= 0)) {
$arFields["FILE_ID"]["MODULE_ID"] = "blog";
}
$prefix = "blog";
if (strlen($arFields["URL"]) > 0) {
$prefix .= "/" . $arFields["URL"];
}
CFile::SaveForDB($arFields, "FILE_ID", $prefix);
}
if (isset($arFields['FILE_ID']) && intval($arFields['FILE_ID']) == $arFields['FILE_ID']) {
$arInsert = $DB->PrepareInsert("b_blog_image", $arFields);
foreach ($arFields1 as $key => $value) {
if (strlen($arInsert[0]) > 0) {
$arInsert[0] .= ", ";
}
$arInsert[0] .= $key;
if (strlen($arInsert[1]) > 0) {
$arInsert[1] .= ", ";
}
$arInsert[1] .= $value;
}
if (strlen($arInsert[0]) > 0) {
$strSql = "INSERT INTO b_blog_image(" . $arInsert[0] . ") " . "VALUES(" . $arInsert[1] . ")";
$DB->Query($strSql, False, "File: " . __FILE__ . "<br>Line: " . __LINE__);
$ID = IntVal($DB->LastID());
return $ID;
}
} else {
$GLOBALS["APPLICATION"]->ThrowException("Error Adding file by CFile::SaveForDB");
}
return False;
}
示例2: Update
function Update($ID, $arFields)
{
global $DB;
$ID = IntVal($ID);
if (strlen($arFields["PATH"]) > 0) {
$path = $arFields["PATH"];
unset($arFields["PATH"]);
}
$arFields1 = array();
foreach ($arFields as $key => $value) {
if (substr($key, 0, 1) == "=") {
$arFields1[substr($key, 1)] = $value;
unset($arFields[$key]);
}
}
if (!CBlogUser::CheckFields("UPDATE", $arFields, $ID)) {
return false;
}
if (array_key_exists("AVATAR", $arFields) && is_array($arFields["AVATAR"]) && (!array_key_exists("MODULE_ID", $arFields["AVATAR"]) || strlen($arFields["AVATAR"]["MODULE_ID"]) <= 0)) {
$arFields["AVATAR"]["MODULE_ID"] = "blog";
}
CFile::SaveForDB($arFields, "AVATAR", "blog/avatar");
$strUpdate = $DB->PrepareUpdate("b_blog_user", $arFields);
foreach ($arFields1 as $key => $value) {
if (strlen($strUpdate) > 0) {
$strUpdate .= ", ";
}
$strUpdate .= $key . "=" . $value . " ";
}
if (strlen($strUpdate) > 0) {
$arUser = CBlogUser::GetByID($ID, BLOG_BY_BLOG_USER_ID);
$strSql = "UPDATE b_blog_user SET " . "\t" . $strUpdate . " " . "WHERE ID = " . $ID . " ";
$DB->Query($strSql, False, "File: " . __FILE__ . "<br>Line: " . __LINE__);
unset($GLOBALS["BLOG_USER"]["BLOG_USER_CACHE_" . $ID]);
unset($GLOBALS["BLOG_USER"]["BLOG_USER1_CACHE_" . $arUser["USER_ID"]]);
} else {
$ID = false;
}
if ($ID && !(count($arFields1) == 1 && strlen($arFields1["LAST_VISIT"]) > 0)) {
if (CModule::IncludeModule("search")) {
$arBlogUser = CBlogUser::GetByID($ID);
$dbUser = CUser::GetByID($arBlogUser["USER_ID"]);
$arUser = $dbUser->Fetch();
$arBlog = CBlog::GetByOwnerID($arBlogUser["USER_ID"]);
if ($arBlog) {
$arGroup = CBlogGroup::GetByID($arBlog["GROUP_ID"]);
if (strlen($path) > 0) {
$arPostSite = array($arGroup["SITE_ID"] => $path);
} else {
$arPostSite = array($arGroup["SITE_ID"] => CBlogUser::PreparePath($arBlogUser["USER_ID"], $arGroup["SITE_ID"]));
}
} else {
if (strlen($arUser["LID"]) <= 0) {
$arUser["LID"] = SITE_ID;
}
if (strlen($path) > 0) {
$arPostSite = array($arUser["LID"] => $path);
} else {
$arPostSite = array($arUser["LID"] => CBlogUser::PreparePath($arBlogUser["USER_ID"], $arUser["LID"]));
}
}
if (strlen($arBlogUser["LAST_VISIT"]) <= 0) {
$arBlogUser["LAST_VISIT"] = ConvertTimeStamp(false, "FULL", false);
}
$arSearchIndex = array("SITE_ID" => $arPostSite, "LAST_MODIFIED" => $arBlogUser["LAST_VISIT"], "PARAM1" => "USER", "PARAM2" => $arBlogUser["USER_ID"], "PERMISSIONS" => array(2), "TITLE" => CBlogUser::GetUserName($arBlogUser["ALIAS"], $arUser["NAME"], $arUser["LAST_NAME"], $arUser["LOGIN"], $arUser["SECOND_NAME"]), "BODY" => blogTextParser::killAllTags($arBlogUser["INTERESTS"] . " " . $arBlogUser["DESCRIPTION"]));
CSearch::Index("blog", "U" . $ID, $arSearchIndex);
}
}
return $ID;
}
示例3: _UploadFile
/**
* @return integer id of file in table b_file
*/
protected static function _UploadFile($fieldNameInDB, $arData)
{
if (!is_array($arData)) {
throw new LearnException('EA_PARAMS: ' . var_export($arData, true), LearnException::EXC_ERR_GN_CHECK_PARAMS);
}
// Check for fields needed by CFile::SaveForDB
$fieldsMustBe = array('name', 'size', 'tmp_name', 'type', 'del', 'MODULE_ID');
if (count(array_diff($fieldsMustBe, array_keys($arData))) !== 0) {
throw new LearnException('EA_PARAMS: some fields not found', LearnException::EXC_ERR_GN_CHECK_PARAMS);
}
if ($arData['del'] !== 'Y') {
$arData['del'] = '';
}
// we can't use N' due to bug in CFile::SaveToDB();
$arFileData = array($fieldNameInDB => $arData);
$rc = CFile::SaveForDB($arFileData, $fieldNameInDB, 'learning');
// learning - is folder in /upload
// This is workaround caused by bug in CFile::SaveToDB();
if ($rc === false && $arData['name'] == '' && $arData['del'] !== 'Y') {
// We are not deleting file and not uploading new, so return FALSE, what means no image's ID updates occured
return false;
}
if ($rc === false || !isset($arFileData[$fieldNameInDB]) || $arData['del'] !== 'Y' && $arFileData[$fieldNameInDB] === false) {
throw new LearnException('EA_OTHER: file uploading error: ' . var_export($rc, true) . '; ' . var_export($arFileData, true) . '; ' . var_export($arData, true), LearnException::EXC_ERR_GN_FILE_UPLOAD);
}
// If file removed - return NULL
if ($arFileData[$fieldNameInDB] === false) {
$fileId = NULL;
} else {
$fileId = intval($arFileData[$fieldNameInDB]);
}
return $fileId;
}
示例4: Update
function Update($ID, $arFields, $bSearchIndex = true)
{
global $DB;
$ID = IntVal($ID);
if(strlen($arFields["PATH"]) > 0)
$arFields["PATH"] = str_replace("#post_id#", $ID, $arFields["PATH"]);
$arFields1 = array();
foreach ($arFields as $key => $value)
{
if (substr($key, 0, 1) == "=")
{
$arFields1[substr($key, 1)] = $value;
unset($arFields[$key]);
}
}
if (!CBlogPost::CheckFields("UPDATE", $arFields, $ID))
return false;
elseif(!$GLOBALS["USER_FIELD_MANAGER"]->CheckFields("BLOG_POST", $ID, $arFields))
return false;
foreach(GetModuleEvents("blog", "OnBeforePostUpdate", true) as $arEvent)
{
if (ExecuteModuleEventEx($arEvent, Array($ID, &$arFields))===false)
return false;
}
$arOldPost = CBlogPost::GetByID($ID);
if(is_array($arFields["ATTACH_IMG"]))
{
if (
!array_key_exists("MODULE_ID", $arFields["ATTACH_IMG"])
|| strlen($arFields["ATTACH_IMG"]["MODULE_ID"]) <= 0
)
$arFields["ATTACH_IMG"]["MODULE_ID"] = "blog";
$prefix = "blog";
if(strlen($arFields["URL"]) > 0)
$prefix .= "/".$arFields["URL"];
CFile::SaveForDB($arFields, "ATTACH_IMG", $prefix);
}
$strUpdate = $DB->PrepareUpdate("b_blog_post", $arFields);
foreach ($arFields1 as $key => $value)
{
if (strlen($strUpdate) > 0)
$strUpdate .= ", ";
$strUpdate .= $key."=".$value." ";
}
if (strlen($strUpdate) > 0)
{
$oldPostPerms = CBlogUserGroup::GetGroupPerms(1, $arOldPost["BLOG_ID"], $ID, BLOG_PERMS_POST);
$strSql =
"UPDATE b_blog_post SET ".
" ".$strUpdate." ".
"WHERE ID = ".$ID." ";
$DB->Query($strSql, False, "File: ".__FILE__."<br>Line: ".__LINE__);
unset($GLOBALS["BLOG_POST"]["BLOG_POST_CACHE_".$ID]);
foreach(GetModuleEvents("blog", "OnBeforePostUserFieldUpdate", true) as $arEvent)
ExecuteModuleEventEx($arEvent, Array("BLOG_POST", $ID, $arFields));
$GLOBALS["USER_FIELD_MANAGER"]->Update("BLOG_POST", $ID, $arFields);
}
else
{
$ID = False;
}
if ($ID)
{
$arNewPost = CBlogPost::GetByID($ID);
if($arNewPost["PUBLISH_STATUS"] != $arOldPost["PUBLISH_STATUS"] || $arNewPost["BLOG_ID"] != $arOldPost["BLOG_ID"])
CBlog::SetStat($arNewPost["BLOG_ID"]);
if ($arNewPost["BLOG_ID"] != $arOldPost["BLOG_ID"])
CBlog::SetStat($arOldPost["BLOG_ID"]);
if (is_set($arFields, "PERMS_POST"))
CBlogPost::SetPostPerms($ID, $arFields["PERMS_POST"], BLOG_PERMS_POST);
if (is_set($arFields, "PERMS_COMMENT"))
CBlogPost::SetPostPerms($ID, $arFields["PERMS_COMMENT"], BLOG_PERMS_COMMENT);
if(array_key_exists("SOCNET_RIGHTS", $arFields))
{
$arFields["SC_PERM_OLD"] = CBlogPost::GetSocNetPermsCode($ID);
$arFields["SC_PERM"] = CBlogPost::UpdateSocNetPerms($ID, $arFields["SOCNET_RIGHTS"], $arNewPost);
}
foreach(GetModuleEvents("blog", "OnPostUpdate", true) as $arEvent)
ExecuteModuleEventEx($arEvent, Array($ID, &$arFields));
if ($bSearchIndex && CModule::IncludeModule("search"))
//.........这里部分代码省略.........
示例5: Update
function Update($ID, $arFields, $arOptions = array())
{
global $DB;
$ID = intval($ID);
if ($ID <= 0 || !CSaleDelivery::CheckFields("UPDATE", $arFields))
return false;
if (array_key_exists("LOGOTIP", $arFields) && is_array($arFields["LOGOTIP"]))
$arFields["LOGOTIP"]["MODULE_ID"] = "sale";
CFile::SaveForDB($arFields, "LOGOTIP", "sale/delivery/logotip");
$strUpdate = $DB->PrepareUpdate("b_sale_delivery", $arFields);
$strSql = "UPDATE b_sale_delivery SET ".$strUpdate." WHERE ID = ".$ID."";
$DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__);
if (is_set($arFields, "LOCATIONS"))
{
if(CSaleLocation::isLocationProMigrated())
{
Helper::resetLocationsForEntity($ID, $arFields['LOCATIONS'], self::CONN_ENTITY_NAME, !!$arOptions['EXPECT_LOCATION_CODES']);
}
else
{
$DB->Query("DELETE FROM b_sale_delivery2location WHERE DELIVERY_ID = ".$ID."");
$countarFieldLoc = count($arFields["LOCATIONS"]);
for ($i = 0; $i < $countarFieldLoc; $i++)
{
// change location id to location code
$arFields["LOCATIONS"][$i]['LOCATION_CODE'] = $arFields["LOCATIONS"][$i]['LOCATION_ID'];
unset($arFields["LOCATIONS"][$i]['LOCATION_ID']);
$arInsert = $DB->PrepareInsert("b_sale_delivery2location", $arFields["LOCATIONS"][$i]);
$strSql =
"INSERT INTO b_sale_delivery2location(DELIVERY_ID, ".$arInsert[0].") ".
"VALUES(".$ID.", ".$arInsert[1].")";
$DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__);
}
}
}
if (is_set($arFields, "PAY_SYSTEM"))
{
CSaleDelivery::UpdateDeliveryPay($ID, $arFields["PAY_SYSTEM"]);
}
return $ID;
}
示例6: Update
/**
* <p>Метод изменяет параметры вопроса с идентификатором ID.</p>
*
*
* @param int $ID Идентификатор вопроса.
*
* @param array $arFields Массив <b>Array("поле"=>"значение", ...)</b>. Содержит значения <a
* href="http://dev.1c-bitrix.ru/api_help/learning/fields.php#question">всех полей</a> вопроса.
* Обязательные поля должны быть заполнены. <br>
*
* @return bool <p>Метод возвращает <i>true</i>, если изменение прошло успешно, при
* возникновении ошибки метод вернёт <i>false</i>. При возникновении
* ошибки в исключениях будет содержаться текст ошибки.</p>
*
* <h4>Example</h4>
* <pre>
* <?
* if (CModule::IncludeModule("learning"))
* {
* $QUESTION_ID = 600;
*
* $arFields = Array(
* "ACTIVE" => "N",
* "NAME" => "New name of question",
* "SORT" => "555",
* );
*
* $question = new CLQuestion;
* $success = $question->Update($QUESTION_ID, $arFields);
*
* if($success)
* {
* echo "Ok!";
* }
* else
* {
* if($e = $APPLICATION->GetException())
* echo "Error: ".$e->GetString();
* }
*
* }
* ?>
* </pre>
*
*
* <h4>See Also</h4>
* <ul> <li> <a href="http://dev.1c-bitrix.ru/api_help/learning/fields.php#question">Поля вопроса</a> </li> <li>
* <a href="http://dev.1c-bitrix.ru/api_help/learning/classes/clquestion/index.php">CLQuestion</a>::<a
* href="http://dev.1c-bitrix.ru/api_help/learning/classes/clquestion/add.php">Add</a> </li> </ul> <a name="examples"></a>
*
*
* @static
* @link http://dev.1c-bitrix.ru/api_help/learning/classes/clquestion/update.php
* @author Bitrix
*/
public function Update($ID, $arFields)
{
global $DB, $USER_FIELD_MANAGER;
$ID = intval($ID);
if ($ID < 1) {
return false;
}
if (is_set($arFields, "FILE_ID")) {
if (strlen($arFields["FILE_ID"]["name"]) <= 0 && strlen($arFields["FILE_ID"]["del"]) <= 0 && strlen($arFields["FILE_ID"]["description"]) <= 0) {
unset($arFields["FILE_ID"]);
} else {
$pic_res = $DB->Query("SELECT FILE_ID FROM b_learn_question WHERE ID=" . $ID);
if ($pic_res = $pic_res->Fetch()) {
$arFields["FILE_ID"]["old_file"] = $pic_res["FILE_ID"];
}
}
}
if ($this->CheckFields($arFields, $ID) && $USER_FIELD_MANAGER->CheckFields('LEARNING_QUESTIONS', $ID, $arFields)) {
unset($arFields["ID"]);
$arBinds = array("DESCRIPTION" => $arFields["DESCRIPTION"], 'COMMENT_TEXT' => $arFields['COMMENT_TEXT'], 'INCORRECT_MESSAGE' => $arFields['INCORRECT_MESSAGE']);
if (array_key_exists("FILE_ID", $arFields) && is_array($arFields["FILE_ID"]) && (!array_key_exists("MODULE_ID", $arFields["FILE_ID"]) || strlen($arFields["FILE_ID"]["MODULE_ID"]) <= 0)) {
$arFields["FILE_ID"]["MODULE_ID"] = "learning";
}
CFile::SaveForDB($arFields, "FILE_ID", "learning");
$USER_FIELD_MANAGER->Update('LEARNING_QUESTIONS', $ID, $arFields);
$strUpdate = $DB->PrepareUpdate("b_learn_question", $arFields);
if ($strUpdate !== '') {
$strSql = "UPDATE b_learn_question SET " . $strUpdate . " WHERE ID=" . $ID;
$DB->QueryBind($strSql, $arBinds, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
}
foreach (GetModuleEvents('learning', 'OnAfterQuestionUpdate', true) as $arEvent) {
ExecuteModuleEventEx($arEvent, array($ID, $arFields));
}
return true;
}
return false;
}
示例7: Update
//.........这里部分代码省略.........
foreach ($arFields as $key => $value) {
if (substr($key, 0, 1) == "=") {
$arFields1[substr($key, 1)] = $value;
unset($arFields[$key]);
}
}
if (!CSocNetGroup::CheckFields("UPDATE", $arFields, $ID)) {
return false;
} else {
$arSiteID = array();
if (is_set($arFields, "SITE_ID")) {
if (is_array($arFields["SITE_ID"])) {
$arSiteID = $arFields["SITE_ID"];
} else {
$arSiteID[] = $arFields["SITE_ID"];
}
$arFields["SITE_ID"] = false;
$str_SiteID = "''";
foreach ($arSiteID as $v) {
$arFields["SITE_ID"] = $v;
$str_SiteID .= ", '" . $DB->ForSql($v) . "'";
}
}
}
$db_events = GetModuleEvents("socialnetwork", "OnBeforeSocNetGroupUpdate");
while ($arEvent = $db_events->Fetch()) {
if (ExecuteModuleEventEx($arEvent, array($ID, &$arFields)) === false) {
return false;
}
}
if (array_key_exists("IMAGE_ID", $arFields) && is_array($arFields["IMAGE_ID"]) && (!array_key_exists("MODULE_ID", $arFields["IMAGE_ID"]) || strlen($arFields["IMAGE_ID"]["MODULE_ID"]) <= 0)) {
$arFields["IMAGE_ID"]["MODULE_ID"] = "socialnetwork";
}
CFile::SaveForDB($arFields, "IMAGE_ID", "socialnetwork");
$strUpdate = $DB->PrepareUpdate("b_sonet_group", $arFields);
foreach ($arFields1 as $key => $value) {
if (strlen($strUpdate) > 0) {
$strUpdate .= ", ";
}
$strUpdate .= $key . "=" . $value . " ";
}
if (strlen($strUpdate) > 0) {
$strSql = "UPDATE b_sonet_group SET " . "\t" . $strUpdate . " " . "WHERE ID = " . $ID . " ";
$DB->Query($strSql, False, "File: " . __FILE__ . "<br>Line: " . __LINE__);
if (count($arSiteID) > 0) {
$strSql = "DELETE FROM b_sonet_group_site WHERE GROUP_ID=" . $ID;
$DB->Query($strSql, false, "FILE: " . __FILE__ . "<br> LINE: " . __LINE__);
$strSql = "INSERT INTO b_sonet_group_site(GROUP_ID, SITE_ID) " . "SELECT " . $ID . ", LID " . "FROM b_lang " . "WHERE LID IN (" . $str_SiteID . ") ";
$DB->Query($strSql, false, "FILE: " . __FILE__ . "<br> LINE: " . __LINE__);
$arLogID = array();
$dbResult = CSocNetLog::GetList(array(), array("LOG_RIGHTS" => "SG" . $ID), false, false, array("ID"));
while ($arResult = $dbResult->Fetch()) {
$DB->Query("DELETE FROM b_sonet_log_site WHERE LOG_ID = " . $arResult["ID"] . "", false, "FILE: " . __FILE__ . "<br> LINE: " . __LINE__);
$DB->Query("\n\t\t\t\t\t\tINSERT INTO b_sonet_log_site(LOG_ID, SITE_ID)\n\t\t\t\t\t\tSELECT " . $arResult["ID"] . ", LID\n\t\t\t\t\t\tFROM b_lang\n\t\t\t\t\t\tWHERE LID IN (" . $str_SiteID . ")\n\t\t\t\t\t", false, "FILE: " . __FILE__ . "<br> LINE: " . __LINE__);
$arLogID[] = $arResult["ID"];
}
$dbResult = CSocNetLog::GetList(array(), array("!ID" => $arLogID, "ENTITY_ID" => $ID, "ENTITY_TYPE" => SONET_ENTITY_GROUP), false, false, array("ID"));
while ($arResult = $dbResult->Fetch()) {
$DB->Query("DELETE FROM b_sonet_log_site WHERE LOG_ID = " . $arResult["ID"] . "", false, "FILE: " . __FILE__ . "<br> LINE: " . __LINE__);
$DB->Query("\n\t\t\t\t\t\tINSERT INTO b_sonet_log_site(LOG_ID, SITE_ID)\n\t\t\t\t\t\tSELECT " . $arResult["ID"] . ", LID\n\t\t\t\t\t\tFROM b_lang\n\t\t\t\t\t\tWHERE LID IN (" . $str_SiteID . ")\n\t\t\t\t\t", false, "FILE: " . __FILE__ . "<br> LINE: " . __LINE__);
}
}
unset($GLOBALS["SONET_GROUP_CACHE"][$ID]);
if (defined("BX_COMP_MANAGED_CACHE")) {
if ($bClearCommonTag) {
$GLOBALS["CACHE_MANAGER"]->ClearByTag("sonet_group");
示例8: Update
function Update($ID, $arFields)
{
global $DB;
$ID = IntVal($ID);
if (!CSalePaySystemAction::CheckFields("UPDATE", $arFields)) {
return false;
}
if (array_key_exists("LOGOTIP", $arFields) && is_array($arFields["LOGOTIP"])) {
$arFields["LOGOTIP"]["MODULE_ID"] = "sale";
}
CFile::SaveForDB($arFields, "LOGOTIP", "sale/paysystem/logotip");
$strUpdate = $DB->PrepareUpdate("b_sale_pay_system_action", $arFields);
$strSql = "UPDATE b_sale_pay_system_action SET " . $strUpdate . " WHERE ID = " . $ID . "";
$DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
return $ID;
}
示例9: Update
//.........这里部分代码省略.........
* href="http://dev.1c-bitrix.ru/api_help/learning/fields.php#question">всех полей</a> вопроса.
* Обязательные поля должны быть заполнены. <br>
*
*
*
* @return bool <p>Метод возвращает <i>true</i>, если изменение прошло успешно, при
* возникновении ошибки функция вернёт <i>false</i>. При возникновении
* ошибки в исключениях будет содержаться текст ошибки.</p>
*
*
* <h4>Example</h4>
* <pre>
* <?
* if (CModule::IncludeModule("learning"))
* {
* $QUESTION_ID = 600;
*
* $arFields = Array(
* "ACTIVE" => "N",
* "NAME" => "New name of question",
* "SORT" => "555",
* );
*
* $question = new CLQuestion;
* $success = $question->Update($QUESTION_ID, $arFields);
*
* if($success)
* {
* echo "Ok!";
* }
* else
* {
* if($e = $APPLICATION->GetException())
* echo "Error: ".$e->GetString();
* }
*
* }
* ?>
* </pre>
*
*
*
* <h4>See Also</h4>
* <ul> <li> <a href="http://dev.1c-bitrix.ru/api_help/learning/fields.php#question">Поля вопроса</a> </li> <li>
* <a href="http://dev.1c-bitrix.ru/api_help/learning/classes/clquestion/index.php">CLQuestion</a>::<a
* href="http://dev.1c-bitrix.ru/api_help/learning/classes/clquestion/add.php">Add</a> </li> </ul><a name="examples"></a>
*
*
* @link http://dev.1c-bitrix.ru/api_help/learning/classes/clquestion/update.php
* @author Bitrix
*/
public function Update($ID, $arFields)
{
global $DB;
$ID = intval($ID);
if ($ID < 1) return false;
if (is_set($arFields, "FILE_ID"))
{
if(strlen($arFields["FILE_ID"]["name"])<=0 && strlen($arFields["FILE_ID"]["del"])<=0 && strlen($arFields["FILE_ID"]["description"])<=0)
unset($arFields["FILE_ID"]);
else
{
$pic_res = $DB->Query("SELECT FILE_ID FROM b_learn_question WHERE ID=".$ID);
if($pic_res = $pic_res->Fetch())
$arFields["FILE_ID"]["old_file"]=$pic_res["FILE_ID"];
}
}
if ($this->CheckFields($arFields, $ID))
{
unset($arFields["ID"]);
$arBinds=Array(
"DESCRIPTION" => $arFields["DESCRIPTION"],
'COMMENT_TEXT' => $arFields['COMMENT_TEXT'],
'INCORRECT_MESSAGE' => $arFields['INCORRECT_MESSAGE']
);
if (
array_key_exists("FILE_ID", $arFields)
&& is_array($arFields["FILE_ID"])
&& (
!array_key_exists("MODULE_ID", $arFields["FILE_ID"])
|| strlen($arFields["FILE_ID"]["MODULE_ID"]) <= 0
)
)
$arFields["FILE_ID"]["MODULE_ID"] = "learning";
CFile::SaveForDB($arFields, "FILE_ID", "learning");
$strUpdate = $DB->PrepareUpdate("b_learn_question", $arFields);
$strSql = "UPDATE b_learn_question SET ".$strUpdate." WHERE ID=".$ID;
$DB->QueryBind($strSql, $arBinds, false, "File: ".__FILE__."<br>Line: ".__LINE__);
return true;
}
return false;
}
示例10: CheckFields
protected function CheckFields($action, &$arFields)
{
global $USER;
if ($action === 'ADD') {
if (isset($arFields["EXTERNAL_AUTH_ID"]) && strlen($arFields["EXTERNAL_AUTH_ID"]) <= 0) {
return false;
}
if (isset($arFields["SITE_ID"]) && strlen($arFields["SITE_ID"]) <= 0) {
$arFields["SITE_ID"] = SITE_ID;
}
if (!isset($arFields["USER_ID"])) {
$arFields["USER_ID"] = $USER->GetID();
}
$dbCheck = CSocServAuthDB::GetList(array(), array("USER_ID" => $arFields["USER_ID"], "EXTERNAL_AUTH_ID" => $arFields["EXTERNAL_AUTH_ID"]), false, false, array("ID"));
if ($dbCheck->Fetch()) {
return false;
}
}
if (is_set($arFields, "PERSONAL_PHOTO")) {
$res = CFile::CheckImageFile($arFields["PERSONAL_PHOTO"]);
if (strlen($res) > 0) {
unset($arFields["PERSONAL_PHOTO"]);
} else {
$arFields["PERSONAL_PHOTO"]["MODULE_ID"] = "socialservices";
CFile::SaveForDB($arFields, "PERSONAL_PHOTO", "socialservices");
}
}
return true;
}
示例11: Update
function Update($id, $fields)
{
if (\Bitrix\Main\Config\Option::get('main', '~sale_paysystem_converted') == 'Y') {
$id = (int) $id;
if (isset($fields['ACTION_FILE'])) {
$map = self::getOldToNewHandlersMap();
if (isset($map[$fields['ACTION_FILE']])) {
$fields['ACTION_FILE'] = $map[$fields['ACTION_FILE']];
}
}
if (!CSalePaySystemAction::CheckFields("UPDATE", $fields)) {
return false;
}
if (array_key_exists("LOGOTIP", $fields) && is_array($fields["LOGOTIP"])) {
$fields["LOGOTIP"]["MODULE_ID"] = "sale";
}
CFile::SaveForDB($fields, "LOGOTIP", "sale/paysystem/logotip");
if (isset($fields['PARAMS'])) {
$params = unserialize($fields['PARAMS']);
if (!isset($params['BX_PAY_SYSTEM_ID'])) {
$params['BX_PAY_SYSTEM_ID'] = array('TYPE' => '', 'VALUE' => $id);
}
$fields['PARAMS'] = serialize($params);
}
$result = PaySystemActionTable::update($id, $fields);
if ($result->isSuccess()) {
if (array_key_exists('PARAMS', $fields)) {
$params = self::prepareParamsForBusVal($id, $fields);
foreach ($params as $item) {
\Bitrix\Sale\BusinessValue::setMapping($item['CODE'], $item['CONSUMER'], $item['PERSON_TYPE_ID'], $item['MAP']);
}
}
if ($fields['PERSON_TYPE_ID']) {
$params = array('filter' => array("SERVICE_ID" => $id, "SERVICE_TYPE" => \Bitrix\Sale\Services\PaySystem\Restrictions\Manager::SERVICE_TYPE_PAYMENT, "=CLASS_NAME" => '\\Bitrix\\Sale\\Services\\PaySystem\\Restrictions\\PersonType'));
$dbRes = \Bitrix\Sale\Internals\ServiceRestrictionTable::getList($params);
if ($data = $dbRes->fetch()) {
$restrictionId = $data['ID'];
} else {
$restrictionId = 0;
}
$fields = array("SERVICE_ID" => $id, "SERVICE_TYPE" => \Bitrix\Sale\Services\PaySystem\Restrictions\Manager::SERVICE_TYPE_PAYMENT, "SORT" => 100, "PARAMS" => array('PERSON_TYPE_ID' => array($fields['PERSON_TYPE_ID'])));
\Bitrix\Sale\Services\PaySystem\Restrictions\PersonType::save($fields, $restrictionId);
}
return $id;
}
return false;
} else {
global $DB;
$arFields = $fields;
$ID = IntVal($id);
if (!CSalePaySystemAction::CheckFields("UPDATE", $arFields)) {
return false;
}
if (array_key_exists("LOGOTIP", $arFields) && is_array($arFields["LOGOTIP"])) {
$arFields["LOGOTIP"]["MODULE_ID"] = "sale";
}
CFile::SaveForDB($arFields, "LOGOTIP", "sale/paysystem/logotip");
$strUpdate = $DB->PrepareUpdate("b_sale_pay_system_action", $arFields);
$strSql = "UPDATE b_sale_pay_system_action SET " . $strUpdate . " WHERE ID = " . $ID . "";
$DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
return $ID;
}
}
示例12: Add
/**
* @param $arFields
* @param array $arOptions
* @return bool|int
* @throws Exception
* @deprecated
*/
static function Add($arFields, $arOptions = array())
{
$fields = array_intersect_key($arFields, Bitrix\Sale\Delivery\Services\Table::getMap());
if (array_key_exists("LOGOTIP", $arFields) && is_array($arFields["LOGOTIP"])) {
$arFields["LOGOTIP"]["MODULE_ID"] = "sale";
CFile::SaveForDB($arFields, "LOGOTIP", "sale/delivery/logotip");
$fields["LOGOTIP"] = $arFields["LOGOTIP"];
}
$fields["CODE"] = isset($arFields["CODE"]) ? $arFields["CODE"] : strval(mktime());
$fields["PARENT_ID"] = 0;
$fields["CLASS_NAME"] = '\\Bitrix\\Sale\\Delivery\\Services\\Configurable';
$fields["CONFIG"] = array("MAIN" => array("PRICE" => $arFields["PRICE"], "PERIOD" => array("FROM" => $arFields["PERIOD_FROM"], "TO" => $arFields["PERIOD_TO"], "TYPE" => $arFields["PERIOD_TYPE"])));
$res = \Bitrix\Sale\Delivery\Services\Table::add($fields);
if (!$res->isSuccess()) {
return false;
}
$newId = $res->getId();
$res = \Bitrix\Sale\Delivery\Restrictions\Table::add(array("DELIVERY_ID" => $newId, "CLASS_NAME" => '\\Bitrix\\Sale\\Delivery\\Restrictions\\BySite', "PARAMS" => array("SITE_ID" => array($arFields["LID"]))));
if (intval($arFields["WEIGHT_FROM"]) > 0 || intval($arFields["WEIGHT_TO"]) > 0) {
$res = \Bitrix\Sale\Delivery\Restrictions\Table::add(array("DELIVERY_ID" => $newId, "CLASS_NAME" => '\\Bitrix\\Sale\\Delivery\\Restrictions\\ByWeight', "PARAMS" => array("MIN_WEIGHT" => $arFields["WEIGHT_FROM"], "MAX_WEIGHT" => $arFields["WEIGHT_TO"])));
}
if (intval($arFields["ORDER_PRICE_FROM"]) > 0 || intval($arFields["ORDER_PRICE_TO"]) > 0) {
$res = \Bitrix\Sale\Delivery\Restrictions\Table::add(array("DELIVERY_ID" => $newId, "CLASS_NAME" => '\\Bitrix\\Sale\\Delivery\\Restrictions\\ByPrice', "PARAMS" => array("MIN_PRICE" => $arFields["ORDER_PRICE_FROM"], "MAX_PRICE" => $arFields["ORDER_PRICE_TO"], "CURRENCY" => $arFields["ORDER_CURRENCY"])));
}
if (isset($arFields["LOCATIONS"]) && is_array($arFields["LOCATIONS"])) {
Helper::resetLocationsForEntity($newId, $arFields['LOCATIONS'], self::CONN_ENTITY_NAME, !!$arOptions['EXPECT_LOCATION_CODES']);
}
if (isset($arFields["PAY_SYSTEM"])) {
CSaleDelivery::UpdateDeliveryPay($newId, $arFields["PAY_SYSTEM"]);
}
if (isset($arFields["STORE"])) {
$stores = unserialize($arFields["STORE"]);
if ($stores) {
\Bitrix\Sale\Delivery\ExtraServices\Manager::saveStores($newId, $stores);
}
}
return $newId;
}
示例13: Set
function Set($SID, $arData, $SITE_ID = false)
{
if(!self::CheckFields($arData))
return false;
if ($SITE_ID == 'ALL')
$SITE_ID = false;
if (!defined('SALE_DH_INITIALIZED'))
CSaleDeliveryHandler::Initialize();
global $APPLICATION, $DB;
$rsHandlerDataFull = CSaleDeliveryHandler::GetBySID($SID, $SITE_ID);
if ($arHandlerDataFull = $rsHandlerDataFull->Fetch())
{
$bInstalled = $arHandlerDataFull["INSTALLED"] == "Y";
$DB->StartTransaction();
$arQueryFields = array();
if ($SITE_ID)
$arQueryFields["LID"] = "'".($SITE_ID == "ALL" ? "" : $DB->ForSql($SITE_ID))."'";
else
$arQueryFields["LID"] = "''";
if (is_set($arData, "ACTIVE"))
$arQueryFields["ACTIVE"] = $arData["ACTIVE"] == 'Y' ? "'Y'" : "'N'";
elseif ($bInstalled)
$arQueryFields["ACTIVE"] = "'N'";
if (!$bInstalled)
{
$arQueryFields["HID"] = "'".$DB->ForSql($SID)."'";
}
if (is_set($arData, "SORT"))
$arQueryFields["SORT"] = "'".intval($arData["SORT"])."'";
elseif (!$bInstalled)
$arQueryFields["SORT"] = '100';
if (is_set($arData, "NAME"))
$arQueryFields["NAME"] = "'".$DB->ForSql($arData["NAME"])."'";
elseif (!$bInstalled)
$arQueryFields["NAME"] = "'".$DB->ForSql($arHandlerDataFull['NAME'])."'";
if (is_set($arData, "DESCRIPTION"))
$arQueryFields["DESCRIPTION"] = "'".$DB->ForSql($arData["DESCRIPTION"])."'";
elseif (!$bInstalled)
$arQueryFields["DESCRIPTION"] = "'".$DB->ForSql($arHandlerDataFull['DESCRIPTION'])."'";
if (is_set($arData, "HANDLER"))
$arQueryFields["HANDLER"] = "'".$DB->ForSql($arData["HANDLER"])."'";
elseif (!$bInstalled)
$arQueryFields["HANDLER"] = "'".$DB->ForSql($arHandlerDataFull['HANDLER'])."'";
if (is_set($arData, "TAX_RATE"))
$arQueryFields["TAX_RATE"] = "'".doubleval($arData["TAX_RATE"])."'";
elseif (!$bInstalled)
$arQueryFields["TAX_RATE"] = 0;
if (is_set($arData, "BASE_CURRENCY"))
$arQueryFields["BASE_CURRENCY"] = "'".$DB->ForSql($arData["BASE_CURRENCY"])."'";
elseif (!$bInstalled)
$arQueryFields["BASE_CURRENCY"] = '';
//save logotip
if (!$bInstalled && (!isset($arData["LOGOTIP"]) || count($arData["LOGOTIP"]) <= 1))
{
$logo = "";
if (is_set($arData, "HANDLER"))
$arPath = pathinfo($arData["HANDLER"]);
elseif (!$bInstalled)
$arPath = pathinfo($arHandlerDataFull["HANDLER"]);
if (!strpos($arPath["dirname"], ":"))
$arPath["dirname"] = $_SERVER["DOCUMENT_ROOT"].$arPath["dirname"];
if (file_exists($arPath["dirname"]."/".$SID."_logo.png"))
$logo = $arPath["dirname"]."/".$SID."_logo.png";
elseif (file_exists($arPath["dirname"]."/".$SID."_logo.jpg"))
$logo = $arPath["dirname"]."/".$SID."_logo.jpg";
elseif (file_exists($arPath["dirname"]."/".$SID."_logo.gif"))
$logo = $arPath["dirname"]."/".$SID."_logo.gif";
if(strlen($logo) > 0)
{
$arData["LOGOTIP"] = CFile::MakeFileArray($logo);
$arData["LOGOTIP"]["MODULE_ID"] = "sale";
}
}
$bDelLogotip = false;
if ($arData["LOGOTIP"]["del"] == "Y")
$bDelLogotip = true;
CFile::SaveForDB($arData, "LOGOTIP", "sale/delivery/logotip");
//.........这里部分代码省略.........
示例14: Set
/** @deprecated */
public static function Set($code, $arData, $siteId = false)
{
global $APPLICATION;
$serviceParams = self::getServiceParams($code, $siteId);
$id = isset($serviceParams["ID"]) ? $serviceParams["ID"] : false;
$update = intval($id) > 0;
$fields = array_intersect_key($arData, Bitrix\Sale\Delivery\Services\Table::getMap());
if (!$update) {
$fields["CODE"] = $code;
if (!isset($arData["CLASS_NAME"])) {
$fields["CLASS_NAME"] = '\\Bitrix\\Sale\\Delivery\\Services\\Automatic';
} else {
$fields["CLASS_NAME"] = $arData["CLASS_NAME"];
}
}
if (isset($arData["PARENT_ID"])) {
$fields["PARENT_ID"] = $arData["PARENT_ID"];
} elseif (!$update) {
$fields["PARENT_ID"] = 0;
}
if (!defined('SALE_DH_INITIALIZED')) {
CSaleDeliveryHandler::Initialize();
}
$handlers = self::__getRegisteredHandlers();
if (isset($serviceParams["CONFIG"])) {
$fields["CONFIG"] = $serviceParams["CONFIG"];
} else {
$fields["CONFIG"] = array();
}
if (isset($arData["CONFIG"])) {
if (isset($handlers[$code]["DBSETSETTINGS"]) && is_callable($handlers[$code]["DBSETSETTINGS"])) {
if (!($strOldSettings = call_user_func($handlers[$code]["DBSETSETTINGS"], $arData["CONFIG"]))) {
$APPLICATION->ThrowException("Can't save delivery services's old settings");
return false;
}
} else {
$strOldSettings = $arData["CONFIG"];
}
$strOldSettings = serialize($strOldSettings);
$fields["CONFIG"]["MAIN"]["OLD_SETTINGS"] = $strOldSettings;
}
if (!empty($arData["BASE_CURRENCY"])) {
$fields["CURRENCY"] = $arData["BASE_CURRENCY"];
} elseif (!empty($serviceParams["CURRENCY"])) {
$fields["CURRENCY"] = $serviceParams["CURRENCY"];
} elseif (!empty($handlers[$code]["BASE_CURRENCY"])) {
$fields["CURRENCY"] = $handlers[$code]["BASE_CURRENCY"];
} else {
$fields["CURRENCY"] = COption::GetOptionString('sale', 'default_currency', 'RUB');
}
if (isset($arData["SID"])) {
$fields["CONFIG"]["MAIN"]["SID"] = $arData["SID"];
} else {
$fields["CONFIG"]["MAIN"]["SID"] = "";
}
if (isset($arData["TAX_RATE"]) && floatval($arData["TAX_RATE"]) > 0) {
$fields["CONFIG"]["MAIN"]["MARGIN_VALUE"] = $arData["TAX_RATE"];
$fields["CONFIG"]["MAIN"]["MARGIN_TYPE"] = "%";
} elseif (!$update) {
$fields["CONFIG"]["MAIN"]["MARGIN"] = 0;
}
if (isset($arData["PROFILE_ID"])) {
$fields["CONFIG"]["MAIN"]["PROFILE_ID"] = $arData["PROFILE_ID"];
} else {
$fields["CONFIG"]["MAIN"]["PROFILE_ID"] = "";
}
if (isset($arData["LOGOTIP"]) && is_array($arData["LOGOTIP"])) {
$fields["LOGOTIP"] = $arData["LOGOTIP"];
$fields["LOGOTIP"]["MODULE_ID"] = "sale";
CFile::SaveForDB($fields, "LOGOTIP", "sale/delivery/logotip");
}
if ($update) {
$res = \Bitrix\Sale\Delivery\Services\Table::update($id, $fields);
} else {
$res = \Bitrix\Sale\Delivery\Services\Table::add($fields);
}
if (!$res->isSuccess()) {
throw new \Bitrix\Main\SystemException(implode("\n", $res->getErrorMessages()));
}
if (!$update) {
$id = $res->getId();
}
if (is_array($arData["PROFILES"])) {
foreach ($arData["PROFILES"] as $profileCode => $profileData) {
self::Set($code . ":" . $profileCode, array("NAME" => strlen($profileData["TITLE"]) > 0 ? $profileData["TITLE"] : $handlers[$code]['PROFILES'][$profileCode]['TITLE'], "DESCRIPTION" => isset($profileData["DESCRIPTION"]) ? $profileData["DESCRIPTION"] : '', "ACTIVE" => isset($profileData["ACTIVE"]) ? $profileData["ACTIVE"] : "N", "TAX_RATE" => isset($profileData["TAX_RATE"]) ? $profileData["TAX_RATE"] : 0, "PARENT_ID" => isset($profileData["PARENT_ID"]) ? $profileData["PARENT_ID"] : $id, "SORT" => isset($arData["SORT"]) ? $arData["SORT"] : 100, "RESTRICTIONS_WEIGHT" => isset($profileData["RESTRICTIONS_WEIGHT"]) ? $profileData["RESTRICTIONS_WEIGHT"] : false, "RESTRICTIONS_SUM" => isset($profileData["RESTRICTIONS_SUM"]) ? $profileData["RESTRICTIONS_SUM"] : false, "RESTRICTIONS_DIMENSIONS" => isset($profileData["RESTRICTIONS_DIMENSIONS"]) ? $profileData["RESTRICTIONS_DIMENSIONS"] : false, "RESTRICTIONS_MAX_SIZE" => isset($profileData["RESTRICTIONS_MAX_SIZE"]) ? $profileData["RESTRICTIONS_MAX_SIZE"] : 0, "RESTRICTIONS_DIMENSIONS_SUM" => isset($profileData["RESTRICTIONS_DIMENSIONS_SUM"]) ? $profileData["RESTRICTIONS_DIMENSIONS_SUM"] : 0, "CLASS_NAME" => '\\Bitrix\\Sale\\Delivery\\Services\\AutomaticProfile', "PROFILE_ID" => $profileCode), strlen($siteId) > 0 ? $siteId : "");
}
}
if (strlen($siteId) > 0) {
if (!self::saveRestrictionBySiteId($id, $siteId, $update)) {
$APPLICATION->ThrowException("Can't save delivery restriction by site", "SITE_ID");
return false;
}
} elseif ($update) {
\Bitrix\Sale\Delivery\Restrictions\Table::deleteByDeliveryIdClassName($id, '\\Bitrix\\Sale\\Delivery\\Restrictions\\BySite');
}
if (is_array($arData["RESTRICTIONS_WEIGHT"]) && (floatval($arData["RESTRICTIONS_WEIGHT"][0]) > 0 || floatval($arData["RESTRICTIONS_WEIGHT"][1]) > 0)) {
if (!self::saveRestrictionByWeight($id, $arData["RESTRICTIONS_WEIGHT"], $update)) {
$APPLICATION->ThrowException("Can't save delivery restriction by weight", "RESTRICTIONS_WEIGHT");
return false;
//.........这里部分代码省略.........
示例15: array
$changedFields = $_POST["CHANGED_FIELDS"];
} else {
$changedFields = array();
}
if (isset($_POST["ACTIVE"]) && $_POST["ACTIVE"] == "Y") {
$fields["ACTIVE"] = "Y";
} else {
$fields["ACTIVE"] = "N";
}
if (array_key_exists("LOGOTIP", $_FILES) && $_FILES["LOGOTIP"]["error"] == 0) {
$imageFileError = CFile::CheckImageFile($_FILES["LOGOTIP"]);
if (is_null($imageFileError)) {
$fields["LOGOTIP"] = $_FILES["LOGOTIP"];
$fields["LOGOTIP"]["del"] = trim($_POST["LOGOTIP_del"]);
$fields["LOGOTIP"]["MODULE_ID"] = "sale";
CFile::SaveForDB($fields, "LOGOTIP", "sale/delivery/logotip");
} else {
$strError .= $imageFileError . ".<br>";
}
} elseif (isset($_POST["LOGOTIP_FILE_ID"]) && intval($_POST["LOGOTIP_FILE_ID"])) {
$fields["LOGOTIP"] = intval($_POST["LOGOTIP_FILE_ID"]);
}
if ($isItSavingProcess) {
if (strlen($fields["NAME"]) <= 0) {
$strError .= Loc::getMessage("SALE_DSE_ERROR_NO_NAME") . "<br>";
}
if (strlen($fields["CLASS_NAME"]) <= 0) {
$strError .= Loc::getMessage("SALE_DSE_ERROR_NO_CLASS_NAME") . "<br>";
}
if ($strError == '') {
try {