Example #1
0
 /**
  * Register stamp
  *
  * @param      integer 	$projectid		Project ID
  * @param      string 	$reference		Reference string to object (JSON)
  * @return     mixed False if error, Object on success
  */
 public function registerStamp($projectid = 0, $reference = '', $type = 'files', $listed = 0, $expires = NULL)
 {
     if (!$projectid || !$reference) {
         return false;
     }
     $now = Date::toSql();
     $obj = new self($this->_db);
     $obj->checkStamp($projectid, $reference, $type);
     // Load record
     if ($obj->id) {
         if ($obj->expires && $obj->expires != '0000-00-00 00:00:00' && $obj->expires < $now) {
             // Expired
             $obj->delete();
             return $this->registerStamp($projectid, $reference, $type, $listed, $expires);
         } else {
             if ($listed === NULL && $expires === NULL) {
                 return $obj->stamp;
             }
             // These values may be updated
             $obj->listed = $listed === NULL ? $obj->listed : $listed;
             $obj->expires = $expires === NULL ? $obj->expires : $expires;
             $obj->store();
             return $obj->stamp;
         }
     }
     // Make new entry
     $created = Date::toSql();
     $created_by = User::get('id');
     // Generate stamp
     require_once PATH_CORE . DS . 'components' . DS . 'com_projects' . DS . 'helpers' . DS . 'html.php';
     $stamp = \Components\Projects\Helpers\Html::generateCode(20, 20, 0, 1, 1);
     $query = "INSERT INTO {$this->_tbl} (stamp, projectid, listed, type, reference, expires, created, created_by)\n\t\t\t\t VALUES ('{$stamp}', '{$projectid}', '{$listed}', '{$type}', '{$reference}', '{$expires}' , '{$created}', '{$created_by}' )";
     $this->_db->setQuery($query);
     if (!$this->_db->query()) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     return $stamp;
 }