예제 #1
0
 /**
  * Constructor.
  * initializes the resource if the id is given
  *
  * @param integer $id DB id
  * @return void
  * @access public
  */
 function CMS_resource($id = 0)
 {
     if ($id) {
         if (SensitiveIO::isPositiveInteger($id)) {
             $sql = "\n\t\t\t\t\tselect\n\t\t\t\t\t\t*\n\t\t\t\t\tfrom\n\t\t\t\t\t\tresources,\n\t\t\t\t\t\tresourceStatuses\n\t\t\t\t\twhere\n\t\t\t\t\t\tid_res='{$id}'\n\t\t\t\t\t\tand status_res=id_rs\n\t\t\t\t";
             $q = new CMS_query($sql);
             if ($q->getNumRows()) {
                 $data = $q->getArray();
                 $this->_id = $id;
                 $this->_status = new CMS_resourceStatus($data);
                 if ($this->_status->hasError()) {
                     $this->raiseError("Unfound status :" . $data["status_res"]);
                     return;
                 }
                 //build editors stack. If stack is malformed, it's a minor error, so proceed.
                 $this->_editors = new CMS_stack();
                 if (!$this->_editors->setTextDefinition($data["editorsStack_res"])) {
                     $this->raiseError("Editors stack malformed");
                     $this->_editors->emptyStack();
                 }
             } else {
                 $this->raiseError("Unknown ID :" . $id);
             }
         } elseif (is_array($id)) {
             $data = $id;
             $this->_id = $data["id_res"];
             $this->_status = new CMS_resourceStatus($data);
             if ($this->_status->hasError()) {
                 $this->raiseError("Unfound status :" . $data["status_res"]);
                 return;
             }
             //build editors stack. If stack is malformed, it's a minor error, so proceed.
             $this->_editors = new CMS_stack();
             if (!$this->_editors->setTextDefinition($data["editorsStack_res"])) {
                 $this->raiseError("Editors stack malformed");
                 $this->_editors->emptyStack();
             }
         } else {
             $this->raiseError("Id is not a positive integer nor array");
             return;
         }
     } else {
         $this->_status = new CMS_resourceStatus();
         $this->_editors = new CMS_stack();
     }
 }