public function createQuestion(Model $questionable, $data, Model $author)
 {
     $question = new static();
     $question->fill(array_merge($data, ['author_id' => $author->id, 'author_type' => get_class($author)]));
     $questionable->questions()->save($question);
     return $question;
 }
Example #2
0
 public static function create(array $attributes)
 {
     $model = new static();
     $model->fill($attributes);
     $model->save();
     return $model;
 }
 public function createAnswer(Question $question, $data, Model $author)
 {
     $answer = new static();
     $answer->fill(array_merge($data, ['author_id' => $author->id, 'author_type' => get_class($author)]));
     $answer = $question->answers()->save($answer);
     return $answer;
 }
Example #4
0
 /**
  * @param Model $ratingable
  * @param $data
  * @param Model $author
  *
  * @return static
  */
 public function createRating(Model $ratingable, $data, Model $author)
 {
     $rating = new static();
     $rating->fill(array_merge($data, ['author_id' => $author->id, 'author_type' => get_class($author)]));
     $ratingable->ratings()->save($rating);
     return $rating;
 }
Example #5
0
 /**
  * Make a new photo instance from an uploaded file
  *
  * @var $file
  * @return self
  */
 public static function fromForm($file)
 {
     $photo = new static();
     $photo->file = $file;
     $photo->name = $photo->fileName();
     return $photo->fill(['path' => $photo->filePath(), 'thumbnail_path' => $photo->thumbnailPath()]);
 }
 /**
  * @param Model $reviewable
  * @param $data
  * @param Model $author
  *
  * @return static
  */
 public function createReview(Model $reviewable, $data, Model $author)
 {
     $review = new static();
     $review->fill(array_merge($data, ['author_id' => $author->id, 'author_type' => get_class($author)]));
     $reviewable->reviews()->save($review);
     return $review;
 }
 public function createComment(Model $commentable, $data, Model $creator)
 {
     $comment = new static();
     $comment->fill(array_merge($data, ['creator_id' => $creator->id, 'creator_type' => get_class($creator)]));
     $commentable->comments()->save($comment);
     return $comment;
 }
Example #8
0
 public static function fromFileWithEvent(UploadedFile $file, Event $event)
 {
     $photo = new static();
     $photo->file = $file;
     $photo->event = $event;
     $photo->eventInfo = $photo->buildEventArray($photo->event->name, $photo->event->date_start);
     return $photo->fill(['name' => $photo->fileName(), 'path' => $photo->filePath(), 'thumbnail_path' => $photo->thumbnailPath(), 'event_main' => 0]);
 }
 /**
  * Retorna inquilino logado.
  * @return Inquilino
  */
 public static function current()
 {
     $model = new static();
     $info = $model->getConnection()->get('/inquilino');
     $model->fill((array) $info);
     $model->syncOriginal();
     return $model;
 }
Example #10
0
 public static function createFromFile(File $file, AccountInterface $account)
 {
     $baseline = new static();
     $baseline->fill($file->toArray());
     $baseline->account_id = $account->id;
     $baseline->save();
     return $baseline;
 }
Example #11
0
 /**
  * @param array $attributes
  * @return Model
  */
 public static function init($attributes = [])
 {
     $model = new static(Di::getDefault()->get('mongo'), static::getDbName(), static::getSource());
     if (count($attributes) > 0) {
         $model->fill($attributes);
     }
     return $model;
 }
Example #12
0
 /**
  * Assign a user to a project with a role
  *
  * @param  int   $user_id
  * @param  int   $project_id
  * @param  int   $role_id
  * @return void
  */
 public static function assign($user_id, $project_id, $role_id = 0)
 {
     if (!static::check_assign($user_id, $project_id)) {
         $fill = array('user_id' => $user_id, 'project_id' => $project_id, 'role_id' => $role_id);
         $relation = new static();
         $relation->fill($fill);
         $relation->save();
     }
 }
Example #13
0
 public static function load($id)
 {
     $page_content_file = static::get_content_directory() . '/' . $id . '.yml';
     $page_content = file_get_contents($page_content_file);
     $page_content_data = Yaml::parse($page_content);
     $page = new static($id);
     $page->fill($page_content_data);
     return $page;
 }
Example #14
0
 /**
  * Get a new instance for the current user.
  *
  * @param null $fields
  *
  * @return static
  */
 public static function current($fields = null)
 {
     global $USER;
     $user = new static($USER->getId());
     if (!is_null($fields)) {
         $user->fill($fields);
     }
     return $user;
 }
Example #15
0
 public function first()
 {
     $this->db->addQuery('LIMIT 1');
     $data = $this->db->first();
     if ($data) {
         $model = new static();
         $model->fill($data);
         return $model;
     }
     return [];
 }
