Example #1
0
 /**
  * Редактирует объявление как автор.
  * 
  * @param int $id
  * @param String $title
  * @param int $category_id
  * @param String $description
  * @return void
  */
 public static function editAdvertAsOwner($id, $title, $category_id, $description)
 {
     $result = NULL;
     try {
         $result = DB::select(array(DB::expr('COUNT(id)'), 'count'))->from('adverts')->where('title', '=', $title)->and_where('category_id', '=', $category_id)->and_where('description', '=', $description)->and_where('id', '=', $id)->execute();
     } catch (Database_Exception $e) {
         if (is_null(self::$controller)) {
             throw $e;
         } else {
             self::$controller->action_server_error();
         }
         return;
     }
     if ((int) $result->get('count') == 1) {
         self::$controller->action_no_changes();
         return;
     }
     try {
         $result = DB::update('adverts')->set(array('title' => $title, 'category_id' => $category_id, 'description' => $description, 'state' => 'process'))->where('id', '=', $id)->execute();
     } catch (Database_Exception $e) {
         if (is_null(self::$controller)) {
             throw $e;
         } else {
             self::$controller->action_server_error();
         }
         return;
     }
 }