Example #1
0
 public static function add($model, $model_id, $status_id)
 {
     $m = new self();
     $m->model = $model;
     $m->model_id = $model_id;
     $m->status_id = $status_id;
     $m->user_id = \Yii::$app->user->id;
     if (!$m->save()) {
         die(var_dump($m->getErrors()));
     }
 }
Example #2
0
 public static function create($link)
 {
     $linkS = new self();
     $linkS->link_id = $link;
     $linkS->user_id = Yii::$app->user->id;
     if (!$linkS->save()) {
         return $linkS->getErrors();
     } else {
         return true;
     }
 }
Example #3
0
 public function create($message, $level, $tag, $userId)
 {
     $model = new self();
     $model->message = $message;
     $model->level = $level;
     $model->time = new \MongoDate(time());
     $model->tag = $tag;
     $model->userId = (int) $userId;
     if ($model->save()) {
         return $model;
     } else {
         throw new ApiException($model->getErrors(), 500);
     }
 }
Example #4
0
 function insertRecords($data)
 {
     $oRecord = new self();
     foreach ($data as $k => $v) {
         $oRecord->{$k} = $v;
     }
     if ($oRecord->validate()) {
         return $oRecord->save();
     }
     tracevar($oRecord->getErrors());
 }
 /**
  * Creates a new survey - does some basic checks of the suppplied data
  *
  * @param array $aData Array with fieldname=>fieldcontents data
  * @return integer The new survey id
  */
 public function insertNewSurvey($aData)
 {
     do {
         if (isset($aData['wishSID'])) {
             $aData['sid'] = $aData['wishSID'];
             unset($aData['wishSID']);
         } else {
             $aData['sid'] = randomChars(6, '123456789');
         }
         $isresult = self::model()->findByPk($aData['sid']);
     } while (!is_null($isresult));
     $survey = new self();
     foreach ($aData as $k => $v) {
         $survey->{$k} = $v;
     }
     $sResult = $survey->save();
     if (!$sResult) {
         tracevar($survey->getErrors());
         return false;
     } else {
         return $aData['sid'];
     }
 }
Example #6
0
 /**
  * Insert an array into the questions table
  * Returns null if insertion fails, otherwise the new QID
  *
  * @param array $data
  */
 function insertRecords($data)
 {
     // This function must be deprecated : don't find a way to have getErrors after (Shnoulle on 131206)
     $oRecord = new self();
     foreach ($data as $k => $v) {
         $oRecord->{$k} = $v;
     }
     if ($oRecord->validate()) {
         $oRecord->save();
         return $oRecord->qid;
     }
     tracevar($oRecord->getErrors());
 }
Example #7
0
 /**
  * 	method:	test
  *
  * 	todo: write documentation
  */
 public static function test($value, $type, $required = false, $options = array())
 {
     $v = new self(array("test" => $value));
     $v->add("test", $type, $required, $options);
     $r = array();
     $r["status"] = $v->execute();
     if ($r["status"]) {
         $d = $v->getValidData();
         $r["value"] = $d["test"];
     } else {
         $e = $v->getErrors();
         $r["error"] = $e["test"]["code"];
         $r["error_value"] = $e["test"]["value"];
     }
     if (!isset($r["value"]) && isset($options["default_value"])) {
         $r["value"] = $options["default_value"];
     }
     return $r && isset($r["value"]) && isset($options["return_value"]) ? $r["value"] : $r;
 }
Example #8
0
 public function wLogEvent($user_id, $user_phone, $eventId, $source, $contentId = '', $contentName = '', $transaction = '', $transactionId = 0, $transaction_name, $log_point)
 {
     try {
         $log = new KLogger('log_event_users_transaction', KLogger::INFO);
         $event = EventModel::model()->findByPk(new MongoId($eventId));
         $point = $event->point;
         if ($log_point == 0) {
             $point = 0;
         }
         $log->LogInfo("{$transaction}|{$user_phone}|{$contentId}|{$point}", false);
         $userSubscribe = true;
         switch ($transaction) {
             case 'play_song':
                 $transactionValid = $this->isContent24h($contentId, $eventId, $user_phone, $transaction);
                 $point = $this->getPoint($contentId, $transaction, $point);
                 $pointValid = $this->isPoint24h($point, $user_phone);
                 break;
             case 'play_video':
                 $transactionValid = $this->isContent24h($contentId, $eventId, $user_phone, $transaction);
                 $point = $this->getPoint($contentId, $transaction, $point);
                 $pointValid = $this->isPoint24h($point, $user_phone);
                 break;
             case 'play_album':
                 $transactionValid = $this->isContent24h($contentId, $eventId, $user_phone, $transaction);
                 $point = $this->getPoint($contentId, $transaction, $point);
                 $pointValid = $this->isPoint24h($point, $user_phone);
                 $userSubscribe = UserSubscribeModel::model()->get($user_phone);
                 break;
             default:
                 $transactionValid = true;
                 $pointValid = true;
                 break;
         }
         if ($transactionValid && $pointValid && $userSubscribe) {
             if ($event && (!empty($user_id) || !empty($user_phone))) {
                 $eventName = $event->name;
                 $groupEventId = $event->group_id;
                 $groupEventName = $event->group_name;
                 $model = new self();
                 $model->user_id = (int) $user_id;
                 $model->user_phone = !empty($user_phone) ? $user_phone : 0;
                 $model->event_id = $eventId;
                 $model->event_name = $eventName;
                 $model->group_id = $groupEventId;
                 $model->group_name = $groupEventName;
                 $model->content_id = $contentId;
                 $model->content_name = $contentName;
                 $model->transaction = $transaction;
                 $model->transaction_name = $transaction_name;
                 $model->transaction_id = (string) $transactionId;
                 $model->point = (int) $point;
                 $model->method = $source;
                 $model->created_time = date('Y-m-d H:i:s');
                 $model->updated_time = date('Y-m-d H:i:s');
                 $res = $model->save();
                 $log->LogInfo('write log ' . $transaction . ' | ' . $user_phone . '|' . $transaction . '|event:' . $eventId . '|' . json_encode($res), false);
                 if (!$res) {
                     $errors = $model->getErrors();
                     $log->LogInfo('update log new:' . json_encode($errors), false);
                 } else {
                     $updatePoint = self::model()->updatePoint($user_id, $user_phone, $point, $event->reset);
                     $log->LogInfo('update point|' . $user_id . '|' . json_encode($user_phone) . ':' . json_encode($updatePoint), false);
                     return $updatePoint;
                 }
                 //return $res;
             }
         }
     } catch (Exception $e) {
         //$e->getMessage();
         $log->LogInfo('update log exception:' . $e->getMessage());
         return false;
     }
     return false;
 }