Example #16
0
 /**
  * create, fill and return the object.
  *
  * @param $response
  *
  * @return static
  */
 private function build($response)
 {
     $video = new static();
     if ($response->kind == self::SEARCH_RESULT) {
         //use this if the reponse is coming from a search request.
         $video->fillFromSearch((array) $response);
     } else {
         //use this if the response if coming form a single video request.
         $video->fill((array) $response);
     }
     return $video;
 }
 /**
  * @param Model $pointable
  * @param $amount
  * @param $message
  * @param $data
  *
  * @return static
  */
 public function addTransaction(Model $pointable, $amount, $message, $data = null)
 {
     $transaction = new static();
     $transaction->amount = $amount;
     $transaction->current = $this->getCurrentPoints($pointable) + $amount;
     $transaction->message = $message;
     if ($data) {
         $transaction->fill($data);
     }
     // $transaction->save();
     $pointable->transactions()->save($transaction);
     return $transaction;
 }
Example #18
0
 /**
  * Add an activity action
  *
  * @param  int     $type_id
  * @param  int     $parent_id
  * @param  int     $item_id
  * @param  int     $action_id
  * @param  string  $data
  * @return bool
  */
 public static function add($type_id, $parent_id, $item_id = null, $action_id = null, $data = null)
 {
     $insert = array('type_id' => $type_id, 'parent_id' => $parent_id, 'user_id' => \Auth::user()->id);
     if (!is_null($item_id)) {
         $insert['item_id'] = $item_id;
     }
     if (!is_null($action_id)) {
         $insert['action_id'] = $action_id;
     }
     if (!is_null($data)) {
         $insert['data'] = $data;
     }
     $activity = new static();
     return $activity->fill($insert)->save();
 }
Example #19
0
 protected static function buildEntity($data)
 {
     $entities = static::getDefinedEntitiesArray();
     if (isset($data['entity'])) {
         if (in_array($data['entity'], $entities)) {
             $class = static::getEntityClass($data['entity']);
             $entity = new $class();
         } else {
             $entity = new static();
         }
     } else {
         $entity = new static();
     }
     $entity->fill($data);
     return $entity;
 }
Example #20
0
 /**
  * Create a new comment
  *
  * @param  array           $input
  * @param  \Project        $project
  * @param  \Project\Issue  $issue
  * @return Comment
  */
 public static function create_comment($input, $project, $issue)
 {
     $fill = array('created_by' => \Auth::user()->id, 'project_id' => $project->id, 'issue_id' => $issue->id, 'comment' => $input['comment']);
     $comment = new static();
     $comment->fill($fill);
     $comment->save();
     /* Add to user's activity log */
     \User\Activity::add(2, $project->id, $issue->id, $comment->id);
     /* Add attachments to issue */
     \DB::table('projects_issues_attachments')->where('upload_token', '=', $input['token'])->where('uploaded_by', '=', \Auth::user()->id)->update(array('issue_id' => $issue->id, 'comment_id' => $comment->id));
     /* Update the project */
     $issue->updated_at = date('Y-m-d H:i:s');
     $issue->updated_by = \Auth::user()->id;
     $issue->save();
     return $comment;
 }
Example #21
0
 /**
  * Upload the attachment
  *
  * @param  array  $input
  * @return bool
  */
 public static function upload($input)
 {
     $path = \Config::get('application.upload_path');
     if (!file_exists($path = $path . $input['project_id'])) {
         mkdir($path);
     }
     if (!file_exists($path = $path . '/' . $input['upload_token'])) {
         mkdir($path);
     }
     $file = \Input::file('Filedata');
     \File::upload('Filedata', $file_path = $path . '/' . $file['name']);
     $fill = array('uploaded_by' => \Auth::user()->id, 'filename' => $file['name'], 'fileextension' => \File::extension($file_path), 'filesize' => $file['size'], 'upload_token' => $input['upload_token']);
     $attachment = new static();
     $attachment->fill($fill);
     $attachment->save();
     return true;
 }
Example #22
0
    /**
     * Create a new comment
     *
     * @param  array           $input
     * @param  \Project        $project
     * @param  \Project\Issue  $issue
     * @return Comment
     */
    public static function create_comment($input, $project, $issue)
    {
        $fill = array('created_by' => \Auth::user()->id, 'project_id' => $project->id, 'issue_id' => $issue->id, 'comment' => $input['comment']);
        $comment = new static();
        $comment->fill($fill);
        $comment->save();
        /* Add to user's activity log */
        \User\Activity::add(2, $project->id, $issue->id, $comment->id);
        /* Add attachments to issue */
        $query = '
			UPDATE `projects_issues_attachments`
			SET issue_id = ?, comment_id = ?
			WHERE upload_token = ? AND uploaded_by = ?';
        \DB::query($query, array($issue->id, $comment->id, $input['token'], \Auth::user()->id));
        /* Update the project */
        $issue->updated_at = \DB::raw('NOW()');
        $issue->updated_by = \Auth::user()->id;
        $issue->save();
        return $comment;
    }
