public function edit($pk, $fields) { $menu = $this->get($pk); if ($this->db->beginTransaction('menu_edit')) { if (parent::edit($pk, $fields) == true) { if (isset($fields['menu_title']) && $menu['menu_title'] != $fields['menu_title']) { M_Blocks::Instance()->edit($menu['block_id'], array('block_title' => $fields['menu_title'])); } if ($this->db->commit('menu_edit')) { return true; } } $this->db->rollBack('menu_edit'); } return false; }
public function edit($post_id, $fields) { $fields['post_date_update'] = date('Y-m-d H:i:s'); $fields2 = array(); $errors = false; $errorsMLink = array(); // Если есть родительская ссылка для меню if ($errors === false && isset($fields['parent']) && substr_count($fields['parent'], ':') == 1) { $parent = explode(':', $fields['parent']); $menu_id = (int) $parent[0]; $plid = (int) $parent[1]; $mlid = (int) $fields['mlid']; $fields_menu = array(); $fields_menu['link_title'] = $fields['link_title']; $fields_menu['menu_id'] = $menu_id; $fields_menu['plid'] = (int) $plid; $fields_menu['link_description'] = $fields['link_description']; $link = M_Link::ToPage('post', $post_id); $fields_menu['link_path'] = strpos($link, BASE_URL) === 0 ? mb_substr($link, iconv_strlen(BASE_URL)) : $link; $mMenuLink = M_MenuLink::Instance(); if ($mlid == 0) { // Если не было в меню пункта добавляем его if (!($mlid = $mMenuLink->add($fields_menu))) { $errors = true; $errorsMLink = $mMenuLink->errors(); } else { $fields['mlid'] = $mlid; } } else { // иначе обновляем данные пункта меню if ($mMenuLink->edit($mlid, $fields_menu) == false) { $errors = true; $errorsMLink = $mMenuLink->errors(); } } } elseif (isset($fields['parent']) && $fields['parent'] == 0 && isset($fields['mlid']) && $fields['mlid'] > 0) { M_MenuLink::Instance()->delete($fields['mlid']); $fields['mlid'] = 0; } // Обновляем данные самой "записи" if ($errors === false && !parent::edit($post_id, $fields)) { $errors = true; } // Если включена сортировка картинок по папкам if ($errors === false && $this->ck_sort_img_folder === true) { $path = $this->ckupload_dir . 'post_' . $post_id . '/'; if (is_dir($path)) { $this->check_img_uses_in_post($fields['post_content'], $path); } } if ($errors === false) { return true; } $this->errors = array_merge($this->errors, $errorsMLink); return false; }
public function editItemList($fields) { foreach ($fields as $key => $value) { list($field_name, $mlid) = explode('_', $key); $obj = array($field_name => (int) $value); parent::edit($mlid, $obj); } $this->listItems = array(); $this->treeArray = array(); return true; }
public function edit($pk, $fields) { $fields_upd = array(); $fields_del = array(); $fields_add = array(); foreach ($fields['answers'] as $key => $answer) { if (substr(trim($key), 0, 3) == 'new') { if (!empty($answer)) { $fields_add[] = array('answer' => $answer, 'weight' => (int) $fields['weights'][$key], 'pid' => $fields['pid']); } } elseif (is_numeric($key)) { if (!empty($answer)) { $fields_upd[] = array('answer' => $answer, 'weight' => (int) $fields['weights'][$key], 'aid' => (int) $key); } else { $fields_del[] = $key; } } } $count = count($fields_add) + count($fields_upd); //var_dump($fields_add, $fields_upd, $fields_del); die(); if ($count < 2) { $this->errors['answers'] = 'Обязательно минимум 2 заполненых варианта ответа'; return false; } if ($this->db->beginTransaction('poll_edit')) { parent::edit($pk, array('question' => $fields['question'])); $mPollA = M_PollAnswers::Instance(); $count2 = 0; foreach ($fields_add as $add) { if ($mPollA->add($add)) { ++$count2; } } foreach ($fields_upd as $upd) { if ($mPollA->edit($upd['aid'], $upd)) { ++$count2; } } foreach ($fields_del as $aid) { $mPollA->delete($aid); } if ($count2 >= 2 && $this->db->commit('poll_edit')) { return true; } $this->db->rollBack('poll_edit'); } return false; }