00001 <?php
00002
00003
00004
00005 class NotifyallUsersCommand extends CommandTransactional {
00006
00007
00008
00009 public function get_name() {
00010 return 'notifyall';
00011 }
00012
00013
00014
00015
00016
00017
00018 protected function do_execute() {
00019 $ret = new Status();
00020 Load::models('notifications');
00021
00022 $params = $this->get_params();
00023 $ret->merge($this->validate($params));
00024 if ($ret->is_ok()) {
00025 $title = Arr::get_item($params, 'title', '');
00026 $message = Arr::get_item($params, 'message', '');
00027 $source = Arr::get_item($params, 'source', '');
00028
00029 $ret->merge($this->mass_insert($title, $message, $source));
00030 }
00031 return $ret;
00032 }
00033
00034
00035
00036
00037 protected function mass_insert($title, $message, $source) {
00038 $user = new DAOUsers();
00039 $notification = new DAONotifications();
00040
00041 $select = $user->create_select_query();
00042 $select->set_fields(array(
00043 'id' => 'id_user',
00044 $notification->quote($title) => 'title',
00045 $notification->quote($message) => 'message',
00046 $notification->quote($source) => 'source',
00047 ));
00048
00049 $insert = $notification->create_insert_query();
00050 $insert->set_fields(array(
00051 'id_user', 'title', 'message', 'source'
00052 ));
00053 $insert->set_select($select);
00054 return DB::execute($insert->get_sql(), $notification->get_table_driver());
00055 }
00056
00057
00058
00059
00060 protected function validate($params) {
00061
00062 $user = new DAOUsers();
00063 $user->limit(0, 1);
00064 $user->find(DAOUsers::AUTOFETCH);
00065 $params['id_user'] = $user->id;
00066
00067 $test = new DAONotifications();
00068 $test->read_from_array($params);
00069 return $test->validate();
00070 }
00071 }