Example #1
0
 public function video($id = null)
 {
     $videos = $this->videos();
     if (empty($videos)) {
         return null;
     }
     if (empty($id)) {
         return $videos[0];
     }
     return FTool::find($videos, 'id', $id);
 }
Example #2
0
 public function save($connection = null)
 {
     if (empty($this->___db)) {
         $this->error('cannot save a doc without db');
     }
     if (empty($this->___collection)) {
         $this->error('cannot save a doc without collection');
     }
     $connection = $this->check($connection);
     try {
         $collection = $connection->selectCollection($this->___db, $this->___collection);
     } catch (Exception $e) {
         $this->error('selecting collection generated an exception.');
     }
     if (empty($this->{$this->___key})) {
         $this->{$this->___key} = FTool::uuid();
     }
     $criteria = array($this->___key => $this->{$this->___key});
     $doc = $this->doc(get_object_vars($this));
     $result = $collection->update($criteria, $doc, array('upsert' => true));
     if (empty($result['ok'])) {
         $this->error('write was unacknowledged!');
     }
     $this->log('saved ' . $this->___key . ' > ' . $this->{$this->___key});
     return true;
 }