Example #9
0
 /**
  * Adds placemark to a placemarks table
  * 
  * @param string $coordinates separated with comma world coordinates in
  * 'Lattitude,Longitude' order e.g. '123.456,234.567
  * @param string $zoom map zoom
  * @param int $user_id user's id number, default is current user (Yii::app()->user->id)
  * @param int $status visibility status, like 0 - visible for me 1 - for everyone, ...
  * @return mixed you can't add placemarks when not authenticated so FALSE
  * will be returned, on success returns new placemark id on failure
  * array of errors.
  */
 public static function addPlace($coordinates, $zoom = '14', $file_id = null, $status = 1)
 {
     if (Yii::app()->user->isGuest) {
         return false;
     }
     $placemark = new self();
     $placemark->file_id = $file_id;
     $placemark->lat = $coordinates['lat'];
     $placemark->long = $coordinates['long'];
     $placemark->zoom = $zoom;
     $placemark->created_at = time();
     $placemark->status = $status;
     if ($placemark->save()) {
         return $placemark->id;
     } else {
         return $placemark->getErrors();
     }
 }
Example #10
0
 public static function add($target, $action, $data = null, $log_message = null, $properties = array())
 {
     if (!($_target = AuditType::model()->find('name=?', array($target)))) {
         $_target = new AuditType();
         $_target->name = $target;
         if (!$_target->save()) {
             throw new Exception('Unable to save audit target: ' . print_r($_target->getErrors(), true));
         }
     }
     if (!($_action = AuditAction::model()->find('name=?', array($action)))) {
         $_action = new AuditAction();
         $_action->name = $action;
         if (!$_action->save()) {
             throw new Exception('Unable to save audit action: ' . print_r($_action->getErrors(), true));
         }
     }
     $audit = new self();
     $audit->type_id = $_target->id;
     $audit->action_id = $_action->id;
     $audit->data = $data;
     if (!isset($properties['user_id'])) {
         if (Yii::app()->session['user']) {
             $properties['user_id'] = Yii::app()->session['user']->id;
         }
     }
     if (isset($properties['module'])) {
         if ($et = EventType::model()->find('class_name=?', array($properties['module']))) {
             $properties['event_type_id'] = $et->id;
         } else {
             if (!($module = AuditModule::model()->find('name=?', array($properties['module'])))) {
                 $module = new AuditModule();
                 $module->name = $properties['module'];
                 if (!$module->save()) {
                     throw new Exception('Unable to create audit_module: ' . print_r($module->getErrors(), true));
                 }
             }
             $properties['module_id'] = $module->id;
         }
         unset($properties['module']);
     }
     if (isset($properties['model'])) {
         if (!($model = AuditModel::model()->find('name=?', array($properties['model'])))) {
             $model = new AuditModel();
             $model->name = $properties['model'];
             if (!$model->save()) {
                 throw new Exception('Unable to save audit_model: ' . print_r($model->getErrors(), true));
             }
         }
         $properties['model_id'] = $model->id;
         unset($properties['model']);
     }
     foreach ($properties as $key => $value) {
         $audit->{$key} = $value;
     }
     if (!$audit->save()) {
         throw new Exception('Failed to save audit entry: ' . print_r($audit->getErrors(), true));
     }
     if (isset($properties['user_id'])) {
         $username = User::model()->findByPk($properties['user_id'])->username;
     }
     $log_message && OELog::log($log_message, @$username);
     return $audit;
 }
Example #11
0
 public function create($user, $appId)
 {
     $string = $user->email . $user->password . $user->id . microtime();
     $model = new self();
     $model->access_token = md5($string);
     $model->refresh_token = md5(str_shuffle($string));
     $model->date = time();
     $model->expire = time() + self::EXPIRE_TIME;
     $model->user_id = $user->id;
     $model->_id = $user->id . $appId;
     $model->app_id = $appId;
     if (!$model->save()) {
         throw new ApiException($model->getErrors(), 500);
     }
     return $model;
 }
 /**
 Static validation method of an HTML fragment. Returns an array with the
 following parameters:
 
 - valid (boolean)
 _ errors (string)
 
 @param	fragment	<b>string</b>		HTML content
 @param	charset	<b>string</b>			Document charset
 @return	<b>array</b>
 */
 public static function validate($fragment, $charset = 'UTF-8')
 {
     $o = new self();
     $fragment = $o->getDocument($fragment, $charset);
     if ($o->perform($fragment, $charset)) {
         return array('valid' => true, 'errors' => null);
     } else {
         return array('valid' => false, 'errors' => $o->getErrors());
     }
 }