/** * Save video to youtube. * @param Bulletin $model * @param CUploadedFile $video */ public static function processBulletin($model, $video) { if (!empty($video)) { if (is_array($video)) { $video = current($video); } $youtube_id = Upload($video, $model->name, $model->text, 'Animals', 'Tags'); if (!empty($youtube_id)) { $model->youtube_id = $youtube_id; $model->save(); } } }
/** * Process uploaded images. * Save to gallery. * @param Bulletin $model * @param CUploadedFile[] $images */ public static function processImages($model, $images) { if (isset($images) && count($images) > 0) { // configure and save gallery model $gallery = new Gallery(); $gallery->name = false; $gallery->description = false; $gallery->versions = array('small' => array('resize' => array(150, null)), 'medium' => array('resize' => array(800, null))); $gallery->save(); $model->gallery_id = $gallery->id; $model->save(); // go through each uploaded image foreach ($images as $imageFile) { $galleryPhoto = new GalleryPhoto(); $galleryPhoto->gallery_id = $gallery->id; $galleryPhoto->name = ''; $galleryPhoto->description = ''; $galleryPhoto->file_name = $imageFile->getName(); $galleryPhoto->save(); $galleryPhoto->setImage($imageFile->getTempName()); } } }
$app->response->setStatus(401); } }); $app->post('/bulletin', function () use($app) { //admins and super admins can post bulletins $posty = $app->request->post(); $is_admin = in_array($posty['company_id'], $app->jwt->role_admin); $is_super = is_super_admin(); if ($is_super || $is_admin) { $bulletin = new \Bulletin(); $bulletin->company_id = $posty['company_id']; $bulletin->from_user_id = $posty['sender_uid']; $bulletin->message_content = $posty['message_content']; $bulletin->timestamp_queued = time(); $bulletin->timestamp_dequeued = time(); $bulletin->save(); $app->response->setStatus(200); //XXX XXX XXX ## $app_id = '140562'; ## $app_key = '95129dfbfbc16ec4a811'; ## $app_secret = '1a5dac7bf5d8f1fd9c33'; ## $pusher = new Pusher( $app_key, $app_secret, $app_id ); ## $pusher->trigger( 'my_channel'.$posty['recipient_uid'], 'my_event', $posty['message_content']); // Send push notification to every member of the company $company = \Company::find($bulletin->company_id); $push_content = $company->name . ": " . $bulletin->message_content; send_bulletin_push($push_content, $bulletin, $app); } else { $app->response->setStatus(401); } });