Example #23
0
 /**
  * Create a new comment
  *
  * @param  array           $input
  * @param  \Project        $project
  * @param  \Project\Issue  $issue
  * @return Comment
  */
 public static function create_comment($input, $project, $issue)
 {
     $fill = array('created_by' => \Auth::user()->id, 'project_id' => $project->id, 'issue_id' => $issue->id, 'comment' => $input['comment']);
     $comment = new static();
     $comment->fill($fill);
     $comment->save();
     /* Add to user's activity log */
     \User\Activity::add(2, $project->id, $issue->id, $comment->id);
     /* Add attachments to issue */
     \DB::table('projects_issues_attachments')->where('upload_token', '=', $input['token'])->where('uploaded_by', '=', \Auth::user()->id)->update(array('issue_id' => $issue->id, 'comment_id' => $comment->id));
     /* Update the project */
     $issue->updated_at = date('Y-m-d H:i:s');
     $issue->updated_by = \Auth::user()->id;
     $issue->save();
     /* Notify the person to whom the issue is currently assigned, unless that person is the one making the comment */
     if ($issue->assigned_to && $issue->assigned_to != \Auth::user()->id) {
         $project = \Project::current();
         //$subject = 'Issue "' . $issue->title . '" in "' . $project->name . '" project has a new comment';
         $subject = sprintf(__('email.new_comment'), $issue->title, $project->name);
         $text = \View::make('email.commented_issue', array('actor' => \Auth::user()->firstname . ' ' . \Auth::user()->lastname, 'project' => $project, 'issue' => $issue, 'comment' => $comment->comment));
         \Mail::send_email($text, $issue->assigned->email, $subject);
     }
     return $comment;
 }
Example #24
0
 public function make(UploadInterface $upload)
 {
     $photo = new static();
     $photo->fill($upload);
     return $photo;
 }
Example #25
0
    /**
     * Create a new issue
     *
     * @param  array    $input
     * @param  \Project  $project
     * @return Issue
     */
    public static function create_issue($input, $project)
    {
        $rules = array('title' => 'required|max:200', 'body' => 'required');
        $validator = \Validator::make($input, $rules);
        if ($validator->invalid()) {
            return array('success' => false, 'errors' => $validator);
        }
        $fill = array('created_by' => \Auth::user()->id, 'project_id' => $project->id, 'title' => $input['title'], 'body' => $input['body']);
        if (\Auth::user()->permission('issue-modify')) {
            $fill['assigned_to'] = $input['assigned_to'];
        }
        $issue = new static();
        $issue->fill($fill);
        $issue->save();
        /* Add to user's activity log */
        \User\Activity::add(1, $project->id, $issue->id);
        /* Add attachments to issue */
        $query = '
			UPDATE `projects_issues_attachments`
			SET issue_id = ?
			WHERE upload_token = ? AND uploaded_by = ?';
        \DB::query($query, array($issue->id, $input['token'], \Auth::user()->id));
        /* Return success and issue object */
        return array('success' => true, 'issue' => $issue);
    }
Example #26
0
 /**
  * Attempts to get the part from the servers and
  * return it.
  *
  * @param string $id 
  * @return Part|null 
  */
 public static function find($id)
 {
     $part = new static([], true);
     if (!$part->findable) {
         return null;
     }
     try {
         $request = Guzzle::get($part->uriReplace('get', ['id' => $id]));
     } catch (DiscordRequestFailedException $e) {
         return null;
     }
     $part->fill($request);
     return $part;
 }
Example #27
0
 /**
  * Create a new model instance from the $_POST input.
  *
  * @return  static
  */
 public static function fromInput()
 {
     $model = new static();
     return $model->fill(r::data());
 }
Example #28
0
 /**
  * Create a new issue
  *
  * @param  array    $input
  * @param  \Project  $project
  * @return Issue
  */
 public static function create_issue($input, $project)
 {
     $rules = array('title' => 'required|max:200', 'body' => 'required');
     $validator = \Validator::make($input, $rules);
     if ($validator->fails()) {
         return array('success' => false, 'errors' => $validator->errors);
     }
     $fill = array('created_by' => \Auth::user()->id, 'project_id' => $project->id, 'title' => $input['title'], 'body' => $input['body']);
     if (\Auth::user()->permission('issue-modify')) {
         $fill['assigned_to'] = $input['assigned_to'];
     }
     $issue = new static();
     $issue->fill($fill);
     $issue->save();
     /* Add to user's activity log */
     \User\Activity::add(1, $project->id, $issue->id);
     /* Add attachments to issue */
     \DB::table('projects_issues_attachments')->where('upload_token', '=', $input['token'])->where('uploaded_by', '=', \Auth::user()->id)->update(array('issue_id' => $issue->id));
     /* Return success and issue object */
     return array('success' => true, 'issue' => $issue);
 }
Example #29
0
 /**
  * Update a model instance in the database.
  *
  * @param  mixed  $id
  * @param  array  $attributes
  * @return int
  */
 public static function update($id, $attributes)
 {
     $model = new static(array(), true);
     $model->fill($attributes);
     if (static::$timestamps) {
         $model->timestamp();
     }
     return $model->query()->where($model->key(), '=', $id)->update($model->attributes);
 }
Example #30
0
 /**
  * @param Model $likeable
  * @param int   $value
  *
  * @return bool
  */
 protected function cast(Model $likeable, $value = 1)
 {
     if (!$likeable->exists) {
         return false;
     }
     $vote = new static();
     $vote->fill(compact('value'));
     return $vote->likeable()->associate($likeable)->save();
 }